From patchwork Thu Nov 24 06:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3214427wrr; Wed, 23 Nov 2022 22:04:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf78eLvy0pyrRd8twT4+PbueVpox7pCosf06J2WFHC8uGuYSJc09StV4jqhtrVF8FkuPCedk X-Received: by 2002:a63:e509:0:b0:474:4380:cca6 with SMTP id r9-20020a63e509000000b004744380cca6mr10305823pgh.229.1669269883972; Wed, 23 Nov 2022 22:04:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269883; cv=none; d=google.com; s=arc-20160816; b=vh9LKXg8sQC17Ae/3tYfG229E5BceisAdNevGCLg6wh7M9RKSd//Hy6CMbnf77Icfx 2BXuxliHvLWrWIB243+/MVWhqZ+6+2sHmw4bkLY2bs5LyP1YE1+Ll4t+xHfOdZ315cQp yFyQMSfg2o6r7b6R7qvAErqW3Sb4O9o0YbWjhaSeNA180Ml26fNEVWq4ctZ1F+tRUKwH WxU+jPyS3I+V/I6A6ucOKokjrOq4GmiG5P1Jn3n6wTxdYiHyNFBjRYG/hatKS5VBtcHb f1YV5Z3v8N1dBFhdmgfSZmuuEZ8wYByWBE8OYBvjfo4SzbvftxdHe8RRtLvqLVMWzoZn hb3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=URaETM0X98/Nxpa8Blvr2XLRxJkzLP12K+95AYQ8A54=; b=mD8YzDLH6N0brCxkT/mNwukap55cR1dVJl6gXh5VR2tKVKbb3xonhgLDqD4dVmvIj9 Z5G2sKt73GzGUmF+Q8iluOJHcJvlT5j2CTyjHRsh09uffy29cxnkE1aHCs2Q8dDajy8+ L8OfKT+eT95gNGkXaq11qlUPZyid1ciV2ek1+xwyGi8Q8lAD5lo4BkcUiGGeWR0FTS+J IFHcV5PYVYA98BBXki4VkXflsSSf1NfNdb4840VfV3uYqPMxneRa+fA8PiCK8xa5xEQ7 wt+VBn6FdfrkvrvyvXO2QlVdgCibKFNPbXAu/vPLLWpavQOiJslNl7YQb2hrHtuuaxuF 6hEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=IvuS3BVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i18-20020a170902cf1200b001871c762261si216243plg.189.2022.11.23.22.04.30; Wed, 23 Nov 2022 22:04:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=IvuS3BVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229508AbiKXGC0 (ORCPT + 99 others); Thu, 24 Nov 2022 01:02:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbiKXGCW (ORCPT ); Thu, 24 Nov 2022 01:02:22 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EFD96C7222; Wed, 23 Nov 2022 22:02:21 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 3F45020B83CB; Wed, 23 Nov 2022 22:02:17 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3F45020B83CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269741; bh=URaETM0X98/Nxpa8Blvr2XLRxJkzLP12K+95AYQ8A54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvuS3BVv9gcJCq5wOI/zb4MGw8kjdnzgEAUhPU2qSSNWs6QRNqNQHwCrayoEYAq2w K/QJ8O2wKw3aHU0ah3HNEVblmQwNfT2rgAX9wyKqdWtsykLuibGSV9WMB+Zh6sKMeJ zFu1uVOYIdwPsrZW1ni6kYdSyCbOpJ0+EK99Dqlw= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, peterz@infradead.org, jpoimboe@kernel.org, jinankjain@linux.microsoft.com, seanjc@google.com, kirill.shutemov@linux.intel.com, ak@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, anrayabh@linux.microsoft.com, mikelley@microsoft.com Subject: [PATCH v6 1/5] x86/hyperv: Add support for detecting nested hypervisor Date: Thu, 24 Nov 2022 06:02:06 +0000 Message-Id: <76e16159610f665c279259672d03c1ce4e52bd62.1669269377.git.jinankjain@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750356337785464324?= X-GMAIL-MSGID: =?utf-8?q?1750356337785464324?= Detect if Linux is running as a nested hypervisor in the root partition for Microsoft Hypervisor, using flags provided by MSHV. Expose a new variable hv_nested that is used later for decisions specific to the nested use case. Signed-off-by: Jinank Jain --- arch/x86/include/asm/hyperv-tlfs.h | 3 +++ arch/x86/kernel/cpu/mshyperv.c | 7 +++++++ drivers/hv/hv_common.c | 9 ++++++--- include/asm-generic/mshyperv.h | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 6d9368ea3701..58c03d18c235 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -114,6 +114,9 @@ /* Recommend using the newer ExProcessorMasks interface */ #define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED BIT(11) +/* Indicates that the hypervisor is nested within a Hyper-V partition. */ +#define HV_X64_HYPERV_NESTED BIT(12) + /* Recommend using enlightened VMCS */ #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 831613959a92..9a4204139490 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -37,6 +37,8 @@ /* Is Linux running as the root partition? */ bool hv_root_partition; +/* Is Linux running on nested Microsoft Hypervisor */ +bool hv_nested; struct ms_hyperv_info ms_hyperv; #if IS_ENABLED(CONFIG_HYPERV) @@ -301,6 +303,11 @@ static void __init ms_hyperv_init_platform(void) pr_info("Hyper-V: running as root partition\n"); } + if (ms_hyperv.hints & HV_X64_HYPERV_NESTED) { + hv_nested = true; + pr_info("Hyper-V: running on a nested hypervisor\n"); + } + /* * Extract host information. */ diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index ae68298c0dca..52a6f89ccdbd 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -25,17 +25,20 @@ #include /* - * hv_root_partition and ms_hyperv are defined here with other Hyper-V - * specific globals so they are shared across all architectures and are + * hv_root_partition, ms_hyperv and hv_nested are defined here with other + * Hyper-V specific globals so they are shared across all architectures and are * built only when CONFIG_HYPERV is defined. But on x86, * ms_hyperv_init_platform() is built even when CONFIG_HYPERV is not - * defined, and it uses these two variables. So mark them as __weak + * defined, and it uses these three variables. So mark them as __weak * here, allowing for an overriding definition in the module containing * ms_hyperv_init_platform(). */ bool __weak hv_root_partition; EXPORT_SYMBOL_GPL(hv_root_partition); +bool __weak hv_nested; +EXPORT_SYMBOL_GPL(hv_nested); + struct ms_hyperv_info __weak ms_hyperv; EXPORT_SYMBOL_GPL(ms_hyperv); diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index bfb9eb9d7215..5df6e944e6a9 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -164,6 +164,7 @@ extern int vmbus_interrupt; extern int vmbus_irq; extern bool hv_root_partition; +extern bool hv_nested; #if IS_ENABLED(CONFIG_HYPERV) /* From patchwork Thu Nov 24 06:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3214597wrr; Wed, 23 Nov 2022 22:05:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf6TI9/kV6+1yFozqyCi6UmXPoDH/CSYVA7TrnBFSkCyfOw7+0m3vLU/bfc4kgjZVehZGbfw X-Received: by 2002:a17:90b:3444:b0:213:519d:fe51 with SMTP id lj4-20020a17090b344400b00213519dfe51mr39915801pjb.239.1669269914393; Wed, 23 Nov 2022 22:05:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269914; cv=none; d=google.com; s=arc-20160816; b=RizzgJM9tih5pT7QRYcDXtz03xhBWsXtCYi3GT+Dnxur5kbxtHqsPck9MVuYIghmBf P36Lu/Ijw9+KBgIvKCXV0j7wR+W1DpuVL5cLqMaxQvdN1t+VQ72fmqpvCyS7a7qrSMIh aeoCMAP1GPmKBToX3Iwawm/7TEvjo836RJDqdyTVHnhKIQIph+/WP2U2vATgpwsQTYDB a7ugwR3Emi0wuTUN7l2TDpWKwsE8ScH/csy1Pp1OUsigg9IzMuislLN+jGVtd6EcFg7r AtfZGKVC/SYvevyZuX6TznO5igYEWvHwCqI7meNZd+EwJPJLRDmD1mjuoM/QLV6iwG45 0Bbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=MKWLvVLStOT5MYIHkjm5sdDjs9fAGhyWlNuXLqeegL4=; b=MVlhhWjwdo79C4ahARF6E2Og34bVipbHjd7mBw19K91dl+stOAj2nMe6owRKzFXBg0 brwB0lHgHfACphHronV9xKxRJ1APb+I1I6K4CfSI9vKQ312EzDa758ORfS+OqKZvphpe 2BEWfeiRdx2mRXHJ0tHyweE2ZjTX0n0/sAnr3eRidH/z+1LPWNoT5EC7phRrJOo1Ti2N H+ebBigaEropF+MlnPgSujbAoRkUZ/zPes5RHGBwAmug9wKP03r7ippJvQO+kJqCGdrU 4+KiPhx+aHfaH1GC2Y5+R8X6YYd7Tc8SZ3SLoVi2dF5AAvaqu745BJQLZqEqoIZ//lnY QmvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Hpp+FZzd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d1-20020a170902854100b00178aec118c9si184991plo.378.2022.11.23.22.05.01; Wed, 23 Nov 2022 22:05:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Hpp+FZzd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229607AbiKXGCj (ORCPT + 99 others); Thu, 24 Nov 2022 01:02:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229673AbiKXGC2 (ORCPT ); Thu, 24 Nov 2022 01:02:28 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE8B41B7AC; Wed, 23 Nov 2022 22:02:26 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 36DF620B83DC; Wed, 23 Nov 2022 22:02:22 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 36DF620B83DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269746; bh=MKWLvVLStOT5MYIHkjm5sdDjs9fAGhyWlNuXLqeegL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hpp+FZzdQcpe8GfsWFVdHWfJeDO3wDWJ9nud+FedvkalAyxCkqUe6wFkZvb123eYJ Fe2pLzw/FL7FBz5nMQMayhcnp23Dgq1txt6DGF6f4sIIL/5VXxnbT5M69WP3txe9aG x1Gu3zRD3F+0TaF9E2Mhl+SJsdPS11+ZYfCgb/Uw= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, peterz@infradead.org, jpoimboe@kernel.org, jinankjain@linux.microsoft.com, seanjc@google.com, kirill.shutemov@linux.intel.com, ak@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, anrayabh@linux.microsoft.com, mikelley@microsoft.com Subject: [PATCH v6 2/5] Drivers: hv: Setup synic registers in case of nested root partition Date: Thu, 24 Nov 2022 06:02:07 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750356369904308855?= X-GMAIL-MSGID: =?utf-8?q?1750356369904308855?= Child partitions are free to allocate SynIC message and event page but in case of root partition it must use the pages allocated by Microsoft Hypervisor (MSHV). Base address for these pages can be found using synthetic MSRs exposed by MSHV. There is a slight difference in those MSRs for nested vs non-nested root partition. Signed-off-by: Jinank Jain --- arch/x86/include/asm/hyperv-tlfs.h | 11 +++++++ arch/x86/include/asm/mshyperv.h | 26 ++-------------- arch/x86/kernel/cpu/mshyperv.c | 49 ++++++++++++++++++++++++++++++ drivers/hv/hv.c | 18 ++++++++--- 4 files changed, 75 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 58c03d18c235..b5019becb618 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -225,6 +225,17 @@ enum hv_isolation_type { #define HV_REGISTER_SINT14 0x4000009E #define HV_REGISTER_SINT15 0x4000009F +/* + * Define synthetic interrupt controller model specific registers for + * nested hypervisor. + */ +#define HV_REGISTER_NESTED_SCONTROL 0x40001080 +#define HV_REGISTER_NESTED_SVERSION 0x40001081 +#define HV_REGISTER_NESTED_SIEFP 0x40001082 +#define HV_REGISTER_NESTED_SIMP 0x40001083 +#define HV_REGISTER_NESTED_EOM 0x40001084 +#define HV_REGISTER_NESTED_SINT0 0x40001090 + /* * Synthetic Timer MSRs. Four timers per vcpu. */ diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 61f0c206bff0..326d699b30d5 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -198,30 +198,8 @@ static inline bool hv_is_synic_reg(unsigned int reg) return false; } -static inline u64 hv_get_register(unsigned int reg) -{ - u64 value; - - if (hv_is_synic_reg(reg) && hv_isolation_type_snp()) - hv_ghcb_msr_read(reg, &value); - else - rdmsrl(reg, value); - return value; -} - -static inline void hv_set_register(unsigned int reg, u64 value) -{ - if (hv_is_synic_reg(reg) && hv_isolation_type_snp()) { - hv_ghcb_msr_write(reg, value); - - /* Write proxy bit via wrmsl instruction */ - if (reg >= HV_REGISTER_SINT0 && - reg <= HV_REGISTER_SINT15) - wrmsrl(reg, value | 1 << 20); - } else { - wrmsrl(reg, value); - } -} +u64 hv_get_register(unsigned int reg); +void hv_set_register(unsigned int reg, u64 value); #else /* CONFIG_HYPERV */ static inline void hyperv_init(void) {} diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 9a4204139490..97d8ce744e47 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -41,6 +41,55 @@ bool hv_root_partition; bool hv_nested; struct ms_hyperv_info ms_hyperv; +static inline unsigned int hv_get_nested_reg(unsigned int reg) +{ + switch (reg) { + case HV_REGISTER_SIMP: + return HV_REGISTER_NESTED_SIMP; + case HV_REGISTER_NESTED_SIEFP: + return HV_REGISTER_SIEFP; + case HV_REGISTER_SCONTROL: + return HV_REGISTER_NESTED_SCONTROL; + case HV_REGISTER_SINT0: + return HV_REGISTER_NESTED_SINT0; + case HV_REGISTER_EOM: + return HV_REGISTER_NESTED_EOM; + default: + return reg; + } +} + +u64 hv_get_register(unsigned int reg) +{ + u64 value; + + if (hv_nested) + reg = hv_get_nested_reg(reg); + + if (hv_is_synic_reg(reg) && hv_isolation_type_snp()) + hv_ghcb_msr_read(reg, &value); + else + rdmsrl(reg, value); + return value; +} + +void hv_set_register(unsigned int reg, u64 value) +{ + if (hv_nested) + reg = hv_get_nested_reg(reg); + + if (hv_is_synic_reg(reg) && hv_isolation_type_snp()) { + hv_ghcb_msr_write(reg, value); + + /* Write proxy bit via wrmsl instruction */ + if (reg >= HV_REGISTER_SINT0 && + reg <= HV_REGISTER_SINT15) + wrmsrl(reg, value | 1 << 20); + } else { + wrmsrl(reg, value); + } +} + #if IS_ENABLED(CONFIG_HYPERV) static void (*vmbus_handler)(void); static void (*hv_stimer0_handler)(void); diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 4d6480d57546..9e1eb50cc76f 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -147,7 +147,7 @@ int hv_synic_alloc(void) * Synic message and event pages are allocated by paravisor. * Skip these pages allocation here. */ - if (!hv_isolation_type_snp()) { + if (!hv_isolation_type_snp() && !hv_root_partition) { hv_cpu->synic_message_page = (void *)get_zeroed_page(GFP_ATOMIC); if (hv_cpu->synic_message_page == NULL) { @@ -188,8 +188,16 @@ void hv_synic_free(void) struct hv_per_cpu_context *hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); - free_page((unsigned long)hv_cpu->synic_event_page); - free_page((unsigned long)hv_cpu->synic_message_page); + if (hv_root_partition) { + if (hv_cpu->synic_event_page != NULL) + memunmap(hv_cpu->synic_event_page); + + if (hv_cpu->synic_message_page != NULL) + memunmap(hv_cpu->synic_message_page); + } else { + free_page((unsigned long)hv_cpu->synic_event_page); + free_page((unsigned long)hv_cpu->synic_message_page); + } free_page((unsigned long)hv_cpu->post_msg_page); } @@ -216,7 +224,7 @@ void hv_synic_enable_regs(unsigned int cpu) simp.as_uint64 = hv_get_register(HV_REGISTER_SIMP); simp.simp_enabled = 1; - if (hv_isolation_type_snp()) { + if (hv_isolation_type_snp() || hv_root_partition) { hv_cpu->synic_message_page = memremap(simp.base_simp_gpa << HV_HYP_PAGE_SHIFT, HV_HYP_PAGE_SIZE, MEMREMAP_WB); @@ -233,7 +241,7 @@ void hv_synic_enable_regs(unsigned int cpu) siefp.as_uint64 = hv_get_register(HV_REGISTER_SIEFP); siefp.siefp_enabled = 1; - if (hv_isolation_type_snp()) { + if (hv_isolation_type_snp() || hv_root_partition) { hv_cpu->synic_event_page = memremap(siefp.base_siefp_gpa << HV_HYP_PAGE_SHIFT, HV_HYP_PAGE_SIZE, MEMREMAP_WB); From patchwork Thu Nov 24 06:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3214915wrr; Wed, 23 Nov 2022 22:06:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7f8l1y5i15/nuGBI/A87U86Qe2QyJSfA15UkELQHmJvN8TSAYpOkgApWMVPz387vwAJ8ye X-Received: by 2002:a65:674e:0:b0:477:ce06:6c98 with SMTP id c14-20020a65674e000000b00477ce066c98mr1561085pgu.290.1669269967835; Wed, 23 Nov 2022 22:06:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269967; cv=none; d=google.com; s=arc-20160816; b=kCtpXiTB6qR7HNxHjncJjOHOr6eEC8aRWQNpes5+ZvE6pnmennMSbk37p954+uko0P VklNu1lIq/6MT9h98UCMi3UaA4V7sundfaHcEDZ4Y6uZj47kfO6SEQlu5uolF14A8cw7 h6p+dg+ajYRwDQHw5RcGJVRlSkFyiZ0ovC+5K5SsJJ2hciUjoVtnGDrXrsORzxqS098m mFmXzrPFwSahQEeAgdW/6tH5EIuXh4b/Wv++Lwg8va6YKe2g6S3oCIeStnVq2NPdzsO2 s1gEskKNWvdtEUQB+w2o69i7LQ7Hrt8ES94HChLMTj0M5mJrEwb0uU3OUbqeNhCiLk7X sz3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=6aCQB6T2s5uMf0GxO2Oxlp22rHTx2Zt0vrLxg7FoSvA=; b=BOJ0WO3KPzvJk0O0CWgHpElnCHt/9uxGYAMtLOn1XlLCII8scxbINhgzN36DLtABC6 4M27XHVJfi6sCTh/TPBAgydFOae5N93rj0DflICnsRWg2qSgCanbdifnEY4/AVrq2Ib+ vAQqXeAz85X3EZeD4DrO3f4i8zUlnppGQRZs/IxRoFCrFUKgd+H4c8BgS6566FbwiKdx +pNaDPR9U2grnHSH3ZFmMopWSBr6jlyjjznsS3Pp4u4N72qggaA2ROSRdoo1O2Qa3EJU m+Sn13zNh7WneRFcCC0kS3jfXOX1eM5kd9Q53+4DnIkd4KYrtI1gyMQ/TeUU3MgfCoPT giOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="b/eE4vl3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w187-20020a6362c4000000b00463dbc5cec8si407497pgb.658.2022.11.23.22.05.54; Wed, 23 Nov 2022 22:06:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="b/eE4vl3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbiKXGC4 (ORCPT + 99 others); Thu, 24 Nov 2022 01:02:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbiKXGCi (ORCPT ); Thu, 24 Nov 2022 01:02:38 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DCFF263CE; Wed, 23 Nov 2022 22:02:31 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 2D79B20B83C2; Wed, 23 Nov 2022 22:02:27 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2D79B20B83C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269751; bh=6aCQB6T2s5uMf0GxO2Oxlp22rHTx2Zt0vrLxg7FoSvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b/eE4vl3zJHnaDSYCepP2jiWaFgki59hJi4vAUUlG73kV/9Qtv6TpveNG1k91by+t vdZ8zsbfRUl9L/aLlSQ7ogiW2KyZQsOrhxcehNDuqYhuVF5N+LuNkNl9iOMTe+URXG tPmtNPMWw+cxX0cBqOMYnrqqiIuvgq8WtibTqrGw= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, peterz@infradead.org, jpoimboe@kernel.org, jinankjain@linux.microsoft.com, seanjc@google.com, kirill.shutemov@linux.intel.com, ak@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, anrayabh@linux.microsoft.com, mikelley@microsoft.com Subject: [PATCH v6 3/5] x86/hyperv: Add an interface to do nested hypercalls Date: Thu, 24 Nov 2022 06:02:08 +0000 Message-Id: <264d024a50f0e8278a66f2c31aa52b614437dfb4.1669269377.git.jinankjain@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750356425576853046?= X-GMAIL-MSGID: =?utf-8?q?1750356425576853046?= According to TLFS, in order to communicate to L0 hypervisor there needs to be an additional bit set in the control register. This communication is required to perform privileged instructions which can only be performed by L0 hypervisor. An example of that could be setting up the VMBus infrastructure. Signed-off-by: Jinank Jain --- arch/x86/include/asm/hyperv-tlfs.h | 3 ++- arch/x86/include/asm/mshyperv.h | 42 +++++++++++++++++++++++++++--- include/asm-generic/hyperv-tlfs.h | 1 + 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index b5019becb618..7758c495541d 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -380,7 +380,8 @@ struct hv_nested_enlightenments_control { __u32 reserved:31; } features; struct { - __u32 reserved; + __u32 inter_partition_comm:1; + __u32 reserved:31; } hypercallControls; } __packed; diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 326d699b30d5..42e42cea0384 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -74,10 +74,16 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output) return hv_status; } +/* Hypercall to the L0 hypervisor */ +static inline u64 hv_do_nested_hypercall(u64 control, void *input, void *output) +{ + return hv_do_hypercall(control | HV_HYPERCALL_NESTED, input, output); +} + /* Fast hypercall with 8 bytes of input and no output */ -static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1) +static inline u64 _hv_do_fast_hypercall8(u64 control, u16 code, u64 input1) { - u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT; + u64 hv_status; #ifdef CONFIG_X86_64 { @@ -105,10 +111,24 @@ static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1) return hv_status; } +static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1) +{ + u64 control = (u64)code | HV_HYPERCALL_FAST_BIT; + + return _hv_do_fast_hypercall8(control, code, input1); +} + +static inline u64 hv_do_fast_nested_hypercall8(u16 code, u64 input1) +{ + u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED; + + return _hv_do_fast_hypercall8(control, code, input1); +} + /* Fast hypercall with 16 bytes of input */ -static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2) +static inline u64 _hv_do_fast_hypercall16(u64 control, u16 code, u64 input1, u64 input2) { - u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT; + u64 hv_status; #ifdef CONFIG_X86_64 { @@ -139,6 +159,20 @@ static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2) return hv_status; } +static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2) +{ + u64 control = (u64)code | HV_HYPERCALL_FAST_BIT; + + return _hv_do_fast_hypercall16(control, code, input1, input2); +} + +static inline u64 hv_do_fast_nested_hypercall16(u16 code, u64 input1, u64 input2) +{ + u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED; + + return _hv_do_fast_hypercall16(control, code, input1, input2); +} + extern struct hv_vp_assist_page **hv_vp_assist_page; static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index b17c6eeb9afa..e61ee461c4fc 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -194,6 +194,7 @@ enum HV_GENERIC_SET_FORMAT { #define HV_HYPERCALL_VARHEAD_OFFSET 17 #define HV_HYPERCALL_VARHEAD_MASK GENMASK_ULL(26, 17) #define HV_HYPERCALL_RSVD0_MASK GENMASK_ULL(31, 27) +#define HV_HYPERCALL_NESTED BIT_ULL(31) #define HV_HYPERCALL_REP_COMP_OFFSET 32 #define HV_HYPERCALL_REP_COMP_1 BIT_ULL(32) #define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32) From patchwork Thu Nov 24 06:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25324 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3215727wrr; Wed, 23 Nov 2022 22:08:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf47lxDwOVMD2EEy0OLQdYGdAWr93KXo95yCwqd52IpMRL4g4g4z1G8Uu1kYnpw3/XnMa/KO X-Received: by 2002:a62:3306:0:b0:56b:8181:fe3e with SMTP id z6-20020a623306000000b0056b8181fe3emr34087549pfz.57.1669270101361; Wed, 23 Nov 2022 22:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669270101; cv=none; d=google.com; s=arc-20160816; b=vj22INIS9FlN6JL96fTMpjYfwOIgbs+Yo5NauqUJF2uzZuizZkq5GJF9rQS0TzjW59 +wfVdfzZl5aUlb12K7EFCEDAqQIZHMguvT5BGjv3y5Gz079kVSLGxDhiUTgEB6/VZ3ox YId4aHZ6YfZUClqviPjGngTqGfDYlfo+B4TKDJXGMQeF/xqPOP1dIa8X4b+ESjsvrQZ4 UhLrlBwNxdDj7r3oLXNdYWI+uAMPgmg2x3QvRMUuzlLLfM7f9dPFXYzA7ofLD45CgvYl eGrDTwTSXNqC/agrptEP1dt2GYOBU8maTdPZ1+zSpfMTt7y5PeG+s2QMf7+bRJZKhxuE FeKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=D+EHMsRYcjPgM7FAsk56dOdUsC5Gb8WTyjClcLwda7k=; b=bwy6/ZaZaDmdZnAjN0TZ36XsILblBNjaVios9MZKMPgoYvzCeK3k/8FPsE87PZJcv9 WvZ+NTND9N60h2sHsRtdCGOASAnIZemwP/uzHBi0CF4XEkKmPq3Sr5LUQLZfSUF4UV5d pQDWwhD7x5yACGBYBTXNa9Iln36YyaDlMWwvTxdBajdp36DZV/f9Mwb7dm51tzldpMIs sJFisotQEl9bEIMAWOy1t9GQ0OrW4cQEn5+gyPWSskHJBMiktv9jlSDW3Bz+mjYWVVBZ b7Ov9w3W913Q0/de/9NUeTb5quxx1T8uZgl5Ig9TCaAaX6+HQc0O3pPAvwpL7nO/mWTy ujyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Gqf7xSFv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o26-20020a63921a000000b0046fcbcb7422si497428pgd.45.2022.11.23.22.08.08; Wed, 23 Nov 2022 22:08:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Gqf7xSFv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229453AbiKXGDS (ORCPT + 99 others); Thu, 24 Nov 2022 01:03:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiKXGCy (ORCPT ); Thu, 24 Nov 2022 01:02:54 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4E2D229349; Wed, 23 Nov 2022 22:02:36 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 24FE820B83CB; Wed, 23 Nov 2022 22:02:31 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 24FE820B83CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269756; bh=D+EHMsRYcjPgM7FAsk56dOdUsC5Gb8WTyjClcLwda7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gqf7xSFvvF1jzxNgz0Oyhb7um6bccURJNog28tTcUijek4n2OPgLxLdVvGQwcA/X5 hD8CAPOfnTd1t0jhxoAoTmY7vHF8rH8qX1GutO6UK9DbgdXZrgIMjndrDe+Qve8PbP ge/Y166XjYLFgTQfyG9Bodxzt5M9zj9bL1/nEN8c= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, peterz@infradead.org, jpoimboe@kernel.org, jinankjain@linux.microsoft.com, seanjc@google.com, kirill.shutemov@linux.intel.com, ak@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, anrayabh@linux.microsoft.com, mikelley@microsoft.com Subject: [PATCH v6 4/5] Drivers: hv: Enable vmbus driver for nested root partition Date: Thu, 24 Nov 2022 06:02:09 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750356565539067496?= X-GMAIL-MSGID: =?utf-8?q?1750356565539067496?= Currently VMBus driver is not initialized for root partition but we need to enable the VMBus driver for nested root partition. This is required, so that L2 root can use the VMBus devices. Signed-off-by: Jinank Jain --- drivers/hv/vmbus_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index db00d20c726d..0937877eade9 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2744,7 +2744,7 @@ static int __init hv_acpi_init(void) if (!hv_is_hyperv_initialized()) return -ENODEV; - if (hv_root_partition) + if (hv_root_partition && !hv_nested) return 0; /* From patchwork Thu Nov 24 06:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3215756wrr; Wed, 23 Nov 2022 22:08:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ZAHIAHE1VdANgF9GgAaW5ILd0QbCDwA9b9djnMjL9YxPfPl0p/OpajaBbzcZYFncc8SK2 X-Received: by 2002:a17:90a:7b8a:b0:218:c92d:1161 with SMTP id z10-20020a17090a7b8a00b00218c92d1161mr12835339pjc.182.1669270106183; Wed, 23 Nov 2022 22:08:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669270106; cv=none; d=google.com; s=arc-20160816; b=YlBXJi/6ISMJRok60Z2v3UIU0rUA8sAhQ8Lqha3E8SNP19Ak/Od38dP4nkIB1gImat j3N2nqhGDD9YRhaNkqYpZxJoBQgi+zntChuWe9qexZHCwiVYn9nDS2uS1FT+ibPlnRfL UIESasCuEfFuovmZvQ9tE+niWIvwRE2d/7Mt4W4MuX1Ds7Zjsvxe8SeQ3UTQ/qYgxf7O Zq+eMaNdRmBc0OWhOHx4k//DfYML0ztGdyvqR8eut4ZeDAfQqgysq8FXQnVMElm5Mk3V gliihC7yxBKQ61lCmi2+mIPoHWcH+8rzvaAaPmkY/Sl89Fe8oUcdyS71IGURP617l282 iC8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=GURa878M+ZD9GAsBMP6GkqmlRzba5bDM5ir2EFzDpPQ=; b=gW5VfWaZ2az6U+bgj2XOxHW9tD7QZe2KWXwJmKKLBdvkmytLtVjqz+arIETe3mOEIk YrB1iQ3+ATh+uKMaeSOmD6qodzc6Yo/f19MDfYd81+q0AbBq8ariFIIYpijQPXYhDJM7 jHfz6E4L+MA7YW2DlEJF2vEnU/MngRN4/zbEo6aQmAZ1A1Lj/1pAZVa2c/yjjKPlg5mo +txHUJsbO0EkfpPNa7dzz3KY264NG5wSnPGWSlY3V011WfJDh6hYMuSvFg6oluoHo6HW VSOgqylfuX7eS8bYA64C47pgV2m5wzPIi/0OujL7oLEPX0vU50lM9LWm0HSajUA64VZx X6OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=GaZVuCxN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a056a001ac800b00562617987a1si251567pfv.264.2022.11.23.22.08.12; Wed, 23 Nov 2022 22:08:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=GaZVuCxN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbiKXGD0 (ORCPT + 99 others); Thu, 24 Nov 2022 01:03:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbiKXGDG (ORCPT ); Thu, 24 Nov 2022 01:03:06 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D9CD664F1; Wed, 23 Nov 2022 22:02:41 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 1D85820B83DC; Wed, 23 Nov 2022 22:02:36 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1D85820B83DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269761; bh=GURa878M+ZD9GAsBMP6GkqmlRzba5bDM5ir2EFzDpPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GaZVuCxNLxaY+fK2KkO1a4Dl0WE9dz0ryOqMl0ufbN/hcUL+3Y9lWZRgGNoGoItd4 Ppn7Bzo2ZjaKG/+xFpaDAFGCoQL9CSEXZ5klq6NMbvMqhKZFaJQ+KaxA3u6+LWfYoN FEHMNJeuyfMaUNpNgCkAg/GldZbKeBqfseU4j1V0= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, peterz@infradead.org, jpoimboe@kernel.org, jinankjain@linux.microsoft.com, seanjc@google.com, kirill.shutemov@linux.intel.com, ak@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, anrayabh@linux.microsoft.com, mikelley@microsoft.com Subject: [PATCH v6 5/5] x86/hyperv: Change interrupt vector for nested root partition Date: Thu, 24 Nov 2022 06:02:10 +0000 Message-Id: <01cbde59aa3a80a184b535a9573857cf895df9a2.1669269377.git.jinankjain@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750356570795014761?= X-GMAIL-MSGID: =?utf-8?q?1750356570795014761?= Traditionally we have been using the HYPERVISOR_CALLBACK_VECTOR to relay the VMBus interrupt. But this does not work in case of nested hypervisor. Microsoft Hypervisor reserves 0x31 to 0x34 as the interrupt vector range for VMBus and thus we have to use one of the vectors from that range and setup the IDT accordingly. Signed-off-by: Jinank Jain --- arch/x86/include/asm/idtentry.h | 2 ++ arch/x86/include/asm/irq_vectors.h | 6 ++++++ arch/x86/kernel/cpu/mshyperv.c | 15 +++++++++++++++ arch/x86/kernel/idt.c | 9 +++++++++ drivers/hv/vmbus_drv.c | 3 ++- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 72184b0b2219..c0648e3e4d4a 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -686,6 +686,8 @@ DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_NESTED_VECTOR, sysvec_kvm_posted_intr_nested DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_hyperv_callback); DECLARE_IDTENTRY_SYSVEC(HYPERV_REENLIGHTENMENT_VECTOR, sysvec_hyperv_reenlightenment); DECLARE_IDTENTRY_SYSVEC(HYPERV_STIMER0_VECTOR, sysvec_hyperv_stimer0); +DECLARE_IDTENTRY_SYSVEC(HYPERV_INTR_NESTED_VMBUS_VECTOR, + sysvec_hyperv_nested_vmbus_intr); #endif #if IS_ENABLED(CONFIG_ACRN_GUEST) diff --git a/arch/x86/include/asm/irq_vectors.h b/arch/x86/include/asm/irq_vectors.h index 43dcb9284208..729d19eab7f5 100644 --- a/arch/x86/include/asm/irq_vectors.h +++ b/arch/x86/include/asm/irq_vectors.h @@ -102,6 +102,12 @@ #if IS_ENABLED(CONFIG_HYPERV) #define HYPERV_REENLIGHTENMENT_VECTOR 0xee #define HYPERV_STIMER0_VECTOR 0xed +/* + * FIXME: Change this, once Microsoft Hypervisor changes its assumption + * around VMBus interrupt vector allocation for nested root partition. + * Or provides a better interface to detect this instead of hardcoding. + */ +#define HYPERV_INTR_NESTED_VMBUS_VECTOR 0x31 #endif #define LOCAL_TIMER_VECTOR 0xec diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 97d8ce744e47..8a692dd6d789 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -110,6 +110,21 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_callback) set_irq_regs(old_regs); } +DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_nested_vmbus_intr) +{ + struct pt_regs *old_regs = set_irq_regs(regs); + + inc_irq_stat(irq_hv_callback_count); + + if (vmbus_handler) + vmbus_handler(); + + if (ms_hyperv.hints & HV_DEPRECATING_AEOI_RECOMMENDED) + ack_APIC_irq(); + + set_irq_regs(old_regs); +} + void hv_setup_vmbus_handler(void (*handler)(void)) { vmbus_handler = handler; diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c index a58c6bc1cd68..ace648856a0b 100644 --- a/arch/x86/kernel/idt.c +++ b/arch/x86/kernel/idt.c @@ -160,6 +160,15 @@ static const __initconst struct idt_data apic_idts[] = { # endif INTG(SPURIOUS_APIC_VECTOR, asm_sysvec_spurious_apic_interrupt), INTG(ERROR_APIC_VECTOR, asm_sysvec_error_interrupt), +#ifdef CONFIG_HYPERV + /* + * This is a hack because we cannot install this interrupt handler via alloc_intr_gate + * as it does not allow interrupt vector less than FIRST_SYSTEM_VECTORS. And hyperv + * does not want anything other than 0x31-0x34 as the interrupt vector for vmbus + * interrupt in case of nested setup. + */ + INTG(HYPERV_INTR_NESTED_VMBUS_VECTOR, asm_sysvec_hyperv_nested_vmbus_intr), +#endif #endif }; diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 0937877eade9..c1477f3a08dd 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2767,7 +2767,8 @@ static int __init hv_acpi_init(void) * normal Linux IRQ mechanism is not used in this case. */ #ifdef HYPERVISOR_CALLBACK_VECTOR - vmbus_interrupt = HYPERVISOR_CALLBACK_VECTOR; + vmbus_interrupt = hv_nested ? HYPERV_INTR_NESTED_VMBUS_VECTOR : + HYPERVISOR_CALLBACK_VECTOR; vmbus_irq = -1; #endif