From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752976AbcIOSdw (ORCPT ); Thu, 15 Sep 2016 14:33:52 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:34968 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750794AbcIOSdo (ORCPT ); Thu, 15 Sep 2016 14:33:44 -0400 Message-ID: <57DAE988.6040609@gmail.com> Date: Fri, 16 Sep 2016 00:03:44 +0530 From: nayeem User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: "Dilger, Andreas" , Greg KH CC: "devel@driverdev.osuosl.org" , Linux Kernel Mailing List , "Drokin, Oleg" , James Simmons , Lustre Development List Subject: Re: [PATCH] staging: lustre: lustre/ldlm: Fixed sparse warnings References: <1473434435-27025-1-git-send-email-itachi.opsrc@gmail.com> <20160912102747.GA13621@kroah.com> <47AECAA7-59D7-41DB-9A85-A23ACF6A7B1F@intel.com> In-Reply-To: <47AECAA7-59D7-41DB-9A85-A23ACF6A7B1F@intel.com> Content-Type: multipart/mixed; boundary="------------010508070409060603050109" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------010508070409060603050109 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On Wednesday 14 September 2016 10:44 AM, Dilger, Andreas wrote: > On Sep 12, 2016, at 04:27, Greg KH wrote: >> >> On Fri, Sep 09, 2016 at 08:50:35PM +0530, Nayeemahmed Badebade wrote: >>> Added __acquires / __releases sparse locking annotations >>> to lock_res_and_lock and unlock_res_and_lock functions in >>> l_lock.c, to fix below sparse warnings: >>> >>> l_lock.c:47:22: warning: context imbalance in 'lock_res_and_lock' - wrong count at exit >>> l_lock.c:62:6: warning: context imbalance in 'unlock_res_and_lock' - unexpected unlock >>> >>> Signed-off-by: Nayeemahmed Badebade >>> --- >>> drivers/staging/lustre/lustre/ldlm/l_lock.c | 4 ++++ >>> 1 file changed, 4 insertions(+) >>> >>> diff --git a/drivers/staging/lustre/lustre/ldlm/l_lock.c b/drivers/staging/lustre/lustre/ldlm/l_lock.c >>> index ea8840c..c4b9612 100644 >>> --- a/drivers/staging/lustre/lustre/ldlm/l_lock.c >>> +++ b/drivers/staging/lustre/lustre/ldlm/l_lock.c >>> @@ -45,6 +45,8 @@ >>> * being an atomic operation. >>> */ >>> struct ldlm_resource *lock_res_and_lock(struct ldlm_lock *lock) >>> + __acquires(&lock->l_lock) >>> + __acquires(lock->l_resource) >> >> Hm, these are tricky, I don't want to take this type of change without >> an ack from the lustre developers... > > The "__acquires(&lock->l_lock)" line here looks correct, along with the > corresponding "__releases(&lock->l_lock)" at unlock_res_and_lock(). > > The problem, however, is that "l_resource" is not a lock, but rather a > struct. The call to "lock_res(lock->l_resource)" is actually locking > "lr_lock" internally. > > It would be better to add "__acquires(&res->lr_lock)" at lock_res() and > "__releases(&res->lr_lock)" at unlock_res(). That will also forestall > any other warnings about an imbalance with lock_res()/unlock_res() or > their callsites. > > Cheers, Andreas > Hi Andreas, Thank you for your review comments. I did the change according to your comments and the diff is attached to mail. But this change doesn't seem to fix the sparse warning. With this change when i compile the code "make C=2 ./drivers/staging/lustre/lustre/", sparse warning still comes: {{{ CHECK drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c:47:22: warning: context imbalance in 'lock_res_and_lock' - wrong count at exit drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c:62:6: warning: context imbalance in 'unlock_res_and_lock' - unexpected unlock CC [M] drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.o }}} Would it be a good idea to add "__acquires(&lock->l_resource->lr_lock)" & "__acquires(&lock->l_lock)" at lock_res_and_lock() and "__releases(&lock->l_resource->lr_lock)" & "__releases(&lock->l_lock)" at unlock_res_and_lock() ? Because with that change the sparse warning is fixed. {{{ CHECK drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.c CC [M] drivers/staging/lustre/lustre/ptlrpc/../../lustre/ldlm/l_lock.o }}} Could you please confirm this. Regards, Nayeem --------------010508070409060603050109 Content-Type: text/x-patch; name="sparse-warnings-fix-patch-v2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sparse-warnings-fix-patch-v2.patch" diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h index 1ec4231..2ae463a 100644 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h @@ -1293,6 +1293,7 @@ enum lock_res_type { /** Lock resource. */ static inline void lock_res(struct ldlm_resource *res) + __acquires(&res->lr_lock) { spin_lock(&res->lr_lock); } @@ -1306,6 +1307,7 @@ static inline void lock_res_nested(struct ldlm_resource *res, /** Unlock resource. */ static inline void unlock_res(struct ldlm_resource *res) + __releases(&res->lr_lock) { spin_unlock(&res->lr_lock); } diff --git a/drivers/staging/lustre/lustre/ldlm/l_lock.c b/drivers/staging/lustre/lustre/ldlm/l_lock.c index ea8840c..a887d9f 100644 --- a/drivers/staging/lustre/lustre/ldlm/l_lock.c +++ b/drivers/staging/lustre/lustre/ldlm/l_lock.c @@ -45,6 +45,7 @@ * being an atomic operation. */ struct ldlm_resource *lock_res_and_lock(struct ldlm_lock *lock) + __acquires(&lock->l_lock) { spin_lock(&lock->l_lock); @@ -59,6 +60,7 @@ EXPORT_SYMBOL(lock_res_and_lock); * Unlock a lock and its resource previously locked with lock_res_and_lock */ void unlock_res_and_lock(struct ldlm_lock *lock) + __releases(&lock->l_lock) { /* on server-side resource of lock doesn't change */ ldlm_clear_res_locked(lock); --------------010508070409060603050109--