Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1383003rdb; Wed, 6 Dec 2023 18:18:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKVsW7pKv1UEwrPKmZbB14ocD1uCMdJucCpYI9osrpqP9Vf5JftXCeB3rknHmg/82sU6vz X-Received: by 2002:a17:903:191:b0:1d0:a53e:263a with SMTP id z17-20020a170903019100b001d0a53e263amr1684318plg.109.1701915512968; Wed, 06 Dec 2023 18:18:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701915512; cv=none; d=google.com; s=arc-20160816; b=rg1BkK2o6ZMTmudEdMr/HSuQqwfbiXrHqrQdw2kp+h6o+3O5BE3aR6UwV+4jIAt81f X4wwf9ekpx1HwGEYnLYoQTmZCuef4Uv/R5eGwDHVe3gabVcdVOpMTPrsGCJftHw64bPm BtRK7FyoiiwaYt2/VxaER1aLMv8BGugLJCgRKwpf/+joHs/N+e4VN9SpXsZy4WlFMry+ gLizgN8Yc8IiOwh4eeKyjYRIeejVl7tkgRTwcRb9yUg8LFV+0i1tbvg2xSg+KLy5PgZW BNrmMl+CdiqsHMgXS8cTxNvAIM+P76OiqOvAUrZczNNZMhkR09DBTs6z3xPy0N6AB3gc IvPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=usKFdb7K4Ul6NjKvfQPUROsFdrbzJEzA8RrdFHrUaRw=; fh=xWfT71I4hcG2nfzrskW0rEWtY2w1rqowohoiUcq1Jjo=; b=1GOhfSLPbUAt6iUoV9/8XWP8xe0z5JG4qxOiIbQC6y0LIgJl32W9cf5cHVyvqQcmMH Dgd7aSHhR94kS020DuRlxFvqhsVnrOZUCNFZGNdxkIRqVJOly1ZzuPM4jTKCgubOuCEe uMUH1jYR1HUqr5wBuYZxS0gpkoDVLromuJPPnf2XvIF9zIJ3oR8HI3xwZ7USMxTKEOFs Gnt4eH0VIyXUvllpwwGIeyboZeLl+2N1RpTVqMLhYmH+dOM3OYRJ3sCwLL3ZGxcGqSUN xG8IG0ow8Sawle01tZqFjbBLDfVlMCxQ9ur5mWGmSaEm9zB8ZVN3cl6kk9mlRyzvrZ0M oOsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GPEqMtN8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bi11-20020a170902bf0b00b001d0c442d76dsi235912plb.246.2023.12.06.18.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 18:18:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GPEqMtN8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 757D38312AFE; Wed, 6 Dec 2023 18:18:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443016AbjLGCSP (ORCPT + 99 others); Wed, 6 Dec 2023 21:18:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443004AbjLGCSO (ORCPT ); Wed, 6 Dec 2023 21:18:14 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A4FFD44 for ; Wed, 6 Dec 2023 18:18:20 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FC23C433C8; Thu, 7 Dec 2023 02:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701915500; bh=c7OyBhAKKMMDcdQ7TOKYguis+q3iuIF4wYZKx0rNcd0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=GPEqMtN8nlLWwHDM78zzptjNKtdVnj3qq7q3pNHPpSPYp8J9zaPr5ZyY5WB7kSVow CaCjLREqaYebqfbmMZuh+R9/3d6gJbukVDXQrD+BddaOatSKl2nPfS8Lw9RGJy+07x 8kjSyzUv0qqfpnxFNEq+TCiZgc6VJzBaBnUPLq/uoMspy5Jyr4cdfEOwZxkur4Ilgy 2xgxx0lFAR6smUenVZV8NAVHyNXOT+1ae1xf3w3g3k8JHx8N1QLJORIyx8KZvO7ovy iSJLqH8U41qO1okKwdI+rAjoZ3Zg9rOei1zngKGlbOBTumZuqTdvb5nt25roOQj9BM GTUvKNYFEvcbA== Date: Wed, 6 Dec 2023 18:18:09 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: "Chen, Jiqian" cc: Jan Beulich , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Juergen Gross , Oleksandr Tyshchenko , Thomas Gleixner , Boris Ostrovsky , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , "xen-devel@lists.xenproject.org" , "linux-kernel@vger.kernel.org" , "linux-acpi@vger.kernel.org" , "Stabellini, Stefano" , "Deucher, Alexander" , "Koenig, Christian" , "Hildebrand, Stewart" , "Ragiadakou, Xenia" , "Huang, Honglei1" , "Zhang, Julia" , "Huang, Ray" Subject: Re: [RFC KERNEL PATCH v2 2/3] xen/pvh: Unmask irq for passthrough device in PVH dom0 In-Reply-To: Message-ID: References: <20231124103123.3263471-1-Jiqian.Chen@amd.com> <20231124103123.3263471-3-Jiqian.Chen@amd.com> <15275706-5c31-4e29-aa29-9f5e90526219@suse.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 18:18:30 -0800 (PST) On Tue, 5 Dec 2023, Chen, Jiqian wrote: > When PVH dom0 enable a device, it will get trigger and polarity from ACPI (see acpi_pci_irq_enable) > I have a version of patch which tried that way, see below: This approach looks much better. I think this patch is OKish. Juergen, what do you think? > diff --git a/arch/x86/xen/enlighten_pvh.c b/arch/x86/xen/enlighten_pvh.c > index ada3868c02c2..43e1bda9f946 100644 > --- a/arch/x86/xen/enlighten_pvh.c > +++ b/arch/x86/xen/enlighten_pvh.c > @@ -1,6 +1,7 @@ > // SPDX-License-Identifier: GPL-2.0 > #include > #include > +#include > > #include > > @@ -25,6 +26,127 @@ > bool __ro_after_init xen_pvh; > EXPORT_SYMBOL_GPL(xen_pvh); > > +typedef struct gsi_info { > + int gsi; > + int trigger; > + int polarity; > + int pirq; > +} gsi_info_t; > + > +struct acpi_prt_entry { > + struct acpi_pci_id id; > + u8 pin; > + acpi_handle link; > + u32 index; /* GSI, or link _CRS index */ > +}; > + > +static int xen_pvh_get_gsi_info(struct pci_dev *dev, > + gsi_info_t *gsi_info) > +{ > + int gsi; > + u8 pin = 0; > + struct acpi_prt_entry *entry; > + int trigger = ACPI_LEVEL_SENSITIVE; > + int polarity = acpi_irq_model == ACPI_IRQ_MODEL_GIC ? > + ACPI_ACTIVE_HIGH : ACPI_ACTIVE_LOW; > + > + if (dev) > + pin = dev->pin; > + if (!pin) { > + xen_raw_printk("No interrupt pin configured\n"); > + return -EINVAL; > + } > + > + entry = acpi_pci_irq_lookup(dev, pin); > + if (entry) { > + if (entry->link) > + gsi = acpi_pci_link_allocate_irq(entry->link, > + entry->index, > + &trigger, &polarity, > + NULL); > + else > + gsi = entry->index; > + } else > + return -EINVAL; > + > + gsi_info->gsi = gsi; > + gsi_info->trigger = trigger; > + gsi_info->polarity = polarity; > + > + return 0; > +} > + > +static int xen_pvh_map_pirq(gsi_info_t *gsi_info) > +{ > + struct physdev_map_pirq map_irq; > + int ret; > + > + map_irq.domid = DOMID_SELF; > + map_irq.type = MAP_PIRQ_TYPE_GSI; > + map_irq.index = gsi_info->gsi; > + map_irq.pirq = gsi_info->gsi; > + > + ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq); > + gsi_info->pirq = map_irq.pirq; > + > + return ret; > +} > + > +static int xen_pvh_unmap_pirq(gsi_info_t *gsi_info) > +{ > + struct physdev_unmap_pirq unmap_irq; > + > + unmap_irq.domid = DOMID_SELF; > + unmap_irq.pirq = gsi_info->pirq; > + > + return HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq); > +} > + > +static int xen_pvh_setup_gsi(gsi_info_t *gsi_info) > +{ > + struct physdev_setup_gsi setup_gsi; > + > + setup_gsi.gsi = gsi_info->gsi; > + setup_gsi.triggering = (gsi_info->trigger == ACPI_EDGE_SENSITIVE ? 0 : 1); > + setup_gsi.polarity = (gsi_info->polarity == ACPI_ACTIVE_HIGH ? 0 : 1); > + > + return HYPERVISOR_physdev_op(PHYSDEVOP_setup_gsi, &setup_gsi); > +} > + > +int xen_pvh_passthrough_gsi(struct pci_dev *dev) > +{ > + int ret; > + gsi_info_t gsi_info; > + > + if (!dev) { > + return -EINVAL; > + } > + > + ret = xen_pvh_get_gsi_info(dev, &gsi_info); > + if (ret) { > + xen_raw_printk("Fail to get gsi info!\n"); > + return ret; > + } > + > + ret = xen_pvh_map_pirq(&gsi_info); > + if (ret) { > + xen_raw_printk("Fail to map pirq for gsi (%d)!\n", gsi_info.gsi); > + return ret; > + } > + > + ret = xen_pvh_setup_gsi(&gsi_info); > + if (ret == -EEXIST) { > + ret = 0; > + xen_raw_printk("Already setup the GSI :%u\n", gsi_info.gsi); > + } else if (ret) { > + xen_raw_printk("Fail to setup gsi (%d)!\n", gsi_info.gsi); > + xen_pvh_unmap_pirq(&gsi_info); > + } > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(xen_pvh_passthrough_gsi); > + > void __init xen_pvh_init(struct boot_params *boot_params) > { > u32 msr; > diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c > index ff30ceca2203..630fe0a34bc6 100644 > --- a/drivers/acpi/pci_irq.c > +++ b/drivers/acpi/pci_irq.c > @@ -288,7 +288,7 @@ static int acpi_reroute_boot_interrupt(struct pci_dev *dev, > } > #endif /* CONFIG_X86_IO_APIC */ > > -static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin) > +struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin) > { > struct acpi_prt_entry *entry = NULL; > struct pci_dev *bridge; > diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c > index e34b623e4b41..1abd4dad6f40 100644 > --- a/drivers/xen/xen-pciback/pci_stub.c > +++ b/drivers/xen/xen-pciback/pci_stub.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -399,6 +400,12 @@ static int pcistub_init_device(struct pci_dev *dev) > if (err) > goto config_release; > > + if (xen_initial_domain() && xen_pvh_domain()) { > + err = xen_pvh_passthrough_gsi(dev); > + if (err) > + goto config_release; > + } > + > if (dev->msix_cap) { > struct physdev_pci_device ppdev = { > .seg = pci_domain_nr(dev->bus), > diff --git a/include/linux/acpi.h b/include/linux/acpi.h > index 641dc4843987..368d56ba2c5e 100644 > --- a/include/linux/acpi.h > +++ b/include/linux/acpi.h > @@ -375,6 +375,7 @@ void acpi_unregister_gsi (u32 gsi); > > struct pci_dev; > > +struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin); > int acpi_pci_irq_enable (struct pci_dev *dev); > void acpi_penalize_isa_irq(int irq, int active); > bool acpi_isa_irq_available(int irq); > diff --git a/include/xen/acpi.h b/include/xen/acpi.h > index b1e11863144d..ce7f5554f88e 100644 > --- a/include/xen/acpi.h > +++ b/include/xen/acpi.h > @@ -67,6 +67,7 @@ static inline void xen_acpi_sleep_register(void) > acpi_suspend_lowlevel = xen_acpi_suspend_lowlevel; > } > } > +int xen_pvh_passthrough_gsi(struct pci_dev *dev); > #else > static inline void xen_acpi_sleep_register(void) > { > > > > > Jan > > -- > Best regards, > Jiqian Chen. >