lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <66dbff89-131b-4bc5-1059-c97342b2efca@linux.intel.com>
Date: Mon, 30 Jun 2025 11:58:39 +0300 (EEST)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: Armin Wolf <W_Armin@....de>, sre@...nel.org
cc: Hans de Goede <hansg@...nel.org>, Hans de Goede <hdegoede@...hat.com>, 
    linux-pm@...r.kernel.org, platform-driver-x86@...r.kernel.org, 
    LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/3] power: supply: core: Add
 power_supply_get/set_property_direct()

On Sat, 28 Jun 2025, Armin Wolf wrote:

> Am 28.06.25 um 11:25 schrieb Hans de Goede:
> 
> > Hi Armin,
> > 
> > On 27-Jun-25 10:51 PM, Armin Wolf wrote:
> > > Power supply extensions might want to interact with the underlying
> > > power supply to retrieve data like serial numbers, charging status
> > > and more. However doing so causes psy->extensions_sem to be locked
> > > twice, possibly causing a deadlock.
> > > 
> > > Provide special variants of power_supply_get/set_property() that
> > > ignore any power supply extensions and thus do not touch the
> > > associated psy->extensions_sem lock.
> > > 
> > > Suggested-by: Hans de Goede <hansg@...nel.org>
> > > Signed-off-by: Armin Wolf <W_Armin@....de>
> > Thank you for your work on this.
> > 
> > The entire series looks good to me:
> > 
> > Reviewed-by: Hans de Goede <hansg@...nel.org>
> > 
> > for the series.
> > 
> > There is the question of how to merge this. I think it might
> > be best for the entire series to go through the power-supply
> > tree.
> > 
> > Ilpo would that work for you and if yes can we have your ack ?
> > 
> > Sebastian, IMHO this should be merged as fixed not as for-next
> > material.
> > 
> > Regards,
> > 
> > Hans
> 
> Personally i would prefer to merge this through the pdx86 tree as the
> uniwill-laptop driver currently under review will also require this
> functionality.

Sebastian, are you okay if I take this through pdx86 fixes branch as 
requested by Armin? If yes, can I have your ack please.


-- 
 i.

