hwspinlock/core: Add testing capabilities
Hi,
It is good idea add this feature.
1: Can we let the "ret = hwspin_lock_tests(ops, hwlock);" add after hwspin_lock_register_single have return
succeed, that can avoid test duplicated Or error lockid. Of course, If this interface is intend to test soc hardware capability only, we can put it in the arch module not this core framework. For driver hardware sanity check, i would add it after software have register it.
2:Is it possible that interface add configs that choose which locks will be test? Because the hwspinlock module is init late in postcore_initcall phase, Maybe MACH/ARCH code(for example: code in early_initcall) need use private other interfaces to lock some hwspinlocks and then register hw locks to hwspinlock framework, Maybe some hw locks is in lock status but which test failed.
Signature · 1 line
Steve Zhan
Quoted 115 lines
From: Ido Yariv <[email protected]>
To: Ohad Ben-Cohen <[email protected]>, linux-kernel at vger.kernel.org,
linux-arm-kernel at lists.infradead.org, linux-omap at vger.kernel.org
Cc: Ido Yariv <[email protected]>
Subject: [PATCH] hwspinlock/core: Add testing capabilities
Message-ID: <[email protected]>Add testing capabilities for verifying correctness of the underlying hwspinlock layers. This can be handy especially during development. These tests are performed only once as part of the hwspinlock registration.
Signed-off-by Ido Yariv <[email protected]>--- drivers/hwspinlock/Kconfig | 9 +++++ drivers/hwspinlock/hwspinlock_core.c | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 0 deletions(-)drivers/hwspinlock/Kconfig +9
-0@@ -8,6 +8,15 @@ config HWSPINLOCK menu "Hardware Spinlock drivers" +config HWSPINLOCK_TEST + bool "Verify underlying hwspinlock implementation" + depends on HWSPINLOCK + help + Say Y here to perform tests on the underlying hwspinlock + implementation. The tests are only performed once per implementation. + + Say N, unless you absolutely know what you are doing. + config HWSPINLOCK_OMAP tristate "OMAP Hardware Spinlock device" depends on ARCH_OMAP4drivers/hwspinlock/hwspinlock_core.c +54
-0@@ -307,6 +307,53 @@ out:return hwlock; } +#ifdef CONFIG_HWSPINLOCK_TEST +#define NUM_OF_TEST_ITERATIONS 100 +static int hwspin_lock_tests (const struct hwspinlock_ops *ops, +struct hwspinlock *hwlock) +{ +int i; +int ret; + +for (i =0 ; i <NUM_OF_TEST_ITERATIONS ; i++) { + ret = ops->trylock (hwlock); +if (!ret) { +pr_err ("%s: Initial lock failed\n" , __func__); +return -EFAULT ; + } + +/* Verify lock actually works - re-acquiring it should fail */ + ret = ops->trylock (hwlock); +if (ret) { +/* Keep locks balanced even in failure cases */ + ops->unlock (hwlock); + ops->unlock (hwlock); +pr_err ("%s: Recursive lock succeeded unexpectedly\n" , + __func__); +return -EFAULT ; + } + +/* Verify unlock by re-acquiring the lock after releasing it */ + ops->unlock (hwlock); + ret = ops->trylock (hwlock); +if (!ret) { +pr_err ("%s: Unlock failed\n" , __func__); +return -EINVAL ; + } + + ops->unlock (hwlock); + } + +return 0 ; +} +#else /* CONFIG_HWSPINLOCK_TEST*/ +static int hwspin_lock_tests (const struct hwspinlock_ops *ops, +struct hwspinlock *hwlock) +{ +return 0 ; +} +#endif +/** * hwspin_lock_register() - register a new hw spinlock device * @bank: the hwspinlock device, which usually provides numerous hw locks @@ -345,6 +392,13 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,spin_lock_init (&hwlock->lock); hwlock->bank = bank; + ret =hwspin_lock_tests (ops, hwlock); +if (ret) { +pr_err ("hwspinlock tests failed on lock %d\n" , + base_id + i); + goto reg_failed; + } + ret =hwspin_lock_register_single (hwlock, base_id + i);if (ret)goto
reg_failed;
--
1.7.7.6
Hi Steve,
Quoted 10 lines · steve.zhan
Hi,
It is good idea add this feature.
1: Can we let the "ret =
hwspin_lock_tests(ops, hwlock);" add afterhwspin_lock_register_singlehave return
succeed, that can avoid test duplicated Or error lockid. Of course, If this interface is intend to test soc hardware capability only, we can put it in the arch module not this core framework. For driver hardware sanity check, i would add it after software have register it.
I'd rather not test the spinlocks after they are registering as they might already be in use by then.
While this feature only verifies the underlying platform implementation, I think it's best to avoid code duplication and keep it in one place that will always get called.
Quoted 6 lines
2:Is it possible that interface add configs that choose which locks will be test? Because the hwspinlock module is init late in
postcore_initcallphase, Maybe MACH/ARCHcode(for example: code in early_initcall)need use private other interfaces to lock some hwspinlocks and then register hw locks to hwspinlock framework, Maybe some hw locks is in lock status but which test failed.
It was assumed that up to the point where the hw spinlocks are registered they will not be used, regardless of when this module is initialized.
If this assumption does not hold for your platform, the simplest solution would be to set this config option to 'N', as there is no safe way of verifying spinlocks that are actively being used.
Thanks for reviewing this,
Ido.
PATCH 1/1 hwspinlock/core: Add testing capabilities
Hi,
Acked-by: Steve zhan zhanzhenbo at gmail.com
"I'd rather not test the spinlocks after they are registering as they
might already be in use by then."
Why? I think user must use it after hwspin_lock_register have retured
sucess.
Steve
2012/12/30 Ido Yariv <[email protected]>
Quoted 38 lines
Hi Steve,
Quoted 10 lines · steve.zhan
Hi,
It is good idea add this feature.
1: Can we let the "ret =
hwspin_lock_tests(ops, hwlock);" add afterhwspin_lock_register_singlehave return
succeed, that can avoid test duplicated Or error lockid. Of course, If this interface is intend to test soc hardware capability only, we can put it in the arch module not this core framework. For driver hardware sanity check, i would add it after software have register it.I'd rather not test the spinlocks after they are registering as they might already be in use by then.
While this feature only verifies the underlying platform implementation, I think it's best to avoid code duplication and keep it in one place that will always get called.
Quoted 6 lines
2:Is it possible that interface add configs that choose which locks will be test? Because the hwspinlock module is init late in
postcore_initcallphase, Maybe MACH/ARCHcode(for example: code in early_initcall)need use private other interfaces to lock some hwspinlocks and then register hw locks to hwspinlock framework, Maybe some hw locks is in lock status but which test failed.It was assumed that up to the point where the hw spinlocks are registered they will not be used, regardless of when this module is initialized.
If this assumption does not hold for your platform, the simplest solution would be to set this config option to 'N', as there is no safe way of verifying spinlocks that are actively being used.Thanks for reviewing this,
Ido.
Signature · 4 lines
Steve Zhan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20121230/375b953e/attachment-0001.html>
Hi Steve,
Quoted 8 lines · steve.zhan
Hi,
?? Acked-by: Steve zhan zhanzhenbo at gmail.com
?
?? "I'd rather not test the spinlocks after they are registering as they might already be in use by then."??? Why? I think user must use it after
hwspin_lock_registerhave retured sucess.
Once the spinlocks are registered anyone can request and acquire these. The tests could then interfere with any users of the hwspinlock layer, or simply fail (because the spinlocks might already be acquired).
Thanks,
Ido.
PATCH 1/1 hwspinlock/core: Add testing capabilities
Thanks, Ido.
I think if hwspinlock mudule probe register have not return 0 Or
executed over, we can assume that system can not do acquire the
lock, that must be later than hardware module register..
For example, if there have 32 locks, that using the same bank,
if register lock 31 failed, then omap hwlock module will release bank struct like this:
reg_fail:
pm_runtime_disable(&pdev->dev);
kfree(bank);
iounmap_base:
iounmap(io_base);
return ret;
}so, for this time, if the spinlocks might already be acquired, that
lock will can not find the bank pointer...
/**
* hwspin_lock_register() - register a new hw spinlock device
* @bank: the hwspinlock device, which usually provides numerous hw locks
@@ -345,9 +392,18 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
spin_lock_init(&hwlock->lock);
hwlock->bank = bank;+
ret = hwspin_lock_register_single(hwlock, base_id + i);
- if (ret)
+ if (ret) {
goto reg_failed;+ } else {
+ ret = hwspin_lock_tests(ops, hwlock);
+ if (ret) {
+ pr_err("hwspinlock tests failed on lock
%d\n",
+ base_id + i);
+ goto reg_failed;
+ }
+ }
}
return 0;Steve.
2012/12/30 Ido Yariv <[email protected]>
Quoted 19 lines
Hi Steve,
Quoted 8 lines · steve.zhan
Hi,
Acked-by: Steve zhan zhanzhenbo at gmail.com"I'd rather not test the spinlocks after they are registering as they
might already be in use by then."Why? I think user must use it after
hwspin_lock_registerhave retured
sucess.Once the spinlocks are registered anyone can request and acquire these. The tests could then interfere with any users of the hwspinlock layer, or simply fail (because the spinlocks might already be acquired).
Thanks,
Ido.
Signature · 4 lines
Steve Zhan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20121230/60dfb7f2/attachment-0001.html>
PATCH 1/1 hwspinlock/core: Add testing capabilities
Hi Steve,
Quoted 6 lines · steve.zhan
Thanks, Ido.
I think if hwspinlock mudule probe register have not return 0 Or
executed over, we can assume that system can not do acquire thelock, that must be later than hardware module register..
That's actually not what I was concerned about. If hwspin_lock_register_single returns 0, anyone could potentially request and acquire that lock. If we then call hwspin_lock_tests it could potentially fail since the lock might already be acquired and the first call to trylock will not succeed.
Since there's no real advantage in testing the locks after registering them, I suggest we keep the current implementation.
Thanks,
Ido.
PATCH 1/1 hwspinlock/core: Add testing capabilities
HI Ido,
I see. But this is system init call order error, something
driver interface have called before module driver init have ready, if this situation is exsist, we can' t release the bank pointer if only some lock have register failed, for example, omap_hwspinlock
"reg_fail:
pm_runtime_disable(&pdev->dev);
kfree(bank);"
So, because this is not problem.
Yes, this test function is good patch, i have use it for test ours hardware.
Steve.
2012/12/30 Ido Yariv <[email protected]>
Quoted 9 lines
That's actually not what I was concerned about. If
hwspin_lock_register_singlereturns 0, anyone could potentially request and acquire that lock. If we then callhwspin_lock_testsit could potentially fail since the lock might already be acquired and the first call to trylock will not succeed.Since there's no real advantage in testing the locks after registering them, I suggest we keep the current implementation.
Signature · 4 lines
Steve Zhan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20121230/b56d6281/attachment-0001.html>