From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DEE01E5201 for ; Mon, 29 Jun 2026 17:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782752687; cv=none; b=DWGtPYR0qS4g61KvMc7ifiTQn93uhGtTPfw0+nbA7jYALPr9ylNwinQ96Kz1ksxKJGNGyfowh1UhVn4JCOzs1k0L0CFycroyms7y4/XZYVMFxAZY3n/31WxbPNwvYLZC0wcGeFNe4ovTln5Q8GF0caL8be3tEO/p55eJDEx1Wcg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782752687; c=relaxed/simple; bh=ODtxB/IOMFiwFhOYltYu1JFT3/mITaahh7CJhO4Jo5M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JIECP1aq/ybf9S5V/YjCutN27Tq04nJYiqGBqZXmxHaMBFyzuAev6Sz04NQ0h6POh3dy1C6SH5FON3nfDqTTHL+KUfgQWHsSPSMFQ2TDuieK8SGgoUE0JU54v0Z3OEdvLOwDNkUhMMgMvzfYOjMjQ+h0FQzQN2WKZzWCcfyfpt8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=akKP4P4f; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="akKP4P4f" Received: from [IPV6:2601:646:8081:7da1:68c9:ba90:b2f5:8138] ([IPv6:2601:646:8081:7da1:68c9:ba90:b2f5:8138]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 65TH4Go9695423 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Mon, 29 Jun 2026 10:04:16 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 65TH4Go9695423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2026062701; t=1782752657; bh=sZecWBnwSGn0zYqkGkwIjUw9c6asBIy2yhHzjUamOtc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=akKP4P4fHiIbaTJ/cybeOGChA76sdMBW+yIrKYLFbr8HirTYOHmhqDpv4msTNnt8U 4kRo/V3khGhE+U5hSe4p+Fw1ISYRH+quOSlD/NVlHMqT9fA0POzHQ8SMyW3BHcL9wz IQM7mqZDLENVuqZ2j7Pj3CiwzNMCKL1eqhyfhIK11McI10XBtGvphko0Waley6Z5G4 l8nPih7Tc8FziIIfLMuVUO07HQIMi2CdTgt9+WuWqaOPqcSHleHWIKy+EoGPjgfGJK V0wVN4dcicZvOToXnMW/Si3COeOjpEjpcwmDfGIigxnG8k/5uEz2/IcDthD6xlg14i /AILwtSEM+jCw== Message-ID: <18106e85-dd3c-4cd2-9039-30361cd477a1@zytor.com> Date: Mon, 29 Jun 2026 10:04:11 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 08/18] x86/extable: Add support for immediate form MSR instructions To: Juergen Gross , linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Xin Li (Intel)" References: <20260629065544.3643253-1-jgross@suse.com> <20260629065544.3643253-9-jgross@suse.com> Content-Language: en-US, sv-SE From: "H. Peter Anvin" In-Reply-To: <20260629065544.3643253-9-jgross@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2026-06-28 23:55, Juergen Gross wrote: > Signed-off-by: Xin Li (Intel) > Signed-off-by: Juergen Gross > --- > V2: > - new patch, taken from the RFC v2 MSR refactor series by Xin Li > V3: > - use instruction decoder (Peter Zijlstra) > V4: > - don't assume %rax for immediate form (Andrew Cooper) > --- > arch/x86/mm/extable.c | 46 +++++++++++++++++++++++++++++++++++++------ > 1 file changed, 40 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c > index ceb8d03191ab..9974785c8968 100644 > --- a/arch/x86/mm/extable.c > +++ b/arch/x86/mm/extable.c > @@ -166,25 +166,59 @@ 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) > { > + unsigned long *regptr; > + struct insn insn; > + bool imm_insn; > + u32 msr; > + > + imm_insn = insn_decode_kernel(&insn, (void *)regs->ip) && > + insn.vex_prefix.nbytes; > + msr = imm_insn ? insn.immediate.value : (u32)regs->cx; > + regptr = imm_insn ? insn_get_modrm_reg_ptr(&insn, regs) : ®s->ax; > + if (unlikely(!regptr)) { > + pr_err("Inconsistent %sMSR access instruction data at rIP: 0x%lx (%pS)!\n", > + wrmsr ? "WR" : "RD", regs->ip, (void *)regs->ip); > + show_stack_regs(regs); > + goto out; > + } > + > if (__ONCE_LITE_IF(!safe && wrmsr)) { > - pr_warn("unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%08x%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) instructions, > + * the register operand for immediate form MSR instructions is ALWAYS > + * encoded as RAX in for reading or writing the MSR value. > + */ > + u64 msr_val = *regptr; This comment is inconsistent with the use of a *regptr. The code is valid without this assumption, since you do insn_get_modrm_reg_ptr(), so I think you can simply omit the comment. -hpa