From patchwork Thu Nov 24 05:53:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3210695wrr; Wed, 23 Nov 2022 21:54:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf68iNNBg0wSQY9w68RhDdLxiatb8wK7k9f7p6i0yAQ07aW+jD7apUcceLnAERY8E6iFL87P X-Received: by 2002:a17:907:a803:b0:7ae:bfeb:f484 with SMTP id vo3-20020a170907a80300b007aebfebf484mr2625252ejc.174.1669269274643; Wed, 23 Nov 2022 21:54:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269274; cv=none; d=google.com; s=arc-20160816; b=cfz5TzB/Y4sMb3G195vN3NOsCJMCwSHptD8nxnf5gY70u/vLjJ1BcD6qpsRDwFYd3J vjt+WEAEImszswxuuntzQ4FHlYkg6h9IUG3yZ2yCDM4bZxwpVXIkcY8X1g9750m/Fwub obCe1KIzPP3Cv5ShObirIhwbaBYE9loyCSEaItPUZzNT4gsA42VSPvC9kovdfN2Ujlkx hUzrnUL85stEj+rVGk3o0YKCBsEG8Ec61i4nXe9BApeZMjz0jNa3FDLRoTlH8BbsSRl2 lAqRxopNyJIcVFSNkQp4k0WNBh7Uw7K45Um/7ZG5JD0Puv1eVgOFcj3mPwRVHSSR0Hh0 aRMg== 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=jZrfE3E4lxhGw+MvJUCDK70VJfmkQMf6oCsKZEKTHbw=; b=i59nSAvNvdM7FV+HZI+MNWzyMl5/YmLjUL35kD+2FnCSAPNbIoIrsON23D5NR73t+6 PfxvZSNCkYzS9sB2Ol/+ekkd8SPqF9XOnX1FzbaqoiPmNIDxfwvLcSx0BA2U9DvLNAyM AtCdr86ug98cU3Ytf7chHT0oMj7NJE0GyFclNdpdN7SdqNf+gbrYYMp/n3poyxaKpPUP OxKLV1fjy+WC8np6ZS/zMOJSo/6Wn4xkGgzX7db0ZXo5nX83a/yFNpQ0Dt9EAWXK1cya Z3ymxiPCmNXyGvDpLmuqf7VkFhHxBqDQ3sCIWtgQr3lWF69xR04wYct+1Gd4c5DZ4hU/ Bsfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fsJkT7MQ; 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 u11-20020a50eacb000000b004687eebac58si200177edp.458.2022.11.23.21.54.11; Wed, 23 Nov 2022 21:54:34 -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=fsJkT7MQ; 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 S229491AbiKXFxX (ORCPT + 99 others); Thu, 24 Nov 2022 00:53:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbiKXFxT (ORCPT ); Thu, 24 Nov 2022 00:53:19 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 970CD1EAC6; Wed, 23 Nov 2022 21:53:17 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 2C4E820B83C2; Wed, 23 Nov 2022 21:53:13 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2C4E820B83C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269197; bh=jZrfE3E4lxhGw+MvJUCDK70VJfmkQMf6oCsKZEKTHbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fsJkT7MQfC2MQvHCaG6nXp5pxlx9jSGzE5gYQO6E0D/dUmMI1oUaJkYe+jgfGBCQk LnTahLt4giB+5hU5n5TK46tXAlx6kN+SV9TzxWI9uIJRWbat9ssOUQIxYYczao2S0w +0+gmQN8s4tsyNggapI0anuKyCI053Qs43EjvXTY= 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 v5 1/5] x86/hyperv: Add support for detecting nested hypervisor Date: Thu, 24 Nov 2022 05:53:02 +0000 Message-Id: <08ab7aede41f2feb1cd8ac21d0ddd17e25b1d070.1669007822.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?1750355699297852774?= X-GMAIL-MSGID: =?utf-8?q?1750355699297852774?= When Linux runs as a root partition for Microsoft Hypervisor. It is possible to detect if it is running as nested hypervisor using hints exposed by mshv. While at it expose a new variable called hv_nested which can be used later for making decisions specific to nested use case. Signed-off-by: Jinank Jain --- arch/arm64/hyperv/mshyperv.c | 6 ++++++ arch/x86/include/asm/hyperv-tlfs.h | 3 +++ arch/x86/kernel/cpu/mshyperv.c | 7 +++++++ drivers/hv/hv_common.c | 7 +++++-- include/asm-generic/mshyperv.h | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index a406454578f0..2024b19dc514 100644 --- a/arch/arm64/hyperv/mshyperv.c +++ b/arch/arm64/hyperv/mshyperv.c @@ -19,6 +19,9 @@ static bool hyperv_initialized; +/* Is Linux running on nested Microsoft Hypervisor */ +bool hv_nested; + static int __init hyperv_init(void) { struct hv_get_vp_registers_output result; @@ -63,6 +66,9 @@ static int __init hyperv_init(void) pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n", b >> 16, b & 0xFFFF, a, d & 0xFFFFFF, c, d >> 24); + /* ARM64 does not support nested virtualization */ + hv_nested = false; + ret = hv_common_init(); if (ret) return ret; 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..dcb336ce374f 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -25,8 +25,8 @@ #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 @@ -36,6 +36,9 @@ 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 05:53:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3210750wrr; Wed, 23 Nov 2022 21:54:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Cbac0Z00WesU4lWnpX/h1Ro9LQ2ZMZMMAiQNUFc3zjWCUPIehGAjea68vow8cTS0xisyy X-Received: by 2002:a17:906:448b:b0:7ad:8bd5:b7df with SMTP id y11-20020a170906448b00b007ad8bd5b7dfmr5545303ejo.57.1669269285858; Wed, 23 Nov 2022 21:54:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269285; cv=none; d=google.com; s=arc-20160816; b=bQTUGvLjSuPqKnmTyEVBHv3ERQrLGOESd9qvnwRNge6A5VwlHwJ5QfB4Jq4dBhRiG1 HM4MEnS3bTbyTpX2tnYwxi3WYJDhAe9Z+xw4ZPHQQh9Xs8LucFCnB6EpMXYEo3AtbF0B 5MfD7mF/tpIk9JwPM0AzaswA7WmFRU7axlY1gYrBDbKd/1w252xeGi5BO1n8Co76W0Ct QZx2LGTxgEPMYbJuuz+Pj10/VN2d7syrdI8u9OnT95Lk82/3wxig+66CzG6NoW/O5Mux v1F/LWkqVSD2ELvfTws5oCwWBZgXa7wG4mjvI41ZPvo56VicHmrUQ95i8LzgwfxSeUFR +gWw== 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=OfWgxvQeVht24a4E8EyqR7JJ0JMc9v0fQdY41479A3A=; b=r2lXWRATCDc5pUAjzkt/MaeZkmHeDIPVxJFU7KJxnOtqF8kfJvU4U1UNirFN81iEAG IVu7P/v2By0TnUC696+jH5pvDaTyULzLsbpXSEI2fWPoeecf193taU+E4R0KWeiW0Pag cS5+8qUNlR9klBGjqZZlvmzhOckEtp5YTVKftXp76Is46h1+pKll6bNaxC5um8qLz6Qp kse3iZI9E6RqpVlhzzdimlW3GRMc7tZScZrTf1YG5sqKc4yk2Kl9tMP8OEI2gaexcWuG ieo4+l4uZF07F2XvF6l3bSQpiN3k4gG1XqntvndXS7WcgaqB6aPmOFaPDKOC8rOy8jQm AI5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ipSMlKGP; 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 js18-20020a17090797d200b007807e1ea26csi125452ejc.637.2022.11.23.21.54.23; Wed, 23 Nov 2022 21:54:45 -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=ipSMlKGP; 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 S229502AbiKXFxe (ORCPT + 99 others); Thu, 24 Nov 2022 00:53:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbiKXFxX (ORCPT ); Thu, 24 Nov 2022 00:53:23 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E5AC419A6; Wed, 23 Nov 2022 21:53:22 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id CA45F20B83DC; Wed, 23 Nov 2022 21:53:17 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CA45F20B83DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269202; bh=OfWgxvQeVht24a4E8EyqR7JJ0JMc9v0fQdY41479A3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ipSMlKGPnv1mIEIXYidzEQ3rPwxeP+RjLs16K6bhQg+Pq7VoQmxGFCowGVvqODWnG lim2CM2e/N7de8LrUVHnlLLJMh89USbl4T+Nmpg4D9A92t0JpryFe1kArYStNHFlyp yyGhNoPYHuv47qFuX0vPFuzOH5SejviafGDffJX0= 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 v5 2/5] Drivers: hv: Setup synic registers in case of nested root partition Date: Thu, 24 Nov 2022 05:53:03 +0000 Message-Id: <11dda2c697781c5d12bbffd11052e6d6bb2ca705.1669007822.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?1750355710639319016?= X-GMAIL-MSGID: =?utf-8?q?1750355710639319016?= 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..3e6711a6af6b 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; + } +} + +inline 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; +} + +inline 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 05:53:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3211093wrr; Wed, 23 Nov 2022 21:55:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf6q2Jv7nuZjgZbUVJ0kMNwCLRphMV9Go98sb3lu3HcNr2VnPTJikbDMa68g7DtJKFs+CCyo X-Received: by 2002:a05:6402:1a28:b0:469:7546:60fe with SMTP id be8-20020a0564021a2800b00469754660femr14223457edb.408.1669269352543; Wed, 23 Nov 2022 21:55:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269352; cv=none; d=google.com; s=arc-20160816; b=CHyLtyjPx0cbVNp4snlsgqgi7EH71Q3x3PkKis+d90faHR+r/TYx3M+4JJ7P6pIRIX 0dwOO77CGK+3xIxjKYCJHlww62/AAlJYaG2Dmph613BRMtAF5ueVY6nWTW6P3bHSgwST B/Q/2RBOffuzdPLPiFz7RHH0Ec5QLc9xpXhUwhy1jhL3ff9OiH84T2tu4wqaLRaiaZ7x Ps9vGAKabs+MiDBZQxj0LscrsdjeWYJO6wXZIPSG89m3GIYzx7I+IuGMexCO3VHMWeMO GzxLzTfh5uWDPca1xkn1I8SvC0pZyFSPr4g8aOyjiYF6YFftXfszyim5jdsgclqceTY5 3UVA== 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=f2dvTfQMlab1T+fkqP76z4+nJ7JVeutcaW8C+Zjdq84=; b=mDGKI7nHhqF1PPxDb0bGtfYYJJIxWkokMmUSHPZU5vuzN88v5jmlNM26azATTM1bCo v4NvVhK0j/qFnqewVUE5Q9sGVdmMTfdyhpC6J4VdQ2bdVT/fKemvVS62doXVC2TeL8bA v0+Lz4OKT8UK6YL+v0t+rtWvNTlTxsvv3e268hLxibP7fkCu2/AVEHTQx0kLjaItoFx2 8JT232MMvOtjuIeXfIqwP7g+Yt92Is9ed4Gl3Hw9FPia6ND5+lnUupgiC/msKOpmlfew vRAR20sND6mdG0aVvI6uSD2pZiY6a1YoJZM0VhclNf9rw7PRGIw9PAG3GKrgzlJcNMHi eSUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=WafPWV5h; 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 ay26-20020a056402203a00b004612505ece4si206089edb.483.2022.11.23.21.55.28; Wed, 23 Nov 2022 21:55:52 -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=WafPWV5h; 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 S229602AbiKXFxp (ORCPT + 99 others); Thu, 24 Nov 2022 00:53:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbiKXFxe (ORCPT ); Thu, 24 Nov 2022 00:53:34 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 49C536B218; Wed, 23 Nov 2022 21:53: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 739E720B83CB; Wed, 23 Nov 2022 21:53:22 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 739E720B83CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269206; bh=f2dvTfQMlab1T+fkqP76z4+nJ7JVeutcaW8C+Zjdq84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WafPWV5hxozWVF4Qzw9T9qS1Hc347grHdmwV6m7ucNbxpJnAKVx+vAu3F9QaUr1Ya dLmRGK56gHrFfXKyrKJSpwg/eoomUR2Jmr/C0ClwTqKaeNIU6jamVGNs5E9vgFvqzI n1XYTIKcoNdeb89VAaycEuJSkBXmTyAlpoOVcSBw= 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 v5 3/5] x86/hyperv: Add an interface to do nested hypercalls Date: Thu, 24 Nov 2022 05:53:04 +0000 Message-Id: <3a09f876982e14cea8883f03fa9260db1fe64857.1669007822.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?1750355780677749510?= X-GMAIL-MSGID: =?utf-8?q?1750355780677749510?= 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 priviledged 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 05:53:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 25318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3211234wrr; Wed, 23 Nov 2022 21:56:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5DOq0luN+ADiZl0kEP+iancwm0hxZt+JkhGH/amGNoZiv06HC7uH+zuJZXCDNNrduVVF/u X-Received: by 2002:a05:6402:2488:b0:467:3ea1:acdd with SMTP id q8-20020a056402248800b004673ea1acddmr29485160eda.96.1669269369905; Wed, 23 Nov 2022 21:56:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269369; cv=none; d=google.com; s=arc-20160816; b=ASSpkFDTukC5GZYaMvwEm4SppHc1w4EfPy9cV2YdXGPAkQqKHIBN5LhzIQHwx4dFDR CkZavCGj/vXEHjFC82mhCZQjTLv5TfTlQjrkTfy/ijEWNk1SNYyAa6ZYEtUbL+RuGhN4 +5O2K5NKJ5hR6f/RczXYXZmDJ9txo+te69l5IndrSGY12/3c/DvIACMAZSQ1rx9rPnhN OJBgeXCRTaqZ7E25DWisKa8dzyTXbOk4JUE5gbwGqNS7/DLl9Q8OhUFlpUf8XI0bX8v7 TYyKpK/yKfqR9oy+hk2v+BE141V6+xP1a5iZ1a3HiDwFpaHxUbJEa+z0NdAa3xP4GYCi 1l/Q== 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=lR81Jg473NXXzFu3DKnLv2OB1HjQK1OmwuKNFxAYxt8kgAElMw6OglBgqK71RvduXZ o+afLnPZQnm00mrwrO94OIMYRK3hy/Q9vniK/ieJawVYrwLIJkCMBZK/P/PsFQ6vSCEh dj/kpurxM9FCAbOFJKLOEyZUNHBynJGi0JOvYlUvATJTbOfNpcqVYnbLo0FkAEGUylWr pZtNmqhCTVIYave+tp0wgYx8Fjq/RCWq5uA8Wx4bvyFxU8BvId2IcuudjTMH6e8QzrN3 8Lk49+emWPrxGiG2onZahdNTSi280TQdfM+jws0r0gmGbbWDR7HMa3WGU2LCEmZcz7nQ 85Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=EaIAW7aL; 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 xb4-20020a170907070400b007815e9c5b80si110700ejb.617.2022.11.23.21.55.47; Wed, 23 Nov 2022 21:56:09 -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=EaIAW7aL; 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 S229706AbiKXFx4 (ORCPT + 99 others); Thu, 24 Nov 2022 00:53:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbiKXFxh (ORCPT ); Thu, 24 Nov 2022 00:53:37 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8D4BC87A45; Wed, 23 Nov 2022 21:53: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 1B93920B83E2; Wed, 23 Nov 2022 21:53:26 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1B93920B83E2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269211; bh=D+EHMsRYcjPgM7FAsk56dOdUsC5Gb8WTyjClcLwda7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EaIAW7aLccziUxnJq1awpM3cjGNcQefNroBjmdHhzpEu7mQWfFxGQ6K3Qlp+gJcF+ 0p749HV38P65yi3ufNuomhQQ8vSXAYAtYgP8jxc4nsxTmsqDJXPkq8OZWZfgFcMkB6 7RS7TXztQWY9nnzijxHpazwHxCLs3OSBTskgP98k= 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 v5 4/5] Drivers: hv: Enable vmbus driver for nested root partition Date: Thu, 24 Nov 2022 05:53:05 +0000 Message-Id: <034117b286fa4cd6fa491325679052f8b71a8c41.1669007822.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?1750355799139758725?= X-GMAIL-MSGID: =?utf-8?q?1750355799139758725?= 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 05:53: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: 25319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3211333wrr; Wed, 23 Nov 2022 21:56:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf5T9DBELUTKCyx75X1dn1HBgLVGb0biHjruLjLKWiW/hZJH2oBavVVIKmYVzzSnvAQCrq7N X-Received: by 2002:a17:906:a209:b0:78e:ebf:2722 with SMTP id r9-20020a170906a20900b0078e0ebf2722mr25475985ejy.490.1669269394331; Wed, 23 Nov 2022 21:56:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669269394; cv=none; d=google.com; s=arc-20160816; b=Dk/g0EZHmspXt7x8LBqO3O0dZlgHteydiLGgesMpeh8g+FUiWAAQeBLDqQdW3Qa51T clSQwRLPZUnnzZ5g1D+poDmE6Q1WwsJWZnT/8s+1/K/fPzklqUE3EJnhmB4sZ2d6aBrU Q5S70jmteSqqb6XncdoldQenez/gXdLTfTdF0cKDS0pIsXE3cN9DpB313NSPWPPWT/8D Ll+QXzEKDBFbhwv6QCTGbiFXpiiqOGP24gkxFp6b2WkD3U7nBNvehyhwyC6ItDfiZE/R uvFRKl6zzjUvsaZVly1mbRgCBZ1PRA0rljCJpy27k7uHZOoWTxSk4FHX6DC5nc5UilAS aswQ== 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=6CNJYVgODGhVbuGhJ7/+oD/8k4GNDkWTlzsgyABaLp8=; b=XJNfVEcc2mmG9B6/PZ24X5Zwb0yyBb01pMjqw6f7Kja/D5GmUQSjRmKpEc5Pyi0RYZ OxCruAa7RgXmzLGkpeKq9Kj9Q1LZYNvIFAQGCBk72cY+9dmOPBoB0BYscoo8Ok29L0Es LmT5N3EBIImuyqV8HIMSwU9b5BRfL9yORwlJyIat3iCI7QpPa5XHMoFzEqeeT32/k9OM N8XvkTfiPlVbaIydzKQ0xn7PybGhHjeoH46uIS/1/ViabbkFHMYQk72iWuYWPbK58yeL z1pCMw9ZFcPK5UwnLacTxKR6v/8BeqDsYzRuXl/K6G3ztrssbiSofSCdzEgUg/kUhR1R rEmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=MkGEai5w; 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 hs1-20020a1709073e8100b0078c8dadd4bbsi115072ejc.742.2022.11.23.21.56.11; Wed, 23 Nov 2022 21:56:34 -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=MkGEai5w; 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 S229684AbiKXFyJ (ORCPT + 99 others); Thu, 24 Nov 2022 00:54:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbiKXFxn (ORCPT ); Thu, 24 Nov 2022 00:53:43 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C2A192B43; Wed, 23 Nov 2022 21:53: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 B9D4020B83C2; Wed, 23 Nov 2022 21:53:31 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B9D4020B83C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669269216; bh=6CNJYVgODGhVbuGhJ7/+oD/8k4GNDkWTlzsgyABaLp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MkGEai5wCS0oDXCk6aZ/TVpNrFVm1A3zibGDS7oypNVr0J+lc2tMWkAb4li00MtpO /VIwx4nbsbkOqA3rOqX9PNLpkb7bykalk209Fg5YkzZ/qrBnEOvb1hBTvsuQ1UcK3V n+sbw7Zv0vQGuUd94uBeGCS65AW38lOM/YGFfHWk= 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 v5 5/5] x86/hyperv: Change interrupt vector for nested root partition Date: Thu, 24 Nov 2022 05:53:06 +0000 Message-Id: <42848accc9dbe87a48a0f2ceb7ae9294452bda68.1669007822.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?1750355824010846572?= X-GMAIL-MSGID: =?utf-8?q?1750355824010846572?= 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 3e6711a6af6b..ec7fef43e03b 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