From patchwork Wed Nov 2 16:35:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 14386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp16973wru; Wed, 2 Nov 2022 09:42:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM61SZt6MGhQg+jwGFFZ+KGoNukyRhsDkFyfjY/6R6uDdnbrgigmpCcZ/x96HRFByOz3tC1R X-Received: by 2002:a17:902:f786:b0:180:6f9e:23b with SMTP id q6-20020a170902f78600b001806f9e023bmr26145287pln.37.1667407330589; Wed, 02 Nov 2022 09:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407330; cv=none; d=google.com; s=arc-20160816; b=MOz43IfX/dqr2meUz0JDw+5Qi8QZB8wF13gkyE7EwfFpdkfciIcRi4bZFIeSrhnnfD gXjU55a/NPPlzp8uHff4OQkZ05++pSPVOWtdhSq3UBkkIumrKQN8IIctjzXLmw21hqfG KgDWhegNDKrajcAwPpQGNNhtv/N77Qgct7KmzeWGAewnBq2w0N0NANQPblnTplQ+DorX lRS3jGMavcbKp1ZmMuDBhBdQEdfhsuHgWTyidZlV9WmGZkGH/8YV3YBZIye9Q3XaxEWl p0DfSNKQiwT0GxzonQ+SR0YfFxL8WpKXB+7GgmCs514M/5l5t80TK0S0a/VuDJOdgtVL OuFw== 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=oW+0gwVBEPgjicK1Au5RL8r3QijDOXjFhJUc9gdVX18=; b=ZiAgmREYaDIR2iZbB+mNZuB8KZ6O90kaK7Z1RJeSD+zLFpUSHUNltCvArr5jTF3lZa ep9CWjN5EHsJkHpGVZFwVTVvPTmIGV2Z56H35h7VWdu8In3xHtCSAXLQ3TQclGXk49P2 Ls6N76EE2eh/zt2t2Waj4YTuLTcUa3rQIDIt9fgQR6U2VTVhsv+IWbne6a65UxuStDkO c89fP5HICnfxHSLAnaXE7fpPFnWHfcvAGX2wVJyjjY6SsGvrRBaWu8e5/0bsg+p9+rjf hsp3APvroaoDFkpPyTKTgA5mSBUb+cLOvDYcDbhlBXh5b8Xb2Yft4TrG4I57ej7V9c28 qhfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="KBNLn/Ux"; 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 g6-20020a056a000b8600b0056c2a741b03si19616725pfj.81.2022.11.02.09.41.53; Wed, 02 Nov 2022 09:42:10 -0700 (PDT) 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="KBNLn/Ux"; 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 S229875AbiKBQlb (ORCPT + 99 others); Wed, 2 Nov 2022 12:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbiKBQk5 (ORCPT ); Wed, 2 Nov 2022 12:40:57 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B72D22ED65; Wed, 2 Nov 2022 09:36:12 -0700 (PDT) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 8C23D20C28BD; Wed, 2 Nov 2022 09:36:08 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8C23D20C28BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667406972; bh=oW+0gwVBEPgjicK1Au5RL8r3QijDOXjFhJUc9gdVX18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KBNLn/UxImLyYQaCXoVZ1wFrGLXg2bT+PKX6p+TRyOPjFbpW2Y2X2CtVdcMuBk15A MVB8xCRUd9jvg23ifU5s1XZ90oLgx04F8+kJ8W845y0FzC/9DVVpixxk4dPo3JRuPN 5BXeOrwBkoXkV5KOU+w8ICezSIVB5yhutNDKuV8Q= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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 Subject: [PATCH v2 1/5] mshv: Add support for detecting nested hypervisor Date: Wed, 2 Nov 2022 16:35:58 +0000 Message-Id: <4200eb3ffd5453cc9c9812b05283f6c2d6a6bef5.1667406350.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?1748403308983257273?= X-GMAIL-MSGID: =?utf-8?q?1748403308983257273?= 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/x86/include/asm/hyperv-tlfs.h | 3 +++ arch/x86/include/asm/mshyperv.h | 2 ++ arch/x86/kernel/cpu/mshyperv.c | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 3089ec352743..d9a611565859 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/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 61f0c206bff0..29388567eafd 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -190,6 +190,8 @@ static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {} extern bool hv_isolation_type_snp(void); +extern bool hv_nested; + static inline bool hv_is_synic_reg(unsigned int reg) { if ((reg >= HV_REGISTER_SCONTROL) && diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 831613959a92..2555535f5237 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: Linux running on a nested hypervisor\n"); + } + /* * Extract host information. */ From patchwork Wed Nov 2 16:35:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 14387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp17089wru; Wed, 2 Nov 2022 09:42:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nn5sbH/qgVwpaMmuK+wRJOPm0E5gNu339QNEkdJRdSIsEzwhsemLOVHb4IHhm6SfW6TuQ X-Received: by 2002:a65:6148:0:b0:458:88cd:f46 with SMTP id o8-20020a656148000000b0045888cd0f46mr21987100pgv.303.1667407344346; Wed, 02 Nov 2022 09:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407344; cv=none; d=google.com; s=arc-20160816; b=PrvKPxduimrynxUVso3QgqHAXSrOXxLs/UYwiF2iTFz1KbCxQZjaDlhhHLZ0g+SHJO ua1d3/FzlhIntT4EOVrzqvsg/UtOniX9R6fpgKamSXru7Ebyc8XaaD7FKlfYJiWX20+Z xZqPw0jhhOqAEmRKQWF+zZE5l8uCu1ukK3LRW8XP0rz6bN10KQrtxmV2byrwUSMDQp6v 5xFs3x6K2aOB7ZwwgAYz2FUYBKH/iHmRUv0Mv+XPmpHZ7yhn8OGXzxnXjcceMnt8CGrn g5DJ8783xWeNfwWSRgHP7Hr3BwAN67iK5xkwLMZzF0ppRzPG96xp3DEq4Rfght4uovaH J4qw== 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=4Ogh4rhxViGGAO+FompEXstUyO65kUpHKIeEc1/rjzg=; b=qeDJFsHOy6pxPaN/HpkwmVLuUucgnFT3YVUs1+THUF+tk0qfa4sNmArK5knrv/Akq8 cZk8S5cZq0LXpcHcApmdZT20H4/eRF/FgTQ9IcyxfeF1xv8eqnmZax5OT3i5CMK8/kw3 qAyVxGk/fZ/siP+qwLl5Vb+Ft4R4PzhgBWWuiAyL0NbuRh7Dt3H0dM3CmUwpDYIwMl7D ePn/rvBreHnog6z7bK4DZwwqT2QQhl90hfioP0SY4SNLdwNJFye88Y6zUj9L0uL+L6Eg 5XFeX9+UWUfigGmpZq5EqTmNXbeSLBgox9v5f6WOnyxiFuA/7fEs+gHCWxz/WzncieOp SkDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="P/WpImMU"; 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 y7-20020a1709027c8700b0017d2c45e93fsi15983972pll.169.2022.11.02.09.42.09; Wed, 02 Nov 2022 09:42:24 -0700 (PDT) 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="P/WpImMU"; 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 S231631AbiKBQlg (ORCPT + 99 others); Wed, 2 Nov 2022 12:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231639AbiKBQlA (ORCPT ); Wed, 2 Nov 2022 12:41:00 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19D542ED74; Wed, 2 Nov 2022 09:36:17 -0700 (PDT) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id E8BE5205D3B9; Wed, 2 Nov 2022 09:36:12 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E8BE5205D3B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667406976; bh=4Ogh4rhxViGGAO+FompEXstUyO65kUpHKIeEc1/rjzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P/WpImMU3XPhwjsN+kW2pd/GPgsMH3Aao08e/OC65yj9jRQ5W4WkGlyTxUEy07THO db4XmBxFYx6LrgAptoOIcTMIntuYAtVQfLpC3kiGLI+zDZJYz9RYQJEQNVgL9Tdi8a P3/ShXZedpf0FEwE6dFGhSQ6fv2WmX0ULzejs+hc= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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 Subject: [PATCH v2 2/5] hv: Setup synic registers in case of nested root partition Date: Wed, 2 Nov 2022 16:35:59 +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?1748403323473786233?= X-GMAIL-MSGID: =?utf-8?q?1748403323473786233?= 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 | 24 ++++++++++++++++++++++++ drivers/hv/hv.c | 18 +++++++++++++----- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index d9a611565859..0319091e2019 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 29388567eafd..415289757428 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -200,10 +200,31 @@ static inline bool hv_is_synic_reg(unsigned int reg) return false; } +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; + } +} + static 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 @@ -213,6 +234,9 @@ static inline u64 hv_get_register(unsigned int reg) static 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); 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 Wed Nov 2 16:36:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 14388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp17290wru; Wed, 2 Nov 2022 09:42:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7OImG1uDm3zX6ewcNZwlxLiP5w7mBwGz7GhxJFY6VNOCDNKu5eOYGlduvLJifp3+ETAaCC X-Received: by 2002:a17:902:e54f:b0:187:2e45:e191 with SMTP id n15-20020a170902e54f00b001872e45e191mr12827815plf.91.1667407366811; Wed, 02 Nov 2022 09:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407366; cv=none; d=google.com; s=arc-20160816; b=1C9+nP7JKgGysEbCa3/gyz3V8Q6VIchuPXm3t/L+yg3pLj2TjNMefso5N3uYGxdimv SAXF1egBPM4WaC69FCXhkN6v4FKd3sFIofeec3Ru6la4NtixMgMvxKFGMjTcyjjvnDpu avmdNTUbVswKS3E6Ja/Wz6ZSN9PZYEFlxFHehqHKLPAYmBg3IdshKxtUdS6IolSK7RNI +EzLh9s1WtmWbOwcy0TMQ0GwTNkMGB/h/FJwZE7xNR8oYoybPOiqnBzKL9is7bJqXC9/ F8zqaPoPZZNU1VUbzSKrNH0JB10Z9m7o/2MuBwqng/JVEdZvhwHjHe8aevLis+kc7Bn7 v9jQ== 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=r21wKJL5UQr7YhLIWikHB7TOW+Z+Q5QGZUIT5zsz2PY=; b=lWOaHVwgKn+G5toncH1ZAMmgPVgsMBtmjTLPGIPNxjijfFu12eANUBIlrJx5xhutBO FJXaOaOCH83VERUXYLePnoksvo1Zxk33kpF9uP0CUn/eLYrPv/F/h1UanZudzPr2Vetw p7Gk1s0Aw0xDO4BROtV1ayWPGxNZk5HU1syv3zNv/0m+WhB3of1viBU0z6VQbVZYYv9L winBrs0dVOBlBQD4xvsllQpAmx78lUogcvrAplARDLEyVheQlYnseEgnz9T3npYcOV+y ndu93sKhzyhSqc4poxRCTIaRygLERjWJxTB0o1wuqp2AiwhT8651biW3F5pRMH/RdYgB kQsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=quPaU0vB; 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 d9-20020a631d09000000b0042b438eeee1si5404189pgd.148.2022.11.02.09.42.24; Wed, 02 Nov 2022 09:42:46 -0700 (PDT) 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=quPaU0vB; 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 S232031AbiKBQlv (ORCPT + 99 others); Wed, 2 Nov 2022 12:41:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbiKBQlI (ORCPT ); Wed, 2 Nov 2022 12:41:08 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74D922EF0B; Wed, 2 Nov 2022 09:36:21 -0700 (PDT) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 50FA720C3338; Wed, 2 Nov 2022 09:36:17 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 50FA720C3338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667406981; bh=r21wKJL5UQr7YhLIWikHB7TOW+Z+Q5QGZUIT5zsz2PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=quPaU0vB/GISothe+aKqKZfeFbzAS48ZDlBRDPoAmze19CMtgGmqmHVqUz3mHDMEO Hyl4OEDHzjxJVYjTqOhvqyocrr45D12OhYGaKNyr6NKtclTZdZELArE9B5Kk3WFuiq cFSzDCbFbvSHWOiWqaDyidMCmwqItGuJVQr0Cfqo= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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 Subject: [PATCH v2 3/5] hv: Add an interface to do nested hypercalls Date: Wed, 2 Nov 2022 16:36:00 +0000 Message-Id: <0a960bee61e46c4e368f351d3cf40d60ff28ca8b.1667406350.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?1748403347396891545?= X-GMAIL-MSGID: =?utf-8?q?1748403347396891545?= 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 + include/asm-generic/mshyperv.h | 1 + 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 0319091e2019..fd066226f12b 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 415289757428..451d8c3ab63b 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 fdce7a4cfc6f..c67836dd8468 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -185,6 +185,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(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) diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index bfb9eb9d7215..a2524d96ce2d 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -53,6 +53,7 @@ extern void * __percpu *hyperv_pcpu_input_arg; extern void * __percpu *hyperv_pcpu_output_arg; extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr); +extern u64 hv_do_nested_hypercall(u64 control, void *inputaddr, void *outputaddr); extern u64 hv_do_fast_hypercall8(u16 control, u64 input8); extern bool hv_isolation_type_snp(void); From patchwork Wed Nov 2 16:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinank Jain X-Patchwork-Id: 14389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp17546wru; Wed, 2 Nov 2022 09:43:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7WaqLKhZzZt1lKO/UGquzEHeU0wAoDXR0tUT098vyWGH1TL4YCag0x0pcL8UD6uGjDne0G X-Received: by 2002:aa7:d710:0:b0:463:bd7b:2b44 with SMTP id t16-20020aa7d710000000b00463bd7b2b44mr8896237edq.385.1667407396185; Wed, 02 Nov 2022 09:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407396; cv=none; d=google.com; s=arc-20160816; b=vmVg8+9qsz1o2ZXotfI68GKkVE2MqXSPs97KvfW/bzpqX/BNzrvkdoJO+R5ZhzUY9r I3ZGZfGOVrFov7BpBLQzA9EmqsFozMkvtCAp03zVCakiYfHQyuSzNtQjrFzwN/oGmDnk NdK1B6vTU3DSIQbub2+TL9hU/mNaCCG9dmBVn7rsKCKqwLvFENt15wFo1inf/r7vxFOy LP1lJu61sHbhIbhcLwygSl4ND7QM0oWEIYGhcELg3sbYWS/jtAIRQRDLAOuET9jT0oQ0 5t4yC+3waVB6XQ5bnikpPzpEXxecOCagAvUPdDnAEaEa0gky+20aBp8M6MxkTfTMQ8ju H55A== 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=1B9p6pFN0yHl6pLuVEuKSNR9XxSBhvzkr5T1mlusw7Q=; b=sTmwDTOplS5KAB1XT+LKwd3A/rZRtNR1cdtEeJKzTEjTB/u7qP/WfAvv8aGcSsZ1bh Xr69aam5P+O7Yf1l9qbBBD0uZVLj3x3Yur2TDd5NSONIcAxEBgoD6kWvePypfXu+Ji8F alVUuNaOOcpykqyGtHtXgLufBhtkxsBd+28ZoAFiZvfR0jHCiy69GJqC8b4cxvO/PfUJ 2Gyruduwdo0fuCe2+xsHwRdoEVQkoR9u64d5Hf3z9UZzam3mosikaCrB46g+Csjazk// MjTAGIKn5l5Mf1LqCVkaXoFfMWuviPOWPGu67dWQfssPU0yDsLcoz7TflgJcECvPFU0y ej+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=bEfUmfGA; 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 dp20-20020a170906c15400b0078df19995e4si17384315ejc.241.2022.11.02.09.42.47; Wed, 02 Nov 2022 09:43:16 -0700 (PDT) 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=bEfUmfGA; 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 S232102AbiKBQmG (ORCPT + 99 others); Wed, 2 Nov 2022 12:42:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231944AbiKBQlU (ORCPT ); Wed, 2 Nov 2022 12:41:20 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D24082EF47; Wed, 2 Nov 2022 09:36:25 -0700 (PDT) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id AD76720C333D; Wed, 2 Nov 2022 09:36:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AD76720C333D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667406985; bh=1B9p6pFN0yHl6pLuVEuKSNR9XxSBhvzkr5T1mlusw7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bEfUmfGAOBS5gITdkhShpUgdIYz8e+w/nnho/XxjusjA2Kkf5dnpHM4P8CHymhhL8 8HCaxw248anAGvGRKkFoo8Qmn43xKnKtKQfY9wCv17wcfD2JfZKky368V8dGvXvmkG ak3Witv1f52bZtBBpaQGXphevowOygPlmqzZFDeg= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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 Subject: [PATCH v2 4/5] hv: Enable vmbus driver for nested root partition Date: Wed, 2 Nov 2022 16:36:01 +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?1748403377674383072?= X-GMAIL-MSGID: =?utf-8?q?1748403377674383072?= Currently VMBus driver is not initialized for root partition but we need to enable the VMBus driver for nested root partition. This is required to expose VMBus devices to the L2 guest in the nested setup. 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 8b2e413bf19c..2f0cf75e811b 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2723,7 +2723,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 Wed Nov 2 16:36: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: 14390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp17572wru; Wed, 2 Nov 2022 09:43:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6v5JJwHqeC8XPD/q9iDU5HPHZY+UDB1xx28ZPvng/ZBRyIaxMoXph7dPu76M8ylxQAbPVh X-Received: by 2002:aa7:d553:0:b0:463:18d3:195c with SMTP id u19-20020aa7d553000000b0046318d3195cmr21968368edr.235.1667407398939; Wed, 02 Nov 2022 09:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667407398; cv=none; d=google.com; s=arc-20160816; b=YvS20QpvTowDtUTkUDS6g4aeNhGGGiA+Qljtm/gyxy1Bc/ri02cGEGsgaJnK3lfzBQ p88sQmVTCb1EN/m0yOCO7rdEiOIy8rUcv0QYyYtVYwA90JIVYMN+f3m0iP/BaWZhJx4X BmdxTMKmhJ/AfYegCsOKdBnZISBs5zlfT/B8rEOFVaTB11HvL7wCs580BmH1Ss5BUp7V AVj3ctODs40dZ3nF08YVCP/oABC+CxcfKCxMqx7yoF24FTktFz+Tc9VNnNyyCumilqPa XjWnI2nZUd4yXccWLl/BvyK9yVV9aSM2rlevc11+3hOAebSVlX1qdJczC4+7yZqzd3XF B9+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=J4DNJwZlTDLqAsrM8lj5O6r1qnyNqnGW9RCCuM0lraM=; b=f3rFseHPt14ObFwLFKFDAg44FFJPJE9Wd/XtAuhgMjCdgpEtUI4KJdJj4UGBxvsRZk V75CQSd4aurcRBHhL4dqi7LQuPpkJ5tMyGrUH5H7k0vg7Fs+uaomVM7jVzrdJBbQhoK4 vAg4yhaP3864reoD8PLSCDQzuzdL8y/L3N5AJ7zr6Bt0llAEWkuLVBClrFh2HuXUT34w UWT4jblCo5jRusxMsAp5LDAL/XagX9S3HkYrPfwt29Cp4zL0Q6nACt28ge+i5WdIDt4l IRCu5wRKy+jvDseSeUlT+VpPFB2hZbX3uUTU2/4MXZjPA9Ta3+4gGCL1sJuBqHioV/I7 nQWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aCDmfOGe; 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 i20-20020a1709064fd400b007a5cdd9550esi18596822ejw.201.2022.11.02.09.42.51; Wed, 02 Nov 2022 09:43:18 -0700 (PDT) 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=aCDmfOGe; 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 S231410AbiKBQmM (ORCPT + 99 others); Wed, 2 Nov 2022 12:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231981AbiKBQl1 (ORCPT ); Wed, 2 Nov 2022 12:41:27 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3AFF02EF6B; Wed, 2 Nov 2022 09:36:30 -0700 (PDT) Received: from jinankjain-dranzer.zrrkmle5drku1h0apvxbr2u2ee.ix.internal.cloudapp.net (unknown [20.188.121.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 159E020C333F; Wed, 2 Nov 2022 09:36:25 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 159E020C333F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667406990; bh=J4DNJwZlTDLqAsrM8lj5O6r1qnyNqnGW9RCCuM0lraM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCDmfOGejL0g0dqhcXtMlxsRuk7MX18AmwVv1BIYx2gKTV3c4F+D27f0MLtNKgKyN 2saSYeaem53OIlzxxPWOqvr0docvuCFSGa1iZh9/Y36gq0e4gIG12FKZUbZnHcYZae tbpDJweuMl0D1cx3jYbEK3PJRuY0oTB3u25JlOB4= From: Jinank Jain To: jinankjain@microsoft.com Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@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 Subject: [PATCH v2 5/5] hv, mshv : Change interrupt vector for nested root partition Date: Wed, 2 Nov 2022 16:36:02 +0000 Message-Id: <66eddd647536f7153462848c34958029e9e9caad.1667406350.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?1748403381232607904?= X-GMAIL-MSGID: =?utf-8?q?1748403381232607904?= 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 2555535f5237..83aab88bf298 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -61,6 +61,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 2f0cf75e811b..e6fb77fb44b9 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2746,7 +2746,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