From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 7B42B3B3C1D for ; Mon, 29 Jun 2026 06:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782716212; cv=none; b=ONOrlRNyuE6pjG3maMltDfxH1YhB4zJhLLNc1aoZ5bd01ogxv6oYZGmZRO4lr87HOF/7IhMq1SD3twM3Bhr0w4hLtkFAm6+0T85I1cBtGDtaas11IoigMcUqOqIUjjd5DEyghJSpTIo6ow8WOOPmQqAhaMOmrezk+QLefoznRtY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782716212; c=relaxed/simple; bh=FP2b2X8cHmJupQxK44FVNcxsuXugf+q7qdGuWIDqSVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i2urX9ZWzeYNnEhpJtzihuVTTB4bUSXYwOBqsZvZ1t/EwJqlJOc3wvGmXdNkFC6lv4hxDCkCO+ZLMjsfFxrigE2qAMWmbNOvpRvZqTQUzu4DoQtp0uXQZRPuhc14EaDZv8I4jwhBGrv9zIlXFspDRyIdai3AAsRWkm84L0wIZmU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=RUiMVdkA; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=RUiMVdkA; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="RUiMVdkA"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="RUiMVdkA" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ACB3971266; Mon, 29 Jun 2026 06:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1782716204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2sAWNQBhg7iKfl9MqPkd8Tzvhw4dfmVwQvO2lsAOV+k=; b=RUiMVdkAekqF4CRFzCcpBwGoeAOqjiyOYPEce0bBIdcyZ/5bQdExnaVo6iZUUGPxJfzCpK rDRkuQwafDYeFXsfCuQhtrPkHV65zWe0yJjKYVAhgPfDF0/WU/G1vJUNrt1CQJDw5yElgx 3kexkgZG4Js51LrFk696j/tPqgCcUAw= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1782716204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2sAWNQBhg7iKfl9MqPkd8Tzvhw4dfmVwQvO2lsAOV+k=; b=RUiMVdkAekqF4CRFzCcpBwGoeAOqjiyOYPEce0bBIdcyZ/5bQdExnaVo6iZUUGPxJfzCpK rDRkuQwafDYeFXsfCuQhtrPkHV65zWe0yJjKYVAhgPfDF0/WU/G1vJUNrt1CQJDw5yElgx 3kexkgZG4Js51LrFk696j/tPqgCcUAw= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6B5D4779A8; Mon, 29 Jun 2026 06:56:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id CmWbGCwXQmpnQgAAD6G6ig (envelope-from ); Mon, 29 Jun 2026 06:56:44 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v4 10/18] x86/msr: Introduce sync_cpu_after_wrmsrns() Date: Mon, 29 Jun 2026 08:55:36 +0200 Message-ID: <20260629065544.3643253-11-jgross@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260629065544.3643253-1-jgross@suse.com> References: <20260629065544.3643253-1-jgross@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Flag: NO X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLfdszjqhz8kzzb9uwpzdm8png)]; DBL_BLOCKED_OPENRESOLVER(0.00)[zytor.com:email,suse.com:email,suse.com:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Level: X-Spam-Score: -6.80 In order to allow using wrmsrns() for multiple MSR register writes introduce sync_cpu_after_wrmsrns() which will then do a CPU serialize operation, if the hardware does support the WRMSRNS instruction. In case the hardware doesn't support WRMSRNS, sync_cpu_after_wrmsrns() will be a NOP. Suggested-by: H. Peter Anvin Signed-off-by: Juergen Gross --- V4: - new patch --- arch/x86/include/asm/msr.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 91d6f481732b..40bb03df162c 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -14,6 +14,7 @@ #include #include #include +#include struct msr_info { u32 msr_no; @@ -362,6 +363,12 @@ static __always_inline int wrmsrns_safe(u32 msr, u64 val) return err; } +static __always_inline void sync_cpu_after_wrmsrns(void) +{ + if (static_cpu_has(X86_FEATURE_WRMSRNS)) + serialize(); +} + struct msr __percpu *msrs_alloc(void); void msrs_free(struct msr __percpu *msrs); int msr_set_bit(u32 msr, u8 bit); -- 2.54.0