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.0 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 6A3C4C433B4 for ; Mon, 26 Apr 2021 16:46:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BD676103E for ; Mon, 26 Apr 2021 16:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234598AbhDZQqt (ORCPT ); Mon, 26 Apr 2021 12:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234595AbhDZQqs (ORCPT ); Mon, 26 Apr 2021 12:46:48 -0400 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15034C061574 for ; Mon, 26 Apr 2021 09:46:06 -0700 (PDT) Received: by mail-qt1-x82a.google.com with SMTP id o1so435458qta.1 for ; Mon, 26 Apr 2021 09:46:06 -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=KlgosoMJOAaR/ET01AhknsNf3mj6gtcliiDg0dLL1e0=; b=FfxC6YTfTyKRjULzScvZeh080rowzObsgfkNkB6PbFU85WK18TorFZb3nTplFpotQN FCzKzeHFiWHC6SAAz0H1ZvobWir4E6RenbNbEqtrFbyTUyimRczwWol0BDixJHUTha+x eXWW6lC9g26ZhTBX/V5pk140gf+3zGj/JaWxQ= 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=KlgosoMJOAaR/ET01AhknsNf3mj6gtcliiDg0dLL1e0=; b=t1RmiE5naQgWua4ZDtGC9fu/7Bu4wPCt7+WaBmSGcCmbHdzggJw81QDJc4LizjMMJu vd0wlPKdWp22A/QIKkIsyUbkJzUm5noV11X5D7IlW4nHMs+miTPsk0xHuDRn89n6BhXZ n26LfiOYxFbTnVnhkIGr+WE3b8RbKIBa3lPniWZRB08a2JF7UuLQjmHgo269NMqYVeIh YzOH7f6mNQrDbe1zkPQMrwRae8vEKvC3oHIdTe6IPJg0yYJu7Cx3bDSKnHuWCPp0SaxN VZOaoAAadV28l9Sg31gcFZ//Lbd1IuZLN8APruTFWhwmFp6WCZaUjUcKzHqYnH6iz4c3 dEjQ== X-Gm-Message-State: AOAM532nMKdp+QJhSSQ9Re2DamO8/pIC+ngeI3I+2F98rYFzIzV735jS HZxukbVAwaK0gyVAoaziCT9VjPmZvAXurA== X-Google-Smtp-Source: ABdhPJxoeeisQKdFEhk0mRNa7XX6+At+v/oGvchXVFsN9mVy4qvkM5eAHqAndJCrbT42ssidX09KQA== X-Received: by 2002:ac8:5a4f:: with SMTP id o15mr604813qta.383.1619455565094; Mon, 26 Apr 2021 09:46:05 -0700 (PDT) Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com. [209.85.160.178]) by smtp.gmail.com with ESMTPSA id 198sm514193qkf.20.2021.04.26.09.46.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:46:04 -0700 (PDT) Received: by mail-qt1-f178.google.com with SMTP id a18so18285392qtj.10 for ; Mon, 26 Apr 2021 09:46:04 -0700 (PDT) X-Received: by 2002:a05:6638:68b:: with SMTP id i11mr17242768jab.90.1619455099476; Mon, 26 Apr 2021 09:38:19 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> <03c5bc8a-3965-bf1d-01a4-97d074dfbe2b@arm.com> In-Reply-To: <03c5bc8a-3965-bf1d-01a4-97d074dfbe2b@arm.com> From: Claire Chang Date: Tue, 27 Apr 2021 00:38:08 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 16/16] of: Add plumbing for restricted DMA pool To: Robin Murphy Cc: 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, 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, nouveau@lists.freedesktop.org, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Fri, Apr 23, 2021 at 9:35 PM Robin Murphy wrote: > > On 2021-04-22 09:15, Claire Chang wrote: > > If a device is not behind an IOMMU, we look up the device node and set > > up the restricted DMA when the restricted-dma-pool is presented. > > > > Signed-off-by: Claire Chang > > --- > > drivers/of/address.c | 25 +++++++++++++++++++++++++ > > drivers/of/device.c | 3 +++ > > drivers/of/of_private.h | 5 +++++ > > 3 files changed, 33 insertions(+) > > > > diff --git a/drivers/of/address.c b/drivers/of/address.c > > index 54f221dde267..fff3adfe4986 100644 > > --- a/drivers/of/address.c > > +++ b/drivers/of/address.c > > @@ -8,6 +8,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > > } > > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > > > +int of_dma_set_restricted_buffer(struct device *dev) > > +{ > > + struct device_node *node; > > + int count, i; > > + > > + if (!dev->of_node) > > + return 0; > > + > > + count = of_property_count_elems_of_size(dev->of_node, "memory-region", > > + sizeof(phandle)); > > + for (i = 0; i < count; i++) { > > + node = of_parse_phandle(dev->of_node, "memory-region", i); > > + /* There might be multiple memory regions, but only one > > + * restriced-dma-pool region is allowed. > > + */ > > What's the use-case for having multiple regions if the restricted pool > is by definition the only one accessible? There might be a device coherent pool (shared-dma-pool) and dma_alloc_attrs might allocate memory from that pool [1]. I'm not sure if it makes sense to have another device coherent pool while using restricted DMA pool though. [1] https://elixir.bootlin.com/linux/v5.12/source/kernel/dma/mapping.c#L435 > > Robin. > > > + if (of_device_is_compatible(node, "restricted-dma-pool") && > > + of_device_is_available(node)) > > + return of_reserved_mem_device_init_by_idx( > > + dev, dev->of_node, i); > > + } > > + > > + return 0; > > +} > > + > > /** > > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > > * @np: device node > > diff --git a/drivers/of/device.c b/drivers/of/device.c > > index c5a9473a5fb1..d8d865223e51 100644 > > --- a/drivers/of/device.c > > +++ b/drivers/of/device.c > > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > > > + if (!iommu) > > + return of_dma_set_restricted_buffer(dev); > > + > > return 0; > > } > > EXPORT_SYMBOL_GPL(of_dma_configure_id); > > diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h > > index d717efbd637d..e9237f5eff48 100644 > > --- a/drivers/of/of_private.h > > +++ b/drivers/of/of_private.h > > @@ -163,12 +163,17 @@ struct bus_dma_region; > > #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA) > > int of_dma_get_range(struct device_node *np, > > const struct bus_dma_region **map); > > +int of_dma_set_restricted_buffer(struct device *dev); > > #else > > static inline int of_dma_get_range(struct device_node *np, > > const struct bus_dma_region **map) > > { > > return -ENODEV; > > } > > +static inline int of_dma_get_restricted_buffer(struct device *dev) > > +{ > > + return -ENODEV; > > +} > > #endif > > > > #endif /* _LINUX_OF_PRIVATE_H */ > >