Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5747471ioo; Wed, 1 Jun 2022 11:41:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3uwO2blEG5BXBnHmx87gOGzp1vHIRtW82d7wWUohXbiqnStWzm2boGRayAMJJ9JGUH50q X-Received: by 2002:a63:5702:0:b0:3fa:b090:d01b with SMTP id l2-20020a635702000000b003fab090d01bmr637182pgb.556.1654108903020; Wed, 01 Jun 2022 11:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654108903; cv=none; d=google.com; s=arc-20160816; b=ZyITR8LdGVeJnlxY07DuZl+wJmWfN//OhrEO5/RYuK0bf9ptB0TeP68sSFjfrAFn2M JY42dvnqNqjvEunxta30XEkCuIThVRW8kFs9uo1J/Eiog0AbcCADxml9PORNfhrUY7v9 i/qBnEOWpk8X2vdnElGXrmiyWpjxBawbahQZGJXeaZ0MoZTA0wjoy8lqm3xM8ZeBniTt qT8WOAei8K/kRAE7Q4JxO2s3jdYHTRjNCSvnE79xVdDg1owmepvwGRjOHmmgP3ksl9RD B1ah9tVc6rQ4cJSW3XZqtrApareusRLO2VhYNFZsGfiPTaGd35WSIVYeFcS+Qf57fhdL bUDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=KKzyrKoozy3dMhw/h6zH3mTSevDdJs9JLGdrXFldJ1M=; b=CKEBYhM1xGaXvy5BGPh5PfPQe9d0LngRNZ2eOvUxRtCJVx0jsG0cS+hq+/mSEZq6XX wV2gZmWjP4ZZ/F5LRS3uFDwdOzt378993VvUlIfYkGIJh7HVCKqvxETfDntTm3Sjmsv4 2qUXtJwgUQULRStEhloqruc9KoEmYYXlaIefUqHUgDXjwcW0MiVwJn+eivk4QESLQLLa +Q9sw/3UTsqXFbvfk+nv+CCnmEWki8j1B6SpKNM0R8leWHKJvBgIzy6IYeWr9s5XIHS6 HIVzsT1VpsDPkOiTzXjn2ddse09svP1sOminIj9DVy+hVVRvYcSwfoM3rlmsllX5sGUh 3Ezg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ACXErPAV; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x70-20020a638649000000b003c6aa1dbd4bsi3390482pgd.30.2022.06.01.11.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:41:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ACXErPAV; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D446BA55C; Wed, 1 Jun 2022 11:38:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343793AbiFAAid (ORCPT + 99 others); Tue, 31 May 2022 20:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231270AbiFAAia (ORCPT ); Tue, 31 May 2022 20:38:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CDF98A078 for ; Tue, 31 May 2022 17:38:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ED443614A4 for ; Wed, 1 Jun 2022 00:38:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C660CC385A9; Wed, 1 Jun 2022 00:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654043908; bh=2Ox7lz8z9nRCuRY+W2ivcqHbD3jf8K4mU3wNbncCJvE=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=ACXErPAVzHV3tUf/6olYKLPTuR5bOIjlhKKUyY3xFc6DSImyxGo37EY6xCnvD9bgw 4DM4E4vCLd9QLtYd71Fm48/NYJeeO3fxr3RYtBwZBdZAw1NvXfvLDGSBjRqk1TJg9o ULhrZzG+WwQZXpVQXGUygWPinwY5HeAFfxKwWBc8TSkrAq1iOEM7QeNmt0iYnZcdpf 77HGEjp94iX1h/RI/iX9rREkuHalhYGzwGp2nRYo0a93bxi2pNVZJfU3CHiiQBxeKC OMuqFBYwGsevlojee5Bjqd3LRBKuefX41tvKdrqypPorQ2gX65nGe8y/DoyrPYAfDV 9AModjdsChDtg== Date: Tue, 31 May 2022 17:38:26 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Oleksandr Tyshchenko cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Oleksandr Tyshchenko , Stefano Stabellini , Boris Ostrovsky , Juergen Gross , Julien Grall , "Michael S. Tsirkin" , Christoph Hellwig Subject: Re: [PATCH V3 6/8] xen/grant-dma-iommu: Introduce stub IOMMU driver In-Reply-To: <1653944417-17168-7-git-send-email-olekstysh@gmail.com> Message-ID: References: <1653944417-17168-1-git-send-email-olekstysh@gmail.com> <1653944417-17168-7-git-send-email-olekstysh@gmail.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 31 May 2022, Oleksandr Tyshchenko wrote: > From: Oleksandr Tyshchenko > > In order to reuse generic IOMMU device tree bindings by Xen grant > DMA-mapping layer we need to add this stub driver from a fw_devlink > perspective (grant-dma-ops cannot be converted into the proper > IOMMU driver). > > Otherwise, just reusing IOMMU bindings (without having a corresponding > driver) leads to the deferred probe timeout afterwards, because > the IOMMU device never becomes available. > > This stub driver does nothing except registering empty iommu_ops, > the upper layer "of_iommu" will treat this as NO_IOMMU condition > and won't return -EPROBE_DEFER. > > As this driver is quite different from the most hardware IOMMU > implementations and only needed in Xen guests, place it in drivers/xen > directory. The subsequent commit will make use of it. > > Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Stefano Stabellini > --- > According to the discussion at: > https://lore.kernel.org/xen-devel/c0f78aab-e723-fe00-a310-9fe52ec75e48@gmail.com/ > > Change V2 -> V3: > - new patch > --- > drivers/xen/Kconfig | 4 +++ > drivers/xen/Makefile | 1 + > drivers/xen/grant-dma-iommu.c | 78 +++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 83 insertions(+) > create mode 100644 drivers/xen/grant-dma-iommu.c > > diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig > index a7bd8ce..35d20d9 100644 > --- a/drivers/xen/Kconfig > +++ b/drivers/xen/Kconfig > @@ -335,6 +335,10 @@ config XEN_UNPOPULATED_ALLOC > having to balloon out RAM regions in order to obtain physical memory > space to create such mappings. > > +config XEN_GRANT_DMA_IOMMU > + bool > + select IOMMU_API > + > config XEN_GRANT_DMA_OPS > bool > select DMA_OPS > diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile > index 1a23cb0..c0503f1 100644 > --- a/drivers/xen/Makefile > +++ b/drivers/xen/Makefile > @@ -40,3 +40,4 @@ xen-privcmd-y := privcmd.o privcmd-buf.o > obj-$(CONFIG_XEN_FRONT_PGDIR_SHBUF) += xen-front-pgdir-shbuf.o > obj-$(CONFIG_XEN_UNPOPULATED_ALLOC) += unpopulated-alloc.o > obj-$(CONFIG_XEN_GRANT_DMA_OPS) += grant-dma-ops.o > +obj-$(CONFIG_XEN_GRANT_DMA_IOMMU) += grant-dma-iommu.o > diff --git a/drivers/xen/grant-dma-iommu.c b/drivers/xen/grant-dma-iommu.c > new file mode 100644 > index 00000000..16b8bc0 > --- /dev/null > +++ b/drivers/xen/grant-dma-iommu.c > @@ -0,0 +1,78 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Stub IOMMU driver which does nothing. > + * The main purpose of it being present is to reuse generic IOMMU device tree > + * bindings by Xen grant DMA-mapping layer. > + * > + * Copyright (C) 2022 EPAM Systems Inc. > + */ > + > +#include > +#include > +#include > + > +struct grant_dma_iommu_device { > + struct device *dev; > + struct iommu_device iommu; > +}; > + > +/* Nothing is really needed here */ > +static const struct iommu_ops grant_dma_iommu_ops; > + > +static const struct of_device_id grant_dma_iommu_of_match[] = { > + { .compatible = "xen,grant-dma" }, > + { }, > +}; > + > +static int grant_dma_iommu_probe(struct platform_device *pdev) > +{ > + struct grant_dma_iommu_device *mmu; > + int ret; > + > + mmu = devm_kzalloc(&pdev->dev, sizeof(*mmu), GFP_KERNEL); > + if (!mmu) > + return -ENOMEM; > + > + mmu->dev = &pdev->dev; > + > + ret = iommu_device_register(&mmu->iommu, &grant_dma_iommu_ops, &pdev->dev); > + if (ret) > + return ret; > + > + platform_set_drvdata(pdev, mmu); > + > + return 0; > +} > + > +static int grant_dma_iommu_remove(struct platform_device *pdev) > +{ > + struct grant_dma_iommu_device *mmu = platform_get_drvdata(pdev); > + > + platform_set_drvdata(pdev, NULL); > + iommu_device_unregister(&mmu->iommu); > + > + return 0; > +} > + > +static struct platform_driver grant_dma_iommu_driver = { > + .driver = { > + .name = "grant-dma-iommu", > + .of_match_table = grant_dma_iommu_of_match, > + }, > + .probe = grant_dma_iommu_probe, > + .remove = grant_dma_iommu_remove, > +}; > + > +static int __init grant_dma_iommu_init(void) > +{ > + struct device_node *iommu_np; > + > + iommu_np = of_find_matching_node(NULL, grant_dma_iommu_of_match); > + if (!iommu_np) > + return 0; > + > + of_node_put(iommu_np); > + > + return platform_driver_register(&grant_dma_iommu_driver); > +} > +subsys_initcall(grant_dma_iommu_init); > -- > 2.7.4 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel >