From nobody Fri Nov 29 22:33:19 2024 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=1620640270; cv=none; d=zohomail.com; s=zohoarc; b=aAbKFMlhdw/Sj/rwRIsEt7P1Ad3y5mKwmPld7iw9bfYt1CNgojEZTk+fvqNiK9nrt7ZOzHJy+iEgMq5kXUKQg4LNVoHdqNM7AjCAUbjz7a+iljKe5Kp9nKlZutcVK5W4+MHyPEnQS5J1tIAU9jLrED6etzh7tbXaQ9+PSSfT7IQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640270; 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=l57NLzuwUUMRZhssJX0lL8JJDXGk+1/UfIIsGGfy3jA=; b=iJ1CKM53CAJOQiYkCuH5HlOuDuyihc8JSdz+KK4XqEue3506dxnkwvzndB8lV9v+KjM/AWTa2AEtyXZZNsK6teBim3svls68LGqKM/6o2tviTEVznrSMBaApqlXq13a2ZH6YtpmEdvmvdKfZoew9C9UC0QwEI39dodD9CYCKsOQ= 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 1620640270520894.0862816939439; Mon, 10 May 2021 02:51:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125049.235414 (Exim 4.92) (envelope-from ) id 1lg2Yt-0006b9-7e; Mon, 10 May 2021 09:50:51 +0000 Received: by outflank-mailman (output) from mailman id 125049.235414; Mon, 10 May 2021 09:50:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Yt-0006b2-4I; Mon, 10 May 2021 09:50:51 +0000 Received: by outflank-mailman (input) for mailman id 125049; Mon, 10 May 2021 09:50:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Yr-0006aU-Rj for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:50:49 +0000 Received: from mail-pl1-x62f.google.com (unknown [2607:f8b0:4864:20::62f]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5288974c-9a9f-4a25-a2f7-6430acd2af01; Mon, 10 May 2021 09:50:49 +0000 (UTC) Received: by mail-pl1-x62f.google.com with SMTP id s20so8846810plr.13 for ; Mon, 10 May 2021 02:50:49 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id i62sm10957565pfc.162.2021.05.10.02.50.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:50:47 -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: 5288974c-9a9f-4a25-a2f7-6430acd2af01 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=l57NLzuwUUMRZhssJX0lL8JJDXGk+1/UfIIsGGfy3jA=; b=huOTaemx/vQNaoB1cvrnA57ypE0vmqhe7ShZkgp3NAItXrk4k8kvOfBQCV83z3IngU LjO0os4LWJvRIc/zT8XVvQ/udpySO4cVFayr8AZ/h253vg4E9s3gUhllP1veAksDKlv1 u/GQbBSuwBtUiADmsFqc0gMGCn19+8viSk9bQ= 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=l57NLzuwUUMRZhssJX0lL8JJDXGk+1/UfIIsGGfy3jA=; b=XnZ1rbtGxLd0xhQsfkLI7uwqusW+5OS+txujJ9uVS1ijtB2Mu7vEcaUKcpgCLAgElF zXrJMYWqhuCV7MKpmDWaMJBwERYi0yZ3ELw/YkfYq/58yUiO2DIq442Vq+HsW22s0KAX zcLhxNHVgytfpY1W4p9hxm/xylDjyTGmDPbWXD2clIybqES+cjIT2tVlABf3ADS55o05 l/zjgqW3PTKOv+Nn01KqYI/JN0PFmw1x1mAEx6bkLgUPtQcImctx0NiGXzZ9GhBL4Njj J6YNWyoKrr/kSpkQ8E0fn+NUr/CjNUu0Y4CGYmh5vrj7CiYqNeQJEAbC+5LRaDZNybZu KAgg== X-Gm-Message-State: AOAM532cRct+3GYR7SHSivF1V1gooVTlMYb1qToGqocoXwpn3u1hE04C GXOQ/U1fQPxQK/RjAEkyZWsDVg== X-Google-Smtp-Source: ABdhPJxWVuCYZwrOa/E4SzReuXkZoXpg2ApXBYG9GCU58CD3SXKffBuVhoPZLaoYkILB2nJk2guWbw== X-Received: by 2002:a17:902:db09:b029:ee:ad5e:cd58 with SMTP id m9-20020a170902db09b02900eead5ecd58mr23870524plx.78.1620640248239; Mon, 10 May 2021 02:50:48 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 01/15] swiotlb: Refactor swiotlb init functions Date: Mon, 10 May 2021 17:50:12 +0800 Message-Id: <20210510095026.3477496-2-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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 Reviewed-by: Christoph Hellwig --- 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 8ca7d505d61c..d3232fc19385 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -168,9 +168,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 @@ -186,16 +207,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) @@ -282,7 +295,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) @@ -297,20 +309,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 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640271; cv=none; d=zohomail.com; s=zohoarc; b=ghmLk3oKyUEztkPiIdUOe6L+lhHSUYR24JxvIEdaZpaOElGXoj2eoYljfr1FXkRaGzDTMypg+xalWgB0eyB8tZBPBLUMfaEeSk4aNmabNv9cqMXAZQXjfTKozbXCqWFyKlLEO81OKmOXcm4mUW3geapg4RHzFtAvXhMSjwIf4k0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640271; 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=xzceaTJbUUoQMRiby9lwQqwtKo4y5qZbVn1w31ybRrg=; b=mCphoiyamt4BsG2ydCZ3GPG5NOfLjo/svX663NQU5BCgo5hLJ6yZhPrCD7vdbGo7h1PnOu1dalwloWGRdKQdpQq9Bcf+dIcXOIb/LLfbMp/8m3TaA5WQvJ/N1to1hGqukEGKdgTCEzcGkTZ54rxxgZMaCCQ/l2pUKUdaY8dyR48= 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 1620640271406376.1854949124289; Mon, 10 May 2021 02:51:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125051.235426 (Exim 4.92) (envelope-from ) id 1lg2Z1-000718-Gy; Mon, 10 May 2021 09:50:59 +0000 Received: by outflank-mailman (output) from mailman id 125051.235426; Mon, 10 May 2021 09:50:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Z1-000711-DD; Mon, 10 May 2021 09:50:59 +0000 Received: by outflank-mailman (input) for mailman id 125051; Mon, 10 May 2021 09:50:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Z0-0006yg-86 for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:50:58 +0000 Received: from mail-pj1-x102f.google.com (unknown [2607:f8b0:4864:20::102f]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c12bb93c-f2ba-419c-84de-ec0eb41aa6f3; Mon, 10 May 2021 09:50:57 +0000 (UTC) Received: by mail-pj1-x102f.google.com with SMTP id lj11-20020a17090b344bb029015bc3073608so9988256pjb.3 for ; Mon, 10 May 2021 02:50:57 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id 14sm10615255pfv.33.2021.05.10.02.50.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:50:56 -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: c12bb93c-f2ba-419c-84de-ec0eb41aa6f3 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=xzceaTJbUUoQMRiby9lwQqwtKo4y5qZbVn1w31ybRrg=; b=bOYHl1lk+9c5fpkjvJLlW2V+ZW1HWQZ8+GqQWpRXOyRwXl5gJ0b79YDClCoBfBBm4i Lg3ZY42RA3b3XCB5qgKa30diM6DGWie5c/Bp8lBvVatzuKYQ+cRSVyrR3Vn43XQ38Fby 6vdAkHilxAu/KAE1HFPNhr6sG764ExUW8d2uc= 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=xzceaTJbUUoQMRiby9lwQqwtKo4y5qZbVn1w31ybRrg=; b=Fk2TUqJxqirNlYbd3NLfg8yIFYOdTCgVsVgoqiSbaAB2/sKGA+1/EK+boKq5kU46J4 qLtoAmwMAkKG+2h5UuD+YirSS3StLbsQ+R1z6kaRC4gk4F+QY6yuhhbgP6URhVNOxZ9m qxuJ15dFgmvHXjGbOpXukC4IG++bQ3WNsdTKnT+YXwftrO7epCUs+PZwxwmUA0A9q+PO zlKa+HBTXjIXnXUN/BnESig2AhJRb/P5V8lw9oJF9gJF1xoFKsGqWXcgnGN/iwwQk95B /1ChRyl8aSruuC2UC1W/T9fhbhg4gRPzFnEPwsxoLXMmKH38JEBCYVI6vlq0Mx79ihjL qIgA== X-Gm-Message-State: AOAM533P8N+Y96HwxyKdWwpSVtzUG+TE5cf3P4R1Zgsc8qMFvAhcPiA0 6LcWKReWZrg+STYFseUO3BJWXA== X-Google-Smtp-Source: ABdhPJxwy0teVP8y0d4KrEbfmPne0jX/g2pgdK0Y1sxb/62SuqcTyQ5c51wqp1akhS8ac/pL7Mr0nw== X-Received: by 2002:a17:90a:bf0c:: with SMTP id c12mr25754828pjs.206.1620640256876; Mon, 10 May 2021 02:50:56 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 02/15] swiotlb: Refactor swiotlb_create_debugfs Date: Mon, 10 May 2021 17:50:13 +0800 Message-Id: <20210510095026.3477496-3-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" Split the debugfs creation to make the code reusable for supporting different bounce buffer pools, e.g. restricted DMA pool. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig --- kernel/dma/swiotlb.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index d3232fc19385..858475bd6923 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -64,6 +64,7 @@ enum swiotlb_force swiotlb_force; =20 struct io_tlb_mem *io_tlb_default_mem; +static struct dentry *debugfs_dir; =20 /* * Max segment that we can provide which (if pages are contingous) will @@ -662,18 +663,27 @@ EXPORT_SYMBOL_GPL(is_swiotlb_active); =20 #ifdef CONFIG_DEBUG_FS =20 -static int __init swiotlb_create_debugfs(void) +static void swiotlb_create_debugfs(struct io_tlb_mem *mem, const char *nam= e, + struct dentry *node) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; - if (!mem) - return 0; - mem->debugfs =3D debugfs_create_dir("swiotlb", NULL); + return; + + mem->debugfs =3D debugfs_create_dir(name, node); debugfs_create_ulong("io_tlb_nslabs", 0400, mem->debugfs, &mem->nslabs); debugfs_create_ulong("io_tlb_used", 0400, mem->debugfs, &mem->used); +} + +static int __init swiotlb_create_default_debugfs(void) +{ + struct io_tlb_mem *mem =3D io_tlb_default_mem; + + swiotlb_create_debugfs(mem, "swiotlb", NULL); + debugfs_dir =3D mem->debugfs; + return 0; } =20 -late_initcall(swiotlb_create_debugfs); +late_initcall(swiotlb_create_default_debugfs); =20 #endif --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640279; cv=none; d=zohomail.com; s=zohoarc; b=mJ5AzJhYLb2lyicLzBEIRBbxFiGEc69JuBj7PRhUIZv990RQZq0iDLYHlc+ORf/DkiRvCScSJ4AeWlJzhGhPsnvZtl1Wt5jQHJhhQRzBpJ4tGKuEgmb1lwBPVJSrJY8GC/qYd0PD9ZtfuM6z6ukIkHi8YhgZYCBidmwVGIXmOJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640279; 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=UxwjATyfUtX3knbkz7Ng4a91AyuLGtHH/dkvosOSCGg=; b=e/vCRkldmCbwrm1f1fgBaNOgqM1FKlR+GEIGXIXZGhSRlM+tb+JauErNxyMXBzKACTpPHRcRwHeQzPb/xv1MbQ94IrQ+Iexz7ln3ZPJnoG+4XX6MBdJU4GEFT+J7wnzEVmKrGuo6SqoMTfbri/KLjnRHT/p1GJRDUK9uSu7/7pk= 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 1620640279311279.16263006019267; Mon, 10 May 2021 02:51:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125054.235438 (Exim 4.92) (envelope-from ) id 1lg2Z9-0007eG-TJ; Mon, 10 May 2021 09:51:07 +0000 Received: by outflank-mailman (output) from mailman id 125054.235438; Mon, 10 May 2021 09:51:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Z9-0007e7-O8; Mon, 10 May 2021 09:51:07 +0000 Received: by outflank-mailman (input) for mailman id 125054; Mon, 10 May 2021 09:51:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Z8-0006yg-Qp for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:51:06 +0000 Received: from mail-pl1-x62a.google.com (unknown [2607:f8b0:4864:20::62a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a732de66-c3c4-4664-ab4f-d6938473f051; Mon, 10 May 2021 09:51:06 +0000 (UTC) Received: by mail-pl1-x62a.google.com with SMTP id b15so2684452plh.10 for ; Mon, 10 May 2021 02:51:06 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id ga1sm11342699pjb.5.2021.05.10.02.50.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:51:05 -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: a732de66-c3c4-4664-ab4f-d6938473f051 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=UxwjATyfUtX3knbkz7Ng4a91AyuLGtHH/dkvosOSCGg=; b=KOr6914IYxgjLwHfgEdtt7yY0GH36g2NGsJo3fGwbbJaZNcrllky3/6cWFIPbrcxnF J6WIRuHd84U2i5BBiDKA/bsQe9y2Z9UkJ/RbWHnAxAdDWQ5FGpvFFVOBGDi0XQRFybWw dDc+W6hlTJe2OtGlIaJLuh2fe89FW6RCivPnU= 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=UxwjATyfUtX3knbkz7Ng4a91AyuLGtHH/dkvosOSCGg=; b=UaKwY+D+WqJ5npUvvk8D9suzezUX1dhxpILFAOY6gPP8ZxVkvamrKgnoonXRMTVTN4 4BbQALl49A9rTf3yh8+qEnojDVZt6KzKD3yvB1OaWXkD1aCAy5RmTfTDDbT//8mvubak CZTLZhYp7BCuqe+j7fwTsi38pVyD32GTCGA3EY4WF5w5SeQPJb1s/0hdJ4bnwkuX/Dzz R1zhR6kDGpGVrg0pn61w140JwxzVmRC+D3zewQqIsltRlQeqhiZ5kmopwPkqy5JCXeBn iGqa/FGSH1N+0dQqHsM7Xj6S/WSzEFc6ctvLImtZu0Y5alCQJRZv9uwQnkFXbYliMc5t thwg== X-Gm-Message-State: AOAM531WkKk3WVm/4575AFw7Ndp7jZ/qseIL3edlb0dXsEzSWXxnOYGX dmXMv4cKrPUXwXCZNWmmVhpCPg== X-Google-Smtp-Source: ABdhPJxTaq6vhy1R6G0CsSRkldwCBABZULYIDbfdaYlGZp1FgQhncVgdgDLR34kcwkcv6yJulF+tnA== X-Received: by 2002:a17:90a:cf10:: with SMTP id h16mr26442566pju.49.1620640265461; Mon, 10 May 2021 02:51:05 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 03/15] swiotlb: Add DMA_RESTRICTED_POOL Date: Mon, 10 May 2021 17:50:14 +0800 Message-Id: <20210510095026.3477496-4-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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 kconfig symbol, DMA_RESTRICTED_POOL, for restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/Kconfig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index 77b405508743..3e961dc39634 100644 --- a/kernel/dma/Kconfig +++ b/kernel/dma/Kconfig @@ -80,6 +80,20 @@ config SWIOTLB bool select NEED_DMA_MAP_STATE =20 +config DMA_RESTRICTED_POOL + bool "DMA Restricted Pool" + depends on OF && OF_RESERVED_MEM + select SWIOTLB + help + This enables support for restricted DMA pools which provide a level of + DMA memory protection on systems with limited hardware protection + capabilities, such as those lacking an IOMMU. + + For more information see + + and . + If unsure, say "n". + # # Should be selected if we can mmap non-coherent mappings to userspace. # The only thing that is really required is a way to set an uncached bit --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640289; cv=none; d=zohomail.com; s=zohoarc; b=MkpiaJ4X/PszNZdkxJwpovlDUtmu2bTel1ISP5ZDPp1ky57lWLe4d4sH2HsAdYXNN74H2gHatKFGh29oKusfhuJCEDq0mh792ES8qWS8yu0HqUQsVtxh+dWpEVto03RKMLCtdkskOyqcSV0TbO5ahB7ogSh8rex3UUahr9eDgQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640289; 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=N3P9GLK7vHKhYVQQtJseEAxm9BpujcOrU5/c0rsEVEk=; b=Mdv7Zw1ug6liB6A0BeVurTJjKvf3CueDjmSt9cdu9YLrX/bGGztiO29bfRWy7m/Z1DO5t5QNX6cn7mPQg+cYOEK4gT19rHCLuEDuRMgKf9bDtVtBsKzZpyBjaw+DYBu7xBjt2Ecln5HtkY1AAhOftKRrH41IPXixfJBXmUqxpQo= 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 1620640289805175.64937300819577; Mon, 10 May 2021 02:51:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125057.235450 (Exim 4.92) (envelope-from ) id 1lg2ZJ-0008Hn-61; Mon, 10 May 2021 09:51:17 +0000 Received: by outflank-mailman (output) from mailman id 125057.235450; Mon, 10 May 2021 09:51:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ZJ-0008Hg-25; Mon, 10 May 2021 09:51:17 +0000 Received: by outflank-mailman (input) for mailman id 125057; Mon, 10 May 2021 09:51:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ZH-0006yg-J4 for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:51:15 +0000 Received: from mail-pj1-x102e.google.com (unknown [2607:f8b0:4864:20::102e]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9173233d-ec42-410c-b964-4a13e051f3ee; Mon, 10 May 2021 09:51:14 +0000 (UTC) Received: by mail-pj1-x102e.google.com with SMTP id gc22-20020a17090b3116b02901558435aec1so9990818pjb.4 for ; Mon, 10 May 2021 02:51:14 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id 85sm10570175pge.92.2021.05.10.02.51.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:51:13 -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: 9173233d-ec42-410c-b964-4a13e051f3ee 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=N3P9GLK7vHKhYVQQtJseEAxm9BpujcOrU5/c0rsEVEk=; b=Y7aOu5/1TjGJ39Q6KlGygdgKwH9kbvC5j2KTJY6W4XTdOExKpGYjoeXyBJiXgd/KYk KzSpnP+ON6ZMnZKtG68AQfgatZrpSEM8rt3qhHBX67wSb4snRTMym5W+JAqIFz3C1rDu rEn+A4sHCgc1HrIPZtrVf2hBqqnA1o60c7EF4= 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=N3P9GLK7vHKhYVQQtJseEAxm9BpujcOrU5/c0rsEVEk=; b=GDvLkPggzBHPEIP4ZVeRi12Lpf1iAQlzTCpPOMwQ1OajrWXtbZuMB2T+EguMxJfjTk leMo5p8TelxINC2GjNGt/msdf/s1RmSclCEkAUz1thBF9HrQg9qvT+94ynDvDvIbC2iF rkonPF2dHAg5432+EnEBcqZD+A1l3rRu6IgKRvPT+yvsho5CADlQUrEqAAaqHgT4UKwR +ScKO/CZkhVG9Pcr1VpHgR8NeoBvyGv1UErZHmtfJixOVa9CUd6vszFFOk/XCm6lUDYW 3bk9rc4u/0ZgMOQK06OrHkAKxTM3XVBQxwetW0B+c9L1EgRotYPYJwyrX4ebmJtdzaIN hVtg== X-Gm-Message-State: AOAM532jd/GD6q52CKpPYmpL5XIqDHhm+xgMc+u4GiaA0QQV7lzq08iO cClvBv7I6MJ0FSYUQ2ZX1h0AVg== X-Google-Smtp-Source: ABdhPJx/+mqX+1PPw1d6WrMopD8tcfP0qxrVaW6dh7H0TOwQsbO/ZVrG7imWQ0Lmzh0hiACiE2GhCg== X-Received: by 2002:a17:902:f203:b029:ee:e32f:2a28 with SMTP id m3-20020a170902f203b02900eee32f2a28mr22959818plc.45.1620640274038; Mon, 10 May 2021 02:51:14 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 04/15] swiotlb: Add restricted DMA pool initialization Date: Mon, 10 May 2021 17:50:15 +0800 Message-Id: <20210510095026.3477496-5-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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 the initialization function to create restricted DMA pools from matching reserved-memory nodes. Signed-off-by: Claire Chang --- include/linux/device.h | 4 +++ include/linux/swiotlb.h | 3 +- kernel/dma/swiotlb.c | 79 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/include/linux/device.h b/include/linux/device.h index 38a2071cf776..4987608ea4ff 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -416,6 +416,7 @@ struct dev_links_info { * @dma_pools: Dma pools (if dma'ble device). * @dma_mem: Internal for coherent mem override. * @cma_area: Contiguous memory area for dma allocations + * @dma_io_tlb_mem: Internal for swiotlb io_tlb_mem override. * @archdata: For arch-specific additions. * @of_node: Associated device tree node. * @fwnode: Associated device node supplied by platform firmware. @@ -521,6 +522,9 @@ struct device { #ifdef CONFIG_DMA_CMA struct cma *cma_area; /* contiguous memory area for dma allocations */ +#endif +#ifdef CONFIG_DMA_RESTRICTED_POOL + struct io_tlb_mem *dma_io_tlb_mem; #endif /* arch specific additions */ struct dev_archdata archdata; diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 216854a5e513..03ad6e3b4056 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -72,7 +72,8 @@ extern enum swiotlb_force swiotlb_force; * range check to see if the memory was in fact allocated by this * API. * @nslabs: The number of IO TLB blocks (in groups of 64) between @start a= nd - * @end. This is command line adjustable via setup_io_tlb_npages. + * @end. For default swiotlb, this is command line adjustable via + * setup_io_tlb_npages. * @used: The number of used IO TLB block. * @list: The free list describing the number of free entries available * from each index. diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 858475bd6923..4ea027b75013 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -39,6 +39,13 @@ #ifdef CONFIG_DEBUG_FS #include #endif +#ifdef CONFIG_DMA_RESTRICTED_POOL +#include +#include +#include +#include +#include +#endif =20 #include #include @@ -687,3 +694,75 @@ static int __init swiotlb_create_default_debugfs(void) late_initcall(swiotlb_create_default_debugfs); =20 #endif + +#ifdef CONFIG_DMA_RESTRICTED_POOL +static int rmem_swiotlb_device_init(struct reserved_mem *rmem, + struct device *dev) +{ + struct io_tlb_mem *mem =3D rmem->priv; + unsigned long nslabs =3D rmem->size >> IO_TLB_SHIFT; + + if (dev->dma_io_tlb_mem) + return 0; + + /* Since multiple devices can share the same pool, the private data, + * io_tlb_mem struct, will be initialized by the first device attached + * to it. + */ + if (!mem) { + mem =3D kzalloc(struct_size(mem, slots, nslabs), GFP_KERNEL); + if (!mem) + return -ENOMEM; +#ifdef CONFIG_ARM + if (!PageHighMem(pfn_to_page(PHYS_PFN(rmem->base)))) { + kfree(mem); + return -EINVAL; + } +#endif /* CONFIG_ARM */ + swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false); + + rmem->priv =3D mem; + +#ifdef CONFIG_DEBUG_FS + if (!debugfs_dir) + debugfs_dir =3D debugfs_create_dir("swiotlb", NULL); + + swiotlb_create_debugfs(mem, rmem->name, debugfs_dir); +#endif /* CONFIG_DEBUG_FS */ + } + + dev->dma_io_tlb_mem =3D mem; + + return 0; +} + +static void rmem_swiotlb_device_release(struct reserved_mem *rmem, + struct device *dev) +{ + if (dev) + dev->dma_io_tlb_mem =3D NULL; +} + +static const struct reserved_mem_ops rmem_swiotlb_ops =3D { + .device_init =3D rmem_swiotlb_device_init, + .device_release =3D rmem_swiotlb_device_release, +}; + +static int __init rmem_swiotlb_setup(struct reserved_mem *rmem) +{ + unsigned long node =3D rmem->fdt_node; + + if (of_get_flat_dt_prop(node, "reusable", NULL) || + of_get_flat_dt_prop(node, "linux,cma-default", NULL) || + of_get_flat_dt_prop(node, "linux,dma-default", NULL) || + of_get_flat_dt_prop(node, "no-map", NULL)) + return -EINVAL; + + rmem->ops =3D &rmem_swiotlb_ops; + pr_info("Reserved memory: created device swiotlb memory pool at %pa, size= %ld MiB\n", + &rmem->base, (unsigned long)rmem->size / SZ_1M); + return 0; +} + +RESERVEDMEM_OF_DECLARE(dma, "restricted-dma-pool", rmem_swiotlb_setup); +#endif /* CONFIG_DMA_RESTRICTED_POOL */ --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640297; cv=none; d=zohomail.com; s=zohoarc; b=eWKe8fLfIQI6psw6d6+28gd7wI1oxok7FOvTQLY3XvasQf9ISlb0d/AVrLuZ/xU95fNBi7Oab/FWc0mVU8opqc7U6UEoxZdJmySThuXzZERZ5/IXs8NimZj+TPeuKDzmbiadxUAMK83fx3gvalP+MR5ky3V+demehS3lRmF0JaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640297; 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=H8s2Ssxedi+m7Lc7mdaT6IyIVFNL7UMFVGCjjIXUKBs=; b=gH1bhmHnlVqy3RpkZRjTbNYMErqI9zFgTHozTSznSJM0hIhlj+XwzDJNMtgxeVc6cadG88RV9GA8L9W/pvidqNLtme8Z0ARgLLxWv/z0NeOx4xpxs47zNujJXIL0cjZgKV7DoqCHv2vLSzxCINbwUdxARNXMcuN2IZVgRyPjrEE= 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 162064029724766.39496821125397; Mon, 10 May 2021 02:51:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125060.235462 (Exim 4.92) (envelope-from ) id 1lg2ZR-0000QA-J9; Mon, 10 May 2021 09:51:25 +0000 Received: by outflank-mailman (output) from mailman id 125060.235462; Mon, 10 May 2021 09:51:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ZR-0000Q1-El; Mon, 10 May 2021 09:51:25 +0000 Received: by outflank-mailman (input) for mailman id 125060; Mon, 10 May 2021 09:51:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ZQ-0000Oo-J5 for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:51:24 +0000 Received: from mail-pj1-x1035.google.com (unknown [2607:f8b0:4864:20::1035]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f223f673-d063-487e-adc7-57718bd48a59; Mon, 10 May 2021 09:51:23 +0000 (UTC) Received: by mail-pj1-x1035.google.com with SMTP id lp4so9445836pjb.1 for ; Mon, 10 May 2021 02:51:23 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id ml19sm46030318pjb.2.2021.05.10.02.51.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:51:22 -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: f223f673-d063-487e-adc7-57718bd48a59 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=H8s2Ssxedi+m7Lc7mdaT6IyIVFNL7UMFVGCjjIXUKBs=; b=aEzUGv6HyICG91lVRchMBsfGFoiKw5t3UKv5r9/XWkq1l03uTxk5gK7BReGArG4wM7 eL8k61LHaWwrgnh+WJYeL7I+S/QoUwEkwv6x0tDx3HcpYoUp9liwFvhqHJX8OnvlaqU3 oxtyLQT57sgPbzesRlkZ21sVrQ/LPb2+Dv9rE= 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=H8s2Ssxedi+m7Lc7mdaT6IyIVFNL7UMFVGCjjIXUKBs=; b=hjX/N7oS5rQGF6Tt9iqBgUiYh8RoSzZVS7T5GWrxWYdc1GmK0o5kY6bV6hwamANSeL Y/Mm/W4c46RoerMHBgxX2bv2jKZn1TJi95AL4DjpzWF/9DEJrzy3zmEDLB9gj2paSh1i d3+SuPtHdKEtjm1fpYBlbqkyiRRIW47I7cEbMLeRZjThB/s16Wxs3vgw4r/xtiyTMHxU bhs9Gxv2tOBiY5edqn5jzsut43RKVl/fcoVhiMZfjhCqj7vvDJhT2JGaVDLGUxNpilQ0 zrP8B1q8rTLgkHUsRn0HRE6jXbg+3+AG/JH/Px0NJgGNF5mqdeeXWSozBpL/L8VrtlpF dmKw== X-Gm-Message-State: AOAM531/N7ts+PWJTe5nWs2f4Nwg81Z0z6FZVCCD/stF00uC8L1SGcMa Nue7KMlBDxIUGjNgACjxsbSteg== X-Google-Smtp-Source: ABdhPJzROW5FUCBZB2fXFHkP0ALBea1sVjbZahlfu04HnoSywATlCq/z9y3jgockvO/xDk1J1RoGzg== X-Received: by 2002:a17:90b:1bcd:: with SMTP id oa13mr40100520pjb.22.1620640283118; Mon, 10 May 2021 02:51:23 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 05/15] swiotlb: Add a new get_io_tlb_mem getter Date: Mon, 10 May 2021 17:50:16 +0800 Message-Id: <20210510095026.3477496-6-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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 getter, get_io_tlb_mem, to help select the io_tlb_mem struct. The restricted DMA pool is preferred if available. Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 03ad6e3b4056..b469f04cca26 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -2,6 +2,7 @@ #ifndef __LINUX_SWIOTLB_H #define __LINUX_SWIOTLB_H =20 +#include #include #include #include @@ -102,6 +103,16 @@ struct io_tlb_mem { }; extern struct io_tlb_mem *io_tlb_default_mem; =20 +static inline struct io_tlb_mem *get_io_tlb_mem(struct device *dev) +{ +#ifdef CONFIG_DMA_RESTRICTED_POOL + if (dev && dev->dma_io_tlb_mem) + return dev->dma_io_tlb_mem; +#endif /* CONFIG_DMA_RESTRICTED_POOL */ + + return io_tlb_default_mem; +} + static inline bool is_swiotlb_buffer(phys_addr_t paddr) { struct io_tlb_mem *mem =3D io_tlb_default_mem; --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640307; cv=none; d=zohomail.com; s=zohoarc; b=lYOZd/8HFyGPAsZFmFGIWVosjXb/7gLftUrGnN4ETh9lhqN4lzRgCAmKgPyysb27FaerXgLxFv+3LNoyFfgQ43sgxjvURWX4nrHj6JBoLXSdi5AR+BJOKnTfaiHdKhaweLvD8n58/dEZ31Ber5F22wPtBQntzrbLQEgV9kgfUYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640307; 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=tZ3CGs8f3EQmgAGpvf1e73TqcXREEE3ZI5sdNnb0eLM=; b=EdViK8SPmO3FfyVzI9YjpDs4HB39iHHtPt2iyot8EffvhW4gTlFjqlmduhqohq/t1PntAFkGdpUoBMvUzXavW+UBU9wYIyA28224M+B+80JbPsFzWzNZtRzNH/f0tIPipoMUSUXEKEoe7JZon5umMj+t9M9INnJfQeVMeUW7RXU= 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 1620640307734714.771288994876; Mon, 10 May 2021 02:51:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125066.235474 (Exim 4.92) (envelope-from ) id 1lg2Za-0000yx-Sm; Mon, 10 May 2021 09:51:34 +0000 Received: by outflank-mailman (output) from mailman id 125066.235474; Mon, 10 May 2021 09:51:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Za-0000yg-OO; Mon, 10 May 2021 09:51:34 +0000 Received: by outflank-mailman (input) for mailman id 125066; Mon, 10 May 2021 09:51:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ZZ-0000Oo-Aq for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:51:33 +0000 Received: from mail-pj1-x102b.google.com (unknown [2607:f8b0:4864:20::102b]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a4f53698-8f8b-4df3-84ef-c1d804054074; Mon, 10 May 2021 09:51:32 +0000 (UTC) Received: by mail-pj1-x102b.google.com with SMTP id gq14-20020a17090b104eb029015be008ab0fso9741937pjb.1 for ; Mon, 10 May 2021 02:51:32 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id w123sm10461275pfw.151.2021.05.10.02.51.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:51:31 -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: a4f53698-8f8b-4df3-84ef-c1d804054074 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=tZ3CGs8f3EQmgAGpvf1e73TqcXREEE3ZI5sdNnb0eLM=; b=lMyouNryYo5w5lJuE95kxHABr2UavthBxCrElnGryB1miCRsJl0qEAj6meErMJSozY Bf+wF4N8bQO1PcUVKGrINY6G+y/OtqfRp6rQIHL8mDnrXGD2FuJWgJ9PSVDL0De8/bNM idqD9o+yRklHjS47HZfFBHHPPAwrsxzQqtqBs= 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=tZ3CGs8f3EQmgAGpvf1e73TqcXREEE3ZI5sdNnb0eLM=; b=NASqcu3dDdb4rBvKCcqyKi1liNZVbrqFu57ln42kQJJxQ9pY+zNmtTR/72qxFo658I LV7K8Rn8TYk9cLw3JPSq9TUS31xnU/99ipRXlY5qAYeudJwmFgEyh5ecHLw7m8nBlQUz KbHTsSNax425MoDSBAlmehcxlFc9GQcEE0hoAc3v+NyHqCDJeBIn919OvY59MWz2+Vcs wcYzplhFJmoT8/ZA9uHXjVpVT/VTpMcqqmRVMktZ7MSdHUbNYAH6T9N36pQjBfnDxyQS Psn2GxgMXhKpQy4nj8ft4q8DXLAj+Rh7BV6E45LUFSCNUZNmBtBi2zcxm5K+IfLBEXOG 1TEQ== X-Gm-Message-State: AOAM5323yGFicKKp9fVedBUQbEaOWSlgwhJxKD7xv4CV3bzMjm9EGh4p KV+DN4/IkSRc1pFxYMuD8gh96g== X-Google-Smtp-Source: ABdhPJy89/+hGNaFqoNDxXRLLHozjYcSxQ6nSmzavfsLOw7KffX2ycDLbnJ717I2O8/EFzmzVKyA2w== X-Received: by 2002:a17:90b:88b:: with SMTP id bj11mr27142987pjb.224.1620640291726; Mon, 10 May 2021 02:51:31 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 06/15] swiotlb: Update is_swiotlb_buffer to add a struct device argument Date: Mon, 10 May 2021 17:50:17 +0800 Message-Id: <20210510095026.3477496-7-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" Update is_swiotlb_buffer to add a struct device argument. This will be useful later to allow for restricted DMA pool. Signed-off-by: Claire Chang --- drivers/iommu/dma-iommu.c | 12 ++++++------ drivers/xen/swiotlb-xen.c | 2 +- include/linux/swiotlb.h | 6 +++--- kernel/dma/direct.c | 6 +++--- kernel/dma/direct.h | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7bcdd1205535..a5df35bfd150 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -504,7 +504,7 @@ static void __iommu_dma_unmap_swiotlb(struct device *de= v, dma_addr_t dma_addr, =20 __iommu_dma_unmap(dev, dma_addr, size); =20 - if (unlikely(is_swiotlb_buffer(phys))) + if (unlikely(is_swiotlb_buffer(dev, phys))) swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); } =20 @@ -575,7 +575,7 @@ static dma_addr_t __iommu_dma_map_swiotlb(struct device= *dev, phys_addr_t phys, } =20 iova =3D __iommu_dma_map(dev, phys, aligned_size, prot, dma_mask); - if (iova =3D=3D DMA_MAPPING_ERROR && is_swiotlb_buffer(phys)) + if (iova =3D=3D DMA_MAPPING_ERROR && is_swiotlb_buffer(dev, phys)) swiotlb_tbl_unmap_single(dev, phys, org_size, dir, attrs); return iova; } @@ -781,7 +781,7 @@ static void iommu_dma_sync_single_for_cpu(struct device= *dev, if (!dev_is_dma_coherent(dev)) arch_sync_dma_for_cpu(phys, size, dir); =20 - if (is_swiotlb_buffer(phys)) + if (is_swiotlb_buffer(dev, phys)) swiotlb_sync_single_for_cpu(dev, phys, size, dir); } =20 @@ -794,7 +794,7 @@ static void iommu_dma_sync_single_for_device(struct dev= ice *dev, return; =20 phys =3D iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle); - if (is_swiotlb_buffer(phys)) + if (is_swiotlb_buffer(dev, phys)) swiotlb_sync_single_for_device(dev, phys, size, dir); =20 if (!dev_is_dma_coherent(dev)) @@ -815,7 +815,7 @@ static void iommu_dma_sync_sg_for_cpu(struct device *de= v, if (!dev_is_dma_coherent(dev)) arch_sync_dma_for_cpu(sg_phys(sg), sg->length, dir); =20 - if (is_swiotlb_buffer(sg_phys(sg))) + if (is_swiotlb_buffer(dev, sg_phys(sg))) swiotlb_sync_single_for_cpu(dev, sg_phys(sg), sg->length, dir); } @@ -832,7 +832,7 @@ static void iommu_dma_sync_sg_for_device(struct device = *dev, return; =20 for_each_sg(sgl, sg, nelems, i) { - if (is_swiotlb_buffer(sg_phys(sg))) + if (is_swiotlb_buffer(dev, sg_phys(sg))) swiotlb_sync_single_for_device(dev, sg_phys(sg), sg->length, dir); =20 diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 4c89afc0df62..0c6ed09f8513 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -100,7 +100,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dm= a_addr_t dma_addr) * in our domain. Therefore _only_ check address within our domain. */ if (pfn_valid(PFN_DOWN(paddr))) - return is_swiotlb_buffer(paddr); + return is_swiotlb_buffer(dev, paddr); return 0; } =20 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index b469f04cca26..2a6cca07540b 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -113,9 +113,9 @@ static inline struct io_tlb_mem *get_io_tlb_mem(struct = device *dev) return io_tlb_default_mem; } =20 -static inline bool is_swiotlb_buffer(phys_addr_t paddr) +static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D get_io_tlb_mem(dev); =20 return mem && paddr >=3D mem->start && paddr < mem->end; } @@ -127,7 +127,7 @@ bool is_swiotlb_active(void); void __init swiotlb_adjust_size(unsigned long size); #else #define swiotlb_force SWIOTLB_NO_FORCE -static inline bool is_swiotlb_buffer(phys_addr_t paddr) +static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr) { return false; } diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index f737e3347059..84c9feb5474a 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -343,7 +343,7 @@ void dma_direct_sync_sg_for_device(struct device *dev, for_each_sg(sgl, sg, nents, i) { phys_addr_t paddr =3D dma_to_phys(dev, sg_dma_address(sg)); =20 - if (unlikely(is_swiotlb_buffer(paddr))) + if (unlikely(is_swiotlb_buffer(dev, paddr))) swiotlb_sync_single_for_device(dev, paddr, sg->length, dir); =20 @@ -369,7 +369,7 @@ void dma_direct_sync_sg_for_cpu(struct device *dev, if (!dev_is_dma_coherent(dev)) arch_sync_dma_for_cpu(paddr, sg->length, dir); =20 - if (unlikely(is_swiotlb_buffer(paddr))) + if (unlikely(is_swiotlb_buffer(dev, paddr))) swiotlb_sync_single_for_cpu(dev, paddr, sg->length, dir); =20 @@ -504,7 +504,7 @@ size_t dma_direct_max_mapping_size(struct device *dev) bool dma_direct_need_sync(struct device *dev, dma_addr_t dma_addr) { return !dev_is_dma_coherent(dev) || - is_swiotlb_buffer(dma_to_phys(dev, dma_addr)); + is_swiotlb_buffer(dev, dma_to_phys(dev, dma_addr)); } =20 /** diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h index 50afc05b6f1d..13e9e7158d94 100644 --- a/kernel/dma/direct.h +++ b/kernel/dma/direct.h @@ -56,7 +56,7 @@ static inline void dma_direct_sync_single_for_device(stru= ct device *dev, { phys_addr_t paddr =3D dma_to_phys(dev, addr); =20 - if (unlikely(is_swiotlb_buffer(paddr))) + if (unlikely(is_swiotlb_buffer(dev, paddr))) swiotlb_sync_single_for_device(dev, paddr, size, dir); =20 if (!dev_is_dma_coherent(dev)) @@ -73,7 +73,7 @@ static inline void dma_direct_sync_single_for_cpu(struct = device *dev, arch_sync_dma_for_cpu_all(); } =20 - if (unlikely(is_swiotlb_buffer(paddr))) + if (unlikely(is_swiotlb_buffer(dev, paddr))) swiotlb_sync_single_for_cpu(dev, paddr, size, dir); =20 if (dir =3D=3D DMA_FROM_DEVICE) @@ -113,7 +113,7 @@ static inline void dma_direct_unmap_page(struct device = *dev, dma_addr_t addr, if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) dma_direct_sync_single_for_cpu(dev, addr, size, dir); =20 - if (unlikely(is_swiotlb_buffer(phys))) + if (unlikely(is_swiotlb_buffer(dev, phys))) swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); } #endif /* _KERNEL_DMA_DIRECT_H */ --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640317; cv=none; d=zohomail.com; s=zohoarc; b=Ad4hRK7zbm8NOuJuabbyEDBYDFJiUdmOe7oi24/zuNRKYAQrK/1yLsHJNg6q8GL1HV0V74G9CKP6GyXWRTsyJ6IxL0z4iCtVbdWCjVZw0oPkOpsDGhLmz0eHNpY167xlb+T7YKsmrsUx3tBThIrlK0RmJ273U+pZWov1fNCq/+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640317; 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=+JmVmhSFGiDk3/OglOY5X9UAspXEPeRZrOOQ1jue7o0=; b=nMthHDcy83sLxG7WxNa+58ax9U3FkEkHu50wNCJUuN11cnlLK0AY2kJQgBAbqlQVrqzAlcgCyPV3doJXBajo715cin5xz3WLXv4IcUXRULLF3xRU3/wbuRXMTdMnSB/wF73zvNs5yx7oG0yd+KnAJz1B+YojObnIEch7qMXuLgs= 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 1620640317169201.64580704871787; Mon, 10 May 2021 02:51:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125070.235486 (Exim 4.92) (envelope-from ) id 1lg2Zj-0001eK-6a; Mon, 10 May 2021 09:51:43 +0000 Received: by outflank-mailman (output) from mailman id 125070.235486; Mon, 10 May 2021 09:51:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Zj-0001e8-2m; Mon, 10 May 2021 09:51:43 +0000 Received: by outflank-mailman (input) for mailman id 125070; Mon, 10 May 2021 09:51:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Zh-0001bJ-Uo for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:51:41 +0000 Received: from mail-pf1-x42c.google.com (unknown [2607:f8b0:4864:20::42c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6740ae25-12c4-410f-93bc-71fb9f834bd8; Mon, 10 May 2021 09:51:41 +0000 (UTC) Received: by mail-pf1-x42c.google.com with SMTP id p4so13283421pfo.3 for ; Mon, 10 May 2021 02:51:41 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id z16sm18516572pjq.42.2021.05.10.02.51.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:51:40 -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: 6740ae25-12c4-410f-93bc-71fb9f834bd8 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=+JmVmhSFGiDk3/OglOY5X9UAspXEPeRZrOOQ1jue7o0=; b=chdPcJe7gomL+7ILnJK41quCdTSfmmzVjcLxZvr96abVbyS2hxQz55JkSmjVpMuD2l 7hrZDyiec0Eptx6DlOgctch3MP18AQl2Z0UBjvJYxcIDfchdSPR9HSnruN0+XHwsK91U nLMYdSbyGfntFvFyhHjVYHf29JB1JZpxW2+jI= 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=+JmVmhSFGiDk3/OglOY5X9UAspXEPeRZrOOQ1jue7o0=; b=WC1STTRg1JByTE0x6z5/kSHureXLSeCUduO2ZpqCUB7/AlyegA1r7ZMe7U67eQEDfJ OIff2lZHW7s7brarGOC++pYNUIY5Rkp6gmXwXt0k2FIIEtYIWqSYae94jV0bum36Yd1E QEDig+8PyDmfYxzesHxMq2c8KqdlU9O9kQkZfcrw6RNYBoEh1BH8l6mOiCZWCi6Gg3Ne npt0J9sAuhsRlrY9n689Ea0XK7pS7JZqVHkSfalNJxGr0umlVR7NfA02XTmUpglyrRhF B5I+kuVsh0JmHD3QTW2RgEpBcGBTNGSu6JQ0BeLnqQeaP8lXOWeK9O6ZF1zf38bYcwgB ypRQ== X-Gm-Message-State: AOAM533t5hduGfJL2cF29dZIAiDAKPivLp1ioq4BH4I+Ki02BY0VXzla Fv3W7QEEAxFu5VyaPmO/C5Rqbg== X-Google-Smtp-Source: ABdhPJwEuklfL8gjazzjb7wDgipUUvm7epPmX8yFSlIdzWj0uWm4MepZyYy8A9RBNCckvPkGtYRV9Q== X-Received: by 2002:aa7:828f:0:b029:200:6e27:8c8f with SMTP id s15-20020aa7828f0000b02902006e278c8fmr24143255pfm.44.1620640300375; Mon, 10 May 2021 02:51:40 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 07/15] swiotlb: Update is_swiotlb_active to add a struct device argument Date: Mon, 10 May 2021 17:50:18 +0800 Message-Id: <20210510095026.3477496-8-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" Update is_swiotlb_active to add a struct device argument. This will be useful later to allow for restricted DMA pool. Signed-off-by: Claire Chang --- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 2 +- drivers/gpu/drm/nouveau/nouveau_ttm.c | 2 +- drivers/pci/xen-pcifront.c | 2 +- include/linux/swiotlb.h | 4 ++-- kernel/dma/direct.c | 2 +- kernel/dma/swiotlb.c | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm= /i915/gem/i915_gem_internal.c index ce6b664b10aa..7d48c433446b 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c @@ -42,7 +42,7 @@ static int i915_gem_object_get_pages_internal(struct drm_= i915_gem_object *obj) =20 max_order =3D MAX_ORDER; #ifdef CONFIG_SWIOTLB - if (is_swiotlb_active()) { + if (is_swiotlb_active(NULL)) { unsigned int max_segment; =20 max_segment =3D swiotlb_max_segment(); diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouvea= u/nouveau_ttm.c index e8b506a6685b..2a2ae6d6cf6d 100644 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c @@ -321,7 +321,7 @@ nouveau_ttm_init(struct nouveau_drm *drm) } =20 #if IS_ENABLED(CONFIG_SWIOTLB) && IS_ENABLED(CONFIG_X86) - need_swiotlb =3D is_swiotlb_active(); + need_swiotlb =3D is_swiotlb_active(NULL); #endif =20 ret =3D ttm_device_init(&drm->ttm.bdev, &nouveau_bo_driver, drm->dev->dev, diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index b7a8f3a1921f..6d548ce53ce7 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -693,7 +693,7 @@ static int pcifront_connect_and_init_dma(struct pcifron= t_device *pdev) =20 spin_unlock(&pcifront_dev_lock); =20 - if (!err && !is_swiotlb_active()) { + if (!err && !is_swiotlb_active(NULL)) { err =3D pci_xen_swiotlb_init_late(); if (err) dev_err(&pdev->xdev->dev, "Could not setup SWIOTLB!\n"); diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 2a6cca07540b..c530c976d18b 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -123,7 +123,7 @@ static inline bool is_swiotlb_buffer(struct device *dev= , phys_addr_t paddr) void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); -bool is_swiotlb_active(void); +bool is_swiotlb_active(struct device *dev); void __init swiotlb_adjust_size(unsigned long size); #else #define swiotlb_force SWIOTLB_NO_FORCE @@ -143,7 +143,7 @@ static inline size_t swiotlb_max_mapping_size(struct de= vice *dev) return SIZE_MAX; } =20 -static inline bool is_swiotlb_active(void) +static inline bool is_swiotlb_active(struct device *dev) { return false; } diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 84c9feb5474a..7a88c34d0867 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -495,7 +495,7 @@ int dma_direct_supported(struct device *dev, u64 mask) size_t dma_direct_max_mapping_size(struct device *dev) { /* If SWIOTLB is active, use its maximum mapping size */ - if (is_swiotlb_active() && + if (is_swiotlb_active(dev) && (dma_addressing_limited(dev) || swiotlb_force =3D=3D SWIOTLB_FORCE)) return swiotlb_max_mapping_size(dev); return SIZE_MAX; diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 4ea027b75013..81bed3d2c771 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -662,9 +662,9 @@ size_t swiotlb_max_mapping_size(struct device *dev) return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE; } =20 -bool is_swiotlb_active(void) +bool is_swiotlb_active(struct device *dev) { - return io_tlb_default_mem !=3D NULL; + return get_io_tlb_mem(dev) !=3D NULL; } EXPORT_SYMBOL_GPL(is_swiotlb_active); =20 --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640325; cv=none; d=zohomail.com; s=zohoarc; b=at11xFIKBJOt/btU2IkTIGHxeQ5DYPWLZPlfJNtP6slNBpPwMOL50yuHTd88bwgSFyVz5IR7+k30Id5VuQ6B6B6Yw7Em/eecD4x6UPsFnWNksuzrcJwSmO/GCaSMhISuo+AtviK+PJicON2m0ffSYY4HPvkk76OPCzXvb+2c3mw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640325; 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=01kC5VD+dD2b0OOexB3kVYJ/sTlgIQPUcrnnVCwnvhY=; b=gWF6DqUPki+udqbdEH8EX4ddFyC8/CJJ5A0NCeB+lEbozkuzkyl7mNRLYJ1kb+bIOoAqahUmI8U2B/ssKtnGuBGXC2jXOegv/hEiG44JJzNR/soRIr6iiDQsrqgZFVJiEcHlhmlpxEKiqkimpJaukk2riHN2eEbHyqd5Pd0qKm8= 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 1620640325116259.60083458997667; Mon, 10 May 2021 02:52:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125074.235498 (Exim 4.92) (envelope-from ) id 1lg2Zs-0002EW-Eu; Mon, 10 May 2021 09:51:52 +0000 Received: by outflank-mailman (output) from mailman id 125074.235498; Mon, 10 May 2021 09:51:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Zs-0002EL-BP; Mon, 10 May 2021 09:51:52 +0000 Received: by outflank-mailman (input) for mailman id 125074; Mon, 10 May 2021 09:51:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Zq-0002B1-J4 for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:51:50 +0000 Received: from mail-pl1-x62d.google.com (unknown [2607:f8b0:4864:20::62d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0b02f7a2-874f-4b06-87b7-47f2c8bbf3ec; Mon, 10 May 2021 09:51:49 +0000 (UTC) Received: by mail-pl1-x62d.google.com with SMTP id z18so5273455plg.8 for ; Mon, 10 May 2021 02:51:49 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id s64sm6702432pfs.3.2021.05.10.02.51.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:51:48 -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: 0b02f7a2-874f-4b06-87b7-47f2c8bbf3ec 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=01kC5VD+dD2b0OOexB3kVYJ/sTlgIQPUcrnnVCwnvhY=; b=lgBDGiALZJWoTMGClwt7gAfCf14fepwM0lhs1vHuCCfVO5wyRcvJle6S59iBD1WHjw VcpIItr7I/JDG2KUPkhdMWHWpmui21OOXJ9ngFwe6+SQwXm1Lr/pV+cfahxnBOMneB9Q gdKX6Ey7xAgGLsyJX9bor8s5uFP/awnm9jDNw= 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=01kC5VD+dD2b0OOexB3kVYJ/sTlgIQPUcrnnVCwnvhY=; b=i9x2Ic4sH2hGOGvMzo0yse9mrQbGm/Wknx1+Iu8hIAUk2aT4PqohdB+fVgpjPvn/dF rLPRfEwiHXVYQi6x7T2qJZkR8pd0gtxqb1PqfgzYapy4KdnE5e7A3Z9G9Z6nAvTkPKYG jTQqymPDjqG3u073A0Wx5v53cYcQ0C4OnR0tIjrDU5UX7TR8lrenxj2LBTjwdn7Fm9kg UqMt0BsiyH0XvMZTRrxFOXby0uRW8MKsXO3KQhfblWppAYzJU9JNwIhyfsxqzhLRcOKA CoZv4pNiI3Kq3WDTU/HA+lZSsp56zP2W16VSaGOgU0saEibVlfz4tvOF+GE0HHHNxYbr snvw== X-Gm-Message-State: AOAM5329K0FfP+m4HU7tx3jb0LOGo0xWmrXZyUoLIcD0cSK1FR1ma21L dtcYXyh/9BVhBQpoAfMExr5GCQ== X-Google-Smtp-Source: ABdhPJye9uoE8lM9qdQ85PwqQIVeAFlLuKjevIwDP1Nhkih9+NHBUgn/S+CAWbVadnjMg7MY4s3LVA== X-Received: by 2002:a17:90b:3551:: with SMTP id lt17mr26991167pjb.92.1620640309019; Mon, 10 May 2021 02:51:49 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 08/15] swiotlb: Bounce data from/to restricted DMA pool if available Date: Mon, 10 May 2021 17:50:19 +0800 Message-Id: <20210510095026.3477496-9-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" Regardless of swiotlb setting, the restricted DMA pool is preferred if available. The restricted DMA pools provide a basic level of protection against the DMA overwriting buffer contents at unexpected times. However, to protect against general data leakage and system memory corruption, the system needs to provide a way to lock down the memory access, e.g., MPU. Note that is_dev_swiotlb_force doesn't check if swiotlb_force =3D=3D SWIOTLB_FORCE. Otherwise the memory allocation behavior with default swiotlb will be changed by the following patche ("dma-direct: Allocate memory from restricted DMA pool if available"). Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 13 +++++++++++++ kernel/dma/direct.c | 3 ++- kernel/dma/direct.h | 3 ++- kernel/dma/swiotlb.c | 8 ++++---- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index c530c976d18b..0c5a18d9cf89 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -120,6 +120,15 @@ static inline bool is_swiotlb_buffer(struct device *de= v, phys_addr_t paddr) return mem && paddr >=3D mem->start && paddr < mem->end; } =20 +static inline bool is_dev_swiotlb_force(struct device *dev) +{ +#ifdef CONFIG_DMA_RESTRICTED_POOL + if (dev->dma_io_tlb_mem) + return true; +#endif /* CONFIG_DMA_RESTRICTED_POOL */ + return false; +} + void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); @@ -131,6 +140,10 @@ static inline bool is_swiotlb_buffer(struct device *de= v, phys_addr_t paddr) { return false; } +static inline bool is_dev_swiotlb_force(struct device *dev) +{ + return false; +} static inline void swiotlb_exit(void) { } diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 7a88c34d0867..078f7087e466 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -496,7 +496,8 @@ size_t dma_direct_max_mapping_size(struct device *dev) { /* If SWIOTLB is active, use its maximum mapping size */ if (is_swiotlb_active(dev) && - (dma_addressing_limited(dev) || swiotlb_force =3D=3D SWIOTLB_FORCE)) + (dma_addressing_limited(dev) || swiotlb_force =3D=3D SWIOTLB_FORCE || + is_dev_swiotlb_force(dev))) return swiotlb_max_mapping_size(dev); return SIZE_MAX; } diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h index 13e9e7158d94..f94813674e23 100644 --- a/kernel/dma/direct.h +++ b/kernel/dma/direct.h @@ -87,7 +87,8 @@ static inline dma_addr_t dma_direct_map_page(struct devic= e *dev, phys_addr_t phys =3D page_to_phys(page) + offset; dma_addr_t dma_addr =3D phys_to_dma(dev, phys); =20 - if (unlikely(swiotlb_force =3D=3D SWIOTLB_FORCE)) + if (unlikely(swiotlb_force =3D=3D SWIOTLB_FORCE) || + is_dev_swiotlb_force(dev)) return swiotlb_map(dev, phys, size, dir, attrs); =20 if (unlikely(!dma_capable(dev, dma_addr, size, true))) { diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 81bed3d2c771..3f1ad080a4bc 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -347,7 +347,7 @@ void __init swiotlb_exit(void) static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_= t size, enum dma_data_direction dir) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D get_io_tlb_mem(dev); int index =3D (tlb_addr - mem->start) >> IO_TLB_SHIFT; phys_addr_t orig_addr =3D mem->slots[index].orig_addr; size_t alloc_size =3D mem->slots[index].alloc_size; @@ -429,7 +429,7 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, = unsigned int index) static int find_slots(struct device *dev, phys_addr_t orig_addr, size_t alloc_size) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D get_io_tlb_mem(dev); unsigned long boundary_mask =3D dma_get_seg_boundary(dev); dma_addr_t tbl_dma_addr =3D phys_to_dma_unencrypted(dev, mem->start) & boundary_mask; @@ -506,7 +506,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, = phys_addr_t orig_addr, size_t mapping_size, size_t alloc_size, enum dma_data_direction dir, unsigned long attrs) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D get_io_tlb_mem(dev); unsigned int offset =3D swiotlb_align_offset(dev, orig_addr); unsigned int i; int index; @@ -557,7 +557,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phy= s_addr_t tlb_addr, size_t mapping_size, enum dma_data_direction dir, unsigned long attrs) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D get_io_tlb_mem(hwdev); unsigned long flags; unsigned int offset =3D swiotlb_align_offset(hwdev, tlb_addr); int index =3D (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT; --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640332; cv=none; d=zohomail.com; s=zohoarc; b=LBQFkJtUq3QpZHgttbtosOyheBwcS93IS5Sy89H9RRFsjLgQ45ROabW9ki0DMpQzRxoHxGk2LHMbDUk41IczvZSqh3PREeW4bowCFbms1okxz0Hty9rFgMNNCAHIZTb6fDvW5VU/W4lid2JY+7ZhmDbb/7AzJKx2nfFaCt3yrMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640332; 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=pTHCFxssIveqpuArSgW3Qj3cZNx2ZZwG3aJYd2ZEd8Y=; b=ePYaDT9hxy4zCu80svyuEKHI6Dz8C0yc/W52RXTSITA4gwTPMXJ+OtP/jsdOlxrvMt9JHUlCLZEPaqGgkbmo0jwAUyP+bHVmoK2e2wfKCWeSjsAblA7Cd5ZfgRbe6ly3/FHYB4QVklW4PW6FgFpVrqH5PODNZUg2E5YGeHc91so= 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 1620640332600966.979473968253; Mon, 10 May 2021 02:52:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125077.235510 (Exim 4.92) (envelope-from ) id 1lg2Zz-0002p3-Ue; Mon, 10 May 2021 09:51:59 +0000 Received: by outflank-mailman (output) from mailman id 125077.235510; Mon, 10 May 2021 09:51:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Zz-0002ou-Pn; Mon, 10 May 2021 09:51:59 +0000 Received: by outflank-mailman (input) for mailman id 125077; Mon, 10 May 2021 09:51:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2Zz-0002B1-9W for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:51:59 +0000 Received: from mail-pj1-x102f.google.com (unknown [2607:f8b0:4864:20::102f]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e7ead912-fb0f-4b56-ab79-c6d660e4883d; Mon, 10 May 2021 09:51:58 +0000 (UTC) Received: by mail-pj1-x102f.google.com with SMTP id g24so9442873pji.4 for ; Mon, 10 May 2021 02:51:58 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id l127sm10665077pfd.128.2021.05.10.02.51.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:51:57 -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: e7ead912-fb0f-4b56-ab79-c6d660e4883d 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=pTHCFxssIveqpuArSgW3Qj3cZNx2ZZwG3aJYd2ZEd8Y=; b=SU2CBBmY8DtSQd0TNZ7943oJOHoK8+TBS5VGCwhcrloaivVlt1fQYEyAF2Dc62+eQt UT9wdd13n+8GJAVW0U5UJTACdpxx/KKTBexY7stqKf1PPvqGXsqREXZG7XFlnC1R91bt 2OsKvp8oZwX6m5c1ltX1+1ihIJktkKBoMRuaA= 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=pTHCFxssIveqpuArSgW3Qj3cZNx2ZZwG3aJYd2ZEd8Y=; b=UHk08k8hga5nmNJ7NvCSyxdwRIB4l/ur7WivvI3zK314GUv6DSyxGmY6xaECbAb0FI vLmNfvLcIDuI1UxC88WX3Z9dfIFq00bFoZoNx4UdPg6ZApBYQcLli36OprLL2I+aF5qH JgsQ7nTOhwhGmI+qWGYu/un58uJRyG2BSj9Z4dmpgelyU1r3isYasbDj23AGwfqmFdWh EBvibmlil5Hb96WI0oLgULfUSAt9rYqiO9t0szU5hnz3W1026YFjhzG6tKOgKhEWJATb /K47XK+Eq05kEJZG5VFQua1w7x8eXtjc65LAHwWa/4isixQb6xNMc6QwnvqPdBVSSbm6 YpQw== X-Gm-Message-State: AOAM533LRHhzgjrfpZBQ4janeAyzqtk0PATFT02pwSQ7GgA6ggFO6aNT jJh1QOe2oBni+Ywz50XuIhg93Q== X-Google-Smtp-Source: ABdhPJyDFzChlNem0OEVDyj1b5MdL1myWQlCxWzTZ5O8kSwg2MCCOlZ4L1D63xzDiO05ddNXDCzncQ== X-Received: by 2002:a17:90a:d78c:: with SMTP id z12mr39367495pju.106.1620640317770; Mon, 10 May 2021 02:51:57 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 09/15] swiotlb: Move alloc_size to find_slots Date: Mon, 10 May 2021 17:50:20 +0800 Message-Id: <20210510095026.3477496-10-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" Move the maintenance of alloc_size to find_slots for better code reusability later. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 3f1ad080a4bc..ef04d8f7708f 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -482,8 +482,11 @@ static int find_slots(struct device *dev, phys_addr_t = orig_addr, return -1; =20 found: - for (i =3D index; i < index + nslots; i++) + for (i =3D index; i < index + nslots; i++) { mem->slots[i].list =3D 0; + mem->slots[i].alloc_size =3D + alloc_size - ((i - index) << IO_TLB_SHIFT); + } for (i =3D index - 1; io_tlb_offset(i) !=3D IO_TLB_SEGSIZE - 1 && mem->slots[i].list; i--) @@ -538,11 +541,8 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev,= phys_addr_t orig_addr, * This is needed when we sync the memory. Then we sync the buffer if * needed. */ - for (i =3D 0; i < nr_slots(alloc_size + offset); i++) { + for (i =3D 0; i < nr_slots(alloc_size + offset); i++) mem->slots[index + i].orig_addr =3D slot_addr(orig_addr, i); - mem->slots[index + i].alloc_size =3D - alloc_size - (i << IO_TLB_SHIFT); - } tlb_addr =3D slot_addr(mem->start, index) + offset; if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && (dir =3D=3D DMA_TO_DEVICE || dir =3D=3D DMA_BIDIRECTIONAL)) --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640341; cv=none; d=zohomail.com; s=zohoarc; b=fZQtcMjUDCz8JuitIIfIIaPk+JpqQxK4qW3JvCOcM9+AxEwXkRzT+t5b0EvvBYzlJkUlgp1RlFIkoiq8S4jCRZFdcNPCJyJIa0hBiLCrFxITc73S8/zHGZiOhgp0djbRCsQI3p/CR2M1xUtcFzKZo8n2R0is5G51DglJfnoxIY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640341; 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=4pOFRke/Q7tZST7mlvM0MmSbL4aoYUvXn+1GR7SUJ34=; b=AgWpBgz73m45WuNK3xvJF0KkhuA0R+LK4waEbGIcI0XHzFxMSGr0fPQNMzvplqeis3xB9INYwwiWLXcJ3Wc5oBlaEylJgOqiCiOVY1tN4YWy9Jdmm2tLwKqgmOa8ouS1yf+wrn4EZeOmRe5j4dI2MqUDX0+lWrSA83yH/6E/cdw= 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 1620640341969211.1493945630881; Mon, 10 May 2021 02:52:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125080.235522 (Exim 4.92) (envelope-from ) id 1lg2a9-0003R4-AO; Mon, 10 May 2021 09:52:09 +0000 Received: by outflank-mailman (output) from mailman id 125080.235522; Mon, 10 May 2021 09:52:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2a9-0003Qu-5G; Mon, 10 May 2021 09:52:09 +0000 Received: by outflank-mailman (input) for mailman id 125080; Mon, 10 May 2021 09:52:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2a7-0003O2-Sk for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:52:07 +0000 Received: from mail-pj1-x1034.google.com (unknown [2607:f8b0:4864:20::1034]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 88736481-0133-4310-a8dd-fa7765ece785; Mon, 10 May 2021 09:52:07 +0000 (UTC) Received: by mail-pj1-x1034.google.com with SMTP id gj14so9442872pjb.5 for ; Mon, 10 May 2021 02:52:07 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id q11sm11036253pjq.6.2021.05.10.02.51.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:52:06 -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: 88736481-0133-4310-a8dd-fa7765ece785 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=4pOFRke/Q7tZST7mlvM0MmSbL4aoYUvXn+1GR7SUJ34=; b=A7U0jjyTG8tgDp385jacEJGLNC4oL7IUZlzoTWyLzKk6RkDKUQ5v+SD+9WKkocmvjG LUaefVuL0kRQGj7dkHAfhhjPa4I0Jfm8PqMLbRTvg4D7h7o8M7PlgtpcXiQ1iqPHQ0aU +IJlZ9Uvbxgm75hG8lTxaMBiVB4c7B5X4T9+c= 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=4pOFRke/Q7tZST7mlvM0MmSbL4aoYUvXn+1GR7SUJ34=; b=kskkabmmiw8NU/38r00XbumD5NZ73T6Qw2DBOu73iHmp8QKw05hWk0yx8qzMm6bfWJ 8XMnudKbNwxUXY310F7a0gVG1KHSUGzFk6V58HoJl1BMNM0v42cBc1i9dClFxoly3jkn 4rmknm7aRPfK4OOgPa/2hu7F9viK9mMRLaVzlA+Ca1COxXmA7yH9WNHcrwPY1XqlFXly +3RC/g9kqvqoTQlO1O2LNNR/djLiiGfGjf1NqLW0SDVsQP7kg3gxMdKyhIQH4S24EeK5 adxs2mDflr9BvHgYHcY0b0+s7eEZ1AzLlnPhTIEa0hNLMUYWqdSU/SMG719vYKQKG61t 7vbg== X-Gm-Message-State: AOAM530qFwZB2fjIHbViI7IbUnkHS+wycQEfWZwvxcjZY05A082nDmvK tBPIJA9RWAIRB3nj1PWk8WeQsg== X-Google-Smtp-Source: ABdhPJyNhiNJqKO//YUtjfv5tp68csdaR9ELLg7UNG8ZjStHGvhbFTS+EdG5CKcr3bxZkctUA/Q/rQ== X-Received: by 2002:a17:90a:246:: with SMTP id t6mr27380633pje.228.1620640326419; Mon, 10 May 2021 02:52:06 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 10/15] swiotlb: Refactor swiotlb_tbl_unmap_single Date: Mon, 10 May 2021 17:50:21 +0800 Message-Id: <20210510095026.3477496-11-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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, release_slots, to make the code reusable for supporting different bounce buffer pools, e.g. restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index ef04d8f7708f..fa11787e4b95 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -550,27 +550,15 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev= , phys_addr_t orig_addr, return tlb_addr; } =20 -/* - * tlb_addr is the physical address of the bounce buffer to unmap. - */ -void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, - size_t mapping_size, enum dma_data_direction dir, - unsigned long attrs) +static void release_slots(struct device *dev, phys_addr_t tlb_addr) { - struct io_tlb_mem *mem =3D get_io_tlb_mem(hwdev); + struct io_tlb_mem *mem =3D get_io_tlb_mem(dev); unsigned long flags; - unsigned int offset =3D swiotlb_align_offset(hwdev, tlb_addr); + unsigned int offset =3D swiotlb_align_offset(dev, tlb_addr); int index =3D (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT; int nslots =3D nr_slots(mem->slots[index].alloc_size + offset); int count, i; =20 - /* - * First, sync the memory before unmapping the entry - */ - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && - (dir =3D=3D DMA_FROM_DEVICE || dir =3D=3D DMA_BIDIRECTIONAL)) - swiotlb_bounce(hwdev, tlb_addr, mapping_size, DMA_FROM_DEVICE); - /* * Return the buffer to the free list by setting the corresponding * entries to indicate the number of contiguous entries available. @@ -605,6 +593,23 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, ph= ys_addr_t tlb_addr, spin_unlock_irqrestore(&mem->lock, flags); } =20 +/* + * tlb_addr is the physical address of the bounce buffer to unmap. + */ +void swiotlb_tbl_unmap_single(struct device *dev, phys_addr_t tlb_addr, + size_t mapping_size, enum dma_data_direction dir, + unsigned long attrs) +{ + /* + * First, sync the memory before unmapping the entry + */ + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && + (dir =3D=3D DMA_FROM_DEVICE || dir =3D=3D DMA_BIDIRECTIONAL)) + swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_FROM_DEVICE); + + release_slots(dev, tlb_addr); +} + void swiotlb_sync_single_for_device(struct device *dev, phys_addr_t tlb_ad= dr, size_t size, enum dma_data_direction dir) { --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640349; cv=none; d=zohomail.com; s=zohoarc; b=nX52wIytxOkDDbRUwIj3UMD1QnFPkHu6da4stknHpI9q32audAnV2bxOJmNM+Rl8FaIMa/tWnK864IPRAW8+D8SpnMdIOmSmUi41i5iiIowlN1h8MWYlm7/J+rlssy1dDQ78NLUKbxTFbPDF+3FePoWYia7Ty7uTxzR8uJT8i/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640349; 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=t6SScDqP0X0FEaGwYViR1WRhEa6WWe5PW8l4/cNEd6s=; b=O8csep+wNW7RMvvpYI+cm7XK5MM6sJsA+J3K73Ucuus1GiKx9LGS/J08UNGtGvukrrwLsE76tqagSqtoN2t3iEKDgf7Fkd4N2xZiSNveFZ/H8QQcxcUi3VPvbN6SrdPFfnr2n3Nw6W3DP1lttSvUV45tlCFPSdOHhOJg2kigaPw= 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 1620640349217325.65139154369103; Mon, 10 May 2021 02:52:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125085.235534 (Exim 4.92) (envelope-from ) id 1lg2aH-00043a-IK; Mon, 10 May 2021 09:52:17 +0000 Received: by outflank-mailman (output) from mailman id 125085.235534; Mon, 10 May 2021 09:52:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2aH-00043P-FE; Mon, 10 May 2021 09:52:17 +0000 Received: by outflank-mailman (input) for mailman id 125085; Mon, 10 May 2021 09:52:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2aG-00040y-CP for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:52:16 +0000 Received: from mail-pf1-x429.google.com (unknown [2607:f8b0:4864:20::429]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dba3aafc-f0ea-43de-8bc7-4122807dadbf; Mon, 10 May 2021 09:52:15 +0000 (UTC) Received: by mail-pf1-x429.google.com with SMTP id c17so13247880pfn.6 for ; Mon, 10 May 2021 02:52:15 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id g2sm4121532pfj.218.2021.05.10.02.52.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:52:14 -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: dba3aafc-f0ea-43de-8bc7-4122807dadbf 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=t6SScDqP0X0FEaGwYViR1WRhEa6WWe5PW8l4/cNEd6s=; b=Np+mNLfnE5UH9v+sj7M7sXVpWmpJwNO1DnmfTEXXKWEeG5PclaliBfYf0J+kN7jfVA EwzmyQstbxUWNj9zGZGjDfvTwocid9N4ile+tbERZqEa6UZsUV+1sXylz+EEx90dcYpA QDp+I0oGFi86MOxid3sXnhVs4C0s/bcSV7YyE= 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=t6SScDqP0X0FEaGwYViR1WRhEa6WWe5PW8l4/cNEd6s=; b=kxjQWgJoucIKqnKnJR+8kAg8VtsFPC0Y/DufhbuRe8QVe1iF7y9GkdI+ecLmnGlyel +2/PH2oKZm+QC0IkEJefZbN+KaXU6UvKAI9xvmEy6A+ohfGFXdOVziJsaqwuMi18ALrK kZ4abwJYihQB88TuaU5rgVw7GjhwyOlzAlMClXF83eUgPVxktCsvFZFf6j6+U2BKrYn1 VztjTXQl5lNcVfXY5G9CWl5MhKMtvziuEFx2inVc9+9/V6JfQjVfMsEtUhkwxOv5GByj Pbwg8WVnmMUToGG/Y7IjR+5ZHXFA84YKMOc6k4vLluvtizs70vQZyKeQxVr/CbIJVmij xMCw== X-Gm-Message-State: AOAM530jkSrmpHxrFs16Ang7dQ+J24IEMY69TNp9UvoXgqHtKSQU+5dB Bho+gRlyZ7QPKPfBBcGgOraAQQ== X-Google-Smtp-Source: ABdhPJzTQch1UU+UQmd61gbcCZP+myc5F721Mj+utWhy5ilRUzzapDijoDqtK3NL+wBlztaE9YFArQ== X-Received: by 2002:a63:fc11:: with SMTP id j17mr20874729pgi.355.1620640335011; Mon, 10 May 2021 02:52:15 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 11/15] dma-direct: Add a new wrapper __dma_direct_free_pages() Date: Mon, 10 May 2021 17:50:22 +0800 Message-Id: <20210510095026.3477496-12-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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 wrapper __dma_direct_free_pages() that will be useful later for swiotlb_free(). Signed-off-by: Claire Chang --- kernel/dma/direct.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 078f7087e466..eb4098323bbc 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -75,6 +75,12 @@ static bool dma_coherent_ok(struct device *dev, phys_add= r_t phys, size_t size) min_not_zero(dev->coherent_dma_mask, dev->bus_dma_limit); } =20 +static void __dma_direct_free_pages(struct device *dev, struct page *page, + size_t size) +{ + dma_free_contiguous(dev, page, size); +} + static struct page *__dma_direct_alloc_pages(struct device *dev, size_t si= ze, gfp_t gfp) { @@ -237,7 +243,7 @@ void *dma_direct_alloc(struct device *dev, size_t size, return NULL; } out_free_pages: - dma_free_contiguous(dev, page, size); + __dma_direct_free_pages(dev, page, size); return NULL; } =20 @@ -273,7 +279,7 @@ void dma_direct_free(struct device *dev, size_t size, else if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED)) arch_dma_clear_uncached(cpu_addr, size); =20 - dma_free_contiguous(dev, dma_direct_to_page(dev, dma_addr), size); + __dma_direct_free_pages(dev, dma_direct_to_page(dev, dma_addr), size); } =20 struct page *dma_direct_alloc_pages(struct device *dev, size_t size, @@ -310,7 +316,7 @@ struct page *dma_direct_alloc_pages(struct device *dev,= size_t size, *dma_handle =3D phys_to_dma_direct(dev, page_to_phys(page)); return page; out_free_pages: - dma_free_contiguous(dev, page, size); + __dma_direct_free_pages(dev, page, size); return NULL; } =20 @@ -329,7 +335,7 @@ void dma_direct_free_pages(struct device *dev, size_t s= ize, if (force_dma_unencrypted(dev)) set_memory_encrypted((unsigned long)vaddr, 1 << page_order); =20 - dma_free_contiguous(dev, page, size); + __dma_direct_free_pages(dev, page, size); } =20 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640358; cv=none; d=zohomail.com; s=zohoarc; b=hWiII4B4j/NiKFH++wuD+myXWKUDeF1LXMRDjwj7kbQO1nA7g81SWah/VPKZzQ8EA6a5Ahu3d7xYt4YDo2neyaOQeo1DytOV+qXn1rxqBUEPSwtOPD9gGCwYkrEiIzNRI/JLdVTQI9oZ4fQDHpbQ6CbkNYZZuoqnEnP74BREI8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640358; 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=3YaoLVJ/BlS2jGrFuaf+HAqZru6rV2ab/VHFDnxpz5s=; b=gnB1ZKpdAR/dXHZ7Eh3K0GwzUpoQDVtwLdavyqK39SmKP70Vc0Ai/n2Jdrrz1BizEXYxELYSK5rAKe3BaJfS9XqeIbU/Se4Aswi1CbyccMcWNW1IAVEA3m/SWk9UEuJHG++Hh1R57y2IEP2xiTZzhCjy3DVMCu+/B6b3MQLqCXk= 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 1620640358405689.3706590818757; Mon, 10 May 2021 02:52:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125089.235546 (Exim 4.92) (envelope-from ) id 1lg2aP-0004dv-SE; Mon, 10 May 2021 09:52:25 +0000 Received: by outflank-mailman (output) from mailman id 125089.235546; Mon, 10 May 2021 09:52:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2aP-0004dg-Ou; Mon, 10 May 2021 09:52:25 +0000 Received: by outflank-mailman (input) for mailman id 125089; Mon, 10 May 2021 09:52:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2aP-0004bT-3d for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:52:25 +0000 Received: from mail-pl1-x62b.google.com (unknown [2607:f8b0:4864:20::62b]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f1a4f09b-a12b-4939-8f69-9d6128ba80a4; Mon, 10 May 2021 09:52:24 +0000 (UTC) Received: by mail-pl1-x62b.google.com with SMTP id n16so8860989plf.7 for ; Mon, 10 May 2021 02:52:24 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id f6sm10227287pfe.74.2021.05.10.02.52.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:52:23 -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: f1a4f09b-a12b-4939-8f69-9d6128ba80a4 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=3YaoLVJ/BlS2jGrFuaf+HAqZru6rV2ab/VHFDnxpz5s=; b=I10YUhrVFYEnBb151sjznBCAywSiwwuXX1ra65r+6Dp7kLXlkJTjZj64MC39DrflfN L6B6coAmKhXT3uzYOIMy3hHP2AqrBakoEoGo6H/hyImCZ+Vs9dEj0AdH5ph0QtkKY+Bg SjBGhbtFT0tOcMKvv+2FyMSaO8PoMl7ClMI8s= 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=3YaoLVJ/BlS2jGrFuaf+HAqZru6rV2ab/VHFDnxpz5s=; b=FoO2R8++42yVAfcdx2QNNhUzxNPEjSup10L064MRyPl794OWeI+uGWf3f4vikhPeiE tloW8gqVHLO2Y5UvsVOsrBbXQMLbvMo3s1U6uu9PXKYyGFQzZ+AepEamAaicfi9VaVwQ L3uKjCqAYeuyqZVvXBsJjjFtLlD65IhelcjJXR+vscIK0zIRdOXnSqgQPatX2au5wBaj tPwcJufFPZMSYnb+21ZnZx4RYhsyTiTLjbm5Eb89bnnvIqxHFxG/jD12mbh1i4EFKdUh L/hn7Rmj3Ct6jiVqWE3lNP4wdjGtnLe58QjdhDVVjFnM/kPDDBhl8lrl+54TJFd9EXqz Tzfg== X-Gm-Message-State: AOAM530kah28iH2rdaYfQu9WijEt894fMyGQrfh47tz8YLssLGKhDjYC 4xtKlcEyepzflozfAfouGhMFRQ== X-Google-Smtp-Source: ABdhPJyvBg/0ILrSmUeqEzW7Fk7bklgK3teEOUZ3TKSkxe3vq+G4eTcWybVNarpL8KZA9dCjKF/+aQ== X-Received: by 2002:a17:90a:246:: with SMTP id t6mr27381833pje.228.1620640343682; Mon, 10 May 2021 02:52:23 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 12/15] swiotlb: Add restricted DMA alloc/free support. Date: Mon, 10 May 2021 17:50:23 +0800 Message-Id: <20210510095026.3477496-13-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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 the functions, swiotlb_{alloc,free} to support the memory allocation from restricted DMA pool. Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 4 ++++ kernel/dma/swiotlb.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 0c5a18d9cf89..e8cf49bd90c5 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -134,6 +134,10 @@ unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); bool is_swiotlb_active(struct device *dev); void __init swiotlb_adjust_size(unsigned long size); +#ifdef CONFIG_DMA_RESTRICTED_POOL +struct page *swiotlb_alloc(struct device *dev, size_t size); +bool swiotlb_free(struct device *dev, struct page *page, size_t size); +#endif /* CONFIG_DMA_RESTRICTED_POOL */ #else #define swiotlb_force SWIOTLB_NO_FORCE static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index fa11787e4b95..d99d5f902259 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -457,8 +457,9 @@ static int find_slots(struct device *dev, phys_addr_t o= rig_addr, =20 index =3D wrap =3D wrap_index(mem, ALIGN(mem->index, stride)); do { - if ((slot_addr(tbl_dma_addr, index) & iotlb_align_mask) !=3D - (orig_addr & iotlb_align_mask)) { + if (orig_addr && + (slot_addr(tbl_dma_addr, index) & iotlb_align_mask) !=3D + (orig_addr & iotlb_align_mask)) { index =3D wrap_index(mem, index + 1); continue; } @@ -701,6 +702,36 @@ late_initcall(swiotlb_create_default_debugfs); #endif =20 #ifdef CONFIG_DMA_RESTRICTED_POOL +struct page *swiotlb_alloc(struct device *dev, size_t size) +{ + struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; + phys_addr_t tlb_addr; + int index; + + if (!mem) + return NULL; + + index =3D find_slots(dev, 0, size); + if (index =3D=3D -1) + return NULL; + + tlb_addr =3D slot_addr(mem->start, index); + + return pfn_to_page(PFN_DOWN(tlb_addr)); +} + +bool swiotlb_free(struct device *dev, struct page *page, size_t size) +{ + phys_addr_t tlb_addr =3D page_to_phys(page); + + if (!is_swiotlb_buffer(dev, tlb_addr)) + return false; + + release_slots(dev, tlb_addr); + + return true; +} + static int rmem_swiotlb_device_init(struct reserved_mem *rmem, struct device *dev) { --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640366; cv=none; d=zohomail.com; s=zohoarc; b=YHC1mK6DK1ovCIHlWgNEGyjWZNBPou/wPtC4uQVs//BkmcDSSRHryht9mM37o5QhdssgTY0QSNHAAAM6SM1gC/+QBbn+35aymWlZwu3PVniqTWLAaCuEnJf0YM4CbM+gOb12b197YET2uHZtSgtTZ0SXVM75gEKxM9YPYoVBMc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640366; 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=fO4/BDgOqSIweTkVlBXlAFU55A/tHyh8EFQ3OCJ0164=; b=EOQUNUevuk/Yu5fiTLh0u2piYG/UOlBLWqYO4htjanS45PLjCvVlJ69kypHMfDEBn5Pw+wAEafs1zBC/9E5HKvA9LauUIOz0zCtCU6/Zc+yNAfcyXhF+098YBUV2at2w13C/XKPHGC1PLtHRrT5TsqKLz/Stab1VZlhDgHmmtKU= 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 1620640366717757.5610285985276; Mon, 10 May 2021 02:52:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125092.235558 (Exim 4.92) (envelope-from ) id 1lg2aZ-0005Hs-6g; Mon, 10 May 2021 09:52:35 +0000 Received: by outflank-mailman (output) from mailman id 125092.235558; Mon, 10 May 2021 09:52:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2aZ-0005Hf-2d; Mon, 10 May 2021 09:52:35 +0000 Received: by outflank-mailman (input) for mailman id 125092; Mon, 10 May 2021 09:52:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2aX-0005Eb-UA for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:52:33 +0000 Received: from mail-pl1-x629.google.com (unknown [2607:f8b0:4864:20::629]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1ac1168f-723a-4f39-b21b-0f436917dd91; Mon, 10 May 2021 09:52:32 +0000 (UTC) Received: by mail-pl1-x629.google.com with SMTP id t21so8875742plo.2 for ; Mon, 10 May 2021 02:52:32 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id 15sm10199759pjt.17.2021.05.10.02.52.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:52:31 -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: 1ac1168f-723a-4f39-b21b-0f436917dd91 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=fO4/BDgOqSIweTkVlBXlAFU55A/tHyh8EFQ3OCJ0164=; b=a/WuPnT5SWKEIKaQCzsTYV8esrJXULCD+Pttku/Hjp9UGsEHrBcpr4K60CJSleWPaJ Cs+rhFZCjeyPwMUFq4cNS3B54eAb1lfhIoXu9ETsYSgcWLTxNsI5jc7/9Z5SKKogzIJd OHxCjg4x9FxeJXA4ZyVgnBWzyFvoWoATrwxIg= 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=fO4/BDgOqSIweTkVlBXlAFU55A/tHyh8EFQ3OCJ0164=; b=e3o3oQYnoujER6hfGXhnhsZzO93RSmWgmD9MFa9q74s58bCctrLEODmDM7kRZn7EAE uF3EYgCk2Ej6Ra+asvxPgNcSon9kEur+vkW74X9cDNvJ8teHwdCwosKkV/Qz1jd4mZ6H cBSPH1vEcQ4QOXiH7VtuxVmKa4Rna6zw6j84p4KhetZlPKlggKwmFyOclMwcjkv6Ssgc e9UMbKfSNQ61R1Ubbdv1huhj6izK2t08KfnEVD19f6wGJ3k+5SACLnteyG8af4ZydsB4 wGlSlHvHhEtYFX5VJSoF83ddosG6cAjK3omKIzwDZigXhoG1CL4qDnO7BVwg6tsCMVYF 6muw== X-Gm-Message-State: AOAM531JIbT2vDj56OJh07vPDRUwDgYNwLas1ZmgyRyATJHAlah0hqmo rDw9eAY3AiUQiEC7IvSLv/mbCg== X-Google-Smtp-Source: ABdhPJwxBoZD0WeI9zQ0gddyfu3vgr7xM+940pwyPaN5j/qpuJotOQIMQPfObl9zFPGpUQ2nKcqGBw== X-Received: by 2002:a17:90a:1d44:: with SMTP id u4mr40914071pju.46.1620640352294; Mon, 10 May 2021 02:52:32 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 13/15] dma-direct: Allocate memory from restricted DMA pool if available Date: Mon, 10 May 2021 17:50:24 +0800 Message-Id: <20210510095026.3477496-14-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" The restricted DMA pool is preferred if available. The restricted DMA pools provide a basic level of protection against the DMA overwriting buffer contents at unexpected times. However, to protect against general data leakage and system memory corruption, the system needs to provide a way to lock down the memory access, e.g., MPU. Note that since coherent allocation needs remapping, one must set up another device coherent pool by shared-dma-pool and use dma_alloc_from_dev_coherent instead for atomic coherent allocation. Signed-off-by: Claire Chang --- kernel/dma/direct.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index eb4098323bbc..0d521f78c7b9 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -78,6 +78,10 @@ static bool dma_coherent_ok(struct device *dev, phys_add= r_t phys, size_t size) static void __dma_direct_free_pages(struct device *dev, struct page *page, size_t size) { +#ifdef CONFIG_DMA_RESTRICTED_POOL + if (swiotlb_free(dev, page, size)) + return; +#endif dma_free_contiguous(dev, page, size); } =20 @@ -92,7 +96,17 @@ static struct page *__dma_direct_alloc_pages(struct devi= ce *dev, size_t size, =20 gfp |=3D dma_direct_optimal_gfp_mask(dev, dev->coherent_dma_mask, &phys_limit); - page =3D dma_alloc_contiguous(dev, size, gfp); + +#ifdef CONFIG_DMA_RESTRICTED_POOL + page =3D swiotlb_alloc(dev, size); + if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) { + __dma_direct_free_pages(dev, page, size); + page =3D NULL; + } +#endif + + if (!page) + page =3D dma_alloc_contiguous(dev, size, gfp); if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) { dma_free_contiguous(dev, page, size); page =3D NULL; @@ -148,7 +162,7 @@ void *dma_direct_alloc(struct device *dev, size_t size, gfp |=3D __GFP_NOWARN; =20 if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) && - !force_dma_unencrypted(dev)) { + !force_dma_unencrypted(dev) && !is_dev_swiotlb_force(dev)) { page =3D __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO); if (!page) return NULL; @@ -161,18 +175,23 @@ void *dma_direct_alloc(struct device *dev, size_t siz= e, } =20 if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) && - !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && - !dev_is_dma_coherent(dev)) + !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && !dev_is_dma_coherent(dev) && + !is_dev_swiotlb_force(dev)) return arch_dma_alloc(dev, size, dma_handle, gfp, attrs); =20 /* * Remapping or decrypting memory may block. If either is required and * we can't block, allocate the memory from the atomic pools. + * If restricted DMA (i.e., is_dev_swiotlb_force) is required, one must + * set up another device coherent pool by shared-dma-pool and use + * dma_alloc_from_dev_coherent instead. */ if (IS_ENABLED(CONFIG_DMA_COHERENT_POOL) && !gfpflags_allow_blocking(gfp) && (force_dma_unencrypted(dev) || - (IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && !dev_is_dma_coherent(dev)))) + (IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && + !dev_is_dma_coherent(dev))) && + !is_dev_swiotlb_force(dev)) return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp); =20 /* we always manually zero the memory once we are done */ @@ -253,15 +272,15 @@ void dma_direct_free(struct device *dev, size_t size, unsigned int page_order =3D get_order(size); =20 if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) && - !force_dma_unencrypted(dev)) { + !force_dma_unencrypted(dev) && !is_dev_swiotlb_force(dev)) { /* cpu_addr is a struct page cookie, not a kernel address */ dma_free_contiguous(dev, cpu_addr, size); return; } =20 if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED) && - !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && - !dev_is_dma_coherent(dev)) { + !IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && !dev_is_dma_coherent(dev) && + !is_dev_swiotlb_force(dev)) { arch_dma_free(dev, size, cpu_addr, dma_addr, attrs); return; } @@ -289,7 +308,8 @@ struct page *dma_direct_alloc_pages(struct device *dev,= size_t size, void *ret; =20 if (IS_ENABLED(CONFIG_DMA_COHERENT_POOL) && - force_dma_unencrypted(dev) && !gfpflags_allow_blocking(gfp)) + force_dma_unencrypted(dev) && !gfpflags_allow_blocking(gfp) && + !is_dev_swiotlb_force(dev)) return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp); =20 page =3D __dma_direct_alloc_pages(dev, size, gfp); --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640376; cv=none; d=zohomail.com; s=zohoarc; b=X4mINF5hDQ3ikEW83iCqAqwV0FhJHKZAowejCEyYTbc/2+bqEUa/1+3wSuL/8lb0cyBhAjv7pEkNSSWvMDFcp/ahjHMDlFmQ7rHc5jYtFg3pyZK+/954WRF17FdkV1VarS6687AeZvQ4RWaF7wFSo+yEEh0UOjXXvYclqcC1ZAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640376; 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=TI//+rWs2AonD6qoX7ur8OGwRk/rsyDr2ocu0NzNq5I=; b=MaMpQWfTwrWODdNvOu4XTl441fJDRB8jNZfAl2LHoiKmdgj1JHRPPgC2TW6E+7jPaIW7WZay0mWJJhV3AHjG/JO6zUgFQxPAjKWxBVyFWE5El2gA37fVK30Z7E1JGSp2K1SF9fB+t5CWH8RnEdTVMdHR33PFHtsrSsAlZaa4Yeo= 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 1620640376897115.45212767894157; Mon, 10 May 2021 02:52:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125095.235569 (Exim 4.92) (envelope-from ) id 1lg2ah-0005tM-KR; Mon, 10 May 2021 09:52:43 +0000 Received: by outflank-mailman (output) from mailman id 125095.235569; Mon, 10 May 2021 09:52:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ah-0005tD-H0; Mon, 10 May 2021 09:52:43 +0000 Received: by outflank-mailman (input) for mailman id 125095; Mon, 10 May 2021 09:52:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ag-0005qZ-FR for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:52:42 +0000 Received: from mail-pf1-x42d.google.com (unknown [2607:f8b0:4864:20::42d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3a018552-59ae-463f-bc29-60b1673a8e23; Mon, 10 May 2021 09:52:41 +0000 (UTC) Received: by mail-pf1-x42d.google.com with SMTP id h127so13224588pfe.9 for ; Mon, 10 May 2021 02:52:41 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id q7sm9111446pfq.172.2021.05.10.02.52.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:52:40 -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: 3a018552-59ae-463f-bc29-60b1673a8e23 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=TI//+rWs2AonD6qoX7ur8OGwRk/rsyDr2ocu0NzNq5I=; b=OeemdSgPmia6P5EsXKkEzN0OL4fVLwcXTd/CieenRMdBKHxFqUP4Df4joJbySWSSMc NQa62kYUP6NBQhMfe69O4Y1TVNyiYjME1kHrojL7NiW2Og6QvxSOkeGdpSahkdmKkkLI olHy6atIMBhauJm3Bf+RxBbMLkFko3Ac9JTU8= 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=TI//+rWs2AonD6qoX7ur8OGwRk/rsyDr2ocu0NzNq5I=; b=VPqEiaFCZ8Iod4Kt7G0A1u2pn69ahRvSOISRAscmaM5gLOipBL7LOcbHpf/9A21z70 B54BUN6AK/DDsJ2Qg+dH0lvyaIrGxbJx/5N9mFDgoVYaeSnHzwmQJ1GMa9++BZH3vayK sLN0tMUUuqNnDFSfRXoMORm+i9WtILQr+FyHFXDqLdL/tYK6oPiBKbvJ5OJ/AONmfHUg hA8MSvtSSfXEaZEU3K0H4gEuE8MGn0On7aBeS2PmsN8nRw75iGRcvpz6z6lNt4llT9PO l3aH+0X4yRjSK56yEmQTNdg+6YRMPDQlFCx0NRZ8x+hRVUYElQnOMuFvsNe4ZdqYs6aI jp1Q== X-Gm-Message-State: AOAM533qEDVjDpdbt6fsXab6PWe264jUjeL41hcbWzTeh7WPGTxcGUZ7 JcH8lAI5WfrnoimWGOgqP/k0pw== X-Google-Smtp-Source: ABdhPJx3NolYg0tYgQE7hrG22fSVZg4paXFqQrFAkVZpowUqVebMyfoHJdLoW9aBQ5hSJPVDYKavFA== X-Received: by 2002:a63:5160:: with SMTP id r32mr23960989pgl.83.1620640360984; Mon, 10 May 2021 02:52:40 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 14/15] dt-bindings: of: Add restricted DMA pool Date: Mon, 10 May 2021 17:50:25 +0800 Message-Id: <20210510095026.3477496-15-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" Introduce the new compatible string, restricted-dma-pool, for restricted DMA. One can specify the address and length of the restricted DMA memory region by restricted-dma-pool in the reserved-memory node. Signed-off-by: Claire Chang --- .../reserved-memory/reserved-memory.txt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Documentation/devicetree/bindings/reserved-memory/reserved-mem= ory.txt b/Documentation/devicetree/bindings/reserved-memory/reserved-memory= .txt index e8d3096d922c..284aea659015 100644 --- a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt +++ b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt @@ -51,6 +51,23 @@ compatible (optional) - standard definition used as a shared pool of DMA buffers for a set of devices. It can be used by an operating system to instantiate the necessary pool management subsystem if necessary. + - restricted-dma-pool: This indicates a region of memory meant to = be + used as a pool of restricted DMA buffers for a set of devices. T= he + memory region would be the only region accessible to those devic= es. + When using this, the no-map and reusable properties must not be = set, + so the operating system can create a virtual mapping that will b= e used + for synchronization. The main purpose for restricted DMA is to + mitigate the lack of DMA access control on systems without an IO= MMU, + which could result in the DMA accessing the system memory at + unexpected times and/or unexpected addresses, possibly leading t= o data + leakage or corruption. The feature on its own provides a basic l= evel + of protection against the DMA overwriting buffer contents at + unexpected times. However, to protect against general data leaka= ge and + system memory corruption, the system needs to provide way to loc= k down + the memory access, e.g., MPU. Note that since coherent allocation + needs remapping, one must set up another device coherent pool by + shared-dma-pool and use dma_alloc_from_dev_coherent instead for = atomic + coherent allocation. - vendor specific string in the form ,[-] no-map (optional) - empty property - Indicates the operating system must not create a virtual mapping @@ -120,6 +137,11 @@ one for multimedia processing (named multimedia-memory= @77000000, 64MiB). compatible =3D "acme,multimedia-memory"; reg =3D <0x77000000 0x4000000>; }; + + restricted_dma_mem_reserved: restricted_dma_mem_reserved { + compatible =3D "restricted-dma-pool"; + reg =3D <0x50000000 0x400000>; + }; }; =20 /* ... */ @@ -138,4 +160,9 @@ one for multimedia processing (named multimedia-memory@= 77000000, 64MiB). memory-region =3D <&multimedia_reserved>; /* ... */ }; + + pcie_device: pcie_device@0,0 { + memory-region =3D <&restricted_dma_mem_reserved>; + /* ... */ + }; }; --=20 2.31.1.607.g51e8a6a459-goog From nobody Fri Nov 29 22:33:19 2024 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=1620640385; cv=none; d=zohomail.com; s=zohoarc; b=G0HZuikW8gIoJSmOvmVBJDP1pmuX2rGvi6BkbNLWGOOEObdrbSNkhuHJ0w+4C+RnrB2f+lt1eOUMsq4Kp7+5Lu0O/AchRybkPw7wZzLOy02SgLKFuiGorw8hZ+ns9oUHWg8D6eR2a8Uz8hxLQX/fzBv6Q5GEX+wxYYiDpmxXjSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620640385; 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=N9YtEc1AKRWzrvXmeOPdeOSLAm21S21YZtTJBnrwUb8=; b=Taih3Ll/8mYnHukXJVD/duHr6MfL1Oh1hZWXxlsCTXYElqEVuFTSoTxRSeiFnece3NbQjJK5fAqzmL+A7x/2xa289PnAxRsmfKGjDUojQkcoFDySOEqWdNoUDwie+V6CDmeBBbZfSzcrqeeK2jnR5MCqxoGNqbvdjSTwX1twIs8= 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 1620640385622106.49763006167188; Mon, 10 May 2021 02:53:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125099.235582 (Exim 4.92) (envelope-from ) id 1lg2ar-0006XU-VH; Mon, 10 May 2021 09:52:53 +0000 Received: by outflank-mailman (output) from mailman id 125099.235582; Mon, 10 May 2021 09:52:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2ar-0006XH-RY; Mon, 10 May 2021 09:52:53 +0000 Received: by outflank-mailman (input) for mailman id 125099; Mon, 10 May 2021 09:52:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg2aq-0006Ri-DW for xen-devel@lists.xenproject.org; Mon, 10 May 2021 09:52:52 +0000 Received: from mail-pg1-x52a.google.com (unknown [2607:f8b0:4864:20::52a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a01bc71d-4107-47c7-8ccd-60c6c51a265c; Mon, 10 May 2021 09:52:50 +0000 (UTC) Received: by mail-pg1-x52a.google.com with SMTP id y32so12888901pga.11 for ; Mon, 10 May 2021 02:52:50 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:a524:abe8:94e3:5601]) by smtp.gmail.com with UTF8SMTPSA id k9sm4190684pgq.27.2021.05.10.02.52.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 May 2021 02:52:49 -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: a01bc71d-4107-47c7-8ccd-60c6c51a265c 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=N9YtEc1AKRWzrvXmeOPdeOSLAm21S21YZtTJBnrwUb8=; b=K1N6EXk85Wvc+hEOva4wXm/pG0LlShcwRNR1nzYaMJRORgqDZTx8d0OHgKA7EZWdW9 DKVvH5XQc7hrxaIcoiPBWcXqLtVTb0ShzjIeG4+8nxjarb1dd1TCqieDYri51cXF3WJ3 rTKZnoW2Yosw5eCi0THzxANV5pwO1EvAdcAaY= 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=N9YtEc1AKRWzrvXmeOPdeOSLAm21S21YZtTJBnrwUb8=; b=UWew6G+VAUU+Fj8ZU8P+u1pjluqMmqRDEFabknrP/tzzXK30i1YrRJWE6El3SRyB3j cwBgEajHtQOe8E8ZtZYjFm6YLOoCdMcCH1imqNfB2gNOdrl4xSYSINw1DOt36tN24v1t xJKrl8WjicoWE5JtY6BZxic5isYEGmsVhQsz29XErvBycJPwmGY19bW6XKdbkPsst/U5 fMpcDm6f6ITSw7Kq1HY5wX4aR5tO/6fSqqT5ReudoezBat4LWQOfKdhYJW5PzhdzJN/e oQdshOEL8fRDZBvbgPbfiq6VV6z7qMYNWLgW4aJOTr8d73udunvvospKX9APrdci1Urz a7Zw== X-Gm-Message-State: AOAM532JiPZ3JXS7zzAl+TzZGXCN0e6ZVu4iMClDXWYNWGm+rUWi5zhy e583gISS7oWwG1LJmMPTORkTNw== X-Google-Smtp-Source: ABdhPJx4HfAA4wpH8/Kt4ymLNpegRYw4Z9ZhxTLF9qKqtTWcfssB+nzDFXYh+57Un66kEi/PTJPfag== X-Received: by 2002:a62:28b:0:b029:28e:e592:fe65 with SMTP id 133-20020a62028b0000b029028ee592fe65mr23864386pfc.75.1620640369611; Mon, 10 May 2021 02:52:49 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 v6 15/15] of: Add plumbing for restricted DMA pool Date: Mon, 10 May 2021 17:50:26 +0800 Message-Id: <20210510095026.3477496-16-tientzu@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210510095026.3477496-1-tientzu@chromium.org> References: <20210510095026.3477496-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" If a device is not behind an IOMMU, we look up the device node and set up the restricted DMA when the restricted-dma-pool is presented. Signed-off-by: Claire Chang --- drivers/of/address.c | 25 +++++++++++++++++++++++++ drivers/of/device.c | 3 +++ drivers/of/of_private.h | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index aca94c348bd4..c562a9ff5f0b 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1112,6 +1113,30 @@ bool of_dma_is_coherent(struct device_node *np) } EXPORT_SYMBOL_GPL(of_dma_is_coherent); =20 +int of_dma_set_restricted_buffer(struct device *dev) +{ + struct device_node *node; + int count, i; + + if (!dev->of_node) + return 0; + + count =3D of_property_count_elems_of_size(dev->of_node, "memory-region", + sizeof(phandle)); + for (i =3D 0; i < count; i++) { + node =3D of_parse_phandle(dev->of_node, "memory-region", i); + /* There might be multiple memory regions, but only one + * restriced-dma-pool region is allowed. + */ + if (of_device_is_compatible(node, "restricted-dma-pool") && + of_device_is_available(node)) + return of_reserved_mem_device_init_by_idx( + dev, dev->of_node, i); + } + + return 0; +} + /** * of_mmio_is_nonposted - Check if device uses non-posted MMIO * @np: device node diff --git a/drivers/of/device.c b/drivers/of/device.c index c5a9473a5fb1..d8d865223e51 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct devi= ce_node *np, =20 arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); =20 + if (!iommu) + return of_dma_set_restricted_buffer(dev); + return 0; } EXPORT_SYMBOL_GPL(of_dma_configure_id); diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index d717efbd637d..e9237f5eff48 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -163,12 +163,17 @@ struct bus_dma_region; #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA) int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map); +int of_dma_set_restricted_buffer(struct device *dev); #else static inline int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) { return -ENODEV; } +static inline int of_dma_get_restricted_buffer(struct device *dev) +{ + return -ENODEV; +} #endif =20 #endif /* _LINUX_OF_PRIVATE_H */ --=20 2.31.1.607.g51e8a6a459-goog