* [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
@ 2014-11-26 16:15 Loic Pefferkorn
2014-11-26 20:54 ` Greg KH
0 siblings, 1 reply; 9+ messages in thread
From: Loic Pefferkorn @ 2014-11-26 16:15 UTC (permalink / raw)
To: oleg.drokin, andreas.dilger, gregkh, gdonald, keith.mannthey,
john.hammond
Cc: devel, HPDD-discuss, linux-kernel
Add __acquires() and __releases() function annotations, to fix sparse warnings related to lock context imbalance.
This fixes the following warnings:
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c:153:5: warning: context imbalance in 'cfs_trace_lock_tcd' - wrong count at exit
drivers/staging/lustre/lustre/libcfs/hash.c:128:1: warning: context imbalance in 'cfs_hash_spin_lock' - wrong count at exit
drivers/staging/lustre/lustre/libcfs/hash.c:142:9: warning: context imbalance in 'cfs_hash_rw_lock' - wrong count at exit
drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c:57:17: warning: context imbalance in 'lock_res_and_lock' - wrong count at exit
drivers/staging/lustre/lustre/libcfs/libcfs_lock.c:93:1: warning: context imbalance in 'cfs_percpt_lock' - wrong count at exit
Signed-off-by: Loic Pefferkorn <loic@loicp.eu>
---
drivers/staging/lustre/lustre/libcfs/hash.c | 4 ++++
drivers/staging/lustre/lustre/libcfs/libcfs_lock.c | 2 ++
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 2 ++
drivers/staging/lustre/lustre/obdclass/cl_object.c | 2 ++
4 files changed, 10 insertions(+)
diff --git a/drivers/staging/lustre/lustre/libcfs/hash.c b/drivers/staging/lustre/lustre/libcfs/hash.c
index 32da783..7c6e2a3 100644
--- a/drivers/staging/lustre/lustre/libcfs/hash.c
+++ b/drivers/staging/lustre/lustre/libcfs/hash.c
@@ -126,18 +126,21 @@ cfs_hash_nl_unlock(union cfs_hash_lock *lock, int exclusive) {}
static inline void
cfs_hash_spin_lock(union cfs_hash_lock *lock, int exclusive)
+ __acquires(&lock->spin)
{
spin_lock(&lock->spin);
}
static inline void
cfs_hash_spin_unlock(union cfs_hash_lock *lock, int exclusive)
+ __releases(&lock->spin)
{
spin_unlock(&lock->spin);
}
static inline void
cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
+ __acquires(&lock->rw)
{
if (!exclusive)
read_lock(&lock->rw);
@@ -147,6 +150,7 @@ cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
static inline void
cfs_hash_rw_unlock(union cfs_hash_lock *lock, int exclusive)
+ __releases(&lock->rw)
{
if (!exclusive)
read_unlock(&lock->rw);
diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
index 2c199c7..1e529fc 100644
--- a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
+++ b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
@@ -91,6 +91,7 @@ EXPORT_SYMBOL(cfs_percpt_lock_alloc);
*/
void
cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index)
+ __acquires(pcl->pcl_locks[index])
{
int ncpt = cfs_cpt_number(pcl->pcl_cptab);
int i;
@@ -125,6 +126,7 @@ EXPORT_SYMBOL(cfs_percpt_lock);
/** unlock a CPU partition */
void
cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index)
+ __releases(pcl->pcl_locks[index])
{
int ncpt = cfs_cpt_number(pcl->pcl_cptab);
int i;
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
index 976c61e..257669b 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
@@ -151,6 +151,7 @@ cfs_trace_buf_type_t cfs_trace_buf_idx_get(void)
* for details.
*/
int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
+ __acquires(&tcd->tc_lock)
{
__LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
@@ -165,6 +166,7 @@ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
}
void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
+ __releases(&tcd->tcd_lock)
{
__LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
index ce96bd2..8577f97 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
@@ -193,6 +193,7 @@ static spinlock_t *cl_object_attr_guard(struct cl_object *o)
* cl_object_attr_get(), cl_object_attr_set().
*/
void cl_object_attr_lock(struct cl_object *o)
+ __acquires(cl_object_attr_guard(o))
{
spin_lock(cl_object_attr_guard(o));
}
@@ -202,6 +203,7 @@ EXPORT_SYMBOL(cl_object_attr_lock);
* Releases data-attributes lock, acquired by cl_object_attr_lock().
*/
void cl_object_attr_unlock(struct cl_object *o)
+ __releases(cl_object_attr_guard(o))
{
spin_unlock(cl_object_attr_guard(o));
}
--
2.1.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-26 16:15 [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance Loic Pefferkorn
@ 2014-11-26 20:54 ` Greg KH
2014-11-27 5:30 ` Loïc Pefferkorn
2014-11-27 18:34 ` Loïc Pefferkorn
0 siblings, 2 replies; 9+ messages in thread
From: Greg KH @ 2014-11-26 20:54 UTC (permalink / raw)
To: oleg.drokin, andreas.dilger, gdonald, keith.mannthey,
john.hammond, devel, HPDD-discuss, linux-kernel
On Wed, Nov 26, 2014 at 05:15:48PM +0100, Loic Pefferkorn wrote:
> Add __acquires() and __releases() function annotations, to fix sparse warnings related to lock context imbalance.
>
> This fixes the following warnings:
>
> drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c:153:5: warning: context imbalance in 'cfs_trace_lock_tcd' - wrong count at exit
> drivers/staging/lustre/lustre/libcfs/hash.c:128:1: warning: context imbalance in 'cfs_hash_spin_lock' - wrong count at exit
> drivers/staging/lustre/lustre/libcfs/hash.c:142:9: warning: context imbalance in 'cfs_hash_rw_lock' - wrong count at exit
> drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c:57:17: warning: context imbalance in 'lock_res_and_lock' - wrong count at exit
> drivers/staging/lustre/lustre/libcfs/libcfs_lock.c:93:1: warning: context imbalance in 'cfs_percpt_lock' - wrong count at exit
>
> Signed-off-by: Loic Pefferkorn <loic@loicp.eu>
> ---
> drivers/staging/lustre/lustre/libcfs/hash.c | 4 ++++
> drivers/staging/lustre/lustre/libcfs/libcfs_lock.c | 2 ++
> drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 2 ++
> drivers/staging/lustre/lustre/obdclass/cl_object.c | 2 ++
> 4 files changed, 10 insertions(+)
>
> diff --git a/drivers/staging/lustre/lustre/libcfs/hash.c b/drivers/staging/lustre/lustre/libcfs/hash.c
> index 32da783..7c6e2a3 100644
> --- a/drivers/staging/lustre/lustre/libcfs/hash.c
> +++ b/drivers/staging/lustre/lustre/libcfs/hash.c
> @@ -126,18 +126,21 @@ cfs_hash_nl_unlock(union cfs_hash_lock *lock, int exclusive) {}
>
> static inline void
> cfs_hash_spin_lock(union cfs_hash_lock *lock, int exclusive)
> + __acquires(&lock->spin)
> {
> spin_lock(&lock->spin);
> }
>
> static inline void
> cfs_hash_spin_unlock(union cfs_hash_lock *lock, int exclusive)
> + __releases(&lock->spin)
> {
> spin_unlock(&lock->spin);
> }
Ugh, how horrid, please just delete these functions and push down the
spin_lock/unlock calls down into the places these are called.
>
> static inline void
> cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
> + __acquires(&lock->rw)
> {
> if (!exclusive)
> read_lock(&lock->rw);
> @@ -147,6 +150,7 @@ cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
>
> static inline void
> cfs_hash_rw_unlock(union cfs_hash_lock *lock, int exclusive)
> + __releases(&lock->rw)
> {
> if (!exclusive)
> read_unlock(&lock->rw);
Same for these.
> diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> index 2c199c7..1e529fc 100644
> --- a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> +++ b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> @@ -91,6 +91,7 @@ EXPORT_SYMBOL(cfs_percpt_lock_alloc);
> */
> void
> cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index)
> + __acquires(pcl->pcl_locks[index])
> {
> int ncpt = cfs_cpt_number(pcl->pcl_cptab);
> int i;
> @@ -125,6 +126,7 @@ EXPORT_SYMBOL(cfs_percpt_lock);
> /** unlock a CPU partition */
> void
> cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index)
> + __releases(pcl->pcl_locks[index])
> {
> int ncpt = cfs_cpt_number(pcl->pcl_cptab);
> int i;
> diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> index 976c61e..257669b 100644
> --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> @@ -151,6 +151,7 @@ cfs_trace_buf_type_t cfs_trace_buf_idx_get(void)
> * for details.
> */
> int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> + __acquires(&tcd->tc_lock)
> {
> __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
> if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> @@ -165,6 +166,7 @@ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> }
>
> void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> + __releases(&tcd->tcd_lock)
> {
> __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
> if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> index ce96bd2..8577f97 100644
> --- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
> +++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> @@ -193,6 +193,7 @@ static spinlock_t *cl_object_attr_guard(struct cl_object *o)
> * cl_object_attr_get(), cl_object_attr_set().
> */
> void cl_object_attr_lock(struct cl_object *o)
> + __acquires(cl_object_attr_guard(o))
> {
> spin_lock(cl_object_attr_guard(o));
> }
> @@ -202,6 +203,7 @@ EXPORT_SYMBOL(cl_object_attr_lock);
> * Releases data-attributes lock, acquired by cl_object_attr_lock().
> */
> void cl_object_attr_unlock(struct cl_object *o)
> + __releases(cl_object_attr_guard(o))
> {
> spin_unlock(cl_object_attr_guard(o));
> }
Same thing here.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-26 20:54 ` Greg KH
@ 2014-11-27 5:30 ` Loïc Pefferkorn
2014-11-27 18:34 ` Loïc Pefferkorn
1 sibling, 0 replies; 9+ messages in thread
From: Loïc Pefferkorn @ 2014-11-27 5:30 UTC (permalink / raw)
To: Greg KH
Cc: oleg.drokin, andreas.dilger, gdonald, keith.mannthey,
john.hammond, devel, HPDD-discuss, linux-kernel
On Wed, Nov 26, 2014 at 12:54:43PM -0800, Greg KH wrote:
>
> Ugh, how horrid, please just delete these functions and push down the
> spin_lock/unlock calls down into the places these are called.
>
> Same for these.
>
> Same thing here.
Hello Greg,
Thanks for your comments, I will write a v2.
--
Cheers,
Loic
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-26 20:54 ` Greg KH
2014-11-27 5:30 ` Loïc Pefferkorn
@ 2014-11-27 18:34 ` Loïc Pefferkorn
2014-11-28 10:00 ` Dan Carpenter
2014-11-28 22:22 ` Greg KH
1 sibling, 2 replies; 9+ messages in thread
From: Loïc Pefferkorn @ 2014-11-27 18:34 UTC (permalink / raw)
To: Greg KH
Cc: oleg.drokin, andreas.dilger, gdonald, keith.mannthey,
john.hammond, devel, HPDD-discuss, linux-kernel
Hello Greg,
After some investigation, I think that removing these wrappers is not going to improve the code readability:
On Wed, Nov 26, 2014 at 12:54:43PM -0800, Greg KH wrote:
> On Wed, Nov 26, 2014 at 05:15:48PM +0100, Loic Pefferkorn wrote:
> > Add __acquires() and __releases() function annotations, to fix sparse warnings related to lock context imbalance.
> >
> > This fixes the following warnings:
> >
> > drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c:153:5: warning: context imbalance in 'cfs_trace_lock_tcd' - wrong count at exit
> > drivers/staging/lustre/lustre/libcfs/hash.c:128:1: warning: context imbalance in 'cfs_hash_spin_lock' - wrong count at exit
> > drivers/staging/lustre/lustre/libcfs/hash.c:142:9: warning: context imbalance in 'cfs_hash_rw_lock' - wrong count at exit
> > drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c:57:17: warning: context imbalance in 'lock_res_and_lock' - wrong count at exit
> > drivers/staging/lustre/lustre/libcfs/libcfs_lock.c:93:1: warning: context imbalance in 'cfs_percpt_lock' - wrong count at exit
> >
> > Signed-off-by: Loic Pefferkorn <loic@loicp.eu>
> > ---
> > drivers/staging/lustre/lustre/libcfs/hash.c | 4 ++++
> > drivers/staging/lustre/lustre/libcfs/libcfs_lock.c | 2 ++
> > drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 2 ++
> > drivers/staging/lustre/lustre/obdclass/cl_object.c | 2 ++
> > 4 files changed, 10 insertions(+)
> >
> > diff --git a/drivers/staging/lustre/lustre/libcfs/hash.c b/drivers/staging/lustre/lustre/libcfs/hash.c
> > index 32da783..7c6e2a3 100644
> > --- a/drivers/staging/lustre/lustre/libcfs/hash.c
> > +++ b/drivers/staging/lustre/lustre/libcfs/hash.c
> > @@ -126,18 +126,21 @@ cfs_hash_nl_unlock(union cfs_hash_lock *lock, int exclusive) {}
> >
> > static inline void
> > cfs_hash_spin_lock(union cfs_hash_lock *lock, int exclusive)
> > + __acquires(&lock->spin)
> > {
> > spin_lock(&lock->spin);
> > }
> >
> > static inline void
> > cfs_hash_spin_unlock(union cfs_hash_lock *lock, int exclusive)
> > + __releases(&lock->spin)
> > {
> > spin_unlock(&lock->spin);
> > }
>
> Ugh, how horrid, please just delete these functions and push down the
> spin_lock/unlock calls down into the places these are called.
cfs_hash_spin_lock() and cfs_hash_spin_unlock() are referenced by function pointers later in the same file:
165 /** no bucket lock, one spinlock to protect everything */
166 static cfs_hash_lock_ops_t cfs_hash_nbl_lops = {
167 .hs_lock = cfs_hash_spin_lock,
168 .hs_unlock = cfs_hash_spin_unlock,
169 .hs_bkt_lock = cfs_hash_nl_lock,
170 .hs_bkt_unlock = cfs_hash_nl_unlock,
171 };
172
173 /** spin bucket lock, rehash is enabled */
174 static cfs_hash_lock_ops_t cfs_hash_bkt_spin_lops = {
175 .hs_lock = cfs_hash_rw_lock,
176 .hs_unlock = cfs_hash_rw_unlock,
177 .hs_bkt_lock = cfs_hash_spin_lock,
178 .hs_bkt_unlock = cfs_hash_spin_unlock,
179 };
>
> >
> > static inline void
> > cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
> > + __acquires(&lock->rw)
> > {
> > if (!exclusive)
> > read_lock(&lock->rw);
> > @@ -147,6 +150,7 @@ cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
> >
> > static inline void
> > cfs_hash_rw_unlock(union cfs_hash_lock *lock, int exclusive)
> > + __releases(&lock->rw)
> > {
> > if (!exclusive)
> > read_unlock(&lock->rw);
>
>
> Same for these.
Likewise for cfs_hash_rw_lock() and cfs_hash_rw_unlock():
173 /** spin bucket lock, rehash is enabled */
174 static cfs_hash_lock_ops_t cfs_hash_bkt_spin_lops = {
175 .hs_lock = cfs_hash_rw_lock,
176 .hs_unlock = cfs_hash_rw_unlock,
177 .hs_bkt_lock = cfs_hash_spin_lock,
178 .hs_bkt_unlock = cfs_hash_spin_unlock,
179 };
180
181 /** rw bucket lock, rehash is enabled */
182 static cfs_hash_lock_ops_t cfs_hash_bkt_rw_lops = {
183 .hs_lock = cfs_hash_rw_lock,
184 .hs_unlock = cfs_hash_rw_unlock,
185 .hs_bkt_lock = cfs_hash_rw_lock,
186 .hs_bkt_unlock = cfs_hash_rw_unlock,
187 };
>
> > diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> > index 2c199c7..1e529fc 100644
> > --- a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> > +++ b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> > @@ -91,6 +91,7 @@ EXPORT_SYMBOL(cfs_percpt_lock_alloc);
> > */
> > void
> > cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index)
> > + __acquires(pcl->pcl_locks[index])
> > {
> > int ncpt = cfs_cpt_number(pcl->pcl_cptab);
> > int i;
> > @@ -125,6 +126,7 @@ EXPORT_SYMBOL(cfs_percpt_lock);
> > /** unlock a CPU partition */
> > void
> > cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index)
> > + __releases(pcl->pcl_locks[index])
> > {
> > int ncpt = cfs_cpt_number(pcl->pcl_cptab);
> > int i;
> > diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> > index 976c61e..257669b 100644
> > --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> > +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> > @@ -151,6 +151,7 @@ cfs_trace_buf_type_t cfs_trace_buf_idx_get(void)
> > * for details.
> > */
> > int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> > + __acquires(&tcd->tc_lock)
> > {
> > __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
> > if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> > @@ -165,6 +166,7 @@ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> > }
> >
> > void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> > + __releases(&tcd->tcd_lock)
> > {
> > __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
> > if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> > diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> > index ce96bd2..8577f97 100644
> > --- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
> > +++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> > @@ -193,6 +193,7 @@ static spinlock_t *cl_object_attr_guard(struct cl_object *o)
> > * cl_object_attr_get(), cl_object_attr_set().
> > */
> > void cl_object_attr_lock(struct cl_object *o)
> > + __acquires(cl_object_attr_guard(o))
> > {
> > spin_lock(cl_object_attr_guard(o));
> > }
> > @@ -202,6 +203,7 @@ EXPORT_SYMBOL(cl_object_attr_lock);
> > * Releases data-attributes lock, acquired by cl_object_attr_lock().
> > */
> > void cl_object_attr_unlock(struct cl_object *o)
> > + __releases(cl_object_attr_guard(o))
> > {
> > spin_unlock(cl_object_attr_guard(o));
> > }
>
> Same thing here.
These ones are easy to replace, but the naming scheme of all functions in cl_object.c is consistent,
from my point of view it ease code reading where they are called, for example in lustre/lustre/osc/osc_request.c:
before:
1827 if (valid != 0) {
1828 cl_object_attr_lock(obj);
1829 cl_object_attr_set(env, obj, attr, valid);
1830 cl_object_attr_unlock(obj);
after:
1827 if (valid != 0) {
1828 spin_lock(cl_object_attr_guard(obj));
1829 cl_object_attr_set(env, obj, attr, valid);
1830 spin_unlock(cl_object_attr_guard(obj));
But I'm here for learning, and I would be grateful to have your opinion.
--
Cheers,
Loic
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-27 18:34 ` Loïc Pefferkorn
@ 2014-11-28 10:00 ` Dan Carpenter
2014-11-28 15:45 ` [HPDD-discuss] " Patrick Farrell
2014-11-28 22:22 ` Greg KH
1 sibling, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2014-11-28 10:00 UTC (permalink / raw)
To: Loïc Pefferkorn
Cc: Greg KH, keith.mannthey, devel, andreas.dilger, linux-kernel,
oleg.drokin, gdonald, HPDD-discuss, john.hammond
On Thu, Nov 27, 2014 at 07:34:10PM +0100, Loïc Pefferkorn wrote:
> 1827 if (valid != 0) {
> 1828 cl_object_attr_lock(obj);
> 1829 cl_object_attr_set(env, obj, attr, valid);
> 1830 cl_object_attr_unlock(obj);
>
> after:
>
> 1827 if (valid != 0) {
> 1828 spin_lock(cl_object_attr_guard(obj));
> 1829 cl_object_attr_set(env, obj, attr, valid);
> 1830 spin_unlock(cl_object_attr_guard(obj));
The word "_object" doesn't add any new information to the name. If you
remove it then the code is improved.
spin_lock(cl_attr_guard(obj));
cl_attr_set(env, obj, attr, valid);
spin_unlock(cl_attr_guard(obj));
regards,
dan carpenter
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [HPDD-discuss] [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-28 10:00 ` Dan Carpenter
@ 2014-11-28 15:45 ` Patrick Farrell
2014-11-28 16:28 ` Dan Carpenter
0 siblings, 1 reply; 9+ messages in thread
From: Patrick Farrell @ 2014-11-28 15:45 UTC (permalink / raw)
To: Dan Carpenter, Loïc Pefferkorn
Cc: devel@driverdev.osuosl.org, Greg KH, linux-kernel@vger.kernel.org,
gdonald@gmail.com, HPDD-discuss@ml01.01.org
Dan,
I disagree about the change suggested here. In this particular code, 'object_attr' is distinct from 'attr', as in a 'setattr' call on an inode. 'cl_object' is a distinct thing from an inode/file on disk, and specifying it is the objects attr is helpful in understanding there is not a direct relationship to 'attr' in the general filesystem sense. (cl_object attrs are used in determining actual on disk attributes, but there is not a one-to-one correspondence.)
I am willing to be corrected, but that is my first feeling here.
- Patrick
________________________________________
From: HPDD-discuss [hpdd-discuss-bounces@lists.01.org] on behalf of Dan Carpenter [dan.carpenter@oracle.com]
Sent: Friday, November 28, 2014 4:00 AM
To: Loïc Pefferkorn
Cc: devel@driverdev.osuosl.org; Greg KH; linux-kernel@vger.kernel.org; gdonald@gmail.com; HPDD-discuss@ml01.01.org
Subject: Re: [HPDD-discuss] [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
On Thu, Nov 27, 2014 at 07:34:10PM +0100, Loïc Pefferkorn wrote:
> 1827 if (valid != 0) {
> 1828 cl_object_attr_lock(obj);
> 1829 cl_object_attr_set(env, obj, attr, valid);
> 1830 cl_object_attr_unlock(obj);
>
> after:
>
> 1827 if (valid != 0) {
> 1828 spin_lock(cl_object_attr_guard(obj));
> 1829 cl_object_attr_set(env, obj, attr, valid);
> 1830 spin_unlock(cl_object_attr_guard(obj));
The word "_object" doesn't add any new information to the name. If you
remove it then the code is improved.
spin_lock(cl_attr_guard(obj));
cl_attr_set(env, obj, attr, valid);
spin_unlock(cl_attr_guard(obj));
regards,
dan carpenter
_______________________________________________
HPDD-discuss mailing list
HPDD-discuss@lists.01.org
https://lists.01.org/mailman/listinfo/hpdd-discuss
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [HPDD-discuss] [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-28 15:45 ` [HPDD-discuss] " Patrick Farrell
@ 2014-11-28 16:28 ` Dan Carpenter
0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2014-11-28 16:28 UTC (permalink / raw)
To: Patrick Farrell
Cc: Loïc Pefferkorn, devel@driverdev.osuosl.org, Greg KH,
linux-kernel@vger.kernel.org, gdonald@gmail.com,
HPDD-discuss@ml01.01.org
On Fri, Nov 28, 2014 at 03:45:24PM +0000, Patrick Farrell wrote:
> Dan,
>
> I disagree about the change suggested here. In this particular code,
> 'object_attr' is distinct from 'attr', as in a 'setattr' call on an
> inode. 'cl_object' is a distinct thing from an inode/file on disk,
> and specifying it is the objects attr is helpful in understanding
> there is not a direct relationship to 'attr' in the general filesystem
> sense. (cl_object attrs are used in determining actual on disk
> attributes, but there is not a one-to-one correspondence.)
>
> I am willing to be corrected, but that is my first feeling here.
I haven't looked at it deeply. Loïc was suggesting that we need new
locking functions to deal with lustre's unwieldy naming schemes and I
think we should just fix the names...
We already have a cl_attr struct. Is that different from what
we're locking here? I don't think anyone will think this takes an inode
argument.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-27 18:34 ` Loïc Pefferkorn
2014-11-28 10:00 ` Dan Carpenter
@ 2014-11-28 22:22 ` Greg KH
2014-11-30 19:54 ` Loïc Pefferkorn
1 sibling, 1 reply; 9+ messages in thread
From: Greg KH @ 2014-11-28 22:22 UTC (permalink / raw)
To: Loïc Pefferkorn
Cc: oleg.drokin, andreas.dilger, gdonald, keith.mannthey,
john.hammond, devel, HPDD-discuss, linux-kernel
On Thu, Nov 27, 2014 at 07:34:10PM +0100, Loïc Pefferkorn wrote:
> Hello Greg,
>
> After some investigation, I think that removing these wrappers is not going to improve the code readability:
>
> On Wed, Nov 26, 2014 at 12:54:43PM -0800, Greg KH wrote:
> > On Wed, Nov 26, 2014 at 05:15:48PM +0100, Loic Pefferkorn wrote:
> > > Add __acquires() and __releases() function annotations, to fix sparse warnings related to lock context imbalance.
> > >
> > > This fixes the following warnings:
> > >
> > > drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c:153:5: warning: context imbalance in 'cfs_trace_lock_tcd' - wrong count at exit
> > > drivers/staging/lustre/lustre/libcfs/hash.c:128:1: warning: context imbalance in 'cfs_hash_spin_lock' - wrong count at exit
> > > drivers/staging/lustre/lustre/libcfs/hash.c:142:9: warning: context imbalance in 'cfs_hash_rw_lock' - wrong count at exit
> > > drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c:57:17: warning: context imbalance in 'lock_res_and_lock' - wrong count at exit
> > > drivers/staging/lustre/lustre/libcfs/libcfs_lock.c:93:1: warning: context imbalance in 'cfs_percpt_lock' - wrong count at exit
> > >
> > > Signed-off-by: Loic Pefferkorn <loic@loicp.eu>
> > > ---
> > > drivers/staging/lustre/lustre/libcfs/hash.c | 4 ++++
> > > drivers/staging/lustre/lustre/libcfs/libcfs_lock.c | 2 ++
> > > drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c | 2 ++
> > > drivers/staging/lustre/lustre/obdclass/cl_object.c | 2 ++
> > > 4 files changed, 10 insertions(+)
> > >
> > > diff --git a/drivers/staging/lustre/lustre/libcfs/hash.c b/drivers/staging/lustre/lustre/libcfs/hash.c
> > > index 32da783..7c6e2a3 100644
> > > --- a/drivers/staging/lustre/lustre/libcfs/hash.c
> > > +++ b/drivers/staging/lustre/lustre/libcfs/hash.c
> > > @@ -126,18 +126,21 @@ cfs_hash_nl_unlock(union cfs_hash_lock *lock, int exclusive) {}
> > >
> > > static inline void
> > > cfs_hash_spin_lock(union cfs_hash_lock *lock, int exclusive)
> > > + __acquires(&lock->spin)
> > > {
> > > spin_lock(&lock->spin);
> > > }
> > >
> > > static inline void
> > > cfs_hash_spin_unlock(union cfs_hash_lock *lock, int exclusive)
> > > + __releases(&lock->spin)
> > > {
> > > spin_unlock(&lock->spin);
> > > }
> >
> > Ugh, how horrid, please just delete these functions and push down the
> > spin_lock/unlock calls down into the places these are called.
>
> cfs_hash_spin_lock() and cfs_hash_spin_unlock() are referenced by function pointers later in the same file:
>
> 165 /** no bucket lock, one spinlock to protect everything */
> 166 static cfs_hash_lock_ops_t cfs_hash_nbl_lops = {
> 167 .hs_lock = cfs_hash_spin_lock,
> 168 .hs_unlock = cfs_hash_spin_unlock,
> 169 .hs_bkt_lock = cfs_hash_nl_lock,
> 170 .hs_bkt_unlock = cfs_hash_nl_unlock,
> 171 };
> 172
> 173 /** spin bucket lock, rehash is enabled */
> 174 static cfs_hash_lock_ops_t cfs_hash_bkt_spin_lops = {
> 175 .hs_lock = cfs_hash_rw_lock,
> 176 .hs_unlock = cfs_hash_rw_unlock,
> 177 .hs_bkt_lock = cfs_hash_spin_lock,
> 178 .hs_bkt_unlock = cfs_hash_spin_unlock,
> 179 };
That's even worse than I imagined. Putting sparse markings on these
function calls is just papering over nonsense. Please work on unwinding
the mess so that you don't need callbacks for locks, that is an
abstraction that isn't needed.
> > > static inline void
> > > cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
> > > + __acquires(&lock->rw)
> > > {
> > > if (!exclusive)
> > > read_lock(&lock->rw);
> > > @@ -147,6 +150,7 @@ cfs_hash_rw_lock(union cfs_hash_lock *lock, int exclusive)
> > >
> > > static inline void
> > > cfs_hash_rw_unlock(union cfs_hash_lock *lock, int exclusive)
> > > + __releases(&lock->rw)
> > > {
> > > if (!exclusive)
> > > read_unlock(&lock->rw);
> >
> >
> > Same for these.
>
> Likewise for cfs_hash_rw_lock() and cfs_hash_rw_unlock():
>
> 173 /** spin bucket lock, rehash is enabled */
> 174 static cfs_hash_lock_ops_t cfs_hash_bkt_spin_lops = {
> 175 .hs_lock = cfs_hash_rw_lock,
> 176 .hs_unlock = cfs_hash_rw_unlock,
> 177 .hs_bkt_lock = cfs_hash_spin_lock,
> 178 .hs_bkt_unlock = cfs_hash_spin_unlock,
> 179 };
> 180
> 181 /** rw bucket lock, rehash is enabled */
> 182 static cfs_hash_lock_ops_t cfs_hash_bkt_rw_lops = {
> 183 .hs_lock = cfs_hash_rw_lock,
> 184 .hs_unlock = cfs_hash_rw_unlock,
> 185 .hs_bkt_lock = cfs_hash_rw_lock,
> 186 .hs_bkt_unlock = cfs_hash_rw_unlock,
> 187 };
Same here, ick ick ick.
> > > diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> > > index 2c199c7..1e529fc 100644
> > > --- a/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> > > +++ b/drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
> > > @@ -91,6 +91,7 @@ EXPORT_SYMBOL(cfs_percpt_lock_alloc);
> > > */
> > > void
> > > cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index)
> > > + __acquires(pcl->pcl_locks[index])
> > > {
> > > int ncpt = cfs_cpt_number(pcl->pcl_cptab);
> > > int i;
> > > @@ -125,6 +126,7 @@ EXPORT_SYMBOL(cfs_percpt_lock);
> > > /** unlock a CPU partition */
> > > void
> > > cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index)
> > > + __releases(pcl->pcl_locks[index])
> > > {
> > > int ncpt = cfs_cpt_number(pcl->pcl_cptab);
> > > int i;
> > > diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> > > index 976c61e..257669b 100644
> > > --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> > > +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
> > > @@ -151,6 +151,7 @@ cfs_trace_buf_type_t cfs_trace_buf_idx_get(void)
> > > * for details.
> > > */
> > > int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> > > + __acquires(&tcd->tc_lock)
> > > {
> > > __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
> > > if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> > > @@ -165,6 +166,7 @@ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> > > }
> > >
> > > void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
> > > + __releases(&tcd->tcd_lock)
> > > {
> > > __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
> > > if (tcd->tcd_type == CFS_TCD_TYPE_IRQ)
> > > diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> > > index ce96bd2..8577f97 100644
> > > --- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
> > > +++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
> > > @@ -193,6 +193,7 @@ static spinlock_t *cl_object_attr_guard(struct cl_object *o)
> > > * cl_object_attr_get(), cl_object_attr_set().
> > > */
> > > void cl_object_attr_lock(struct cl_object *o)
> > > + __acquires(cl_object_attr_guard(o))
> > > {
> > > spin_lock(cl_object_attr_guard(o));
> > > }
> > > @@ -202,6 +203,7 @@ EXPORT_SYMBOL(cl_object_attr_lock);
> > > * Releases data-attributes lock, acquired by cl_object_attr_lock().
> > > */
> > > void cl_object_attr_unlock(struct cl_object *o)
> > > + __releases(cl_object_attr_guard(o))
> > > {
> > > spin_unlock(cl_object_attr_guard(o));
> > > }
> >
> > Same thing here.
>
> These ones are easy to replace, but the naming scheme of all functions in cl_object.c is consistent,
> from my point of view it ease code reading where they are called, for example in lustre/lustre/osc/osc_request.c:
>
> before:
>
> 1827 if (valid != 0) {
> 1828 cl_object_attr_lock(obj);
> 1829 cl_object_attr_set(env, obj, attr, valid);
> 1830 cl_object_attr_unlock(obj);
>
> after:
>
> 1827 if (valid != 0) {
> 1828 spin_lock(cl_object_attr_guard(obj));
> 1829 cl_object_attr_set(env, obj, attr, valid);
> 1830 spin_unlock(cl_object_attr_guard(obj));
>
>
> But I'm here for learning, and I would be grateful to have your opinion.
Don't hide "implementation of locks" in functions like this, it only
causes problems. This code has layers of layers of layers of
abstractions due to it wanting to be originally ported to other
operating systems and lots of different kernel versions of Linux itself.
Unwinding and removing those layers is a good thing to do, don't paper
over the nonsense by putting sparse markings on pointless functions.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance
2014-11-28 22:22 ` Greg KH
@ 2014-11-30 19:54 ` Loïc Pefferkorn
0 siblings, 0 replies; 9+ messages in thread
From: Loïc Pefferkorn @ 2014-11-30 19:54 UTC (permalink / raw)
To: Greg KH
Cc: oleg.drokin, andreas.dilger, gdonald, keith.mannthey,
john.hammond, devel, HPDD-discuss, linux-kernel
On Fri, Nov 28, 2014 at 02:22:07PM -0800, Greg KH wrote:
>
> That's even worse than I imagined. Putting sparse markings on these
> function calls is just papering over nonsense. Please work on unwinding
> the mess so that you don't need callbacks for locks, that is an
> abstraction that isn't needed.
>
> Same here, ick ick ick.
>
>
> Don't hide "implementation of locks" in functions like this, it only
> causes problems. This code has layers of layers of layers of
> abstractions due to it wanting to be originally ported to other
> operating systems and lots of different kernel versions of Linux itself.
> Unwinding and removing those layers is a good thing to do, don't paper
> over the nonsense by putting sparse markings on pointless functions.
>
> thanks,
Hi guys,
Thanks for your reply. I'm going to write a v2.
--
Cheers,
Loïc
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-11-30 19:54 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-26 16:15 [PATCH] staging: lustre: fix sparse warnings related to lock context imbalance Loic Pefferkorn
2014-11-26 20:54 ` Greg KH
2014-11-27 5:30 ` Loïc Pefferkorn
2014-11-27 18:34 ` Loïc Pefferkorn
2014-11-28 10:00 ` Dan Carpenter
2014-11-28 15:45 ` [HPDD-discuss] " Patrick Farrell
2014-11-28 16:28 ` Dan Carpenter
2014-11-28 22:22 ` Greg KH
2014-11-30 19:54 ` Loïc Pefferkorn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox