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=-5.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 418B1C282DD for ; Thu, 9 Jan 2020 14:16:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15629206ED for ; Thu, 9 Jan 2020 14:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578579371; bh=KQ9qbQtsoYGPMZdXi3hjrhuI0cSPD0xhAqRsLeBwpYw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=p1bVBn0MroRWb6bXKD8yNJRkbD9IoUkV5i6e5QJtPVgUGi5gHHJ4HcQULVq+3WojP p0ZunEBYoMHR4fCEuwgJtGwFKLrmGSuOti49047orwuST7yVSySJGJsddmKza3HeRs bOfVJOO1bNuSGr9+kJ5FRdyGxeTxEh3/lpw8yV8w= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731602AbgAIOQK (ORCPT ); Thu, 9 Jan 2020 09:16:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:44650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729085AbgAIOQK (ORCPT ); Thu, 9 Jan 2020 09:16:10 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E417F2067D; Thu, 9 Jan 2020 14:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578579369; bh=KQ9qbQtsoYGPMZdXi3hjrhuI0cSPD0xhAqRsLeBwpYw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Kb0Oe0gQ9b6CX8A3gAR3Ok2ZegM9K9eb4asZOuoXX5z6sDC15mICSWodGJyVkTgPu 16iDpMhmNEbRHE/NSRNBBtqnQtawQUxyT7lui3Z4Ipp4w39HhsCMvhxeUaGtjqPKi5 u05OlGw2rUb6OWLon9rdEygdpEIMl+hTawNs7IfA= Date: Thu, 9 Jan 2020 14:16:03 +0000 From: Will Deacon To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, iommu@lists.linuxfoundation.org, kernel-team@android.com, Jean-Philippe Brucker , Jordan Crouse , John Garry , Bjorn Helgaas , Saravana Kannan , "Isaac J. Manjarres" , Robin Murphy , Lorenzo Pieralisi , Joerg Roedel , Ard Biesheuvel Subject: Re: [PATCH v4 05/16] drivers/iommu: Take a ref to the IOMMU driver prior to ->add_device() Message-ID: <20200109141602.GA12236@willie-the-truck> References: <20191219120352.382-1-will@kernel.org> <20191219120352.382-6-will@kernel.org> <20191219144437.GA1959534@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191219144437.GA1959534@kroah.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, On Thu, Dec 19, 2019 at 03:44:37PM +0100, Greg Kroah-Hartman wrote: > On Thu, Dec 19, 2019 at 12:03:41PM +0000, Will Deacon wrote: > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > > index f2223cbb5fd5..e9f94d3f7a04 100644 > > --- a/include/linux/iommu.h > > +++ b/include/linux/iommu.h > > @@ -246,9 +246,10 @@ struct iommu_iotlb_gather { > > * @sva_get_pasid: Get PASID associated to a SVA handle > > * @page_response: handle page request response > > * @cache_invalidate: invalidate translation caches > > - * @pgsize_bitmap: bitmap of all possible supported page sizes > > * @sva_bind_gpasid: bind guest pasid and mm > > * @sva_unbind_gpasid: unbind guest pasid and mm > > + * @pgsize_bitmap: bitmap of all possible supported page sizes > > + * @owner: Driver module providing these ops > > */ > > struct iommu_ops { > > bool (*capable)(enum iommu_cap); > > @@ -318,6 +319,7 @@ struct iommu_ops { > > int (*sva_unbind_gpasid)(struct device *dev, int pasid); > > > > unsigned long pgsize_bitmap; > > + struct module *owner; > > Everyone is always going to forget to set this field. I don't think you > even set it for all of the different iommu_ops possible in this series, > right? I only initialised the field for those drivers which can actually be built as a module, but I take your point about this being error-prone. > The "trick" we did to keep people from having to remember this is to do > what we did for the bus registering functions. > > Look at pci_register_driver in pci.h: > #define pci_register_driver(driver) \ > __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) > > Then we set the .owner field in the "real" __pci_register_driver() call. > > Same thing for USB and lots, if not all, other driver register > functions. > > You can do the same thing here, and I would recommend it. Yes, that makes sense, cheers. Diff below. I'll send it to Joerg along with some other SMMU patches that have come in since the holiday. Will --->8 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 03dc97842875..e82997a705a8 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2733,7 +2733,6 @@ static struct iommu_ops arm_smmu_ops = { .get_resv_regions = arm_smmu_get_resv_regions, .put_resv_regions = arm_smmu_put_resv_regions, .pgsize_bitmap = -1UL, /* Restricted during device attach */ - .owner = THIS_MODULE, }; /* Probing and initialisation functions */ diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 5ef1f2e100d7..93d332423f6f 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1623,7 +1623,6 @@ static struct iommu_ops arm_smmu_ops = { .get_resv_regions = arm_smmu_get_resv_regions, .put_resv_regions = arm_smmu_put_resv_regions, .pgsize_bitmap = -1UL, /* Restricted during device attach */ - .owner = THIS_MODULE, }; static void arm_smmu_device_reset(struct arm_smmu_device *smmu) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e9f94d3f7a04..90007c92ad2d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -388,12 +388,19 @@ void iommu_device_sysfs_remove(struct iommu_device *iommu); int iommu_device_link(struct iommu_device *iommu, struct device *link); void iommu_device_unlink(struct iommu_device *iommu, struct device *link); -static inline void iommu_device_set_ops(struct iommu_device *iommu, - const struct iommu_ops *ops) +static inline void __iommu_device_set_ops(struct iommu_device *iommu, + const struct iommu_ops *ops) { iommu->ops = ops; } +#define iommu_device_set_ops(iommu, ops) \ +do { \ + struct iommu_ops *__ops = (struct iommu_ops *)(ops); \ + __ops->owner = THIS_MODULE; \ + __iommu_device_set_ops(iommu, __ops); \ +} while (0) + static inline void iommu_device_set_fwnode(struct iommu_device *iommu, struct fwnode_handle *fwnode) { 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=-5.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 54C0DC33CA1 for ; Thu, 9 Jan 2020 14:16:13 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 1DC5E206ED for ; Thu, 9 Jan 2020 14:16:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kb0Oe0gQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DC5E206ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.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 silver.osuosl.org (Postfix) with ESMTP id EE91E20C41; Thu, 9 Jan 2020 14:16:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rIytcbSWsCX1; Thu, 9 Jan 2020 14:16:11 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id CBD33203E6; Thu, 9 Jan 2020 14:16:11 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BF259C18DC; Thu, 9 Jan 2020 14:16:11 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id AACDBC0881 for ; Thu, 9 Jan 2020 14:16:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 93F728616A for ; Thu, 9 Jan 2020 14:16:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eBtJ_fLb_zBe for ; Thu, 9 Jan 2020 14:16:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 657F086090 for ; Thu, 9 Jan 2020 14:16:09 +0000 (UTC) Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E417F2067D; Thu, 9 Jan 2020 14:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578579369; bh=KQ9qbQtsoYGPMZdXi3hjrhuI0cSPD0xhAqRsLeBwpYw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Kb0Oe0gQ9b6CX8A3gAR3Ok2ZegM9K9eb4asZOuoXX5z6sDC15mICSWodGJyVkTgPu 16iDpMhmNEbRHE/NSRNBBtqnQtawQUxyT7lui3Z4Ipp4w39HhsCMvhxeUaGtjqPKi5 u05OlGw2rUb6OWLon9rdEygdpEIMl+hTawNs7IfA= Date: Thu, 9 Jan 2020 14:16:03 +0000 From: Will Deacon To: Greg Kroah-Hartman Subject: Re: [PATCH v4 05/16] drivers/iommu: Take a ref to the IOMMU driver prior to ->add_device() Message-ID: <20200109141602.GA12236@willie-the-truck> References: <20191219120352.382-1-will@kernel.org> <20191219120352.382-6-will@kernel.org> <20191219144437.GA1959534@kroah.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20191219144437.GA1959534@kroah.com> User-Agent: Mutt/1.10.1 (2018-07-13) Cc: iommu@lists.linuxfoundation.org, Jean-Philippe Brucker , Saravana Kannan , Robin Murphy , linux-kernel@vger.kernel.org, Ard Biesheuvel , Bjorn Helgaas , kernel-team@android.com, "Isaac J. Manjarres" 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" Hi Greg, On Thu, Dec 19, 2019 at 03:44:37PM +0100, Greg Kroah-Hartman wrote: > On Thu, Dec 19, 2019 at 12:03:41PM +0000, Will Deacon wrote: > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > > index f2223cbb5fd5..e9f94d3f7a04 100644 > > --- a/include/linux/iommu.h > > +++ b/include/linux/iommu.h > > @@ -246,9 +246,10 @@ struct iommu_iotlb_gather { > > * @sva_get_pasid: Get PASID associated to a SVA handle > > * @page_response: handle page request response > > * @cache_invalidate: invalidate translation caches > > - * @pgsize_bitmap: bitmap of all possible supported page sizes > > * @sva_bind_gpasid: bind guest pasid and mm > > * @sva_unbind_gpasid: unbind guest pasid and mm > > + * @pgsize_bitmap: bitmap of all possible supported page sizes > > + * @owner: Driver module providing these ops > > */ > > struct iommu_ops { > > bool (*capable)(enum iommu_cap); > > @@ -318,6 +319,7 @@ struct iommu_ops { > > int (*sva_unbind_gpasid)(struct device *dev, int pasid); > > > > unsigned long pgsize_bitmap; > > + struct module *owner; > > Everyone is always going to forget to set this field. I don't think you > even set it for all of the different iommu_ops possible in this series, > right? I only initialised the field for those drivers which can actually be built as a module, but I take your point about this being error-prone. > The "trick" we did to keep people from having to remember this is to do > what we did for the bus registering functions. > > Look at pci_register_driver in pci.h: > #define pci_register_driver(driver) \ > __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) > > Then we set the .owner field in the "real" __pci_register_driver() call. > > Same thing for USB and lots, if not all, other driver register > functions. > > You can do the same thing here, and I would recommend it. Yes, that makes sense, cheers. Diff below. I'll send it to Joerg along with some other SMMU patches that have come in since the holiday. Will --->8 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 03dc97842875..e82997a705a8 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2733,7 +2733,6 @@ static struct iommu_ops arm_smmu_ops = { .get_resv_regions = arm_smmu_get_resv_regions, .put_resv_regions = arm_smmu_put_resv_regions, .pgsize_bitmap = -1UL, /* Restricted during device attach */ - .owner = THIS_MODULE, }; /* Probing and initialisation functions */ diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 5ef1f2e100d7..93d332423f6f 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1623,7 +1623,6 @@ static struct iommu_ops arm_smmu_ops = { .get_resv_regions = arm_smmu_get_resv_regions, .put_resv_regions = arm_smmu_put_resv_regions, .pgsize_bitmap = -1UL, /* Restricted during device attach */ - .owner = THIS_MODULE, }; static void arm_smmu_device_reset(struct arm_smmu_device *smmu) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e9f94d3f7a04..90007c92ad2d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -388,12 +388,19 @@ void iommu_device_sysfs_remove(struct iommu_device *iommu); int iommu_device_link(struct iommu_device *iommu, struct device *link); void iommu_device_unlink(struct iommu_device *iommu, struct device *link); -static inline void iommu_device_set_ops(struct iommu_device *iommu, - const struct iommu_ops *ops) +static inline void __iommu_device_set_ops(struct iommu_device *iommu, + const struct iommu_ops *ops) { iommu->ops = ops; } +#define iommu_device_set_ops(iommu, ops) \ +do { \ + struct iommu_ops *__ops = (struct iommu_ops *)(ops); \ + __ops->owner = THIS_MODULE; \ + __iommu_device_set_ops(iommu, __ops); \ +} while (0) + static inline void iommu_device_set_fwnode(struct iommu_device *iommu, struct fwnode_handle *fwnode) { _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu