From patchwork Thu Apr 6 16:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 81049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp522776vqo; Fri, 7 Apr 2023 13:59:55 -0700 (PDT) X-Google-Smtp-Source: AKy350YnhGqMZvPCAmS/GnDNr+6WghNCLpDDz0DBTgCO3IOzRqm4JZIW+DZh3CAvfUZ2cqsMFrb4 X-Received: by 2002:a17:906:8684:b0:947:80a4:5cce with SMTP id g4-20020a170906868400b0094780a45ccemr568437ejx.65.1680901195192; Fri, 07 Apr 2023 13:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680901195; cv=none; d=google.com; s=arc-20160816; b=oITvd+neVXIr28mzxl+5PTyScIJJzGJZuRrbYvaCb6wHEax/IJAvuVX7mUxMX76tC0 pW5eDKWBRqcY9HzRLeJfV5VevKqmmYCOC2cklUAQhcw4jzVbRekGN7ULVLNWljTVWyrg H+P2vtrpoIvhIbWCoADAKj2JgLxOPrUw8fkXINabgaz6QqRTYRm5Y1cMnxAs7TasF/vQ H13Yzi6XZYTrxe3CYtgUxRzBH3PyUOHNo0VcXyVNNWxNMEpAROMCj8pGg16mwmd+wRGR APChbUUwHXIUD3WLWBJpp8kSznz6a6ma32T4NvyS693iyx7KWgLRaql6SwaTWEq3IrD5 KxVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:from:subject :dkim-signature:dkim-filter; bh=xX8UglqAO9D7VIeqlVY4oCyfwKnXYYeF9E8GHXwADe8=; b=v5FuJyXFkjYfT+4xIbsGr915zoE95hzIcNrewisbpFPp0GLPVgyqmFzcAPf7s4pnuw CZL7OtlabvzIxzMSz6QvYvwVVJnWpygmJhK6jTd0LcknjSh31PX0DlkPr86Xu7Oqzs0V v8axwDzx0uwWziAvGGaX2FXBbX/F33V+iZ3PC3YjSO/2PjE1XhuN057tBxj3mQCGDP+I KTUknGQTlEWvZpEU8IzkGiPV6rw2NEvm14SOp6iu4jRYoEbWizA+pnlQ0LE37UbdBtEe Jb2ADkrx4UzJ1q32BXmquMVSmV2IZvvu3aOKwIuXJe/+CxdHyO+m/Vpz0oaFGSOi4E3f Abng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=EBR4QqWw; 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 j15-20020aa7c40f000000b004fd16f5aa1bsi2028372edq.103.2023.04.07.13.59.31; Fri, 07 Apr 2023 13:59:55 -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=EBR4QqWw; 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 S231236AbjDGU6U (ORCPT + 99 others); Fri, 7 Apr 2023 16:58:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjDGU6R (ORCPT ); Fri, 7 Apr 2023 16:58:17 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E6296A5A; Fri, 7 Apr 2023 13:58:06 -0700 (PDT) Received: from skinsburskii.localdomain (unknown [131.107.1.229]) by linux.microsoft.com (Postfix) with ESMTPSA id 8A33F213B62E; Fri, 7 Apr 2023 13:58:05 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8A33F213B62E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680901085; bh=xX8UglqAO9D7VIeqlVY4oCyfwKnXYYeF9E8GHXwADe8=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=EBR4QqWwM+ZQqLtV4TvHcsYuZ2h/kW2CX9N2HwqasiNBonZKItJrQIHwbY/iIa9LU Yq+b2qJfdGikoEN5HDAlQciAAHgaHFPnoiazLeYjdnRKQ/JYglTHz6j/gq+nqaaYyN muYftxB+yz5U6DhigioqqwvacNI5xHPwAPJK6jN8= Subject: [PATCH 1/2] x86/hyperv: Expose an helper to map PCI interrupts From: Stanislav Kinsburskii Cc: Stanislav Kinsburskii , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 06 Apr 2023 09:33:13 -0700 Message-ID: <168079870998.14175.16015623662679754647.stgit@skinsburskii.localdomain> In-Reply-To: <168079806973.14175.17999267023207421381.stgit@skinsburskii.localdomain> References: <168079806973.14175.17999267023207421381.stgit@skinsburskii.localdomain> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-16.2 required=5.0 tests=DATE_IN_PAST_24_48, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH, MISSING_HEADERS,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) 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?1762552651224705985?= X-GMAIL-MSGID: =?utf-8?q?1762552651224705985?= From: Stanislav Kinsburskii This patch moves a part of currently internal logic into the new hv_map_msi_interrupt function and makes it globally available helper, which will be used to map PCI interrupts in case of root partition. Signed-off-by: Stanislav Kinsburskii CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: x86@kernel.org CC: "H. Peter Anvin" CC: linux-hyperv@vger.kernel.org CC: linux-kernel@vger.kernel.org --- arch/x86/hyperv/irqdomain.c | 40 +++++++++++++++++++++++++++------------ arch/x86/include/asm/mshyperv.h | 2 ++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c index 42c70d28ef27..fd9c487726e3 100644 --- a/arch/x86/hyperv/irqdomain.c +++ b/arch/x86/hyperv/irqdomain.c @@ -169,13 +169,35 @@ static union hv_device_id hv_build_pci_dev_id(struct pci_dev *dev) return dev_id; } -static int hv_map_msi_interrupt(struct pci_dev *dev, int cpu, int vector, - struct hv_interrupt_entry *entry) +/** + * hv_map_msi_interrupt() - "Map" the MSI IRQ in the hypervisor. + * @data: Describes the IRQ + * @out_entry: Hypervisor (MSI) interrupt entry (can be NULL) + * + * Map the IRQ in the hypervisor by issuing a MAP_DEVICE_INTERRUPT hypercall. + */ +int hv_map_msi_interrupt(struct irq_data *data, + struct hv_interrupt_entry *out_entry) { - union hv_device_id device_id = hv_build_pci_dev_id(dev); + struct msi_desc *msidesc; + struct pci_dev *dev; + union hv_device_id device_id; + struct hv_interrupt_entry dummy, *entry; + struct irq_cfg *cfg = irqd_cfg(data); + const cpumask_t *affinity; + int cpu, vector; + + msidesc = irq_data_get_msi_desc(data); + dev = msi_desc_to_pci_dev(msidesc); + device_id = hv_build_pci_dev_id(dev); + affinity = irq_data_get_effective_affinity_mask(data); + cpu = cpumask_first_and(affinity, cpu_online_mask); + entry = out_entry ? out_entry : &dummy; + vector = cfg->vector; return hv_map_interrupt(device_id, false, cpu, vector, entry); } +EXPORT_SYMBOL_GPL(hv_map_msi_interrupt); static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi_msg *msg) { @@ -190,10 +212,8 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) { struct msi_desc *msidesc; struct pci_dev *dev; - struct hv_interrupt_entry out_entry, *stored_entry; + struct hv_interrupt_entry *stored_entry; struct irq_cfg *cfg = irqd_cfg(data); - const cpumask_t *affinity; - int cpu; u64 status; msidesc = irq_data_get_msi_desc(data); @@ -204,9 +224,6 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) return; } - affinity = irq_data_get_effective_affinity_mask(data); - cpu = cpumask_first_and(affinity, cpu_online_mask); - if (data->chip_data) { /* * This interrupt is already mapped. Let's unmap first. @@ -235,15 +252,14 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) return; } - status = hv_map_msi_interrupt(dev, cpu, cfg->vector, &out_entry); + status = hv_map_msi_interrupt(data, stored_entry); if (status != HV_STATUS_SUCCESS) { kfree(stored_entry); return; } - *stored_entry = out_entry; data->chip_data = stored_entry; - entry_to_msi_msg(&out_entry, msg); + entry_to_msi_msg(data->chip_data, msg); return; } diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 4c4c0ec3b62e..aa0e83acacbd 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -203,6 +203,8 @@ static inline void hv_apic_init(void) {} struct irq_domain *hv_create_pci_msi_domain(void); +int hv_map_msi_interrupt(struct irq_data *data, + struct hv_interrupt_entry *out_entry); int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector, struct hv_interrupt_entry *entry); int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry); From patchwork Thu Apr 6 16:33:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 81050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp523033vqo; Fri, 7 Apr 2023 14:00:25 -0700 (PDT) X-Google-Smtp-Source: AKy350YKRKZSjvFQBlht8QnFaXx3Muf3CyhCJx6cNoqYcoeYY12yxTu9eaR9yDy0YkvO2mFLeGXu X-Received: by 2002:aa7:c14c:0:b0:4fb:3ab9:fe81 with SMTP id r12-20020aa7c14c000000b004fb3ab9fe81mr3627496edp.30.1680901225235; Fri, 07 Apr 2023 14:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680901225; cv=none; d=google.com; s=arc-20160816; b=hBvcKnkz6tOGcKygL5xuH4FqpX/lpOBSQn2IBMragQwNU1qehSwbRZIYd6cGXVTwpt U10Qd2Ph28aQoxBryIa+wrRuJYFkvJLkcDVSYtelJrINZPLB2V3UeQ+h2vXZairL8W3F 63G1BVmtdokQWGTxjq/O40aOsShTBe98ldWeV85n95c7vMjuRimaIriQLE1evjDbwgOi j5aWdEVE7DHdMdhHWLj59BTVJHt7I3pjYWxpCdq0aXq4kVT8cmPxlSGOvaed6lqOY9Hd CtCjdiLDD/J4YJeHBX4A0cojsiVKjitNuFKCyK+qQxlSf3Bf/kEdE6zSm+6mzIZ5cSZL IzHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:from:subject :dkim-signature:dkim-filter; bh=32mhPLCSnFqlWC0muL7q44icEI++yknNcaEQIU1ZLvE=; b=ieBYNp8/jZkoXz7xu385xDsHok2359WDuYU2yGtRSa6MuZAwxUBUOWjTLJfXdAgG04 XvpRlT09eJaDwKu0STDZS1DZ4mSgQofzPZeTMCnfPNsYtE5dE2TW7w3XqM4RBqHoesDF BvsFHBwZbczXDSzZS08ybUHaW7B2GWiYWASZRw9awq2weY+VLWPezhdCt1rqox/ZbTqt TggzmeNuaL9m7E84acgOshZ4HNFk3ajQHDNCw+C8Z4yPbDiOcIQJJq6xDOOB4OvY4TeP l9ommDd/OpaCaV52IXf3ValoGioYnGL4XZLxD309xswawP3aObaho0V8opPKEwpqgAL8 vR0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rLRQUe03; 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 l1-20020a056402124100b004abcb9e6563si4114896edw.80.2023.04.07.14.00.01; Fri, 07 Apr 2023 14:00:25 -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=rLRQUe03; 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 S231262AbjDGU6X (ORCPT + 99 others); Fri, 7 Apr 2023 16:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbjDGU6T (ORCPT ); Fri, 7 Apr 2023 16:58:19 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 45E1AC17E; Fri, 7 Apr 2023 13:58:17 -0700 (PDT) Received: from skinsburskii.localdomain (unknown [131.107.1.229]) by linux.microsoft.com (Postfix) with ESMTPSA id AE674213B634; Fri, 7 Apr 2023 13:58:16 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AE674213B634 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680901096; bh=32mhPLCSnFqlWC0muL7q44icEI++yknNcaEQIU1ZLvE=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=rLRQUe03PQBMKbXvSZ/VJWDxgdc9PySimsj3H5+d3DxKwZjzOd7WeHSUUetID2zxh nayWNjg4p5Co3J52iHGyG4JgzQm14NIt/oJhXv8wMvDRwEzY6CKH3KWd94mThdmOxA wVJYjO39KNVcye7uCLbs6BOrthe+MQi/hGzv8c+c= Subject: [PATCH 2/2] PCI: hv: Deal with nested MSHV setup From: Stanislav Kinsburskii Cc: Stanislav Kinsburskii , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 06 Apr 2023 09:33:24 -0700 Message-ID: <168079879905.14175.16212926378045082102.stgit@skinsburskii.localdomain> In-Reply-To: <168079806973.14175.17999267023207421381.stgit@skinsburskii.localdomain> References: <168079806973.14175.17999267023207421381.stgit@skinsburskii.localdomain> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-16.2 required=5.0 tests=DATE_IN_PAST_24_48, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH, MISSING_HEADERS,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) 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?1762552683021917446?= X-GMAIL-MSGID: =?utf-8?q?1762552683021917446?= From: Stanislav Kinsburskii Running Microsoft hypervisor as nested (i.e., on top of another Microsoft hypervisor) imposes a different requirement for the PCI-hyperv controller. In this setup, the interrupt will first come to the nested (L1) hypervisor from the hypervisor, running on bare metal (L0), and then the L1 hypervisor will deliver the interrupt to the appropriate CPU of the nested root partition. Thus, instead of issuing the RETARGET hypercall to the L0 hypervisor, MAP_DEVICE_INTERRUPT hypercall should be issued to the L1 hypervisor to complete the interrupt setup. Signed-off-by: Stanislav Kinsburskii CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Lorenzo Pieralisi CC: "Krzysztof WilczyƄski" CC: Rob Herring CC: Bjorn Helgaas CC: linux-hyperv@vger.kernel.org CC: linux-pci@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/pci/controller/pci-hyperv.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index f33370b75628..61bee8babad4 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1570,7 +1570,16 @@ static void hv_irq_mask(struct irq_data *data) static void hv_irq_unmask(struct irq_data *data) { - hv_arch_irq_unmask(data); + if (hv_nested && hv_root_partition) + /* + * In case of the nested root partition, the nested hypervisor + * is taking care of interrupt remapping and thus the + * MAP_DEVICE_INTERRUPT hypercall is required instead of the + * RETARGET_INTERRUPT one. + */ + (void)hv_map_msi_interrupt(data, NULL); + else + hv_arch_irq_unmask(data); if (data->parent_data->chip->irq_unmask) irq_chip_unmask_parent(data);