From nobody Tue Feb 10 19:09:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1619079363; cv=none; d=zohomail.com; s=zohoarc; b=maiX5YwPPV1CH32fyH79ulZETGp+fV1f8f/Z6whqsT2Oxva0StTrhS9ZPOxPTzIvHCEBF1PeETxjRkCIWDclqsLy+9uNVEMbuHAjGG0pXxzesc3o0DZQXmYIpRbUV6v6NZc4kwFdqjmYRzCqsfhFxGfzSktS1TuD50S9WwWU+xE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619079363; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DCqTI/hrajjPwkk8HEowW3TBxQKFywGZJ7zj1kAgSTY=; b=AzB2bk3L0nkNmYk7vmbArLnYrvMfZ+uFhFo/Umi0g3+TWx/htCP98yAnW/TueT6ulrzSSRo5+gsbgOeDX755XQvopNhDyfNuoJoHMHg3rBHuaF18qwNPifoD6zwiM0Pg1KaYNLzkblZbcoToEvh+7mQXwWD5tNnL43r8V74I9dc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619079363414125.96409836789542; Thu, 22 Apr 2021 01:16:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.115104.219463 (Exim 4.92) (envelope-from ) id 1lZUUv-00021C-PJ; Thu, 22 Apr 2021 08:15:41 +0000 Received: by outflank-mailman (output) from mailman id 115104.219463; Thu, 22 Apr 2021 08:15:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZUUv-000215-Lm; Thu, 22 Apr 2021 08:15:41 +0000 Received: by outflank-mailman (input) for mailman id 115104; Thu, 22 Apr 2021 08:15:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZUUu-0001sR-9R for xen-devel@lists.xenproject.org; Thu, 22 Apr 2021 08:15:40 +0000 Received: from mail-pf1-x435.google.com (unknown [2607:f8b0:4864:20::435]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id fb0f823e-5565-478f-b2bf-f41c2d045505; Thu, 22 Apr 2021 08:15:36 +0000 (UTC) Received: by mail-pf1-x435.google.com with SMTP id w6so16598116pfc.8 for ; Thu, 22 Apr 2021 01:15:36 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:1a8e:1bde:f79e:c302]) by smtp.gmail.com with UTF8SMTPSA id h24sm4254231pjv.50.2021.04.22.01.15.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 01:15:35 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: fb0f823e-5565-478f-b2bf-f41c2d045505 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DCqTI/hrajjPwkk8HEowW3TBxQKFywGZJ7zj1kAgSTY=; b=PCD+TgwZ3AiIHtjyLdB6UVXLjDV96H7O710PE71qja4j6uBcwL6eMs8rIbMv0cvAFQ cknTAU+f5ughf4xS8sPG0t3S2Z5C3uFec0t2GAey9KzOD4hvmC5srj0EUFUk8IMbKFFx HuDL4t5SO2wRDWgfMYB4sF73Mazkige4becoA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DCqTI/hrajjPwkk8HEowW3TBxQKFywGZJ7zj1kAgSTY=; b=tGIuEL50GRSqtXBsZewVAQebHogiq1uEVNKC4Kk0HjTeTUSznZ9QMfSj6oZETvno6Y Jc7cJoC48RDUFS1Xf2zer+A9MCKc56Vkf/PWSECLoXGR8CUmLcuWJWHZxnbZMgj9S4La KwiBTsz/EUuu+Ba6arxtTXVQvgX+rpVGJIyoLYAW4JUMLofOg+FNCEvF2qifHK1AUjX0 gA7FF2C+NFlYm+W6sKPz5vs/hMl20lcoHWjMzncNxboDKEh1XOfmAEznH6XuvQmS72vj JaohCuDIdadx1pTyMcuVsvH+8+jzHGEeLZu5PFRmXFniNCSJQtvqAgOnoZYjaVsO3M87 3aYw== X-Gm-Message-State: AOAM533FgKgF13huKlTL2lAsuRyKoxPhDn3kqEk/LW1Gt5hnfOHE2ze5 BNiKJOvRFejk6SSrXYUai0r0wQ== X-Google-Smtp-Source: ABdhPJzCAPtMPZjZd4TjI7FfrTaFcb2I4L39Wwlj9XGgVexb3c0kbKDiOe3PnJYnNG72JITLPFAsSA== X-Received: by 2002:a63:145a:: with SMTP id 26mr2332561pgu.300.1619079335503; Thu, 22 Apr 2021 01:15:35 -0700 (PDT) From: Claire Chang To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Cc: benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, Robin Murphy , grant.likely@arm.com, xypron.glpk@gmx.de, Thierry Reding , mingo@kernel.org, bauerman@linux.ibm.com, peterz@infradead.org, Greg KH , Saravana Kannan , "Rafael J . Wysocki" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , tfiga@chromium.org, bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, tientzu@chromium.org, daniel@ffwll.ch, airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, jxgao@google.com, joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, nouveau@lists.freedesktop.org, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Subject: [PATCH v5 02/16] swiotlb: Refactor swiotlb init functions Date: Thu, 22 Apr 2021 16:14:54 +0800 Message-Id: <20210422081508.3942748-3-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210422081508.3942748-1-tientzu@chromium.org> References: <20210422081508.3942748-1-tientzu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @chromium.org) Content-Type: text/plain; charset="utf-8" Add a new function, swiotlb_init_io_tlb_mem, for the io_tlb_mem struct initialization to make the code reusable. Note that we now also call set_memory_decrypted in swiotlb_init_with_tbl. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 51 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 8635a57f88e9..3f1adee35097 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -166,9 +166,30 @@ void __init swiotlb_update_mem_attributes(void) memset(vaddr, 0, bytes); } =20 -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verb= ose) +static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t st= art, + unsigned long nslabs, bool late_alloc) { + void *vaddr =3D phys_to_virt(start); unsigned long bytes =3D nslabs << IO_TLB_SHIFT, i; + + mem->nslabs =3D nslabs; + mem->start =3D start; + mem->end =3D mem->start + bytes; + mem->index =3D 0; + mem->late_alloc =3D late_alloc; + spin_lock_init(&mem->lock); + for (i =3D 0; i < mem->nslabs; i++) { + mem->slots[i].list =3D IO_TLB_SEGSIZE - io_tlb_offset(i); + mem->slots[i].orig_addr =3D INVALID_PHYS_ADDR; + mem->slots[i].alloc_size =3D 0; + } + + set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); + memset(vaddr, 0, bytes); +} + +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verb= ose) +{ struct io_tlb_mem *mem; size_t alloc_size; =20 @@ -184,16 +205,8 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned l= ong nslabs, int verbose) if (!mem) panic("%s: Failed to allocate %zu bytes align=3D0x%lx\n", __func__, alloc_size, PAGE_SIZE); - mem->nslabs =3D nslabs; - mem->start =3D __pa(tlb); - mem->end =3D mem->start + bytes; - mem->index =3D 0; - spin_lock_init(&mem->lock); - for (i =3D 0; i < mem->nslabs; i++) { - mem->slots[i].list =3D IO_TLB_SEGSIZE - io_tlb_offset(i); - mem->slots[i].orig_addr =3D INVALID_PHYS_ADDR; - mem->slots[i].alloc_size =3D 0; - } + + swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false); =20 io_tlb_default_mem =3D mem; if (verbose) @@ -280,7 +293,6 @@ swiotlb_late_init_with_default_size(size_t default_size) int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) { - unsigned long bytes =3D nslabs << IO_TLB_SHIFT, i; struct io_tlb_mem *mem; =20 if (swiotlb_force =3D=3D SWIOTLB_NO_FORCE) @@ -295,20 +307,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long ns= labs) if (!mem) return -ENOMEM; =20 - mem->nslabs =3D nslabs; - mem->start =3D virt_to_phys(tlb); - mem->end =3D mem->start + bytes; - mem->index =3D 0; - mem->late_alloc =3D 1; - spin_lock_init(&mem->lock); - for (i =3D 0; i < mem->nslabs; i++) { - mem->slots[i].list =3D IO_TLB_SEGSIZE - io_tlb_offset(i); - mem->slots[i].orig_addr =3D INVALID_PHYS_ADDR; - mem->slots[i].alloc_size =3D 0; - } - - set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); - memset(tlb, 0, bytes); + swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true); =20 io_tlb_default_mem =3D mem; swiotlb_print_info(); --=20 I'm not 100% sure if set_memory_decrypted is safe to call in swiotlb_init_with_tbl, but I didn't hit any issue booting with this. 2.31.1.368.gbe11c130af-goog