From nobody Thu Dec 18 11:33:33 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0EC03145FE0; Thu, 26 Dec 2024 20:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735245054; cv=none; b=PSn0z8wmRnuW8WTI7l7EWgk0EeqDLJZLIw2GM6HpT8lteMlH8OwfNwhfMiXV7vCy19WYCV/BPS0K3sEdoeWmIOL2VBCzkGA7CHMvz4K8fYzxbUGoowDx1pF9XwPDR19u7GFXLroBH3lvvUfY8jP3r3hR5Dz6TZPII19oVS7WXp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735245054; c=relaxed/simple; bh=NRkCjRnkhySE+BcClf+onZvPISWdYGLXxqfdEBq6MW4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gYzLolvuahwskHQB+pJ109Ve/JEpNW7cAc80HjfQLJPVYva/WbP02R8FtDtnLJLSn57eck6NKnGSaKhZaEdvn8njEf0GmkB0x2Six3Brm3e9pV9HenWlC898iz0IaE16KeU3tXmYriGawm0qq4dcH3c1geZZupGreUcx1RxY8xI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=kWXnLmSd; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="kWXnLmSd" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 7908E203EC24; Thu, 26 Dec 2024 12:30:52 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7908E203EC24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1735245052; bh=ry0dde5x4r+6U0CVAjvuGCMTA9d6rF8pmhm+rOPKAfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kWXnLmSdDLLQhzu9vL74ileaK5i9Fuy0Y6/pZBPBtHgUX+GhKSTQEj6g/ySOecYdP fgLgriLtzp2Mmx8c8S8ijaOFdKYPLeMM5AH9W8xUqhNkYDzANXe6Q/Wg9IxslSEtk6 dhNpy55rV1n/SGOKZp+NVHQXiQh3c4GYSC9PJ8zw= From: Roman Kisel To: hpa@zytor.com, kys@microsoft.com, bp@alien8.de, dave.hansen@linux.intel.com, decui@microsoft.com, eahariha@linux.microsoft.com, haiyangz@microsoft.com, mingo@redhat.com, mhklinux@outlook.com, nunodasneves@linux.microsoft.com, tglx@linutronix.de, tiala@microsoft.com, wei.liu@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v2 1/3] hyperv: Define struct hv_output_get_vp_registers Date: Thu, 26 Dec 2024 12:30:48 -0800 Message-Id: <20241226203050.800524-2-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241226203050.800524-1-romank@linux.microsoft.com> References: <20241226203050.800524-1-romank@linux.microsoft.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 Content-Type: text/plain; charset="utf-8" There is no definition of the output structure for the GetVpRegisters hypercall. Hence, using the hypercall is not possible when the output value has some structure to it. Even getting a datum of a primitive type reads as ad-hoc without that definition. Define struct hv_output_get_vp_registers to enable using the GetVpRegisters hypercall. Make provisions for all supported architectures. No functional changes. Signed-off-by: Roman Kisel --- include/hyperv/hvgdk_mini.h | 58 +++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h index db3d1aaf7330..31c11550af73 100644 --- a/include/hyperv/hvgdk_mini.h +++ b/include/hyperv/hvgdk_mini.h @@ -781,6 +781,8 @@ struct hv_timer_message_payload { __u64 delivery_time; /* When the message was delivered */ } __packed; =20 +#if defined(CONFIG_X86) + struct hv_x64_segment_register { u64 base; u32 limit; @@ -807,6 +809,8 @@ struct hv_x64_table_register { u64 base; } __packed; =20 +#endif + union hv_input_vtl { u8 as_uint8; struct { @@ -1068,6 +1072,41 @@ union hv_dispatch_suspend_register { } __packed; }; =20 +#if defined(CONFIG_ARM64) + +union hv_arm64_pending_interruption_register { + u64 as_uint64; + struct { + u64 interruption_pending : 1; + u64 interruption_type : 1; + u64 reserved : 30; + u32 error_code; + } __packed; +}; + +union hv_arm64_interrupt_state_register { + u64 as_uint64; + struct { + u64 interrupt_shadow : 1; + u64 reserved : 63; + } __packed; +}; + +union hv_arm64_pending_synthetic_exception_event { + u64 as_uint64[2]; + struct { + u32 event_pending : 1; + u32 event_type : 3; + u32 reserved : 4; + u32 exception_type; + u64 context; + } __packed; +}; + +#endif + +#if defined(CONFIG_X86) + union hv_x64_interrupt_state_register { u64 as_uint64; struct { @@ -1091,6 +1130,8 @@ union hv_x64_pending_interruption_register { } __packed; }; =20 +#endif + union hv_register_value { struct hv_u128 reg128; u64 reg64; @@ -1098,13 +1139,26 @@ union hv_register_value { u16 reg16; u8 reg8; =20 - struct hv_x64_segment_register segment; - struct hv_x64_table_register table; union hv_explicit_suspend_register explicit_suspend; union hv_intercept_suspend_register intercept_suspend; union hv_dispatch_suspend_register dispatch_suspend; +#if defined(CONFIG_X86) + struct hv_x64_segment_register segment; + struct hv_x64_table_register table; union hv_x64_interrupt_state_register interrupt_state; union hv_x64_pending_interruption_register pending_interruption; +#elif defined(CONFIG_ARM64) + union hv_arm64_pending_interruption_register pending_interruption; + union hv_arm64_interrupt_state_register interrupt_state; + union hv_arm64_pending_synthetic_exception_event pending_synthetic_except= ion_event; +#else + #error "This architecture is not supported" +#endif +}; + +/* NOTE: Linux helper struct - NOT from Hyper-V code */ +struct hv_output_get_vp_registers { + DECLARE_FLEX_ARRAY(union hv_register_value, values); }; =20 #if defined(CONFIG_ARM64) --=20 2.34.1 From nobody Thu Dec 18 11:33:33 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 704561494CC; Thu, 26 Dec 2024 20:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735245054; cv=none; b=Vs6I8SgrbdfK465jmoNqTqqmY2mc49Xr4yRtHJMwHRAhae53FbSg5eVOHBeRoq1hqDPlkfoL0vj3/MIAYnhmhYuYnRt/vG01rYepEPj14Oy+fJYgs6Kya/sVpEtipw+TI9RdMkcRa9iSPn5kkNeagknQ52FqHKACVLQ/JCHJh/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735245054; c=relaxed/simple; bh=HoFMyxPQ4+vHjO5aNu8dprTKaB0BfQ/OCxXps0eLfws=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DL7IlrqKwodbobES2Wjnopi7/9CiYVD6a+mWTnnPKC+6H1Sk7YOHjOCh61dcczVlkZrdZGbrIOGzucUA0kbA4cOUahQ3tIvDng0i4sLU6dV42mqvOoGozhOgxxl4eKfQ0jnlGiAbssjv07HEFLtN6AhzYzzrL8Z3decJf7TUBBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=s1WDabHG; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="s1WDabHG" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id B85E2203EC26; Thu, 26 Dec 2024 12:30:52 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B85E2203EC26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1735245052; bh=n/7BbD0J/6ZyeZxeLEf6nxi13TKSTWUcLtaICTY9HoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s1WDabHGwwVqTvucnCmigA1wNzXsCkYxzktf+NQ03yBw4tYsrSblO4tFLwymO3hll np30Y5oDya8YYb4RUJy8bo/bPPxuWg78nrlkE6yZPhsiUlTOOd23H0yZJvxY0E6t/I t7vFlBfp2FPWj8gZlBeMUjzXhXByz5AZf9SL6KuU= From: Roman Kisel To: hpa@zytor.com, kys@microsoft.com, bp@alien8.de, dave.hansen@linux.intel.com, decui@microsoft.com, eahariha@linux.microsoft.com, haiyangz@microsoft.com, mingo@redhat.com, mhklinux@outlook.com, nunodasneves@linux.microsoft.com, tglx@linutronix.de, tiala@microsoft.com, wei.liu@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v2 2/3] hyperv: Fix pointer type for the output of the hypercall in get_vtl(void) Date: Thu, 26 Dec 2024 12:30:49 -0800 Message-Id: <20241226203050.800524-3-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241226203050.800524-1-romank@linux.microsoft.com> References: <20241226203050.800524-1-romank@linux.microsoft.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 Content-Type: text/plain; charset="utf-8" Commit bc905fa8b633 ("hyperv: Switch from hyperv-tlfs.h to hyperv/hvhdk.h") changed the type of the output pointer to `struct hv_register_assoc` from `struct hv_get_vp_registers_output`. That leads to an incorrect computation, and leaves the system broken. Use the correct pointer type for the output of the GetVpRegisters hypercall. Signed-off-by: Roman Kisel --- arch/x86/hyperv/hv_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 3cf2a227d666..ba469d6b8250 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -416,13 +416,13 @@ static u8 __init get_vtl(void) { u64 control =3D HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS; struct hv_input_get_vp_registers *input; - struct hv_register_assoc *output; + struct hv_output_get_vp_registers *output; unsigned long flags; u64 ret; =20 local_irq_save(flags); input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D (struct hv_register_assoc *)input; + output =3D (struct hv_output_get_vp_registers *)input; =20 memset(input, 0, struct_size(input, names, 1)); input->partition_id =3D HV_PARTITION_ID_SELF; @@ -432,7 +432,7 @@ static u8 __init get_vtl(void) =20 ret =3D hv_do_hypercall(control, input, output); if (hv_result_success(ret)) { - ret =3D output->value.reg8 & HV_X64_VTL_MASK; + ret =3D output->values[0].reg8 & HV_X64_VTL_MASK; } else { pr_err("Failed to get VTL(error: %lld) exiting...\n", ret); BUG(); --=20 2.34.1 From nobody Thu Dec 18 11:33:33 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A92AE15B12A; Thu, 26 Dec 2024 20:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735245055; cv=none; b=Tr1dIhc9gQ7136GbvIwQFqlonnmk2dcEKuL52Sd1CP3ooRvYpbwd1Fg/pnkBScOYUkyIXiEZHyqE+lTsON9UeTY2pyq6qTSIdQVL129EzO9UW23OBeLqO+Xix91RUSNrpdNEjKBeC2oNhz8rGcqQYR5R9J5stiNtsHNYl75yETA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735245055; c=relaxed/simple; bh=8V3SdDAjo5hYZEYWGigqLpYTv9096EwohgpIUxpEcoQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rH/VO2WgT640nOL+9q7oox4h4/2UxBMhqIlE/sHeLUvzKbyBhdsdc9ixr+m08Yr84BCQZp4KbcVIePY0voEVRv2bJyPw8plzO/eOlw08bb11JOul+Kz+lrxscx7055YRh/+aHQUbzyvONH6Xyyp+oqZYin9FcVnbB7pALpBoXd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=VWw8gEQL; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="VWw8gEQL" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 032A1203EC25; Thu, 26 Dec 2024 12:30:53 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 032A1203EC25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1735245053; bh=n3Rya0oa1MLjPmSnHsEzA1dUh4UC9i89NnBD409hxC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VWw8gEQLMfGA9C7XPWDGGktgxvMQnRJ9k2LysLPD+Hd+4ID4ZwggOdxOiTB6n89kP eU3SM960wykfQqZEPXAClvXJNvuvi1ukYyg/ljjvAL3iCJmNdu20VuIgG2QPQ1q369 jiQIPD6ofrde/Gy/52y/NRH0cGiz8yWuIJoq/GfQ= From: Roman Kisel To: hpa@zytor.com, kys@microsoft.com, bp@alien8.de, dave.hansen@linux.intel.com, decui@microsoft.com, eahariha@linux.microsoft.com, haiyangz@microsoft.com, mingo@redhat.com, mhklinux@outlook.com, nunodasneves@linux.microsoft.com, tglx@linutronix.de, tiala@microsoft.com, wei.liu@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v2 3/3] hyperv: Do not overlap the input and output hypercall areas in get_vtl(void) Date: Thu, 26 Dec 2024 12:30:50 -0800 Message-Id: <20241226203050.800524-4-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241226203050.800524-1-romank@linux.microsoft.com> References: <20241226203050.800524-1-romank@linux.microsoft.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 Content-Type: text/plain; charset="utf-8" The Top-Level Functional Specification for Hyper-V, Section 3.6 [1, 2], disallows overlapping of the input and output hypercall areas, and get_vtl(void) does overlap them. To fix this, enable allocation of the output hypercall pages when running in the VTL mode and use the output hypercall page of the current vCPU for the hypercall. [1] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlf= s/hypercall-interface [2] https://github.com/MicrosoftDocs/Virtualization-Documentation/tree/main= /tlfs Fixes: 8387ce06d70b ("x86/hyperv: Set Virtual Trust Level in VMBus init mes= sage") Signed-off-by: Roman Kisel --- arch/x86/hyperv/hv_init.c | 2 +- drivers/hv/hv_common.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index ba469d6b8250..cf3f7d30fcdd 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -422,7 +422,7 @@ static u8 __init get_vtl(void) =20 local_irq_save(flags); input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D (struct hv_output_get_vp_registers *)input; + output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); =20 memset(input, 0, struct_size(input, names, 1)); input->partition_id =3D HV_PARTITION_ID_SELF; diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index c4fd07d9bf1a..5178beed6ca8 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -340,7 +340,7 @@ int __init hv_common_init(void) BUG_ON(!hyperv_pcpu_input_arg); =20 /* Allocate the per-CPU state for output arg for root */ - if (hv_root_partition) { + if (hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE)) { hyperv_pcpu_output_arg =3D alloc_percpu(void *); BUG_ON(!hyperv_pcpu_output_arg); } @@ -435,7 +435,7 @@ int hv_common_cpu_init(unsigned int cpu) void **inputarg, **outputarg; u64 msr_vp_index; gfp_t flags; - int pgcount =3D hv_root_partition ? 2 : 1; + const int pgcount =3D (hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_= MODE)) ? 2 : 1; void *mem; int ret; =20 @@ -453,7 +453,7 @@ int hv_common_cpu_init(unsigned int cpu) if (!mem) return -ENOMEM; =20 - if (hv_root_partition) { + if (hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE)) { outputarg =3D (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg =3D (char *)mem + HV_HYP_PAGE_SIZE; } --=20 2.34.1