From nobody Mon Apr 29 13:54:26 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=1624550176; cv=none; d=zohomail.com; s=zohoarc; b=YLuL3KB0A0JscC88WmlVCFathc+3z0SNcIhijfGbs9u/KUaoG1FHdI6JGgwEDAos90dkkvUOWyTQlIy4bO1sI6+sv4nZC2eDJ5EL6dEPbCFXOl7+N48hWGhActJzZsTbgTvWeWR+3gwwDBI1gSY0/zB0iA1nBJX4KoUHa4WwGNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550176; 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=YJFR7rMJgjSCjddzLV99+gcsv72cCY4rcuJfLx7ix2M=; b=gVyZxViI5xH1dUBbf5raXt9zCgcax0JiNZ/0fAOAiZl+7k8YvM6mCd062jMMyU8dB3flr/Cdv5BrLaJut3FHgd7bl2iK1Y6TUUmUWR1ryHsJxNHYeW69RnPAPeH0qY2Umey/MdV7vZpUmUKh8fwP0emTBxVPOnL56wQ/vUelllo= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550176149553.6959003890242; Thu, 24 Jun 2021 08:56:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146892.270458 (Exim 4.92) (envelope-from ) id 1lwRhm-000849-Mp; Thu, 24 Jun 2021 15:55:50 +0000 Received: by outflank-mailman (output) from mailman id 146892.270458; Thu, 24 Jun 2021 15:55:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRhm-000840-IT; Thu, 24 Jun 2021 15:55:50 +0000 Received: by outflank-mailman (input) for mailman id 146892; Thu, 24 Jun 2021 15:55: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 1lwRhl-00083W-2v for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:55:49 +0000 Received: from mail-pf1-x42e.google.com (unknown [2607:f8b0:4864:20::42e]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3bf28517-40d5-4d76-aa28-41823a864d62; Thu, 24 Jun 2021 15:55:48 +0000 (UTC) Received: by mail-pf1-x42e.google.com with SMTP id c5so5535501pfv.8 for ; Thu, 24 Jun 2021 08:55:48 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id f12sm3216544pfc.100.2021.06.24.08.55.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:55: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: 3bf28517-40d5-4d76-aa28-41823a864d62 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=YJFR7rMJgjSCjddzLV99+gcsv72cCY4rcuJfLx7ix2M=; b=IZ8zEMilmar/QDVLgl1NDX/TTwxyjXxS5kA1fSnBE6n5IfzENsPcNaND27UjFp5jiN u8HH6B7JIXK5EX6f67y7l9dDoZ++rPB0nrtDbiVwhfF52n//6y1BzEqiBhQhAh+kBIK8 UMPl2mPih9xqS2jFSSaq+Fm8SSizc0d0wP3VY= 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=YJFR7rMJgjSCjddzLV99+gcsv72cCY4rcuJfLx7ix2M=; b=eT5hIB2VemRRKa2tisFQNpxyE8brda5Bj2VENk2buUQl3i2tqEWyfm8IFR+/la0gQ1 JYpZop3AieY3c2BCsuoe/WZw/awEeQgzOVZF2DzqyC+giKKB4UzvLXHYU+G+4tyZ7Rpo 4L1MmtNVKVYQBo95p/euk9zu867aYW3KD/98e+NGMTbayHZZG5P6IVnsZ/xbz3vgNPDf 4IgMGXCI9pWX8WoPGq3zMBarH69Mo/cSH/CYiYAx4m7D8uV3ekyW71QqA2l4gjT7TdvK Mhwy8LCq/l0v0OYQ0pqShNck6XnU69cDdjVneTOsfiwifTk6vU71gltYCcvw163fgK6I CJcQ== X-Gm-Message-State: AOAM531YJ7I85kkBHCwZ2sJBcyBpephRh0plL6x45pBsSesM2zcuhPW0 UpZQaCGpMh2u9Bf2wjqlg6uWrA== X-Google-Smtp-Source: ABdhPJz6AmQg2p36DPOtVtB4TSDM/glgE/K0cXRSpLrBRHDSDkrUzfxWqUOOjFBiYq3vGkkuKVesgQ== X-Received: by 2002:a63:d908:: with SMTP id r8mr5249237pgg.414.1624550147592; Thu, 24 Jun 2021 08:55:47 -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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 01/12] swiotlb: Refactor swiotlb init functions Date: Thu, 24 Jun 2021 23:55:15 +0800 Message-Id: <20210624155526.2775863-2-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon Acked-by: Stefano Stabellini --- kernel/dma/swiotlb.c | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 52e2ac526757..1f9b2b9e7490 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -168,9 +168,28 @@ 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; + } + 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 +205,8 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned l= ong nslabs, int verbose) if (!mem) panic("%s: Failed to allocate %zu bytes align=3D0x%lx\n", __func__, alloc_size, PAGE_SIZE); - mem->nslabs =3D nslabs; - mem->start =3D __pa(tlb); - mem->end =3D mem->start + bytes; - mem->index =3D 0; - spin_lock_init(&mem->lock); - for (i =3D 0; i < mem->nslabs; i++) { - mem->slots[i].list =3D IO_TLB_SEGSIZE - io_tlb_offset(i); - mem->slots[i].orig_addr =3D INVALID_PHYS_ADDR; - mem->slots[i].alloc_size =3D 0; - } + + swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false); =20 io_tlb_default_mem =3D mem; if (verbose) @@ -282,8 +293,8 @@ 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; + unsigned long bytes =3D nslabs << IO_TLB_SHIFT; =20 if (swiotlb_force =3D=3D SWIOTLB_NO_FORCE) return 0; @@ -297,20 +308,9 @@ 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; - } - + memset(mem, 0, sizeof(*mem)); 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.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550169; cv=none; d=zohomail.com; s=zohoarc; b=RI9bYezBdPBHIn02W60sUtsFRR2jIUGsJ0UeGHBlBH2/2aLk9wVRdJrFfNxWtxWyPKtDMcBGltk1pHzElvr/iXZVYXiQ70BWKjmXf2mdsKAA8MtXxKN226Vr/sMhbCTvrMFC0KeU/9r81xUzOomBImklAgwairFt1Hae3qDUDUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550169; 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=87F32lyNJPVTVtO+0wV8iOXVR4FYPSJ8Efeoe/l3AWY=; b=KYsCK7wCPamGeZqdAjlF6CZTXpKR6AdW1zS6hHpLYjoCLH5pXrwsggUENUxrxuiwWgI7G9C0yHzswg3v7Puq2jl1wae8iIIddmF1m0YG8E9ijVdcCDLarh5vlHl/jij4B0p7/I0lHDJGl4vVObyEQZyVoSId3OJfRhQi7fgHqbM= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550169914246.21635814741023; Thu, 24 Jun 2021 08:56:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146893.270469 (Exim 4.92) (envelope-from ) id 1lwRhv-0008Re-4E; Thu, 24 Jun 2021 15:55:59 +0000 Received: by outflank-mailman (output) from mailman id 146893.270469; Thu, 24 Jun 2021 15:55: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 1lwRhv-0008RW-0c; Thu, 24 Jun 2021 15:55:59 +0000 Received: by outflank-mailman (input) for mailman id 146893; Thu, 24 Jun 2021 15:55:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRht-0008QL-Pt for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:55:57 +0000 Received: from mail-pg1-x52e.google.com (unknown [2607:f8b0:4864:20::52e]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2733aba1-665c-4386-894c-6259c438ad9e; Thu, 24 Jun 2021 15:55:57 +0000 (UTC) Received: by mail-pg1-x52e.google.com with SMTP id a2so5059784pgi.6 for ; Thu, 24 Jun 2021 08:55:57 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id la18sm5913675pjb.55.2021.06.24.08.55.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:55: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: 2733aba1-665c-4386-894c-6259c438ad9e 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=87F32lyNJPVTVtO+0wV8iOXVR4FYPSJ8Efeoe/l3AWY=; b=fPyR7LNfa+/lU3WGWQPO3NZkUjo26lxHQdRzo89jZMyBjRWMed8i0Y6RqoJEyweboI IubDRG9d7RiT3UTHReJE0MAliYBlmMLlLps0zkeHlwgKitR9Va5Y9JWu2QIhfoUNH31f Sz4HZ90/m+NBhkrEaC1sLlamv48IpLCMUi5TY= 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=87F32lyNJPVTVtO+0wV8iOXVR4FYPSJ8Efeoe/l3AWY=; b=HYfwdu1wgg8FskX/jl3/TMyHQLoITmvhEeGzvK2qEyDVWDJzpP/D7TqvYJBIDHng1Q elNDXwtyHkammEOmEB5tShJy4KuVT03fxOyYmccKegZDgXAk/rTW0Bk5y/MN/ijBxSyW A5PglIlR4EHIJNHV/0nAe/MDBcomRzcZNSrkd3xO17QzzH5X4ZZ7qPM1+TNArJK0T7CO NACJq0oEwusxfEeoy3EV+WpLDBZFg2O5W+FhLUGPT0+Q3BTIhZCc61QNGXGzMsbLDlN8 JtXVIMJ+zT/vnohBXBMj8zSInh/aWqmk5Q7PHSV+KCMqCacTOdjAvnwfxTpsC4NPtJVF FYUQ== X-Gm-Message-State: AOAM530qtxkYcdqzDXUuoPTbnwdjBxK/Y1HMt98OikCA5FO9ksO+b71q oVbz++2lIOfUQiJdQV/3TJwJqQ== X-Google-Smtp-Source: ABdhPJxQx3pwzFqcBdR/DNm2W1TpNOCeT4sa0oGntLB2nXanycaT15P3BNOzlPmGxyWI5Z+ImzxIzA== X-Received: by 2002:a63:4e4d:: with SMTP id o13mr5258697pgl.361.1624550156451; Thu, 24 Jun 2021 08:55: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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 02/12] swiotlb: Refactor swiotlb_create_debugfs Date: Thu, 24 Jun 2021 23:55:16 +0800 Message-Id: <20210624155526.2775863-3-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon --- kernel/dma/swiotlb.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 1f9b2b9e7490..ede66df6835b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -671,19 +671,26 @@ bool is_swiotlb_active(void) EXPORT_SYMBOL_GPL(is_swiotlb_active); =20 #ifdef CONFIG_DEBUG_FS +static struct dentry *debugfs_dir; =20 -static int __init swiotlb_create_debugfs(void) +static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; - - if (!mem) - return 0; - mem->debugfs =3D debugfs_create_dir("swiotlb", NULL); 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; + + debugfs_dir =3D debugfs_create_dir("swiotlb", NULL); + if (mem) { + mem->debugfs =3D debugfs_dir; + swiotlb_create_debugfs_files(mem); + } return 0; } =20 -late_initcall(swiotlb_create_debugfs); +late_initcall(swiotlb_create_default_debugfs); =20 #endif --=20 2.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550180; cv=none; d=zohomail.com; s=zohoarc; b=YOMF5yeAswlvpS1qFK+tM8zTP2WwwyJYmaH7NmHbOc/sMLnQNh+s1rBPLWXcC28OhX65S43F1WRpH86Lcj/NkKgvFNdOZm8AbnQlJ8IQdhiyZLuIgcjVgAs2drEnbmfx/55mQDjCBuKn1pVI3fPQFdnnjtR5QzdGb7NGqXfLd9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550180; 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=+yhAgwjq5z1dAtXH3bS6halUgnpsXrGer7IGToK2ifg=; b=NI0UCJw0hikmPGAL04BrZ1uvZeCYOygC+3/I7/k8LvBVLfUMZIv/OiG0auvJGrGUNj28qTRbTKMOx1MfSYTCsgiTytf24en9azQpOEryR93cO3WOswZv2ilkn66qZaCIlHbAO6TBwrtAWn5qcRTirgrtOCPCEXskYv5WnN52ntY= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550180117306.85818537974967; Thu, 24 Jun 2021 08:56:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146897.270480 (Exim 4.92) (envelope-from ) id 1lwRi4-0000W2-D0; Thu, 24 Jun 2021 15:56:08 +0000 Received: by outflank-mailman (output) from mailman id 146897.270480; Thu, 24 Jun 2021 15:56:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRi4-0000Vv-9q; Thu, 24 Jun 2021 15:56:08 +0000 Received: by outflank-mailman (input) for mailman id 146897; Thu, 24 Jun 2021 15:56: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 1lwRi3-0000Nz-DU for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:56:07 +0000 Received: from mail-pj1-x102a.google.com (unknown [2607:f8b0:4864:20::102a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id bf6f5d6b-06f2-4a02-802c-1fa6e7d74328; Thu, 24 Jun 2021 15:56:06 +0000 (UTC) Received: by mail-pj1-x102a.google.com with SMTP id l11so3725150pji.5 for ; Thu, 24 Jun 2021 08:56:06 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id v21sm3445482pfu.77.2021.06.24.08.55.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:56: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: bf6f5d6b-06f2-4a02-802c-1fa6e7d74328 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=+yhAgwjq5z1dAtXH3bS6halUgnpsXrGer7IGToK2ifg=; b=amIqlLHGrUt8djVOf4yys2+imq4cPT7hCVf0b/QuzNNknjD6TQ5PH/FESx40Jfm2Sy e9vppGwlrw0CYkZwPegdpkHKAhnvdkrDfv3mH1s+b6/aR0Bz86Elj1k+BXGZoNp8MZsX qL6/glvhzEwDwjhnM7F3SEdYPjqJ2hAkhfF50= 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=+yhAgwjq5z1dAtXH3bS6halUgnpsXrGer7IGToK2ifg=; b=nKTtwv+6uRp80/Twgs3na7JPUiFFtLBwvcDfhEImQr0rH3Etov9E9FVkPnr3mb26rc LXyD7oFAxfvnMf8MRLL+unbYZtOQ3V3nzKsXBAud9IKpqcqKSx7ZDOKzORn1mP3SAyG8 hbr81EsZPHL5j2y6MyhfyKoxL16a3Z5SfPmWMNIOvqDLrWxHbwNi3x9rtpgaUnN/CDkb kQR+1v8lMeIzyO6s3j6SFtyY0qlh7g9PZsiBnpFOziEF5btjgkrHsihZoA3aObpSuw/0 82XBCsSLWrMWFITW3b+Ik+s0sPWuOJwC93w7P2WNDdL8DSRSE7ekB8WFXTEd/fnWKg63 alLA== X-Gm-Message-State: AOAM530SVeMCASfsL20+8tq64QMbUZzph924vcjXj7zAe7nOn4LLtZUz aWJHXXmYvN3eGL9aoPKw/HClbQ== X-Google-Smtp-Source: ABdhPJx5buaD+Aj0oQHu9wgvwnByTOy2l3ZvCASGd6R1iZ+Ag+wNfG3I5+8ywo8QG6jWoo4vpvXgOg== X-Received: by 2002:a17:902:d483:b029:127:95c1:19d8 with SMTP id c3-20020a170902d483b029012795c119d8mr4930234plg.42.1624550165683; Thu, 24 Jun 2021 08:56: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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 03/12] swiotlb: Set dev->dma_io_tlb_mem to the swiotlb pool used Date: Thu, 24 Jun 2021 23:55:17 +0800 Message-Id: <20210624155526.2775863-4-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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" Always have the pointer to the swiotlb pool used in struct device. This could help simplify the code for other pools. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon Acked-by: Stefano Stabellini --- drivers/base/core.c | 4 ++++ include/linux/device.h | 4 ++++ kernel/dma/swiotlb.c | 8 ++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index f29839382f81..cb3123e3954d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include /* for dma_default_coherent */ =20 @@ -2736,6 +2737,9 @@ void device_initialize(struct device *dev) defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) dev->dma_coherent =3D dma_default_coherent; #endif +#ifdef CONFIG_SWIOTLB + dev->dma_io_tlb_mem =3D io_tlb_default_mem; +#endif } EXPORT_SYMBOL_GPL(device_initialize); =20 diff --git a/include/linux/device.h b/include/linux/device.h index ba660731bd25..240d652a0696 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: Pointer to the swiotlb pool used. Not for driver use. * @archdata: For arch-specific additions. * @of_node: Associated device tree node. * @fwnode: Associated device node supplied by platform firmware. @@ -518,6 +519,9 @@ struct device { #ifdef CONFIG_DMA_CMA struct cma *cma_area; /* contiguous memory area for dma allocations */ +#endif +#ifdef CONFIG_SWIOTLB + struct io_tlb_mem *dma_io_tlb_mem; #endif /* arch specific additions */ struct dev_archdata archdata; diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index ede66df6835b..72a4289faed1 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -340,7 +340,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 dev->dma_io_tlb_mem; int index =3D (tlb_addr - mem->start) >> IO_TLB_SHIFT; unsigned int offset =3D (tlb_addr - mem->start) & (IO_TLB_SIZE - 1); phys_addr_t orig_addr =3D mem->slots[index].orig_addr; @@ -431,7 +431,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 dev->dma_io_tlb_mem; 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; @@ -508,7 +508,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 dev->dma_io_tlb_mem; unsigned int offset =3D swiotlb_align_offset(dev, orig_addr); unsigned int i; int index; @@ -559,7 +559,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 hwdev->dma_io_tlb_mem; 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.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550197; cv=none; d=zohomail.com; s=zohoarc; b=KZz+nqlXRXJjEn8OgCnFokVTZgYFqguXWuubH6aDJ3ASPBFCrWHMBHgG463I1NLvUJsLRAiXtwnwByAZgs9zpSf0AVqhG0SWVCuBlTXZFx+tW76qupTkXx8gWInaiVTJtQNZp8grKLht1sOfedwCGAP/g1IExiWeVNy+WcMyeH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550197; 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=n+WwDLLEZtw2fHfSMVUWtPxnVCk0hCuq73bmvGm/m1o=; b=g8bzgf6uyjQLyKxBJ0vmGnoHC8ZQzAdNIofptRvWfoT7itDtIER9aeVs/I/BHyu3XkssWwDWmKkUNU7awZEvkOS9U13Ax1KadwRBvS+d8Mazt20tNzI5pCJYfjNJyUB4ysgyZj1jJir0kzbxGh7qghbcjPBBPBwzAE/I5syNjzk= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550197287663.0237837760457; Thu, 24 Jun 2021 08:56:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146904.270491 (Exim 4.92) (envelope-from ) id 1lwRiK-0001PH-Ld; Thu, 24 Jun 2021 15:56:24 +0000 Received: by outflank-mailman (output) from mailman id 146904.270491; Thu, 24 Jun 2021 15:56:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRiK-0001P3-IJ; Thu, 24 Jun 2021 15:56:24 +0000 Received: by outflank-mailman (input) for mailman id 146904; Thu, 24 Jun 2021 15:56:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRiJ-0000Nz-2M for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:56:23 +0000 Received: from mail-pg1-x534.google.com (unknown [2607:f8b0:4864:20::534]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b7a589a2-206c-4f5c-82d9-3ffbb18ac911; Thu, 24 Jun 2021 15:56:15 +0000 (UTC) Received: by mail-pg1-x534.google.com with SMTP id d12so5058479pgd.9 for ; Thu, 24 Jun 2021 08:56:15 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id n69sm3378565pfd.132.2021.06.24.08.56.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:56: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: b7a589a2-206c-4f5c-82d9-3ffbb18ac911 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=n+WwDLLEZtw2fHfSMVUWtPxnVCk0hCuq73bmvGm/m1o=; b=k80KiTOwSw6iqF0Tp4xgpgrjitk6znoX9PPzioQVvI1J496rPMnShxqQOjBDG8DOMQ 1bNHBVAz8XiK0s2pSZm07pjWVfh1BfH1RIofiBnVz4e+uMjrm5LFJghyv1GRvp1G0Ul0 ttLVVnlchPBK9QpMayvjMdUbCFfuPr+qofBQ4= 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=n+WwDLLEZtw2fHfSMVUWtPxnVCk0hCuq73bmvGm/m1o=; b=ql4vG5SvC6b6MuS+YC/TGvqeLQfdFGP/UTNedzXaz8dYp/iGjoTXVc0eyGbVY7k6SR p+xsgPoxre4Ogran+lFqrFtyvJbNR7GRbjGgR+D8hJv3USDiQYIX95oMp2sZ2euH3MQQ PPIAFYJqf+GQz0ChD9i+Y228HID/bGLIFuXm0pwUwRB5qf9Wszc/AupHLKA8kEnkDv4y 31FHtPTxdBADwR4lmeZyKJT3LXDUrj7GLUpbaUePjZC/0rsfoY4avzZwXlqDplsCIVsO 4yNJ13QLnPrcnWLy7PedJ3ROI/cC++jburGz5n4U94WQ7TSAtcGwLF0bzB5ch8AWfN5S HkOQ== X-Gm-Message-State: AOAM532dEp08emolAClW/9vDypM7zJFbn6U/eB4xSFDENrZqwcoJ3SGX hGzWj9Mpb3024bklOH11/6DD2Q== X-Google-Smtp-Source: ABdhPJzgje+wGQrvOOjfb6HbmbmMTosJM0TPXVPHtGPlgUEf/ZkvFvEuVcA/l9nFO74UYNuZfzJChg== X-Received: by 2002:a63:c058:: with SMTP id z24mr5427217pgi.264.1624550174569; Thu, 24 Jun 2021 08:56: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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 04/12] swiotlb: Update is_swiotlb_buffer to add a struct device argument Date: Thu, 24 Jun 2021 23:55:18 +0800 Message-Id: <20210624155526.2775863-5-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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 different pools. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon Acked-by: Stefano Stabellini --- drivers/iommu/dma-iommu.c | 12 ++++++------ drivers/xen/swiotlb-xen.c | 2 +- include/linux/swiotlb.h | 7 ++++--- kernel/dma/direct.c | 6 +++--- kernel/dma/direct.h | 6 +++--- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 3087d9fa6065..10997ef541f8 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -507,7 +507,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 @@ -578,7 +578,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; } @@ -749,7 +749,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 @@ -762,7 +762,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)) @@ -783,7 +783,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); } @@ -800,7 +800,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 216854a5e513..d1f3d95881cd 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 @@ -101,9 +102,9 @@ struct io_tlb_mem { }; extern struct io_tlb_mem *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 dev->dma_io_tlb_mem; =20 return mem && paddr >=3D mem->start && paddr < mem->end; } @@ -115,7 +116,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.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550201; cv=none; d=zohomail.com; s=zohoarc; b=Zi8YbZTTACUBMC8dQT7xVaulS9bk9HSgBMn3Jr6Rj40lmXHKjllw4cTm0GkxGfKgxk8tzEf7i26k/zNJBJEPFU2e9ghs34LmmV+1UMcZqJMynqajKoYqSLTQJxRc8kOkcrCx6x3W2SZL2SngbuCs1Lzq7cuwECYbGl2+MyW3Hlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550201; 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=zrGk5vL3UOmfV1+EKp1h1m3lS/SKJ23U3aRYavMW2u4=; b=H1n7feX/F7VCemJ5QAkTB8g+qikvev9erYzL1LQR5LhuJQgNDbmaSHuxV+VpJzY0zkyeLcqsc26MlC+RbRGiW3gOgDgjLo0X+Y4Yfx0ZY3gkxo+DqOM65vcADborO9bnxg0P+GIIelUgg9ctgxEQir3VoplKYEW+RCJqQ5Ids18= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550201052278.9055773237434; Thu, 24 Jun 2021 08:56:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146906.270501 (Exim 4.92) (envelope-from ) id 1lwRiP-0001nj-UC; Thu, 24 Jun 2021 15:56:29 +0000 Received: by outflank-mailman (output) from mailman id 146906.270501; Thu, 24 Jun 2021 15:56:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRiP-0001nc-R7; Thu, 24 Jun 2021 15:56:29 +0000 Received: by outflank-mailman (input) for mailman id 146906; Thu, 24 Jun 2021 15:56:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRiO-0000Nz-2Y for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:56:28 +0000 Received: from mail-pg1-x52d.google.com (unknown [2607:f8b0:4864:20::52d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4d86ed21-4b75-4afb-85da-a4aeeed0864f; Thu, 24 Jun 2021 15:56:24 +0000 (UTC) Received: by mail-pg1-x52d.google.com with SMTP id h4so5077322pgp.5 for ; Thu, 24 Jun 2021 08:56:24 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id e1sm3380452pfd.16.2021.06.24.08.56.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:56: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: 4d86ed21-4b75-4afb-85da-a4aeeed0864f 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=zrGk5vL3UOmfV1+EKp1h1m3lS/SKJ23U3aRYavMW2u4=; b=B6hn/8348JH2vHnPkyUEYC2fLk0Sj3SDc+OnMd4jx/VFUgTlJezOC+YlolCAOweLAt Oo0kyBMkmJHHWmhS0fvrHHODCR6O1qWW4bWw+QS4jTi9LZEBbOnCcJNgE55n3uGDNe5i HSER8yBYSdHvr4Z8kgs209kJHa4Ry9RL7QVfY= 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=zrGk5vL3UOmfV1+EKp1h1m3lS/SKJ23U3aRYavMW2u4=; b=b/oiUHW38WQYB329i9rbpDNCkgbxxQvTN0YxHDFymqw4v7D82LvG9X7QJ2J7zuhcol N3FSczYVb7HiiLTFGjLKS/nJXcfVL5+23fgPGDJDoMV+Ti45v1TR7G5QVkt4P9tP7Wpv mpMmAtymuXi2LEOzUFPGlPtxVDT7AaA4IoDM0X6tTb9SE/6HXASUFtjGaajKPeer+qor lBEeXCgaoPn0hijGsZphexMOlAhITd1rwdHKFvXL7H5++BLOUQMZ5g794niE8mneltjq 4wB+F080cPCTxA7MlFjLJYS9nTsRj1R/3CDLqTbAL41KEYnsBWkD1qw6Dp+9+j/2VKW1 JH1A== X-Gm-Message-State: AOAM531gq1ORxvW/RA4HkWnX2ZbtGXkX6VGCksubpF7xHwHM/PARGdwF CfXZizVmMOP+7A0rgIUsXvSvFw== X-Google-Smtp-Source: ABdhPJznGkhArLV3Q5epacwrDV6aWTJSesN4ouhS8WfY0NXWOghLPXDssO25Zt6tnlDnLhwafUevTA== X-Received: by 2002:a63:4554:: with SMTP id u20mr5205395pgk.23.1624550183886; Thu, 24 Jun 2021 08:56: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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 05/12] swiotlb: Update is_swiotlb_active to add a struct device argument Date: Thu, 24 Jun 2021 23:55:19 +0800 Message-Id: <20210624155526.2775863-6-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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 different pools. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon Acked-by: Stefano Stabellini --- 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 a9d65fc8aa0e..4b7afa0fc85d 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(obj->base.dev->dev)) { 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 9662522aa066..be15bfd9e0ee 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(dev->dev); #endif =20 ret =3D ttm_bo_device_init(&drm->ttm.bdev, &nouveau_bo_driver, diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index b7a8f3a1921f..0d56985bfe81 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(&pdev->xdev->dev)) { 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 d1f3d95881cd..dd1c30a83058 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -112,7 +112,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 @@ -132,7 +132,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 72a4289faed1..8a120f42340b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -664,9 +664,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 dev->dma_io_tlb_mem !=3D NULL; } EXPORT_SYMBOL_GPL(is_swiotlb_active); =20 --=20 2.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550208; cv=none; d=zohomail.com; s=zohoarc; b=ioZlDkO0K3rL9KT1lj7EW+wL61kg2sNMNI+WdZQ8dGG3VyZFJiWetNKCao7cR41/bo9dHh9Xlk4VgyQFY5LX+9PBMpeC6CEKnM4brUIADNPQd/0BgYQdv8nJDRBEFsXGHTh5wE4xvTiHwMoTuNy3ThBafp5sGHTTn7FZvfG8RDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550208; 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=vWWa68OFQeb7FNC92AYjUweQlraoAtZ2qywuTutOPN8=; b=mXSMBzrixIx091611guxiUZyucbxoPliC7D7WqlHTI6Z22ai3/OG/tQD2Wu63vAz0p/8PxxyZU/2jDP99kRB8pJyEKSz7Q6Q2On12Gz1xLAqdI6q0UBk2pqqaQ+QTWuPQV6et0RY6lNqd2HED0qj6NMnPZRrWKJJNQhQBEWPhjE= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550208014162.25931054720218; Thu, 24 Jun 2021 08:56:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146907.270513 (Exim 4.92) (envelope-from ) id 1lwRiV-0002Fb-AN; Thu, 24 Jun 2021 15:56:35 +0000 Received: by outflank-mailman (output) from mailman id 146907.270513; Thu, 24 Jun 2021 15:56: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 1lwRiV-0002FN-68; Thu, 24 Jun 2021 15:56:35 +0000 Received: by outflank-mailman (input) for mailman id 146907; Thu, 24 Jun 2021 15:56: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 1lwRiU-0002ED-9Y for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:56:34 +0000 Received: from mail-pj1-x102f.google.com (unknown [2607:f8b0:4864:20::102f]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 688a7c78-e76d-4e48-baed-983584c8d738; Thu, 24 Jun 2021 15:56:33 +0000 (UTC) Received: by mail-pj1-x102f.google.com with SMTP id bv7-20020a17090af187b029016fb18e04cfso5696842pjb.0 for ; Thu, 24 Jun 2021 08:56:33 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id 10sm3356835pfh.174.2021.06.24.08.56.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:56:32 -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: 688a7c78-e76d-4e48-baed-983584c8d738 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=vWWa68OFQeb7FNC92AYjUweQlraoAtZ2qywuTutOPN8=; b=VXwSpljaHyT9CGsX566zaWUYjLWqT6EZGvW+HUV35ZUKMCtL+5WOxJcFRf4L1/7RFc qGeV6pbn94x/vW7fLhV34a5kH7V7Jg+oyk1mVqp0p88iltTd6zaG8ZqWhoFwX03BHlru OGskxuzkvEXUDLIs9WCRDc/Gg2nJw/vs7F2Ng= 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=vWWa68OFQeb7FNC92AYjUweQlraoAtZ2qywuTutOPN8=; b=IwX7ih9KwTOqoXEaN6RWN9KkP8r9hI/xCNl+/zh0iSwoxSmWmsmIXycBPw4tN7jMrk czQReVDm+JmeQ/aa3z7U75tR7sWfkgykHte82CrF7BcSacPw9c7mhrCMTwKbhhI3X+bp 3mLkXXLt2+qpybYDoXwbAAAgPfR6rp4dgQOOWk0siB4FN3PWruM67UY/XIMfocnLG41m NGIl0dVf9UU/kNIxVWFs220s6Ek6LLH1ANi6++UYaAzYDr93DI0zcrHryR4w4+49ksT3 /ouWothH0Xltm3dKBMsuspUh/WWOTlzDSXzYYk+0GI9jPTzx6yCvO36FFdL4DHjpGSWA br7Q== X-Gm-Message-State: AOAM530qdD4qAdXau9Ra4bENTmjRTgsFvSeLuneMij1sHeKmdJ8SrDj4 gqbzn2yFJyzZ5GQ9MQ18641Kfg== X-Google-Smtp-Source: ABdhPJyM3ZtD9p071nGaZ41yrN00ryvbfXJ3YxQAdjvfE9uJr/thaI9NsyuGT18oKxVn0E9uAB208g== X-Received: by 2002:a17:90a:db8a:: with SMTP id h10mr16188658pjv.50.1624550192680; Thu, 24 Jun 2021 08:56: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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 06/12] swiotlb: Use is_swiotlb_force_bounce for swiotlb data bouncing Date: Thu, 24 Jun 2021 23:55:20 +0800 Message-Id: <20210624155526.2775863-7-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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" Propagate the swiotlb_force into io_tlb_default_mem->force_bounce and use it to determine whether to bounce the data or not. This will be useful later to allow for different pools. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon Acked-by: Stefano Stabellini --- drivers/xen/swiotlb-xen.c | 2 +- include/linux/swiotlb.h | 13 +++++++++++++ kernel/dma/direct.c | 2 +- kernel/dma/direct.h | 2 +- kernel/dma/swiotlb.c | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 0c6ed09f8513..4730a146fa35 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -369,7 +369,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *d= ev, struct page *page, if (dma_capable(dev, dev_addr, size, true) && !range_straddles_page_boundary(phys, size) && !xen_arch_need_swiotlb(dev, phys, dev_addr) && - swiotlb_force !=3D SWIOTLB_FORCE) + !is_swiotlb_force_bounce(dev)) goto done; =20 /* diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index dd1c30a83058..da348671b0d5 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -84,6 +84,7 @@ extern enum swiotlb_force swiotlb_force; * unmap calls. * @debugfs: The dentry to debugfs. * @late_alloc: %true if allocated using the page allocator + * @force_bounce: %true if swiotlb bouncing is forced */ struct io_tlb_mem { phys_addr_t start; @@ -94,6 +95,7 @@ struct io_tlb_mem { spinlock_t lock; struct dentry *debugfs; bool late_alloc; + bool force_bounce; struct io_tlb_slot { phys_addr_t orig_addr; size_t alloc_size; @@ -109,6 +111,13 @@ 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_swiotlb_force_bounce(struct device *dev) +{ + struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; + + return mem && mem->force_bounce; +} + void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); @@ -120,6 +129,10 @@ static inline bool is_swiotlb_buffer(struct device *de= v, phys_addr_t paddr) { return false; } +static inline bool is_swiotlb_force_bounce(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..a92465b4eb12 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -496,7 +496,7 @@ 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) || is_swiotlb_force_bounce(dev))) return swiotlb_max_mapping_size(dev); return SIZE_MAX; } diff --git a/kernel/dma/direct.h b/kernel/dma/direct.h index 13e9e7158d94..4632b0f4f72e 100644 --- a/kernel/dma/direct.h +++ b/kernel/dma/direct.h @@ -87,7 +87,7 @@ 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 (is_swiotlb_force_bounce(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 8a120f42340b..0d294bbf274c 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -179,6 +179,10 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem = *mem, phys_addr_t start, mem->end =3D mem->start + bytes; mem->index =3D 0; mem->late_alloc =3D late_alloc; + + if (swiotlb_force =3D=3D SWIOTLB_FORCE) + mem->force_bounce =3D true; + 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); --=20 2.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550230; cv=none; d=zohomail.com; s=zohoarc; b=iugE6ED3T4meQAbE+AfLTgsTyg0WZFZBUglOUL9LSu9tydJxfCmSDtP9MlXhu+wWz6MNlLKBFkd9upoZ/kpj8Y+JnYdCQZQwtktQ4ILC7VUauLtTNsvV4m0ZgfhuUYs1l9qty4CZMJClIvtwWWhd4xeEY5AWEFgtCSA0lQZqa9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550230; 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=k2v4ULCUV3P/ZykooMt4RnFrTyFS8LVxGS67nnIjZ/E=; b=DUpcOjQpEyWph/Fzo/evYcvbkRleWPAOSK3Kdp0Yg4Au4NvJdJlFznGjNiZMV13Nj2ii/v62Rokls8lfOd/xTn8EgAXjphjdRmvtvBE/ao1woRIvs2yLz2wYviU95dkrvnwodmIfj7m63UyBaczi49IIknmB6z2S4Q582xrgaog= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162455023080857.81298013062781; Thu, 24 Jun 2021 08:57:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146914.270524 (Exim 4.92) (envelope-from ) id 1lwRit-0003N5-JH; Thu, 24 Jun 2021 15:56:59 +0000 Received: by outflank-mailman (output) from mailman id 146914.270524; Thu, 24 Jun 2021 15:56: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 1lwRit-0003Mw-Fr; Thu, 24 Jun 2021 15:56:59 +0000 Received: by outflank-mailman (input) for mailman id 146914; Thu, 24 Jun 2021 15:56: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 1lwRis-0002ED-3q for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:56:58 +0000 Received: from mail-pj1-x102d.google.com (unknown [2607:f8b0:4864:20::102d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 630627be-6f8c-45eb-bdd4-27bef3c2bce7; Thu, 24 Jun 2021 15:56:42 +0000 (UTC) Received: by mail-pj1-x102d.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso3770258pjp.2 for ; Thu, 24 Jun 2021 08:56:42 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id t13sm3434704pfq.173.2021.06.24.08.56.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:56:41 -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: 630627be-6f8c-45eb-bdd4-27bef3c2bce7 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=k2v4ULCUV3P/ZykooMt4RnFrTyFS8LVxGS67nnIjZ/E=; b=QrT3tJse9UwGIKHlr8MsnQ/5shpb9vzqfj7YMQ2fYijn7FCRoIijuokKPkX0W4emjg zIW9mO8KXkFug0OUuL1YqRloVsCf7/HNDUAAE7RH/8xRS3Mt1GINoLA/1NQjeCh/6ZZs IZdWLInrLmUEvcR0rzL0waTaUCb67EWeMYbx0= 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=k2v4ULCUV3P/ZykooMt4RnFrTyFS8LVxGS67nnIjZ/E=; b=hmayg/KplL7q+j00gMpJ4RezvQR59D6niSNyDdrNGQcLWsbR6HLQI8/erFSbOIXs4q ePDRDKdinnsw8r/mI3zfQPteq40iTgGC4k7zaiynVQduzRDuhr8E4NepYND9u5VYWF7B +Ig3W3Mw99MyWvCBXmlbAdE03z89cKMSE7n/GzwpLYGeDKUcYi16WDZCQufNi13zZc5L V9tKvD40362/Wc9/TD3KW5HA3MGGfbYdecWOB8PLVt840XRw2dHIwC5Db/AhJZDykIoi rG4wrLr7KzRxldE4IXNXcofDU8urfi+cwbH0Ce7bF6cr+bIktZKua+jmMIZUjrTj1QyK mfmg== X-Gm-Message-State: AOAM533vOL0y8fIoYVhKaCPRFKeEFh/c3XJJnJIelBNr6CovxlCG7xFF Ekg04oM8YeCFjCo2xd+MDE+lvA== X-Google-Smtp-Source: ABdhPJzbejiNIcTS+DoAyoRSN0idnXT3+mB1g+t9ZbfEjTYMX6+0aJ+6gkXmZUbbSTOePShgS47cWw== X-Received: by 2002:a17:90b:1bc6:: with SMTP id oa6mr15922344pjb.151.1624550201945; Thu, 24 Jun 2021 08:56:41 -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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 07/12] swiotlb: Move alloc_size to swiotlb_find_slots Date: Thu, 24 Jun 2021 23:55:21 +0800 Message-Id: <20210624155526.2775863-8-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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" Rename find_slots to swiotlb_find_slots and move the maintenance of alloc_size to it for better code reusability later. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon --- kernel/dma/swiotlb.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 0d294bbf274c..b41d16e92cf6 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -432,8 +432,8 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, = unsigned int index) * Find a suitable number of IO TLB entries size that will fit this reques= t and * allocate a buffer from that IO TLB pool. */ -static int find_slots(struct device *dev, phys_addr_t orig_addr, - size_t alloc_size) +static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr, + size_t alloc_size) { struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; unsigned long boundary_mask =3D dma_get_seg_boundary(dev); @@ -444,6 +444,7 @@ static int find_slots(struct device *dev, phys_addr_t o= rig_addr, dma_get_min_align_mask(dev) & ~(IO_TLB_SIZE - 1); unsigned int nslots =3D nr_slots(alloc_size), stride; unsigned int index, wrap, count =3D 0, i; + unsigned int offset =3D swiotlb_align_offset(dev, orig_addr); unsigned long flags; =20 BUG_ON(!nslots); @@ -488,8 +489,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 - (offset + ((i - index) << IO_TLB_SHIFT)); + } for (i =3D index - 1; io_tlb_offset(i) !=3D IO_TLB_SEGSIZE - 1 && mem->slots[i].list; i--) @@ -530,7 +534,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, = phys_addr_t orig_addr, return (phys_addr_t)DMA_MAPPING_ERROR; } =20 - index =3D find_slots(dev, orig_addr, alloc_size + offset); + index =3D swiotlb_find_slots(dev, orig_addr, alloc_size + offset); if (index =3D=3D -1) { if (!(attrs & DMA_ATTR_NO_WARN)) dev_warn_ratelimited(dev, @@ -544,11 +548,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.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550249; cv=none; d=zohomail.com; s=zohoarc; b=CZXecXlrGkBAoePL2q8faMYrQtRYH+Fo2hNqAdOsYT8AUp/MeMi3h0TD9AJbMJLCDJqVHQBBCsSk4CiXArCAFRMHtixIFPfLJ+KgMLYWu7WDKS+cKUxkmY5ekGUACbsDTkdTj66/Sqs7oOYP8K9922bSq5gFYF9WVkxtT1fc4JE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550249; 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=DgMLkxnMrm1ElKh2pKbH6DNaZYR5ugLD1JouEAo1Krw=; b=JrsiS29EtIMllpvaNfx8GdzsA2nBDe/Mw0LPpa5Mf0qjrbUMhLkpL4auar9gNpF0/jPCeN1Ldaqi42hhHvgxMQl8gNPyHHRBkKkiS9QbriUqnwtPCkuogOT2cjctlBrBV5D5zLghv8sHvZb6W3X4aFJTwrAGeDCsIHRbN+NXMSY= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550249085302.72538694447644; Thu, 24 Jun 2021 08:57:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146920.270546 (Exim 4.92) (envelope-from ) id 1lwRjD-0004Q7-AB; Thu, 24 Jun 2021 15:57:19 +0000 Received: by outflank-mailman (output) from mailman id 146920.270546; Thu, 24 Jun 2021 15:57:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRjD-0004Ps-6N; Thu, 24 Jun 2021 15:57:19 +0000 Received: by outflank-mailman (input) for mailman id 146920; Thu, 24 Jun 2021 15:57:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRjC-0002ED-4f for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:57:18 +0000 Received: from mail-pg1-x52f.google.com (unknown [2607:f8b0:4864:20::52f]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6dda1818-df10-435e-aa73-6d1a6321736f; Thu, 24 Jun 2021 15:56:51 +0000 (UTC) Received: by mail-pg1-x52f.google.com with SMTP id t13so5053950pgu.11 for ; Thu, 24 Jun 2021 08:56:51 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id s1sm2804633pgg.49.2021.06.24.08.56.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:56:50 -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: 6dda1818-df10-435e-aa73-6d1a6321736f 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=DgMLkxnMrm1ElKh2pKbH6DNaZYR5ugLD1JouEAo1Krw=; b=CBMnwj3bqWSxJk9QuIRXj7AXS1rDlhnCorGo2xL5ODh+Y1ZQXuqRVjdQ1sf+NKMF68 LGTA1Lrr3OIkG7vhENTIDNd/H+9BmAfoCOyqiHCsY0TRSuVzsnR4mZ3/RZi0ObYA87bL L7rL4dqepWMHniYpyZxN1LD1FH654rL7Zq2lk= 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=DgMLkxnMrm1ElKh2pKbH6DNaZYR5ugLD1JouEAo1Krw=; b=dxZ0CyoBqtwO+pSoTaw6Pb/Dg4ff49rKVDHk/VOnr3xPEtb1dMlpaVxoQc97m83BG/ 6WKvPRvYLBRImA3OKiJdio5Ei/sRoyb9livV6rpFbrz76soQzWzOYE9PssfBefWp6Mq5 QdB1RTTBX/omFaTbf6TgyFRoLMbc/JGvkBIfyZpfurdW0ff/JzGPK9Z/nCTgy28NSvDM PeAIrZojotuIzUi/KXOazBQbi0nAiXyDxSiBgIqaAvgrPCjl4aZLD9mGxubAJbQ7yxCq PkErRxa9KWgjl4I8sKjL3mjz46+gJXC3RH3hEAlapGlCS1QSVPsba93tmOS5cq1lWcPQ Z2dw== X-Gm-Message-State: AOAM530QZRcQIILX5aYPGuwrgMehgWnd0Fx4RUvjmYYRTisn3B1ZLz+F mZgkvGUtb8/74KO1URd7R+L2oA== X-Google-Smtp-Source: ABdhPJz0K8c/e85685sEfhv/cLt8Y/+djdObhlSxD8seBO46vO4znhwmAjNx3on/y8xXncFvFChqNA== X-Received: by 2002:a62:d41e:0:b029:305:b3ff:4056 with SMTP id a30-20020a62d41e0000b0290305b3ff4056mr5643354pfh.78.1624550211262; Thu, 24 Jun 2021 08:56:51 -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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 08/12] swiotlb: Refactor swiotlb_tbl_unmap_single Date: Thu, 24 Jun 2021 23:55:22 +0800 Message-Id: <20210624155526.2775863-9-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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_release_slots, to make the code reusable for supporting different bounce buffer pools. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon --- 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 b41d16e92cf6..93752e752e76 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -557,27 +557,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 swiotlb_release_slots(struct device *dev, phys_addr_t tlb_addr) { - struct io_tlb_mem *mem =3D hwdev->dma_io_tlb_mem; + struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; 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. @@ -612,6 +600,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); + + swiotlb_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.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550542; cv=none; d=zohomail.com; s=zohoarc; b=GJbOyt/mJo8HK5bARuoZRs+nIh5EypCv7L3CRM5ar9MP5tqhQPVhbeOfJ9MveLxlYhxa4uOE19TRXOc1paHin36qK3kQ5CXaizFTb0G3cCzf/Pe8dPUBoOJdTt6qKGqjYZOUN9uHHyPIoxZzy+qDRMApoOQ1nUu93By0BrFREW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550542; 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=3nr5duANOct6/oGOQLy2DP5IEE8G3PvgXwIs/U9R4Gw=; b=nWde+bINpEzhrC3blACCRY7PDY2WK8B/N9+88x830fhsIjX4A7JqWjLOXFX2wgK2J8Sax88/JbtURuApjTdjT0dG7G8ch0rtz5iUxU9iSQm2WSV9g0x6kTiQWI8c/j5JS6priPGY6q5Vn9scxaPtLUmDohCppkWk0yj5YOhllZM= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550542211184.37571148684697; Thu, 24 Jun 2021 09:02:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146946.270578 (Exim 4.92) (envelope-from ) id 1lwRnu-0007Zy-Gh; Thu, 24 Jun 2021 16:02:10 +0000 Received: by outflank-mailman (output) from mailman id 146946.270578; Thu, 24 Jun 2021 16:02:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRnu-0007Zp-DX; Thu, 24 Jun 2021 16:02:10 +0000 Received: by outflank-mailman (input) for mailman id 146946; Thu, 24 Jun 2021 16:02:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRjM-0002ED-54 for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:57:28 +0000 Received: from mail-pl1-x633.google.com (unknown [2607:f8b0:4864:20::633]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9b7f386b-385b-4d6b-ba3a-e6a7ce97517d; Thu, 24 Jun 2021 15:57:01 +0000 (UTC) Received: by mail-pl1-x633.google.com with SMTP id y21so3183043plb.4 for ; Thu, 24 Jun 2021 08:57:01 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id p14sm3021513pgb.2.2021.06.24.08.56.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:57:00 -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: 9b7f386b-385b-4d6b-ba3a-e6a7ce97517d 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=3nr5duANOct6/oGOQLy2DP5IEE8G3PvgXwIs/U9R4Gw=; b=a8cmMzGcpXmztmz+lmxPA1Q6xyV16M28kxjqgCBbf1Ks7zV690v77sgOhYEhzTEZs5 +Kq7hKLiNtZRYure1Gm29HwsXL5yWOVlL7+xFg6ipueZCOjHoaeiULU+xMBCxf2GAzqT bKoJgbcAHXJKSgTGFtRzL1B3lMuyRPBHOjNVs= 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=3nr5duANOct6/oGOQLy2DP5IEE8G3PvgXwIs/U9R4Gw=; b=XHQmT/9ISvRDk5LaLVQaN83qKAxzA8qb+5/NAbcw7Cqs7iktJEqr/RlNt27xicnSNB n4jfnal6AhHE8D4V5a0lKreRanvsRTFygpjHao4x5jhHd6zaVX0PXrx0pNzXktnzMduc cc+nlWVBPP6T1GlLCRiMPfHD9QJeFgDCa9H6EkyZXVUvb3bvvVtpmxivIVU8775vQLXP ifE6aiuCPftxiHmWAygcbgMuk2d8tXfLeIZFCwGxc7CzBaLsJEH6iHpTWbfQ6YrOVqLx SCDt+4CzDWoFxlYMDvXxd6enYQNYMb9dvkj0ei8RQld4qt7j+kUewE2IdKkM3A8Td/Al x9GQ== X-Gm-Message-State: AOAM5319gGN0jg6Q3Re4BeG8jp6UmIXYYcIS02GmOSdtXmjqM1bCpn2D ctT+kkdwkAysm+3YDXc/VHnsBg== X-Google-Smtp-Source: ABdhPJxmEwVXJd6cAH00JVqNM1sPqMocZqAA0whpk6jl7w3uVsxxZQx+6Mf7e+Nh2MKMhnKmM6WWEg== X-Received: by 2002:a17:90a:3d09:: with SMTP id h9mr15516036pjc.78.1624550220587; Thu, 24 Jun 2021 08:57:00 -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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 09/12] swiotlb: Add restricted DMA alloc/free support Date: Thu, 24 Jun 2021 23:55:23 +0800 Message-Id: <20210624155526.2775863-10-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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} and is_swiotlb_for_alloc to support the memory allocation from restricted DMA pool. The restricted DMA pool is preferred if available. 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 Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon Acked-by: Stefano Stabellini --- include/linux/swiotlb.h | 26 ++++++++++++++++++++++ kernel/dma/direct.c | 49 +++++++++++++++++++++++++++++++---------- kernel/dma/swiotlb.c | 38 ++++++++++++++++++++++++++++++-- 3 files changed, 99 insertions(+), 14 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index da348671b0d5..3b9454d1e498 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -85,6 +85,7 @@ extern enum swiotlb_force swiotlb_force; * @debugfs: The dentry to debugfs. * @late_alloc: %true if allocated using the page allocator * @force_bounce: %true if swiotlb bouncing is forced + * @for_alloc: %true if the pool is used for memory allocation */ struct io_tlb_mem { phys_addr_t start; @@ -96,6 +97,7 @@ struct io_tlb_mem { struct dentry *debugfs; bool late_alloc; bool force_bounce; + bool for_alloc; struct io_tlb_slot { phys_addr_t orig_addr; size_t alloc_size; @@ -158,4 +160,28 @@ static inline void swiotlb_adjust_size(unsigned long s= ize) extern void swiotlb_print_info(void); extern void swiotlb_set_max_segment(unsigned int); =20 +#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); + +static inline bool is_swiotlb_for_alloc(struct device *dev) +{ + return dev->dma_io_tlb_mem->for_alloc; +} +#else +static inline struct page *swiotlb_alloc(struct device *dev, size_t size) +{ + return NULL; +} +static inline bool swiotlb_free(struct device *dev, struct page *page, + size_t size) +{ + return false; +} +static inline bool is_swiotlb_for_alloc(struct device *dev) +{ + return false; +} +#endif /* CONFIG_DMA_RESTRICTED_POOL */ + #endif /* __LINUX_SWIOTLB_H */ diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index a92465b4eb12..2de33e5d302b 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -75,6 +75,15 @@ 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) +{ + if (IS_ENABLED(CONFIG_DMA_RESTRICTED_POOL) && + swiotlb_free(dev, page, size)) + return; + dma_free_contiguous(dev, page, size); +} + static struct page *__dma_direct_alloc_pages(struct device *dev, size_t si= ze, gfp_t gfp) { @@ -86,6 +95,16 @@ 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); + if (IS_ENABLED(CONFIG_DMA_RESTRICTED_POOL) && + is_swiotlb_for_alloc(dev)) { + page =3D swiotlb_alloc(dev, size); + if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) { + __dma_direct_free_pages(dev, page, size); + return NULL; + } + return 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); @@ -142,7 +161,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_swiotlb_for_alloc(dev)) { page =3D __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO); if (!page) return NULL; @@ -155,18 +174,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_swiotlb_for_alloc(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_swiotlb_for_alloc) 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_swiotlb_for_alloc(dev)) return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp); =20 /* we always manually zero the memory once we are done */ @@ -237,7 +261,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 @@ -247,15 +271,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_swiotlb_for_alloc(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_swiotlb_for_alloc(dev)) { arch_dma_free(dev, size, cpu_addr, dma_addr, attrs); return; } @@ -273,7 +297,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, @@ -283,7 +307,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_swiotlb_for_alloc(dev)) return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp); =20 page =3D __dma_direct_alloc_pages(dev, size, gfp); @@ -310,7 +335,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 +354,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) || \ diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 93752e752e76..6a7c6e30eb4b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -464,8 +464,9 @@ static int swiotlb_find_slots(struct device *dev, phys_= addr_t orig_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; } @@ -704,3 +705,36 @@ static int __init swiotlb_create_default_debugfs(void) late_initcall(swiotlb_create_default_debugfs); =20 #endif + +#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 swiotlb_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; + + swiotlb_release_slots(dev, tlb_addr); + + return true; +} + +#endif /* CONFIG_DMA_RESTRICTED_POOL */ --=20 2.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550541; cv=none; d=zohomail.com; s=zohoarc; b=cQD8D7aIwxQGKcteuQgVgGLe3ZdTuzjxht0EtZ8nXL3Z+Q27+1uWhmCkRZFOWr3G90sd1BYX9ZlZhoW6A1ym+El7FihTr0U2jNPc6y4aobjZpkiiHZ3bPoh55jrylP/jwF18pLjykCrBLjpmM8z97Y8pm6c3162t1VqNA5sZkLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550541; 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=WbwCPwkWNsZyfDNcMOTWOtrRGSDB7ukqN5rFm3/fcqM=; b=C0bNezyc1ofDJlGuJ9lPKFRF31beceHfbbr8ZgncI3jbueYpYaSI9SGPsUBJ8j6HhFemQY2nFkpjU6AlXH33b8wOwCTRqPjXRbxZHsAE56xt4mW4RRLMTeuRE4LBH53V6Vf2VTaI7L8MpOEOf4LX25nc6XitAMAvgg/bRuX+kXk= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550541959339.6618336660563; Thu, 24 Jun 2021 09:02:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146947.270583 (Exim 4.92) (envelope-from ) id 1lwRnu-0007de-TX; Thu, 24 Jun 2021 16:02:10 +0000 Received: by outflank-mailman (output) from mailman id 146947.270583; Thu, 24 Jun 2021 16:02:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRnu-0007cb-OP; Thu, 24 Jun 2021 16:02:10 +0000 Received: by outflank-mailman (input) for mailman id 146947; Thu, 24 Jun 2021 16:02:09 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRjW-0002ED-5f for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:57:38 +0000 Received: from mail-pj1-x102c.google.com (unknown [2607:f8b0:4864:20::102c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2b9064ef-c70c-4fb8-9352-8c0a17f0ede4; Thu, 24 Jun 2021 15:57:10 +0000 (UTC) Received: by mail-pj1-x102c.google.com with SMTP id bb10-20020a17090b008ab029016eef083425so6176206pjb.5 for ; Thu, 24 Jun 2021 08:57:10 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id x143sm3365707pfc.6.2021.06.24.08.57.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:57:09 -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: 2b9064ef-c70c-4fb8-9352-8c0a17f0ede4 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=WbwCPwkWNsZyfDNcMOTWOtrRGSDB7ukqN5rFm3/fcqM=; b=ST6t0XkrMRO5f6HAim2SUwLoqEUtVKc7/G35fun8pnEgrYgmaoy7jqM/CzM5ROKScW CaGs/CYeApWd6boKyliYyHZkZ8m75hN3AsFBcdHAPE4h8DeZNWtiFC9jFlW6gHYxntTL /JewURtKdZPaJv0dBLRhrI68g5ieBdJUAcjT8= 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=WbwCPwkWNsZyfDNcMOTWOtrRGSDB7ukqN5rFm3/fcqM=; b=t9Swqbcv1zShPcHkU0ISi1lI0LohhQvyCxhqPIYBR2r/61RlgD43I4xvQNaf7L3evx uOEOxtGzbHzgdQznYhMLSShdQJSO24r2mCYdoLIfgeirHgb+hdU+pee1sRQiyUbaa4Vj OaE2Qv3iqopcVVo1OCLKOSVVm1sdtcmKEjITekTg3SJ2fNqDwktN3T2emJnJvukxgzPD jE5YbHEZTZAViU16KYd2yi7gJtsxNgyFq07QR3VyEaiXMfkP7QYf2k/Z1DdKOuaynD/p U2+IedveGVbr+vtMQt6oeuYqqkX0OsMLPs3+zBh98RSj/5taHjc2v4Xw86zj7ov1Z2a8 fTIg== X-Gm-Message-State: AOAM532txavLmeKVa9pLV40jO7fC6HUoTeeyqLOASIyuPYFCsCjarSPX ALBaUWRhJmw16u1SZF7D+qxhaA== X-Google-Smtp-Source: ABdhPJwI7EWsoc2ppnuqnW/9yjxiTzSeTHN60zP/WQgGph69JaVmO4yY57xwR4157oqtL7lcnhpfUA== X-Received: by 2002:a17:903:1043:b029:11e:7489:9bad with SMTP id f3-20020a1709031043b029011e74899badmr5076690plc.34.1624550229453; Thu, 24 Jun 2021 08:57:09 -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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 10/12] swiotlb: Add restricted DMA pool initialization Date: Thu, 24 Jun 2021 23:55:24 +0800 Message-Id: <20210624155526.2775863-11-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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. 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. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon --- include/linux/swiotlb.h | 3 +- kernel/dma/Kconfig | 14 ++++++++ kernel/dma/swiotlb.c | 76 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 3b9454d1e498..39284ff2a6cd 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -73,7 +73,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/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 diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 6a7c6e30eb4b..3baf49c9b766 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 @@ -737,4 +744,73 @@ bool swiotlb_free(struct device *dev, struct page *pag= e, size_t size) return true; } =20 +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; + + /* + * 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; + + set_memory_decrypted((unsigned long)phys_to_virt(rmem->base), + rmem->size >> PAGE_SHIFT); + swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false); + mem->force_bounce =3D true; + mem->for_alloc =3D true; + + rmem->priv =3D mem; + + if (IS_ENABLED(CONFIG_DEBUG_FS)) { + mem->debugfs =3D + debugfs_create_dir(rmem->name, debugfs_dir); + swiotlb_create_debugfs_files(mem); + } + } + + dev->dma_io_tlb_mem =3D mem; + + return 0; +} + +static void rmem_swiotlb_device_release(struct reserved_mem *rmem, + struct device *dev) +{ + dev->dma_io_tlb_mem =3D io_tlb_default_mem; +} + +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; + + if (PageHighMem(pfn_to_page(PHYS_PFN(rmem->base)))) { + pr_err("Restricted DMA pool must be accessible within the linear mapping= ."); + return -EINVAL; + } + + rmem->ops =3D &rmem_swiotlb_ops; + pr_info("Reserved memory: created restricted DMA pool at %pa, size %ld Mi= B\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.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550532; cv=none; d=zohomail.com; s=zohoarc; b=AG/j0INlaGjc8KAtPi+H6yUsJ+446MNA03IMXf6+oWXDG6ejx2Pl8NIGQvSZFLodgucayn75SIuSzynXyvMHj559WfVV4YxBIQuLKF1sfmsVL13re8dmeziaubtEIXqexA9oruF9k0sFqZ8EhQ0N1f+99TF+6QxWhPQ8Fi7T0j0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550532; 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=YPdZA059qJtBhHo92L+QtxB+I/HHPOi+M+A9tEqXqKY=; b=cfjSwnVCtB+n2qLkbNq+HQepEB82LfKZeFi+eWYUSMGbFBM8SB22dVAQCzOU4J8U/EReUKphD7zJTrE/f4CslSF+yjIgWE2wCk2fnxdPXrJrAcZCzJQVxsM2Vfhi/aqqFufMzXkW0E+bPJXuo5+3cQwmCbXVbGUTts6L/WXsR7A= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550532743826.0747025256029; Thu, 24 Jun 2021 09:02:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146939.270562 (Exim 4.92) (envelope-from ) id 1lwRnj-0006z5-85; Thu, 24 Jun 2021 16:01:59 +0000 Received: by outflank-mailman (output) from mailman id 146939.270562; Thu, 24 Jun 2021 16:01: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 1lwRnj-0006yq-3t; Thu, 24 Jun 2021 16:01:59 +0000 Received: by outflank-mailman (input) for mailman id 146939; Thu, 24 Jun 2021 16:01: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 1lwRjg-0002ED-63 for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:57:48 +0000 Received: from mail-pj1-x1036.google.com (unknown [2607:f8b0:4864:20::1036]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 202d8dac-cb63-4540-813e-498207b93e04; Thu, 24 Jun 2021 15:57:19 +0000 (UTC) Received: by mail-pj1-x1036.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso3751583pjb.4 for ; Thu, 24 Jun 2021 08:57:19 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id s4sm2950901pjn.31.2021.06.24.08.57.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:57:18 -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: 202d8dac-cb63-4540-813e-498207b93e04 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=YPdZA059qJtBhHo92L+QtxB+I/HHPOi+M+A9tEqXqKY=; b=PjlqqBPlZ7HlVzWQ/NG7jUEmdRoSGdDyyhsicywtHJWmlQpajkDrqtejX1sn/5F2sS SwwO3EzEcXtbM4jLQSoe8mUbP22ohS6knOWK2YU5Q+OvqR8ORZOMLvrptba985Ay6g72 468Ys8fEwAI9IAi2Nx5OeG0lVcTQ7r4EAMUuk= 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=YPdZA059qJtBhHo92L+QtxB+I/HHPOi+M+A9tEqXqKY=; b=R7wc6MgtOu2zi9CbtnXIUU1rxSOs2rcYKFkLA+wm4lBI3W5mlFHyXZgYSQU3f9C9FD 4EtXErdRL+ixPBltXfk0ftV20tok8xfENNWQv5fH5liIhqaDrqM0ZVsXP+hSll4B5+lr kGwwG0b23qzmBu2j2WhaiXCdEGqOhXRedv54GqCgvJDiplYKTQp7PfKPY6IlVeDq5UBN 5UjMy/uiCB9TcCpsl79M2PkW0y931RerioovIVMaXeWxtdNrCFrxuM0VVSanp6oAHr9g 1EAsPOUm9ij33dgLst8u/mu7rDUUOSYnhe+XOiJzc/yIf0LtvoOfysm2c9FHxPgjWjo1 40fw== X-Gm-Message-State: AOAM530zE3hpnT9barK27/Ckfiz87/NlfFpX0CMjdLLE2p4IEsAAhm+Y 8JZCMVlCaO312CWeZuCmNFzFHA== X-Google-Smtp-Source: ABdhPJxRwzuvR6w9vPa8M+gkJy/ziAGvgsthCKYRNma8WFuVe3INiwBpDz8jqeLqK9XJyVskEplkvw== X-Received: by 2002:a17:90b:1d06:: with SMTP id on6mr5855940pjb.149.1624550238780; Thu, 24 Jun 2021 08:57:18 -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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 11/12] dt-bindings: of: Add restricted DMA pool Date: Thu, 24 Jun 2021 23:55:25 +0800 Message-Id: <20210624155526.2775863-12-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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 Tested-by: Stefano Stabellini Tested-by: Will Deacon --- .../reserved-memory/reserved-memory.txt | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/reserved-memory/reserved-mem= ory.txt b/Documentation/devicetree/bindings/reserved-memory/reserved-memory= .txt index e8d3096d922c..39b5f4c5a511 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 @@ -85,10 +102,11 @@ memory-region-names (optional) - a list of names, one = for each corresponding =20 Example ------- -This example defines 3 contiguous regions are defined for Linux kernel: +This example defines 4 contiguous regions for Linux kernel: one default of all device drivers (named linux,cma@72000000 and 64MiB in s= ize), -one dedicated to the framebuffer device (named framebuffer@78000000, 8MiB)= , and -one for multimedia processing (named multimedia-memory@77000000, 64MiB). +one dedicated to the framebuffer device (named framebuffer@78000000, 8MiB), +one for multimedia processing (named multimedia-memory@77000000, 64MiB), a= nd +one for restricted dma pool (named restricted_dma_reserved@0x50000000, 64M= iB). =20 / { #address-cells =3D <1>; @@ -120,6 +138,11 @@ one for multimedia processing (named multimedia-memory= @77000000, 64MiB). compatible =3D "acme,multimedia-memory"; reg =3D <0x77000000 0x4000000>; }; + + restricted_dma_reserved: restricted_dma_reserved { + compatible =3D "restricted-dma-pool"; + reg =3D <0x50000000 0x4000000>; + }; }; =20 /* ... */ @@ -138,4 +161,11 @@ one for multimedia processing (named multimedia-memory= @77000000, 64MiB). memory-region =3D <&multimedia_reserved>; /* ... */ }; + + pcie_device: pcie_device@0,0 { + reg =3D <0x83010000 0x0 0x00000000 0x0 0x00100000 + 0x83010000 0x0 0x00100000 0x0 0x00100000>; + memory-region =3D <&restricted_dma_reserved>; + /* ... */ + }; }; --=20 2.32.0.288.g62a8d224e6-goog From nobody Mon Apr 29 13:54:26 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=1624550534; cv=none; d=zohomail.com; s=zohoarc; b=jrCUXsgrUyf+Eew+Pyre4NNsEiWdq0pIZCn0KXSo2134C6wUqaiyO8xTY7sFdYC3ikfaRZol3ecyvNBuiZa7qFuKuSY8/7aFcfzEPM2g+rET1JPPwzSfCX3eqZCNqAt89QFy5KKO/RJkVXg1mgBIeF/ZphdZ6arPyOQUQqG69M4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624550534; 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=xfRvKXXPDGozL9xpkc2RXgCWY6OxEYfQN41+lxoFnvY=; b=IaBYAOR+Grf62MeHfyJHsJLfXN/+a5zw7Uv0b5cP9FK4HBP1/DxkmVAzFnwP1/+bdM22ETkEd88wHNCiMmEbXFzflhq7OhWsfKZDyhSWh2pM+CCz66/a7ZGIaMUCA0K2mGL6J/hpXOYeKHWGF5vLzalR8vIfocT9noEBQe8anZY= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1624550533994732.8917835097487; Thu, 24 Jun 2021 09:02:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.146936.270557 (Exim 4.92) (envelope-from ) id 1lwRnj-0006vT-05; Thu, 24 Jun 2021 16:01:59 +0000 Received: by outflank-mailman (output) from mailman id 146936.270557; Thu, 24 Jun 2021 16:01:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRni-0006vM-RI; Thu, 24 Jun 2021 16:01:58 +0000 Received: by outflank-mailman (input) for mailman id 146936; Thu, 24 Jun 2021 16:01:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lwRjl-0002ED-66 for xen-devel@lists.xenproject.org; Thu, 24 Jun 2021 15:57:53 +0000 Received: from mail-pl1-x62c.google.com (unknown [2607:f8b0:4864:20::62c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f2361213-e94d-44cc-8b8a-3f6e1033fbb4; Thu, 24 Jun 2021 15:57:28 +0000 (UTC) Received: by mail-pl1-x62c.google.com with SMTP id v12so3171942plo.10 for ; Thu, 24 Jun 2021 08:57:28 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id n6sm2862924pgt.7.2021.06.24.08.57.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:57:27 -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: f2361213-e94d-44cc-8b8a-3f6e1033fbb4 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=xfRvKXXPDGozL9xpkc2RXgCWY6OxEYfQN41+lxoFnvY=; b=kEshnj7M08k1T5XsbOYdzjZbq7nVnmjng6eJnfjl4lHMzaAZWk6m94BUgoAkO9vE9h LGUHt/CR+GHi3cdJm3u8om1RbudjT01C0RCIVYBXBb3iKIFLf6Hz/aFd03GLLTot9C9q is4g5Rc9w98QwWpmpTahpJ12S/0U2a21x3Eus= 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=xfRvKXXPDGozL9xpkc2RXgCWY6OxEYfQN41+lxoFnvY=; b=U1Ls8tjq4mbnKuBMwzbrUV7xNUc+ejem6YHpK5KyHYMr3orK9z8V3mcp8yI2b0xPKm 1IGz7a5zHGj6LEhga2lFsfIDa0MzBr2QS9+A/Rg8Pyu1u9kMqAFw2Uf9w3RJi5n9sfP+ /errx3bg0IUhgbdrUhWSHIma5PsXC6s92v1u51g8gMK2NlA3nIv4VyN8eOVbZgorPAv2 dzlxjXzgrwBLIzcRUEumoAftTy8Xax/g8XhKvYmnhAVV9bkdtvUbzb74reN/yDFSOh/c mD3XOCA7EdnDMtdA0OtoC6XhoYqKplNdbZ+h6f3ru1gzBh5lXlt954L++mXz/osmYNzl 8odw== X-Gm-Message-State: AOAM530b/VUz+uugWYjzT0YofgLGZt5F4xkTH8Aw8Xys6w8paCU0WBPZ 1Kab9tNXL1EbKxz6TThV3RYXlA== X-Google-Smtp-Source: ABdhPJzInUpAy17snFNN0CGcBB/ghyLU73coTfwG0l77wDEHQQH9RWDi8n5UN9ZkYoU3wlPKMD5xpQ== X-Received: by 2002:a17:90b:2282:: with SMTP id kx2mr5939882pjb.60.1624550248050; Thu, 24 Jun 2021 08:57:28 -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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 12/12] of: Add plumbing for restricted DMA pool Date: Thu, 24 Jun 2021 23:55:26 +0800 Message-Id: <20210624155526.2775863-13-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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 Tested-by: Stefano Stabellini Tested-by: Will Deacon Reported-by: Guenter Roeck Suggested-by: Robin Murphy Tested-by: Guenter Roeck --- drivers/of/address.c | 33 +++++++++++++++++++++++++++++++++ drivers/of/device.c | 3 +++ drivers/of/of_private.h | 6 ++++++ 3 files changed, 42 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index 73ddf2540f3f..cdf700fba5c4 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1022,6 +1023,38 @@ int of_dma_get_range(struct device_node *np, const s= truct bus_dma_region **map) of_node_put(node); return ret; } + +int of_dma_set_restricted_buffer(struct device *dev, struct device_node *n= p) +{ + struct device_node *node, *of_node =3D dev->of_node; + int count, i; + + count =3D of_property_count_elems_of_size(of_node, "memory-region", + sizeof(u32)); + /* + * If dev->of_node doesn't exist or doesn't contain memory-region, try + * the OF node having DMA configuration. + */ + if (count <=3D 0) { + of_node =3D np; + count =3D of_property_count_elems_of_size( + of_node, "memory-region", sizeof(u32)); + } + + for (i =3D 0; i < count; i++) { + node =3D of_parse_phandle(of_node, "memory-region", i); + /* + * There might be multiple memory regions, but only one + * restricted-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, of_node, + i); + } + + return 0; +} #endif /* CONFIG_HAS_DMA */ =20 /** diff --git a/drivers/of/device.c b/drivers/of/device.c index 6cb86de404f1..e68316836a7a 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, np); + return 0; } EXPORT_SYMBOL_GPL(of_dma_configure_id); diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index d9e6a324de0a..25cebbed5f02 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -161,12 +161,18 @@ 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, struct device_node *n= p); #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_set_restricted_buffer(struct device *dev, + struct device_node *np) +{ + return -ENODEV; +} #endif =20 #endif /* _LINUX_OF_PRIVATE_H */ --=20 2.32.0.288.g62a8d224e6-goog