From patchwork Mon Jan 2 07:12:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 38010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4047919wrt; Sun, 1 Jan 2023 23:13:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXvPosHp2CqJZP5AQLduoldzLbAj4N8EyxBLmOljldhu0m+5WoZulXP8aN4mVn1ZcAWsPm3w X-Received: by 2002:a05:6a20:8ed8:b0:9d:efbf:48de with SMTP id m24-20020a056a208ed800b0009defbf48demr38984343pzk.34.1672643630738; Sun, 01 Jan 2023 23:13:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672643630; cv=none; d=google.com; s=arc-20160816; b=OmO1+eYTYIHlyOAPOxHwEpRYU2E6e4otsVKTqWH8yKmaTIj5PKQYyHTIWwSpCUt1cx 5maEs5dLVk24FDmZ/qtpvaL7F1nbSNEbqblk5QvTOwZMTT373rB77QhmyIvxyJ6oThU2 PPiMSyT85zJAFeZsSGlXjQj5X35jvE6AptQCFt9tV+QWNK3KREx0eMEYy70b2QuyAVfS yn0pps9sVExLFDhdBrQo74ds9fFuLOqZacKgB5QSw+HzExMfGPzk/ozRH82B6p1Otrhb Udyrif5IeYXCbVDN0fCmmGDEs2VryuaKAhcGT+GvGLp3bqCr3q7zWfNjGDaQhgk3iHwU P6og== 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=wqo8SKjqAvAPfB0JD2Zy4udGVJ0BdIhQjoIMI1f64Wg=; b=W5nILwvBS+WfhOzsX5b0SW7FVWRKFrCjVN5iWWNbF86mb7fecHebhRX5nkXHGNR+V/ hFuDQiT5OFcJRFYCQeUxir1mpdJWsgSEWecknyXGvvnjGeyBU6LItbPFq8+zY3YasDOt H0lGE3IZ8v65vL42x75W4AE8e2eNHE5Ce9cj5MuaCwI/McDG5SYGbdlfgnBbnPx2pyMs rEFmeTGHRrpHFmfelem1OZOVyIHdJ+e5dx2l1CPEK0UXXrpcq+9cPRJlFtxBaFDHACcv /DNY0I5BhAtHDry4XcRabzkTLrt19tqsMAq6RoVyUe5vFcUSsznLbL0btn4pNEGBNZvu xjeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=FsZyOxeJ; 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 q1-20020a056a00150100b005805f1db012si3950282pfu.255.2023.01.01.23.13.38; Sun, 01 Jan 2023 23:13:50 -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=FsZyOxeJ; 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 S230102AbjABHNO (ORCPT + 99 others); Mon, 2 Jan 2023 02:13:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbjABHNH (ORCPT ); Mon, 2 Jan 2023 02:13:07 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E42621BA; Sun, 1 Jan 2023 23:13:06 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id DAE2F20FB6C8; Sun, 1 Jan 2023 23:13:01 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DAE2F20FB6C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1672643586; bh=wqo8SKjqAvAPfB0JD2Zy4udGVJ0BdIhQjoIMI1f64Wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FsZyOxeJok205w83YIqzUrSeI/Fh1lFUJ63ZBJS7WJ1BnsL2oynfRzMzvjvrRoawm 4vpNOZxvk6DY8q7uNCQ1Zqk/7lP17ZyWgNvPaTGS4Q8SWmiioP1L0yOX8SFcwo+Q59 s0SdY4lggfQ/C8FoDFQQxW5jRl0auIxSEQzE499k= 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 v10 1/5] x86/hyperv: Add support for detecting nested hypervisor Date: Mon, 2 Jan 2023 07:12:51 +0000 Message-Id: <8e3e7112806e81d2292a66a56fe547162754ecea.1672639707.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?1753893968120914281?= X-GMAIL-MSGID: =?utf-8?q?1753893968120914281?= 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 Reviewed-by: Michael Kelley --- 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 46668e255421..f9b78d4829e3 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..f131027830c3 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -48,6 +48,7 @@ struct ms_hyperv_info { u64 shared_gpa_boundary; }; extern struct ms_hyperv_info ms_hyperv; +extern bool hv_nested; extern void * __percpu *hyperv_pcpu_input_arg; extern void * __percpu *hyperv_pcpu_output_arg; From patchwork Mon Jan 2 07:12:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 38011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4048111wrt; Sun, 1 Jan 2023 23:14:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXtXc8U0NZu+4jlmTmk23IRLLF2akfarokYc7uPf26OvMceOlV7V+GGpPErKSNdPhZ+r0HF7 X-Received: by 2002:aa7:d04e:0:b0:45c:835b:ac4d with SMTP id n14-20020aa7d04e000000b0045c835bac4dmr34435689edo.8.1672643680872; Sun, 01 Jan 2023 23:14:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672643680; cv=none; d=google.com; s=arc-20160816; b=UY4vd4m6f59aDxBB/QjDbNPU1TU59zm50li5GgdlUbjfENf8Ehh0H6WphiM9psGY37 fXvRXqO7eXa/qWdIA3kQKXwIcQZf8Xi0b9VCiF7xnfQv3nttMtx/FHR8Oy6nWH8rOPBM JSSgosP5PSncGYz2IzTceuM3MvWhm0+IaVHZ2vh/4xY9XjKaH8WVhU50jBc7LPaObI5Q NVMgQxrpZc5RLDL0lEmrEGWZ/ITwQsWNZ1dQYuHDAX/wdX5UPMsaFQ+ov3z0W/5Yyk9r 5BzkBN05ile+q1LX8VEYm4mE6pQjsMoS9+NoK9REdPZ4EpRDXcenM+FgVji5oU4Y5L3Z eOWw== 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=gm0tJXQ/jfaWeFhURQC0+QSvpptcC3iL8+Y2LUdbQRU=; b=a3MLh90WhqOs4X3Ll9cWFAmJ4jUujsKW+k62O4i90A0CWB/VNQ5aercDr0SM5VYBgr SyRU5xERkpljhkguPSG7/HQxbqEsiPvwr+9R+dg7jhHBqDULLgNmAHmS71veo5MFU5dD iEhookbdMzuMOTgQx8QbLbWt4ikYDGpGKDHWkDe5B+yb2ZVT0Rx+OvyUwxqPWWibWWuD YIxUaYtTAr/hYqSB0V6I/EkG5aJCVhPFQEz8dMtSdT+APXU3BVc5MF7QF+Soh6X/Gy/a AexYhNO1FFPd0MsdUY1JrPvtEJNNV4QPk01LKEH76Xt8zYBbRI01+aH8KJwhv1qxApsm KBSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Y9kJYNDk; 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 n18-20020aa7c692000000b0047f2f8bfc05si21910860edq.135.2023.01.01.23.14.16; Sun, 01 Jan 2023 23:14:40 -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=Y9kJYNDk; 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 S230289AbjABHNR (ORCPT + 99 others); Mon, 2 Jan 2023 02:13:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjABHNM (ORCPT ); Mon, 2 Jan 2023 02:13:12 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 01A9625C3; Sun, 1 Jan 2023 23:13:11 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 86C3020FB6CC; Sun, 1 Jan 2023 23:13:06 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 86C3020FB6CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1672643590; bh=gm0tJXQ/jfaWeFhURQC0+QSvpptcC3iL8+Y2LUdbQRU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y9kJYNDkllkBgad2RMpU8L4vn1rKEtb3d89UBRuWzPuyhKPBaF1CssPch+FucTMus sNlgI/bbcDtZ69E8NKxsKOiP87Z40S7z5xAKFe6W0uHJ9LYlxM3nh0Krvjps4zA1xN bPJHHypIzF7jcT4d/Ex47MQTdYGLQ+VXzvHT9lWY= 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 v10 2/5] Drivers: hv: Setup synic registers in case of nested root partition Date: Mon, 2 Jan 2023 07:12:52 +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?1753894020280937561?= X-GMAIL-MSGID: =?utf-8?q?1753894020280937561?= 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 Reviewed-by: Michael Kelley Reviewed-by: Nuno Das Neves --- arch/x86/include/asm/hyperv-tlfs.h | 11 +++++ arch/x86/include/asm/mshyperv.h | 30 +++----------- arch/x86/kernel/cpu/mshyperv.c | 65 ++++++++++++++++++++++++++++++ drivers/hv/hv.c | 18 +++++---- 4 files changed, 93 insertions(+), 31 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..c38e4c66a3ac 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -198,30 +198,10 @@ 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); +u64 hv_get_non_nested_register(unsigned int reg); +void hv_set_non_nested_register(unsigned int reg, u64 value); #else /* CONFIG_HYPERV */ static inline void hyperv_init(void) {} @@ -241,6 +221,8 @@ static inline int hyperv_flush_guest_mapping_range(u64 as, } static inline void hv_set_register(unsigned int reg, u64 value) { } static inline u64 hv_get_register(unsigned int reg) { return 0; } +static inline void hv_set_non_nested_register(unsigned int reg, u64 value) { } +static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } static inline int hv_set_mem_host_visibility(unsigned long addr, int numpages, bool visible) { diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index f9b78d4829e3..938fc82edf05 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -41,7 +41,72 @@ 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_SIEFP: + return HV_REGISTER_NESTED_SIEFP; + case HV_REGISTER_SVERSION: + return HV_REGISTER_NESTED_SVERSION; + 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; + } +} + #if IS_ENABLED(CONFIG_HYPERV) +u64 hv_get_non_nested_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; +} +EXPORT_SYMBOL_GPL(hv_get_non_nested_register); + +void hv_set_non_nested_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); + } +} +EXPORT_SYMBOL_GPL(hv_set_non_nested_register); + +u64 hv_get_register(unsigned int reg) +{ + if (hv_nested) + reg = hv_get_nested_reg(reg); + + return hv_get_non_nested_register(reg); +} +EXPORT_SYMBOL_GPL(hv_get_register); + +void hv_set_register(unsigned int reg, u64 value) +{ + if (hv_nested) + reg = hv_get_nested_reg(reg); + + hv_set_non_nested_register(reg, value); +} +EXPORT_SYMBOL_GPL(hv_set_register); + static void (*vmbus_handler)(void); static void (*hv_stimer0_handler)(void); static void (*hv_kexec_handler)(void); diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 4d6480d57546..8b0dd8e5244d 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) { @@ -216,7 +216,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 +233,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); @@ -315,20 +315,24 @@ void hv_synic_disable_regs(unsigned int cpu) * addresses. */ simp.simp_enabled = 0; - if (hv_isolation_type_snp()) + if (hv_isolation_type_snp() || hv_root_partition) { memunmap(hv_cpu->synic_message_page); - else + hv_cpu->synic_message_page = NULL; + } else { simp.base_simp_gpa = 0; + } hv_set_register(HV_REGISTER_SIMP, simp.as_uint64); siefp.as_uint64 = hv_get_register(HV_REGISTER_SIEFP); siefp.siefp_enabled = 0; - if (hv_isolation_type_snp()) + if (hv_isolation_type_snp() || hv_root_partition) { memunmap(hv_cpu->synic_event_page); - else + hv_cpu->synic_event_page = NULL; + } else { siefp.base_siefp_gpa = 0; + } hv_set_register(HV_REGISTER_SIEFP, siefp.as_uint64); From patchwork Mon Jan 2 07:12:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 38012 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4048234wrt; Sun, 1 Jan 2023 23:15:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXtEk56vTouoMaSHQRgrRBKUJQEoAKSi6yEuNRj6IN/XcVTE1hHwepPMm5NqAYRL3XarLEiN X-Received: by 2002:aa7:ccc2:0:b0:477:8ab8:43e0 with SMTP id y2-20020aa7ccc2000000b004778ab843e0mr33778808edt.2.1672643704478; Sun, 01 Jan 2023 23:15:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672643704; cv=none; d=google.com; s=arc-20160816; b=gEb6MSfDRaNH355fuCPfIOWvAfYIlaQDBb9g7RdxTtZZFpDzuDkB0boIe+DGtO/WXa 7U+jVvlMGpXWNpPgU/TXjdBY6WDJm7czZsh1iDoXqYFprafao8sASgNXTkQtqQSv2Pj0 K3/3oK2SNjzrFNmjO1wZ1f9sCZkF2Jei7vqCCXLDPaXgKV0Njh/AwbdGHUI5V02Wq39S L4Ka9IvxNzy62d9x5/dn5VTDQh53kjnkmlPxaY4jETBPJ4cjterrNq1zBR4L4m5VQRqV eKPZZHZGTQfVQtDLbnLgMUC9Etm+SfM2PBaJsnZjnZVW1nO/u3nEGXBR49/FVOZtoabb tNLg== 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=V1UTcCzxZhrX66ni7EkN0sgxFpyq66pNFaLQ4WMDQKY=; b=aJvgoUy4Grn2kn9vVRc7AEVuxkqKeSnAmoP//gCdhiqh5226aVzrdwHcPiLvaTjz54 TKe+wif+c2lDInDpQHQ/HpY5h/7PYjCpWvSykOAelISGqzZXys8i9DBew5sC42/cNdp6 kfd/8ANP0Sb2PWjJHiphxeB3/PPxQY2bJCHWIAgFJ8GIWpfEC+ngX5YA49Aq3J7lFVmB i4PTGDv0DjTh4AwnVwIf+1N8i/CBkBxBG3bUDHxDseMkakJGRJW3D0JOfpLn18YmB07h sHztnLqM36sr+ybwRGmycs+IqUE4MIvmfqOwS5ioYnIhvewVceCbxrww5JANeeFffQA3 JxYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="liWS/ncg"; 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 z99-20020a509e6c000000b0046c9a4ab639si22710623ede.548.2023.01.01.23.14.40; Sun, 01 Jan 2023 23:15:04 -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="liWS/ncg"; 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 S231289AbjABHNi (ORCPT + 99 others); Mon, 2 Jan 2023 02:13:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbjABHNR (ORCPT ); Mon, 2 Jan 2023 02:13:17 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A539B21BA; Sun, 1 Jan 2023 23:13:15 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 3219A20FB6CF; Sun, 1 Jan 2023 23:13:11 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3219A20FB6CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1672643595; bh=V1UTcCzxZhrX66ni7EkN0sgxFpyq66pNFaLQ4WMDQKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=liWS/ncgcL4hihiWLdVcDMOAHCG90nokVu/dJlL3yVvvyfRw56QrrslvWAXOt33N3 uqZTZPlEnJ78GFejlOk02rHl6TXJH785c5cVjrheyG+oD1Ni5BmfxIg+1JAiemrkYG WioaEev+KnTgrHYEN5MHpClZMn/lfhCatmLlau74= 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 v10 3/5] x86/hyperv: Add an interface to do nested hypercalls Date: Mon, 2 Jan 2023 07:12:53 +0000 Message-Id: <24f9d46d5259a688113e6e5e69e21002647f4949.1672639707.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?1753894045013173498?= X-GMAIL-MSGID: =?utf-8?q?1753894045013173498?= 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 Reviewed-by: Michael Kelley --- 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 c38e4c66a3ac..9e5535044ed0 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, 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, 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, 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, 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, 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, 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 Mon Jan 2 07:12:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 38013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4048454wrt; Sun, 1 Jan 2023 23:15:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXurSskFdnpIIeyKXUvUaTcDH42jK5IlCmPqO2MtnAsAmeZW0EDSnHBLgwhQ+Z4dy4vewVe6 X-Received: by 2002:a17:906:2a05:b0:7c1:e7a:62e6 with SMTP id j5-20020a1709062a0500b007c10e7a62e6mr5933689eje.71.1672643757079; Sun, 01 Jan 2023 23:15:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672643757; cv=none; d=google.com; s=arc-20160816; b=GhfuZB3hhSsQVtoFZtu9RaOuz48hth5eK2i7PVMGz1lKTBzJQN6sjNdWQyEtPsVqmz yspVbIgTlwORsbyF91ediuZccBZ3NDNv9RqOhkY9WHjn+PknvApayahFNe7QdVmC3JqW dh/0REFALa4unsiVSvBzadSTRk4qL2KzcJp49QWaIS4t78S5caFVJN9U76Y6cDn1Wf/g wGcXz3OPpaFel386Mm2S3PbgTV8W97KZ+Dzrr0yJIGXU/IBf7fsLxzYi+Bdr/eAoA9Wj h6CD2tqoM0hMXxwX94ob+u5/pYeRySV6JAacmJZs/MvXNdFZ5ZUZV3XzK7kRo0JPXxXB LSTg== 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=WwgTdzq933yo46nX8RcCPBXut+LFdh0yPYBgTMkkcFM=; b=xCyGWSMMJpMhMd1MWhYMnk/hkjPdFZLy1S47PEJXcIEAfG1PojfV8GVx80PJYVOq6N GOPe5MzK2HDzDZsPlYDgBnCiCXrWUhsZHQFp1+ISeaQAyhUzBbGCJ0M9Bi4KKcQ5NCrX iQpj5KCutMB6GW/pVifIHpK9gOFsCatCXrCq2tq2FVNHYdc9iAMDFtpwhBh3YBRki5f4 pokhC33ghtGhi3RLHuqlO8E71boYX+omYk+dIwF3QeS0ojKhhMBih2zlDXGEycbth7ol JJSeqJScwLBGFP0TJvVdNItMDnU0wwgrnTufJh5uODdSNTa6DVpJEjrM9lnFmGU798mP 52xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="cpyT/cqo"; 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 w10-20020a05640234ca00b0048d63df54d7si4138367edc.20.2023.01.01.23.15.33; Sun, 01 Jan 2023 23:15:57 -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="cpyT/cqo"; 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 S231236AbjABHOD (ORCPT + 99 others); Mon, 2 Jan 2023 02:14:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230505AbjABHNh (ORCPT ); Mon, 2 Jan 2023 02:13:37 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 470B926D1; Sun, 1 Jan 2023 23:13:20 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id D10C120FB6C2; Sun, 1 Jan 2023 23:13:15 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D10C120FB6C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1672643600; bh=WwgTdzq933yo46nX8RcCPBXut+LFdh0yPYBgTMkkcFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cpyT/cqoWkkmbPfM0AhkKC4PwVsYK1NNGw80nxb7E5zfT9Pvu+/iBdUO1pSb4/IPj bZrzO7UVOpaCqLdNlgDJ7oAPEnFgcfp/2Ziuc46rEJ/daTigNwqsHdgjdQwJbLSonL Bfu+8aPTyfI8SEBKD9y4HdFbEWCtbyIs6O68FxUM= 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 v10 4/5] Drivers: hv: Enable vmbus driver for nested root partition Date: Mon, 2 Jan 2023 07:12:54 +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?1753894100713875953?= X-GMAIL-MSGID: =?utf-8?q?1753894100713875953?= 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 Reviewed-by: Michael Kelley --- 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 0f00d57b7c25..6324e01d5eec 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2745,7 +2745,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 Mon Jan 2 07:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 38015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4052187wrt; Sun, 1 Jan 2023 23:31:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXuY+HzWwrqH7xUkUbYalFaEjWUZEMxASY7NJU4z/JTZayq/qXpFQCV9CNwW7+EpExbktwna X-Received: by 2002:a17:906:398f:b0:7fd:ec83:b8b9 with SMTP id h15-20020a170906398f00b007fdec83b8b9mr33127059eje.44.1672644703660; Sun, 01 Jan 2023 23:31:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672644703; cv=none; d=google.com; s=arc-20160816; b=fXBUZ6dorSjRyPE2GuIBHTDF5HKmALn0CI+OYPKTFVrjGvDZEm2IEztRRLjC+Tr03G lmWhVGqt6LJaK79bPkPbm/786yQnlMJ/qMEQOa0Cf3REW2IjoppWv6BT0ERYvdNOI8o7 H669PZzZxJQdiW2c0Ff6c9gtZGYJqoQlKntm2TXEftcEgataEE+la5nzd29s64hs5WEt PQWgq41C2c2DQYUBHKlohN+XIo7ZeVudEQPcMpaHl+M4DBO02ShbKOjpngDjaF0bBe6h oX4UjsNWCe2DaiJEEMXAjcRQXLX7NST6Ki1SAmKtwfTlqK4DJJBZsHPnns9evhmKvnWO ze4g== 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=fKLjtuuPGAtchKDyFtDylHNiErV4QIBu79FyXGkX27g=; b=BrFeexvuiYgo/5zQse0aB0T/Tio4AgsatTLgiIbUdRG+vQcEpXqInM/T5W+Z/2nviP qX3FAnuP4j/us1OtFllE9OADY7N9RkcHaMZtiLM8/ENwVAQn+L0WHfnRYU9SLJCKx7LR nwSTNYvk4+h7fnep77Q9GUsVLFU12k2Tbdv3Bfl0GpNjrkwX+bTbvfmuLkfTwnKI4ctZ 2Q/Me0K5O6LMYF7s20Hahs1jVAKwQKBDq4hZ+Pi720z2ItVIc8EEbjnvv4RrMKqMrX1z tTehhh2R06YikXdcZpsiMwzooBLiGAHTGfxwkI6bASOmsyhu3B3raCvVAGCx3/ZvvKel Saxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ZXBG92DV; 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 ec40-20020a0564020d6800b0048e9a2f7678si606603edb.292.2023.01.01.23.31.19; Sun, 01 Jan 2023 23:31: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=ZXBG92DV; 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 S231489AbjABHOV (ORCPT + 99 others); Mon, 2 Jan 2023 02:14:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbjABHNr (ORCPT ); Mon, 2 Jan 2023 02:13:47 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F009126D9; Sun, 1 Jan 2023 23:13:24 -0800 (PST) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 7889C20FB6C8; Sun, 1 Jan 2023 23:13:20 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7889C20FB6C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1672643604; bh=fKLjtuuPGAtchKDyFtDylHNiErV4QIBu79FyXGkX27g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZXBG92DVin4cBqJkN3h2nlqzrovrbpitptcXZIalzrLuFVcOvgcI/oAcnA1R4PFzN wf4BegtWvJ6eFTC8GS0C4g0Xy6iGN1v9FRzYxjyBCjdtGhTolZnL2Ejx6Ow2++lTC+ b6yAWwaU40Pedfp63LB8VbC+nRCh5bJgSLhh8yts= 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 v10 5/5] x86/hyperv: Change interrupt vector for nested root partition Date: Mon, 2 Jan 2023 07:12:55 +0000 Message-Id: <021f748f15870f3e41f417511aa88607627ec327.1672639707.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?1753895092492928313?= X-GMAIL-MSGID: =?utf-8?q?1753895092492928313?= 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 Reviewed-by: Michael Kelley --- 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 | 10 ++++++++++ drivers/hv/vmbus_drv.c | 3 ++- 5 files changed, 35 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 938fc82edf05..4dfe0f9d7be3 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -126,6 +126,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..3536935cea39 100644 --- a/arch/x86/kernel/idt.c +++ b/arch/x86/kernel/idt.c @@ -160,6 +160,16 @@ 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 6324e01d5eec..740878367426 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2768,7 +2768,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