From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47B1BC433ED for ; Thu, 20 May 2021 06:39:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 254EE61184 for ; Thu, 20 May 2021 06:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbhETGkx (ORCPT ); Thu, 20 May 2021 02:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbhETGkw (ORCPT ); Thu, 20 May 2021 02:40:52 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B999C061574 for ; Wed, 19 May 2021 23:39:31 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id v4so12042587qtp.1 for ; Wed, 19 May 2021 23:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=e/NSxqpkIDrHAb8EdngT+J5y92xOhsZUELUZeumbo14=; b=XZhu4NB364LO5HgzFR5xaRq+2+Ny8I/tbuM557W/djcP2WZR5/YY1P3k16G0KqQZ5g 9wOC75EFGAaEHt77aJ4y5qFZynUNK1/otklqj7so1biOf1FGROrwm/ILpXyxkwLvM+aC k3452c8bAQ6BEmJklQOi+zYSoBDbgxiFQQFO0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=e/NSxqpkIDrHAb8EdngT+J5y92xOhsZUELUZeumbo14=; b=hEBcYj4pS3QRbMIfARPpaimSt2gQltA8g/byt0KuLQzJE0YjKvOp8chXl5uID1UQuC FF3EqoRGgHb7+vi+CAQ0/oddUZCfiAeOORaZEP/oOpPbxRXuQbUi0PEdfQP+mDrX8ZrB Nt2Z1saBss18xNOrNNkIGWXb1wjemDBbKvg/dJTlH6nV6BkDQ/qnze4fdSSx+jfsqiK4 6TZ3Yb2HUqJSyRpzlztLIoWtN4+FDBm7aMNAXAH2PushYGQvTP9KM+sQqa0PUqDXm1xD 0cM4MbT1rzZwt3IRmkOiK4tc9dH9CHly5QXKQ9kjv9dU6jeYHAyPF4UXxLpcu0yzg4HJ p2Kw== X-Gm-Message-State: AOAM533NOZOSa3h+tyT/qWrGoTGNigXUpD2qU7CspArhsdcUZdFwgIP2 JZFCwqDEYlnCMtzLp0LjicIKdBgebOB2TA== X-Google-Smtp-Source: ABdhPJz5q6foA2qJcJ/WP1O/xeeXsCHFpnEVEzyCJFbZzZyme3eACyiVVlmoTYwW2sw9V7jOq0UVTw== X-Received: by 2002:ac8:5205:: with SMTP id r5mr3543180qtn.305.1621492770504; Wed, 19 May 2021 23:39:30 -0700 (PDT) Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com. [209.85.160.170]) by smtp.gmail.com with ESMTPSA id g5sm1469478qtm.2.2021.05.19.23.39.30 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 May 2021 23:39:30 -0700 (PDT) Received: by mail-qt1-f170.google.com with SMTP id m13so12007342qtk.13 for ; Wed, 19 May 2021 23:39:30 -0700 (PDT) X-Received: by 2002:a05:6638:14ce:: with SMTP id l14mr3931980jak.90.1621492759440; Wed, 19 May 2021 23:39:19 -0700 (PDT) MIME-Version: 1.0 References: <20210518064215.2856977-1-tientzu@chromium.org> <20210518064215.2856977-5-tientzu@chromium.org> In-Reply-To: From: Claire Chang Date: Thu, 20 May 2021 14:39:08 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 04/15] swiotlb: Add restricted DMA pool initialization To: Florian Fainelli Cc: 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 , 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 , Tomasz Figa , bskeggs@redhat.com, Bjorn Helgaas , chris@chris-wilson.co.uk, Daniel Vetter , airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, Jianxiong Gao , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Thu, May 20, 2021 at 2:54 AM Florian Fainelli wrote: > > > > On 5/17/2021 11:42 PM, Claire Chang wrote: > > Add the initialization function to create restricted DMA pools from > > matching reserved-memory nodes. > > > > Signed-off-by: Claire Chang > > --- > > include/linux/device.h | 4 +++ > > include/linux/swiotlb.h | 3 +- > > kernel/dma/swiotlb.c | 76 +++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 82 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/device.h b/include/linux/device.h > > index 38a2071cf776..4987608ea4ff 100644 > > --- a/include/linux/device.h > > +++ b/include/linux/device.h > > @@ -416,6 +416,7 @@ struct dev_links_info { > > * @dma_pools: Dma pools (if dma'ble device). > > * @dma_mem: Internal for coherent mem override. > > * @cma_area: Contiguous memory area for dma allocations > > + * @dma_io_tlb_mem: Internal for swiotlb io_tlb_mem override. > > * @archdata: For arch-specific additions. > > * @of_node: Associated device tree node. > > * @fwnode: Associated device node supplied by platform firmware. > > @@ -521,6 +522,9 @@ struct device { > > #ifdef CONFIG_DMA_CMA > > struct cma *cma_area; /* contiguous memory area for dma > > allocations */ > > +#endif > > +#ifdef CONFIG_DMA_RESTRICTED_POOL > > + struct io_tlb_mem *dma_io_tlb_mem; > > #endif > > /* arch specific additions */ > > struct dev_archdata archdata; > > diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h > > index 216854a5e513..03ad6e3b4056 100644 > > --- a/include/linux/swiotlb.h > > +++ b/include/linux/swiotlb.h > > @@ -72,7 +72,8 @@ extern enum swiotlb_force swiotlb_force; > > * range check to see if the memory was in fact allocated by this > > * API. > > * @nslabs: The number of IO TLB blocks (in groups of 64) between @start and > > - * @end. This is command line adjustable via setup_io_tlb_npages. > > + * @end. For default swiotlb, this is command line adjustable via > > + * setup_io_tlb_npages. > > * @used: The number of used IO TLB block. > > * @list: The free list describing the number of free entries available > > * from each index. > > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > > index b849b01a446f..1d8eb4de0d01 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 > > > > #include > > #include > > @@ -690,3 +697,72 @@ static int __init swiotlb_create_default_debugfs(void) > > late_initcall(swiotlb_create_default_debugfs); > > > > #endif > > + > > +#ifdef CONFIG_DMA_RESTRICTED_POOL > > +static int rmem_swiotlb_device_init(struct reserved_mem *rmem, > > + struct device *dev) > > +{ > > + struct io_tlb_mem *mem = rmem->priv; > > + unsigned long nslabs = rmem->size >> IO_TLB_SHIFT; > > + > > + if (dev->dma_io_tlb_mem) > > + return 0; > > + > > + /* > > + * Since multiple devices can share the same pool, the private data, > > + * io_tlb_mem struct, will be initialized by the first device attached > > + * to it. > > + */ > > + if (!mem) { > > + mem = kzalloc(struct_size(mem, slots, nslabs), GFP_KERNEL); > > + if (!mem) > > + return -ENOMEM; > > + > > + if (PageHighMem(pfn_to_page(PHYS_PFN(rmem->base)))) { > > + kfree(mem); > > + return -EINVAL; > > This could probably deserve a warning here to indicate that the reserved > area must be accessible within the linear mapping as I would expect a > lot of people to trip over that. Ok. Will add it. > > Reviewed-by: Florian Fainelli > -- > Florian