From nobody Sun Feb 8 05:20:18 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8693973477 for ; Thu, 27 Feb 2025 01:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618080; cv=none; b=dg0VNi8iNB50ntf/2BnTQ2nXRuxjH2tE3eANWHLl97KuGZzbEpgwmwfJSSxYLCdueSVmg0Ot3yQO+I7eZ6OkHABHntux0riFGs461JBo36aYEmdLsSYG1z+LziVYlmMklHCQ1uaJ2ZSryRU7cVVNQPfbdiHKWB0CUmHbnoZTgCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618080; c=relaxed/simple; bh=GZ6qMOoOVuiq1MAFI9FkQ+kQcduE2jvLA2wNIUu2RL4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hQknJDVnG8UW6R2hs9HaqvX5pLSGv1ZTMl/pbdc+uyZV6gwJjzNemtqMkh87dZwdccc0x7Pfs5r/Jafz0auN729weReVBiuh13Z5CpHiJ6GriikmkfcurNKJ90veRk7knSb+FJSB+6nmSQconUEyskot+nYio3FvEYMyIccf5Ng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jGTj5zd7; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jGTj5zd7" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2fc2fee4425so1391969a91.0 for ; Wed, 26 Feb 2025 17:01:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740618076; x=1741222876; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=RDoWSiiBmUA4Cvc4ko+cuVneWh/qlxcsIoQ/Ggi5MbQ=; b=jGTj5zd7Pl7Sjfe3lxYdK3cPRnlbeKCHyeOl4JzzQRM5+RX/cqOMH98XLyVndS9JN1 Q8VSThw7CWrJVAwb/xpCZYkKk22v6PMk94gTJj7RAoVnaO0uWoL9uSKbORHF/VQohTE3 jnMBpTxB5cfwzMJGs/7/VVQj70B4AGaUCofjb+TzOV9YTUbCXXXG9zDoROIynInqFc4D Knet/4v7FlJwDrEvHnz+jC93UFaRQWgYR8nKvgeXwq9v/uF9iBoqb2aNvRZeXgdcQtlY oc6Dt5i5IlrZ7ZwO7kf/jZBbYKSsZs2AZB9MkQpTdFVf2z6NTxip0gJ7xyFE+8hLl1se tHXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740618076; x=1741222876; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RDoWSiiBmUA4Cvc4ko+cuVneWh/qlxcsIoQ/Ggi5MbQ=; b=s+NEUO7DVCzakA+xgAjKKhXroJJX4ie3buMyA44xXC3A5o0fQLJoQ8VSBpaSdMHEU1 hsLErAmlUoObIhX97vbQqeMRBIdQyI81ETAJHnCCl9oG3CL2pB+aY6Xdn06TuLUAVlyc P66pWahyF8zqpZhkyiuigco8IVDu1/3O2D2i5GXddXlYUfnnzOCjcpxgPfUzvCtHSV0l bWmOHTsbmL1wo1SnCB66hl+T8XuefSG3FcgEzboq5oWnZtZfGBqvIA9kXnKWD0AiCXHO Z3C7AYitum1qHdYWUO/cmMoQ3h6qkGBolYaUjcrPA3y/kLMNmg4zPlH0xZr8zHMOr8F3 Z1Xg== X-Forwarded-Encrypted: i=1; AJvYcCXlvKjEofJXQnAlEGmUWj6o39y2h1jbjgJbs4zBt7mLnes+RwMUZRXvaapD4A8NRaGBNY886HzcWGe/tq8=@vger.kernel.org X-Gm-Message-State: AOJu0YxScNtBSXvdyb/EoVSA8XVKajTSYk71uQ2BAaibYjp+sUblj2zC keugxoWtafNZ8FloaaAGQVIti1D4nO8vMk6+Bicxt8SSsB05AMQyyncLTHZISxDc4yiistKCrGB voQ== X-Google-Smtp-Source: AGHT+IH1hWe5Okz6/gdiRccw2sOEjxHYPXs3ilAyiVOoy2RH4ZzxsE7mftj9onRF83A6Ybwzulh3XobBvzI= X-Received: from pjbtb8.prod.google.com ([2002:a17:90b:53c8:b0:2fc:ccfe:368]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5686:b0:2ee:aed6:9ec2 with SMTP id 98e67ed59e1d1-2fe7e30045emr10064662a91.14.1740618075925; Wed, 26 Feb 2025 17:01:15 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:01:10 -0800 In-Reply-To: <20250227010111.3222742-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227010111.3222742-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227010111.3222742-2-seanjc@google.com> Subject: [PATCH 1/2] x86/msr: Rename the WRMSRNS opcode macro to ASM_WRMSRNS (for KVM) From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xin Li Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename the WRMSRNS instruction opcode macro so that it doesn't collide with X86_FEATURE_WRMSRNS when using token pasting to generate references to X86_FEATURE_WRMSRNS. KVM heavily uses token pasting to generate KVM's set of support feature bits, and adding WRMSRNS support in KVM will run will run afoul of the opcode macro. arch/x86/kvm/cpuid.c:719:37: error: pasting "X86_FEATURE_" and "" "" does= not give a valid preprocessing token 719 | u32 __leaf =3D __feature_leaf(X86_FEATURE_##name); = \ | ^~~~~~~~~~~~ KVM has worked around one such collision in the past by #undef'ing the problematic macro in order to avoid blocking a KVM rework, but such games are generally undesirable, e.g. requires bleeding macro details into KVM, risks weird behavior if what KVM is #undef'ing changes, etc. Signed-off-by: Sean Christopherson Reviewed-by: Xin Li (Intel) --- arch/x86/include/asm/msr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 001853541f1e..60b80a36d045 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -300,7 +300,7 @@ do { \ #endif /* !CONFIG_PARAVIRT_XXL */ =20 /* Instruction opcode for WRMSRNS supported in binutils >=3D 2.40 */ -#define WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6) +#define ASM_WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6) =20 /* Non-serializing WRMSR, when available. Falls back to a serializing WRM= SR. */ static __always_inline void wrmsrns(u32 msr, u64 val) @@ -309,7 +309,7 @@ static __always_inline void wrmsrns(u32 msr, u64 val) * WRMSR is 2 bytes. WRMSRNS is 3 bytes. Pad WRMSR with a redundant * DS prefix to avoid a trailing NOP. */ - asm volatile("1: " ALTERNATIVE("ds wrmsr", WRMSRNS, X86_FEATURE_WRMSRNS) + asm volatile("1: " ALTERNATIVE("ds wrmsr", ASM_WRMSRNS, X86_FEATURE_WRMSR= NS) "2: " _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR) : : "c" (msr), "a" ((u32)val), "d" ((u32)(val >> 32))); } --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 05:20:18 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 548A476034 for ; Thu, 27 Feb 2025 01:01:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618079; cv=none; b=GTtt/gm9jzMTFMluLQKJvGAltCkUJudvbnXxto/ZQn9PaViWR7uuGe9x2XffW57+OvsIRg/a9PdrOOV/pinMf/vL78UpqC83AytjGQ6k9qM/BOtQP6UkjPN8ihp3nhEpHAPw7iDoFl6qjmG10Gb6BCyhCrF17KJ8sKvzIOYcjbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618079; c=relaxed/simple; bh=WlG71nbfhMG+iZLSreFus8KOoSWVnI0WTDVJb/q9jyI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XrObacmnDrHoNQGVyhsf/nZ4nmAoGPT+s9JHmlf0U35VWwY7IUVmGt8iqpciHP05l1yNzBzNH6fGOSJ1bImUlDgH5M/yVS878xS3isMnqlk4WBYze5jYTcFeNekNzx8u5ZRFUKNxfjnaYVCJPayTnIHe4OIKbrqCHJTU5R7Z7EU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=h5bwLIWn; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h5bwLIWn" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-21f6cb3097bso7795635ad.3 for ; Wed, 26 Feb 2025 17:01:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740618077; x=1741222877; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=vBrLV0hVNi1a5D0W6BOn6trR5W1NotqikKgQ5Tv/tAA=; b=h5bwLIWnwuwrVytdM2CbIkyHDKiwxHsBucwH/HVkYoAGvzRRf2ExPXlMyntnUdjoas QobhzuDj107Ca/zGaDS+w8BQFr4aSwDVqMKP3XztP9CbtwtNVGlmpelAT2ovNx+GajMm MW2gB//r/0CeMbPWGRG9avSqFq6QfKj/zmv+4MgIL9RTU8bo18I1u6ZRNezMD64Pd+AZ N/m+tHyM9GIw+bIwKehFhe/KSUdgemEDxI44vQrKaHbMakUVB9awcY8nIHSsZKgi5LWS pogQZ+xysPF02k+tial2LdtKDUuLvHQJ/awgaLnsIvwGX+oUiAzO6f50wXg4+AtF/DPw orjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740618077; x=1741222877; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vBrLV0hVNi1a5D0W6BOn6trR5W1NotqikKgQ5Tv/tAA=; b=iVOCKEtBrb5ZkrrKrHSupT+ALVwKV769i3ughln+B8y1ruF4IfCmTJc5CIa9OE0/KP QQL9OTWmct5sUevsOaWNQD+1RQQXwoIYKeTkaBzOkMSG1jbVOIvTaLmi/BrSuIhT4dqg mrcYcdM9zAasK7lN65hZMGOsdejhogArzOd68EtbFTJhAg3RPCRI8H8CTgZP6pS4zc/+ adqf4JPPcno1ghP1jg4j2LWuLRf1WAuZkTECtpnZdij5de+V7DE99sDVHg9zu7CP+K8z B38+7M47gs1pQn3arNRphOwlii5dJwGD+KwTg2qjmCoHo4NsdrMvDwk0CpItDlvOBaF2 h4eA== X-Forwarded-Encrypted: i=1; AJvYcCXbEnXuCaHTBuw6cddEa2VB1jsLbHmDGVrxBLz+yh5AQljsWYzESnOTvBhgKfR54fSeSLFAWvjmdQxvtmM=@vger.kernel.org X-Gm-Message-State: AOJu0YzhNF+/opLk7TFnYd5dTu9kJpUImAJw0EdLzAzB0iLTdj6vnOjm 2habi62rxd/tHaMO433y7EzB/026wgSVx6Q8wegGMTrkAjhRbZLnvqquApG1aiEMPs70MSn/mql kIA== X-Google-Smtp-Source: AGHT+IHs7OvM6rkyJG6uPTB8OuiiFrOfEIijhU66O7j1sKQRSBCikrQVvi/YgsIilD/6fEgCFLkFRZL+ErE= X-Received: from pfbfb26.prod.google.com ([2002:a05:6a00:2d9a:b0:734:4341:5d97]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:eccb:b0:220:ea90:1925 with SMTP id d9443c01a7336-221a1148e99mr409270715ad.35.1740618077666; Wed, 26 Feb 2025 17:01:17 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:01:11 -0800 In-Reply-To: <20250227010111.3222742-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227010111.3222742-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227010111.3222742-3-seanjc@google.com> Subject: [PATCH 2/2] KVM: x86: Advertise support for WRMSRNS From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xin Li Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Advertise support for WRMSRNS (WRMSR non-serializing) to userspace if the instruction is supported by the underlying CPU. From a virtualization perspective, the only difference between WRMSRNS and WRMSR is that VM-Exits due to WRMSRNS set EXIT_QUALIFICATION to '1'. WRMSRNS doesn't require a new enabling control, shares the same basic exit reason, and behaves the same as WRMSR with respect to MSR interception. WRMSR and WRMSRNS use the same basic exit reason (see Appendix C). For WRMSR, the exit qualification is 0, while for WRMSRNS it is 1. Don't do anything different when emulating WRMSRNS vs. WRMSR, as KVM can't do anything less, i.e. can't make emulation non-serializing. The motivation for the guest to use WRMSRNS instead of WRMSR is to avoid immediately serializing the CPU when the necessary serialization is guaranteed by some other mechanism, i.e. WRMSRNS being fully serializing isn't guest-visible, just less performant. Suggested-by: Xin Li (Intel) Signed-off-by: Sean Christopherson --- arch/x86/kvm/cpuid.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 97a90689a9dc..ebecfe4bea1e 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -992,6 +992,7 @@ void kvm_set_cpu_caps(void) F(FZRM), F(FSRS), F(FSRC), + F(WRMSRNS), F(AMX_FP16), F(AVX_IFMA), F(LAM), --=20 2.48.1.711.g2feabab25a-goog