From patchwork Mon Jun 12 14:25:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13276767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2965FC88CB2 for ; Mon, 12 Jun 2023 14:26:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547177.854453 (Exim 4.92) (envelope-from ) id 1q8iUn-0001ad-Rj; Mon, 12 Jun 2023 14:26:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547177.854453; Mon, 12 Jun 2023 14:26:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8iUn-0001Zd-KD; Mon, 12 Jun 2023 14:26:13 +0000 Received: by outflank-mailman (input) for mailman id 547177; Mon, 12 Jun 2023 14:26:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8iUm-0001S1-99 for xen-devel@lists.xenproject.org; Mon, 12 Jun 2023 14:26:12 +0000 Received: from bombadil.infradead.org (bombadil.infradead.org [2607:7c80:54:3::133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0ff87eb8-092d-11ee-8611-37d641c3527e; Mon, 12 Jun 2023 16:26:05 +0200 (CEST) Received: from 2a02-8389-2341-5b80-8c8c-28f8-1274-e038.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:8c8c:28f8:1274:e038] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q8iUQ-004I8Z-1u; Mon, 12 Jun 2023 14:25:50 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0ff87eb8-092d-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=xk7UcK2JitL8EW9ZuelDDstRDKvC7QWgJZaUJF9iY8U=; b=gi/Nxa/zQEPmiix7WWxiDcuGaQ UXWNUHjwEt1uV9G92Cki/tGyE4Fxl9h7Uw5/VW0QgnJaASa9uwWV+jTL1gGuqDpKpZSeQCnal1E5J qEv0DtE4DOdI2krZd7P/X4lJwG0qNpuqNQ/o25wL+x7eif+U1SXUWZb60We+k49zNk8r/rmi/Tl4E SoZuJ+wCJxNYD4SRNiAsgCiNftC3faUgZS/u0LJDBvs8x175TAWPm0lP2tjb4Cswk2u4xkFViVI4h PPfk9D+URfM35VS9Ur/NWziYDFfRS0b4rQtJX0lZUcaXERtO1ykJfsTkvpjcFifFd0gsamVHI2h6y NlYvrHJA==; From: Christoph Hellwig To: Juergen Gross , Stefano Stabellini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: xen-devel@lists.xenproject.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] xen/pci: add flag for PCI passthrough being possible Date: Mon, 12 Jun 2023 16:25:40 +0200 Message-Id: <20230612142542.111581-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230612142542.111581-1-hch@lst.de> References: <20230612142542.111581-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html From: Juergen Gross When running as a Xen PV guests passed through PCI devices only have a chance to work if the Xen supplied memory map has some PCI space reserved. Add a flag xen_pv_pci_possible which will be set in early boot in case the memory map has at least one area with the type E820_TYPE_RESERVED. Signed-off-by: Juergen Gross Signed-off-by: Christoph Hellwig --- arch/x86/xen/setup.c | 6 ++++++ include/xen/xen.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index c2be3efb2ba0fa..716f76c4141651 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -43,6 +43,9 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata; /* Number of pages released from the initial allocation. */ unsigned long xen_released_pages; +/* Memory map would allow PCI passthrough. */ +bool xen_pv_pci_possible; + /* E820 map used during setting up memory. */ static struct e820_table xen_e820_table __initdata; @@ -804,6 +807,9 @@ char * __init xen_memory_setup(void) chunk_size = size; type = xen_e820_table.entries[i].type; + if (type == E820_TYPE_RESERVED) + xen_pv_pci_possible = true; + if (type == E820_TYPE_RAM) { if (addr < mem_end) { chunk_size = min(size, mem_end - addr); diff --git a/include/xen/xen.h b/include/xen/xen.h index 0efeb652f9b8fb..5eb0a974a11e7e 100644 --- a/include/xen/xen.h +++ b/include/xen/xen.h @@ -29,6 +29,12 @@ extern bool xen_pvh; extern uint32_t xen_start_flags; +#ifdef CONFIG_XEN_PV +extern bool xen_pv_pci_possible; +#else +#define xen_pv_pci_possible 0 +#endif + #include extern struct hvm_start_info pvh_start_info; From patchwork Mon Jun 12 14:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13276768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68BDDC88CB4 for ; Mon, 12 Jun 2023 14:26:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547175.854440 (Exim 4.92) (envelope-from ) id 1q8iUn-0001SU-7R; Mon, 12 Jun 2023 14:26:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547175.854440; Mon, 12 Jun 2023 14:26:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8iUn-0001SN-4w; Mon, 12 Jun 2023 14:26:13 +0000 Received: by outflank-mailman (input) for mailman id 547175; Mon, 12 Jun 2023 14:26:11 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8iUl-0001S2-HT for xen-devel@lists.xenproject.org; Mon, 12 Jun 2023 14:26:11 +0000 Received: from bombadil.infradead.org (bombadil.infradead.org [2607:7c80:54:3::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 11a9d0f2-092d-11ee-b232-6b7b168915f2; Mon, 12 Jun 2023 16:26:08 +0200 (CEST) Received: from 2a02-8389-2341-5b80-8c8c-28f8-1274-e038.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:8c8c:28f8:1274:e038] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q8iUS-004I8p-2v; Mon, 12 Jun 2023 14:25:53 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 11a9d0f2-092d-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Do07+ZJ8mt79MyKnagn3FmtuEPVS6qLM8Uvv604VtrU=; b=ft+LfENSbzDpGdR/jPu3Jnufmf IHfMnVhVYCDVxL4lsWCBWJNprt6qecPh6iVJH/jyJVtFumN4qbS/yfXinn70dOukq6yXFXA2M+RRH FxQpGw2Lk57s0+ygZfS5ucxKr9EfjhLyg81/6pzAN4HAsl67+sCPnuCdCkiJ2UUERt+DcZl7kUxYX 1xyscFp19lM8RLbNmZhw1hpPskXnts+EK7+TobUzf3g8hRDwewyJipGeaMsQ0LGSpUwlEpT2Hp4jq ab/k68N1uDss72tLrlMmwIJaDI+iWY9G36Z1jHRVNlO48LAHDdfPieKLQl3MLtJDhnZggvllYttAA 3vrSr1ng==; From: Christoph Hellwig To: Juergen Gross , Stefano Stabellini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: xen-devel@lists.xenproject.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] x86: always initialize xen-swiotlb when xen-pcifront is enabling Date: Mon, 12 Jun 2023 16:25:41 +0200 Message-Id: <20230612142542.111581-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230612142542.111581-1-hch@lst.de> References: <20230612142542.111581-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Remove the dangerous late initialization of xen-swiotlb in pci_xen_swiotlb_init_late and instead just always initialize xen-swiotlb in the boot code if CONFIG_XEN_PCIDEV_FRONTEND is enabled and Xen PV PCI is possible. Signed-off-by: Christoph Hellwig Reviewed-by: Juergen Gross --- arch/x86/include/asm/xen/swiotlb-xen.h | 6 ------ arch/x86/kernel/pci-dma.c | 29 +++++++------------------- drivers/pci/xen-pcifront.c | 6 ------ 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/arch/x86/include/asm/xen/swiotlb-xen.h b/arch/x86/include/asm/xen/swiotlb-xen.h index 77a2d19cc9909e..abde0f44df57dc 100644 --- a/arch/x86/include/asm/xen/swiotlb-xen.h +++ b/arch/x86/include/asm/xen/swiotlb-xen.h @@ -2,12 +2,6 @@ #ifndef _ASM_X86_SWIOTLB_XEN_H #define _ASM_X86_SWIOTLB_XEN_H -#ifdef CONFIG_SWIOTLB_XEN -extern int pci_xen_swiotlb_init_late(void); -#else -static inline int pci_xen_swiotlb_init_late(void) { return -ENXIO; } -#endif - int xen_swiotlb_fixup(void *buf, unsigned long nslabs); int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits, diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index de6be0a3965ee4..f323d83e40a70b 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -72,9 +72,15 @@ static inline void __init pci_swiotlb_detect(void) #endif /* CONFIG_SWIOTLB */ #ifdef CONFIG_SWIOTLB_XEN +static bool xen_swiotlb_enabled(void) +{ + return xen_initial_domain() || x86_swiotlb_enable || + (IS_ENABLED(CONFIG_XEN_PCIDEV_FRONTEND) && xen_pv_pci_possible); +} + static void __init pci_xen_swiotlb_init(void) { - if (!xen_initial_domain() && !x86_swiotlb_enable) + if (!xen_swiotlb_enabled()) return; x86_swiotlb_enable = true; x86_swiotlb_flags |= SWIOTLB_ANY; @@ -83,27 +89,6 @@ static void __init pci_xen_swiotlb_init(void) if (IS_ENABLED(CONFIG_PCI)) pci_request_acs(); } - -int pci_xen_swiotlb_init_late(void) -{ - if (dma_ops == &xen_swiotlb_dma_ops) - return 0; - - /* we can work with the default swiotlb */ - if (!io_tlb_default_mem.nslabs) { - int rc = swiotlb_init_late(swiotlb_size_or_default(), - GFP_KERNEL, xen_swiotlb_fixup); - if (rc < 0) - return rc; - } - - /* XXX: this switches the dma ops under live devices! */ - dma_ops = &xen_swiotlb_dma_ops; - if (IS_ENABLED(CONFIG_PCI)) - pci_request_acs(); - return 0; -} -EXPORT_SYMBOL_GPL(pci_xen_swiotlb_init_late); #else static inline void __init pci_xen_swiotlb_init(void) { diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index 83c0ab50676dff..11636634ae512f 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -669,11 +668,6 @@ static int pcifront_connect_and_init_dma(struct pcifront_device *pdev) spin_unlock(&pcifront_dev_lock); - if (!err && !is_swiotlb_active(&pdev->xdev->dev)) { - err = pci_xen_swiotlb_init_late(); - if (err) - dev_err(&pdev->xdev->dev, "Could not setup SWIOTLB!\n"); - } return err; } From patchwork Mon Jun 12 14:25:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13276769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36B3EC88CB6 for ; Mon, 12 Jun 2023 14:26:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547178.854461 (Exim 4.92) (envelope-from ) id 1q8iUo-0001nW-C1; Mon, 12 Jun 2023 14:26:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547178.854461; Mon, 12 Jun 2023 14:26:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8iUo-0001lT-5p; Mon, 12 Jun 2023 14:26:14 +0000 Received: by outflank-mailman (input) for mailman id 547178; Mon, 12 Jun 2023 14:26:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q8iUm-0001S1-Rb for xen-devel@lists.xenproject.org; Mon, 12 Jun 2023 14:26:12 +0000 Received: from bombadil.infradead.org (bombadil.infradead.org [2607:7c80:54:3::133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1130dc07-092d-11ee-8611-37d641c3527e; Mon, 12 Jun 2023 16:26:07 +0200 (CEST) Received: from 2a02-8389-2341-5b80-8c8c-28f8-1274-e038.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:8c8c:28f8:1274:e038] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q8iUV-004I92-0g; Mon, 12 Jun 2023 14:25:55 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1130dc07-092d-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=7+xegEsHtqdZfD90PqdQG2V9qml0A9VagIuPc+XndpY=; b=nOfGMv5BDRQxDfnrKd8bzmQWqr goBsBKB7Iw1m2LxzLRFbWVRVGrjRdpF9rFhCZElyGUexeqx5Gd9/KXOz8Z/0AvV6Y2V4vqzAHsT6M 7gsR0fVXxD0Ee2qf1VyGvSE4UDuPsMTrlK1/DNRnlXS6AY76SN3HBTrdKLf3sdFvc7RaNofiW/9Mp cq5fhS41yZ0jYIePZfhZ1xV0fXI0Ev3LIRDrz5qE4H3oed9BmraNqp8ahrJhZN2yibbAhjChO5VYJ z3KK6ayWVF4A0AKXxPff8zQPHaAPIfph3bQmUV3jONDK18rW/BiLpeLYl4TfbalzVkNQyDg9yP4ZQ 7jqvZpVQ==; From: Christoph Hellwig To: Juergen Gross , Stefano Stabellini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: xen-devel@lists.xenproject.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] swiotlb: unexport is_swiotlb_active Date: Mon, 12 Jun 2023 16:25:42 +0200 Message-Id: <20230612142542.111581-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230612142542.111581-1-hch@lst.de> References: <20230612142542.111581-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Drivers have no business looking at dma-mapping or swiotlb internals. Signed-off-by: Christoph Hellwig Reviewed-by: Juergen Gross --- kernel/dma/swiotlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 775f7bb10ab184..1891faa3a6952e 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -932,7 +932,6 @@ bool is_swiotlb_active(struct device *dev) return mem && mem->nslabs; } -EXPORT_SYMBOL_GPL(is_swiotlb_active); #ifdef CONFIG_DEBUG_FS