From nobody Fri Feb 13 08:17:56 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fC4mP1vJ5z6Sj7Z for ; Fri, 13 Feb 2026 08:17:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fC4mN71WRz3fGv for ; Fri, 13 Feb 2026 08:17:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770970677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0LSiH4Daed9iuQIuvLu9j+zK614tRKwTiA5sE4Bh4Kg=; b=e2wXG+8Fr/u1V+SpI1k3Aly+hQm8sO+higxLdj+P84fhQ0BYca/T+71/llDUT2SXC6gv/v yEvhPlxF7qD+bOjpRJPwfblX+UmuLX0ZXIHbHbNvhrgHjVtLsl/1jUUiWfANuMAhkYCOnn 8DnMPK+S54l4rqFMZ2oYeVZjR5E3WAaqRMH/fqjGxKPhc76ZlSD+cBiiHWf02acHOiiO6m xkEfZE+8nuAq7i8srqbxysrnkDHlde9TS1uWXgM8UV+of3I2/5Zd3Qwlz551f2hTArtu1f g4cS5umYyMrw5lE4S/yiavP1nCjt6zodF5jXAFywAOs5sOh3macO5bKPcL9+zg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1770970677; a=rsa-sha256; cv=none; b=xWQydJ5O3lnIekroKziuM2o4mO4knBvaBPF/o4Y63iKPuNmyo0QbH3DHDbdagW/WBN2ztX /w900+sELahOgw65bxOVkkFgYyJzKQS//zqrDeDU7oV7K4IT7I4IZIbrcawbkEoFftWciK bl6iscasSJotseS70IYi4CJ8JG1VXDwKiLB39i7/MkyRsU5q4kLSKjnA5tCv5Y5oI6JeZ3 F082jP1VZiuAhCuuQUUk+9DxEItpAJ1tgFTdiLLDxvAaSnuWHIhlsGKcr9oZHwLvEP8kvr NeGZV73DaXxI5nPQdcFPoYXAyAOvgXQ2XHL8oUnNfRKz9MG3e0zXfF+Rp9cZmA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770970677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0LSiH4Daed9iuQIuvLu9j+zK614tRKwTiA5sE4Bh4Kg=; b=igp4Kl1VIFvU+w1afhnyvAys0ggIPvxVm/x1pBwL0REpz49JiSQPKIw2LgS3xZZuwggABQ bc2k132o1qBGCfhIi2g05lI3b6p+M1Y7Mu3pLUC6+FWIjNaWJ9gNixKaRXNU1TYAiBp3MG rPlwPqsc8CGSryOxKPOysx9hX0SNKNBnDiaJ74ZEKvAVJLUkfpKsgTGmQFTDYbYsEBesN8 VDlTLaOJ4LhQi/cVc9HVZNN+cld054aKm27S21WPeStC8jBVvxUTocOq2WYdOc7aWIz75Y MKkE1vCj1F+Vo0bwYujxgeTrRUVPRUlqpKyHrTc9Z0fmna7KY8SG64mLVZvHbg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fC4mN6BZPz1C7q for ; Fri, 13 Feb 2026 08:17:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3e05c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 13 Feb 2026 08:17:56 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: cb81a9c18db9 - main - x86: provide extended description for x86_msr_op(9) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cb81a9c18db93a2046c47b0c7dc0bd6adcdd2495 Auto-Submitted: auto-generated Date: Fri, 13 Feb 2026 08:17:56 +0000 Message-Id: <698ede34.3e05c.3beb55d4@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=cb81a9c18db93a2046c47b0c7dc0bd6adcdd2495 commit cb81a9c18db93a2046c47b0c7dc0bd6adcdd2495 Author: Konstantin Belousov AuthorDate: 2026-02-04 00:22:08 +0000 Commit: Konstantin Belousov CommitDate: 2026-02-13 07:55:04 +0000 x86: provide extended description for x86_msr_op(9) Reviewed by: markj, olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D55045 --- sys/x86/include/x86_var.h | 6 ++---- sys/x86/x86/cpu_machdep.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/sys/x86/include/x86_var.h b/sys/x86/include/x86_var.h index caaab207b57a..40dd21107436 100644 --- a/sys/x86/include/x86_var.h +++ b/sys/x86/include/x86_var.h @@ -162,7 +162,7 @@ void x86_set_fork_retval(struct thread *td); uint64_t rdtsc_ordered(void); /* - * MSR ops for x86_msr_op() + * MSR ops for x86_msr_op(). */ #define MSR_OP_ANDNOT 0x00000001 #define MSR_OP_OR 0x00000002 @@ -170,9 +170,7 @@ uint64_t rdtsc_ordered(void); #define MSR_OP_READ 0x00000004 /* - * Where and which execution mode - * - * All modes cause execution on the target CPU(s) with interrupts disabled. + * Where and which execution mode. */ #define MSR_OP_SAFE 0x08000000 #define MSR_OP_LOCAL 0x10000000 diff --git a/sys/x86/x86/cpu_machdep.c b/sys/x86/x86/cpu_machdep.c index 6c3f4add6202..5483fbd6dd4e 100644 --- a/sys/x86/x86/cpu_machdep.c +++ b/sys/x86/x86/cpu_machdep.c @@ -223,6 +223,49 @@ x86_msr_op_one(void *arg) #define MSR_OP_GET_CPUID(x) \ (((x) & ~(MSR_OP_EXMODE_MASK | MSR_OP_SAFE)) >> 8) +/* + * Utility function to wrap common MSR accesses. + * + * The msr argument specifies the MSR number to operate on. + * arg1 is an optional additional argument which is needed by + * modifying ops. + * + * res is the location where the value read from MSR is placed. It is + * the value that was initially read from the MSR, before applying the + * specified operation. Can be NULL if the value is not needed. If + * the op is executed on more than one CPU, it is unspecified on which + * CPU the value was read. + * + * op encoding combines the target/mode specification and the requested + * operation, all or-ed together. + * + * MSR accesses are executed with interrupts disabled. + + * The following targets can be specified: + * MSR_OP_LOCAL execute on current CPU. + * MSR_OP_SCHED_ALL execute on all CPUs, by migrating + * the current thread to them in sequence. + * MSR_OP_SCHED_ALL | MSR_OP_SAFE execute on all CPUs by migrating, using + * safe MSR access. + * MSR_OP_SCHED_ONE execute on specified CPU, migrate + * curthread to it. + * MSR_OP_SCHED_ONE | MSR_OP_SAFE safely execute on specified CPU, + * migrate curthread to it. + * MSR_OP_RENDEZVOUS_ALL execute on all CPUs in interrupt + * context. + * MSR_OP_RENDEZVOUS_ONE execute on specified CPU in interrupt + * context. + * If a _ONE target is specified, 'or' the op value with MSR_OP_CPUID(cpuid) + * to name the target CPU. _SAFE variants might return EFAULT if access to + * MSR faulted with #GP. Non-_SAFE variants most likely panic or reboot + * the machine if the MSR is not present or access is not tolerated by hw. + * + * The following operations can be specified: + * MSR_OP_ANDNOT *res = v = *msr; *msr = v & ~arg1 + * MSR_OP_OR *res = v = *msr; *msr = v | arg1 + * MSR_OP_READ *res = *msr + * MSR_OP_WRITE *res = *msr; *msr = arg1 + */ int x86_msr_op(u_int msr, u_int op, uint64_t arg1, uint64_t *res) {