From nobody Sun May 5 15:35:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1558709083; cv=none; d=zoho.com; s=zohoarc; b=dG9ugfPjYwNaPYrUixpzh0l2hBog+b6SSUHthP835MyWJ6/LbsA+GPt6orNJmtVwS02F4Rtb/FBK0CaagpVR++n9LUMLJndMpWlsD6WkSfn04rp6r8Y1ndspPw9/6fUF8wJiHBNjwB0Cvv9e2qQajZXn3S9grGvGWxeyWJ3Bshs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558709083; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=RJvBJXolAWlfhmCwvYXECL0DA9SWqVJEu3FWYlTbBvM=; b=oIBXZMItV2+27lLODdPSmB1zdAidV+EERTJYDHbo3hmjsdJiddTBwCkXkXv9hVDIQGVijFzJ7rmIKWPDIyEYis6lckqCcpWB/ZpR3o1nlX9Y2eS7QSd6XtFM2DOndLi7Saxe0wQgG0PYh/mn/tVjs6OeuKrHcZ8lXYbQQ07kLfs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 155870908309112.676991915747067; Fri, 24 May 2019 07:44:43 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hUBPO-0005VS-AU; Fri, 24 May 2019 14:42:58 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hUBPN-0005VN-Ei for xen-devel@lists.xenproject.org; Fri, 24 May 2019 14:42:57 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 37903574-7e32-11e9-8980-bc764e045a96; Fri, 24 May 2019 14:42:56 +0000 (UTC) X-Inumbo-ID: 37903574-7e32-11e9-8980-bc764e045a96 Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=sergey.dyasli@citrix.com; spf=Pass smtp.mailfrom=sergey.dyasli@citrix.com; spf=None smtp.helo=postmaster@MIAPEX02MSOL01.citrite.net Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of sergey.dyasli@citrix.com) identity=pra; client-ip=23.29.105.83; receiver=esa6.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of sergey.dyasli@citrix.com designates 23.29.105.83 as permitted sender) identity=mailfrom; client-ip=23.29.105.83; receiver=esa6.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:23.29.105.83 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@MIAPEX02MSOL01.citrite.net) identity=helo; client-ip=23.29.105.83; receiver=esa6.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="postmaster@MIAPEX02MSOL01.citrite.net"; x-conformance=sidf_compatible IronPort-SDR: L92NSaSjxlBdCrBZmCT7+KZG4Ypxl9hxObzcbTlTGj1ik8mZ/QurcPRcudyPz0wT7NEsSH7sP3 MJXkDS/mgE6r+D8y+MZKfLXq0xyFTms518AlB8qdQXaw6+EL7Pe0M6+KaigzDGzS12uuU9pYHq Q+lrpr3VMvhzt24mGoUa15wMAbtzddgMkHVzVVor0dUXNW9kxpO4KKE0DN8R2SvfRDQELlhvBt 48OfDLveutAj2VxKV7f4KrqfSNilCmX8emHh+m/YsH9zlv2Zw5LxMiRFE01CtKoNNfcn+c+UIS WFc= X-SBRS: 2.7 X-MesageID: 860160 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 23.29.105.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.60,507,1549947600"; d="scan'208";a="860160" From: Sergey Dyasli To: , , Date: Fri, 24 May 2019 15:42:50 +0100 Message-ID: <20190524144250.5102-1-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v1] xen/swiotlb: rework early repeat code X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Sergey Dyasli , Stefano Stabellini , Konrad Rzeszutek Wilk , Paul Durrant , Boris Ostrovsky Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Current repeat code is plain broken for the early=3Dtrue case. Xen exchanges all DMA (<4GB) pages that it can on the first xen_swiotlb_fixup() attempt. All further attempts with a halved region will fail immediately because all DMA pages already belong to Dom0. Introduce contig_pages param for xen_swiotlb_fixup() to track the number of pages that were made contiguous in MFN space and use the same bootmem region while halving the memory requirements. Signed-off-by: Sergey Dyasli --- CC: Konrad Rzeszutek Wilk CC: Boris Ostrovsky CC: Juergen Gross CC: Stefano Stabellini CC: Paul Durrant --- drivers/xen/swiotlb-xen.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 5dcb06fe9667..d2aba804d06c 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -142,7 +142,8 @@ static int is_xen_swiotlb_buffer(dma_addr_t dma_addr) static int max_dma_bits =3D 32; =20 static int -xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) +xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs, + unsigned long *contig_pages) { int i, rc; int dma_bits; @@ -156,10 +157,13 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned lo= ng nslabs) int slabs =3D min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE); =20 do { + unsigned int order =3D get_order(slabs << IO_TLB_SHIFT); rc =3D xen_create_contiguous_region( p + (i << IO_TLB_SHIFT), - get_order(slabs << IO_TLB_SHIFT), + order, dma_bits, &dma_handle); + if (rc =3D=3D 0) + *contig_pages +=3D 1 << order; } while (rc && dma_bits++ < max_dma_bits); if (rc) return rc; @@ -202,7 +206,7 @@ static const char *xen_swiotlb_error(enum xen_swiotlb_e= rr err) } int __ref xen_swiotlb_init(int verbose, bool early) { - unsigned long bytes, order; + unsigned long bytes, order, contig_pages; int rc =3D -ENOMEM; enum xen_swiotlb_err m_ret =3D XEN_SWIOTLB_UNKNOWN; unsigned int repeat =3D 3; @@ -244,13 +248,32 @@ int __ref xen_swiotlb_init(int verbose, bool early) /* * And replace that memory with pages under 4GB. */ + contig_pages =3D 0; rc =3D xen_swiotlb_fixup(xen_io_tlb_start, bytes, - xen_io_tlb_nslabs); + xen_io_tlb_nslabs, + &contig_pages); if (rc) { - if (early) + if (early) { + unsigned long orig_bytes =3D bytes; + while (repeat-- > 0) { + xen_io_tlb_nslabs =3D max(1024UL, /* Min is 2MB */ + (xen_io_tlb_nslabs >> 1)); + pr_info("Lowering to %luMB\n", + (xen_io_tlb_nslabs << IO_TLB_SHIFT) >> 20); + bytes =3D xen_set_nslabs(xen_io_tlb_nslabs); + order =3D get_order(xen_io_tlb_nslabs << IO_TLB_SHIFT); + xen_io_tlb_end =3D xen_io_tlb_start + bytes; + if (contig_pages >=3D (1ul << order)) { + /* Enough pages were made contiguous */ + memblock_free(__pa(xen_io_tlb_start + bytes), + PAGE_ALIGN(orig_bytes - bytes)); + goto fixup_done; + } + } memblock_free(__pa(xen_io_tlb_start), PAGE_ALIGN(bytes)); + } else { free_pages((unsigned long)xen_io_tlb_start, order); xen_io_tlb_start =3D NULL; @@ -258,6 +281,7 @@ int __ref xen_swiotlb_init(int verbose, bool early) m_ret =3D XEN_SWIOTLB_EFIXUP; goto error; } +fixup_done: start_dma_addr =3D xen_virt_to_bus(xen_io_tlb_start); if (early) { if (swiotlb_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs, @@ -272,7 +296,7 @@ int __ref xen_swiotlb_init(int verbose, bool early) =20 return rc; error: - if (repeat--) { + if (repeat-- > 0) { xen_io_tlb_nslabs =3D max(1024UL, /* Min is 2MB */ (xen_io_tlb_nslabs >> 1)); pr_info("Lowering to %luMB\n", --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel