All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	 Jason Wang <jasowang@redhat.com>,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
	 Richard Weinberger <richard@nod.at>,
	Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	 Johannes Berg <johannes@sipsolutions.net>,
	Paolo Bonzini <pbonzini@redhat.com>,
	 Stefan Hajnoczi <stefanha@redhat.com>,
	Jens Axboe <axboe@kernel.dk>,
	 Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	 Olivia Mackall <olivia@selenic.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	 Amit Shah <amit@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Gonglei <arei.gonglei@huawei.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Viresh Kumar <vireshk@kernel.org>,
	 Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	 David Airlie <airlied@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	 Gurchetan Singh <gurchetansingh@chromium.org>,
	Chia-I Wu <olvaffe@gmail.com>,
	 Jean-Philippe Brucker <jean-philippe@linaro.org>,
	Joerg Roedel <joro@8bytes.org>, Alexander Graf <graf@amazon.com>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	Eric Van Hensbergen <ericvh@kernel.org>,
	 Latchesar Ionkov <lucho@ionkov.net>,
	Dominique Martinet <asmadeus@codewreck.org>,
	 Christian Schoenebeck <linux_oss@crudebyte.com>,
	Kalle Valo <kvalo@kernel.org>,
	 Dan Williams <dan.j.williams@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	 Dave Jiang <dave.jiang@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	 Pankaj Gupta <pankaj.gupta.linux@gmail.com>,
	Bjorn Andersson <andersson@kernel.org>,
	 Mathieu Poirier <mathieu.poirier@linaro.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	 Vivek Goyal <vgoyal@redhat.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	 Anton Yakovlev <anton.yakovlev@opensynergy.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	 virtualization@lists.linux.dev, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,  linux-um@lists.infradead.org,
	linux-block@vger.kernel.org, linux-bluetooth@vger.kernel.org,
	 linux-crypto@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	 dri-devel@lists.freedesktop.org, iommu@lists.linux.dev,
	netdev@vger.kernel.org,  v9fs@lists.linux.dev,
	kvm@vger.kernel.org, linux-wireless@vger.kernel.org,
	 nvdimm@lists.linux.dev, linux-remoteproc@vger.kernel.org,
	linux-scsi@vger.kernel.org,  linux-fsdevel@vger.kernel.org,
	alsa-devel@alsa-project.org, linux-sound@vger.kernel.org
Subject: Re: [PATCH 01/22] virtio: store owner from modules with register_virtio_driver()
Date: Fri, 29 Mar 2024 12:42:08 +0100	[thread overview]
Message-ID: <oaoiehcpkjs3wrhc22pwx676pompxml2z5dcq32a6fvsyntonw@hnohrbbp6wpm> (raw)
In-Reply-To: <20240327-module-owner-virtio-v1-1-0feffab77d99@linaro.org>

