From nobody Tue May 26 22:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1779382331; cv=none; d=zohomail.com; s=zohoarc; b=c2j4gbGVV7wTTE1lfeiU4g+1lCbsvVWOzNMw+VJi3clPQJHxMDtpYa95MpOopDkyvmyLqvRiKlX66ZeCBsogxA/1q7QhJHAimiq1kjCs3qOgMszCZ/2qJfICSlaE4lIpBaiGPGK52thbyurP92zdfjqBIlgLsU2mwJhrMHvNRZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779382331; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G/N6a+EPTHHVm59twzRAAc8BmvLdSoWkzl5r46hF50w=; b=EAMF9LnTu+8hxIi/LenxPY3ktgYVLzbeNRWhsYQWYht6UfANiOfSqzRUdK/m5YoiNUIJwGX0hW8vnumXkqXFAZKX/sSr5lgJ6co0TkOBy9q1KuSrbYI0Zgwf97Fcn4Uia3GqsPODozHOC8YIV1iUb47usOkrmHfj/ePeIf7kqY4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779382331655858.3477723645974; Thu, 21 May 2026 09:52:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6c1-0004OI-N2; Thu, 21 May 2026 12:51:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ6bn-0004MB-Fn for qemu-devel@nongnu.org; Thu, 21 May 2026 12:50:57 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6bk-00070E-DO for qemu-devel@nongnu.org; Thu, 21 May 2026 12:50:55 -0400 Received: from laptop.localdomain (unknown [86.121.140.206]) by linux.microsoft.com (Postfix) with ESMTPSA id 9C22920B7168; Thu, 21 May 2026 09:50:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9C22920B7168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779382243; bh=G/N6a+EPTHHVm59twzRAAc8BmvLdSoWkzl5r46hF50w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PoLQp0V3kvkKtrWWmzuLbXpm4wCRRG3qFH+9awqs9QnhYBFW+Op9JFdkXtZjzLHBy 8VYpaJimZeVWVZhgQLxK6Yp9rT1Rk0BmVUzsgn4XQvI0tVt8Yj1begUISRvlEHk4OI JaX36uOioTagznu27a6S3V7TIzx6kNpu5vOl39eU= From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , Paolo Bonzini , Zhao Liu , Wei Liu , Magnus Kulke , Wei Liu , Magnus Kulke Subject: [PATCH v3 1/7] target/i386/mshv: remove duplicate function for reading vcpu registers Date: Thu, 21 May 2026 19:50:35 +0300 Message-ID: <20260521165041.131477-2-dblanzeanu@linux.microsoft.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> References: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=dblanzeanu@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1779382333360158500 Remove function `fetch_guest_state` because it is a duplicate function of `mshv_load_regs` function. Signed-off-by: Doru Bl=C3=A2nzeanu Reviewed-by: Magnus Kulke Reviewed-by: Anirudh Rayabharam (Microsoft) --- target/i386/mshv/mshv-cpu.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index 4ed6e7548f..9defd05db6 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -1291,25 +1291,6 @@ static int handle_pio_non_str(const CPUState *cpu, return 0; } =20 -static int fetch_guest_state(CPUState *cpu) -{ - int ret; - - ret =3D mshv_get_standard_regs(cpu); - if (ret < 0) { - error_report("Failed to get standard registers"); - return -1; - } - - ret =3D mshv_get_special_regs(cpu); - if (ret < 0) { - error_report("Failed to get special registers"); - return -1; - } - - return 0; -} - static int read_memory(const CPUState *cpu, uint64_t initial_gva, uint64_t initial_gpa, uint64_t gva, uint8_t *data, size_t len) @@ -1429,7 +1410,7 @@ static int handle_pio_str(CPUState *cpu, hv_x64_io_po= rt_intercept_message *info) X86CPU *x86_cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86_cpu->env; =20 - ret =3D fetch_guest_state(cpu); + ret =3D mshv_load_regs(cpu); if (ret < 0) { error_report("Failed to fetch guest state"); return -1; --=20 2.53.0 From nobody Tue May 26 22:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1779382331; cv=none; d=zohomail.com; s=zohoarc; b=MITKGFygSXgjQxvV5eyEgvjpTnMj6LjmMhG7r/3LBeIktUoeK50Az1BpyoC8OQmQImV61cDjwdST08u2l3QHcVbBAjzmDZx4EEZyS9dcRUu0X6WxU0zDCC11zFHIiEvsPYvtOykoFdWO1WR9fzxHi7YzeFhyIzPN5Vwa5rO2fEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779382331; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JlpbxG0l5HnNNZhi6MoHMmlFp4OaZ+gjEkjpeb/dFsw=; b=kJ64x0Uts71m8UIW3RVzQ/ojzARM4l/hcSB7fKkW4nyb0pdcoKVuhbwCj4hUKLHdS+SI6j7g0wqMfW5Nal5lpOMa3P8E8Zq2tt2B8sNofddJscN4dArxmDRhuwFQPoDqhDV5nxAXvPIyAoH9Y/DPgV9M6A4cBAkjTtEKqw7ake8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779382331619773.0586432848863; Thu, 21 May 2026 09:52:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6cH-0004RA-JS; Thu, 21 May 2026 12:51:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ6bo-0004MF-3p for qemu-devel@nongnu.org; Thu, 21 May 2026 12:50:57 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6bm-00071k-Am for qemu-devel@nongnu.org; Thu, 21 May 2026 12:50:55 -0400 Received: from laptop.localdomain (unknown [86.121.140.206]) by linux.microsoft.com (Postfix) with ESMTPSA id 4732820B716A; Thu, 21 May 2026 09:50:44 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4732820B716A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779382246; bh=JlpbxG0l5HnNNZhi6MoHMmlFp4OaZ+gjEkjpeb/dFsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EY678/l8Fj+U7XglZr5L4s9Qqym2YO/qwM7o13Fnd8+NNeEWwemHqXztf/5KEbhLA Q91Dr0yrZwkVLJ0dPWBuBytZt6H8skstptdIQKVCfq0rC9VHlQWdgheO8COIHR5g/3 9hxeL8tG+JGU7oNbGcSe1HXHvwGptF0RQmtJky4Y= From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , Paolo Bonzini , Zhao Liu , Wei Liu , Magnus Kulke , Wei Liu , Magnus Kulke Subject: [PATCH v3 2/7] accel/mshv: move vcpu arch specific initialization after vcpu creation Date: Thu, 21 May 2026 19:50:36 +0300 Message-ID: <20260521165041.131477-3-dblanzeanu@linux.microsoft.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> References: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=dblanzeanu@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1779382333352158500 Call mshv_arch_init_vcpu after the vcpu is created to ensure a valid vcpu fd. Signed-off-by: Doru Bl=C3=A2nzeanu Reviewed-by: Magnus Kulke Reviewed-by: Anirudh Rayabharam (Microsoft) --- accel/mshv/mshv-all.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index 58af674bd9..e3da583f21 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -415,13 +415,14 @@ static int mshv_init_vcpu(CPUState *cpu) int ret; =20 cpu->accel =3D g_new0(AccelCPUState, 1); - mshv_arch_init_vcpu(cpu); =20 ret =3D mshv_create_vcpu(vm_fd, vp_index, &cpu->accel->cpufd); if (ret < 0) { return -1; } =20 + mshv_arch_init_vcpu(cpu); + cpu->accel->dirty =3D true; =20 return 0; --=20 2.53.0 From nobody Tue May 26 22:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1779382367; cv=none; d=zohomail.com; s=zohoarc; b=btGm/cM7ciTpkB9akluIQlTN2g/JKFZpkXxl/x8ulQTDxqxxsd/pbhnLqmLsPDYHApZRa2AJ3FVWENFJD3z6UEXihAyPrKkH/QfKzAoemIjxfYcdB2Gkap6B2lX9+czHALcW6jOJsPT9UF6sJ5Dr2XiVux8KmWuzYtytqFVh60o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779382367; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rLsIuWY8QSuZMRArxFUxp0Wfr3g+5w7YocoK+TcJu+Y=; b=darfVNqyoOsTeL0wUTLcfvamLwj63OFYLD36JMqPo2sdEx1rHp6IViogV+IohE/LB9XyAS/4DDmD7Kn3NlNPePyxmtiHIyPawKZ975AaDQ24mVmSEjBMJ1t4tm8tuN8D7V4+x84IvQsW2fGYvEvadMWS4DsLi6zE4joGbyXPrXs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779382367592117.50592848829308; Thu, 21 May 2026 09:52:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6cV-0004U8-OG; Thu, 21 May 2026 12:51:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ6br-0004MZ-Vi for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:04 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6bq-00074L-4U for qemu-devel@nongnu.org; Thu, 21 May 2026 12:50:59 -0400 Received: from laptop.localdomain (unknown [86.121.140.206]) by linux.microsoft.com (Postfix) with ESMTPSA id D2F6C20B7169; Thu, 21 May 2026 09:50:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D2F6C20B7169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779382248; bh=rLsIuWY8QSuZMRArxFUxp0Wfr3g+5w7YocoK+TcJu+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j56EYP45qyLL0u4rM4AtG8HwnhLgjYhBqWjuhYXUq1jAaIzFC909JG1alsiJW5Alo d/jTqfcL9Wge10j1QI4xkp9TVlZuVW0LwyHq+aIJQCwgOudsI7loQRqZ3EzLb1iYOq o6ClPidlvqKe1BzCf6CAbmjzlVx/hnfQ8xRIVcWs= From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , Paolo Bonzini , Zhao Liu , Wei Liu , Magnus Kulke , Wei Liu , Magnus Kulke Subject: [PATCH v3 3/7] include/hw/hyperv: add hv_vp_register_page struct definition Date: Thu, 21 May 2026 19:50:37 +0300 Message-ID: <20260521165041.131477-4-dblanzeanu@linux.microsoft.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> References: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=dblanzeanu@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1779382369021158500 Define the `hv_vp_register_page` structure that the linux kernel uses to allow access to vcpu registers. This structure is going to be used in later patches to access vcpu registers. Signed-off-by: Doru Bl=C3=A2nzeanu Reviewed-by: Magnus Kulke --- include/hw/hyperv/hvgdk.h | 2 + include/hw/hyperv/hvhdk.h | 106 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/include/hw/hyperv/hvgdk.h b/include/hw/hyperv/hvgdk.h index 71161f477c..e4be861716 100644 --- a/include/hw/hyperv/hvgdk.h +++ b/include/hw/hyperv/hvgdk.h @@ -9,6 +9,8 @@ #ifndef HW_HYPERV_HVGDK_H #define HW_HYPERV_HVGDK_H =20 +#include "hvgdk_mini.h" + #define HVGDK_H_VERSION (25125) =20 enum hv_unimplemented_msr_action { diff --git a/include/hw/hyperv/hvhdk.h b/include/hw/hyperv/hvhdk.h index 41af743847..39b1e2497b 100644 --- a/include/hw/hyperv/hvhdk.h +++ b/include/hw/hyperv/hvhdk.h @@ -9,7 +9,12 @@ #ifndef HW_HYPERV_HVHDK_H #define HW_HYPERV_HVHDK_H =20 +#include "hvgdk.h" +#include "hvhdk_mini.h" + #define HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS 1 +#define HV_VP_REGISTER_PAGE_VERSION_1 1u +#define HV_VP_REGISTER_PAGE_MAX_VECTOR_COUNT 7 =20 struct hv_input_set_partition_property { uint64_t partition_id; @@ -246,4 +251,105 @@ typedef struct hv_input_register_intercept_result { union hv_register_intercept_result_parameters parameters; } QEMU_PACKED hv_input_register_intercept_result; =20 +/* Flags for dirty mask of hv_vp_register_page */ +enum hv_x64_register_class_type { + HV_X64_REGISTER_CLASS_GENERAL =3D 0, + HV_X64_REGISTER_CLASS_IP =3D 1, + HV_X64_REGISTER_CLASS_XMM =3D 2, + HV_X64_REGISTER_CLASS_SEGMENT =3D 3, + HV_X64_REGISTER_CLASS_FLAGS =3D 4, +}; + +union hv_vp_register_page_interrupt_vectors { + uint64_t as_uint64; + struct { + uint8_t vector_count; + uint8_t vector[HV_VP_REGISTER_PAGE_MAX_VECTOR_COUNT]; + }; +}; + +struct hv_vp_register_page { + uint16_t version; + uint8_t isvalid; + uint8_t rsvdz; + uint32_t dirty; + + union { + struct { + /* General purpose registers (HV_X64_REGISTER_CLASS_GENERAL) */ + union { + struct { + uint64_t rax; + uint64_t rcx; + uint64_t rdx; + uint64_t rbx; + uint64_t rsp; + uint64_t rbp; + uint64_t rsi; + uint64_t rdi; + uint64_t r8; + uint64_t r9; + uint64_t r10; + uint64_t r11; + uint64_t r12; + uint64_t r13; + uint64_t r14; + uint64_t r15; + } QEMU_PACKED; + + uint64_t gp_registers[16]; + }; + /* Instruction pointer (HV_X64_REGISTER_CLASS_IP) */ + uint64_t rip; + /* Flags (HV_X64_REGISTER_CLASS_FLAGS) */ + uint64_t rflags; + } QEMU_PACKED; + + uint64_t registers[18]; + }; + uint8_t reserved[8]; + /* Volatile XMM registers (HV_X64_REGISTER_CLASS_XMM) */ + union { + struct { + struct hv_u128 xmm0; + struct hv_u128 xmm1; + struct hv_u128 xmm2; + struct hv_u128 xmm3; + struct hv_u128 xmm4; + struct hv_u128 xmm5; + } QEMU_PACKED; + + struct hv_u128 xmm_registers[6]; + }; + /* Segment registers (HV_X64_REGISTER_CLASS_SEGMENT) */ + union { + struct { + struct hv_x64_segment_register es; + struct hv_x64_segment_register cs; + struct hv_x64_segment_register ss; + struct hv_x64_segment_register ds; + struct hv_x64_segment_register fs; + struct hv_x64_segment_register gs; + } QEMU_PACKED; + + struct hv_x64_segment_register segment_registers[6]; + }; + /* Misc. control registers (cannot be set via this interface) */ + uint64_t cr0; + uint64_t cr3; + uint64_t cr4; + uint64_t cr8; + uint64_t efer; + uint64_t dr7; + union hv_x64_pending_interruption_register pending_interruption; + union hv_x64_interrupt_state_register interrupt_state; + uint64_t instruction_emulation_hints; + uint64_t xfem; + + uint8_t reserved1[0x100]; + + /* Interrupts injected as part of HvCallDispatchVp. */ + union hv_vp_register_page_interrupt_vectors interrupt_vectors; +} QEMU_PACKED; + #endif /* HW_HYPERV_HVHDK_H */ --=20 2.53.0 From nobody Tue May 26 22:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1779382331; cv=none; d=zohomail.com; s=zohoarc; b=XXEPgLRUUmOOoFoD2Q+KT5W85Hgkx+hr+D2c0nZQnq+h7H6+1LnfnagxzFJWfxneRQbf1gNH7zUz4XVSXgjVOTOerksBTuI8ld+MacsK1C2iHaUcDvAeOcwxGbI3ZCP1ZKR0b7fyRb714+nxFwJPga5FRdQUhMYy1wE8BN7U3vc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779382331; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=n4h4mYEWzTMHu9MUcHkhj8dUWbKeXfr2q3O9DzkwbGk=; b=UviG7M7xfBELKSBxBlMhWpW4pAFyPvnzIT9C5T4chh65sd4z9H1jbt7Teq+WxCDIGWpiNCSZ7Lt5f711I7MwBQTtK2igVqVm/YAqyxcjGYbQXnW3QxTI+mlQ+ed3hqOs2T4gGLXC/22ACqCYWfXSNvgHD5dHAIKN9LSR/vmyBAc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779382331424241.03090577884143; Thu, 21 May 2026 09:52:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6cW-0004VG-2G; Thu, 21 May 2026 12:51:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ6bt-0004Mj-KK for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:05 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6br-00076y-NX for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:01 -0400 Received: from laptop.localdomain (unknown [86.121.140.206]) by linux.microsoft.com (Postfix) with ESMTPSA id B926520B7167; Thu, 21 May 2026 09:50:49 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B926520B7167 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779382251; bh=n4h4mYEWzTMHu9MUcHkhj8dUWbKeXfr2q3O9DzkwbGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=segOrNIJt/gjcQZ+aJAfZJGOYsx+Iah+vOENb3+W0lYR1YMGyN8nBk71ow6Zwh9QN g4Rcz887QhQ7gQAdmtDRZqXwVbYcDQGbmA01WPDV0eN+4dKle33HxL2X4hsbKnt6K/ u3W3mBtu7ONmN6FvBJquY73sJxx3dx3nQIhrqPNQ= From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , Paolo Bonzini , Zhao Liu , Wei Liu , Magnus Kulke , Wei Liu , Magnus Kulke Subject: [PATCH v3 4/7] target/i386/mshv: hv_vp_register_page setup for the vcpu Date: Thu, 21 May 2026 19:50:38 +0300 Message-ID: <20260521165041.131477-5-dblanzeanu@linux.microsoft.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> References: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=dblanzeanu@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1779382333391154100 When the vcpu is created, call mmap to configure access to the register pag= e. In case the call to mmap fails, we log an error and abort to signal there is something wrong with the system. Check the register page version and compare with the expected version and abort in case of a mismatch. Update CPUArchState to store a pointer to the mmapped hv_vp_register_page. Signed-off-by: Doru Bl=C3=A2nzeanu Reviewed-by: Magnus Kulke --- target/i386/cpu.h | 4 ++++ target/i386/mshv/mshv-cpu.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index bdd4fff89d..d772b4c4cc 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2214,6 +2214,10 @@ typedef struct CPUArchState { struct {} end_reset_fields; =20 /* Fields after this point are preserved across CPU reset. */ +#ifdef CONFIG_MSHV + /* Shared register page */ + struct hv_vp_register_page *regs_page; +#endif =20 /* processor features (e.g. for CPUID insn) */ /* Minimum cpuid leaf 7 value */ diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index 9defd05db6..45dc6e6331 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -1587,6 +1587,7 @@ void mshv_arch_init_vcpu(CPUState *cpu) CPUX86State *env =3D &x86_cpu->env; AccelCPUState *state =3D cpu->accel; size_t page =3D HV_HYP_PAGE_SIZE; + void *regs_page; void *mem =3D qemu_memalign(page, 2 * page); =20 /* sanity check, to make sure we don't overflow the page */ @@ -1595,6 +1596,24 @@ void mshv_arch_init_vcpu(CPUState *cpu) + sizeof(hv_input_get_vp_registers) > HV_HYP_PAGE_SIZE)); =20 + + /* mmap the registers page */ + regs_page =3D mmap(NULL, page, PROT_READ | PROT_WRITE, + MAP_SHARED, mshv_vcpufd(cpu), + MSHV_VP_MMAP_OFFSET_REGISTERS * page); + if (regs_page =3D=3D MAP_FAILED) { + /* This shouldn't fail, so we treat it as a fatal error */ + error_report("register page mmap failed: %s", strerror(errno)); + abort(); + } + env->regs_page =3D (struct hv_vp_register_page *) regs_page; + + if (env->regs_page->version !=3D HV_VP_REGISTER_PAGE_VERSION_1) { + error_report("register page version mismatch: got %u, expected %u", + env->regs_page->version, HV_VP_REGISTER_PAGE_VERSION_= 1); + abort(); + } + state->hvcall_args.base =3D mem; state->hvcall_args.input_page =3D mem; state->hvcall_args.output_page =3D (uint8_t *)mem + page; @@ -1608,6 +1627,11 @@ void mshv_arch_destroy_vcpu(CPUState *cpu) CPUX86State *env =3D &x86_cpu->env; AccelCPUState *state =3D cpu->accel; =20 + /* Unmap the register page */ + if (env->regs_page) { + munmap(env->regs_page, HV_HYP_PAGE_SIZE); + env->regs_page =3D NULL; + } g_free(state->hvcall_args.base); state->hvcall_args =3D (MshvHvCallArgs){0}; g_clear_pointer(&env->emu_mmio_buf, g_free); --=20 2.53.0 From nobody Tue May 26 22:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1779382331; cv=none; d=zohomail.com; s=zohoarc; b=j0SL0GoubGlF35UCjMEmWHos3Gf0+gQ72qMHuLyFMSPmmizPcH/sPhni9uPQX+kbq5sBjljyNb0PpHnnqNaEhqTKQikw9rzycdCiKyaFa/GC3cinmS7voxmjz8P1Wt3e11GfmFuLENXmEyI8fY4wGomGmVNOGlf/Vuuwnh6kdzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779382331; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+TH8cWmGlklXi/vqiEG7E4IrjXJbF3Oqz5W2s6/S5c8=; b=jkzR5x+NaKRx/beyaKiJ5NOi/LeTj2j4sY+r1sfklwWQn8whfXpNyofF7sI1Yb95OOV8Cy6gBWyGTbVGYcP/n8QSgYDElbD5VWsEuXWifIXxdqNk29iAtBre05Bizr8l6XP9R+/TgUOa4RFUV3d1+f4mQyVTUz6Cw6QuXd8eePY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779382331871548.5264282007087; Thu, 21 May 2026 09:52:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6cB-0004PW-Cr; Thu, 21 May 2026 12:51:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ6bw-0004NG-SK for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:05 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6bu-000785-Uh for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:04 -0400 Received: from laptop.localdomain (unknown [86.121.140.206]) by linux.microsoft.com (Postfix) with ESMTPSA id 5C7A820B7168; Thu, 21 May 2026 09:50:52 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5C7A820B7168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779382254; bh=+TH8cWmGlklXi/vqiEG7E4IrjXJbF3Oqz5W2s6/S5c8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n4dcxKLKbbqyskfsicBG2a5Q/TFDxYjjzpU2X+34VNIv8OFCPc0y+1kjBnIzrRvI7 LawcUrmUEa9FOyvOQ+XnTPudWsw85X8K0j/E28bOWjWrRJxXvET892M8ZSFb0ikiIU maqq2Bc2kr545kt4IFspU6WVxuQ1PaMZ9lcdcib4= From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , Paolo Bonzini , Zhao Liu , Wei Liu , Magnus Kulke , Wei Liu , Magnus Kulke Subject: [PATCH v3 5/7] target/i386/mshv: use the register page to get registers Date: Thu, 21 May 2026 19:50:39 +0300 Message-ID: <20260521165041.131477-6-dblanzeanu@linux.microsoft.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> References: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=dblanzeanu@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1779382333539158500 Change the mshv_load_regs to use the register page when it is mmapped and is valid. Eliminate the hypercall based logic and fail in case the register page is found in an unexpected state. When retrieving the special registers, there are some registers that are not present in the register page: TR, LDTR, GDTR, IDTR, CR2, APIC_BASE. As this registers are not likely to be used in an MMIO/PIO operation, and to avoid a hypercall overhead we do not retrieve them. Local testing showed no regression when using this logic. To properly retrieve all the necessary registers for each decoded operation implies having a mechanism that tracks the state of each register, which is beyond the scope of this patch series. Signed-off-by: Doru Bl=C3=A2nzeanu Reviewed-by: Magnus Kulke --- accel/mshv/mshv-all.c | 9 +-- include/system/mshv_int.h | 2 +- target/i386/mshv/mshv-cpu.c | 113 +++++++++++++++++++++++++++++------- 3 files changed, 93 insertions(+), 31 deletions(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index e3da583f21..bd3bf557ec 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -666,14 +666,7 @@ static void mshv_cpu_synchronize_pre_loadvm(CPUState *= cpu) static void do_mshv_cpu_synchronize(CPUState *cpu, run_on_cpu_data arg) { if (!cpu->accel->dirty) { - int ret =3D mshv_load_regs(cpu); - if (ret < 0) { - error_report("Failed to load registers for vcpu %d", - cpu->cpu_index); - - cpu_dump_state(cpu, stderr, CPU_DUMP_CODE); - vm_stop(RUN_STATE_INTERNAL_ERROR); - } + mshv_load_regs(cpu); =20 cpu->accel->dirty =3D true; } diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index 35386c422f..a8a59ebf16 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -85,7 +85,7 @@ int mshv_configure_vcpu(const CPUState *cpu, const MshvFP= U *fpu, uint64_t xcr0); int mshv_get_standard_regs(CPUState *cpu); int mshv_get_special_regs(CPUState *cpu); int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *e= xit); -int mshv_load_regs(CPUState *cpu); +void mshv_load_regs(CPUState *cpu); int mshv_store_regs(CPUState *cpu); int mshv_set_generic_regs(const CPUState *cpu, const hv_register_assoc *as= socs, size_t n_regs); diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index 45dc6e6331..500967b53e 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -401,6 +401,80 @@ static void populate_special_regs(const hv_register_as= soc *assocs, cpu_set_apic_base(x86cpu->apic_state, assocs[16].value.reg64); } =20 +static void mshv_get_standard_regs_vp_page(CPUState *cpu) +{ + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + + /* General Purpose Registers */ + env->regs[R_EAX] =3D env->regs_page->rax; + env->regs[R_EBX] =3D env->regs_page->rbx; + env->regs[R_ECX] =3D env->regs_page->rcx; + env->regs[R_EDX] =3D env->regs_page->rdx; + env->regs[R_ESI] =3D env->regs_page->rsi; + env->regs[R_EDI] =3D env->regs_page->rdi; + env->regs[R_ESP] =3D env->regs_page->rsp; + env->regs[R_EBP] =3D env->regs_page->rbp; + env->regs[R_R8] =3D env->regs_page->r8; + env->regs[R_R9] =3D env->regs_page->r9; + env->regs[R_R10] =3D env->regs_page->r10; + env->regs[R_R11] =3D env->regs_page->r11; + env->regs[R_R12] =3D env->regs_page->r12; + env->regs[R_R13] =3D env->regs_page->r13; + env->regs[R_R14] =3D env->regs_page->r14; + env->regs[R_R15] =3D env->regs_page->r15; + + env->eip =3D env->regs_page->rip; + env->eflags =3D env->regs_page->rflags; + rflags_to_lflags(env); +} + +/* + * This function synchronizes the special registers present in the + * register vp page, which are not all the special registers. + * The rest of the special registers (LD, TR, GDT, IDT, CR2, APIC_BASE) + * are not synchronized to avoid the overhead of a hypercall. + * + * These special registers are not normally used by the guest, + * and are only used in some specific cases. + */ +static void mshv_get_special_regs_vp_page(CPUState *cpu) +{ + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + hv_x64_segment_register seg; + + /* Populate special registers that are in the VP register page */ + env->cr[0] =3D env->regs_page->cr0; + env->cr[3] =3D env->regs_page->cr3; + env->cr[4] =3D env->regs_page->cr4; + env->efer =3D env->regs_page->efer; + cpu_set_apic_tpr(x86cpu->apic_state, env->regs_page->cr8); + + /* Segment Registers - copy from packed struct to avoid unaligned acce= ss */ + memcpy(&seg, &env->regs_page->es, sizeof(hv_x64_segment_register)); + populate_segment_reg(&seg, &env->segs[R_ES]); + memcpy(&seg, &env->regs_page->cs, sizeof(hv_x64_segment_register)); + populate_segment_reg(&seg, &env->segs[R_CS]); + memcpy(&seg, &env->regs_page->ss, sizeof(hv_x64_segment_register)); + populate_segment_reg(&seg, &env->segs[R_SS]); + memcpy(&seg, &env->regs_page->ds, sizeof(hv_x64_segment_register)); + populate_segment_reg(&seg, &env->segs[R_DS]); + memcpy(&seg, &env->regs_page->fs, sizeof(hv_x64_segment_register)); + populate_segment_reg(&seg, &env->segs[R_FS]); + memcpy(&seg, &env->regs_page->gs, sizeof(hv_x64_segment_register)); + populate_segment_reg(&seg, &env->segs[R_GS]); +} + +static void mshv_get_registers_vp_page(CPUState *cpu) +{ + /* General Purpose Registers */ + mshv_get_standard_regs_vp_page(cpu); + + /* Special Registers */ + mshv_get_special_regs_vp_page(cpu); +} + =20 int mshv_get_special_regs(CPUState *cpu) { @@ -422,23 +496,26 @@ int mshv_get_special_regs(CPUState *cpu) return 0; } =20 -int mshv_load_regs(CPUState *cpu) +void mshv_load_regs(CPUState *cpu) { - int ret; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; =20 - ret =3D mshv_get_standard_regs(cpu); - if (ret < 0) { - error_report("Failed to load standard registers"); - return -1; + /* Check register page pointer and abort if in unexpected state */ + if (!env->regs_page) { + error_report( + "load regs: register page not set for vcpu %d", + cpu->cpu_index); + abort(); } - - ret =3D mshv_get_special_regs(cpu); - if (ret < 0) { - error_report("Failed to load special registers"); - return -1; + if (env->regs_page->isvalid =3D=3D 0) { + error_report( + "load regs: register page invalid for vcpu %d", + cpu->cpu_index); + abort(); } =20 - return 0; + mshv_get_registers_vp_page(cpu); } =20 static void add_cpuid_entry(GList *cpuid_entries, @@ -1103,11 +1180,7 @@ static int emulate_instruction(CPUState *cpu, int ret; x86_insn_stream stream =3D { .bytes =3D insn_bytes, .len =3D insn_len = }; =20 - ret =3D mshv_load_regs(cpu); - if (ret < 0) { - error_report("failed to load registers"); - return -1; - } + mshv_load_regs(cpu); =20 decode_instruction_stream(env, &decode, &stream); exec_instruction(env, &decode); @@ -1410,11 +1483,7 @@ static int handle_pio_str(CPUState *cpu, hv_x64_io_p= ort_intercept_message *info) X86CPU *x86_cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86_cpu->env; =20 - ret =3D mshv_load_regs(cpu); - if (ret < 0) { - error_report("Failed to fetch guest state"); - return -1; - } + mshv_load_regs(cpu); =20 direction_flag =3D (env->eflags & DESC_E_MASK) !=3D 0; =20 --=20 2.53.0 From nobody Tue May 26 22:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1779382331; cv=none; d=zohomail.com; s=zohoarc; b=M2awzQpcde6/fc/c5wfNEH/elOA2nj89mXkmBsNTGzudEcGtzbplobJ2xkNnlqUv3HPGijrALPTAG9d8+HYGyO51/ODlpQpWzRjPQai49ZalUG0xMdfTGX7j1PIgQXUIW58fEEIILyzHGXWGcltAweTAvqkgqPT+YqQA/vrR7GM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779382331; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ra3UPx5dVax89EnvKy9scLgsiN2gpmwZB5nPfld3f80=; b=dWL1WTKWDOxmPyunKCLNVjvKoBuGq3OtsS082en+P8SOfCU8EZle7KKiWYwBvgQDmdtfdezyFH4G8lPAE7druu08CeU/A1LhIkHE1Iobfe9JMkjLMjv9QBd+s+PTZARes1iTQsKAkcuyiEgPI5wG7VYumv3KeKJfGBlXFr9t0mk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779382331217345.7975703574016; Thu, 21 May 2026 09:52:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6cB-0004Q1-L7; Thu, 21 May 2026 12:51:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ6bz-0004OG-KG for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:07 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6bx-00078l-BY for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:07 -0400 Received: from laptop.localdomain (unknown [86.121.140.206]) by linux.microsoft.com (Postfix) with ESMTPSA id 2D11620B7167; Thu, 21 May 2026 09:50:54 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2D11620B7167 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779382257; bh=ra3UPx5dVax89EnvKy9scLgsiN2gpmwZB5nPfld3f80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EnULu5qNW+qnlvyiD5n4vpPaXR2FCbguqnn9LKuXwdAoiLsStfzH78sfm1zDEBWzj rnH1dS631BLnAIMKEG3vgc9lqd0Uq1hrt3ZSYSzjEEnh2y8T9Aoor7W1WHhQtlZJMp lYFczlxSPrKxeNsclNkIq1EDxICR5OMBMGvlqejs= From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , Paolo Bonzini , Zhao Liu , Wei Liu , Magnus Kulke , Wei Liu , Magnus Kulke Subject: [PATCH v3 6/7] target/i386/mshv: use the register page to set registers Date: Thu, 21 May 2026 19:50:40 +0300 Message-ID: <20260521165041.131477-7-dblanzeanu@linux.microsoft.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> References: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=dblanzeanu@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1779382333590158500 Update mshv_store_regs to use the register page when it is mmapped and valid to set registers. Remove the ioctl based register retrieval and fail in case the register page is not correctly set or valid. Signed-off-by: Doru Bl=C3=A2nzeanu --- include/system/mshv_int.h | 2 +- target/i386/mshv/mshv-cpu.c | 70 ++++++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index a8a59ebf16..c2bc36ec60 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -86,7 +86,7 @@ int mshv_get_standard_regs(CPUState *cpu); int mshv_get_special_regs(CPUState *cpu); int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *e= xit); void mshv_load_regs(CPUState *cpu); -int mshv_store_regs(CPUState *cpu); +void mshv_store_regs(CPUState *cpu); int mshv_set_generic_regs(const CPUState *cpu, const hv_register_assoc *as= socs, size_t n_regs); int mshv_arch_put_registers(const CPUState *cpu); diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index 500967b53e..a2bc29abd4 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -285,17 +285,56 @@ static int set_standard_regs(const CPUState *cpu) return 0; } =20 -int mshv_store_regs(CPUState *cpu) +static void mshv_set_standard_regs_vp_page(CPUState *cpu) { - int ret; + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; =20 - ret =3D set_standard_regs(cpu); - if (ret < 0) { - error_report("Failed to store standard registers"); - return -1; + env->regs_page->rax =3D env->regs[R_EAX]; + env->regs_page->rbx =3D env->regs[R_EBX]; + env->regs_page->rcx =3D env->regs[R_ECX]; + env->regs_page->rdx =3D env->regs[R_EDX]; + env->regs_page->rsi =3D env->regs[R_ESI]; + env->regs_page->rdi =3D env->regs[R_EDI]; + env->regs_page->rsp =3D env->regs[R_ESP]; + env->regs_page->rbp =3D env->regs[R_EBP]; + env->regs_page->r8 =3D env->regs[R_R8]; + env->regs_page->r9 =3D env->regs[R_R9]; + env->regs_page->r10 =3D env->regs[R_R10]; + env->regs_page->r11 =3D env->regs[R_R11]; + env->regs_page->r12 =3D env->regs[R_R12]; + env->regs_page->r13 =3D env->regs[R_R13]; + env->regs_page->r14 =3D env->regs[R_R14]; + env->regs_page->r15 =3D env->regs[R_R15]; + env->regs_page->rip =3D env->eip; + lflags_to_rflags(env); + env->regs_page->rflags =3D env->eflags; + + env->regs_page->dirty |=3D (1u << HV_X64_REGISTER_CLASS_GENERAL) + | (1u << HV_X64_REGISTER_CLASS_IP) + | (1u << HV_X64_REGISTER_CLASS_FLAGS); +} + +void mshv_store_regs(CPUState *cpu) +{ + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + + /* Check register page pointer and abort if in unexpected state */ + if (!env->regs_page) { + error_report( + "store regs: register page not set for vcpu %d", + cpu->cpu_index); + abort(); + } + if (env->regs_page->isvalid =3D=3D 0) { + error_report( + "store regs: register page invalid for vcpu %d", + cpu->cpu_index); + abort(); } =20 - return 0; + mshv_set_standard_regs_vp_page(cpu); } =20 static void populate_standard_regs(const hv_register_assoc *assocs, @@ -1170,14 +1209,13 @@ static int set_memory_info(const struct hyperv_mess= age *msg, return 0; } =20 -static int emulate_instruction(CPUState *cpu, +static void emulate_instruction(CPUState *cpu, const uint8_t *insn_bytes, size_t insn_len, uint64_t gva, uint64_t gpa) { X86CPU *x86_cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86_cpu->env; struct x86_decode decode =3D { 0 }; - int ret; x86_insn_stream stream =3D { .bytes =3D insn_bytes, .len =3D insn_len = }; =20 mshv_load_regs(cpu); @@ -1185,13 +1223,7 @@ static int emulate_instruction(CPUState *cpu, decode_instruction_stream(env, &decode, &stream); exec_instruction(env, &decode); =20 - ret =3D mshv_store_regs(cpu); - if (ret < 0) { - error_report("failed to store registers"); - return -1; - } - - return 0; + mshv_store_regs(cpu); } =20 static int handle_mmio(CPUState *cpu, const struct hyperv_message *msg, @@ -1227,13 +1259,9 @@ static int handle_mmio(CPUState *cpu, const struct h= yperv_message *msg, =20 instruction_bytes =3D info.instruction_bytes; =20 - ret =3D emulate_instruction(cpu, instruction_bytes, insn_len, + emulate_instruction(cpu, instruction_bytes, insn_len, info.guest_virtual_address, info.guest_physical_address); - if (ret < 0) { - error_report("failed to emulate mmio"); - return -1; - } =20 *exit_reason =3D MshvVmExitIgnore; =20 --=20 2.53.0 From nobody Tue May 26 22:32:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1779382376; cv=none; d=zohomail.com; s=zohoarc; b=mecqhQKd7nLkwIJR9wtgptXzHoPPN7i69tRzH1+Xoq5CyN3q1q/c1hDjYwa45Vr/Z9bJH/oN7X0Bq9E3EspT1Ro7zMLtG/PhAp+rXvMrmTF1Iyd7UFLxn8yQSi1aI4K8lqjl9kG9Hh/0R6dSeG+MCAk8B7HsOcshczTYibX89m8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779382376; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XH+JRGJXKCFRmrWjSkiZ8RWMbcx1sY7JXUEnLVWDxwY=; b=kphXJnHL/K1k1Y4GWduRaLP9vfW0rMHVKW8MQOxa4/61KD8wctKF19VrL2pJRuSXNbqYFTWjHiLGj6IvdWDwO1keCvlIMgTH3jayOQ6Pz2NJALTP9bKwyFuzq76xmevFRsb/q7k5ZoAY89xLewdrw14cvLvj7WF4iTrnTi+9SN8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17793823761451023.2721509596315; Thu, 21 May 2026 09:52:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6cW-0004Vf-8t; Thu, 21 May 2026 12:51:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ6c3-0004Ov-Ct for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:11 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ6c1-00079H-H0 for qemu-devel@nongnu.org; Thu, 21 May 2026 12:51:11 -0400 Received: from laptop.localdomain (unknown [86.121.140.206]) by linux.microsoft.com (Postfix) with ESMTPSA id D058120B7168; Thu, 21 May 2026 09:50:57 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D058120B7168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779382259; bh=XH+JRGJXKCFRmrWjSkiZ8RWMbcx1sY7JXUEnLVWDxwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+zyRBy7klpv7kkG/pEwV6rfxqIqNn2YV4GmSSE/7F5gi7fz9mk5WOEeAyyPHGcHc j1d03q2TzRseMwjQwbXGp3zG49d+wp9H1f6g8mxOuJ4uqfAqjurckvPQeT2VbZf8uh 2HshEUP5bd8//5h1wCU3MkNU36NsGzsqeuIU/DzQ= From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= , Paolo Bonzini , Zhao Liu , Wei Liu , Magnus Kulke , Wei Liu , Magnus Kulke Subject: [PATCH v3 7/7] target/i386/mshv: fix pio handlers clobbering device-modified registers Date: Thu, 21 May 2026 19:50:41 +0300 Message-ID: <20260521165041.131477-8-dblanzeanu@linux.microsoft.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> References: <20260521165041.131477-1-dblanzeanu@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=dblanzeanu@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1779382377701154100 When a device handler (e.g. vmport) calls cpu_synchronize_state() during I/O port dispatch, it sets cpu->accel->dirty =3D true and may modify registers directly in env. The old PIO code ignored this: it unconditionally wrote the stale info->rax from the VM-exit intercept message back to the hypervisor and then cleared dirty, discarding any register changes made by the device. Bifurcate both handlers on cpu->accel->dirty: handle_pio_non_str: - dirty path: update env->eip directly. For reads (IN), merge the I/O result into env->regs[R_EAX] (which may have been modified by the device) rather than info->rax. For writes (OUT), leave RAX untouched. Flush all registers via mshv_store_regs() and clear dirty. - non-dirty path: write RIP and RAX via set_x64_registers hypercall as before. handle_pio_str: - dirty path: update env->eip and the appropriate index register (RSI for OUTS, RDI for INS) directly. Flush via mshv_store_regs() and clear dirty. - non-dirty path: write the index register and RIP via set_x64_registers. Drop the RAX assignment that was here before; string I/O does not modify RAX, and set_x64_registers is hardcoded to write only 2 registers so the third slot was silently ignored anyway. Remove the unconditional "cpu->accel->dirty =3D false" at the end of both handlers. In the non-dirty fast path it was redundant (already false). In the dirty path it was actively harmful: it told the vcpu run loop that env was clean when it was not, losing the device's modifications. Signed-off-by: Doru Bl=C3=A2nzeanu Reviewed-by: Magnus Kulke --- target/i386/mshv/mshv-cpu.c | 74 +++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index a2bc29abd4..60d21cedbb 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -1331,7 +1331,7 @@ static int pio_write(uint64_t port, const uint8_t *da= ta, uintptr_t size, return ret; } =20 -static int handle_pio_non_str(const CPUState *cpu, +static int handle_pio_non_str(CPUState *cpu, hv_x64_io_port_intercept_message *info) { size_t len =3D info->access_info.access_size; @@ -1340,10 +1340,12 @@ static int handle_pio_non_str(const CPUState *cpu, uint32_t val, eax; const uint32_t eax_mask =3D 0xffffffffu >> (32 - len * 8); size_t insn_len; - uint64_t rip, rax; + uint64_t rip; uint32_t reg_names[2]; uint64_t reg_values[2]; uint16_t port =3D info->port_number; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; =20 if (access_type =3D=3D HV_X64_INTERCEPT_ACCESS_TYPE_WRITE) { union { @@ -1374,21 +1376,36 @@ static int handle_pio_non_str(const CPUState *cpu, =20 /* Advance RIP and update RAX */ rip =3D info->header.rip + insn_len; - rax =3D info->rax; =20 - reg_names[0] =3D HV_X64_REGISTER_RIP; - reg_values[0] =3D rip; - reg_names[1] =3D HV_X64_REGISTER_RAX; - reg_values[1] =3D rax; + if (cpu->accel->dirty) { + env->eip =3D rip; + if (access_type !=3D HV_X64_INTERCEPT_ACCESS_TYPE_WRITE) { + /* + * For reads, merge the I/O result into the current RAX. + * Use env->regs[R_EAX] as the base since a device handler + * (e.g. vmport) may have called cpu_synchronize_state() + * and modified registers. + */ + eax =3D (((uint32_t)env->regs[R_EAX]) & ~eax_mask) + | (val & eax_mask); + env->regs[R_EAX] =3D (uint64_t)eax; + } + /* Sync modified standard registers back and clear dirty. */ + mshv_store_regs(cpu); + cpu->accel->dirty =3D false; + } else { + reg_names[0] =3D HV_X64_REGISTER_RIP; + reg_values[0] =3D rip; + reg_names[1] =3D HV_X64_REGISTER_RAX; + reg_values[1] =3D info->rax; =20 - ret =3D set_x64_registers(cpu, reg_names, reg_values); - if (ret < 0) { - error_report("Failed to set x64 registers"); - return -1; + ret =3D set_x64_registers(cpu, reg_names, reg_values); + if (ret < 0) { + error_report("Failed to set x64 registers"); + return -1; + } } =20 - cpu->accel->dirty =3D false; - return 0; } =20 @@ -1504,6 +1521,7 @@ static int handle_pio_str(CPUState *cpu, hv_x64_io_po= rt_intercept_message *info) bool repop =3D info->access_info.rep_prefix =3D=3D 1; size_t repeat =3D repop ? info->rcx : 1; size_t insn_len =3D info->header.instruction_length; + uint64_t rip; bool direction_flag; uint32_t reg_names[3]; uint64_t reg_values[3]; @@ -1533,18 +1551,28 @@ static int handle_pio_str(CPUState *cpu, hv_x64_io_= port_intercept_message *info) reg_values[0] =3D info->rdi; } =20 - reg_names[1] =3D HV_X64_REGISTER_RIP; - reg_values[1] =3D info->header.rip + insn_len; - reg_names[2] =3D HV_X64_REGISTER_RAX; - reg_values[2] =3D info->rax; + rip =3D info->header.rip + insn_len; =20 - ret =3D set_x64_registers(cpu, reg_names, reg_values); - if (ret < 0) { - error_report("Failed to set x64 registers"); - return -1; - } + if (cpu->accel->dirty) { + env->eip =3D rip; + if (access_type =3D=3D HV_X64_INTERCEPT_ACCESS_TYPE_WRITE) { + env->regs[R_ESI] =3D info->rsi; + } else { + env->regs[R_EDI] =3D info->rdi; + } + /* Sync modified standard registers back and clear dirty. */ + mshv_store_regs(cpu); + cpu->accel->dirty =3D false; + } else { + reg_names[1] =3D HV_X64_REGISTER_RIP; + reg_values[1] =3D rip; =20 - cpu->accel->dirty =3D false; + ret =3D set_x64_registers(cpu, reg_names, reg_values); + if (ret < 0) { + error_report("Failed to set x64 registers"); + return -1; + } + } =20 return 0; } --=20 2.53.0