Message ID | 20240226193557.2888-2-W_Armin@gmx.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-82250-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2292999dyb; Mon, 26 Feb 2024 11:38:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWPZZAv38hroNInPXyRl9nKA1p9pMTPlQ38z/JFyvKACWQAfocPy4lWUrosQTlim40cpYnbn+obKUSe/X8AZqlckxziIw== X-Google-Smtp-Source: AGHT+IH6cY1wiq2SAFtwrhe9vIeg392uAsWwJ+SMllPcun++LY2Z0EfeaAamQZfC0fpPxgWWuXmr X-Received: by 2002:a05:6402:1b07:b0:565:7f43:a0e5 with SMTP id by7-20020a0564021b0700b005657f43a0e5mr5022267edb.20.1708976280282; Mon, 26 Feb 2024 11:38:00 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id k24-20020a508ad8000000b005661edf52e6si37669edk.659.2024.02.26.11.38.00 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 11:38:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82250-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmx.de header.s=s31663417 header.b=Lnx+qlg+; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-82250-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82250-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AB82A1F23B0A for <ouuuleilei@gmail.com>; Mon, 26 Feb 2024 19:37:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88965130E58; Mon, 26 Feb 2024 19:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="Lnx+qlg+" Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF9B412FF86; Mon, 26 Feb 2024 19:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708976202; cv=none; b=NYVMvIQsHyIsyqqEYU6vxiPxdLWH/T9w7kuMaBegZP7Q3XJQSU0QbtAS1c/3t1hjLKExdg0TuhbdnCOSFFWG+vc3utXYggBUxwXKLbOnEjgrnhMQolKtakQMuDDC0HWPJVwg5yfx2WqSlosGkO0Jh2aWDv1Ij/LvD641/b4ZDqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708976202; c=relaxed/simple; bh=2MBzDikgSPllH5SSceffq3hf3NNRNBuh2ZebYc9KLFU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OpRgGVqyrLTY9HDM6YQAPR44GCRit72d/IkgIcHSn0KMY3d/ZJ/omfIy2SjpkikR9QmFSPvA3UARm9SQY6uthU81Wiqj3MYH3+QdOcQkw7po0WoMmRJNC17wfNPA3AyyLbziJIEQndEZIGYnCFs2dvxv30Ah0lKb1LfdCh/dDKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=Lnx+qlg+; arc=none smtp.client-ip=212.227.17.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1708976167; x=1709580967; i=w_armin@gmx.de; bh=2MBzDikgSPllH5SSceffq3hf3NNRNBuh2ZebYc9KLFU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To: References; b=Lnx+qlg+YSABALUHig+PYcEeS5yWicr2qSYBc+3Dn1SZI4de1bq1R7t+dtY4FiXi h2E7D4DEErhKnr3jgGCubZkGaAeAV45cORzjk4Nz/XAildW0TfeqobGgQiz3W2reS h9AFWJrNWkJctOEzL2xU6+CG1rGb5GAuEB1lHLUbp/UgjtkOrMfPMM16fvBALoIva BFcyNuiyWitMxxJvqIaR94macJd8ru7+vvwtQmn28h4+ewyhdG5Sqnj+V1iHPjbN6 c/4RbsNn8EeHtViGotKVAmy9QiMZ+BW7c73E43W/3AO102VazHR6w0zh1khmSQ1IV 7wVdM1W/I4lVXqW0qQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MQvD5-1rIN602xQl-00NvOl; Mon, 26 Feb 2024 20:36:07 +0100 From: Armin Wolf <W_Armin@gmx.de> To: jithu.joseph@intel.com, linux@weissschuh.net, pali@kernel.org Cc: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, Dell.Client.Kernel@dell.com, jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] platform/x86: wmi: Do not instantiate older WMI drivers multiple times Date: Mon, 26 Feb 2024 20:35:56 +0100 Message-Id: <20240226193557.2888-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240226193557.2888-1-W_Armin@gmx.de> References: <20240226193557.2888-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:zBmwMbmkDKMJpCljEU9J9fD9nRUvemHsPHKma7Mmdk+LWv3OhMh Uetj7RE1fu1JkwTWW3hBPPAAZt65KegTN+8EB4xgIfRKjnNFKIgQluhJqquriD+HEYMteUL XVGvalSIQr21FmJMMMDqF1z3PfR+y1SPhSFCwVLvUjTRmsxRXJPlYo2aAI+dKYktkiB2A/s yfjfV+hptNYouNS0GPp4Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:lr/uKsM/SI8=;6nQ0TV7uXCpGzUwdCn1W69j6ImD oNilSyIzNr8wgRotQQ1hLHy+f972uYbv+Pdlwc20HP+d3SWHgs5L9XceAP/fmMmNna0qtzyij xNZ3zIa1jRASEAIaegrt9kKb0USGtcirwtiiAJpW49zoSmQRwh50KCZj9z4NA2ck2xLYGtb2p /HzbeKNg/BldgLMregyhZY0TTi8V2598LITzRU4cXRUBo+DjoFU5fpHd7m/FjX6XHxFpl3nro eco0o+P8VU6tTNYvKXuSr1BRCnHNOzqzCoq5Q3/okiKJ4Q9kDdjmGO+silMZaEj5PkmPsGJjP HCAmnpkFClsRzMv0fuC5x/KnF/fXgFzgmacyYlRjUSRZX5KPkpFxlUWwvOwyTaom8x9W243op w02qt8C93H/Y8vOmh+1mDDOLRJcdbZjTtE6BlHTHvHMurZklyfzxxpwt7AuOWELOLC4xhS46+ obCdVyfqVlWGt7T/qzS2O1sBoYoYf9zTtbxE8nwLx9O6dCaRWNmAjPtR1Hbj+ZH7M7mRMmpWB B8ksX53kmuDXDBKehrGc1sBS6cATei73WzczQ0icfBxZN/Pmn56EuU2H5x0MG3KOzhuI4ywGh JKk30F5kzFbenYU3Abn4UYCXVR5vR+9NPGCiUUtHypdYteiLjwkcwXvxSnBY0hX4H2rgJRReu /CO8zRZ0JiIIB2YPz4D6RbKfPhEYU0yRjXKlRYEQq67hfhJ1zY2sALLW2qp9lT6Bshcuemhn3 ReMasxI3y0Kfw8yua/YFeAU3jPwn90CSobl5GJjq/i8ZZ3Z/j+hv9ciedWjzO+rh3YLhtnJcm YkQke4BnqgHGJO+0c4biOzZv/S0cceGMR3+hKfUSrwzLA= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791991512268865306 X-GMAIL-MSGID: 1791991512268865306 |
Series |
None
|
|
Commit Message
Armin Wolf
Feb. 26, 2024, 7:35 p.m. UTC
Many older WMI drivers cannot be instantiated multiple times for
two reasons:
- they are using the legacy GUID-based WMI API
- they are singletons (with global state)
Prevent such WMI drivers from binding to WMI devices with a duplicated
GUID, as this would mean that the WMI driver will be instantiated at
least two times (one for the original GUID and one for the duplicated
GUID).
WMI drivers which can be instantiated multiple times can signal this
by setting a flag inside struct wmi_driver.
Tested on a ASUS Prime B650-Plus.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/hwmon/dell-smm-hwmon.c | 1 +
drivers/platform/x86/dell/dell-wmi-ddv.c | 1 +
drivers/platform/x86/intel/wmi/sbl-fw-update.c | 1 +
drivers/platform/x86/intel/wmi/thunderbolt.c | 1 +
drivers/platform/x86/wmi-bmof.c | 1 +
drivers/platform/x86/wmi.c | 12 ++++++++++++
include/linux/wmi.h | 2 ++
7 files changed, 19 insertions(+)
--
2.39.2
Comments
On Monday 26 February 2024 20:35:56 Armin Wolf wrote: > Many older WMI drivers cannot be instantiated multiple times for > two reasons: > > - they are using the legacy GUID-based WMI API > - they are singletons (with global state) > > Prevent such WMI drivers from binding to WMI devices with a duplicated > GUID, as this would mean that the WMI driver will be instantiated at > least two times (one for the original GUID and one for the duplicated > GUID). > WMI drivers which can be instantiated multiple times can signal this > by setting a flag inside struct wmi_driver. What do you think about opposite direction? Adding ".singleton = true" into every driver which is not compatible with duplicated initialization and having the default value that drivers are not singletons. But if the direction it to not accept new "legacy" drivers and start get rid of all "legacy" drivers by rewriting them, then it does not matter if "no_singleton" or "is_singleton" is used... > Tested on a ASUS Prime B650-Plus. > > Signed-off-by: Armin Wolf <W_Armin@gmx.de> > --- > drivers/hwmon/dell-smm-hwmon.c | 1 + > drivers/platform/x86/dell/dell-wmi-ddv.c | 1 + > drivers/platform/x86/intel/wmi/sbl-fw-update.c | 1 + > drivers/platform/x86/intel/wmi/thunderbolt.c | 1 + > drivers/platform/x86/wmi-bmof.c | 1 + > drivers/platform/x86/wmi.c | 12 ++++++++++++ > include/linux/wmi.h | 2 ++ > 7 files changed, 19 insertions(+) > > diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c > index 6d8c0f328b7b..168d669c4eca 100644 > --- a/drivers/hwmon/dell-smm-hwmon.c > +++ b/drivers/hwmon/dell-smm-hwmon.c > @@ -1587,6 +1587,7 @@ static struct wmi_driver dell_smm_wmi_driver = { > }, > .id_table = dell_smm_wmi_id_table, > .probe = dell_smm_wmi_probe, > + .no_singleton = true, > }; > > /* > diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c > index db1e9240dd02..0b2299f7a2de 100644 > --- a/drivers/platform/x86/dell/dell-wmi-ddv.c > +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c > @@ -882,6 +882,7 @@ static struct wmi_driver dell_wmi_ddv_driver = { > }, > .id_table = dell_wmi_ddv_id_table, > .probe = dell_wmi_ddv_probe, > + .no_singleton = true, > }; > module_wmi_driver(dell_wmi_ddv_driver); > > diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c > index 040153ad67c1..75c82c08117f 100644 > --- a/drivers/platform/x86/intel/wmi/sbl-fw-update.c > +++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c > @@ -131,6 +131,7 @@ static struct wmi_driver intel_wmi_sbl_fw_update_driver = { > .probe = intel_wmi_sbl_fw_update_probe, > .remove = intel_wmi_sbl_fw_update_remove, > .id_table = intel_wmi_sbl_id_table, > + .no_singleton = true, > }; > module_wmi_driver(intel_wmi_sbl_fw_update_driver); > > diff --git a/drivers/platform/x86/intel/wmi/thunderbolt.c b/drivers/platform/x86/intel/wmi/thunderbolt.c > index e2ad3f46f356..08df560a2c7a 100644 > --- a/drivers/platform/x86/intel/wmi/thunderbolt.c > +++ b/drivers/platform/x86/intel/wmi/thunderbolt.c > @@ -63,6 +63,7 @@ static struct wmi_driver intel_wmi_thunderbolt_driver = { > .dev_groups = tbt_groups, > }, > .id_table = intel_wmi_thunderbolt_id_table, > + .no_singleton = true, > }; > > module_wmi_driver(intel_wmi_thunderbolt_driver); > diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c > index 644d2fd889c0..df6f0ae6e6c7 100644 > --- a/drivers/platform/x86/wmi-bmof.c > +++ b/drivers/platform/x86/wmi-bmof.c > @@ -94,6 +94,7 @@ static struct wmi_driver wmi_bmof_driver = { > .probe = wmi_bmof_probe, > .remove = wmi_bmof_remove, > .id_table = wmi_bmof_id_table, > + .no_singleton = true, > }; > > module_wmi_driver(wmi_bmof_driver); > diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c > index 29dfe52eb802..349deced87e8 100644 > --- a/drivers/platform/x86/wmi.c > +++ b/drivers/platform/x86/wmi.c > @@ -883,6 +883,18 @@ static int wmi_dev_probe(struct device *dev) > struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); > int ret = 0; > > + /* Some older WMI drivers will break if instantiated multiple times, > + * so they are blocked from probing WMI devices with a duplicated GUID. > + * > + * New WMI drivers should support being instantiated multiple times. > + */ > + if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { > + dev_warn(dev, "Legacy driver %s cannot be instantiated multiple times\n", > + dev->driver->name); > + > + return -ENODEV; > + } > + > if (wdriver->notify) { > if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) > return -ENODEV; > diff --git a/include/linux/wmi.h b/include/linux/wmi.h > index 781958310bfb..63cca3b58d6d 100644 > --- a/include/linux/wmi.h > +++ b/include/linux/wmi.h > @@ -49,6 +49,7 @@ u8 wmidev_instance_count(struct wmi_device *wdev); > * @driver: Driver model structure > * @id_table: List of WMI GUIDs supported by this driver > * @no_notify_data: Driver supports WMI events which provide no event data > + * @no_singleton: Driver can be instantiated multiple times > * @probe: Callback for device binding > * @remove: Callback for device unbinding > * @notify: Callback for receiving WMI events > @@ -59,6 +60,7 @@ struct wmi_driver { > struct device_driver driver; > const struct wmi_device_id *id_table; > bool no_notify_data; > + bool no_singleton; > > int (*probe)(struct wmi_device *wdev, const void *context); > void (*remove)(struct wmi_device *wdev); > -- > 2.39.2 >
Am 27.02.24 um 21:30 schrieb Pali Rohár: > On Monday 26 February 2024 20:35:56 Armin Wolf wrote: >> Many older WMI drivers cannot be instantiated multiple times for >> two reasons: >> >> - they are using the legacy GUID-based WMI API >> - they are singletons (with global state) >> >> Prevent such WMI drivers from binding to WMI devices with a duplicated >> GUID, as this would mean that the WMI driver will be instantiated at >> least two times (one for the original GUID and one for the duplicated >> GUID). >> WMI drivers which can be instantiated multiple times can signal this >> by setting a flag inside struct wmi_driver. > What do you think about opposite direction? Adding ".singleton = true" > into every driver which is not compatible with duplicated initialization > and having the default value that drivers are not singletons. > > But if the direction it to not accept new "legacy" drivers and start get > rid of all "legacy" drivers by rewriting them, then it does not matter > if "no_singleton" or "is_singleton" is used... Hi, i want to make sure that i wont forget any legacy WMI drivers. This way, the older legacy WMI drivers automatically initialize no_singleton with false. Also i intent to not accept new legacy WMI drivers. Thanks, Armin Wolf >> Tested on a ASUS Prime B650-Plus. >> >> Signed-off-by: Armin Wolf <W_Armin@gmx.de> >> --- >> drivers/hwmon/dell-smm-hwmon.c | 1 + >> drivers/platform/x86/dell/dell-wmi-ddv.c | 1 + >> drivers/platform/x86/intel/wmi/sbl-fw-update.c | 1 + >> drivers/platform/x86/intel/wmi/thunderbolt.c | 1 + >> drivers/platform/x86/wmi-bmof.c | 1 + >> drivers/platform/x86/wmi.c | 12 ++++++++++++ >> include/linux/wmi.h | 2 ++ >> 7 files changed, 19 insertions(+) >> >> diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c >> index 6d8c0f328b7b..168d669c4eca 100644 >> --- a/drivers/hwmon/dell-smm-hwmon.c >> +++ b/drivers/hwmon/dell-smm-hwmon.c >> @@ -1587,6 +1587,7 @@ static struct wmi_driver dell_smm_wmi_driver = { >> }, >> .id_table = dell_smm_wmi_id_table, >> .probe = dell_smm_wmi_probe, >> + .no_singleton = true, >> }; >> >> /* >> diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c >> index db1e9240dd02..0b2299f7a2de 100644 >> --- a/drivers/platform/x86/dell/dell-wmi-ddv.c >> +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c >> @@ -882,6 +882,7 @@ static struct wmi_driver dell_wmi_ddv_driver = { >> }, >> .id_table = dell_wmi_ddv_id_table, >> .probe = dell_wmi_ddv_probe, >> + .no_singleton = true, >> }; >> module_wmi_driver(dell_wmi_ddv_driver); >> >> diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c >> index 040153ad67c1..75c82c08117f 100644 >> --- a/drivers/platform/x86/intel/wmi/sbl-fw-update.c >> +++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c >> @@ -131,6 +131,7 @@ static struct wmi_driver intel_wmi_sbl_fw_update_driver = { >> .probe = intel_wmi_sbl_fw_update_probe, >> .remove = intel_wmi_sbl_fw_update_remove, >> .id_table = intel_wmi_sbl_id_table, >> + .no_singleton = true, >> }; >> module_wmi_driver(intel_wmi_sbl_fw_update_driver); >> >> diff --git a/drivers/platform/x86/intel/wmi/thunderbolt.c b/drivers/platform/x86/intel/wmi/thunderbolt.c >> index e2ad3f46f356..08df560a2c7a 100644 >> --- a/drivers/platform/x86/intel/wmi/thunderbolt.c >> +++ b/drivers/platform/x86/intel/wmi/thunderbolt.c >> @@ -63,6 +63,7 @@ static struct wmi_driver intel_wmi_thunderbolt_driver = { >> .dev_groups = tbt_groups, >> }, >> .id_table = intel_wmi_thunderbolt_id_table, >> + .no_singleton = true, >> }; >> >> module_wmi_driver(intel_wmi_thunderbolt_driver); >> diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c >> index 644d2fd889c0..df6f0ae6e6c7 100644 >> --- a/drivers/platform/x86/wmi-bmof.c >> +++ b/drivers/platform/x86/wmi-bmof.c >> @@ -94,6 +94,7 @@ static struct wmi_driver wmi_bmof_driver = { >> .probe = wmi_bmof_probe, >> .remove = wmi_bmof_remove, >> .id_table = wmi_bmof_id_table, >> + .no_singleton = true, >> }; >> >> module_wmi_driver(wmi_bmof_driver); >> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c >> index 29dfe52eb802..349deced87e8 100644 >> --- a/drivers/platform/x86/wmi.c >> +++ b/drivers/platform/x86/wmi.c >> @@ -883,6 +883,18 @@ static int wmi_dev_probe(struct device *dev) >> struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); >> int ret = 0; >> >> + /* Some older WMI drivers will break if instantiated multiple times, >> + * so they are blocked from probing WMI devices with a duplicated GUID. >> + * >> + * New WMI drivers should support being instantiated multiple times. >> + */ >> + if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { >> + dev_warn(dev, "Legacy driver %s cannot be instantiated multiple times\n", >> + dev->driver->name); >> + >> + return -ENODEV; >> + } >> + >> if (wdriver->notify) { >> if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) >> return -ENODEV; >> diff --git a/include/linux/wmi.h b/include/linux/wmi.h >> index 781958310bfb..63cca3b58d6d 100644 >> --- a/include/linux/wmi.h >> +++ b/include/linux/wmi.h >> @@ -49,6 +49,7 @@ u8 wmidev_instance_count(struct wmi_device *wdev); >> * @driver: Driver model structure >> * @id_table: List of WMI GUIDs supported by this driver >> * @no_notify_data: Driver supports WMI events which provide no event data >> + * @no_singleton: Driver can be instantiated multiple times >> * @probe: Callback for device binding >> * @remove: Callback for device unbinding >> * @notify: Callback for receiving WMI events >> @@ -59,6 +60,7 @@ struct wmi_driver { >> struct device_driver driver; >> const struct wmi_device_id *id_table; >> bool no_notify_data; >> + bool no_singleton; >> >> int (*probe)(struct wmi_device *wdev, const void *context); >> void (*remove)(struct wmi_device *wdev); >> -- >> 2.39.2 >>
On Tuesday 27 February 2024 23:47:11 Armin Wolf wrote: > Am 27.02.24 um 21:30 schrieb Pali Rohár: > > > On Monday 26 February 2024 20:35:56 Armin Wolf wrote: > > > Many older WMI drivers cannot be instantiated multiple times for > > > two reasons: > > > > > > - they are using the legacy GUID-based WMI API > > > - they are singletons (with global state) > > > > > > Prevent such WMI drivers from binding to WMI devices with a duplicated > > > GUID, as this would mean that the WMI driver will be instantiated at > > > least two times (one for the original GUID and one for the duplicated > > > GUID). > > > WMI drivers which can be instantiated multiple times can signal this > > > by setting a flag inside struct wmi_driver. > > What do you think about opposite direction? Adding ".singleton = true" > > into every driver which is not compatible with duplicated initialization > > and having the default value that drivers are not singletons. > > > > But if the direction it to not accept new "legacy" drivers and start get > > rid of all "legacy" drivers by rewriting them, then it does not matter > > if "no_singleton" or "is_singleton" is used... > > Hi, > > i want to make sure that i wont forget any legacy WMI drivers. This way, the > older legacy WMI drivers automatically initialize no_singleton with false. > > Also i intent to not accept new legacy WMI drivers. Ok. In this case it does not matter. > Thanks, > Armin Wolf > > > > Tested on a ASUS Prime B650-Plus. > > > > > > Signed-off-by: Armin Wolf <W_Armin@gmx.de> > > > --- > > > drivers/hwmon/dell-smm-hwmon.c | 1 + > > > drivers/platform/x86/dell/dell-wmi-ddv.c | 1 + > > > drivers/platform/x86/intel/wmi/sbl-fw-update.c | 1 + > > > drivers/platform/x86/intel/wmi/thunderbolt.c | 1 + > > > drivers/platform/x86/wmi-bmof.c | 1 + > > > drivers/platform/x86/wmi.c | 12 ++++++++++++ > > > include/linux/wmi.h | 2 ++ > > > 7 files changed, 19 insertions(+) > > > > > > diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c > > > index 6d8c0f328b7b..168d669c4eca 100644 > > > --- a/drivers/hwmon/dell-smm-hwmon.c > > > +++ b/drivers/hwmon/dell-smm-hwmon.c > > > @@ -1587,6 +1587,7 @@ static struct wmi_driver dell_smm_wmi_driver = { > > > }, > > > .id_table = dell_smm_wmi_id_table, > > > .probe = dell_smm_wmi_probe, > > > + .no_singleton = true, > > > }; > > > > > > /* > > > diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c > > > index db1e9240dd02..0b2299f7a2de 100644 > > > --- a/drivers/platform/x86/dell/dell-wmi-ddv.c > > > +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c > > > @@ -882,6 +882,7 @@ static struct wmi_driver dell_wmi_ddv_driver = { > > > }, > > > .id_table = dell_wmi_ddv_id_table, > > > .probe = dell_wmi_ddv_probe, > > > + .no_singleton = true, > > > }; > > > module_wmi_driver(dell_wmi_ddv_driver); > > > > > > diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c > > > index 040153ad67c1..75c82c08117f 100644 > > > --- a/drivers/platform/x86/intel/wmi/sbl-fw-update.c > > > +++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c > > > @@ -131,6 +131,7 @@ static struct wmi_driver intel_wmi_sbl_fw_update_driver = { > > > .probe = intel_wmi_sbl_fw_update_probe, > > > .remove = intel_wmi_sbl_fw_update_remove, > > > .id_table = intel_wmi_sbl_id_table, > > > + .no_singleton = true, > > > }; > > > module_wmi_driver(intel_wmi_sbl_fw_update_driver); > > > > > > diff --git a/drivers/platform/x86/intel/wmi/thunderbolt.c b/drivers/platform/x86/intel/wmi/thunderbolt.c > > > index e2ad3f46f356..08df560a2c7a 100644 > > > --- a/drivers/platform/x86/intel/wmi/thunderbolt.c > > > +++ b/drivers/platform/x86/intel/wmi/thunderbolt.c > > > @@ -63,6 +63,7 @@ static struct wmi_driver intel_wmi_thunderbolt_driver = { > > > .dev_groups = tbt_groups, > > > }, > > > .id_table = intel_wmi_thunderbolt_id_table, > > > + .no_singleton = true, > > > }; > > > > > > module_wmi_driver(intel_wmi_thunderbolt_driver); > > > diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c > > > index 644d2fd889c0..df6f0ae6e6c7 100644 > > > --- a/drivers/platform/x86/wmi-bmof.c > > > +++ b/drivers/platform/x86/wmi-bmof.c > > > @@ -94,6 +94,7 @@ static struct wmi_driver wmi_bmof_driver = { > > > .probe = wmi_bmof_probe, > > > .remove = wmi_bmof_remove, > > > .id_table = wmi_bmof_id_table, > > > + .no_singleton = true, > > > }; > > > > > > module_wmi_driver(wmi_bmof_driver); > > > diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c > > > index 29dfe52eb802..349deced87e8 100644 > > > --- a/drivers/platform/x86/wmi.c > > > +++ b/drivers/platform/x86/wmi.c > > > @@ -883,6 +883,18 @@ static int wmi_dev_probe(struct device *dev) > > > struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); > > > int ret = 0; > > > > > > + /* Some older WMI drivers will break if instantiated multiple times, > > > + * so they are blocked from probing WMI devices with a duplicated GUID. > > > + * > > > + * New WMI drivers should support being instantiated multiple times. > > > + */ > > > + if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { > > > + dev_warn(dev, "Legacy driver %s cannot be instantiated multiple times\n", > > > + dev->driver->name); > > > + > > > + return -ENODEV; > > > + } > > > + > > > if (wdriver->notify) { > > > if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) > > > return -ENODEV; > > > diff --git a/include/linux/wmi.h b/include/linux/wmi.h > > > index 781958310bfb..63cca3b58d6d 100644 > > > --- a/include/linux/wmi.h > > > +++ b/include/linux/wmi.h > > > @@ -49,6 +49,7 @@ u8 wmidev_instance_count(struct wmi_device *wdev); > > > * @driver: Driver model structure > > > * @id_table: List of WMI GUIDs supported by this driver > > > * @no_notify_data: Driver supports WMI events which provide no event data > > > + * @no_singleton: Driver can be instantiated multiple times > > > * @probe: Callback for device binding > > > * @remove: Callback for device unbinding > > > * @notify: Callback for receiving WMI events > > > @@ -59,6 +60,7 @@ struct wmi_driver { > > > struct device_driver driver; > > > const struct wmi_device_id *id_table; > > > bool no_notify_data; > > > + bool no_singleton; > > > > > > int (*probe)(struct wmi_device *wdev, const void *context); > > > void (*remove)(struct wmi_device *wdev); > > > -- > > > 2.39.2 > > >
Hi Armin, On 2/27/24 23:47, Armin Wolf wrote: > Am 27.02.24 um 21:30 schrieb Pali Rohár: > >> On Monday 26 February 2024 20:35:56 Armin Wolf wrote: >>> Many older WMI drivers cannot be instantiated multiple times for >>> two reasons: >>> >>> - they are using the legacy GUID-based WMI API >>> - they are singletons (with global state) >>> >>> Prevent such WMI drivers from binding to WMI devices with a duplicated >>> GUID, as this would mean that the WMI driver will be instantiated at >>> least two times (one for the original GUID and one for the duplicated >>> GUID). >>> WMI drivers which can be instantiated multiple times can signal this >>> by setting a flag inside struct wmi_driver. >> What do you think about opposite direction? Adding ".singleton = true" >> into every driver which is not compatible with duplicated initialization >> and having the default value that drivers are not singletons. >> >> But if the direction it to not accept new "legacy" drivers and start get >> rid of all "legacy" drivers by rewriting them, then it does not matter >> if "no_singleton" or "is_singleton" is used... > > Hi, > > i want to make sure that i wont forget any legacy WMI drivers. This way, the > older legacy WMI drivers automatically initialize no_singleton with false. > > Also i intent to not accept new legacy WMI drivers. Somewhat offtopic question, how do you plan to handle the case where there are 2 WMI GUIDs for what really is a single "thing", specifically one main WMI GUID for a vendor specific interface for say the embedded-controller and a separate GUID for events ? IIRC we have several such cases. I thought we even have a case where the main WMI GUID already is bound to using wmi_bus wmi_driver, while the event guid is listened to by using wmi_install_notify_handler() but I cannot find the code doing this, so I might be mistaken on this. Regards, Hans >>> Tested on a ASUS Prime B650-Plus. >>> >>> Signed-off-by: Armin Wolf <W_Armin@gmx.de> >>> --- >>> drivers/hwmon/dell-smm-hwmon.c | 1 + >>> drivers/platform/x86/dell/dell-wmi-ddv.c | 1 + >>> drivers/platform/x86/intel/wmi/sbl-fw-update.c | 1 + >>> drivers/platform/x86/intel/wmi/thunderbolt.c | 1 + >>> drivers/platform/x86/wmi-bmof.c | 1 + >>> drivers/platform/x86/wmi.c | 12 ++++++++++++ >>> include/linux/wmi.h | 2 ++ >>> 7 files changed, 19 insertions(+) >>> >>> diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c >>> index 6d8c0f328b7b..168d669c4eca 100644 >>> --- a/drivers/hwmon/dell-smm-hwmon.c >>> +++ b/drivers/hwmon/dell-smm-hwmon.c >>> @@ -1587,6 +1587,7 @@ static struct wmi_driver dell_smm_wmi_driver = { >>> }, >>> .id_table = dell_smm_wmi_id_table, >>> .probe = dell_smm_wmi_probe, >>> + .no_singleton = true, >>> }; >>> >>> /* >>> diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c >>> index db1e9240dd02..0b2299f7a2de 100644 >>> --- a/drivers/platform/x86/dell/dell-wmi-ddv.c >>> +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c >>> @@ -882,6 +882,7 @@ static struct wmi_driver dell_wmi_ddv_driver = { >>> }, >>> .id_table = dell_wmi_ddv_id_table, >>> .probe = dell_wmi_ddv_probe, >>> + .no_singleton = true, >>> }; >>> module_wmi_driver(dell_wmi_ddv_driver); >>> >>> diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c >>> index 040153ad67c1..75c82c08117f 100644 >>> --- a/drivers/platform/x86/intel/wmi/sbl-fw-update.c >>> +++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c >>> @@ -131,6 +131,7 @@ static struct wmi_driver intel_wmi_sbl_fw_update_driver = { >>> .probe = intel_wmi_sbl_fw_update_probe, >>> .remove = intel_wmi_sbl_fw_update_remove, >>> .id_table = intel_wmi_sbl_id_table, >>> + .no_singleton = true, >>> }; >>> module_wmi_driver(intel_wmi_sbl_fw_update_driver); >>> >>> diff --git a/drivers/platform/x86/intel/wmi/thunderbolt.c b/drivers/platform/x86/intel/wmi/thunderbolt.c >>> index e2ad3f46f356..08df560a2c7a 100644 >>> --- a/drivers/platform/x86/intel/wmi/thunderbolt.c >>> +++ b/drivers/platform/x86/intel/wmi/thunderbolt.c >>> @@ -63,6 +63,7 @@ static struct wmi_driver intel_wmi_thunderbolt_driver = { >>> .dev_groups = tbt_groups, >>> }, >>> .id_table = intel_wmi_thunderbolt_id_table, >>> + .no_singleton = true, >>> }; >>> >>> module_wmi_driver(intel_wmi_thunderbolt_driver); >>> diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c >>> index 644d2fd889c0..df6f0ae6e6c7 100644 >>> --- a/drivers/platform/x86/wmi-bmof.c >>> +++ b/drivers/platform/x86/wmi-bmof.c >>> @@ -94,6 +94,7 @@ static struct wmi_driver wmi_bmof_driver = { >>> .probe = wmi_bmof_probe, >>> .remove = wmi_bmof_remove, >>> .id_table = wmi_bmof_id_table, >>> + .no_singleton = true, >>> }; >>> >>> module_wmi_driver(wmi_bmof_driver); >>> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c >>> index 29dfe52eb802..349deced87e8 100644 >>> --- a/drivers/platform/x86/wmi.c >>> +++ b/drivers/platform/x86/wmi.c >>> @@ -883,6 +883,18 @@ static int wmi_dev_probe(struct device *dev) >>> struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); >>> int ret = 0; >>> >>> + /* Some older WMI drivers will break if instantiated multiple times, >>> + * so they are blocked from probing WMI devices with a duplicated GUID. >>> + * >>> + * New WMI drivers should support being instantiated multiple times. >>> + */ >>> + if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { >>> + dev_warn(dev, "Legacy driver %s cannot be instantiated multiple times\n", >>> + dev->driver->name); >>> + >>> + return -ENODEV; >>> + } >>> + >>> if (wdriver->notify) { >>> if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) >>> return -ENODEV; >>> diff --git a/include/linux/wmi.h b/include/linux/wmi.h >>> index 781958310bfb..63cca3b58d6d 100644 >>> --- a/include/linux/wmi.h >>> +++ b/include/linux/wmi.h >>> @@ -49,6 +49,7 @@ u8 wmidev_instance_count(struct wmi_device *wdev); >>> * @driver: Driver model structure >>> * @id_table: List of WMI GUIDs supported by this driver >>> * @no_notify_data: Driver supports WMI events which provide no event data >>> + * @no_singleton: Driver can be instantiated multiple times >>> * @probe: Callback for device binding >>> * @remove: Callback for device unbinding >>> * @notify: Callback for receiving WMI events >>> @@ -59,6 +60,7 @@ struct wmi_driver { >>> struct device_driver driver; >>> const struct wmi_device_id *id_table; >>> bool no_notify_data; >>> + bool no_singleton; >>> >>> int (*probe)(struct wmi_device *wdev, const void *context); >>> void (*remove)(struct wmi_device *wdev); >>> -- >>> 2.39.2 >>> >
Am 28.02.24 um 14:23 schrieb Hans de Goede: > Hi Armin, > > On 2/27/24 23:47, Armin Wolf wrote: >> Am 27.02.24 um 21:30 schrieb Pali Rohár: >> >>> On Monday 26 February 2024 20:35:56 Armin Wolf wrote: >>>> Many older WMI drivers cannot be instantiated multiple times for >>>> two reasons: >>>> >>>> - they are using the legacy GUID-based WMI API >>>> - they are singletons (with global state) >>>> >>>> Prevent such WMI drivers from binding to WMI devices with a duplicated >>>> GUID, as this would mean that the WMI driver will be instantiated at >>>> least two times (one for the original GUID and one for the duplicated >>>> GUID). >>>> WMI drivers which can be instantiated multiple times can signal this >>>> by setting a flag inside struct wmi_driver. >>> What do you think about opposite direction? Adding ".singleton = true" >>> into every driver which is not compatible with duplicated initialization >>> and having the default value that drivers are not singletons. >>> >>> But if the direction it to not accept new "legacy" drivers and start get >>> rid of all "legacy" drivers by rewriting them, then it does not matter >>> if "no_singleton" or "is_singleton" is used... >> Hi, >> >> i want to make sure that i wont forget any legacy WMI drivers. This way, the >> older legacy WMI drivers automatically initialize no_singleton with false. >> >> Also i intent to not accept new legacy WMI drivers. > Somewhat offtopic question, how do you plan to handle the case where > there are 2 WMI GUIDs for what really is a single "thing", > specifically one main WMI GUID for a vendor specific interface > for say the embedded-controller and a separate GUID for events ? > > IIRC we have several such cases. I thought we even have a case > where the main WMI GUID already is bound to using wmi_bus wmi_driver, > while the event guid is listened to by using wmi_install_notify_handler() > but I cannot find the code doing this, so I might be mistaken on this. > > Regards, > > Hans I am aware of those WMI device constellations, for the classic event-data constellation i think there should be two WMI drivers (one for the event and one for the data) which are connected with each other through a standard notifier. I plan on writing a WMI driver developing guide which will address this by giving examples on what to do in such cases. The problem is that many WMI interfaces consisting of multiple GUIDs are inherently unstable since the vendor assumes that they will just be available after the Windows userspace has loaded, so the WMI driver has no means of discovering which GUIDs are available at probe time (other GUIDs can be discovered later by the WMI driver core, so the WMI driver cannot see them sooner). The solution for this depends on the specific WMI device constellation. Armin Wolf. > >>>> Tested on a ASUS Prime B650-Plus. >>>> >>>> Signed-off-by: Armin Wolf <W_Armin@gmx.de> >>>> --- >>>> drivers/hwmon/dell-smm-hwmon.c | 1 + >>>> drivers/platform/x86/dell/dell-wmi-ddv.c | 1 + >>>> drivers/platform/x86/intel/wmi/sbl-fw-update.c | 1 + >>>> drivers/platform/x86/intel/wmi/thunderbolt.c | 1 + >>>> drivers/platform/x86/wmi-bmof.c | 1 + >>>> drivers/platform/x86/wmi.c | 12 ++++++++++++ >>>> include/linux/wmi.h | 2 ++ >>>> 7 files changed, 19 insertions(+) >>>> >>>> diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c >>>> index 6d8c0f328b7b..168d669c4eca 100644 >>>> --- a/drivers/hwmon/dell-smm-hwmon.c >>>> +++ b/drivers/hwmon/dell-smm-hwmon.c >>>> @@ -1587,6 +1587,7 @@ static struct wmi_driver dell_smm_wmi_driver = { >>>> }, >>>> .id_table = dell_smm_wmi_id_table, >>>> .probe = dell_smm_wmi_probe, >>>> + .no_singleton = true, >>>> }; >>>> >>>> /* >>>> diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c >>>> index db1e9240dd02..0b2299f7a2de 100644 >>>> --- a/drivers/platform/x86/dell/dell-wmi-ddv.c >>>> +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c >>>> @@ -882,6 +882,7 @@ static struct wmi_driver dell_wmi_ddv_driver = { >>>> }, >>>> .id_table = dell_wmi_ddv_id_table, >>>> .probe = dell_wmi_ddv_probe, >>>> + .no_singleton = true, >>>> }; >>>> module_wmi_driver(dell_wmi_ddv_driver); >>>> >>>> diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c >>>> index 040153ad67c1..75c82c08117f 100644 >>>> --- a/drivers/platform/x86/intel/wmi/sbl-fw-update.c >>>> +++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c >>>> @@ -131,6 +131,7 @@ static struct wmi_driver intel_wmi_sbl_fw_update_driver = { >>>> .probe = intel_wmi_sbl_fw_update_probe, >>>> .remove = intel_wmi_sbl_fw_update_remove, >>>> .id_table = intel_wmi_sbl_id_table, >>>> + .no_singleton = true, >>>> }; >>>> module_wmi_driver(intel_wmi_sbl_fw_update_driver); >>>> >>>> diff --git a/drivers/platform/x86/intel/wmi/thunderbolt.c b/drivers/platform/x86/intel/wmi/thunderbolt.c >>>> index e2ad3f46f356..08df560a2c7a 100644 >>>> --- a/drivers/platform/x86/intel/wmi/thunderbolt.c >>>> +++ b/drivers/platform/x86/intel/wmi/thunderbolt.c >>>> @@ -63,6 +63,7 @@ static struct wmi_driver intel_wmi_thunderbolt_driver = { >>>> .dev_groups = tbt_groups, >>>> }, >>>> .id_table = intel_wmi_thunderbolt_id_table, >>>> + .no_singleton = true, >>>> }; >>>> >>>> module_wmi_driver(intel_wmi_thunderbolt_driver); >>>> diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c >>>> index 644d2fd889c0..df6f0ae6e6c7 100644 >>>> --- a/drivers/platform/x86/wmi-bmof.c >>>> +++ b/drivers/platform/x86/wmi-bmof.c >>>> @@ -94,6 +94,7 @@ static struct wmi_driver wmi_bmof_driver = { >>>> .probe = wmi_bmof_probe, >>>> .remove = wmi_bmof_remove, >>>> .id_table = wmi_bmof_id_table, >>>> + .no_singleton = true, >>>> }; >>>> >>>> module_wmi_driver(wmi_bmof_driver); >>>> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c >>>> index 29dfe52eb802..349deced87e8 100644 >>>> --- a/drivers/platform/x86/wmi.c >>>> +++ b/drivers/platform/x86/wmi.c >>>> @@ -883,6 +883,18 @@ static int wmi_dev_probe(struct device *dev) >>>> struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); >>>> int ret = 0; >>>> >>>> + /* Some older WMI drivers will break if instantiated multiple times, >>>> + * so they are blocked from probing WMI devices with a duplicated GUID. >>>> + * >>>> + * New WMI drivers should support being instantiated multiple times. >>>> + */ >>>> + if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { >>>> + dev_warn(dev, "Legacy driver %s cannot be instantiated multiple times\n", >>>> + dev->driver->name); >>>> + >>>> + return -ENODEV; >>>> + } >>>> + >>>> if (wdriver->notify) { >>>> if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) >>>> return -ENODEV; >>>> diff --git a/include/linux/wmi.h b/include/linux/wmi.h >>>> index 781958310bfb..63cca3b58d6d 100644 >>>> --- a/include/linux/wmi.h >>>> +++ b/include/linux/wmi.h >>>> @@ -49,6 +49,7 @@ u8 wmidev_instance_count(struct wmi_device *wdev); >>>> * @driver: Driver model structure >>>> * @id_table: List of WMI GUIDs supported by this driver >>>> * @no_notify_data: Driver supports WMI events which provide no event data >>>> + * @no_singleton: Driver can be instantiated multiple times >>>> * @probe: Callback for device binding >>>> * @remove: Callback for device unbinding >>>> * @notify: Callback for receiving WMI events >>>> @@ -59,6 +60,7 @@ struct wmi_driver { >>>> struct device_driver driver; >>>> const struct wmi_device_id *id_table; >>>> bool no_notify_data; >>>> + bool no_singleton; >>>> >>>> int (*probe)(struct wmi_device *wdev, const void *context); >>>> void (*remove)(struct wmi_device *wdev); >>>> -- >>>> 2.39.2 >>>> >
diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmonc index 6d8c0f328b7b..168d669c4eca 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1587,6 +1587,7 @@ static struct wmi_driver dell_smm_wmi_driver = { }, .id_table = dell_smm_wmi_id_table, .probe = dell_smm_wmi_probe, + .no_singleton = true, }; /* diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c index db1e9240dd02..0b2299f7a2de 100644 --- a/drivers/platform/x86/dell/dell-wmi-ddv.c +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c @@ -882,6 +882,7 @@ static struct wmi_driver dell_wmi_ddv_driver = { }, .id_table = dell_wmi_ddv_id_table, .probe = dell_wmi_ddv_probe, + .no_singleton = true, }; module_wmi_driver(dell_wmi_ddv_driver); diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c index 040153ad67c1..75c82c08117f 100644 --- a/drivers/platform/x86/intel/wmi/sbl-fw-update.c +++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c @@ -131,6 +131,7 @@ static struct wmi_driver intel_wmi_sbl_fw_update_driver = { .probe = intel_wmi_sbl_fw_update_probe, .remove = intel_wmi_sbl_fw_update_remove, .id_table = intel_wmi_sbl_id_table, + .no_singleton = true, }; module_wmi_driver(intel_wmi_sbl_fw_update_driver); diff --git a/drivers/platform/x86/intel/wmi/thunderbolt.c b/drivers/platform/x86/intel/wmi/thunderbolt.c index e2ad3f46f356..08df560a2c7a 100644 --- a/drivers/platform/x86/intel/wmi/thunderbolt.c +++ b/drivers/platform/x86/intel/wmi/thunderbolt.c @@ -63,6 +63,7 @@ static struct wmi_driver intel_wmi_thunderbolt_driver = { .dev_groups = tbt_groups, }, .id_table = intel_wmi_thunderbolt_id_table, + .no_singleton = true, }; module_wmi_driver(intel_wmi_thunderbolt_driver); diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c index 644d2fd889c0..df6f0ae6e6c7 100644 --- a/drivers/platform/x86/wmi-bmof.c +++ b/drivers/platform/x86/wmi-bmof.c @@ -94,6 +94,7 @@ static struct wmi_driver wmi_bmof_driver = { .probe = wmi_bmof_probe, .remove = wmi_bmof_remove, .id_table = wmi_bmof_id_table, + .no_singleton = true, }; module_wmi_driver(wmi_bmof_driver); diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 29dfe52eb802..349deced87e8 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -883,6 +883,18 @@ static int wmi_dev_probe(struct device *dev) struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); int ret = 0; + /* Some older WMI drivers will break if instantiated multiple times, + * so they are blocked from probing WMI devices with a duplicated GUID. + * + * New WMI drivers should support being instantiated multiple times. + */ + if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { + dev_warn(dev, "Legacy driver %s cannot be instantiated multiple times\n", + dev->driver->name); + + return -ENODEV; + } + if (wdriver->notify) { if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) return -ENODEV; diff --git a/include/linux/wmi.h b/include/linux/wmi.h index 781958310bfb..63cca3b58d6d 100644 --- a/include/linux/wmi.h +++ b/include/linux/wmi.h @@ -49,6 +49,7 @@ u8 wmidev_instance_count(struct wmi_device *wdev); * @driver: Driver model structure * @id_table: List of WMI GUIDs supported by this driver * @no_notify_data: Driver supports WMI events which provide no event data + * @no_singleton: Driver can be instantiated multiple times * @probe: Callback for device binding * @remove: Callback for device unbinding * @notify: Callback for receiving WMI events @@ -59,6 +60,7 @@ struct wmi_driver { struct device_driver driver; const struct wmi_device_id *id_table; bool no_notify_data; + bool no_singleton; int (*probe)(struct wmi_device *wdev, const void *context); void (*remove)(struct wmi_device *wdev);