[{"id":3679369,"web_url":"http://patchwork.ozlabs.org/comment/3679369/","msgid":"<5D9A012C-0278-44A4-82AA-185FF61AF3D8@unpredictable.fr>","list_archive_url":null,"date":"2026-04-20T11:27:24","subject":"Re: [PATCH v2 35/38] target/i386: emulate, hvf: rdmsr/wrmsr GPF\n handling","submitter":{"id":91318,"url":"http://patchwork.ozlabs.org/api/people/91318/","name":"Mohamed Mediouni","email":"mohamed@unpredictable.fr"},"content":"> On 20. Apr 2026, at 12:42, Mohamed Mediouni <mohamed@unpredictable.fr> wrote:\n> \n> In that case, the instruction pointer mustn't be incremented.\n> \n> Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>\n> ---\n> target/i386/emulate/x86_emu.c | 10 ++++++----\n> target/i386/emulate/x86_emu.h |  4 ++--\n> target/i386/hvf/hvf.c         |  9 +++++++--\n> 3 files changed, 15 insertions(+), 8 deletions(-)\nHi,\n\nForgot to include this to the sent patch…\n\ndiff --git a/target/i386/hvf/hvf-i386.h b/target/i386/hvf/hvf-i386.h\nindex 8c42ae6b01..b91c17e2fc 100644\n--- a/target/i386/hvf/hvf-i386.h\n+++ b/target/i386/hvf/hvf-i386.h\n@@ -19,8 +19,8 @@\n uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx, int reg);\n \n void hvf_handle_io(CPUState *, uint16_t, void *, int, int, int);\n-void hvf_simulate_rdmsr(CPUState *cpu);\n-void hvf_simulate_wrmsr(CPUState *cpu);\n+bool hvf_simulate_rdmsr(CPUState *cpu);\n+bool hvf_simulate_wrmsr(CPUState *cpu);\n\n\n> diff --git a/target/i386/emulate/x86_emu.c b/target/i386/emulate/x86_emu.c\n> index c2da1a133f..c6ea854290 100644\n> --- a/target/i386/emulate/x86_emu.c\n> +++ b/target/i386/emulate/x86_emu.c\n> @@ -792,15 +792,17 @@ void x86_emul_raise_exception(CPUX86State *env, int exception_index, int error_c\n> \n> static bool exec_rdmsr(CPUX86State *env, struct x86_decode *decode)\n> {\n> -    emul_ops->simulate_rdmsr(env_cpu(env));\n> -    env->eip += decode->len;\n> +    if (!emul_ops->simulate_rdmsr(env_cpu(env))) {\n> +        env->eip += decode->len;\n> +    }\n>     return 0;\n> }\n> \n> static bool exec_wrmsr(CPUX86State *env, struct x86_decode *decode)\n> {\n> -    emul_ops->simulate_wrmsr(env_cpu(env));\n> -    env->eip += decode->len;\n> +    if (!emul_ops->simulate_wrmsr(env_cpu(env))) {\n> +        env->eip += decode->len;\n> +    }\n>     return 0;\n> }\n> \n> diff --git a/target/i386/emulate/x86_emu.h b/target/i386/emulate/x86_emu.h\n> index a8d4c93098..b985240b90 100644\n> --- a/target/i386/emulate/x86_emu.h\n> +++ b/target/i386/emulate/x86_emu.h\n> @@ -31,8 +31,8 @@ struct x86_emul_ops {\n>     target_ulong (*read_cr) (CPUState *cpu, int cr);\n>     void (*handle_io)(CPUState *cpu, uint16_t port, void *data, int direction,\n>                       int size, int count);\n> -    void (*simulate_rdmsr)(CPUState *cs);\n> -    void (*simulate_wrmsr)(CPUState *cs);\n> +    bool (*simulate_rdmsr)(CPUState *cs);\n> +    bool (*simulate_wrmsr)(CPUState *cs);\n>     bool (*is_protected_mode)(CPUState *cpu);\n>     bool (*is_long_mode)(CPUState *cpu);\n>     bool (*is_user_mode)(CPUState *cpu);\n> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c\n> index c0d028b147..dfe7500010 100644\n> --- a/target/i386/hvf/hvf.c\n> +++ b/target/i386/hvf/hvf.c\n> @@ -536,7 +536,7 @@ void hvf_store_regs(CPUState *cs)\n>     macvm_set_rip(cs, env->eip);\n> }\n> \n> -void hvf_simulate_rdmsr(CPUState *cs)\n> +bool hvf_simulate_rdmsr(CPUState *cs)\n> {\n>     X86CPU *cpu = X86_CPU(cs);\n>     CPUX86State *env = &cpu->env;\n> @@ -557,6 +557,7 @@ void hvf_simulate_rdmsr(CPUState *cs)\n>         ret = apic_msr_read(cpu->apic_state, index, &val);\n>         if (ret < 0) {\n>             x86_emul_raise_exception(env, EXCP0D_GPF, 0);\n> +            return 1;\n>         }\n> \n>         break;\n> @@ -639,9 +640,10 @@ void hvf_simulate_rdmsr(CPUState *cs)\n> \n>     RAX(env) = (uint32_t)val;\n>     RDX(env) = (uint32_t)(val >> 32);\n> +    return 0;\n> }\n> \n> -void hvf_simulate_wrmsr(CPUState *cs)\n> +bool hvf_simulate_wrmsr(CPUState *cs)\n> {\n>     X86CPU *cpu = X86_CPU(cs);\n>     CPUX86State *env = &cpu->env;\n> @@ -657,6 +659,7 @@ void hvf_simulate_wrmsr(CPUState *cs)\n>         r = cpu_set_apic_base(cpu->apic_state, data);\n>         if (r < 0) {\n>             x86_emul_raise_exception(env, EXCP0D_GPF, 0);\n> +            return 1;\n>         }\n> \n>         break;\n> @@ -668,6 +671,7 @@ void hvf_simulate_wrmsr(CPUState *cs)\n>         ret = apic_msr_write(cpu->apic_state, index, data);\n>         if (ret < 0) {\n>             x86_emul_raise_exception(env, EXCP0D_GPF, 0);\n> +            return 1;\n>         }\n> \n>         break;\n> @@ -746,6 +750,7 @@ void hvf_simulate_wrmsr(CPUState *cs)\n>          g_hypervisor_iface->wrmsr_handler(cs, msr, data);\n> \n>     printf(\"write msr %llx\\n\", RCX(cs));*/\n> +    return 0;\n> }\n> \n> static int hvf_handle_vmexit(CPUState *cpu)\n> -- \n> 2.50.1 (Apple Git-155)\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=unpredictable.fr header.i=@unpredictable.fr\n header.a=rsa-sha256 header.s=sig1 header.b=ZtFK0Re5;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzjtJ63M0z1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 21:28:55 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wEmn9-00043s-Jd; Mon, 20 Apr 2026 07:27:51 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1wEmn4-00043Q-OS\n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 07:27:47 -0400","from p-west3-cluster1-host8-snip4-10.eps.apple.com ([57.103.73.211]\n helo=outbound.ms.icloud.com)\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1wEmn1-0003vU-HE\n for qemu-devel@nongnu.org; Mon, 20 Apr 2026 07:27:45 -0400","from outbound.ms.icloud.com (unknown [127.0.0.2])\n by p00-icloudmta-asmtp-us-west-3a-60-percent-5 (Postfix) with ESMTPS id\n C15791800411; Mon, 20 Apr 2026 11:27:38 +0000 (UTC)","from smtpclient.apple (unknown [17.57.154.37])\n by p00-icloudmta-asmtp-us-west-3a-60-percent-5 (Postfix) with ESMTPSA id\n 5814B1800401; Mon, 20 Apr 2026 11:27:36 +0000 (UTC)"],"Dkim-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr;\n s=sig1; t=1776684461; x=1779276461;\n bh=Krffpx7w2ZVSMIrNsZDbV8VgM7sYpLIn8x9ysKUuL/8=;\n h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To:x-icloud-hme;\n b=ZtFK0Re5/WdV1c0DJUDvM/5ty/S3DhFgBDsqDaotcthJUyXg1baJ98MrcgPIRq6mR4KjA3rKunmPuLxcDAFz9wHUDSaOI24D6F6k3l4qsqhwqDdwbX2dcKvViWimqfEWId9CuzCw3P4tDEhRvQFOrMHA+xpH6Lv8r/zAmiIDVg7Su0FDabYoQ6Bo5u8UMd57O1Sqz/6FKOHmlIM6bvVzSJACd5dHK8IIZJBEIfPKoe1YfJZBMd7Z5reyl9SPefEHUx4UZhGuO9396a+Go3KSmgKJnn1+CnCAN4W1POeXrVI0vTg/T2cy6FdWpXbMiZEGk/gm/prye8G1n5Unw9QIdg==","mail-alias-created-date":"1752046281608","Content-Type":"text/plain;\n\tcharset=utf-8","Mime-Version":"1.0 (Mac OS X Mail 16.0 \\(3864.500.181\\))","Subject":"Re: [PATCH v2 35/38] target/i386: emulate, hvf: rdmsr/wrmsr GPF\n handling","From":"Mohamed Mediouni <mohamed@unpredictable.fr>","In-Reply-To":"<20260420104248.86702-36-mohamed@unpredictable.fr>","Date":"Mon, 20 Apr 2026 13:27:24 +0200","Cc":"qemu-arm@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,\n Phil Dennis-Jordan <phil@philjordan.eu>,\n Roman Bolshakov <rbolshakov@ddn.com>,\n Pierrick Bouvier <pierrick.bouvier@linaro.org>,\n Pedro Barbuda <pbarbuda@microsoft.com>, Wei Liu <wei.liu@kernel.org>,\n \"Michael S. Tsirkin\" <mst@redhat.com>,\n Peter Maydell <peter.maydell@linaro.org>, Zhao Liu <zhao1.liu@intel.com>","Content-Transfer-Encoding":"quoted-printable","Message-Id":"<5D9A012C-0278-44A4-82AA-185FF61AF3D8@unpredictable.fr>","References":"<20260420104248.86702-1-mohamed@unpredictable.fr>\n <20260420104248.86702-36-mohamed@unpredictable.fr>","To":"qemu-devel@nongnu.org","X-Mailer":"Apple Mail (2.3864.500.181)","X-Authority-Info-Out":"v=2.4 cv=TambdBQh c=1 sm=1 tr=0 ts=69e60dab\n cx=c_apl:c_pps:t_out a=qkKslKyYc0ctBTeLUVfTFg==:117 a=IkcTkHD0fZMA:10\n a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=U6C6HV61ui0oiVVhl9AA:9\n a=QEXdDO2ut3YA:10","X-Proofpoint-GUID":"16tPBr9IHtOHWuoujYDLbEz0qr5Jr7Mt","X-Proofpoint-ORIG-GUID":"16tPBr9IHtOHWuoujYDLbEz0qr5Jr7Mt","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDIwMDExMSBTYWx0ZWRfX6X4izME+gVhF\n aZ/cgfneMbFhM/cFQrnOUUtC4yUAVSVJkT3YxAHXpWi8AkTFfQcqQ3JIm6xIPgWyCEIxvzk1d4h\n 9PTaqhVG0iMO4YVzzsdDF3XmXAyemgfhtkNKNFz4TlE4BrZFFuuI84T/YxTg5/hJhJgSUA/04eT\n QBCixXSSry8prpsDxk/evjswv418Rgc5+dss2bEykg1liNQeYStL26bd4BBKtX5yeb6/McHZXYB\n LuDWZkEvmvRPZoll9uAKn41rDgjyPg0rlNc5R+Nm00HE4b+r3PxVRuhlco+vAXtuePL11BcMFr6\n qBmhD9qGGrPVkuUYOFnLaF0Hop8o52IDcypSrTA5sqBBDvQP1GwjIQPQ71iEek=","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-20_02,2026-04-17_04,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=notspam policy=default score=0 suspectscore=0\n bulkscore=0 spamscore=0 mlxscore=0 clxscore=1030\n phishscore=0\n lowpriorityscore=0 mlxlogscore=865 adultscore=0 malwarescore=0\n classifier=spam authscore=0 adjust=0 reason=mlx scancount=1\n engine=8.22.0-2601150000 definitions=main-2604200111","Received-SPF":"pass client-ip=57.103.73.211;\n envelope-from=mohamed@unpredictable.fr; helo=outbound.ms.icloud.com","X-Spam_score_int":"-27","X-Spam_score":"-2.8","X-Spam_bar":"--","X-Spam_report":"(-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001,\n SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]