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 1E9E7C433B4 for ; Mon, 26 Apr 2021 16:44:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFE6A61059 for ; Mon, 26 Apr 2021 16:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234673AbhDZQoq (ORCPT ); Mon, 26 Apr 2021 12:44:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234559AbhDZQoo (ORCPT ); Mon, 26 Apr 2021 12:44:44 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B75EC061574 for ; Mon, 26 Apr 2021 09:44:01 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id 8so23380484qkv.8 for ; Mon, 26 Apr 2021 09:44:01 -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=toBtHq0iPz/ATchwd8M6aPNac/V5UTH9pGkHRjyqW4exylYVdsAuF8tbuLHyNtBZHL YW1d/7mKo9BFrEJ+q4CG6MV1vSj64Yxu56rp2svtU4Ar6+B3coPUeUL0smNLDbLmrpvL E4EV32vZ/STL/edhY8eTjToX0yRLrRZ9w2uNufn7arU7xe3tSLiQ3fYchq1WIBkIoMzV maI4s/xmCv+dwUFk4KWNAb4VoirdSSW+rNs//kJctODqNLvQO59yXlk5pQnnk75zXSLe Zv1KYs07zaBbfgtKQU3eRn0YrMZzEeMBS/EWdnQhr1HuHxUWsRb4CXyMCRlqTfIOWdqa UJ1w== X-Gm-Message-State: AOAM532BXKLJQBP7b41n9i5n2Bi12xfvl0e7mYbIZeCmYx4+mnf7pjb+ eXTYGkmi2Yd5zT2nDCpD4dTrVia0dUalUg== X-Google-Smtp-Source: ABdhPJxWtowEfKf8HZ0+CPgajbB/hNDXcFrWAJLIbao2LFUBvFuWspeye+ZvNs7MIgup97zwXjJe7g== X-Received: by 2002:a37:e06:: with SMTP id 6mr18708102qko.373.1619455440475; Mon, 26 Apr 2021 09:44:00 -0700 (PDT) Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com. [209.85.160.179]) by smtp.gmail.com with ESMTPSA id 7sm6189626qtu.38.2021.04.26.09.44.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:44:00 -0700 (PDT) Received: by mail-qt1-f179.google.com with SMTP id z5so3916719qts.3 for ; Mon, 26 Apr 2021 09:44:00 -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: linux-kernel@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 */ > > 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 34738C433B4 for ; Mon, 26 Apr 2021 16:46:36 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 93CDE60BBB for ; Mon, 26 Apr 2021 16:46:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93CDE60BBB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FTW4p0WX0z301L for ; Tue, 27 Apr 2021 02:46:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=FfxC6YTf; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=chromium.org (client-ip=2607:f8b0:4864:20::72a; helo=mail-qk1-x72a.google.com; envelope-from=tientzu@chromium.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=FfxC6YTf; dkim-atps=neutral Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FTW462m3wz30Bc for ; Tue, 27 Apr 2021 02:45:58 +1000 (AEST) Received: by mail-qk1-x72a.google.com with SMTP id k127so1523032qkc.6 for ; Mon, 26 Apr 2021 09:45:57 -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=oqe0IYzbg+tf9btGzReFjCNiEf7gfbp3vq4D6VHRVEU3ZyvPhdEw4lWOBSPmCqrNqg rOAMBj9f0ic0Bxo5qjPLUwtBSMYs6pmbHOMpgc+qIgEeTOVq6luzaYH2YvaOVtHESckS DRGEOXTjuLZq9n9Xix5aMw/mVAATrpvkCyMwqvdGYIdFAHutufqWWCSPRQlub1fDCBK7 eHibhTNA2tn94om7ic+KkRbEMnYhRPasunTPV1REu5l29Nb0uDChKrgAzmC4V64rarAP I7RxM0cKGljwRNCNy8xVZqBy5lMB9gYs8vtqKSS35/ImUzLbMiHO1ptQ/HS7SVWZZRzf 0Afg== X-Gm-Message-State: AOAM532Zv1A9pb9JM/VcafqfNVCKEUhJ8eNiWPsbgl7j3WG/VPoLlsS3 AbbS8Xlk2ExFE5qfyDNJSD4icY3RXTmLQQ== X-Google-Smtp-Source: ABdhPJzxzU+ImBzb/sTTOwXvRg6fSCzun2ybzwqmjfoGKlpov9xloSr5TGWXZaX+g4w88H9Jh+s+Jw== X-Received: by 2002:a37:680e:: with SMTP id d14mr19009605qkc.48.1619455554938; Mon, 26 Apr 2021 09:45:54 -0700 (PDT) Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com. [209.85.222.175]) by smtp.gmail.com with ESMTPSA id o130sm462231qke.121.2021.04.26.09.45.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:45:54 -0700 (PDT) Received: by mail-qk1-f175.google.com with SMTP id y136so25032555qkb.1 for ; Mon, 26 Apr 2021 09:45:54 -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 Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, joonas.lahtinen@linux.intel.com, dri-devel@lists.freedesktop.org, lkml , grant.likely@arm.com, paulus@samba.org, Will Deacon , mingo@kernel.org, Marek Szyprowski , sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, Joerg Roedel , "Rafael J . Wysocki" , Christoph Hellwig , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , Jianxiong Gao , Daniel Vetter , Konrad Rzeszutek Wilk , maarten.lankhorst@linux.intel.com, airlied@linux.ie, Dan Williams , jani.nikula@linux.intel.com, Nicolas Boichat , rodrigo.vivi@intel.com, Bjorn Helgaas , boris.ostrovsky@oracle.com, Andy Shevchenko , jgross@suse.com, chris@chris-wilson.co.uk, nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , Frank Rowand , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 */ > > 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 5098EC43460 for ; Mon, 26 Apr 2021 22:23:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E6CDC61103 for ; Mon, 26 Apr 2021 22:23:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6CDC61103 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=nouveau-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69F436E8A0; Mon, 26 Apr 2021 22:23:08 +0000 (UTC) Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2F7996E852 for ; Mon, 26 Apr 2021 16:46:28 +0000 (UTC) Received: by mail-qv1-xf2d.google.com with SMTP id gv2so18242444qvb.8 for ; Mon, 26 Apr 2021 09:46:28 -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=kriSkIUhuN//iL2UN5BWfpDehrDaZ2VEE/2YHp2CiQzKbY/oLMPKsI0qJGhdop8Fvx sbVXShnf+WGN0pVnFe4igj59uuTVp+SqJaxphGtMu/2+I3FsaBHYKR2j6qTJLft0UxTO VaJpU3yrZolGm7Z0incj6iEF+Wz3HTxmk4EBRmHgfttU6lw1LdprYaVAKD+phIeOD8k+ lew1RnNdz92LrJEN/M8Rwl4lHMGEcwvwDWvYDExO+SF6D+2Vm1FO6JYsC+S90oZ4BEXk QOZa9oO11fPcMvZbwJ27HgmpwdCwefKmW1Tj/iLUum9eM89MPz3URHOnHbHcmohCSo7a SJzg== X-Gm-Message-State: AOAM531AwRKdxZyEuTJf2mux/2fJqthkKcniV7r0XAJgj4+HmKC62mV2 OnzOMYqyz+6X2x5D5765XuEpTTKv94bhTA== X-Google-Smtp-Source: ABdhPJxePJeMHsUmhMzmyC6ALoANhfU4wViaRKCx/d9seVt85TBvS2HbJdo0LvPhZGXXvuaXKX7+2g== X-Received: by 2002:ad4:5f8a:: with SMTP id jp10mr19029320qvb.56.1619455587043; Mon, 26 Apr 2021 09:46:27 -0700 (PDT) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com. [209.85.160.180]) by smtp.gmail.com with ESMTPSA id t63sm537748qkh.6.2021.04.26.09.46.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:46:26 -0700 (PDT) Received: by mail-qt1-f180.google.com with SMTP id g1so374868qtq.6 for ; Mon, 26 Apr 2021 09:46:26 -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: To: Robin Murphy X-Mailman-Approved-At: Mon, 26 Apr 2021 22:23:06 +0000 Subject: Re: [Nouveau] [PATCH v5 16/16] of: Add plumbing for restricted DMA pool X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, benh@kernel.crashing.org, joonas.lahtinen@linux.intel.com, dri-devel@lists.freedesktop.org, lkml , grant.likely@arm.com, paulus@samba.org, Will Deacon , mingo@kernel.org, Marek Szyprowski , sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, Joerg Roedel , "Rafael J . Wysocki" , Christoph Hellwig , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , Jianxiong Gao , Daniel Vetter , Konrad Rzeszutek Wilk , maarten.lankhorst@linux.intel.com, airlied@linux.ie, Dan Williams , jani.nikula@linux.intel.com, Nicolas Boichat , rodrigo.vivi@intel.com, Bjorn Helgaas , boris.ostrovsky@oracle.com, Andy Shevchenko , jgross@suse.com, chris@chris-wilson.co.uk, nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , Frank Rowand , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" 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 */ > > _______________________________________________ Nouveau mailing list Nouveau@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/nouveau 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=ham 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 3E96BC433B4 for ; Mon, 26 Apr 2021 16:38:27 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF3DB61009 for ; Mon, 26 Apr 2021 16:38:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF3DB61009 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 933B48378A; Mon, 26 Apr 2021 16:38:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y6GjIEA6HiCP; Mon, 26 Apr 2021 16:38:25 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTP id 6FC69835FB; Mon, 26 Apr 2021 16:38:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 594B6C000F; Mon, 26 Apr 2021 16:38:25 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4198DC000B for ; Mon, 26 Apr 2021 16:38:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 2D2194037E for ; Mon, 26 Apr 2021 16:38:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=chromium.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wMcIJ407Eb-B for ; Mon, 26 Apr 2021 16:38:23 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by smtp4.osuosl.org (Postfix) with ESMTPS id 08D224037A for ; Mon, 26 Apr 2021 16:38:22 +0000 (UTC) Received: by mail-io1-xd2f.google.com with SMTP id f21so20493752ioh.8 for ; Mon, 26 Apr 2021 09:38:22 -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=mEc6HOGCA5mbYNNUKYziOVw7kKmy6KRo0m33wAXfmp/Vt27zvEVRmEqymvmXgEH6wx tY8kxsmVvQF/RQLsRnJ/WmLW5Qqqf4sxQd4cMror93ErPCqBkUkmvONn3F/aQnvGCfVD PrUaAA7Us6I4UiNwXnae3Re94DxeR0BteTCInhpZQfNRoqg5ITbLF6reJ+wuZWBmliLN dbTdVvwDzgbAtN8Hh7SOzIwo2DmytlDIGyYJJdATB8UhZKvXfVqpFOp4U0at+414B65N PA/fwyTH9LfVWOCgMy4fcKtcFdYVvmfJcnt75II8cSjiPPLZ4fllwYtdecSqOH9E33R8 rLqw== X-Gm-Message-State: AOAM532V93WQTAtdKqiC0AT5Ur04GKyBhiKyP7U+yiC95Ss+PT32KG2F NU20JqyeblOqYOr1ugZFJzxlz0bmL+Gxcg== X-Google-Smtp-Source: ABdhPJwGR1GlwifMiEczgg/vKIYXr4x0LOgfQVQxlz20xMollkdVY7/L22vKhYdWdiHhvSXw/qKY1g== X-Received: by 2002:a6b:cd08:: with SMTP id d8mr15283848iog.69.1619455101512; Mon, 26 Apr 2021 09:38:21 -0700 (PDT) Received: from mail-io1-f48.google.com (mail-io1-f48.google.com. [209.85.166.48]) by smtp.gmail.com with ESMTPSA id h8sm171284ils.35.2021.04.26.09.38.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:38:20 -0700 (PDT) Received: by mail-io1-f48.google.com with SMTP id e186so3589327iof.7 for ; Mon, 26 Apr 2021 09:38:19 -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: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, benh@kernel.crashing.org, joonas.lahtinen@linux.intel.com, dri-devel@lists.freedesktop.org, lkml , grant.likely@arm.com, paulus@samba.org, Will Deacon , mingo@kernel.org, sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, "Rafael J . Wysocki" , Christoph Hellwig , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , Jianxiong Gao , Daniel Vetter , Konrad Rzeszutek Wilk , maarten.lankhorst@linux.intel.com, airlied@linux.ie, Dan Williams , jani.nikula@linux.intel.com, Nicolas Boichat , rodrigo.vivi@intel.com, Bjorn Helgaas , boris.ostrovsky@oracle.com, Andy Shevchenko , jgross@suse.com, chris@chris-wilson.co.uk, nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , Frank Rowand , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" 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 */ > > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 C63B8C433ED for ; Mon, 26 Apr 2021 16:44:20 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 657D960FE8 for ; Mon, 26 Apr 2021 16:44:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 657D960FE8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A921E6E83E; Mon, 26 Apr 2021 16:44:19 +0000 (UTC) Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by gabe.freedesktop.org (Postfix) with ESMTPS id BC5FA6E84F for ; Mon, 26 Apr 2021 16:44:18 +0000 (UTC) Received: by mail-qt1-x833.google.com with SMTP id g1so368967qtq.6 for ; Mon, 26 Apr 2021 09:44:18 -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=m12Vja+9FRIyBEtzRdJZPRbJ4bI/aw5z80NBZ7+fIB9HxmdaEShz8eGa6w6gIVUagd U6i/hXEhmBMcA/fpi5SgPBNk6K8rdWoRruMSv5riFzoLAiA6Vl1rHn6GXyPQ59kC9XKq sYmNPN6piQ2abdVMz99Ue+0v+kERu6bMPf/g9vopDHqZ7TyRVgj9x04F1w945paW4RNQ WcVTYsUBJtc+49JmlgzitEpgp14psMZ1iMPF2vEk1BhY6sSDZ5oM/tNQOX5xNGQKEdE7 Xg83ocxIQfQCTPWn/033VwxY0u8DMC/v3RP3KsxxZtr37RoUzf+Lcar4g3TnPXAQ1J/O q55w== X-Gm-Message-State: AOAM533AO3lKf+qE4miqLwjTqi+SqEx7Jft5S9cd4b6SfZE49H+qJH73 SJg3yVaLTAKVUulk6DtMqBPkpfVb+khlxQ== X-Google-Smtp-Source: ABdhPJzu0cuyf7HYLHB7x8aP36nsKEZnYymy4Y7k3IBcezEYeUQNAioftkf2jvVS0sVHSlJXMWJXEw== X-Received: by 2002:ac8:76d0:: with SMTP id q16mr17899731qtr.269.1619455457534; Mon, 26 Apr 2021 09:44:17 -0700 (PDT) Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com. [209.85.160.176]) by smtp.gmail.com with ESMTPSA id h193sm470439qke.90.2021.04.26.09.44.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:44:17 -0700 (PDT) Received: by mail-qt1-f176.google.com with SMTP id o21so13938854qtp.7 for ; Mon, 26 Apr 2021 09:44:17 -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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, dri-devel@lists.freedesktop.org, lkml , grant.likely@arm.com, paulus@samba.org, Will Deacon , mingo@kernel.org, Marek Szyprowski , sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, Joerg Roedel , "Rafael J . Wysocki" , Christoph Hellwig , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , Jianxiong Gao , Konrad Rzeszutek Wilk , airlied@linux.ie, Dan Williams , Nicolas Boichat , rodrigo.vivi@intel.com, Bjorn Helgaas , boris.ostrovsky@oracle.com, Andy Shevchenko , jgross@suse.com, chris@chris-wilson.co.uk, nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , Frank Rowand , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 */ > > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 66B50C433B4 for ; Mon, 26 Apr 2021 16:46:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 10BDD61009 for ; Mon, 26 Apr 2021 16:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10BDD61009 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 923896E84F; Mon, 26 Apr 2021 16:46:48 +0000 (UTC) Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by gabe.freedesktop.org (Postfix) with ESMTPS id 356146E84F for ; Mon, 26 Apr 2021 16:46:46 +0000 (UTC) Received: by mail-qk1-x732.google.com with SMTP id k127so1525873qkc.6 for ; Mon, 26 Apr 2021 09:46:46 -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=Dl483YraTLyebc0k94/Q393kh68Pxy545Ppt/ifHK3aGA4Sh1IENKQ3BhW1g56Cvz7 BYBv9C3uWI0yfVP6GyNXcAj4YPlExiiQcmtgf/ZSLyjfoFHXZTYG1xq0/UZyp+UtBogj yP1wJCYILR4l5/LuLsI92ncuNRx4EtNx/kW3sFEiWZ7jj1dZv4BKRgRMhMuD6KBzkqWL A0PlljYm+7M7dpopsfFFlEThTH4IvHrvcP/M/txQq/u22T+Nep1v9bmtnzArpmXXlJBE Yz9HYDyEOkGd3xb05u3RDiz+BXbJJMwU+qXGvwUf8zPIDr7gl7cRyvjhjiWt3SVqg/l2 E5ZQ== X-Gm-Message-State: AOAM532Z6x7VLILrfZCdlKP0uN9hvM12ty0yxX7OTSXZT1t8GO/XDdX/ eooNb6DKRdw7DVVqEVWC8dyjPk2OtkBxlg== X-Google-Smtp-Source: ABdhPJw+tMs9BpXw1/Z750WdGkvf87kiA0N9KfiNoWWA+V/Noa24LNMUoWWTgDQ9FlpUNHhi+Kgj/g== X-Received: by 2002:a37:c209:: with SMTP id i9mr10041393qkm.363.1619455605116; Mon, 26 Apr 2021 09:46:45 -0700 (PDT) Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com. [209.85.222.179]) by smtp.gmail.com with ESMTPSA id l16sm522073qkg.91.2021.04.26.09.46.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:46:44 -0700 (PDT) Received: by mail-qk1-f179.google.com with SMTP id 66so17554221qkf.2 for ; Mon, 26 Apr 2021 09:46:44 -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: To: Robin Murphy Subject: Re: [Intel-gfx] [PATCH v5 16/16] of: Add plumbing for restricted DMA pool X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, benh@kernel.crashing.org, dri-devel@lists.freedesktop.org, lkml , grant.likely@arm.com, paulus@samba.org, Will Deacon , mingo@kernel.org, Marek Szyprowski , sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, Joerg Roedel , "Rafael J . Wysocki" , Christoph Hellwig , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , Jianxiong Gao , Konrad Rzeszutek Wilk , airlied@linux.ie, Dan Williams , Nicolas Boichat , Bjorn Helgaas , boris.ostrovsky@oracle.com, Andy Shevchenko , jgross@suse.com, chris@chris-wilson.co.uk, nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , Frank Rowand , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 */ > > _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx 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 7FED4C433ED for ; Mon, 26 Apr 2021 16:44:32 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 062BA60FE8 for ; Mon, 26 Apr 2021 16:44:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 062BA60FE8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117819.223731 (Exim 4.92) (envelope-from ) id 1lb4LF-0007XS-PD; Mon, 26 Apr 2021 16:44:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117819.223731; Mon, 26 Apr 2021 16:44:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lb4LF-0007XL-Ko; Mon, 26 Apr 2021 16:44:13 +0000 Received: by outflank-mailman (input) for mailman id 117819; Mon, 26 Apr 2021 16:44:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lb4LE-0007XG-75 for xen-devel@lists.xenproject.org; Mon, 26 Apr 2021 16:44:12 +0000 Received: from mail-qk1-x729.google.com (unknown [2607:f8b0:4864:20::729]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 30cdc03d-9319-40ec-b94b-52b9603b2123; Mon, 26 Apr 2021 16:44:11 +0000 (UTC) Received: by mail-qk1-x729.google.com with SMTP id q136so36163968qka.7 for ; Mon, 26 Apr 2021 09:44:11 -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 q14sm11517428qtp.26.2021.04.26.09.44.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Apr 2021 09:44:10 -0700 (PDT) Received: by mail-qt1-f170.google.com with SMTP id a18so18280254qtj.10 for ; Mon, 26 Apr 2021 09:44:10 -0700 (PDT) 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: 30cdc03d-9319-40ec-b94b-52b9603b2123 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=Fm+Tg2T0DdYUSXpOmBsmVad6lYlGt+j59pppbltRbTOEc/izHqBjYhF+s8djs3ZaNa Go/l7v9+l2bQlucseUuwWf3rKcsN1MBBTf9Qs7p5w4MvIWoBNn8r2ucA2sNRnw7i6JEL WGlLbf0UBpiz7Z2Tn2fPt/mkEBixDllXWZrgFkX24cvLqN4WzyKrOeqi/qTwJaz/uGnv Dkk/r0xv/tg2xBDjHrlZnUOJWVCVPBq5YqUTY1v5EOO0s3Czdu7jH5UjrDt/pdH2c8A2 G/SPU/1oxXuIuB7x2fC4c3oDzlF3rOjbuCYOwR5EaoQSGcgKfAIE0r4ZOV3OTRnovIrY zOdw== X-Gm-Message-State: AOAM530pEtXMG3OT0nCYt91yAzONJJRPfCESy4fZxhXAswV452oQEVuE K33XWcC3D5p1OM9tCg2HHLd2wOgCibHJYw== X-Google-Smtp-Source: ABdhPJzVHTsXveYJFHdWmdSUKcEcmkDKH3h5f0wbWlnCWvL/pDj5HU/C3eGpJDiRJraor3HO5NMcJA== X-Received: by 2002:a37:a68a:: with SMTP id p132mr18679664qke.413.1619455450619; Mon, 26 Apr 2021 09:44:10 -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" 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 */ > >