From nobody Wed Dec 17 12:46:55 2025 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 5F71D2BCF4A for ; Tue, 30 Sep 2025 07:04:12 +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=1759215855; cv=none; b=APjilmrcRz6/mY7NaK2DO7Z5U4QKvPI6NsyjY4PA112OvQ3kEaxPEOlWZcvvgNrtyFBBd699Pxf38tfeD8Sr2TxCnCMrcSD0vRi65PpVT7eg1QMkU+k2azbCg2XTOU8HEpIHfTtgMNoW6PWEu4AEpPvhwmNlWxWg8qufW1s1VgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215855; c=relaxed/simple; bh=wkhZAHsBoKKngbAAqQTVMDLeDlcckAP1gUo2JTFae0M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hMFkGs/JN4v8UcWXG22avuJqChyNjtr6zE25GZsOpOAEy8qSWFul8ZJsv10L0Zm5CLr56pcrris2hyMX7W0WInDUamvDB/prBxKPV0+YWFI2A2E7rTWmkUmW+f9R37AdzXmTdAr5vuT0Hoe6yAu5eSBZdqsmlpX1qOCtjW04cSw= 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=rQ0tmSjC; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=rQ0tmSjC; 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="rQ0tmSjC"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="rQ0tmSjC" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 72D4D3374B; Tue, 30 Sep 2025 07:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215846; 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=NSf+6D4MbYL+XlpJyDDayy5soUcQQSx27jf/xJMjXUI=; b=rQ0tmSjCv0szHdlkeG8DWbThL3VPzsomAzP86KV/RmMPylBtOnVbuuGCOGXvwKLx+oVaa/ 9URzm6ibpBE9UhxTWC3zeOFVlUYSrpftVEfRfBbDi1ZTTXoEevhubUwff+kW+T+msk/IAQ 9miHnUPVRnET3ZgEclbXWGetuMcS1rQ= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=rQ0tmSjC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215846; 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=NSf+6D4MbYL+XlpJyDDayy5soUcQQSx27jf/xJMjXUI=; b=rQ0tmSjCv0szHdlkeG8DWbThL3VPzsomAzP86KV/RmMPylBtOnVbuuGCOGXvwKLx+oVaa/ 9URzm6ibpBE9UhxTWC3zeOFVlUYSrpftVEfRfBbDi1ZTTXoEevhubUwff+kW+T+msk/IAQ 9miHnUPVRnET3ZgEclbXWGetuMcS1rQ= 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 0BE6013A3F; Tue, 30 Sep 2025 07:04:06 +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 YOwbAeaA22iARwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:06 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev Cc: xin@zytor.com, Juergen Gross , "Kirill A. Shutemov" , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH v2 01/12] coco/tdx: Rename MSR access helpers Date: Tue, 30 Sep 2025 09:03:45 +0200 Message-ID: <20250930070356.30695-2-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spamd-Result: default: False [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; R_RATELIMIT(0.00)[to_ip_from(RLkdkdrsxe9hqhhs5ask8616i6)]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:mid,suse.com:dkim,suse.com:email] X-Spam-Flag: NO X-Spam-Level: X-Rspamd-Queue-Id: 72D4D3374B X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 Content-Type: text/plain; charset="utf-8" In order to avoid a name clash with some general MSR access helpers after a future MSR infrastructure rework, rename the TDX specific helpers. Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) Reviewed-by: Kiryl Shutsemau --- arch/x86/coco/tdx/tdx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 7b2833705d47..500166c1a161 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -468,7 +468,7 @@ static void __cpuidle tdx_safe_halt(void) raw_local_irq_enable(); } =20 -static int read_msr(struct pt_regs *regs, struct ve_info *ve) +static int tdx_read_msr(struct pt_regs *regs, struct ve_info *ve) { struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, @@ -489,7 +489,7 @@ static int read_msr(struct pt_regs *regs, struct ve_inf= o *ve) return ve_instr_len(ve); } =20 -static int write_msr(struct pt_regs *regs, struct ve_info *ve) +static int tdx_write_msr(struct pt_regs *regs, struct ve_info *ve) { struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, @@ -842,9 +842,9 @@ static int virt_exception_kernel(struct pt_regs *regs, = struct ve_info *ve) case EXIT_REASON_HLT: return handle_halt(ve); case EXIT_REASON_MSR_READ: - return read_msr(regs, ve); + return tdx_read_msr(regs, ve); case EXIT_REASON_MSR_WRITE: - return write_msr(regs, ve); + return tdx_write_msr(regs, ve); case EXIT_REASON_CPUID: return handle_cpuid(regs, ve); case EXIT_REASON_EPT_VIOLATION: --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 7A65E2BCF4A for ; Tue, 30 Sep 2025 07:04:19 +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=1759215861; cv=none; b=IZcZJ8GwFVwtpscQyIdBOWPDZ14lN/FBaro3xjNip1fr+9QR6e+xRQ2bTFViGn7xGOO3s3Gg5YjepgowoicLZ9nxQn3SUR2/ZP4veBj0B1b0JCfNJ3Fg+Zu6/Hlw2/6Xu0MhWc33sNgVWxLWNyNx+G38HJrO23FQnYt9DaV6cuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215861; c=relaxed/simple; bh=MHd1JuhTVp0OuwvZ62GFJ8TuQiFrgCoaZIGEbFjBZxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XX+zRBt9x9S38u5HZdEtLVCbXSVOSZrQ/eNn2R2Y19Bw+HFoAJlFtElIblyyLqY6eEPQtf1m4JuAg3jUI018IpnwT1/vdbv17M2rIU9P/kbYa42A2G/S86HDZFVe4QxXywEQ8NoeieFkecjz/1I7GIgywhG/01AqfU5DiDX++P4= 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=nr6af/P5; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=nr6af/P5; 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="nr6af/P5"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="nr6af/P5" 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 2B30933718; Tue, 30 Sep 2025 07:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215852; 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=Z7XgKJp81XAKQzsO5evcierbcHSvXy59F4lgNI3RTk0=; b=nr6af/P5B55nJh/5xfAByKIhn0AzZerLl8x8jgsbqyxWMjvNvMuDbprk7g2dLDhxqMKtYW bB8bUbuBB1aafKqttTuzLaMZEIMxVvQ8YS+5CP/YOmC+WE3JCwC0dMwWgDUimLLfHMgPVx 0G+pCkyaJUdEmRbYx5HdLgYOfPG5vZY= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215852; 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=Z7XgKJp81XAKQzsO5evcierbcHSvXy59F4lgNI3RTk0=; b=nr6af/P5B55nJh/5xfAByKIhn0AzZerLl8x8jgsbqyxWMjvNvMuDbprk7g2dLDhxqMKtYW bB8bUbuBB1aafKqttTuzLaMZEIMxVvQ8YS+5CP/YOmC+WE3JCwC0dMwWgDUimLLfHMgPVx 0G+pCkyaJUdEmRbYx5HdLgYOfPG5vZY= 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 D82D313A3F; Tue, 30 Sep 2025 07:04:11 +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 nepoM+uA22iHRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:11 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: xin@zytor.com, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 02/12] x86/sev: Replace call of native_wrmsr() with native_wrmsrq() Date: Tue, 30 Sep 2025 09:03:46 +0200 Message-ID: <20250930070356.30695-3-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:mid,imap1.dmz-prg2.suse.org:helo]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -2.80 Content-Type: text/plain; charset="utf-8" In sev_es_wr_ghcb_msr() the 64 bit MSR value is split into 2 32 bit values in order to call native_wrmsr(), which will combine the values into a 64 bit value again. Just use native_wrmsrq() instead. Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) Reviewed-by: Nikunj A Dadhania --- V2: - new patch --- arch/x86/include/asm/sev-internal.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/x86/include/asm/sev-internal.h b/arch/x86/include/asm/sev= -internal.h index 3dfd306d1c9e..f5d6fb3b5916 100644 --- a/arch/x86/include/asm/sev-internal.h +++ b/arch/x86/include/asm/sev-internal.h @@ -89,12 +89,7 @@ static inline u64 sev_es_rd_ghcb_msr(void) =20 static __always_inline void sev_es_wr_ghcb_msr(u64 val) { - u32 low, high; - - low =3D (u32)(val); - high =3D (u32)(val >> 32); - - native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low, high); + native_wrmsrq(MSR_AMD64_SEV_ES_GHCB, val); } =20 void snp_register_ghcb_early(unsigned long paddr); --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 7F710222587 for ; Tue, 30 Sep 2025 07:04:25 +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=1759215867; cv=none; b=Pv8UTGtuD7zkQU5mAUbKyIM3W/mrzJScxviqeWO7gbhbZxmssiG1uC4PlxKOQnnpfFX06gX3OQGtbjs6RGCHsV/F1hiTu8k8UnYNY7bA+5sFxNa1oV8QOTRe3/s7qWS5jWHvLKbZVaG9fhnronLMX4Rc/7AQNvRjxmSr/+xbg58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215867; c=relaxed/simple; bh=3vHsnR/o5asb5SnnHb/R17GZ2vgaoCxPRAPJMkAHAMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pNGdIpWgZu8uny13aeFWthSnVrIoTtHpPFvLOwV6IdVRGcwlDYQ/JETzujCP5UOMz5w49Vem30lj1Oo46JA4lQI/lfeVvfXGACQ7mbsMdnbd1jupDjU1SRIHcBTjDiYFhZJ0LoGFKc8IiaQWENjo5hX1uMZW7iczodlH66V+Ly8= 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=udZD/qBx; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=udZD/qBx; 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="udZD/qBx"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="udZD/qBx" 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 03217336FF; Tue, 30 Sep 2025 07:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215858; 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=/dyoxqlvmHpNQVL6a03vU/ea7RhvB/xZzRJIaBbmmRM=; b=udZD/qBxL/btw9GcCnfcUZONgAQB6c2RRR0WnPfMAbEgaAX80wQl7ja0JF0RBIF4SCEYFI kQIApESthheWJFHgLn2K0y8A+OW6rjSjky01hDCpkx4ZkSkpEIFRdL3PcZ0ZWtxja19hBZ DE9hVqtpdLYbp8T3OoVq6TuA4KxM1tw= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215858; 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=/dyoxqlvmHpNQVL6a03vU/ea7RhvB/xZzRJIaBbmmRM=; b=udZD/qBxL/btw9GcCnfcUZONgAQB6c2RRR0WnPfMAbEgaAX80wQl7ja0JF0RBIF4SCEYFI kQIApESthheWJFHgLn2K0y8A+OW6rjSjky01hDCpkx4ZkSkpEIFRdL3PcZ0ZWtxja19hBZ DE9hVqtpdLYbp8T3OoVq6TuA4KxM1tw= 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 982C713A3F; Tue, 30 Sep 2025 07:04:17 +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 jYV9I/GA22iPRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:17 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org Cc: xin@zytor.com, Juergen Gross , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 03/12] x86/kvm: Remove the KVM private read_msr() function Date: Tue, 30 Sep 2025 09:03:47 +0200 Message-ID: <20250930070356.30695-4-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWELVE(0.00)[12]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.com:mid,suse.com:email]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: X-Spam-Score: -2.80 Content-Type: text/plain; charset="utf-8" Instead of having a KVM private read_msr() function, just use rdmsrq(). Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- V2: - remove the helper and use rdmsrq() directly (Sean Christopherson) --- arch/x86/include/asm/kvm_host.h | 10 ---------- arch/x86/kvm/vmx/vmx.c | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index f19a76d3ca0e..aed754dda1a3 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2296,16 +2296,6 @@ static inline void kvm_load_ldt(u16 sel) asm("lldt %0" : : "rm"(sel)); } =20 -#ifdef CONFIG_X86_64 -static inline unsigned long read_msr(unsigned long msr) -{ - u64 value; - - rdmsrq(msr, value); - return value; -} -#endif - static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code) { kvm_queue_exception_e(vcpu, GP_VECTOR, error_code); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index aa157fe5b7b3..12bb1769e3ae 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1288,8 +1288,8 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcp= u) } else { savesegment(fs, fs_sel); savesegment(gs, gs_sel); - fs_base =3D read_msr(MSR_FS_BASE); - vt->msr_host_kernel_gs_base =3D read_msr(MSR_KERNEL_GS_BASE); + rdmsrq(MSR_FS_BASE, fs_base); + rdmsrq(MSR_KERNEL_GS_BASE, vt->msr_host_kernel_gs_base); } =20 wrmsrq(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1759215885; cv=none; d=zohomail.com; s=zohoarc; b=APhywxJi761NEE4308TWzM4a095j53TUo2uAlPeTk2H+oTj30etruKGzSSpR/KO5BXwRGuiV9+AoSVEsGSHIDGTH8uaDdj2v00rDvHvcSLlKYy+ekIJts+6eDqgKF8otGIgqeLeXAhAiX+Y8KiviRacgbNByRrObC/zPro5d7SI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759215885; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Gb/490BwBT2pJb8VyiYCDqR7oVEXLp6PItp8lOXpG+8=; b=kPP89QrAvSzZnHel7MiWdCbPan6a8+L+Nl1oJ3HK3IGrEELp4dvcpRwV3WtJE3ibAvYFip53fdlfJuoqa3Ne7VG3Zsg3xkVjALVkSvSu9NSLBE9X0yG1ayIo/RxFJU0OCEKiDE0MdpG49msW8SlXYylg4HuD9bxRqkDUdJUND+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1759215885402940.4157491020535; Tue, 30 Sep 2025 00:04:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1133729.1471797 (Exim 4.92) (envelope-from ) id 1v3UPW-0008WL-Dt; Tue, 30 Sep 2025 07:04:30 +0000 Received: by outflank-mailman (output) from mailman id 1133729.1471797; Tue, 30 Sep 2025 07:04:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3UPW-0008WE-Aw; Tue, 30 Sep 2025 07:04:30 +0000 Received: by outflank-mailman (input) for mailman id 1133729; Tue, 30 Sep 2025 07:04:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3UPV-0008Ue-0d for xen-devel@lists.xenproject.org; Tue, 30 Sep 2025 07:04:29 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b35477d6-9dcb-11f0-9809-7dc792cee155; Tue, 30 Sep 2025 09:04:26 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 1F3561F7F0; Tue, 30 Sep 2025 07:04:24 +0000 (UTC) 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 724E513A3F; Tue, 30 Sep 2025 07:04:23 +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 PKpCGveA22iWRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b35477d6-9dcb-11f0-9809-7dc792cee155 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215864; 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=Gb/490BwBT2pJb8VyiYCDqR7oVEXLp6PItp8lOXpG+8=; b=cLHyrL958OTnlFYNDsyhvs5Jx8YJsVXY3jgWesU9DwMy3sVcFdlCJ6ofnheGWYTCoTixda XBUj2VZxq9APW9dl7AuCDkHiLj3C8xTaZ/QlrTEdbQkGzHMAjdnP1F3UOSoDrfCLpbglhW 660NgLMHkoojRmT5xYEh5UQk2nCGC1w= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=cLHyrL95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215864; 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=Gb/490BwBT2pJb8VyiYCDqR7oVEXLp6PItp8lOXpG+8=; b=cLHyrL958OTnlFYNDsyhvs5Jx8YJsVXY3jgWesU9DwMy3sVcFdlCJ6ofnheGWYTCoTixda XBUj2VZxq9APW9dl7AuCDkHiLj3C8xTaZ/QlrTEdbQkGzHMAjdnP1F3UOSoDrfCLpbglhW 660NgLMHkoojRmT5xYEh5UQk2nCGC1w= From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hyperv@vger.kernel.org, kvm@vger.kernel.org Cc: xin@zytor.com, Juergen Gross , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Sean Christopherson , Boris Ostrovsky , xen-devel@lists.xenproject.org Subject: [PATCH v2 04/12] x86/msr: Minimize usage of native_*() msr access functions Date: Tue, 30 Sep 2025 09:03:48 +0200 Message-ID: <20250930070356.30695-5-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[20]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_EQ_ENVFROM(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLkdkdrsxe9hqhhs5ask8616i6)]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:dkim,suse.com:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns] X-Spam-Flag: NO X-Spam-Level: X-Rspamd-Queue-Id: 1F3561F7F0 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1759215887238116600 Content-Type: text/plain; charset="utf-8" In order to prepare for some MSR access function reorg work, switch most users of native_{read|write}_msr[_safe]() to the more generic rdmsr*()/wrmsr*() variants. For now this will have some intermediate performance impact with paravirtualization configured when running on bare metal, but this is a prereq change for the planned direct inlining of the rdmsr/wrmsr instructions with this configuration. The main reason for this switch is the planned move of the MSR trace function invocation from the native_*() functions to the generic rdmsr*()/wrmsr*() variants. Without this switch the users of the native_*() functions would lose the related tracing entries. Note that the Xen related MSR access functions will not be switched, as these will be handled after the move of the trace hooks. Signed-off-by: Juergen Gross Acked-by: Sean Christopherson Acked-by: Wei Liu Reviewed-by: H. Peter Anvin (Intel) --- arch/x86/hyperv/ivm.c | 2 +- arch/x86/kernel/kvmclock.c | 2 +- arch/x86/kvm/svm/svm.c | 16 ++++++++-------- arch/x86/xen/pmu.c | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index ade6c665c97e..202ed01dc151 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -327,7 +327,7 @@ int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip,= unsigned int cpu) asm volatile("movl %%ds, %%eax;" : "=3Da" (vmsa->ds.selector)); hv_populate_vmcb_seg(vmsa->ds, vmsa->gdtr.base); =20 - vmsa->efer =3D native_read_msr(MSR_EFER); + rdmsrq(MSR_EFER, vmsa->efer); =20 vmsa->cr4 =3D native_read_cr4(); vmsa->cr3 =3D __native_read_cr3(); diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index ca0a49eeac4a..b6cd45cce5fe 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -196,7 +196,7 @@ static void kvm_setup_secondary_clock(void) void kvmclock_disable(void) { if (msr_kvm_system_time) - native_write_msr(msr_kvm_system_time, 0); + wrmsrq(msr_kvm_system_time, 0); } =20 static void __init kvmclock_init_mem(void) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 1bfebe40854f..105d5c2aae46 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -393,12 +393,12 @@ static void svm_init_erratum_383(void) return; =20 /* Use _safe variants to not break nested virtualization */ - if (native_read_msr_safe(MSR_AMD64_DC_CFG, &val)) + if (rdmsrq_safe(MSR_AMD64_DC_CFG, &val)) return; =20 val |=3D (1ULL << 47); =20 - native_write_msr_safe(MSR_AMD64_DC_CFG, val); + wrmsrq_safe(MSR_AMD64_DC_CFG, val); =20 erratum_383_found =3D true; } @@ -558,9 +558,9 @@ static int svm_enable_virtualization_cpu(void) u64 len, status =3D 0; int err; =20 - err =3D native_read_msr_safe(MSR_AMD64_OSVW_ID_LENGTH, &len); + err =3D rdmsrq_safe(MSR_AMD64_OSVW_ID_LENGTH, &len); if (!err) - err =3D native_read_msr_safe(MSR_AMD64_OSVW_STATUS, &status); + err =3D rdmsrq_safe(MSR_AMD64_OSVW_STATUS, &status); =20 if (err) osvw_status =3D osvw_len =3D 0; @@ -2032,7 +2032,7 @@ static bool is_erratum_383(void) if (!erratum_383_found) return false; =20 - if (native_read_msr_safe(MSR_IA32_MC0_STATUS, &value)) + if (rdmsrq_safe(MSR_IA32_MC0_STATUS, &value)) return false; =20 /* Bit 62 may or may not be set for this mce */ @@ -2043,11 +2043,11 @@ static bool is_erratum_383(void) =20 /* Clear MCi_STATUS registers */ for (i =3D 0; i < 6; ++i) - native_write_msr_safe(MSR_IA32_MCx_STATUS(i), 0); + wrmsrq_safe(MSR_IA32_MCx_STATUS(i), 0); =20 - if (!native_read_msr_safe(MSR_IA32_MCG_STATUS, &value)) { + if (!rdmsrq_safe(MSR_IA32_MCG_STATUS, &value)) { value &=3D ~(1ULL << 2); - native_write_msr_safe(MSR_IA32_MCG_STATUS, value); + wrmsrq_safe(MSR_IA32_MCG_STATUS, value); } =20 /* Flush tlb to evict multi-match entries */ diff --git a/arch/x86/xen/pmu.c b/arch/x86/xen/pmu.c index 8f89ce0b67e3..d49a3bdc448b 100644 --- a/arch/x86/xen/pmu.c +++ b/arch/x86/xen/pmu.c @@ -323,7 +323,7 @@ static u64 xen_amd_read_pmc(int counter) u64 val; =20 msr =3D amd_counters_base + (counter * amd_msr_step); - native_read_msr_safe(msr, &val); + rdmsrq_safe(msr, &val); return val; } =20 @@ -349,7 +349,7 @@ static u64 xen_intel_read_pmc(int counter) else msr =3D MSR_IA32_PERFCTR0 + counter; =20 - native_read_msr_safe(msr, &val); + rdmsrq_safe(msr, &val); return val; } =20 --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 9F0092C029C for ; Tue, 30 Sep 2025 07:04:31 +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=1759215873; cv=none; b=ZN8/anbAaLNVljKtxyxGZOq8vNM7HUNJyaTiXTBS29BG8doEs/YHcIt/xnfxASrQtJpyveVarCt/oILRKXIxkxf79ymfrG10CpBl86/LDtgsycbDDLTs7bYh9/BwvAo7UyIS9pzNZU7DVZJXQLdHF1OHEPo4m2Jb89VwD69oWjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215873; c=relaxed/simple; bh=3rfCjpKNLXLR1fAnsIdKw81xvKIE9jB92NxHSILJRwk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D70aPJ5A576EAU5pMBkU3UtUv1YOqdKMBZR5fJoIerE3rlYCdnC7P+FoHMrEvn4oQ59n6hAd8hxn2C2JBON4IppevXc1T+CTw0VmIVwSoT59GulN9AiykjygGtwKcfa5yopgjKH4WrALWYSZQwUnSDBNvCSHx01j1doQlqR0cb0= 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=pVRRp5vh; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=NjLRkJtu; 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="pVRRp5vh"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="NjLRkJtu" 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 EB61A3373A; Tue, 30 Sep 2025 07:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215870; 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=U1QZwRe3sp3J8ayY3qoOpOJqCfrtlDYSiFDC99SlKAQ=; b=pVRRp5vh7aTv4ofNW/sJITC5BDkWOl0rN2K3GlALiU/T9xvOwjY4Iwr4zZT0Tqqzxm0vea apKGkzb1PdwkZlvpAcHD6T132H8g4ITVyiKk1mRKnEcROxw+86rlqW+SGDmEcPYK4/Ywyt 5Owimj75qoSgAXOs0myPmv94XcEXeg8= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215869; 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=U1QZwRe3sp3J8ayY3qoOpOJqCfrtlDYSiFDC99SlKAQ=; b=NjLRkJtu6Y7jofe9TBMkbJQ1rPmmOO+0kkMqtSOWBb2j/7J6Gh2w9cTRIooXJkCoEszL4K rhG/8iBH++JI1H1Ys8k1c6TKNBqazBNAGteq399YL7Q69EMZKDhm9M12jlbRkvrEtz5gcA 8wV2dD9yF98JTGqCkLpRyn+OnDGS9u0= 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 89C6C13A3F; Tue, 30 Sep 2025 07:04:29 +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 V9QwIP2A22ihRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:29 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, virtualization@lists.linux.dev Cc: xin@zytor.com, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ajay Kaher , Alexey Makhalov , Broadcom internal kernel review list Subject: [PATCH v2 05/12] x86/msr: Move MSR trace calls one function level up Date: Tue, 30 Sep 2025 09:03:49 +0200 Message-ID: <20250930070356.30695-6-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; R_RATELIMIT(0.00)[to_ip_from(RLfdszjqhz8kzzb9uwpzdm8png)]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -2.80 Content-Type: text/plain; charset="utf-8" In order to prepare paravirt inlining of the MSR access instructions move the calls of MSR trace functions one function level up. Introduce {read|write}_msr[_safe]() helpers allowing to have common definitions in msr.h doing the trace calls. Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- arch/x86/include/asm/msr.h | 102 ++++++++++++++++++++------------ arch/x86/include/asm/paravirt.h | 38 +++--------- 2 files changed, 73 insertions(+), 67 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 9c2ea29e12a9..71f41af11591 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -103,14 +103,7 @@ static __always_inline u64 native_rdmsrq(u32 msr) =20 static inline u64 native_read_msr(u32 msr) { - u64 val; - - val =3D __rdmsr(msr); - - if (tracepoint_enabled(read_msr)) - do_trace_read_msr(msr, val, 0); - - return val; + return __rdmsr(msr); } =20 static inline int native_read_msr_safe(u32 msr, u64 *p) @@ -123,8 +116,6 @@ static inline int native_read_msr_safe(u32 msr, u64 *p) _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_RDMSR_SAFE, %[err]) : [err] "=3Dr" (err), EAX_EDX_RET(val, low, high) : "c" (msr)); - if (tracepoint_enabled(read_msr)) - do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), err); =20 *p =3D EAX_EDX_VAL(val, low, high); =20 @@ -135,9 +126,6 @@ static inline int native_read_msr_safe(u32 msr, u64 *p) static inline void notrace native_write_msr(u32 msr, u64 val) { native_wrmsrq(msr, val); - - if (tracepoint_enabled(write_msr)) - do_trace_write_msr(msr, val, 0); } =20 /* Can be uninlined because referenced by paravirt */ @@ -151,8 +139,6 @@ static inline int notrace native_write_msr_safe(u32 msr= , u64 val) : [err] "=3Da" (err) : "c" (msr), "0" ((u32)val), "d" ((u32)(val >> 32)) : "memory"); - if (tracepoint_enabled(write_msr)) - do_trace_write_msr(msr, val, err); return err; } =20 @@ -173,59 +159,96 @@ static inline u64 native_read_pmc(int counter) #include #else #include +static __always_inline u64 read_msr(u32 msr) +{ + return native_read_msr(msr); +} + +static __always_inline int read_msr_safe(u32 msr, u64 *p) +{ + return native_read_msr_safe(msr, p); +} + +static __always_inline void write_msr(u32 msr, u64 val) +{ + native_write_msr(msr, val); +} + +static __always_inline int write_msr_safe(u32 msr, u64 val) +{ + return native_write_msr_safe(msr, val); +} + +static __always_inline u64 rdpmc(int counter) +{ + return native_read_pmc(counter); +} + +#endif /* !CONFIG_PARAVIRT_XXL */ + /* * Access to machine-specific registers (available on 586 and better only) * Note: the rd* operations modify the parameters directly (without using * pointer indirection), this allows gcc to optimize better */ =20 +#define rdmsrq(msr, val) \ +do { \ + (val) =3D read_msr(msr); \ + if (tracepoint_enabled(read_msr)) \ + do_trace_read_msr(msr, val, 0); \ +} while (0) + #define rdmsr(msr, low, high) \ do { \ - u64 __val =3D native_read_msr((msr)); \ + u64 __val; \ + rdmsrq(msr, __val); \ (void)((low) =3D (u32)__val); \ (void)((high) =3D (u32)(__val >> 32)); \ } while (0) =20 -static inline void wrmsr(u32 msr, u32 low, u32 high) +/* rdmsr with exception handling */ +static inline int rdmsrq_safe(u32 msr, u64 *p) { - native_write_msr(msr, (u64)high << 32 | low); -} + int err; =20 -#define rdmsrq(msr, val) \ - ((val) =3D native_read_msr((msr))) + err =3D read_msr_safe(msr, p); =20 -static inline void wrmsrq(u32 msr, u64 val) -{ - native_write_msr(msr, val); -} + if (tracepoint_enabled(read_msr)) + do_trace_read_msr(msr, *p, err); =20 -/* wrmsr with exception handling */ -static inline int wrmsrq_safe(u32 msr, u64 val) -{ - return native_write_msr_safe(msr, val); + return err; } =20 -/* rdmsr with exception handling */ #define rdmsr_safe(msr, low, high) \ ({ \ u64 __val; \ - int __err =3D native_read_msr_safe((msr), &__val); \ + int __err =3D rdmsrq_safe((msr), &__val); \ (*low) =3D (u32)__val; \ (*high) =3D (u32)(__val >> 32); \ __err; \ }) =20 -static inline int rdmsrq_safe(u32 msr, u64 *p) +static inline void wrmsrq(u32 msr, u64 val) { - return native_read_msr_safe(msr, p); + write_msr(msr, val); + + if (tracepoint_enabled(write_msr)) + do_trace_write_msr(msr, val, 0); } =20 -static __always_inline u64 rdpmc(int counter) +/* wrmsr with exception handling */ +static inline int wrmsrq_safe(u32 msr, u64 val) { - return native_read_pmc(counter); -} + int err; =20 -#endif /* !CONFIG_PARAVIRT_XXL */ + err =3D write_msr_safe(msr, val); + + if (tracepoint_enabled(write_msr)) + do_trace_write_msr(msr, val, err); + + return err; +} =20 /* Instruction opcode for WRMSRNS supported in binutils >=3D 2.40 */ #define ASM_WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6) @@ -242,6 +265,11 @@ static __always_inline void wrmsrns(u32 msr, u64 val) : : "c" (msr), "a" ((u32)val), "d" ((u32)(val >> 32))); } =20 +static inline void wrmsr(u32 msr, u32 low, u32 high) +{ + wrmsrq(msr, (u64)high << 32 | low); +} + /* * Dual u32 version of wrmsrq_safe(): */ diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravir= t.h index b5e59a7ba0d0..dc297f62b935 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -195,46 +195,24 @@ static inline int paravirt_write_msr_safe(u32 msr, u6= 4 val) return PVOP_CALL2(int, cpu.write_msr_safe, msr, val); } =20 -#define rdmsr(msr, val1, val2) \ -do { \ - u64 _l =3D paravirt_read_msr(msr); \ - val1 =3D (u32)_l; \ - val2 =3D _l >> 32; \ -} while (0) - -static __always_inline void wrmsr(u32 msr, u32 low, u32 high) +static __always_inline u64 read_msr(u32 msr) { - paravirt_write_msr(msr, (u64)high << 32 | low); + return paravirt_read_msr(msr); } =20 -#define rdmsrq(msr, val) \ -do { \ - val =3D paravirt_read_msr(msr); \ -} while (0) - -static inline void wrmsrq(u32 msr, u64 val) +static __always_inline int read_msr_safe(u32 msr, u64 *p) { - paravirt_write_msr(msr, val); + return paravirt_read_msr_safe(msr, p); } =20 -static inline int wrmsrq_safe(u32 msr, u64 val) +static __always_inline void write_msr(u32 msr, u64 val) { - return paravirt_write_msr_safe(msr, val); + paravirt_write_msr(msr, val); } =20 -/* rdmsr with exception handling */ -#define rdmsr_safe(msr, a, b) \ -({ \ - u64 _l; \ - int _err =3D paravirt_read_msr_safe((msr), &_l); \ - (*a) =3D (u32)_l; \ - (*b) =3D (u32)(_l >> 32); \ - _err; \ -}) - -static __always_inline int rdmsrq_safe(u32 msr, u64 *p) +static __always_inline int write_msr_safe(u32 msr, u64 val) { - return paravirt_read_msr_safe(msr, p); + return paravirt_write_msr_safe(msr, val); } =20 static __always_inline u64 rdpmc(int counter) --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 EA59E2C08C5 for ; Tue, 30 Sep 2025 07:04:37 +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=1759215879; cv=none; b=YD1uuCKHzM80Z0CNAfHOLm44hf/cF2OxoK9dw8P3J5Uizv5xNyHzwAjdIDLHi7ruO3roimjoef4gz9tZMMkNt1PZobpeB/nL/JyFfcjE84VbQ6XT3ggHSJYjHyNvV5wFqX7+S3RX/IfNwmlIkfGl9V8kqJV3LBgbt9wHAMi1thw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215879; c=relaxed/simple; bh=Xt2rNIPFxWsNjhnA5spmpWQgH5RkMGTp08KBW9qkXk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SE8pKb7JZGV2c4I5GmHthzJ1wHMzREPvtIt3OU3Gvy2rFhs2KaArQuYnnz58lS4dXA5CEHjMImJgdSL/IsjLW23hTmKMTWe9K9XuzYKdNTQaHA2ZpRPp4wgQFEfCB2nb1S+efIzP8SXxpBJ3FrdSU7ksmL3zxm8Tdqox6UYMxYs= 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=VV9+OiBb; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=VV9+OiBb; 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="VV9+OiBb"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="VV9+OiBb" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 A87051F747; Tue, 30 Sep 2025 07:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215875; 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=As7bm7YqdqSa5NE/1ECIapsnF2GvZiWEUr8Xc8BQ+pA=; b=VV9+OiBbW/OM3JJPKoCPGuHUJuxEiARMD46EIJDe7E96lv4X442mJjfGgEGfRjYbaOIda1 6sPM3duGZhCMmlGFr7KFNLQe+v6d18idJhIq6xGOLkFMsUqTcT0wuWWs9l7Yq4KhfrX23S 4SV1xYlEzRfWCzBVl1lYtsORfQhRFCY= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=VV9+OiBb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215875; 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=As7bm7YqdqSa5NE/1ECIapsnF2GvZiWEUr8Xc8BQ+pA=; b=VV9+OiBbW/OM3JJPKoCPGuHUJuxEiARMD46EIJDe7E96lv4X442mJjfGgEGfRjYbaOIda1 6sPM3duGZhCMmlGFr7KFNLQe+v6d18idJhIq6xGOLkFMsUqTcT0wuWWs9l7Yq4KhfrX23S 4SV1xYlEzRfWCzBVl1lYtsORfQhRFCY= 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 5F74113A3F; Tue, 30 Sep 2025 07:04:35 +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 5AW2FQOB22iwRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:35 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: xin@zytor.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Juergen Gross Subject: [PATCH v2 06/12] x86/cpufeatures: Add a CPU feature bit for MSR immediate form instructions Date: Tue, 30 Sep 2025 09:03:50 +0200 Message-ID: <20250930070356.30695-7-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spam-Level: X-Spam-Flag: NO X-Rspamd-Queue-Id: A87051F747 X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; R_RATELIMIT(0.00)[to_ip_from(RLkdkdrsxe9hqhhs5ask8616i6)]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -3.01 Content-Type: text/plain; charset="utf-8" From: "Xin Li (Intel)" The immediate form of MSR access instructions are primarily motivated by performance, not code size: by having the MSR number in an immediate, it is available *much* earlier in the pipeline, which allows the hardware much more leeway about how a particular MSR is handled. Use a scattered CPU feature bit for MSR immediate form instructions. Suggested-by: Borislav Petkov (AMD) Signed-off-by: Xin Li (Intel) Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- V2: - new patch, taken from the RFC v2 MSR refactor series by Xin Li --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 751ca35386b0..625635767085 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -496,6 +496,7 @@ #define X86_FEATURE_TSA_L1_NO (21*32+12) /* AMD CPU not vulnerable to TSA= -L1 */ #define X86_FEATURE_CLEAR_CPU_BUF_VM (21*32+13) /* Clear CPU buffers using= VERW before VMRUN */ #define X86_FEATURE_IBPB_EXIT_TO_USER (21*32+14) /* Use IBPB on exit-to-us= erspace, see VMSCAPE bug */ +#define X86_FEATURE_MSR_IMM (21*32+15) /* MSR immediate form instructions= */ =20 /* * BUG word(s) diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattere= d.c index 6b868afb26c3..cf4ae822bcc0 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -27,6 +27,7 @@ static const struct cpuid_bit cpuid_bits[] =3D { { X86_FEATURE_APERFMPERF, CPUID_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CPUID_ECX, 3, 0x00000006, 0 }, { X86_FEATURE_INTEL_PPIN, CPUID_EBX, 0, 0x00000007, 1 }, + { X86_FEATURE_MSR_IMM, CPUID_ECX, 5, 0x00000007, 1 }, { X86_FEATURE_APX, CPUID_EDX, 21, 0x00000007, 1 }, { X86_FEATURE_RRSBA_CTRL, CPUID_EDX, 2, 0x00000007, 2 }, { X86_FEATURE_BHI_CTRL, CPUID_EDX, 4, 0x00000007, 2 }, --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 A1D4B2BE037 for ; Tue, 30 Sep 2025 07:04:43 +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=1759215885; cv=none; b=C2jLrToCq7biAhCGBjPYS0qCXf6fWVe713AW6EGG8Y2iewQ46GFhwOPatyzG1ybqwktzZoG4q2UwB6dJ/fpllkYk/6vuVmLKR+sgPYz8gOCflJbWtBW2puZHBRefgmZY4yRHT7TzLHXI+rnkwJuNdTBeQpwqHxQ9RDrqH/hSgew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215885; c=relaxed/simple; bh=DURkwRke2cx9nsvZCjdaKHO//XZ8sDlKFa/gLDLWIwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k4hijDYIkjYL4Dd87AAq4oDFV+8Mv0tLpK6eVzCZSgJ8bS/QzRRY9pp9cszf2BlVyo1O3KVxEwMvm/Vj541l1U2BUl7s9t7WagFaD3DR/FxsjU/PjazZlwVxqVTCLuOKwk8e4uUigghFRmpvBj2YC8ByD3w+dlzWcQOR1stKghg= 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=e24a7szX; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=e24a7szX; 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="e24a7szX"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="e24a7szX" 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 7AEC11F449; Tue, 30 Sep 2025 07:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215881; 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=54W/P7dmPqvd6kdIyWRFWs72NWtxPZWW/Zs0TK1TxK4=; b=e24a7szXrQZrO7uLgKABySpfC0o/tYBudz39agRCJCF4vlvEnLXyiHhyTJuN56cKWCJbBA bj4kYfxAJxzMZjPKYD/SxC/6ER+O4DFCpcWiAtEy0t7wjYuOkcad/WgVBpgVfLFYOiAGKr jOkx1nK3Z/cn4ZtZK1r/wK7Trn85cBI= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215881; 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=54W/P7dmPqvd6kdIyWRFWs72NWtxPZWW/Zs0TK1TxK4=; b=e24a7szXrQZrO7uLgKABySpfC0o/tYBudz39agRCJCF4vlvEnLXyiHhyTJuN56cKWCJbBA bj4kYfxAJxzMZjPKYD/SxC/6ER+O4DFCpcWiAtEy0t7wjYuOkcad/WgVBpgVfLFYOiAGKr jOkx1nK3Z/cn4ZtZK1r/wK7Trn85cBI= 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 20ABD13A3F; Tue, 30 Sep 2025 07:04:41 +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 vF9dBgmB22i3RwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:41 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: xin@zytor.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Juergen Gross Subject: [PATCH v2 07/12] x86/opcode: Add immediate form MSR instructions Date: Tue, 30 Sep 2025 09:03:51 +0200 Message-ID: <20250930070356.30695-8-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; R_RATELIMIT(0.00)[to_ip_from(RLfdszjqhz8kzzb9uwpzdm8png)]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: X-Spam-Score: -2.80 Content-Type: text/plain; charset="utf-8" From: "Xin Li (Intel)" Add the instruction opcodes used by the immediate form WRMSRNS/RDMSR to x86-opcode-map. Signed-off-by: Xin Li (Intel) Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- V2: - new patch, taken from the RFC v2 MSR refactor series by Xin Li --- arch/x86/lib/x86-opcode-map.txt | 5 +++-- tools/arch/x86/lib/x86-opcode-map.txt | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/lib/x86-opcode-map.txt b/arch/x86/lib/x86-opcode-map.= txt index 262f7ca1fb95..65aeb18ad22d 100644 --- a/arch/x86/lib/x86-opcode-map.txt +++ b/arch/x86/lib/x86-opcode-map.txt @@ -839,7 +839,7 @@ f1: MOVBE My,Gy | MOVBE Mw,Gw (66) | CRC32 Gd,Ey (F2) |= CRC32 Gd,Ew (66&F2) f2: ANDN Gy,By,Ey (v) f3: Grp17 (1A) f5: BZHI Gy,Ey,By (v) | PEXT Gy,By,Ey (F3),(v) | PDEP Gy,By,Ey (F2),(v) | = WRUSSD/Q My,Gy (66) -f6: ADCX Gy,Ey (66) | ADOX Gy,Ey (F3) | MULX By,Gy,rDX,Ey (F2),(v) | WRSSD= /Q My,Gy +f6: ADCX Gy,Ey (66) | ADOX Gy,Ey (F3) | MULX By,Gy,rDX,Ey (F2),(v) | WRSSD= /Q My,Gy | RDMSR Rq,Gq (F2),(11B) | WRMSRNS Gq,Rq (F3),(11B) f7: BEXTR Gy,Ey,By (v) | SHLX Gy,Ey,By (66),(v) | SARX Gy,Ey,By (F3),(v) |= SHRX Gy,Ey,By (F2),(v) f8: MOVDIR64B Gv,Mdqq (66) | ENQCMD Gv,Mdqq (F2) | ENQCMDS Gv,Mdqq (F3) | = URDMSR Rq,Gq (F2),(11B) | UWRMSR Gq,Rq (F3),(11B) f9: MOVDIRI My,Gy @@ -1014,7 +1014,7 @@ f1: CRC32 Gy,Ey (es) | CRC32 Gy,Ey (66),(es) | INVVPI= D Gy,Mdq (F3),(ev) f2: INVPCID Gy,Mdq (F3),(ev) f4: TZCNT Gv,Ev (es) | TZCNT Gv,Ev (66),(es) f5: LZCNT Gv,Ev (es) | LZCNT Gv,Ev (66),(es) -f6: Grp3_1 Eb (1A),(ev) +f6: Grp3_1 Eb (1A),(ev) | RDMSR Rq,Gq (F2),(11B),(ev) | WRMSRNS Gq,Rq (F3)= ,(11B),(ev) f7: Grp3_2 Ev (1A),(es) f8: MOVDIR64B Gv,Mdqq (66),(ev) | ENQCMD Gv,Mdqq (F2),(ev) | ENQCMDS Gv,Md= qq (F3),(ev) | URDMSR Rq,Gq (F2),(11B),(ev) | UWRMSR Gq,Rq (F3),(11B),(ev) f9: MOVDIRI My,Gy (ev) @@ -1103,6 +1103,7 @@ EndTable Table: VEX map 7 Referrer: AVXcode: 7 +f6: RDMSR Rq,Id (F2),(v1),(11B) | WRMSRNS Id,Rq (F3),(v1),(11B) f8: URDMSR Rq,Id (F2),(v1),(11B) | UWRMSR Id,Rq (F3),(v1),(11B) EndTable =20 diff --git a/tools/arch/x86/lib/x86-opcode-map.txt b/tools/arch/x86/lib/x86= -opcode-map.txt index 262f7ca1fb95..65aeb18ad22d 100644 --- a/tools/arch/x86/lib/x86-opcode-map.txt +++ b/tools/arch/x86/lib/x86-opcode-map.txt @@ -839,7 +839,7 @@ f1: MOVBE My,Gy | MOVBE Mw,Gw (66) | CRC32 Gd,Ey (F2) |= CRC32 Gd,Ew (66&F2) f2: ANDN Gy,By,Ey (v) f3: Grp17 (1A) f5: BZHI Gy,Ey,By (v) | PEXT Gy,By,Ey (F3),(v) | PDEP Gy,By,Ey (F2),(v) | = WRUSSD/Q My,Gy (66) -f6: ADCX Gy,Ey (66) | ADOX Gy,Ey (F3) | MULX By,Gy,rDX,Ey (F2),(v) | WRSSD= /Q My,Gy +f6: ADCX Gy,Ey (66) | ADOX Gy,Ey (F3) | MULX By,Gy,rDX,Ey (F2),(v) | WRSSD= /Q My,Gy | RDMSR Rq,Gq (F2),(11B) | WRMSRNS Gq,Rq (F3),(11B) f7: BEXTR Gy,Ey,By (v) | SHLX Gy,Ey,By (66),(v) | SARX Gy,Ey,By (F3),(v) |= SHRX Gy,Ey,By (F2),(v) f8: MOVDIR64B Gv,Mdqq (66) | ENQCMD Gv,Mdqq (F2) | ENQCMDS Gv,Mdqq (F3) | = URDMSR Rq,Gq (F2),(11B) | UWRMSR Gq,Rq (F3),(11B) f9: MOVDIRI My,Gy @@ -1014,7 +1014,7 @@ f1: CRC32 Gy,Ey (es) | CRC32 Gy,Ey (66),(es) | INVVPI= D Gy,Mdq (F3),(ev) f2: INVPCID Gy,Mdq (F3),(ev) f4: TZCNT Gv,Ev (es) | TZCNT Gv,Ev (66),(es) f5: LZCNT Gv,Ev (es) | LZCNT Gv,Ev (66),(es) -f6: Grp3_1 Eb (1A),(ev) +f6: Grp3_1 Eb (1A),(ev) | RDMSR Rq,Gq (F2),(11B),(ev) | WRMSRNS Gq,Rq (F3)= ,(11B),(ev) f7: Grp3_2 Ev (1A),(es) f8: MOVDIR64B Gv,Mdqq (66),(ev) | ENQCMD Gv,Mdqq (F2),(ev) | ENQCMDS Gv,Md= qq (F3),(ev) | URDMSR Rq,Gq (F2),(11B),(ev) | UWRMSR Gq,Rq (F3),(11B),(ev) f9: MOVDIRI My,Gy (ev) @@ -1103,6 +1103,7 @@ EndTable Table: VEX map 7 Referrer: AVXcode: 7 +f6: RDMSR Rq,Id (F2),(v1),(11B) | WRMSRNS Id,Rq (F3),(v1),(11B) f8: URDMSR Rq,Id (F2),(v1),(11B) | UWRMSR Id,Rq (F3),(v1),(11B) EndTable =20 --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 E05532BE620 for ; Tue, 30 Sep 2025 07:04:50 +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=1759215892; cv=none; b=g9jxas2WsKx0+uikD7U+mZJAG9C9v10rsioFjGtF0bQUGkEzo5yd6ldY4cpRYIrdNLkC0ACjM8J+T4R+kRQFOCKw7Pao5bGmsWFLKxPqs1L+PGnK40XCoPGyOCzKhE/i8Vx5J18N3XZoPXl6Swv9DVwwYeK37IADQ+VVGJ0DwhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215892; c=relaxed/simple; bh=2btrxefdF4Q1zNspVlgbxPl0NsoD/LlIuiuyOKZXiE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QmrZF6Qg+phCeeThoxLDB7019XKPbPwOPNlvALzt43yseowm8RBQI5GtMFVzMQB3E4cqrUl082tSmI5MKn+vfAhiCZ5VznxbHUSbxORkOz6EMF5Ve0LaQ85cRkGWL88mIUjTqrhrUxHY+ziagDaBhA+aiJYwRtjAAEZp/OWCuNw= 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=TdHByD1K; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=M9kVM9BV; 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="TdHByD1K"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="M9kVM9BV" 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 387941F7A1; Tue, 30 Sep 2025 07:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215888; 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=klTuaYwceM5pQDhHUjQjBczV/l6B7KGMatMdzB4iS/M=; b=TdHByD1Kv7M84qNdnMljJrwPkH6/M+T8wMWWadnKi/T+gqe/mgcltZr24PhxVQCn1+9HWA R9gK9OIwkbre4kYyGfKO77y2ymQQJtIyC9ch120v5F3PwKTrB+TAOzZOMcFgir5qEmtK9o Sad0qlvp9SypA1M1jj9WL2MTWFPLQkA= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215887; 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=klTuaYwceM5pQDhHUjQjBczV/l6B7KGMatMdzB4iS/M=; b=M9kVM9BVkIaStY5mG502QcigzjaN4gGBuFkmHrso3xn/Aoa5l+Xy5CHnoKI6I8/2xOp30y m1VjKLZs224Gn/Zu0foZqEW6xqaMHF5nvM3hiJj3xaYdCA8aD1C+kLrnh6YuFJ/NJhyGB2 Q++GNlB5Rze3ABUN8bK8sCuQOnrrPyw= 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 D910713A3F; Tue, 30 Sep 2025 07:04:46 +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 k2OCMw6B22i+RwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:46 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: xin@zytor.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Juergen Gross Subject: [PATCH v2 08/12] x86/extable: Add support for immediate form MSR instructions Date: Tue, 30 Sep 2025 09:03:52 +0200 Message-ID: <20250930070356.30695-9-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:mid,imap1.dmz-prg2.suse.org:helo]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; R_RATELIMIT(0.00)[to_ip_from(RLfdszjqhz8kzzb9uwpzdm8png)]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -2.80 Content-Type: text/plain; charset="utf-8" From: "Xin Li (Intel)" Signed-off-by: Xin Li (Intel) Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- V2: - new patch, taken from the RFC v2 MSR refactor series by Xin Li --- arch/x86/include/asm/msr.h | 18 ++++++++++++++++++ arch/x86/mm/extable.c | 39 +++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 71f41af11591..cf5205300266 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -56,6 +56,24 @@ static inline void do_trace_read_msr(u32 msr, u64 val, i= nt failed) {} static inline void do_trace_rdpmc(u32 msr, u64 val, int failed) {} #endif =20 +/* + * Called only from an MSR fault handler, the instruction pointer points to + * the MSR access instruction that caused the fault. + */ +static __always_inline bool is_msr_imm_insn(void *ip) +{ + /* + * A full decoder for immediate form MSR instructions appears excessive. + */ +#ifdef CONFIG_X86_64 + const u8 msr_imm_insn_prefix[] =3D { 0xc4, 0xe7 }; + + return !memcmp(ip, msr_imm_insn_prefix, sizeof(msr_imm_insn_prefix)); +#else + return false; +#endif +} + /* * __rdmsr() and __wrmsr() are the two primitives which are the bare minim= um MSR * accessors and should not have any tracing or other functionality piggyb= acking diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index 2fdc1f1f5adb..c021e4dbc69d 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -166,23 +166,52 @@ static bool ex_handler_uaccess(const struct exception= _table_entry *fixup, static bool ex_handler_msr(const struct exception_table_entry *fixup, struct pt_regs *regs, bool wrmsr, bool safe, int reg) { + bool imm_insn =3D is_msr_imm_insn((void *)regs->ip); + u32 msr; + + if (imm_insn) + /* + * The 32-bit immediate specifying a MSR is encoded into + * byte 5 ~ 8 of an immediate form MSR instruction. + */ + msr =3D *(u32 *)(regs->ip + 5); + else + msr =3D (u32)regs->cx; + if (__ONCE_LITE_IF(!safe && wrmsr)) { - pr_warn("unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%08= x%08x) at rIP: 0x%lx (%pS)\n", - (unsigned int)regs->cx, (unsigned int)regs->dx, - (unsigned int)regs->ax, regs->ip, (void *)regs->ip); + /* + * To maintain consistency with existing RDMSR and WRMSR(NS) instruction= s, + * the register operand for immediate form MSR instructions is ALWAYS + * encoded as RAX in for reading or writing the MSR value. + */ + u64 msr_val =3D regs->ax; + + if (!imm_insn) { + /* + * On processors that support the Intel 64 architecture, the + * high-order 32 bits of each of RAX and RDX are ignored. + */ + msr_val &=3D 0xffffffff; + msr_val |=3D (u64)regs->dx << 32; + } + + pr_warn("unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%01= 6llx) at rIP: 0x%lx (%pS)\n", + msr, msr_val, regs->ip, (void *)regs->ip); show_stack_regs(regs); } =20 if (__ONCE_LITE_IF(!safe && !wrmsr)) { pr_warn("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%lx (%pS)= \n", - (unsigned int)regs->cx, regs->ip, (void *)regs->ip); + msr, regs->ip, (void *)regs->ip); show_stack_regs(regs); } =20 if (!wrmsr) { /* Pretend that the read succeeded and returned 0. */ regs->ax =3D 0; - regs->dx =3D 0; + + if (!imm_insn) + regs->dx =3D 0; } =20 if (safe) --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 0CD7D2BF009 for ; Tue, 30 Sep 2025 07:04:57 +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=1759215900; cv=none; b=EPBVvkRANy1KlWjHhe4ohyw7t9E6/btcd07QPHyWYbqZ2S9AZ9uewbLvdPeOAZ7KnB++zIsxRV/1KSHXqqROIW1DTaaJXzpYtv+vDh2HacD3qqOySPQhqdUZ5J/3mnx4CDFnFjCa7LjYNUPXYLKt3SoyzRnzZs+Vi3ocmhEH+II= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215900; c=relaxed/simple; bh=TcE/NhZ1eGRmnpo5YUdRpOEqLBtad3z7/J5atrh1vjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GYFONiF3Xn/luE62/VQHFOTGXCP3tXUPsWBvb4IfoTjN1xURi0qfPqYBY/fwSYIe5nn+eggcwCPrTM55ab+jR+uuAJ9Np+9eovcC690ENQZH6J2R4kv0Aydy4JQq+LNwch8yBMwjXraT7IniBanapTBQvMs3tjE9ZcZKa5nHt4w= 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=k6pVVKk7; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=k6pVVKk7; 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="k6pVVKk7"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="k6pVVKk7" 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 1760B1F83B; Tue, 30 Sep 2025 07:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215893; 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=/1LVuMgazC1Onbf9ADrNmOc+JVVm6iLogAHDZnTOsKc=; b=k6pVVKk7WIN4jlPSAapwAePey/L92clCe9nPEWdsS3bHebHHHnm6I+q+PURusNJ+X3g71/ HuclRLExL0WoQsfik7GxLbNVfpCruPD6m4sL7ybtbBCUO9IY9v28tCTLupKwBAoh63iJd9 kJWhMb4+ffGbCa/RDo7q1VJnTD05Sds= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215893; 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=/1LVuMgazC1Onbf9ADrNmOc+JVVm6iLogAHDZnTOsKc=; b=k6pVVKk7WIN4jlPSAapwAePey/L92clCe9nPEWdsS3bHebHHHnm6I+q+PURusNJ+X3g71/ HuclRLExL0WoQsfik7GxLbNVfpCruPD6m4sL7ybtbBCUO9IY9v28tCTLupKwBAoh63iJd9 kJWhMb4+ffGbCa/RDo7q1VJnTD05Sds= 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 9E35313A3F; Tue, 30 Sep 2025 07:04:52 +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 VvYXJRSB22jPRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:52 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, llvm@lists.linux.dev Cc: xin@zytor.com, Juergen Gross , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Subject: [PATCH v2 09/12] x86/msr: Use the alternatives mechanism for WRMSR Date: Tue, 30 Sep 2025 09:03:53 +0200 Message-ID: <20250930070356.30695-10-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-1.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:mid,imap1.dmz-prg2.suse.org:helo]; RCPT_COUNT_TWELVE(0.00)[14]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[lkml]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_CC(0.00)[zytor.com,suse.com,linutronix.de,redhat.com,alien8.de,linux.intel.com,kernel.org,gmail.com,google.com]; FROM_HAS_DN(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLfdszjqhz8kzzb9uwpzdm8png)]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Score: -1.30 Content-Type: text/plain; charset="utf-8" When available use one of the non-serializing WRMSR variants (WRMSRNS with or without an immediate operand specifying the MSR register) in __wrmsrq(). For the safe/unsafe variants make __wrmsrq() to be a common base function instead of duplicating the ALTERNATIVE*() macros. This requires to let native_wrmsr() use native_wrmsrq() instead of __wrmsrq(). While changing this, convert native_wrmsr() into an inline function. Replace the only call of wsrmsrns() with the now equivalent call to native_wrmsrq() and remove wsrmsrns(). The paravirt case will be handled later. Originally-by: Xin Li (Intel) Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- V2: - new patch, partially taken from "[RFC PATCH v2 21/34] x86/msr: Utilize the alternatives mechanism to write MSR" by Xin Li. --- arch/x86/include/asm/fred.h | 2 +- arch/x86/include/asm/msr.h | 144 +++++++++++++++++++++++++++--------- 2 files changed, 110 insertions(+), 36 deletions(-) diff --git a/arch/x86/include/asm/fred.h b/arch/x86/include/asm/fred.h index 12b34d5b2953..8ae4429e5401 100644 --- a/arch/x86/include/asm/fred.h +++ b/arch/x86/include/asm/fred.h @@ -101,7 +101,7 @@ static __always_inline void fred_update_rsp0(void) unsigned long rsp0 =3D (unsigned long) task_stack_page(current) + THREAD_= SIZE; =20 if (cpu_feature_enabled(X86_FEATURE_FRED) && (__this_cpu_read(fred_rsp0) = !=3D rsp0)) { - wrmsrns(MSR_IA32_FRED_RSP0, rsp0); + native_wrmsrq(MSR_IA32_FRED_RSP0, rsp0); __this_cpu_write(fred_rsp0, rsp0); } } diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index cf5205300266..19ed780c2a09 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -7,11 +7,11 @@ #ifndef __ASSEMBLER__ =20 #include -#include #include #include #include =20 +#include #include #include =20 @@ -56,6 +56,36 @@ static inline void do_trace_read_msr(u32 msr, u64 val, i= nt failed) {} static inline void do_trace_rdpmc(u32 msr, u64 val, int failed) {} #endif =20 +/* The GNU Assembler (Gas) with Binutils 2.40 adds WRMSRNS support */ +#if defined(CONFIG_AS_IS_GNU) && CONFIG_AS_VERSION >=3D 24000 +#define ASM_WRMSRNS "wrmsrns" +#else +#define ASM_WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6) +#endif + +/* The GNU Assembler (Gas) with Binutils 2.41 adds the .insn directive sup= port */ +#if defined(CONFIG_AS_IS_GNU) && CONFIG_AS_VERSION >=3D 24100 +#define ASM_WRMSRNS_IMM \ + " .insn VEX.128.F3.M7.W0 0xf6 /0, %[val], %[msr]%{:u32}\n\t" +#else +/* + * Note, clang also doesn't support the .insn directive. + * + * The register operand is encoded as %rax because all uses of the immedia= te + * form MSR access instructions reference %rax as the register operand. + */ +#define ASM_WRMSRNS_IMM \ + " .byte 0xc4,0xe7,0x7a,0xf6,0xc0; .long %c[msr]" +#endif + +#define PREPARE_RDX_FOR_WRMSR \ + "mov %%rax, %%rdx\n\t" \ + "shr $0x20, %%rdx\n\t" + +#define PREPARE_RCX_RDX_FOR_WRMSR \ + "mov %[msr], %%ecx\n\t" \ + PREPARE_RDX_FOR_WRMSR + /* * Called only from an MSR fault handler, the instruction pointer points to * the MSR access instruction that caused the fault. @@ -93,12 +123,76 @@ static __always_inline u64 __rdmsr(u32 msr) return EAX_EDX_VAL(val, low, high); } =20 -static __always_inline void __wrmsrq(u32 msr, u64 val) +static __always_inline bool __wrmsrq_variable(u32 msr, u64 val, int type) { - asm volatile("1: wrmsr\n" - "2:\n" - _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR) - : : "c" (msr), "a" ((u32)val), "d" ((u32)(val >> 32)) : "memory"); +#ifdef CONFIG_X86_64 + BUILD_BUG_ON(__builtin_constant_p(msr)); +#endif + + /* + * WRMSR is 2 bytes. WRMSRNS is 3 bytes. Pad WRMSR with a redundant + * DS prefix to avoid a trailing NOP. + */ + asm_inline volatile goto( + "1:\n" + ALTERNATIVE("ds wrmsr", + ASM_WRMSRNS, + X86_FEATURE_WRMSRNS) + _ASM_EXTABLE_TYPE(1b, %l[badmsr], %c[type]) + + : + : "c" (msr), "a" ((u32)val), "d" ((u32)(val >> 32)), [type] "i" (type) + : "memory" + : badmsr); + + return false; + +badmsr: + return true; +} + +#ifdef CONFIG_X86_64 +/* + * Non-serializing WRMSR or its immediate form, when available. + * + * Otherwise, it falls back to a serializing WRMSR. + */ +static __always_inline bool __wrmsrq_constant(u32 msr, u64 val, int type) +{ + BUILD_BUG_ON(!__builtin_constant_p(msr)); + + asm_inline volatile goto( + "1:\n" + ALTERNATIVE_2(PREPARE_RCX_RDX_FOR_WRMSR + "2: ds wrmsr", + PREPARE_RCX_RDX_FOR_WRMSR + ASM_WRMSRNS, + X86_FEATURE_WRMSRNS, + ASM_WRMSRNS_IMM, + X86_FEATURE_MSR_IMM) + _ASM_EXTABLE_TYPE(1b, %l[badmsr], %c[type]) /* For WRMSRNS immediate */ + _ASM_EXTABLE_TYPE(2b, %l[badmsr], %c[type]) /* For WRMSR(NS) */ + + : + : [val] "a" (val), [msr] "i" (msr), [type] "i" (type) + : "memory", "ecx", "rdx" + : badmsr); + + return false; + +badmsr: + return true; +} +#endif + +static __always_inline bool __wrmsrq(u32 msr, u64 val, int type) +{ +#ifdef CONFIG_X86_64 + if (__builtin_constant_p(msr)) + return __wrmsrq_constant(msr, val, type); +#endif + + return __wrmsrq_variable(msr, val, type); } =20 #define native_rdmsr(msr, val1, val2) \ @@ -113,11 +207,15 @@ static __always_inline u64 native_rdmsrq(u32 msr) return __rdmsr(msr); } =20 -#define native_wrmsr(msr, low, high) \ - __wrmsrq((msr), (u64)(high) << 32 | (low)) +static __always_inline void native_wrmsrq(u32 msr, u64 val) +{ + __wrmsrq(msr, val, EX_TYPE_WRMSR); +} =20 -#define native_wrmsrq(msr, val) \ - __wrmsrq((msr), (val)) +static __always_inline void native_wrmsr(u32 msr, u32 low, u32 high) +{ + native_wrmsrq(msr, (u64)high << 32 | low); +} =20 static inline u64 native_read_msr(u32 msr) { @@ -149,15 +247,7 @@ static inline void notrace native_write_msr(u32 msr, u= 64 val) /* Can be uninlined because referenced by paravirt */ static inline int notrace native_write_msr_safe(u32 msr, u64 val) { - int err; - - asm volatile("1: wrmsr ; xor %[err],%[err]\n" - "2:\n\t" - _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_WRMSR_SAFE, %[err]) - : [err] "=3Da" (err) - : "c" (msr), "0" ((u32)val), "d" ((u32)(val >> 32)) - : "memory"); - return err; + return __wrmsrq(msr, val, EX_TYPE_WRMSR_SAFE) ? -EIO : 0; } =20 extern int rdmsr_safe_regs(u32 regs[8]); @@ -176,7 +266,6 @@ static inline u64 native_read_pmc(int counter) #ifdef CONFIG_PARAVIRT_XXL #include #else -#include static __always_inline u64 read_msr(u32 msr) { return native_read_msr(msr); @@ -268,21 +357,6 @@ static inline int wrmsrq_safe(u32 msr, u64 val) return err; } =20 -/* Instruction opcode for WRMSRNS supported in binutils >=3D 2.40 */ -#define ASM_WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6) - -/* Non-serializing WRMSR, when available. Falls back to a serializing WRM= SR. */ -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", ASM_WRMSRNS, X86_FEATURE_WRMSR= NS) - "2: " _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR) - : : "c" (msr), "a" ((u32)val), "d" ((u32)(val >> 32))); -} - static inline void wrmsr(u32 msr, u32 low, u32 high) { wrmsrq(msr, (u64)high << 32 | low); --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 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 D401D2BF015 for ; Tue, 30 Sep 2025 07:05:01 +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=1759215903; cv=none; b=CnyXhE8SCnCubNfgsxyYAkX5b3YGLDWk1vfemp7ll65f2tfIp1AwRlGKr5IURHAIR+7XexpGIihnoOJk/oLvHVIPdN8Dni90Dc6gU4qpPvzP9CVTwJOCc/ln2fgZD9+BmbJ+9xk9wpre8tbhHw8yMkshwK+Io5kJkX2P9U7ie8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759215903; c=relaxed/simple; bh=/IFvLdmIX8BDFoHD122++2YqQJYtKvBqnRop4BCtQc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IOr4Qnlt+ugH52JdCTtsG9UPYSM5yZAWjWdn0YFj0SCmOJ8c5n5G0UJ7EFLcw/50iYjIKauy7cqg/VS5U3uHYkw6KjH/1KqXGF30lfyegZVvnmH/6lRz+FsMT5kA528T/2oH87WEX9UPbICioukT7t900x12zRD7dFwSXUFzPuM= 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=Ac6Ns3BG; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=mdjOZfn3; 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="Ac6Ns3BG"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="mdjOZfn3" 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 D75F2336FF; Tue, 30 Sep 2025 07:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215900; 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=JZm0DnA6KdLtON2UgVBMrVDAI2zIvqlTqbr+n8W7AZc=; b=Ac6Ns3BGPRP9+BHlragN+B33IvyJQdFzRCKmVaXGVLp2rXq6cWUi8fM4u1Gq24Cw3Ml8rE /e+xx1RxAYXY9VoXFzbe1KvLw9XMi7K/xorf6+DInvuc3lxoI5oJ2qtyGHK2J1qKh4HnB8 IOUvA2yHDhRNInrzu8QK2tIN6S6yTxg= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215898; 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=JZm0DnA6KdLtON2UgVBMrVDAI2zIvqlTqbr+n8W7AZc=; b=mdjOZfn3bHNMs0I5wtj5G7KL+vnM1Fong4JLmM6RuK9uzkG1fuyK6T7XB6JfPs7pdCPYLR 3GbkUD9acTzL9QAdf5xQzfA2wJZ1fZ0M0kpi4k3D3LqvE4mowYWSsAEuw/lnNM734IApwL VpIb2JIBMuM4LwjH785oUljHUKvgJQg= 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 8F5AE13A3F; Tue, 30 Sep 2025 07:04:58 +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 6nhWIRqB22jWRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:04:58 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: xin@zytor.com, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 10/12] x86/msr: Use the alternatives mechanism for RDMSR Date: Tue, 30 Sep 2025 09:03:54 +0200 Message-ID: <20250930070356.30695-11-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-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: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo,zytor.com:email]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; R_RATELIMIT(0.00)[to_ip_from(RLfdszjqhz8kzzb9uwpzdm8png)]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: X-Spam-Score: -2.80 Content-Type: text/plain; charset="utf-8" When available use the immediate variant of RDMSR in __rdmsr(). For the safe/unsafe variants make __rdmsr() to be a common base function instead of duplicating the ALTERNATIVE*() macros. Modify native_rdmsr() and native_read_msr() to use native_rdmsrq(). The paravirt case will be handled later. Originally-by: Xin Li (Intel) Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- V2: - new patch, partially taken from "[RFC PATCH v2 22/34] x86/msr: Utilize the alternatives mechanism to read MSR" by Xin Li --- arch/x86/include/asm/msr.h | 116 ++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 27 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 19ed780c2a09..cc592611e333 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -65,6 +65,8 @@ static inline void do_trace_rdpmc(u32 msr, u64 val, int f= ailed) {} =20 /* The GNU Assembler (Gas) with Binutils 2.41 adds the .insn directive sup= port */ #if defined(CONFIG_AS_IS_GNU) && CONFIG_AS_VERSION >=3D 24100 +#define ASM_RDMSR_IMM \ + " .insn VEX.128.F2.M7.W0 0xf6 /0, %[msr]%{:u32}, %[val]\n\t" #define ASM_WRMSRNS_IMM \ " .insn VEX.128.F3.M7.W0 0xf6 /0, %[val], %[msr]%{:u32}\n\t" #else @@ -74,10 +76,17 @@ static inline void do_trace_rdpmc(u32 msr, u64 val, int= failed) {} * The register operand is encoded as %rax because all uses of the immedia= te * form MSR access instructions reference %rax as the register operand. */ +#define ASM_RDMSR_IMM \ + " .byte 0xc4,0xe7,0x7b,0xf6,0xc0; .long %c[msr]" #define ASM_WRMSRNS_IMM \ " .byte 0xc4,0xe7,0x7a,0xf6,0xc0; .long %c[msr]" #endif =20 +#define RDMSR_AND_SAVE_RESULT \ + "rdmsr\n\t" \ + "shl $0x20, %%rdx\n\t" \ + "or %%rdx, %%rax\n\t" + #define PREPARE_RDX_FOR_WRMSR \ "mov %%rax, %%rdx\n\t" \ "shr $0x20, %%rdx\n\t" @@ -111,16 +120,76 @@ static __always_inline bool is_msr_imm_insn(void *ip) * think of extending them - you will be slapped with a stinking trout or = a frozen * shark will reach you, wherever you are! You've been warned. */ -static __always_inline u64 __rdmsr(u32 msr) +static __always_inline bool __rdmsrq_variable(u32 msr, u64 *val, int type) + { +#ifdef CONFIG_X86_64 + BUILD_BUG_ON(__builtin_constant_p(msr)); + + asm_inline volatile goto( + "1:\n" + RDMSR_AND_SAVE_RESULT + _ASM_EXTABLE_TYPE(1b, %l[badmsr], %c[type]) /* For RDMSR */ + + : [val] "=3Da" (*val) + : "c" (msr), [type] "i" (type) + : "rdx" + : badmsr); +#else + asm_inline volatile goto( + "1: rdmsr\n\t" + _ASM_EXTABLE_TYPE(1b, %l[badmsr], %c[type]) /* For RDMSR */ + + : "=3DA" (*val) + : "c" (msr), [type] "i" (type) + : + : badmsr); +#endif + + return false; + +badmsr: + *val =3D 0; + + return true; +} + +#ifdef CONFIG_X86_64 +static __always_inline bool __rdmsrq_constant(u32 msr, u64 *val, int type) { - EAX_EDX_DECLARE_ARGS(val, low, high); + BUILD_BUG_ON(!__builtin_constant_p(msr)); =20 - asm volatile("1: rdmsr\n" - "2:\n" - _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_RDMSR) - : EAX_EDX_RET(val, low, high) : "c" (msr)); + asm_inline volatile goto( + "1:\n" + ALTERNATIVE("mov %[msr], %%ecx\n\t" + "2:\n" + RDMSR_AND_SAVE_RESULT, + ASM_RDMSR_IMM, + X86_FEATURE_MSR_IMM) + _ASM_EXTABLE_TYPE(1b, %l[badmsr], %c[type]) /* For RDMSR immediate */ + _ASM_EXTABLE_TYPE(2b, %l[badmsr], %c[type]) /* For RDMSR */ + + : [val] "=3Da" (*val) + : [msr] "i" (msr), [type] "i" (type) + : "ecx", "rdx" + : badmsr); =20 - return EAX_EDX_VAL(val, low, high); + return false; + +badmsr: + *val =3D 0; + + return true; +} +#endif + +static __always_inline bool __rdmsr(u32 msr, u64 *val, int type) +{ +#ifdef CONFIG_X86_64 + if (__builtin_constant_p(msr)) + return __rdmsrq_constant(msr, val, type); +#endif + + return __rdmsrq_variable(msr, val, type); } =20 static __always_inline bool __wrmsrq_variable(u32 msr, u64 val, int type) @@ -195,18 +264,22 @@ static __always_inline bool __wrmsrq(u32 msr, u64 val= , int type) return __wrmsrq_variable(msr, val, type); } =20 +static __always_inline u64 native_rdmsrq(u32 msr) +{ + u64 val; + + __rdmsr(msr, &val, EX_TYPE_RDMSR); + + return val; +} + #define native_rdmsr(msr, val1, val2) \ do { \ - u64 __val =3D __rdmsr((msr)); \ + u64 __val =3D native_rdmsrq((msr)); \ (void)((val1) =3D (u32)__val); \ (void)((val2) =3D (u32)(__val >> 32)); \ } while (0) =20 -static __always_inline u64 native_rdmsrq(u32 msr) -{ - return __rdmsr(msr); -} - static __always_inline void native_wrmsrq(u32 msr, u64 val) { __wrmsrq(msr, val, EX_TYPE_WRMSR); @@ -219,23 +292,12 @@ static __always_inline void native_wrmsr(u32 msr, u32= low, u32 high) =20 static inline u64 native_read_msr(u32 msr) { - return __rdmsr(msr); + return native_rdmsrq(msr); } =20 -static inline int native_read_msr_safe(u32 msr, u64 *p) +static inline int native_read_msr_safe(u32 msr, u64 *val) { - int err; - EAX_EDX_DECLARE_ARGS(val, low, high); - - asm volatile("1: rdmsr ; xor %[err],%[err]\n" - "2:\n\t" - _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_RDMSR_SAFE, %[err]) - : [err] "=3Dr" (err), EAX_EDX_RET(val, low, high) - : "c" (msr)); - - *p =3D EAX_EDX_VAL(val, low, high); - - return err; + return __rdmsr(msr, val, EX_TYPE_RDMSR_SAFE) ? -EIO : 0; } =20 /* Can be uninlined because referenced by paravirt */ --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1759215921; cv=none; d=zohomail.com; s=zohoarc; b=LVePrN13B0lhqRrPUNAfsZZUwYDv52m59m2ViD08E8pu/mPMcb8NEqIp218R9sHC/Uap62xZzCJSQbrpJ1Ro4Qml+4mCa5osohJ6VrdZ535vvi5VY+ucrjR0bhQy/0PKoysRd/ss/BLbIVyXPCPlV6UmKK4NOsDo3Nw6gyX8MJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759215921; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=k/gRu11gXgbmlZdLI3CmLMHqbiCSOdJDjKieoXm17Zs=; b=IL2KWN4FB/m6gfKIYy/nxtdrdpEmVqmgRMaW/vtOmWULrlnJVKuAtHXzEruEgSc/HmZD+e1GDkfzyI74YBb5vpn5s+gMchoLO2eqido1ecrzQlHOIQYwMVj4u8suDOdZxcstpM6tH/GIwLOulH+qvjGF4p4tPDtEt7i3+nj6nug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1759215921148150.52585441921735; Tue, 30 Sep 2025 00:05:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1133744.1471808 (Exim 4.92) (envelope-from ) id 1v3UQA-0000hM-Ro; Tue, 30 Sep 2025 07:05:10 +0000 Received: by outflank-mailman (output) from mailman id 1133744.1471808; Tue, 30 Sep 2025 07:05:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3UQA-0000hF-Nc; Tue, 30 Sep 2025 07:05:10 +0000 Received: by outflank-mailman (input) for mailman id 1133744; Tue, 30 Sep 2025 07:05:09 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3UQ9-0008Ue-Np for xen-devel@lists.xenproject.org; Tue, 30 Sep 2025 07:05:09 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cc1f23ff-9dcb-11f0-9809-7dc792cee155; Tue, 30 Sep 2025 09:05:07 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 D78EA1F898; Tue, 30 Sep 2025 07:05:04 +0000 (UTC) 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 59B8813A3F; Tue, 30 Sep 2025 07:05:04 +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 1I8fFCCB22jcRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:05:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cc1f23ff-9dcb-11f0-9809-7dc792cee155 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215905; 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=k/gRu11gXgbmlZdLI3CmLMHqbiCSOdJDjKieoXm17Zs=; b=J4PQvC04B+PSPU5Qn0kbYDejEXysFawQCmfnFZpkuz+0XUVkV1HqUqBG3Il0Wo6kN6BnOg sajF6F2Ud8w6aYGOQkXNNJKhdJO1QQAPMKxREUCCe+yVhUdjy4ehAUGNrj9auqwNXf2E5c 6TfBk+rIMkHcYuJlw6RXmLfymsIsER8= Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=BlbtgpeX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215904; 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=k/gRu11gXgbmlZdLI3CmLMHqbiCSOdJDjKieoXm17Zs=; b=BlbtgpeXbLF5152uqQWV0JAAKoFLaMKHAq6+2yypXHAlf+7CTkYb7c8skwiJxhzxfURFNY Mn+g8IuOXIJ+0XuhbydgFKILHbP8IRRGpTJsPFn/fTxM8Qdr4d+NYbJP6tntvKOL2tHQAT KCDiguuQTp2eUWCmNph/s5SLlhCYHVQ= From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, virtualization@lists.linux.dev Cc: xin@zytor.com, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ajay Kaher , Alexey Makhalov , Broadcom internal kernel review list , Boris Ostrovsky , xen-devel@lists.xenproject.org Subject: [PATCH v2 11/12] x86/paravirt: Don't use pv_ops vector for MSR access functions Date: Tue, 30 Sep 2025 09:03:55 +0200 Message-ID: <20250930070356.30695-12-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: X-Spam-Flag: NO X-Rspamd-Queue-Id: D78EA1F898 X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 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)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[15]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_EQ_ENVFROM(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLkdkdrsxe9hqhhs5ask8616i6)]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.com:dkim,suse.com:mid,suse.com:email] X-Spam-Score: -3.01 X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1759215923512116600 Content-Type: text/plain; charset="utf-8" Instead of using the pv_ops vector for RDMSR/WRMSR related functions, use a more explicit approach allowing to inline the RDMSR/WRMSR instructions directly when not running as a Xen PV guest. By using cpu_feature_enabled(X86_FEATURE_XENPV) for the Xen PV case the related calls to Xen specific code will be statically disabled via runtime patching. Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- V2: - new patch --- arch/x86/include/asm/msr.h | 57 ++++++++++++++++++++++----- arch/x86/include/asm/paravirt.h | 45 --------------------- arch/x86/include/asm/paravirt_types.h | 13 ------ arch/x86/kernel/paravirt.c | 5 --- arch/x86/xen/enlighten_pv.c | 20 ++++------ arch/x86/xen/pmu.c | 1 + 6 files changed, 57 insertions(+), 84 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index cc592611e333..d42cd2c19818 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -290,24 +290,22 @@ static __always_inline void native_wrmsr(u32 msr, u32= low, u32 high) native_wrmsrq(msr, (u64)high << 32 | low); } =20 -static inline u64 native_read_msr(u32 msr) +static __always_inline u64 native_read_msr(u32 msr) { return native_rdmsrq(msr); } =20 -static inline int native_read_msr_safe(u32 msr, u64 *val) +static __always_inline int native_read_msr_safe(u32 msr, u64 *val) { return __rdmsr(msr, val, EX_TYPE_RDMSR_SAFE) ? -EIO : 0; } =20 -/* Can be uninlined because referenced by paravirt */ -static inline void notrace native_write_msr(u32 msr, u64 val) +static __always_inline void native_write_msr(u32 msr, u64 val) { native_wrmsrq(msr, val); } =20 -/* Can be uninlined because referenced by paravirt */ -static inline int notrace native_write_msr_safe(u32 msr, u64 val) +static __always_inline int native_write_msr_safe(u32 msr, u64 val) { return __wrmsrq(msr, val, EX_TYPE_WRMSR_SAFE) ? -EIO : 0; } @@ -325,8 +323,49 @@ static inline u64 native_read_pmc(int counter) return EAX_EDX_VAL(val, low, high); } =20 -#ifdef CONFIG_PARAVIRT_XXL -#include +#ifdef CONFIG_XEN_PV +#include + +static __always_inline u64 read_msr(u32 msr) +{ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return xen_read_msr(msr); + + return native_rdmsrq(msr); +} + +static __always_inline int read_msr_safe(u32 msr, u64 *p) +{ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return xen_read_msr_safe(msr, p); + + return native_read_msr_safe(msr, p); +} + +static __always_inline void write_msr(u32 msr, u64 val) +{ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + xen_write_msr(msr, val); + else + native_wrmsrq(msr, val); +} + +static __always_inline int write_msr_safe(u32 msr, u64 val) +{ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return xen_write_msr_safe(msr, val); + + return native_write_msr_safe(msr, val); +} + +static __always_inline u64 rdpmc(int counter) +{ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return xen_read_pmc(counter); + + return native_read_pmc(counter); +} + #else static __always_inline u64 read_msr(u32 msr) { @@ -353,7 +392,7 @@ static __always_inline u64 rdpmc(int counter) return native_read_pmc(counter); } =20 -#endif /* !CONFIG_PARAVIRT_XXL */ +#endif /* !CONFIG_XEN_PV */ =20 /* * Access to machine-specific registers (available on 586 and better only) diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravir= t.h index dc297f62b935..45f47b7d9f56 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -175,51 +175,6 @@ static inline void __write_cr4(unsigned long x) PVOP_VCALL1(cpu.write_cr4, x); } =20 -static inline u64 paravirt_read_msr(u32 msr) -{ - return PVOP_CALL1(u64, cpu.read_msr, msr); -} - -static inline void paravirt_write_msr(u32 msr, u64 val) -{ - PVOP_VCALL2(cpu.write_msr, msr, val); -} - -static inline int paravirt_read_msr_safe(u32 msr, u64 *val) -{ - return PVOP_CALL2(int, cpu.read_msr_safe, msr, val); -} - -static inline int paravirt_write_msr_safe(u32 msr, u64 val) -{ - return PVOP_CALL2(int, cpu.write_msr_safe, msr, val); -} - -static __always_inline u64 read_msr(u32 msr) -{ - return paravirt_read_msr(msr); -} - -static __always_inline int read_msr_safe(u32 msr, u64 *p) -{ - return paravirt_read_msr_safe(msr, p); -} - -static __always_inline void write_msr(u32 msr, u64 val) -{ - paravirt_write_msr(msr, val); -} - -static __always_inline int write_msr_safe(u32 msr, u64 val) -{ - return paravirt_write_msr_safe(msr, val); -} - -static __always_inline u64 rdpmc(int counter) -{ - return PVOP_CALL1(u64, cpu.read_pmc, counter); -} - static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned en= tries) { PVOP_VCALL2(cpu.alloc_ldt, ldt, entries); diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/p= aravirt_types.h index 37a8627d8277..0d03e658ea8f 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -90,19 +90,6 @@ struct pv_cpu_ops { void (*cpuid)(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx); =20 - /* Unsafe MSR operations. These will warn or panic on failure. */ - u64 (*read_msr)(u32 msr); - void (*write_msr)(u32 msr, u64 val); - - /* - * Safe MSR operations. - * Returns 0 or -EIO. - */ - int (*read_msr_safe)(u32 msr, u64 *val); - int (*write_msr_safe)(u32 msr, u64 val); - - u64 (*read_pmc)(int counter); - void (*start_context_switch)(struct task_struct *prev); void (*end_context_switch)(struct task_struct *next); #endif diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index ab3e172dcc69..240eeb1beab5 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -129,11 +129,6 @@ struct paravirt_patch_template pv_ops =3D { .cpu.read_cr0 =3D native_read_cr0, .cpu.write_cr0 =3D native_write_cr0, .cpu.write_cr4 =3D native_write_cr4, - .cpu.read_msr =3D native_read_msr, - .cpu.write_msr =3D native_write_msr, - .cpu.read_msr_safe =3D native_read_msr_safe, - .cpu.write_msr_safe =3D native_write_msr_safe, - .cpu.read_pmc =3D native_read_pmc, .cpu.load_tr_desc =3D native_load_tr_desc, .cpu.set_ldt =3D native_set_ldt, .cpu.load_gdt =3D native_load_gdt, diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 26bbaf4b7330..df653099c567 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1160,15 +1160,16 @@ static void xen_do_write_msr(u32 msr, u64 val, int = *err) } } =20 -static int xen_read_msr_safe(u32 msr, u64 *val) +int xen_read_msr_safe(u32 msr, u64 *val) { int err =3D 0; =20 *val =3D xen_do_read_msr(msr, &err); return err; } +EXPORT_SYMBOL(xen_read_msr_safe); =20 -static int xen_write_msr_safe(u32 msr, u64 val) +int xen_write_msr_safe(u32 msr, u64 val) { int err =3D 0; =20 @@ -1176,20 +1177,23 @@ static int xen_write_msr_safe(u32 msr, u64 val) =20 return err; } +EXPORT_SYMBOL(xen_write_msr_safe); =20 -static u64 xen_read_msr(u32 msr) +u64 xen_read_msr(u32 msr) { int err =3D 0; =20 return xen_do_read_msr(msr, xen_msr_safe ? &err : NULL); } +EXPORT_SYMBOL(xen_read_msr); =20 -static void xen_write_msr(u32 msr, u64 val) +void xen_write_msr(u32 msr, u64 val) { int err; =20 xen_do_write_msr(msr, val, xen_msr_safe ? &err : NULL); } +EXPORT_SYMBOL(xen_write_msr); =20 /* This is called once we have the cpu_possible_mask */ void __init xen_setup_vcpu_info_placement(void) @@ -1225,14 +1229,6 @@ static const typeof(pv_ops) xen_cpu_ops __initconst = =3D { =20 .write_cr4 =3D xen_write_cr4, =20 - .read_msr =3D xen_read_msr, - .write_msr =3D xen_write_msr, - - .read_msr_safe =3D xen_read_msr_safe, - .write_msr_safe =3D xen_write_msr_safe, - - .read_pmc =3D xen_read_pmc, - .load_tr_desc =3D paravirt_nop, .set_ldt =3D xen_set_ldt, .load_gdt =3D xen_load_gdt, diff --git a/arch/x86/xen/pmu.c b/arch/x86/xen/pmu.c index d49a3bdc448b..d0dea950cd4f 100644 --- a/arch/x86/xen/pmu.c +++ b/arch/x86/xen/pmu.c @@ -370,6 +370,7 @@ u64 xen_read_pmc(int counter) else return xen_intel_read_pmc(counter); } +EXPORT_SYMBOL(xen_read_pmc); =20 int pmu_apic_update(uint32_t val) { --=20 2.51.0 From nobody Wed Dec 17 12:46:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1759215931; cv=none; d=zohomail.com; s=zohoarc; b=MQX+LxF8gVRqmjK+JeCFflulZOTFAQCTRteh1nx6g94oujGw0bU+GgHoikOGm3+YCivQu9xA1ZjnNBEZ4NoMqpS9A8LnCZEh2HRZMXcP93gEMvM6s2eSUBlqHGKe7T6g3ZmWLe+/4im1NU7H7EQ1350oJurdkR4FrEPQhiU95ZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759215931; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DWVg40kg3cCGlbRyjRUpQT7gp/Qt5+z4LTlGPsiGrXQ=; b=KfBdWgKDWnPWEMriy02ureuTjgPDe3hoYlatvr5UsLdg9mvzAfsYZ60xmqzWIKhQYg7XI0oAaP5KtanFeNOJWyBEeRuhi/Y/RgTHKLzwPq8mvMGelkoA4RSFfp4Wyzy+xD7PB4+BvoLQRGMkFMsAoP4AZ9Pq9+BXGAu9xszIE9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1759215931298287.8215019347082; Tue, 30 Sep 2025 00:05:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1133745.1471818 (Exim 4.92) (envelope-from ) id 1v3UQG-0000xd-2I; Tue, 30 Sep 2025 07:05:16 +0000 Received: by outflank-mailman (output) from mailman id 1133745.1471818; Tue, 30 Sep 2025 07:05:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3UQF-0000xU-Vp; Tue, 30 Sep 2025 07:05:15 +0000 Received: by outflank-mailman (input) for mailman id 1133745; Tue, 30 Sep 2025 07:05:14 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3UQE-00089Y-Iy for xen-devel@lists.xenproject.org; Tue, 30 Sep 2025 07:05:14 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cfcec0f3-9dcb-11f0-9d14-b5c5bf9af7f9; Tue, 30 Sep 2025 09:05:14 +0200 (CEST) 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 A05161FB9F; Tue, 30 Sep 2025 07:05:10 +0000 (UTC) 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 4D06413A3F; Tue, 30 Sep 2025 07:05:10 +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 kk1UESaB22jlRwAAD6G6ig (envelope-from ); Tue, 30 Sep 2025 07:05:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cfcec0f3-9dcb-11f0-9d14-b5c5bf9af7f9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215910; 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=DWVg40kg3cCGlbRyjRUpQT7gp/Qt5+z4LTlGPsiGrXQ=; b=GRVg5tr0HEd/zfji2Am9gUzCqwhy/P7cpZ0YqMKn1p2vm/K6PZjvE/xKZ+HTt1e5zEfSPv LOjQd5/AGoxOsinDK3vohhJW6ExL1IshA4USHZvyAShs1Vinh0d0R9nNWByddY4+O84CE8 iDnY1/zxQYKvD6WCT3sUZxg9Y/4NvRc= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1759215910; 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=DWVg40kg3cCGlbRyjRUpQT7gp/Qt5+z4LTlGPsiGrXQ=; b=GRVg5tr0HEd/zfji2Am9gUzCqwhy/P7cpZ0YqMKn1p2vm/K6PZjvE/xKZ+HTt1e5zEfSPv LOjQd5/AGoxOsinDK3vohhJW6ExL1IshA4USHZvyAShs1Vinh0d0R9nNWByddY4+O84CE8 iDnY1/zxQYKvD6WCT3sUZxg9Y/4NvRc= From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: xin@zytor.com, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Boris Ostrovsky , xen-devel@lists.xenproject.org Subject: [PATCH v2 12/12] x86/msr: Reduce number of low level MSR access helpers Date: Tue, 30 Sep 2025 09:03:56 +0200 Message-ID: <20250930070356.30695-13-jgross@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930070356.30695-1-jgross@suse.com> References: <20250930070356.30695-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; R_RATELIMIT(0.00)[to_ip_from(RLfdszjqhz8kzzb9uwpzdm8png)]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Level: X-Spam-Score: -2.80 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1759215933538116600 Content-Type: text/plain; charset="utf-8" Some MSR access helpers are redundant now, so remove the no longer needed ones. Signed-off-by: Juergen Gross Reviewed-by: H. Peter Anvin (Intel) --- arch/x86/include/asm/msr.h | 14 ++------------ arch/x86/xen/enlighten_pv.c | 4 ++-- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index d42cd2c19818..43924d8a3d66 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -290,21 +290,11 @@ static __always_inline void native_wrmsr(u32 msr, u32= low, u32 high) native_wrmsrq(msr, (u64)high << 32 | low); } =20 -static __always_inline u64 native_read_msr(u32 msr) -{ - return native_rdmsrq(msr); -} - static __always_inline int native_read_msr_safe(u32 msr, u64 *val) { return __rdmsr(msr, val, EX_TYPE_RDMSR_SAFE) ? -EIO : 0; } =20 -static __always_inline void native_write_msr(u32 msr, u64 val) -{ - native_wrmsrq(msr, val); -} - static __always_inline int native_write_msr_safe(u32 msr, u64 val) { return __wrmsrq(msr, val, EX_TYPE_WRMSR_SAFE) ? -EIO : 0; @@ -369,7 +359,7 @@ static __always_inline u64 rdpmc(int counter) #else static __always_inline u64 read_msr(u32 msr) { - return native_read_msr(msr); + return native_rdmsrq(msr); } =20 static __always_inline int read_msr_safe(u32 msr, u64 *p) @@ -379,7 +369,7 @@ static __always_inline int read_msr_safe(u32 msr, u64 *= p) =20 static __always_inline void write_msr(u32 msr, u64 val) { - native_write_msr(msr, val); + native_wrmsrq(msr, val); } =20 static __always_inline int write_msr_safe(u32 msr, u64 val) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index df653099c567..277e053cf3dd 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1097,7 +1097,7 @@ static u64 xen_do_read_msr(u32 msr, int *err) if (err) *err =3D native_read_msr_safe(msr, &val); else - val =3D native_read_msr(msr); + val =3D native_rdmsrq(msr); =20 switch (msr) { case MSR_IA32_APICBASE: @@ -1156,7 +1156,7 @@ static void xen_do_write_msr(u32 msr, u64 val, int *e= rr) if (err) *err =3D native_write_msr_safe(msr, val); else - native_write_msr(msr, val); + native_wrmsrq(msr, val); } } =20 --=20 2.51.0