Virtualization Archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: 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: Sun, 31 Mar 2024 07:20:24 -0400	[thread overview]
Message-ID: <20240331071546-mutt-send-email-mst@kernel.org> (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>



This makes sense. So this will be:

Fixes: 3cfc88380413 ("i2c: virtio: add a virtio i2c frontend driver")
Cc: "Jie Deng" <jie.deng@intel.com>

and I think I will pick this patch for this cycle to fix
the bug. The cleanups can go in the next cycle.


> ---
>  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;
> +
>  	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-31 11:20 UTC|newest]

Thread overview: 39+ 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-29 11:42   ` Stefano Garzarella
2024-03-29 12:07     ` Krzysztof Kozlowski
2024-03-29 13:28       ` Stefano Garzarella
2024-03-31 11:20   ` Michael S. Tsirkin [this message]
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=20240331071546-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=iommu@lists.linux.dev \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=kvm@vger.kernel.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=netdev@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=v9fs@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).