From patchwork Tue May 28 22:48:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 10965887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4CA576 for ; Tue, 28 May 2019 22:50:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9288F287E2 for ; Tue, 28 May 2019 22:50:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8601D28874; Tue, 28 May 2019 22:50:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9890C28857 for ; Tue, 28 May 2019 22:50:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVktO-0006WA-36; Tue, 28 May 2019 22:48:26 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVktM-0006VL-HW for xen-devel@lists.xenproject.org; Tue, 28 May 2019 22:48:24 +0000 X-Inumbo-ID: b2d5a4b2-819a-11e9-ae8f-57a10ded9d94 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b2d5a4b2-819a-11e9-ae8f-57a10ded9d94; Tue, 28 May 2019 22:48:24 +0000 (UTC) Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F11920B1F; Tue, 28 May 2019 22:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559083703; bh=1lcuTO8r4FjCrgtzeV5AH8J5IwwIPxaTPIFzkL9GMxA=; h=Date:From:To:cc:Subject:From; b=15iL24htgosGHPqxQAvYN8aXa9nj2MZgJZPyO5POq+C6+DMGBs9xt0KKqj54QafUe Da16Ts8r5nt0nCZEDYzkqBeMQVTycFAa3Ctky72h4+SPj++G+VAqTox5G3j0toFwZv rGHZn42qcgxCXxHKyw8QHHgOraLDEyU4Tk6n2qdA= Date: Tue, 28 May 2019 15:48:22 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] xen/swiotlb: don't initialize swiotlb twice on arm64 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: xen-devel@lists.xenproject.org, Julien.Grall@arm.com, sstabellini@kernel.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Stefano Stabellini On arm64 swiotlb is often (not always) already initialized by mem_init. We don't want to initialize it twice, which would trigger a second memory allocation. Moreover, the second memory pool is typically made of high pages and ends up replacing the original memory pool of low pages. As a side effect of this change, it is possible to have low pages in swiotlb-xen on arm64. Signed-off-by: Stefano Stabellini Reviewed-by: Boris Ostrovsky --- Changes in v2: - improve commit message - don't add nested ifs diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 877baf2..8a3cdd1 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -211,6 +211,15 @@ int __ref xen_swiotlb_init(int verbose, bool early) retry: bytes = xen_set_nslabs(xen_io_tlb_nslabs); order = get_order(xen_io_tlb_nslabs << IO_TLB_SHIFT); + + /* + * IO TLB memory already allocated. Just use it. + */ + if (io_tlb_start != 0) { + xen_io_tlb_start = phys_to_virt(io_tlb_start); + goto end; + } + /* * Get IO TLB memory from any location. */ @@ -240,7 +249,6 @@ int __ref xen_swiotlb_init(int verbose, bool early) m_ret = XEN_SWIOTLB_ENOMEM; goto error; } - xen_io_tlb_end = xen_io_tlb_start + bytes; /* * And replace that memory with pages under 4GB. */ @@ -267,6 +275,8 @@ int __ref xen_swiotlb_init(int verbose, bool early) } else rc = swiotlb_late_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs); +end: + xen_io_tlb_end = xen_io_tlb_start + bytes; if (!rc) swiotlb_set_max_segment(PAGE_SIZE);