From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5C5C2045B0 for ; Wed, 5 Mar 2025 09:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741166833; cv=none; b=d0BYbUCgBWsdfp5I+PFrf3UUKxqFgQ81t9IUw2/A7badZXshp08ZS4OObFsVFvujx90xiICzjItlXI90qovDgiTOea9nI7jI4GubcNLSDAKBMJ5bQ0gj/KJlyV6KvxB1/pZ+r54MmyngOoHXYVLfJ2uZUz/GcXLrhFcsf8ha5BI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741166833; c=relaxed/simple; bh=3mDFeB3Bpj3IOfRwlQRf3Grj75HR3nrndwXyWmM3Ob4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pFEgI2ZYH+prY4vd6PDfz0I8K35gGxiIT+zWigYPAnWHfCHmv77ha30xjIM/bUulJEguz5fppIBozuq2Mrc44ZyeFeAgFNW+hd752iqTVseCfDoyJd3burQ+F+ZI8FCFZEdVdwzS6gHP695e+PNPw7Y97pjGVPg8pyGNtA/mkUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=awQ2WJus; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="awQ2WJus" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43bc30adad5so19964495e9.1 for ; Wed, 05 Mar 2025 01:27:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741166829; x=1741771629; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VaMa3tOr/8WS8V6AnlLw/eUNgZqrJVmxSDme9KtSQnA=; b=awQ2WJusxW6Ge0kv9C7Zju2JITr5EXSeephgcSpgRUB67uiBC2wUReZa/SrihqlmBV zMms2er4oICT6Quz/tBnkW/bMaNIjXMdxymm2mdhR9xfSuxVKM9ONClD/eluuDgTAG9Z cSTRS5qBoAatCwOyBW6idxIRVSxCnO+pKzcmP7MQ0TPj3qdmkaBJ8Q/LWpx+Y/szwxxZ LJpMWsH3PAH+QZGkJAJa1GPJ2b+1Y75T/DTdOUHiHu9jDRkjLhakyxdJWPiRbV2Wn6jw PqJzVJnpSRn6f7FKJcb4MvkK/ygd88eqJXzL8DmZTvV5KzE9q14qcQvpm1uWSxpYfF86 iw7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741166829; x=1741771629; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VaMa3tOr/8WS8V6AnlLw/eUNgZqrJVmxSDme9KtSQnA=; b=kLfkMs4zh3b28gZ0T9x21wcy6LDkwO9kQsq+zQ7yuwqLTfPAmxQYd4E62Uz2MFhNsS kRITEmfUfpdkPet32Hb8OctdC1euIWU6PGpO0x8W+ilZCaWKtWIvF5RJS9AjnpZwVVy1 KfYTCxwrx2IgdO+YR8vcKxhn3F6rDhZBFVPmpIETJn9pmRrwpauAPDt9cX/eAqu3Rd/q 4CM+9FvGhpFnGHplMkJVE241f6GDJXI+67Y4LtvK1JparaxUxO6VzCEwdsnXBvPAxb6m mIJkF4VSsRhXHs73b1wztwIbL4mXDnSz19ud+oCeXyLHtPQPmSv/A58XbM3kF8MC3Fkt 78+A== X-Forwarded-Encrypted: i=1; AJvYcCXROC0ssJfw63hsucUVbK1C22kJ+7Ya2exWxHFVfq3G8zydhwMwQ9E0lx/Iuf3A3FckcBPwsgt1pRjt7v8=@vger.kernel.org X-Gm-Message-State: AOJu0YyYLWgsVg9Et9+L4YeArmVsvnNBc22yrbnNTcrtz537gjGnYluz Y9eK7SdX8u39zDTrncQEBl1smEe7iXd2jYfNMPrxiIO5ID1brFQDRaC+Ml+IMsY= X-Gm-Gg: ASbGncvH8q+K1TL/WHel8KCq5eDgwSNAtzSjMnvGTuV1zGu73oXEsl3+ZPE8LMBl3Pm fpEoJ5lwj68cluCxp244xuZbd8uFgpyhosNYNWUsD+UbnLJQobMZJZADcj3iYBMMx7Q4bHOyGAq csyLjoebfgunv5cKKNXdFjUIlWAibDPlde/bwzgZGr0r02TXUehRjmeSxoSEEXAhHg2sLHL9cG9 cXEmIXWpRc7CoXtOZ0FMkYOqCqwg05ZEj1Uri5YrtxTuBIQKMnz8LCrf/WJvA6y/VmjHdKvvgr4 T2L6FZRnfk40yOcWKiem2U+n5jxFC3GD6esr8/vkRkCajcFWPw== X-Google-Smtp-Source: AGHT+IE3mizAOsnSuTtcbkO82OvTIYaM5IjOsyfCaEaBUlwqBcpm21mf2Z2/NNT65xir9k5CCr442Q== X-Received: by 2002:a05:600c:4750:b0:439:9e8b:228e with SMTP id 5b1f17b1804b1-43bd29c42c8mr13412085e9.20.1741166829098; Wed, 05 Mar 2025 01:27:09 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43bd426d069sm11942015e9.3.2025.03.05.01.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 01:27:08 -0800 (PST) Date: Wed, 5 Mar 2025 12:27:04 +0300 From: Dan Carpenter To: Marco Elver Cc: "David S. Miller" , Luc Van Oostenryck , "Paul E. McKenney" , Alexander Potapenko , Arnd Bergmann , Bart Van Assche , Bill Wendling , Boqun Feng , Dmitry Vyukov , Eric Dumazet , Frederic Weisbecker , Greg Kroah-Hartman , Herbert Xu , Ingo Molnar , Jann Horn , Jiri Slaby , Joel Fernandes , Jonathan Corbet , Josh Triplett , Justin Stitt , Kees Cook , Kentaro Takeda , Mark Rutland , Mathieu Desnoyers , Miguel Ojeda , Nathan Chancellor , Neeraj Upadhyay , Peter Zijlstra , Steven Rostedt , Tetsuo Handa , Thomas Gleixner , Uladzislau Rezki , Waiman Long , Will Deacon , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, rcu@vger.kernel.org, linux-crypto@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH v2 01/34] compiler_types: Move lock checking attributes to compiler-capability-analysis.h Message-ID: References: <20250304092417.2873893-1-elver@google.com> <20250304092417.2873893-2-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Mar 05, 2025 at 10:13:44AM +0100, Marco Elver wrote: > On Wed, Mar 05, 2025 at 11:36AM +0300, Dan Carpenter wrote: > > On Tue, Mar 04, 2025 at 10:21:00AM +0100, Marco Elver wrote: > > > +#ifndef _LINUX_COMPILER_CAPABILITY_ANALYSIS_H > > > +#define _LINUX_COMPILER_CAPABILITY_ANALYSIS_H > > > + > > > +#ifdef __CHECKER__ > > > + > > > +/* Sparse context/lock checking support. */ > > > +# define __must_hold(x) __attribute__((context(x,1,1))) > > > +# define __acquires(x) __attribute__((context(x,0,1))) > > > +# define __cond_acquires(x) __attribute__((context(x,0,-1))) > > > +# define __releases(x) __attribute__((context(x,1,0))) > > > +# define __acquire(x) __context__(x,1) > > > +# define __release(x) __context__(x,-1) > > > +# define __cond_lock(x, c) ((c) ? ({ __acquire(x); 1; }) : 0) > > > + > > > > The other thing you might want to annotate is ww_mutex_destroy(). > > We can add an annotation to check the lock is not held: > Sorry, my email was bad. I haven't actually tried your patch at all. I have locking check in Smatch so I'm just basing this on the things that I did... https://github.com/error27/smatch/blob/master/smatch_locking.c This isn't a mandatory thing. Whatever happens we're going to end up doing dozens of patches all over the kernel later. I thought you could destroy a mutex regardless or whether it was held or not. I was getting false positives which said that we should drop the lock on error but actually the mutex is destroyed on that path so it doesn't matter. regards, dan carpenter