From nobody Sun May 5 02:17:59 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=1623824561; cv=none; d=zohomail.com; s=zohoarc; b=oH50yAQgdbfndtzHDpsJL6X5jg5QDzb+SikR6CiGKx0Aeg0NDKf49ArRZ16f/jLixJw+FrwexLOTCYWvJjcfXGY6BpM0CUWbaLrM1iG2BR04VcKGug/3Hk3ZW+9e61uM7G5DN0RMviO1wvYXt08dKiMi5wvDD/3n74LosUXyulk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824561; 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=w8jpaGfzoLiwzikPo4cNB/z3ajmfRt4xSbdunsHd/ZI=; b=TtRHb8q/VcwMgclAPBzpKRRjAwsqmZbXxn0NlkYc+JQnSshd+UeMuwUzSBAcvT/v/CO4oIbOAP5ix9RrenOGJhhLrHfLOT4ZUY1d9oE9pCNooadIW+fGr87+Fnh6Hx0jeGtmmTqxQ/nKao1EBjvtF0LPXUYiik9nBD/hf0vBflM= 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 1623824561397938.3878528195498; Tue, 15 Jun 2021 23:22:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142605.263084 (Exim 4.92) (envelope-from ) id 1ltOwO-0005jk-Uh; Wed, 16 Jun 2021 06:22:20 +0000 Received: by outflank-mailman (output) from mailman id 142605.263084; Wed, 16 Jun 2021 06:22:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwO-0005jd-Rh; Wed, 16 Jun 2021 06:22:20 +0000 Received: by outflank-mailman (input) for mailman id 142605; Wed, 16 Jun 2021 06:22:19 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwN-0005j0-5e for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:22:19 +0000 Received: from mail-pg1-x532.google.com (unknown [2607:f8b0:4864:20::532]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e29148ab-aaad-4f83-9ea7-8c09b98a8e37; Wed, 16 Jun 2021 06:22:18 +0000 (UTC) Received: by mail-pg1-x532.google.com with SMTP id q15so1101429pgg.12 for ; Tue, 15 Jun 2021 23:22:18 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id b21sm1100157pgj.74.2021.06.15.23.22.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:22:17 -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: e29148ab-aaad-4f83-9ea7-8c09b98a8e37 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=w8jpaGfzoLiwzikPo4cNB/z3ajmfRt4xSbdunsHd/ZI=; b=jTt9XUv4c1VjZCWjqcVf0OaKHSTM9qmeLPQt+E1mw44/Li4ZuKLF18RfGpTBv+Tid+ nNOVbaYyhWI150qfN2S9ojFKh1FavQDj6Z6EHE2L+OIk+zrqnwXrhwMp/ayMHUZgSc6S YgAnH6iJxwdJ6kj8kmg0G1HcyFcGfORXwT+L0= 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=w8jpaGfzoLiwzikPo4cNB/z3ajmfRt4xSbdunsHd/ZI=; b=lsQB1GfnBKdVKsPNh/UZvM2s8kqgP/VITDtL0uamKbWqEGPSVey7VaPuAlnxBzRi7w Eq6db/NqEH82n0oYM75EgqZv1CkEdA/wjfHx/VylRYDGwAefAhpAAKvpaItF+3ykBolg md6AN2DVEdJFdnFYOI4f5IDoU8252lPlRuPvepnvpBgj7OubT/2NhdNwh6KYwXDHAd5f pFiiDLascAIwL2zA+6+g5C8GN4qTO7nWFdq+lg3C4bBsozZ2j6pE1Vo5wv4WNgVFOtqJ iVtUsQFolUg8E1WLLJaZ1PXnhyjOksj/VEKqi9IHxK18iUv6JQI0fG1FXjp9xDowAoeh QwYw== X-Gm-Message-State: AOAM533Ji2jMbvgv6ccImOH6KhXeo0y0WkrAhXRaLyHaBLbu/O1VBa4v AXyaCDj43WV09VfrjXCue2Pq2A== X-Google-Smtp-Source: ABdhPJxpe+iBf1VRMAYcdNKErtktFJS8QnINRpm76Af1BX1/Se6xXKJpZTxwC+DgLqnfRBuhk3siqg== X-Received: by 2002:a63:4c8:: with SMTP id 191mr3477163pge.217.1623824537639; Tue, 15 Jun 2021 23:22:17 -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 Subject: [PATCH v12 01/12] swiotlb: Refactor swiotlb init functions Date: Wed, 16 Jun 2021 14:21:46 +0800 Message-Id: <20210616062157.953777-2-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon --- kernel/dma/swiotlb.c | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 52e2ac526757..3ba0f08a39a1 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,8 @@ 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; - } - + swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true); set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); - memset(tlb, 0, bytes); =20 io_tlb_default_mem =3D mem; swiotlb_print_info(); --=20 2.32.0.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623824560; cv=none; d=zohomail.com; s=zohoarc; b=VZ//RAJtt+CZE6U1O8ojcwU+62SQohE+dWfSQS0ZPmsENkSnQ4HeLaJHDoYzakJy0qWdAqSorn8QUPBQHkuPmcv9TBeCf7jeCCEykPAe9A02SfDEYpRV6Fh2qUydhVP0orxYwq8eNxvpZce7S87/qT2DvxGHOojJsVj4VRs9zOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824560; 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=U6ZYMbmpZtiKwFDcQ7JFrtewUpbfgXD5Ls9ZoD2Zrzg=; b=dk7fhJErgE8VZM/Dh61bsGfxOTU1HewezyLgxFnVMv5wBv4yxZ08b6wqMNY83BWbqn0DezSDAc2AyG2iEIZiR6KZBs61WkN1A0g/rJut5Ifc4H3lWYQHlH3xp4sh74g8plH/JrH3hOGBSb6XmJXGFTrDNAaeTpgxDbnmE+P7lYk= 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 1623824560568593.1722494256087; Tue, 15 Jun 2021 23:22:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142606.263095 (Exim 4.92) (envelope-from ) id 1ltOwX-00066k-73; Wed, 16 Jun 2021 06:22:29 +0000 Received: by outflank-mailman (output) from mailman id 142606.263095; Wed, 16 Jun 2021 06:22: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 1ltOwX-00066X-38; Wed, 16 Jun 2021 06:22:29 +0000 Received: by outflank-mailman (input) for mailman id 142606; Wed, 16 Jun 2021 06:22:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwV-00065R-Ow for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:22:27 +0000 Received: from mail-pj1-x1031.google.com (unknown [2607:f8b0:4864:20::1031]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1e131413-abd5-4670-85c2-77d3c2be2ad7; Wed, 16 Jun 2021 06:22:27 +0000 (UTC) Received: by mail-pj1-x1031.google.com with SMTP id i11-20020a17090a2acbb029016f0cce7c3fso912348pjg.3 for ; Tue, 15 Jun 2021 23:22:27 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id 21sm1024194pfy.92.2021.06.15.23.22.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:22:26 -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: 1e131413-abd5-4670-85c2-77d3c2be2ad7 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=U6ZYMbmpZtiKwFDcQ7JFrtewUpbfgXD5Ls9ZoD2Zrzg=; b=PJvHRcLLv4fhlWeXvSfKMQcWBxKOg+Fvvldtj3Y2Rwy0NG+fV8esg1TcKHxfLuji8x fALYR4BBGda9gTcNxGVF5jiXo1hdqXLQ9/EojERkZznhsp+lq9qt4VGs9UqStorOUfPe QcYH5iC4/YfxuhCJrGU8L8Q0LpoEXtWiU0umg= 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=U6ZYMbmpZtiKwFDcQ7JFrtewUpbfgXD5Ls9ZoD2Zrzg=; b=XFyrsUgnoDjKxePY9JvFfTnuPHu5aI3NwxkhcnumHTvR3lD9G5laVHUZxjOyBdXint vcpnMpGaafBT8k3EaxIJldQ/jzysMROKiQz+UDl2nEdmlOLv2gxpzGvhwo8E3mMR1lgP hg1Eygk/dOgFIP/1C9sDt1ttJ/F38WJwFL+TPExw2U6vsi+BLkqxX5AmPP0CToWmDLbM 1pSGxbHbfRgtHO9xDHR1eghmidEngevz3wghmcA/54bHZrZF9GV4anKLCIVJtCjD9+yd Nypn0kIW0hbPLtDTxplP42Xqug/Ah4FSLkPE5YBzVefxMgEY3Iqo/gHAbzVN+ImM50wA CIHw== X-Gm-Message-State: AOAM5333YX66TUefkJNy9SSUMJcahxl+kJutMgUa27apDIMZBHGKpPGl V4Y4y3Gaj3EoH7kLx2ExRSAERQ== X-Google-Smtp-Source: ABdhPJyVyel5b3yfzmvkqrYXS5Eq1yNF15/6agY067MF9HfP0+RZa2tjHWPks9M0csBX136+z0kj6g== X-Received: by 2002:a17:902:860b:b029:103:b23b:f1c3 with SMTP id f11-20020a170902860bb0290103b23bf1c3mr7842702plo.34.1623824546376; Tue, 15 Jun 2021 23:22:26 -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 Subject: [PATCH v12 02/12] swiotlb: Refactor swiotlb_create_debugfs Date: Wed, 16 Jun 2021 14:21:47 +0800 Message-Id: <20210616062157.953777-3-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: 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 3ba0f08a39a1..af416bcd1914 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -670,19 +670,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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623824572; cv=none; d=zohomail.com; s=zohoarc; b=jnBaMlu2j378Pswrz/FFZipz/UmGyeJr0j0C8XC3VivLdlRUdnMDmBqaB1qlUAOfe9aU+fp3VO4yM1X70wMu585mcLNvc0A3ymxngnnK4uQxrhpNBZebpuYu5Yz9pXSy4NP1WH3I3675+jo/NbkBcG9lvWG/iqhnuHGIAtjlFGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824572; 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=pEdYN/CfqowQHo6LUUVSljtyJhX5z4kEbgyPSIqEKts=; b=YZQK6+ITeaU5CfPqerxqZQYyNGlSUSqHrGwmp+wfzcA/AS1Wt0cNYhzSiCC7F5m69jCdMmwEk9PbduAR8svINPilI4vDLO1/Kg2hfyvtRk6/zkIwxCOa9RpiJBJ8XMK9w6AvdFV7q6r862eiHJKBTLUuyib2lYVA+q58tYwQ2sg= 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 1623824572165542.8283693009993; Tue, 15 Jun 2021 23:22:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142610.263106 (Exim 4.92) (envelope-from ) id 1ltOwi-0006j8-Ft; Wed, 16 Jun 2021 06:22:40 +0000 Received: by outflank-mailman (output) from mailman id 142610.263106; Wed, 16 Jun 2021 06:22:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwi-0006ix-Cl; Wed, 16 Jun 2021 06:22:40 +0000 Received: by outflank-mailman (input) for mailman id 142610; Wed, 16 Jun 2021 06:22:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwg-0006SS-CI for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:22:38 +0000 Received: from mail-pf1-x42a.google.com (unknown [2607:f8b0:4864:20::42a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1c449626-2437-4825-8057-472082ff1899; Wed, 16 Jun 2021 06:22:35 +0000 (UTC) Received: by mail-pf1-x42a.google.com with SMTP id y15so1354825pfl.4 for ; Tue, 15 Jun 2021 23:22:35 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id m2sm1096854pjf.24.2021.06.15.23.22.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:22:34 -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: 1c449626-2437-4825-8057-472082ff1899 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=pEdYN/CfqowQHo6LUUVSljtyJhX5z4kEbgyPSIqEKts=; b=EVy8q8LRlBwXjbv5ZgdM2So19WcSXgvUoCIgbciZgrT3bQ/Raz5EfpUl8QY1EeXxlR AtchZXRhTiVu8fzyfGqQsWJ/9eTD+e6JzMhRxq8qv1qy08hGq8Fg+qotTCOaejp1tcgi Xzx8bRHUlFhvQX+18c32FXdPsodjGeZnyhYIM= 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=pEdYN/CfqowQHo6LUUVSljtyJhX5z4kEbgyPSIqEKts=; b=ClUbMH1YFw0q7NWEIviWqXMF0Utcnjm1jdNWsCC/UZVtnwnvcAfEL2vi69CIu5CmGq 741fl/06nlt0GqViKobsFEShjPmrpXKX4N0upc4m7pXK/EcNlWpRuXqwD0ZZy/RVt5wS IHbc5tlmKJ/xoad8hPWsWmAFaxP+4oTIlNzpsl1+INfp6uDaE3JF5u/0oIlkjrApY2Yf YtjTpa2XA0Wh9IqyfJb+sfe0x3YdPRGe4FJVWlc+FsDj0QNeLbDsv9UC316fLC0YX+PJ qx9V2f2nnQTeBBRTtcsv7iqshml92FracLefyWa8YkYn7ToKx25UCLeoaUSknldmfci3 bwYA== X-Gm-Message-State: AOAM530sQHqFKNwzYbOuY1oc/sru+2lRMdlIGdSUpf4Ikn/rLLnl0INA 4rSaZU5d9hm3+3dtt8oLt5UZ3g== X-Google-Smtp-Source: ABdhPJwSkx5TMyTilGiVCcnPAeSvfxyOuh/e9rZIyr4xzr0620kbXFmZJ3BjZw8BvaIHoMpQs8L2Sw== X-Received: by 2002:a62:2785:0:b029:2ec:b165:db1f with SMTP id n127-20020a6227850000b02902ecb165db1fmr7950026pfn.34.1623824555026; Tue, 15 Jun 2021 23:22:35 -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 Subject: [PATCH v12 03/12] swiotlb: Set dev->dma_io_tlb_mem to the swiotlb pool used Date: Wed, 16 Jun 2021 14:21:48 +0800 Message-Id: <20210616062157.953777-4-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon --- 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 af416bcd1914..a9f5c08dd94a 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -339,7 +339,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; @@ -430,7 +430,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; @@ -507,7 +507,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; @@ -558,7 +558,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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623824578; cv=none; d=zohomail.com; s=zohoarc; b=HGI9IDaEeQarkGb70zbbM4qPHL/Pk0V3pT+GD2LWGuxEf53SjoBq7IERd+94DJkwWwydrd2eFurkMyJQfxlp2ztV2I/U7PbLBCHU4jEiWv52Xtz/rpxoD0sf8W4P2XbeFbEr0cXZPcZ0cOTpWKzGJaw7JZ4HzF2yM/TEXIAP2nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824578; 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=qgVN2ZlJMrK0ZQ+KxIYsV5GmxXVfYXxXGP7J+tRHaos=; b=ZUtiwdLiKJKC70QQb1n3lU+zk0ppfY6cvtZi62OzqQ1vqXFcD3dthMOcJ3vfI+o6Qy4j2C0an2CREIwMWElM2Lz2VehNKH2xeSeeS+dXNRhPcOX1KaW5BL/6SnlW9geHRzD0fvhDOJ9p6g9UCvsZwtmItEsyvl4FgDMSQCQ+824= 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 1623824578831638.3009326867463; Tue, 15 Jun 2021 23:22:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142613.263116 (Exim 4.92) (envelope-from ) id 1ltOwo-0007Es-U8; Wed, 16 Jun 2021 06:22:46 +0000 Received: by outflank-mailman (output) from mailman id 142613.263116; Wed, 16 Jun 2021 06:22:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwo-0007Eg-R3; Wed, 16 Jun 2021 06:22:46 +0000 Received: by outflank-mailman (input) for mailman id 142613; Wed, 16 Jun 2021 06:22:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwn-0007DA-Bn for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:22:45 +0000 Received: from mail-pj1-x1032.google.com (unknown [2607:f8b0:4864:20::1032]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 59979d36-ebd0-4c2f-a375-45dc75bc0ceb; Wed, 16 Jun 2021 06:22:44 +0000 (UTC) Received: by mail-pj1-x1032.google.com with SMTP id g24so1088006pji.4 for ; Tue, 15 Jun 2021 23:22:44 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id q23sm987071pff.175.2021.06.15.23.22.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:22:43 -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: 59979d36-ebd0-4c2f-a375-45dc75bc0ceb 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=qgVN2ZlJMrK0ZQ+KxIYsV5GmxXVfYXxXGP7J+tRHaos=; b=PZld1QjN9cC6qyAiQlWMGq58ojGyKGD0OvWirRWxGXNHoIwzW2but0Gm8wH4sIBEJn aIXZU6okb1sX7duIF8MvFO8dGYEYDukRHcVhEvcFXGI5C3vTDq+fxOKJevmGSJ8Rdjpe be2NRnHaX3ZOOzTU6z4ZH7BWle9WiAyXD4TMA= 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=qgVN2ZlJMrK0ZQ+KxIYsV5GmxXVfYXxXGP7J+tRHaos=; b=fYkA1nfybhUfhcZRoxucwXEZBwdVIbHJbmnRGjMewMYEG0yqxUDAf7SFXCYQBQrz16 bnP67Z0STNV+udQfZq/cWxs1OzCuGECITRDgNMmZX2sjE9nJLt4WhU/fYzWY8fF4tyZJ 78odp+leBBj11TGP1ufM2Wrzx38MsNZ2R7xVviZjAe+4ZR5JP/lgpgwjTJnclVw5+cSW /715Sg8OZVNLm6QAGpsaU1Pl15rlCkCxXDmq2Nh5yOH/2w/uZNbuZqoBtCEswLPxEuTO r17QAAj7P9x1YWnLXkDS6/WaI9boJoqvYdh67MCcnm+JBDTrBlJVrnOiExXwPWDau0sh btBg== X-Gm-Message-State: AOAM531cbhxlYusczzLG/qD6TNGhWWUOfgJyVsx09ITbkaHpZj6bR0hk OM6tcnXSHt5N4ir6xIJD5/FHKA== X-Google-Smtp-Source: ABdhPJzpzgCOKivn8rY3IxOSAbfDCKTaPReTRSBtzedOlZ2uVd6q3v0yAaSKsTkNrOCfP2FTDsiAsA== X-Received: by 2002:a17:90a:540d:: with SMTP id z13mr3445560pjh.159.1623824563630; Tue, 15 Jun 2021 23:22:43 -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 Subject: [PATCH v12 04/12] swiotlb: Update is_swiotlb_buffer to add a struct device argument Date: Wed, 16 Jun 2021 14:21:49 +0800 Message-Id: <20210616062157.953777-5-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon --- 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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623824587; cv=none; d=zohomail.com; s=zohoarc; b=G3jwWMC85YV3dw4qJOT7JjVmXMN2sSGsw70zzqf+ZVP9hx8smqeiilydaATpoFpYNT16z206QXf1gQTIeNvIWi2xuWs5krqvGhXi2KiwUpc+n1cHguymGoCr7YP8I7mEhNTE8nbzY8AdfvjIf2+be7SuDwGKxbslKElFsE0jL+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824587; 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=fDjj9RwGiHMHYf08qnwDA+ssC0u7zUi8VvqNHSt/pLY=; b=ku8osZMZ52eteB/7eZthXlxZVzUzvT5XqeMvl89ZyDJIi0elU3yCUFKsB7cgIuk+RfsmBxk82Ftcdmf/mK0kPhw5qdhk9tfid/Q6zYz3+/KDZGoyp6/mD3GMPhU203KiZNaRd9GoBAR+FWEd6RC7gp4YHkGShPbMTtVxaq+zFRQ= 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 1623824587183993.4815908362126; Tue, 15 Jun 2021 23:23:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142617.263128 (Exim 4.92) (envelope-from ) id 1ltOwx-0007k0-8i; Wed, 16 Jun 2021 06:22:55 +0000 Received: by outflank-mailman (output) from mailman id 142617.263128; Wed, 16 Jun 2021 06:22:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwx-0007jn-4s; Wed, 16 Jun 2021 06:22:55 +0000 Received: by outflank-mailman (input) for mailman id 142617; Wed, 16 Jun 2021 06:22:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOwv-0007gS-NB for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:22:53 +0000 Received: from mail-pf1-x436.google.com (unknown [2607:f8b0:4864:20::436]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8fbb8b62-c3cd-4d8d-b5bc-2911fc723675; Wed, 16 Jun 2021 06:22:52 +0000 (UTC) Received: by mail-pf1-x436.google.com with SMTP id y15so1355305pfl.4 for ; Tue, 15 Jun 2021 23:22:52 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id q23sm987609pff.175.2021.06.15.23.22.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:22:51 -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: 8fbb8b62-c3cd-4d8d-b5bc-2911fc723675 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=fDjj9RwGiHMHYf08qnwDA+ssC0u7zUi8VvqNHSt/pLY=; b=bPjT67wPmPfunMVw5qx31ETGuTCm2RR/+eH0A8svDKwhKwfx0BYl7eocGETox1lRoT 977YMxN4+A7BXPEtxRs1B0Lo85Jh14VIgB3QM4CD7Ib4/z6BrdB8jp0tztp/W6uPGqok edQ+sMvcRtQUwsPAFLHWSIBpT2O036z/Szk4w= 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=fDjj9RwGiHMHYf08qnwDA+ssC0u7zUi8VvqNHSt/pLY=; b=FrmKhhuCwJg9k27OJmFkXBqzJU431E5Q2ou70Bmm4SL5dzahUyzXZ0zX/bNLFrUXlV GQ8gew47FPbq9A1+8wD2yoZjc1EcgbS4cNsypN5D6E4F6cU73yYrpRXgib3kXF1iYk5Q bA0wDBijlWSCrkmzXtTptBVBzhcn5GiCc79NiIqvaKRtOZiiQmnTes/MbWQoI1X3GpZz lDhAfNoRYaXT+wRxxFIpPPP/Z+RfavD0MrVuRPd3iPUAOo8mHajWvi4X8cH3RcyQxeq9 tJZvrNC7i5IXWQBQZJaCK2djAJJo+KWr4QW9TSgNQ0cC6cLjEj0OUGTFlB20aG9nb3dk 2xJw== X-Gm-Message-State: AOAM533Fqhtd+YZwn214tLJTi5mhGLs+XdmhNdkNYjaszsRJuXhhjp/S sTQmSg9KWEmawm/0tzyxaarGJg== X-Google-Smtp-Source: ABdhPJx/kCYyXn4Tu5RgYPFt+4XicnJPGmv9fsFjoKCS/8liFbzjjxoVt1Ap3EAoVNJt5dkstWejkQ== X-Received: by 2002:a63:5d52:: with SMTP id o18mr3460733pgm.440.1623824572179; Tue, 15 Jun 2021 23:22:52 -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 Subject: [PATCH v12 05/12] swiotlb: Update is_swiotlb_active to add a struct device argument Date: Wed, 16 Jun 2021 14:21:50 +0800 Message-Id: <20210616062157.953777-6-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon --- 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 a9f5c08dd94a..101abeb0a57d 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -663,9 +663,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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623824602; cv=none; d=zohomail.com; s=zohoarc; b=eAlfp4k71GYceDmuouM9BvDR2888FNYIX8t4ZbBQ8pNl2u5Zg52Q9Gs31r3TF6fQ/982kYqMtAo/gGwhsCqH9dgeFMF9c+GCPj7klX2qyKykDRWOWWUajTDt1KMu1jN1jWqDYJxNddtZxQOJyMpKzSlZgCkBzTxBo0cbbCfLo2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824602; 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=yx1sBUKg2SZ/J5oPuuLxuIdituaRXED8so7Vw8sLIws=; b=fHnBQ4u9H0A5LZsENWjKiz99v7J3Urnz5OdkK+gbFJCUAWjRGGg5yZjJ3dQfOx8ezLolUuceXaZ5sWO2GxhPZKlQH2aFEeptv062WKesOFhl0FEfq2UssHM/K3F25OmbQaVt7nes3LURzJr2eW+59VaPeRs3m2LwRybZWUj5QTQ= 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 1623824602385636.6902475741714; Tue, 15 Jun 2021 23:23:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142624.263139 (Exim 4.92) (envelope-from ) id 1ltOxC-0000Cw-IB; Wed, 16 Jun 2021 06:23:10 +0000 Received: by outflank-mailman (output) from mailman id 142624.263139; Wed, 16 Jun 2021 06:23: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 1ltOxC-0000Co-FG; Wed, 16 Jun 2021 06:23:10 +0000 Received: by outflank-mailman (input) for mailman id 142624; Wed, 16 Jun 2021 06:23: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 1ltOxA-0007gS-HC for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:23:08 +0000 Received: from mail-pg1-x532.google.com (unknown [2607:f8b0:4864:20::532]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7906c1e4-39f2-4265-ab58-03d7d3f436a9; Wed, 16 Jun 2021 06:23:01 +0000 (UTC) Received: by mail-pg1-x532.google.com with SMTP id t13so1105359pgu.11 for ; Tue, 15 Jun 2021 23:23:01 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id f18sm4233834pjq.48.2021.06.15.23.22.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23: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: 7906c1e4-39f2-4265-ab58-03d7d3f436a9 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=yx1sBUKg2SZ/J5oPuuLxuIdituaRXED8so7Vw8sLIws=; b=Q4K6eTywavWHh5xBRTV2Sn1QN0pqm21rAHVV9HUXv/UP1w8xNe4Z5udU+NX1vgnB1+ c3YMRhLko40t5PNbJ2OEaPKxiaHUl4VjZBfqy96tFVH3Qfa8f64z0y648a814QEkXJ8w S/rgJ3x7L88xW9cuGs4qk0A1P9NST1SKpuLUA= 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=yx1sBUKg2SZ/J5oPuuLxuIdituaRXED8so7Vw8sLIws=; b=Kkjp/2hKp+A6/6EHhR1lpb2n7IDjOJdovWDudj/E4Xhx8j8Rr48HJQCoBPGnPaycIF 4K6NioejY88aPlO87wOLTEDSH+J0/XXkoylPW0nbm6HyJ7Y6vKYBs9rnfXOCoP8kePe7 cgW6ivWROcu9zE0Pib+DiDlSDJKykwmbDKaMYIH2qLUYIpOXvcowNoMNUE9oUEJsuKy9 u2UloizxfBw+Bjmi1yQIzST1TM5KvWxf/cmbB54b5ijNS+8M7oW0Gj5eE2IZhDOJh7BV 3IGq2oGz2Vjkv7+ciZqyYh+Zr8UIDYNajpQrdayv8q/t1CaQI3lZuIIMa2bjwgj+NLFD cjbA== X-Gm-Message-State: AOAM532ig/d+LX1gPfNjZSbfYRoEPBxAFN0cl7UoEcrM7lJ1uO6BRsqy AZbu4kDxAW/bO8UTVkuMfAnK+w== X-Google-Smtp-Source: ABdhPJw3qSZ6gJG41Gxh6T5HUfWmBlX+79o8LgLEBQMF8QRY4VhLx/+veYL/HvERe1FdH5EyrXhyxw== X-Received: by 2002:a63:4719:: with SMTP id u25mr3506046pga.193.1623824580858; Tue, 15 Jun 2021 23:23: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 Subject: [PATCH v12 06/12] swiotlb: Use is_swiotlb_force_bounce for swiotlb data bouncing Date: Wed, 16 Jun 2021 14:21:51 +0800 Message-Id: <20210616062157.953777-7-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon tested-by. --- include/linux/swiotlb.h | 11 +++++++++++ kernel/dma/direct.c | 2 +- kernel/dma/direct.h | 2 +- kernel/dma/swiotlb.c | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index dd1c30a83058..8d8855c77d9a 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,11 @@ 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) +{ + return dev->dma_io_tlb_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 +127,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 101abeb0a57d..b5a9c4c0b4db 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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623824622; cv=none; d=zohomail.com; s=zohoarc; b=hv/lY9/0OZkGtzLK6nPQqDudcBelFWcI2JRVP7wilC/5r4F+VK/T9gP5ay6H3AB/1h86aS4CeEdx8Tfz3VNAO1hA7PXkJxYzR/IzOouwctsh+fTsq5rDzIeneoNmR5utaUZNn9SCqHsEQsOhU4h2MpCNhH4jO6oeTWj6FMDowpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824622; 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=cTgFKnn3cLtvPfjI+55Cezw2EcnHDtp9/QQ3R2B3hUE=; b=hjSWqFsfDMOUEJoI01RNtQtfGLxof7OBUHrK3/S7M5pel4FJUj9uFKNS2bZWXuUgx1Gl38lkLQ07YpUcENvrpnw24/MdjCBUDZroH6InLf1tU3limISSY2JAHqdv9QBMY/dejAbh3O1McOIuV7O7D4sIYyYteXdn+CYVAmwCYfU= 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 1623824622407352.7614711573102; Tue, 15 Jun 2021 23:23:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142633.263150 (Exim 4.92) (envelope-from ) id 1ltOxV-0000xI-S1; Wed, 16 Jun 2021 06:23:29 +0000 Received: by outflank-mailman (output) from mailman id 142633.263150; Wed, 16 Jun 2021 06:23: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 1ltOxV-0000xB-OF; Wed, 16 Jun 2021 06:23:29 +0000 Received: by outflank-mailman (input) for mailman id 142633; Wed, 16 Jun 2021 06:23: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 1ltOxU-0007gS-I7 for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:23:28 +0000 Received: from mail-pj1-x1034.google.com (unknown [2607:f8b0:4864:20::1034]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id da795035-0c40-493b-9931-90ae26866678; Wed, 16 Jun 2021 06:23:10 +0000 (UTC) Received: by mail-pj1-x1034.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso1127147pjb.4 for ; Tue, 15 Jun 2021 23:23:10 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id f8sm960978pfv.73.2021.06.15.23.23.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:08 -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: da795035-0c40-493b-9931-90ae26866678 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=cTgFKnn3cLtvPfjI+55Cezw2EcnHDtp9/QQ3R2B3hUE=; b=cyJuCSilvPYniiPuEKQywgAZ2h40B6myx9TbQoS+O9qIihERcGr8FMpcEdjS0/tshr T6oF/Jqx7uEfUaJBG88Ds+6w77XhG2zyZ5Tn4UAWzJqH5XWwEFNMsFYg6ebrjJXldgCo SKPhXn/2f6RY0GqzhxLpDEImP7+pN5t8KYNM0= 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=cTgFKnn3cLtvPfjI+55Cezw2EcnHDtp9/QQ3R2B3hUE=; b=nChgnxE84+OhuWIzzK2Cz8tbKPdPN1su9PtluNo1Op2KMgkbj5/xd+Bdz/+M4qBgxZ MkAbvTGnM5tcbzfqnMdzhXKl0HxMV09wkGakcz9lCDwfxmzkLx6ePdWAjD+pK83/I6pQ nh+BOghMla3jYgNyhV1YQl6y+CG679YsbJMFVUFtzE7M6tuwB+cqO+4ftyWKt+qf//6e SsvutwI6HbHlqBIVrUgORGBPwOEaHlO6nQfCfPPohdWBM1em8hThH2XQpSGTz8Fi+6Ei HHzCBewew2SG0CREYRiSkRQBFVy88Or4/WWD8oU/wbM3B/Qq5BkgykQ73lmtgPIiewlj zxZA== X-Gm-Message-State: AOAM533/Hz7tWk+VYO7oUQRQMNDr6EeuJTuej9MZpH1UgNOMgp9E5N2e CM7fC8BKJPkptx/5KZcz6o8UyA== X-Google-Smtp-Source: ABdhPJxAvAAxvtMv6OUMS0EcucXOxwEcajpljVPpcHfCCwVFyghupOkDxlHVu6RexNkHSd0Tgg6RHw== X-Received: by 2002:a17:90a:9511:: with SMTP id t17mr3458123pjo.108.1623824589397; Tue, 15 Jun 2021 23:23: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 Subject: [PATCH v12 07/12] swiotlb: Move alloc_size to swiotlb_find_slots Date: Wed, 16 Jun 2021 14:21:52 +0800 Message-Id: <20210616062157.953777-8-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon --- kernel/dma/swiotlb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index b5a9c4c0b4db..b59e689aa79d 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -431,8 +431,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); @@ -487,8 +487,11 @@ static int find_slots(struct device *dev, phys_addr_t = orig_addr, return -1; =20 found: - for (i =3D index; i < index + nslots; i++) + for (i =3D index; i < index + nslots; i++) { mem->slots[i].list =3D 0; + mem->slots[i].alloc_size =3D + alloc_size - ((i - index) << IO_TLB_SHIFT); + } for (i =3D index - 1; io_tlb_offset(i) !=3D IO_TLB_SEGSIZE - 1 && mem->slots[i].list; i--) @@ -529,7 +532,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, @@ -543,11 +546,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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623824627; cv=none; d=zohomail.com; s=zohoarc; b=i+Y5Cz9G8gH5UHUEmzCWQffPMmjDlMToJTb5WNjsk0HdITYG9HsZtgh0XCmtTePyuny0tBg7Cdy4yvn+2HYK3xpS0dqGt9kU8URhOD8mZjdINWRf4bFgpXK60JHAoMfKaOchSvlNyhqxAeMFbbZ25s7UHRtk9RyJbLcqLhplWTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623824627; 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=4uQkI0iLfUCijuOepwUkiZcSLaj5vr9UchvXk27nRw0=; b=cMOWgEGD4sM37rFBVP5TBc/kOcepQxpUDieacDJ10q8LHHt0QTDecl1X18WFTt/SgO4keevW5CHGNv4Gyi4WBNdiilEpVhILd+Ls7tsAyYQFoJMmKG4bY97UXlPB9Dxu5Yv7IH//XQgxmjU72ZuEMOI5X/Szvwh/ByMWtiJXY5c= 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 1623824627370732.1488686260763; Tue, 15 Jun 2021 23:23:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142635.263161 (Exim 4.92) (envelope-from ) id 1ltOxb-0001LB-8t; Wed, 16 Jun 2021 06:23:35 +0000 Received: by outflank-mailman (output) from mailman id 142635.263161; Wed, 16 Jun 2021 06:23: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 1ltOxb-0001L2-5n; Wed, 16 Jun 2021 06:23:35 +0000 Received: by outflank-mailman (input) for mailman id 142635; Wed, 16 Jun 2021 06:23:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOxZ-0007gS-IA for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:23:33 +0000 Received: from mail-pg1-x536.google.com (unknown [2607:f8b0:4864:20::536]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1493b031-134f-4c35-9ab8-397669532dde; Wed, 16 Jun 2021 06:23:18 +0000 (UTC) Received: by mail-pg1-x536.google.com with SMTP id i34so1112831pgl.9 for ; Tue, 15 Jun 2021 23:23:18 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id a187sm943813pfb.66.2021.06.15.23.23.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:17 -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: 1493b031-134f-4c35-9ab8-397669532dde 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=4uQkI0iLfUCijuOepwUkiZcSLaj5vr9UchvXk27nRw0=; b=i8vpfgPJ9bPz7Z1Al2l+J6+mN/Xl35Xu1XE2A22X8XR/Zq8Z0ZAIZW1TRjKf3ok7nZ cVehop1oa/YF7qhuElQsqUmYkYcuOfcjTbNEd4KCXAUWVnRRY2/VoP7cICHlXtOyLHuZ HdMm+p5xlQYTdItRv/hg6efoNr1CAhA7jHk00= 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=4uQkI0iLfUCijuOepwUkiZcSLaj5vr9UchvXk27nRw0=; b=XIyZkHGMzspX8s4ctM1gXa/pldRiLtTirsrtyVQ7nD65/C5q5ttkWWhoRN2Q39QrYw 5YGjIPu8VqXDErdzbvtxBwKZ3vjVZh5ICrlbNSNuyFBvQczeikaDgT/t4SBX17YC5Eso 38VLbka6QbKFHTNwPMkmfyl+w/C5q5V4rtARTTHatX3tLsTpzAtnnd7NDLZj0p6HPm2y bMoyityIZJ0kEaKqHROiFzL3uW1Ckk29IPOpIH1hwSjFMcrnuhLBUGK8mi4ZdO6WYrMd yBvguoyhxpDjdvc1ikL1Lpxw8h1zfvCu2WzUZHbU/SC15cb5C91jTXMjh+mssQGNprAV syZg== X-Gm-Message-State: AOAM533/Z3fljTm8Zy0UITbWstE/5iKMGwomoY52Yv/2Ru1zZ6EqUNfw sn3kQbYaffQDmqJ4cof8IpVB7A== X-Google-Smtp-Source: ABdhPJzlTcTJITW8roEO1Qs6Oi6y2lI0FUouCTwChc7sW4UDPIgbdbK3IINTmKh9YLKWu+Lc6AZqFA== X-Received: by 2002:aa7:9118:0:b029:2eb:2ef3:f197 with SMTP id 24-20020aa791180000b02902eb2ef3f197mr7844722pfh.27.1623824597932; Tue, 15 Jun 2021 23:23:17 -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 Subject: [PATCH v12 08/12] swiotlb: Refactor swiotlb_tbl_unmap_single Date: Wed, 16 Jun 2021 14:21:53 +0800 Message-Id: <20210616062157.953777-9-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: 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 b59e689aa79d..688c6e0c43ff 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -555,27 +555,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. @@ -610,6 +598,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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623825113; cv=none; d=zohomail.com; s=zohoarc; b=NXPgQztLsjOoFcPVOxbuKsIyh2fdrxJx/QlzrXl/GHW/88l7gHdaC/+32tr0S8pMbxa1YSSrdDWRLkGOQsrxhtb5h2RhNvJNUspmv4rR6tX5iQT0vtsZKezP2Hl1M7okCLfSTfeAelgZUVgC79odLg3XvGj32ey96P94aJ5eKVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623825113; 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=//XvPeeos9rDreXGanBmItfF/L7P6KDOKno/Q971SkI=; b=nJtsY4QMq2NAuZ/Vja3RUYVBbCp7Ssk6ld2IPR9LIppfk+i0LCtVc8Gpf1lztP7OuhqW9y7M+gFftN7ywd0tRG4UBw95iiC3WsbSbbpg2ZwNPjj9apJI4tTaUJWuhZyPgvXdO6ojBKme5mMZEc7kchgi6Y1f3gR1pLlQe7b5cvw= 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 1623825113877529.9050767715498; Tue, 15 Jun 2021 23:31:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142665.263183 (Exim 4.92) (envelope-from ) id 1ltP5O-00042d-CB; Wed, 16 Jun 2021 06:31:38 +0000 Received: by outflank-mailman (output) from mailman id 142665.263183; Wed, 16 Jun 2021 06:31:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltP5O-00042W-8y; Wed, 16 Jun 2021 06:31:38 +0000 Received: by outflank-mailman (input) for mailman id 142665; Wed, 16 Jun 2021 06:31:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOxj-0007gS-Ii for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:23:43 +0000 Received: from mail-pf1-x42c.google.com (unknown [2607:f8b0:4864:20::42c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c28d7f57-0d72-49dc-ba48-629a3b062300; Wed, 16 Jun 2021 06:23:27 +0000 (UTC) Received: by mail-pf1-x42c.google.com with SMTP id k15so1341786pfp.6 for ; Tue, 15 Jun 2021 23:23:27 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id w23sm962726pfi.220.2021.06.15.23.23.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:26 -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: c28d7f57-0d72-49dc-ba48-629a3b062300 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=//XvPeeos9rDreXGanBmItfF/L7P6KDOKno/Q971SkI=; b=GTtz78AqdP/K84KwrCCWY+yBsCK9twtSZHRyXSvV/h2opQBzsZMnn60wDFOZINUrOZ 0URxUFIrHTlHymU+oZhs7U+vJo/L/4H0gb8jFa6zVJwXW+SAx8XnjdNmFzoaBe1BaNN9 vTj8mjzgSlRGdibtD+PBwbIuvuowKhfhtnBHE= 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=//XvPeeos9rDreXGanBmItfF/L7P6KDOKno/Q971SkI=; b=W3Jux/0rqQMoRkenm4oPvso7HKZ70xd92EeZcPe0PgwKOG17dr9w/uy0mxxoe4JYDa 3M7THn5rSIHlZX4gnJByEs5kMYwW+C5JLjHFDV6JEu2dz98ehCezMzeIYhrfk0AZAQ9O seR2kHgvu4Sbw8srswi08Gi26CPQOP8RXFZZNMCKWYqMxRVlvYR4nULtNk0TQn5UZURa ijtZBKDj/vWuMV9JsyNc10BITMf3/dRKoqmyocwqY0u4NuLnqFQGzkUI+SdjyM/+rvlk PrvUSBUp+W0Njs/mntR8Wi3lO30Nqvt66/dlASQAMvwn9V6QX7oTNiefQ/7V/EGlVJmk eJjg== X-Gm-Message-State: AOAM532O4nkAFbk4/l+4CAsnSZKHn+n3QCht5EbgN0Rcy3RxdyyutpR3 TChm/vLqRt9CCUjgM/nlR3P6Ww== X-Google-Smtp-Source: ABdhPJz6EHrLqZ49j895TpaXeqXynHRoBE7uCDjKORaP6OUYcVW6K9wplRvx6YQFZ25ZL8MPI1QCfA== X-Received: by 2002:a65:49c3:: with SMTP id t3mr3542154pgs.150.1623824606539; Tue, 15 Jun 2021 23:23:26 -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 Subject: [PATCH v12 09/12] swiotlb: Add restricted DMA alloc/free support Date: Wed, 16 Jun 2021 14:21:54 +0800 Message-Id: <20210616062157.953777-10-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon --- 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 8d8855c77d9a..a73fad460162 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; @@ -156,4 +158,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 688c6e0c43ff..d3d4f1a25fee 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -462,8 +462,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; } @@ -702,3 +703,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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623825117; cv=none; d=zohomail.com; s=zohoarc; b=WSguLeiN7gHgTtnXufmU6/3Q9Nl2xnwkps0gWM9AY4FfYHkyJjUnV5p452nSAbYVx7itzW3dDXNaWI6ij1NSzfcUItRV01OtfUPvdsS+CSFRxGbw2N3qaem0owjEtyEdf7bIv0ew6AOPNME+aWAiGbPsiEta73NlPs5Syv7te+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623825117; 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=fvqOnnEtZvf+5rDIUrGZxBrY9gGEpTlWY7ChHAnSGjQ=; b=MBNRQrHgs9gKR++7JT0CTHSS8Kc5NJAUB1qj57GHfvgR3dLs6MksiWPdXA7ibGYLSKxK/KHf7mfcWoeSRG4UzorMVHV3YphBwG9ClTes72UjCfzygpz5aT/0aEZRQLGvSjX8D0yA67Vz+M+5ZVk+2p3Rtt4uE4hVBWxY10Gt3mQ= 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 1623825117635866.8149553728118; Tue, 15 Jun 2021 23:31:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142671.263205 (Exim 4.92) (envelope-from ) id 1ltP5W-0004gg-0H; Wed, 16 Jun 2021 06:31:46 +0000 Received: by outflank-mailman (output) from mailman id 142671.263205; Wed, 16 Jun 2021 06:31:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltP5V-0004gM-Su; Wed, 16 Jun 2021 06:31:45 +0000 Received: by outflank-mailman (input) for mailman id 142671; Wed, 16 Jun 2021 06:31:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOxo-0007gS-Im for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:23:48 +0000 Received: from mail-pf1-x42a.google.com (unknown [2607:f8b0:4864:20::42a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8bb72469-fe6a-4543-a218-52917a668c0c; Wed, 16 Jun 2021 06:23:35 +0000 (UTC) Received: by mail-pf1-x42a.google.com with SMTP id x73so1330778pfc.8 for ; Tue, 15 Jun 2021 23:23:35 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id f18sm4236365pjq.48.2021.06.15.23.23.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:34 -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: 8bb72469-fe6a-4543-a218-52917a668c0c 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=fvqOnnEtZvf+5rDIUrGZxBrY9gGEpTlWY7ChHAnSGjQ=; b=CRDjTJny+g1kqwDU7SWfTmY39w2Rvq9MmzvXnaKADK16TTP156eE2b3ioWfQJOZ3tJ gXx3vsP7yjSxzXHOZ8RPJ4uBTExKTI64V9ahdlNBwF+jrYbdanOBblfWP2yVFyPYF/xm VSljuQBpG1I2SjGNTlKM4aUniu14NDyAl5pgE= 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=fvqOnnEtZvf+5rDIUrGZxBrY9gGEpTlWY7ChHAnSGjQ=; b=B5oKFNoXC6zfVeXkvWCP4nmQFd/zlm/g+G2uNkCXzeDi+wtQ95phpvXHRqK5meqrnf 2aRl5zpQl3VEBadCnn0kquwgNcnW1EdqlqHdgXtEfaGP+gzn/HoyNUiWXT4KUqoNc/wE zUq/ad5Kwl98UkOsZaN2+Uc9MfLCFxYeTHF7g3l0+3nYbQPcKp/TJa7Koh+zLN/CJdp6 hV0s6mIavQ4QY214NuaIXbrRnxZ+Xvir7ta5v/x56astIEJhxipbmzQ8kdjsOYyMkZoe VyiPzf/6HbnlLobqOBkXF4YZEHoHrOOYbubs4RHc9LpU3FntUrQmnJyeFIkoe8JQ3BDb M/eA== X-Gm-Message-State: AOAM530kpdI3g2t0lp9TLUwVMs1vCnDGGUBz5C0BxXfkpAoJV8C/n63b /Pbqze5UjOJmPpQYg2H+C7sz2w== X-Google-Smtp-Source: ABdhPJwB8iJBY8gdPjxo1XSBiCow9YJsHV8sERx41OovNyQ1fGlSSsxchqWWNEC/J5WyR15S1lTtNA== X-Received: by 2002:a63:3246:: with SMTP id y67mr3510828pgy.244.1623824615136; Tue, 15 Jun 2021 23:23:35 -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 Subject: [PATCH v12 10/12] swiotlb: Add restricted DMA pool initialization Date: Wed, 16 Jun 2021 14:21:55 +0800 Message-Id: <20210616062157.953777-11-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: 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 a73fad460162..175b6c113ed8 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 d3d4f1a25fee..8a4d4ad4335e 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 @@ -735,4 +742,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; + + swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false); + mem->force_bounce =3D true; + mem->for_alloc =3D true; + set_memory_decrypted((unsigned long)phys_to_virt(rmem->base), + rmem->size >> PAGE_SHIFT); + + 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.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623825114; cv=none; d=zohomail.com; s=zohoarc; b=SDmqKwPfeGcQsaIjo6ahHnhQpyo/5U03CgUH3uz4M3I/8mEOtgghJvM0IJuxhITJ8WtOjeK2p5k2kU3qU4sfj1JS+q2U9TmTvPJ7VG2nQl4qUxy3TZVZXNSvBrs2c20/koHEXXZIJwM/bBrMJRdCix2rtWONFn4IkY3SGdrMqWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623825114; 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=GymVnULBeJ03m5EPo7c7VEX7DSqoBwMT6L2fMWoeeEc=; b=IW0mpbMglW6SUwzGWmLYKl1f3sGIvkuwMc1Jn/KUXx1vZp/wg00EAd0qaoanqCVTA+qNVjCCQtud4rUJjMO9ThtZXqJbrjZy6CbDTcjScCGPfCkwGfwIzJl/Z89W5Cg3Q0LkjuBDlxu1dcqyinkKUpvW0a9Upgt0vxa4IQ00hTo= 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 1623825114041563.8466527181276; Tue, 15 Jun 2021 23:31:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142667.263193 (Exim 4.92) (envelope-from ) id 1ltP5Q-0004K5-NU; Wed, 16 Jun 2021 06:31:40 +0000 Received: by outflank-mailman (output) from mailman id 142667.263193; Wed, 16 Jun 2021 06:31:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltP5Q-0004Jy-KP; Wed, 16 Jun 2021 06:31:40 +0000 Received: by outflank-mailman (input) for mailman id 142667; Wed, 16 Jun 2021 06:31:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOxy-0007gS-J3 for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:23:58 +0000 Received: from mail-pg1-x533.google.com (unknown [2607:f8b0:4864:20::533]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ecd20f7a-d8a9-4f05-ae44-1afb6b9ba497; Wed, 16 Jun 2021 06:23:44 +0000 (UTC) Received: by mail-pg1-x533.google.com with SMTP id l184so1116931pgd.8 for ; Tue, 15 Jun 2021 23:23:44 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id s37sm1040984pfg.90.2021.06.15.23.23.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:43 -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: ecd20f7a-d8a9-4f05-ae44-1afb6b9ba497 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=GymVnULBeJ03m5EPo7c7VEX7DSqoBwMT6L2fMWoeeEc=; b=U3eun+ENVyocWxLJj29G6RCpfONi9/U6hPEIyZyKw371lsv5ZvHOuZIFA51JbRET1+ Op95gA7j695YxlxlvZL3RhiG4sat3KCnGzJWEyj6V60Tnw5upJgOTBhRDMBdHFtlUqmv mWPc8X3tmbnhBe3Nq+XG0xr87l9VopnL/TOas= 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=GymVnULBeJ03m5EPo7c7VEX7DSqoBwMT6L2fMWoeeEc=; b=lm5BINg7YSrP52/1PXnvJGtF2QfgKiZ5Bpkrdjty4KOMb2BnjKL1Nj5UisJQNG7QdX saFGwUIR9qSikmM3RQBaHOSaaJx85dX4pXTVbqg2J+lbgXdOIUuXHE0RQrN1AVcReNDD oSEI+fLWVJ9RDij4Uq5qnoUwaxYIgnoz/IL5Ic3V0LXH0Z3IWwsjMGhKl1qdYeImTqeC enL1vGBFbxsEZihT0wWxcDCxUkOlJRNcKUGV6ByWszYEkpWaC9/vrRipMjfWBt74g+Vt UeXkUTp0encULsZ/YwYh+e/AenqJDFFxT++odYm8gvsCxu3bAB11M5FE+ROMCeobCdle b7oQ== X-Gm-Message-State: AOAM532JKjaR2VCBuxl7Yttf2TSRKE0C4GkTZAJ6IyMJqgrOuHdPCG8n +8iihbqxLb3wkfanPaVGnfSHqw== X-Google-Smtp-Source: ABdhPJzos0AE316eqwE5bukVSiSBXorK5IVepm+pS66FYVRIq/CQ/YuE4vEFUrrRi3iREp0s0X/Ddw== X-Received: by 2002:a63:6e87:: with SMTP id j129mr3484297pgc.45.1623824623702; Tue, 15 Jun 2021 23:23:43 -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 Subject: [PATCH v12 11/12] dt-bindings: of: Add restricted DMA pool Date: Wed, 16 Jun 2021 14:21:56 +0800 Message-Id: <20210616062157.953777-12-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: 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..46804f24df05 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_mem_reserved>; + /* ... */ + }; }; --=20 2.32.0.272.g935e593368-goog From nobody Sun May 5 02:17:59 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=1623825131; cv=none; d=zohomail.com; s=zohoarc; b=Kc3oDkhbDqyeqP1dX5N0sROf+t8ylAtsgeNS4njCj8WRJnXjwsvhgGkJSaKInKPldIHDRX3I5BFk1hbMSOivOeHMbWK+0rJeMlFs/6xatjhgqm7Pk4acPHOqC6DM3o7TuMyg9pyESL4jgUYHdQ9vJCGSHJi16irfu+9mng26O3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623825131; 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=4psftO+uH/TVnoki1qOI27Xe5kV3FYGMoE+zQAlSb7o=; b=HsWDklizbb+9PiW295j7p7S4YHFQZ2m9Xz7AuFFbcc4cr9ykjnVWOTrbSu4T88LOUXdNj3Auu2kjJHJkZyTp9RbpyUj8RMLWBKbXhdR/vYB+uyeVIPG+9vK9OBc/dpEqOkxHHNryW/U9w6ADuSZ/QLFLKcI648l3OF6iXLNOZqk= 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 1623825131946545.6102111798923; Tue, 15 Jun 2021 23:32:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142678.263216 (Exim 4.92) (envelope-from ) id 1ltP5h-0005LZ-7S; Wed, 16 Jun 2021 06:31:57 +0000 Received: by outflank-mailman (output) from mailman id 142678.263216; Wed, 16 Jun 2021 06:31:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltP5h-0005Kp-4K; Wed, 16 Jun 2021 06:31:57 +0000 Received: by outflank-mailman (input) for mailman id 142678; Wed, 16 Jun 2021 06:31:55 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOy8-0007gS-JC for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:24:08 +0000 Received: from mail-pf1-x435.google.com (unknown [2607:f8b0:4864:20::435]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6b1491c1-09a5-4755-8e83-7151d1949dba; Wed, 16 Jun 2021 06:23:53 +0000 (UTC) Received: by mail-pf1-x435.google.com with SMTP id h12so1364045pfe.2 for ; Tue, 15 Jun 2021 23:23:53 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id j13sm1144475pgp.29.2021.06.15.23.23.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:51 -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: 6b1491c1-09a5-4755-8e83-7151d1949dba 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=4psftO+uH/TVnoki1qOI27Xe5kV3FYGMoE+zQAlSb7o=; b=V/ahoq2vs8tTy7w+Y5OEwDE5hShbh8znTC5ewffraAkNPn/O4nZhX/k5O/Q4vn+BYw sVVqtxW5hQdZQN9GpVNrLf5hjnu+aW1hXGdh6T0neJbe4VzN1V/QXoB+hgAnMu1VsF+r sglWPBXIWMNhL2qZeTlT+lltwdWi+fBX8GceE= 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=4psftO+uH/TVnoki1qOI27Xe5kV3FYGMoE+zQAlSb7o=; b=T9a7k/fArYc7db8jismCo8ZfdIYWi1h6jF5NYjL6cJS4DKQkIlIGgmjbKdPHamBxJF 2MKid/S/DpCnLRrekcBOax+p3peGmBzkbGMqZdNZrOqcHAmD+PMNcmoaJ0bdqyilxBgX w+DKF2/OUnfmjcKL3ve5cOTiiqUF9fJ1KpGV7ilUAAUhLKo8syr+H5Nu55qVMBCyqzlv 0N/eUkjfJ9jPA6xPz/qAfg+e939+vv8IpbzkHBs3te7lNP+yOAMwvJx7gWYyzmmzSoHh fcrWIjNS/7PJ2jzQbVECMxrRoBfA0CLoBhiWkfX8Ezr6Bc0jadhilUqKmaSJvqmBSGxX 3psw== X-Gm-Message-State: AOAM530zx047OZmtwOI0XrH8fQ7ZmozitofZpifemDzebqkxfZWAI/pa SKg4o31Pe6G1xtn/ffEGNw7cMw== X-Google-Smtp-Source: ABdhPJzGZYWYJboxtRbRv1n6aZlIOVWrHtwOTnE26briGp5Jug1JkMDb00dOZitCigU2dddBDVGa/Q== X-Received: by 2002:a62:ae03:0:b029:2f8:b04f:c012 with SMTP id q3-20020a62ae030000b02902f8b04fc012mr8079076pff.62.1623824632264; Tue, 15 Jun 2021 23:23:52 -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 Subject: [PATCH v12 12/12] of: Add plumbing for restricted DMA pool Date: Wed, 16 Jun 2021 14:21:57 +0800 Message-Id: <20210616062157.953777-13-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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: Will Deacon --- 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.272.g935e593368-goog