From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 0842438550E for ; Mon, 20 Apr 2026 09:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776676620; cv=none; b=KsWPwPvuVOKUtexmHpZXUUKnwPCuAzr5P2CVXhtEDZs2a7mf5hE1jaipDCF5IY2o8c95328HcQWofyf6CeGlHXQtVlFBqNWT6IAfcFOOjoI1lAM+IkOH8m0J5BWszZCXdXGsplMrLOn3FxGNKT9J3ezXookMY0AXatU9higCars= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776676620; c=relaxed/simple; bh=uDAtzIr09POoiA68Zem+8p4NrDgenjrCvY0fHrxTovY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jrJTl0PS57qyTnUd1S/FFBM09cagu2X8MBt8eQTRHH5SqRAJM8n9R/DvzPkvBrPPMTSK8J39Tc+iyj9+jnTOfd5nPJMb7v7d533ZGgwguUVeqQj18jSqoFCoYKod6msM9fWeIAmJXT6jV7yEP+e3EhnepO8xmDMJNI/gPXWUHS4= 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=u2BqB+oz; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=u2BqB+oz; arc=none smtp.client-ip=195.135.223.131 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="u2BqB+oz"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="u2BqB+oz" 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-out2.suse.de (Postfix) with ESMTPS id 50EED5BD22; Mon, 20 Apr 2026 09:16:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1776676615; 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=Q7rrGCVlsS3R/AjxzlI2HAv2K2IxMbsCL1rzEK421iU=; b=u2BqB+ozHWJLrj2BqI5mgdrLWDMhShBmqH9Z+bXLonto7GdXdd01bPEOnnsM5BVngkLn1G vEPw76/yOs6R64l53RkbAP2wgU2CSuq/1inoi8t1V9fWeAI0FL9MvQhOm4DJO7RZfx299a wQYHlxDw14obH85MbXBkW8dIk9InpTY= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1776676615; 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=Q7rrGCVlsS3R/AjxzlI2HAv2K2IxMbsCL1rzEK421iU=; b=u2BqB+ozHWJLrj2BqI5mgdrLWDMhShBmqH9Z+bXLonto7GdXdd01bPEOnnsM5BVngkLn1G vEPw76/yOs6R64l53RkbAP2wgU2CSuq/1inoi8t1V9fWeAI0FL9MvQhOm4DJO7RZfx299a wQYHlxDw14obH85MbXBkW8dIk9InpTY= 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 1FB02593AE; Mon, 20 Apr 2026 09:16:55 +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 OKiqBgfv5WnEPQAAD6G6ig (envelope-from ); Mon, 20 Apr 2026 09:16:55 +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 RFC 2/6] x86/msr: Create a new minimal set of local MSR access functions Date: Mon, 20 Apr 2026 11:16:30 +0200 Message-ID: <20260420091634.128787-3-jgross@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260420091634.128787-1-jgross@suse.com> References: <20260420091634.128787-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-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.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]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[8]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; URIBL_BLOCKED(0.00)[imap1.dmz-prg2.suse.org:helo,suse.com:mid,suse.com:email]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO Today there are two sets of MSR access functions (apart from the low level ones): one is using 64 bit values, and the other a pair of 32-bit values for the MSR contents. The read variants are macros, while the write variants are proper inline functions. In order to prepare for non-serializing variants of the write functions, create a complete set of MSR functions using a proper name space ("msr_*") without the 32-bit pair variants. Name the write variants explicitly msr_write_[safe_]ser() and msr_write_[safe_]noser() in order to make it very clear whether the serializing or the non-serializing variant is meant. Right now the new set will be based on the old wrmsr*() and rdmsr*() functions, but when all users have been switched to use the new functions, the old wrmsr*() and rdmsr*() functions will be dropped. Signed-off-by: Juergen Gross --- arch/x86/include/asm/msr.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 9c2ea29e12a9..cc21c8699e23 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -227,6 +227,44 @@ static __always_inline u64 rdpmc(int counter) #endif /* !CONFIG_PARAVIRT_XXL */ +/* + * New set of MSR access functions. New code should use those instead of the + * legacy wrmsr*() and rdmsr*() ones. + */ +static __always_inline u64 msr_read(u32 msr) +{ + u64 val; + + rdmsrq(msr, val); + + return val; +} + +static __always_inline int msr_read_safe(u32 msr, u64 *val) +{ + return rdmsrq_safe(msr, val); +} + +static __always_inline void msr_write_ser(u32 msr, u64 val) +{ + wrmsrq(msr, val); +} + +static __always_inline int msr_write_safe_ser(u32 msr, u64 val) +{ + return wrmsrq_safe(msr, val); +} + +static __always_inline void msr_write_noser(u32 msr, u64 val) +{ + wrmsrq(msr, val); +} + +static __always_inline int msr_write_safe_noser(u32 msr, u64 val) +{ + return wrmsrq_safe(msr, val); +} + /* Instruction opcode for WRMSRNS supported in binutils >= 2.40 */ #define ASM_WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6) -- 2.53.0