> > > ---
> > >   drivers/power/supply/power_supply_core.c | 82 ++++++++++++++++++++----
> > >   include/linux/power_supply.h             |  8 +++
> > >   2 files changed, 78 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/drivers/power/supply/power_supply_core.c
> > > b/drivers/power/supply/power_supply_core.c
> > > index aedb20c1d276..e70ffedf1a80 100644
> > > --- a/drivers/power/supply/power_supply_core.c
> > > +++ b/drivers/power/supply/power_supply_core.c
> > > @@ -1241,9 +1241,8 @@ bool power_supply_has_property(struct power_supply
> > > *psy,
> > >   	return false;
> > >   }
> > >   -int power_supply_get_property(struct power_supply *psy,
> > > -			    enum power_supply_property psp,
> > > -			    union power_supply_propval *val)
> > > +static int __power_supply_get_property(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +				       union power_supply_propval *val, bool
> > > use_extensions)
> > >   {
> > >   	struct power_supply_ext_registration *reg;
> > >   @@ -1253,10 +1252,14 @@ int power_supply_get_property(struct
> > > power_supply *psy,
> > >   		return -ENODEV;
> > >   	}
> > >   -	scoped_guard(rwsem_read, &psy->extensions_sem) {
> > > -		power_supply_for_each_extension(reg, psy) {
> > > -			if (power_supply_ext_has_property(reg->ext, psp))
> > > +	if (use_extensions) {
> > > +		scoped_guard(rwsem_read, &psy->extensions_sem) {
> > > +			power_supply_for_each_extension(reg, psy) {
> > > +				if (!power_supply_ext_has_property(reg->ext,
> > > psp))
> > > +					continue;
> > > +
> > >   				return reg->ext->get_property(psy, reg->ext,
> > > reg->data, psp, val);
> > > +			}
> > >   		}
> > >   	}
> > >   @@ -1267,20 +1270,49 @@ int power_supply_get_property(struct
> > > power_supply *psy,
> > >   	else
> > >   		return -EINVAL;
> > >   }
> > > +
> > > +int power_supply_get_property(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +			      union power_supply_propval *val)
> > > +{
> > > +	return __power_supply_get_property(psy, psp, val, true);
> > > +}
> > >   EXPORT_SYMBOL_GPL(power_supply_get_property);
> > >   -int power_supply_set_property(struct power_supply *psy,
> > > -			    enum power_supply_property psp,
> > > -			    const union power_supply_propval *val)
> > > +/**
> > > + * power_supply_get_property_direct - Read a power supply property
> > > without checking for extensions
> > > + * @psy: The power supply
> > > + * @psp: The power supply property to read
> > > + * @val: The resulting value of the power supply property
> > > + *
> > > + * Read a power supply property without taking into account any power
> > > supply extensions registered
> > > + * on the given power supply. This is mostly useful for power supply
> > > extensions that want to access
> > > + * their own power supply as using power_supply_get_property() directly
> > > will result in a potential
> > > + * deadlock.
> > > + *
> > > + * Return: 0 on success or negative error code on failure.
> > > + */
> > > +int power_supply_get_property_direct(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +				     union power_supply_propval *val)
> > > +{
> > > +        return __power_supply_get_property(psy, psp, val, false);
> > > +}
> > > +EXPORT_SYMBOL_GPL(power_supply_get_property_direct);
> > > +
> > > +
> > > +static int __power_supply_set_property(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +				       const union power_supply_propval *val,
> > > bool use_extensions)
> > >   {
> > >   	struct power_supply_ext_registration *reg;
> > >     	if (atomic_read(&psy->use_cnt) <= 0)
> > >   		return -ENODEV;
> > >   -	scoped_guard(rwsem_read, &psy->extensions_sem) {
> > > -		power_supply_for_each_extension(reg, psy) {
> > > -			if (power_supply_ext_has_property(reg->ext, psp)) {
> > > +	if (use_extensions) {
> > > +		scoped_guard(rwsem_read, &psy->extensions_sem) {
> > > +			power_supply_for_each_extension(reg, psy) {
> > > +				if (!power_supply_ext_has_property(reg->ext,
> > > psp))
> > > +					continue;
> > > +
> > >   				if (reg->ext->set_property)
> > >   					return reg->ext->set_property(psy,
> > > reg->ext, reg->data,
> > >   								      psp,
> > > val);
> > > @@ -1295,8 +1327,34 @@ int power_supply_set_property(struct power_supply
> > > *psy,
> > >     	return psy->desc->set_property(psy, psp, val);
> > >   }
> > > +
> > > +int power_supply_set_property(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +			      const union power_supply_propval *val)
> > > +{
> > > +	return __power_supply_set_property(psy, psp, val, true);
> > > +}
> > >   EXPORT_SYMBOL_GPL(power_supply_set_property);
> > >   +/**
> > > + * power_supply_set_property_direct - Write a power supply property
> > > without checking for extensions
> > > + * @psy: The power supply
> > > + * @psp: The power supply property to write
> > > + * @val: The value to write to the power supply property
> > > + *
> > > + * Write a power supply property without taking into account any power
> > > supply extensions registered
> > > + * on the given power supply. This is mostly useful for power supply
> > > extensions that want to access
> > > + * their own power supply as using power_supply_set_property() directly
> > > will result in a potential
> > > + * deadlock.
> > > + *
> > > + * Return: 0 on success or negative error code on failure.
> > > + */
> > > +int power_supply_set_property_direct(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +				     const union power_supply_propval *val)
> > > +{
> > > +	return __power_supply_set_property(psy, psp, val, false);
> > > +}
> > > +EXPORT_SYMBOL_GPL(power_supply_set_property_direct);
> > > +
> > >   int power_supply_property_is_writeable(struct power_supply *psy,
> > >   					enum power_supply_property psp)
> > >   {
> > > diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> > > index 45468959dd98..f21f806bfb38 100644
> > > --- a/include/linux/power_supply.h
> > > +++ b/include/linux/power_supply.h
> > > @@ -878,15 +878,23 @@ static inline int
> > > power_supply_is_system_supplied(void) { return -ENOSYS; }
> > >   extern int power_supply_get_property(struct power_supply *psy,
> > >   			    enum power_supply_property psp,
> > >   			    union power_supply_propval *val);
> > > +int power_supply_get_property_direct(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +				     union power_supply_propval *val);
> > >   #if IS_ENABLED(CONFIG_POWER_SUPPLY)
> > >   extern int power_supply_set_property(struct power_supply *psy,
> > >   			    enum power_supply_property psp,
> > >   			    const union power_supply_propval *val);
> > > +int power_supply_set_property_direct(struct power_supply *psy, enum
> > > power_supply_property psp,
> > > +				     const union power_supply_propval *val);
> > >   #else
> > >   static inline int power_supply_set_property(struct power_supply *psy,
> > >   			    enum power_supply_property psp,
> > >   			    const union power_supply_propval *val)
> > >   { return 0; }
> > > +static inline int power_supply_set_property_direct(struct power_supply
> > > *psy,
> > > +						   enum power_supply_property
> > > psp,
> > > +						   const union
> > > power_supply_propval *val)
> > > +{ return 0; }
> > >   #endif
> > >   extern void power_supply_external_power_changed(struct power_supply
> > > *psy);
> > >   
> > 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