On Wed, Mar 27, 2024 at 01:40:54PM +0100, Krzysztof Kozlowski wrote:
>Modules registering driver with register_virtio_driver() might forget to
>set .owner field.  i2c-virtio.c for example has it missing.  The field
>is used by some of other kernel parts for reference counting
>(try_module_get()), so it is expected that drivers will set it.
>
>Solve the problem by moving this task away from the drivers to the core
>amba bus code, just like we did for platform_driver in
>commit 9447057eaff8 ("platform_device: use a macro instead of
>platform_driver_register").
>
>Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>---
> Documentation/driver-api/virtio/writing_virtio_drivers.rst | 1 -
> drivers/virtio/virtio.c                                    | 6 ++++--
> include/linux/virtio.h                                     | 7 +++++--
> 3 files changed, 9 insertions(+), 5 deletions(-)
>
>diff --git a/Documentation/driver-api/virtio/writing_virtio_drivers.rst b/Documentation/driver-api/virtio/writing_virtio_drivers.rst
>index e14c58796d25..e5de6f5d061a 100644
>--- a/Documentation/driver-api/virtio/writing_virtio_drivers.rst
>+++ b/Documentation/driver-api/virtio/writing_virtio_drivers.rst
>@@ -97,7 +97,6 @@ like this::
>
> 	static struct virtio_driver virtio_dummy_driver = {
> 		.driver.name =  KBUILD_MODNAME,
>-		.driver.owner = THIS_MODULE,
> 		.id_table =     id_table,
> 		.probe =        virtio_dummy_probe,
> 		.remove =       virtio_dummy_remove,
>diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
>index f173587893cb..9510c551dce8 100644
>--- a/drivers/virtio/virtio.c
>+++ b/drivers/virtio/virtio.c
>@@ -362,14 +362,16 @@ static const struct bus_type virtio_bus = {
> 	.remove = virtio_dev_remove,
> };
>
>-int register_virtio_driver(struct virtio_driver *driver)
>+int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
> {
> 	/* Catch this early. */
> 	BUG_ON(driver->feature_table_size && !driver->feature_table);
> 	driver->driver.bus = &virtio_bus;
>+	driver->driver.owner = owner;
>+

`.driver.name =  KBUILD_MODNAME` also seems very common, should we put
that in the macro as well?

> 	return driver_register(&driver->driver);
> }
>-EXPORT_SYMBOL_GPL(register_virtio_driver);
>+EXPORT_SYMBOL_GPL(__register_virtio_driver);
>
> void unregister_virtio_driver(struct virtio_driver *driver)
> {
>diff --git a/include/linux/virtio.h b/include/linux/virtio.h
>index b0201747a263..26c4325aa373 100644
>--- a/include/linux/virtio.h
>+++ b/include/linux/virtio.h
>@@ -170,7 +170,7 @@ size_t virtio_max_dma_size(const struct virtio_device *vdev);
>
> /**
>  * struct virtio_driver - operations for a virtio I/O driver
>- * @driver: underlying device driver (populate name and owner).
>+ * @driver: underlying device driver (populate name).
>  * @id_table: the ids serviced by this driver.
>  * @feature_table: an array of feature numbers supported by this driver.
>  * @feature_table_size: number of entries in the feature table array.
>@@ -208,7 +208,10 @@ static inline struct virtio_driver *drv_to_virtio(struct device_driver *drv)
> 	return container_of(drv, struct virtio_driver, driver);
> }
>
>-int register_virtio_driver(struct virtio_driver *drv);
>+/* use a macro to avoid include chaining to get THIS_MODULE */
>+#define register_virtio_driver(drv) \
>+	__register_virtio_driver(drv, THIS_MODULE)
>+int __register_virtio_driver(struct virtio_driver *drv, struct module *owner);
> void unregister_virtio_driver(struct virtio_driver *drv);
>
> /* module_virtio_driver() - Helper macro for drivers that don't do
>
>-- 
>2.34.1
>


  parent reply	other threads:[~2024-03-29 11:42 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 12:40 [PATCH 00/22] virtio: store owner from modules with register_virtio_driver() Krzysztof Kozlowski
2024-03-27 12:40 ` [PATCH 01/22] " Krzysztof Kozlowski
2024-03-27 13:11   ` bluez.test.bot
2024-03-29 11:42   ` Stefano Garzarella [this message]
2024-03-29 12:07     ` [PATCH 01/22] " Krzysztof Kozlowski
2024-03-29 13:28       ` Stefano Garzarella
2024-03-31 11:20   ` Michael S. Tsirkin
2024-03-31 11:20     ` Michael S. Tsirkin
2024-03-27 12:40 ` [PATCH 02/22] um: virt-pci: drop owner assignment Krzysztof Kozlowski
2024-03-27 13:34   ` Johannes Berg
2024-03-27 13:40     ` Krzysztof Kozlowski
2024-03-27 12:40 ` [PATCH 03/22] virtio_blk: " Krzysztof Kozlowski
2024-03-27 12:40 ` [PATCH 04/22] bluetooth: virtio: " Krzysztof Kozlowski
2024-03-27 12:40 ` [PATCH 05/22] hwrng: " Krzysztof Kozlowski
2024-03-27 12:40 ` [PATCH 06/22] virtio_console: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 07/22] crypto: virtio - " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 08/22] firmware: arm_scmi: virtio: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 09/22] gpio: " Krzysztof Kozlowski
2024-03-28  5:16   ` Viresh Kumar
2024-03-29 10:27   ` Bartosz Golaszewski
2024-03-29 10:58     ` Stefano Garzarella
2024-03-29 11:35     ` Krzysztof Kozlowski
2024-03-29 12:22       ` Bartosz Golaszewski
2024-03-27 12:41 ` [PATCH 10/22] drm/virtio: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 11/22] iommu: virtio: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 12/22] misc: nsm: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 13/22] net: caif: virtio: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 14/22] net: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 15/22] net: 9p: " Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 16/22] net: vmw_vsock: " Krzysztof Kozlowski
2024-03-29 11:45   ` Stefano Garzarella
2024-03-27 12:41 ` [PATCH 17/22] wireless: mac80211_hwsim: " Krzysztof Kozlowski
2024-03-27 12:55   ` Kalle Valo
2024-03-27 13:07     ` Krzysztof Kozlowski
2024-03-27 12:41 ` [PATCH 18/22] nvdimm: virtio_pmem: " Krzysztof Kozlowski
2024-03-27 15:52   ` Dave Jiang
2024-03-27 12:41 ` [PATCH 19/22] rpmsg: virtio: " Krzysztof Kozlowski
2024-03-28 15:39   ` Mathieu Poirier
2024-03-27 13:04 ` [PATCH 20/22] scsi: " Krzysztof Kozlowski
2024-03-27 13:05 ` [PATCH 21/22] fuse: " Krzysztof Kozlowski
2024-03-27 13:07 ` [PATCH 22/22] sound: " Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=oaoiehcpkjs3wrhc22pwx676pompxml2z5dcq32a6fvsyntonw@hnohrbbp6wpm \
    --to=sgarzare@redhat.com \
    --cc=airlied@redhat.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=amit@kernel.org \
    --cc=andersson@kernel.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=anton.yakovlev@opensynergy.com \
    --cc=arei.gonglei@huawei.com \
    --cc=arnd@arndb.de \
    --cc=asmadeus@codewreck.org \
    --cc=axboe@kernel.dk \
    --cc=brgl@bgdev.pl \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=davem@davemloft.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=edumazet@google.com \
    --cc=ericvh@kernel.org \
    --cc=graf@amazon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gurchetansingh@chromium.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=iommu@lists.linux.dev \
    --cc=ira.weiny@intel.com \
    --cc=jasowang@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=johannes@sipsolutions.net \
    --cc=joro@8bytes.org \
    --cc=kraxel@redhat.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux_oss@crudebyte.com \
    --cc=lucho@ionkov.net \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=martin.petersen@oracle.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=miklos@szeredi.hu \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=olivia@selenic.com \
    --cc=olvaffe@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pankaj.gupta.linux@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=perex@perex.cz \
    --cc=richard@nod.at \
    --cc=stefanha@redhat.com \
    --cc=tiwai@suse.com \
    --cc=v9fs@lists.linux.dev \
    --cc=vgoyal@redhat.com \
    --cc=vireshk@kernel.org \
    --cc=virtualization@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.