Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752074AbaJOKal (ORCPT ); Wed, 15 Oct 2014 06:30:41 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:40359 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751938AbaJOKaj (ORCPT ); Wed, 15 Oct 2014 06:30:39 -0400 Date: Wed, 15 Oct 2014 12:30:36 +0200 From: Pavel Machek To: Krzysztof Kozlowski Cc: Linus Walleij , Samuel Ortiz , Lee Jones , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Anton Vorontsov , Guenter Roeck , Myungjoo Ham , Jonghwa Lee , Kyungmin Park , Marek Szyprowski , Bartlomiej Zolnierkiewicz Subject: Re: [PATCH 1/8] power_supply: Add API for safe access of power supply function attrs Message-ID: <20141015103036.GA14266@amd> References: <1413289246-31650-1-git-send-email-k.kozlowski@samsung.com> <1413289246-31650-2-git-send-email-k.kozlowski@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1413289246-31650-2-git-send-email-k.kozlowski@samsung.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2014-10-14 14:20:39, Krzysztof Kozlowski wrote: > Add simple wrappers for accessing power supply's function attributes: > - get_property -> power_supply_get_property > - set_property -> power_supply_set_property > - property_is_writeable -> power_supply_property_is_writeable > - external_power_changed -> power_supply_external_power_changed > - set_charged -> power_supply_set_charged > > This API adds a safe way of accessing a power supply from another > driver. Particularly it solves invalid memory references (and lockup) in > following race condition scenario: > > Thread 1: charger manager > Thread 2: power supply driver, used by charger manager > > THREAD 1 (charger manager) THREAD 2 (power supply driver) > ========================== ============================== > psy = power_supply_get_by_name() > Driver unbind, .remove > power_supply_unregister > Device fully removed > psy->get_property() > > The 'get_property' callback is still valid and leads to actual calling of > Thread2->get_property() but now in invalid context because the driver was > unbound. > > This could be observed easily with charger manager driver (here compiled > with max17042 fuel gauge): > $ echo "12-0036" > /sys/bus/i2c/drivers/max17042/unbind > $ cat /sys/devices/virtual/power_supply/battery/temp > [ 240.505998] INFO: task cat:1394 blocked for more than 120 seconds. > [ 240.510762] Not tainted 3.17.0-next-20141007-00028-ge60b6dd79570-dirty #183 > [ 240.518208] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. > [ 240.526025] cat D c0469548 0 1394 1 0x00000000 > [ 240.532384] [] (__schedule) from [] (schedule_preempt_disabled+0x14/0x20) > [ 240.540885] [] (schedule_preempt_disabled) from [] (mutex_lock_nested+0x1bc/0x458) > [ 240.550171] [] (mutex_lock_nested) from [] (regmap_read+0x30/0x60) > [ 240.558079] [] (regmap_read) from [] (max17042_get_property+0x2e8/0x350) > [ 240.566490] [] (max17042_get_property) from [] (charger_get_property+0x238/0x31c) > [ 240.575688] [] (charger_get_property) from [] (power_supply_show_property+0x48/0x1e0) > [ 240.585241] [] (power_supply_show_property) from [] (dev_attr_show+0x1c/0x48) > [ 240.594100] [] (dev_attr_show) from [] (sysfs_kf_seq_show+0x84/0x104) > [ 240.602251] [] (sysfs_kf_seq_show) from [] (kernfs_seq_show+0x24/0x28) > [ 240.610497] [] (kernfs_seq_show) from [] (seq_read+0x1b0/0x484) > [ 240.618138] [] (seq_read) from [] (vfs_read+0x88/0x144) > [ 240.625127] [] (vfs_read) from [] (SyS_read+0x40/0x8c) > [ 240.631941] [] (SyS_read) from [] (ret_fast_syscall+0x0/0x48) > > Or: > [ 17.277605] Division by zero in kernel. > [ 17.280043] CPU: 2 PID: 1384 Comm: cat Not tainted 3.17.0-next-20141007-00028-ge60b6dd79570-dirty #181 > [ 17.289348] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > [ 17.297055] [] (show_stack) from [] (dump_stack+0x70/0xbc) > [ 17.304264] [] (dump_stack) from [] (Ldiv0+0x8/0x10) > [ 17.310933] [] (Ldiv0) from [] (__aeabi_uidivmod+0x8/0x18) > [ 17.318132] [] (__aeabi_uidivmod) from [] (regmap_read+0x1c/0x60) > [ 17.325956] [] (regmap_read) from [] (max17042_get_property+0x1bc/0x350) > [ 17.334361] [] (max17042_get_property) from [] (charger_get_property+0x198/0x328) > [ 17.343560] [] (charger_get_property) from [] (power_supply_show_property+0x48/0x1e0) > [ 17.353108] [] (power_supply_show_property) from [] (power_supply_uevent+0x9c/0x1c4) > [ 17.362575] [] (power_supply_uevent) from [] (dev_uevent+0xb8/0x1c8) > [ 17.370639] [] (dev_uevent) from [] (uevent_show+0xa8/0x104) > [ 17.378015] [] (uevent_show) from [] (dev_attr_show+0x1c/0x48) > [ 17.385579] [] (dev_attr_show) from [] (sysfs_kf_seq_show+0x84/0x104) > [ 17.393731] [] (sysfs_kf_seq_show) from [] (kernfs_seq_show+0x24/0x28) > [ 17.401979] [] (kernfs_seq_show) from [] (seq_read+0x1b0/0x484) > [ 17.409619] [] (seq_read) from [] (vfs_read+0x88/0x144) > [ 17.416557] [] (vfs_read) from [] (SyS_read+0x40/0x8c) > [ 17.423416] [] (SyS_read) from [] (ret_fast_syscall+0x0/0x48) > [ 17.430880] power_supply battery: driver failed to report `voltage_now' property: -22 > > Signed-off-by: Krzysztof Kozlowski Acked-by: Pavel Machek -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/