Message ID | 021f748f15870f3e41f417511aa88607627ec327.1672639707.git.jinankjain@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;cscallsign@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <jinankjain@linux.microsoft.com> 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: <cover.1672639707.git.jinankjain@linux.microsoft.com> References: <cover.1672639707.git.jinankjain@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> 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?= |
Series |
[v10,1/5] x86/hyperv: Add support for detecting nested hypervisor
|
|
Commit Message
Jinank Jain
Jan. 2, 2023, 7:12 a.m. UTC
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 <jinankjain@linux.microsoft.com>
---
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(-)
Comments
From: Jinank Jain <jinankjain@linux.microsoft.com> Sent: Sunday, January 1, 2023 11:13 PM > > 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 <jinankjain@linux.microsoft.com> > --- > 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 > > -- > 2.25.1 I'm giving my "Reviewed-by" based on what I know, but I'm unsure about the validity of grabbing vector 0x31 out of the middle of the range versus at the end like all the other fixed vectors. Getting this changed on the MSHV side would really be a better solution. Reviewed-by: Michael Kelley <mikelley@microsoft.com>
On Mon, Jan 02, 2023 at 07:12:55AM +0000, Jinank Jain wrote: > 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 <jinankjain@linux.microsoft.com> I've applied all but this patch to hyperv-next. This patch still needs an ack or nack from x86 maintainers to proceed. Thanks, Wei. > --- > 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 > > -- > 2.25.1 >
On Mon, Jan 02, 2023 at 07:12:55AM +0000, Jinank Jain wrote: > Traditionally we have been using the HYPERVISOR_CALLBACK_VECTOR to relay Who's "we"? Please use passive voice in your commit message: no "we" or "I", etc, and describe your changes in imperative mood. Also, pls read section "2) Describe your changes" in Documentation/process/submitting-patches.rst for more details. Also, see section "Changelog" in Documentation/process/maintainer-tip.rst Bottom line is: personal pronouns are ambiguous in text, especially with so many parties/companies/etc developing the kernel so let's avoid them please. > 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 <jinankjain@linux.microsoft.com> > --- > 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 ^^^^^^ This patch looks like it is not ready to go anywhere yet... > + * around VMBus interrupt vector allocation for nested root partition. When is that going to happen? If at all... > + * 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 Well: /* * IDT vectors usable for external interrupt sources start at 0x20. * (0x80 is the syscall vector, 0x30-0x3f are for ISA) ^^^^^^^^^^^^^^^^^^^^^^ */ #define FIRST_EXTERNAL_VECTOR 0x20 I guess HyperV decided to reuse those...?
Jinank! On Mon, Jan 02 2023 at 07:12, Jinank Jain wrote: > --- a/arch/x86/include/asm/irq_vectors.h > +++ b/arch/x86/include/asm/irq_vectors.h > +/* > + * 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 arch/x86/include/asm/irq_vectors.h line 47: /* * Vectors 0x30-0x3f are used for ISA interrupts. * round up to the next 16-vector boundary */ #define ISA_IRQ_VECTOR(irq) (((FIRST_EXTERNAL_VECTOR + 16) & ~15) + irq) So this overlaps with the legacy interrupt vector space. > +#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 I agree, that this is a hack, but that puts it mildly: It's a completely broken hack. > +DECLARE_IDTENTRY_SYSVEC(HYPERV_INTR_NESTED_VMBUS_VECTOR, sysvec_hyperv_nested_vmbus_intr); This generates the low level entry stub for vector 0x31 at compile time, which competes with the interrupt stub for external interrupts generated by: SYM_CODE_START(irq_entries_start) Now the above INTG() hard-codes the IDT entry for vector 0x31 into the apic_idts table. That marks it as system vector which in turn prevents idt_setup_apic_and_irq_gates() to install the IDT entry for the external vector on _ALL_ systems unconditionally. IOW, you broke world except for systems which do not use the legacy interrupt space. Congrats! That legacy space is hardcoded and that's clearly documented so. 0x31 becomes IRQ1 - usually the i8042 - which makes it pretty much guaranteed that this collides and fails. The worst case consequence is a fully uncontrolled interrupt storm which is not even detectable. So this patch is /dev/null material and either the hypervisor side makes it possible to use a different vector space or this needs some very careful modifications to the legacy ISA vector assignment. Thanks, tglx
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