From patchwork Wed Mar 27 12:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 785181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 823D0C6FD1F for ; Tue, 2 Apr 2024 06:53:01 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9C1232BCF; Tue, 2 Apr 2024 08:52:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9C1232BCF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1712040779; bh=fwrJWKj8nU797mE0IC4lY3eH4qtf6HIC5ncnQg0kcy4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Yqnbh6FZUBiQ76joNDlzsnnEXzldQEUvJay9Zlz9abYauo2pu/UleKtggT7J8nQ3V Ha82t4fyWYlk5DqdbdrzD2qwOvvwnrguyph3ucqcw0jvxZHGAM3MULMqLbvbO+l2yF 6IU0LRjovC65qBBdg0j9ge4LySJtydKLBQ0DhxnI= Received: by alsa1.perex.cz (Postfix, from userid 50401) id E9E69F808C2; Tue, 2 Apr 2024 08:49:24 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 64827F808C9; Tue, 2 Apr 2024 08:49:23 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 25D70F8025F; Wed, 27 Mar 2024 13:42:07 +0100 (CET) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 02633F80093 for ; Wed, 27 Mar 2024 13:41:57 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 02633F80093 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UwaG39cD Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a450bedffdfso775087766b.3 for ; Wed, 27 Mar 2024 05:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711543316; x=1712148116; darn=alsa-project.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=o4tr5NG48SIYjCNbZydnC9ylnwvR5SnVT2LtcwsiMwA=; b=UwaG39cD94ClIjUDfp/1LUDiPBnOIlL6FclXnKj8kHQS0OdQ9PyB/3aC0Gy/FqkT1L XHTJVst6of5pozudV3ln1uQ6dgxynRovHbAlokRMhi16Kmd6x2QFqL7dvT1mRzabf+Cd F+tsfvsKzL5ilMdf41rOxmtqPEIOKfwIfuOWDem21FHmRbmBORBNtRPXntXmyk7OE6A3 ZRDE5uUtWyPWf/IMS0AUzlodMlK2CHM+yFq3i7tKuIP8eqJumPORxRTJiUb696BTLfGw F4fmCz1A2K/uqIfGS/C+zyxJq99ktHt7Hm25qo+B35El4yGNQGMBI8341nuXZUTpGwQk NL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711543316; x=1712148116; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o4tr5NG48SIYjCNbZydnC9ylnwvR5SnVT2LtcwsiMwA=; b=XVm8jQXek1929f/MoRM0vkqwa8P/+QRvuPtUQSa9xl5WL/EjjKoZB6TuCpPQ4zC925 XURYHHgsJZFEwppj7fi2axwCQhNE6wm61UhJz+w7ay5bLYovyKYeIVh7ALC77bcidZ8N lUQgy3zSk8qzFIrugCubzumrPo/VEXkkRXJeTtlMx33hLIonRUbCGQjb/XjqZWDcfb50 s8R6fdqAkapZOAqvU4r1f5v5UF79eVtx8JZs94zWBvit4gTSE0/EKr4IfhmBDd5ohxsE MBp68HqsZcmM6TOPqjLtO4xHjX3QkTdbNq/vWqiDyFhxyMnj6oM+B/dUoI3aB58RjAzm 2JEw== X-Forwarded-Encrypted: i=1; AJvYcCX9sYZw1cxB38W2NKH4L9kLDF+I4pkAZLmIdTmAqlhojO8UB58rnaaoYyWKgFiX0z27R9gYuPgKyiFMIK9L0wBLCbBDYMI3y11spmE= X-Gm-Message-State: AOJu0Yw/C0w+d6IcrdeG0in7DKp1oPyIRbV78X+e/ITuzRAAd2vx3vOM xQOu6+dIpmbO3gG6Ga8o7/mbQ8IwNQCdun438lanNCqik3KuxT0oRf0MM1k1/xs= X-Google-Smtp-Source: AGHT+IHGDex70EGchFACtzsm2nrHrUxeSKSSg9117jWaPs7ddpDO3oid2XR2oF47HXk5SLd38PbHNg== X-Received: by 2002:a17:907:970a:b0:a4d:f77a:b8d6 with SMTP id jg10-20020a170907970a00b00a4df77ab8d6mr3727212ejc.22.1711543315681; Wed, 27 Mar 2024 05:41:55 -0700 (PDT) Received: from [127.0.1.1] ([178.197.206.205]) by smtp.gmail.com with ESMTPSA id gx16-20020a170906f1d000b00a4707ec7c34sm5379175ejb.166.2024.03.27.05.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 05:41:55 -0700 (PDT) From: Krzysztof Kozlowski Date: Wed, 27 Mar 2024 13:40:54 +0100 Subject: [PATCH 01/22] virtio: store owner from modules with register_virtio_driver() MIME-Version: 1.0 Message-Id: <20240327-module-owner-virtio-v1-1-0feffab77d99@linaro.org> References: <20240327-module-owner-virtio-v1-0-0feffab77d99@linaro.org> In-Reply-To: <20240327-module-owner-virtio-v1-0-0feffab77d99@linaro.org> To: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Richard Weinberger , Anton Ivanov , Johannes Berg , Paolo Bonzini , Stefan Hajnoczi , Jens Axboe , Marcel Holtmann , Luiz Augusto von Dentz , Olivia Mackall , Herbert Xu , Amit Shah , Arnd Bergmann , Greg Kroah-Hartman , Gonglei , "David S. Miller" , Viresh Kumar , Linus Walleij , Bartosz Golaszewski , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Jean-Philippe Brucker , Joerg Roedel , Alexander Graf , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , Stefano Garzarella , Kalle Valo , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Pankaj Gupta , Bjorn Andersson , Mathieu Poirier , "Martin K. Petersen" , Vivek Goyal , Miklos Szeredi , Anton Yakovlev , Jaroslav Kysela , Takashi Iwai 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, Krzysztof Kozlowski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3444; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=fwrJWKj8nU797mE0IC4lY3eH4qtf6HIC5ncnQg0kcy4=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmBBPaF1JDzqTfV6cOXqJmyzXYsgEqPQATvYRQk WnQRf8t/LyJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZgQT2gAKCRDBN2bmhouD 1+oYD/42/c31q0OYiLqEi/06F54yokibXBcPIkZLpMFNOTFEC7z+HyQLH1rUQjhhXMgwJ7AzI8y 7NznQsKuUd6y2WCWJnFhBDts6kEHJvQU6E+xqGzP2vmAVnMROlQy/LkXQIRLZafz1m+V1KtGAHU DUddrXGe58/IULO6HGJXn5W88W87cHRhL+VzuPgLPSZ1r+2UgOJJPsXQHGSCBwzazewyJCPdVBL aVAs5/3SwH4JaBj0a2yWWmqghkUrpKThxS1Z9qlZ31JkNUvyUPD1Uw24FMkTdQgdD9gkACGcwn4 EFpICaVxRC2a10UH4qf9NSqNkAU3FdzajlC/nA75p3AAU7+TsrHZzPNv/qF1IHIoP/W6eB/UKI7 3U4PWq1LIDq7UYmL9tMxbveghvTTu67p90AA2uJrI2tE9ZZq6zFMijWlDvHb+SS5hXLXuAj/oOg claga2VkfoNDU2HP3F4to11EblvFhdSfJJDnLzKLBnrbjnVM7dkqY3GavOlIslOcd2ZW8gHDi+Z bsYIHCHPTvSdrW+Rf96zy3s822rN2dtNm9bxU769KmiWXmCytk48eZlxVoITtSNZAoGPTmM7i3N Qk0Y5SRvJ/PnycrTHfKDykbvzTENDEK7+rErnq6incSGSqzmmVreGoc0RhcyC/e4specV3/cM1K s9oa3DKTSHa4YBA== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Hits: max-recipients X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-size; news-moderation; no-subject; digests; suspicious-header Message-ID-Hash: 4JFQHBZMNLU22RKOTGQ7CTLFHPY6TWKZ X-Message-ID-Hash: 4JFQHBZMNLU22RKOTGQ7CTLFHPY6TWKZ X-Mailman-Approved-At: Tue, 02 Apr 2024 06:48:50 +0000 X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: <> List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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