Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14503342ybl; Mon, 30 Dec 2019 11:17:55 -0800 (PST) X-Google-Smtp-Source: APXvYqz9jBnA+eURb7fUI/2JjBQcy1q0qylKiDRegtTHrChVSLrsKNUuTzeh2yK2d+QfMI9ioazt X-Received: by 2002:a05:6830:1608:: with SMTP id g8mr71827442otr.169.1577733475805; Mon, 30 Dec 2019 11:17:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577733475; cv=none; d=google.com; s=arc-20160816; b=Jim25GwcTqFp2NSrr0vjEFevy4WQiED0NfHvTaAhy/RRVTA/1zSyEB7Vt/7dFEPj40 4VeQoxkTHBGxBA3L35my6PRC7EZXh3BfsJN/5W99yW4QwgjJWH65x8O2TiDpLlSnGmor dyQnFVBWKv9PR7EIqM74OwKY8egCyi4gIi01NigMGHg7MhjUn9+uLIcGVpsTmXc+Gy60 wtSsJsQbhRwLXq3UqXJ8FMyDDQ2KwryuSCjVEBFV7WjDnBYiuebmSCAcxi7l9JkyYuNS tVR9ZJ25Aa9REdbFfoMkYFcZK8dDhjUXxO3brPQmABTys+DuY3VhXZSZ070I8Su2xpC+ 97rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=n1seYeqgHj+/viVyWOjxOX42F5TuJ5AtUDDRFbWudzk=; b=FGfbWGTOVx/OnQhomeV64Ism1VFW/O0xsmvXHTL0/Ol0zG1I5UL50xwPkEuuq7aTGD M1xRq6+eYj/GzQAam5mOArEQhNh7/GOq2fQ/UdRWIlj9sUJQe/jkHTT+uqqMrgcRLnDg JcSfCgHPbSUCWc9uvXkGe2z+z3CrYuD3b2CgDEpqlX1ykHTqpUK/qH3gGgtxLD2TlZak L2TvFjcIuNnMgEDKZ4q81/GRgMT9PK3kELF+Kfp6Nvvzp9P2QqfvQJN2PcKhZjUldyza clCjq6fcAhjr3eHLr14ye/yft+HKshEJdITAL4zH5/JdnbdxlMEIR8M3Lybiuq3/O+Lb DEVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gCA5m3Jv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si22133200oia.264.2019.12.30.11.17.44; Mon, 30 Dec 2019 11:17:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gCA5m3Jv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727703AbfL3TPu (ORCPT + 99 others); Mon, 30 Dec 2019 14:15:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:47416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727642AbfL3TPu (ORCPT ); Mon, 30 Dec 2019 14:15:50 -0500 Received: from zzz.localdomain (h75-100-12-111.burkwi.broadband.dynamic.tds.net [75.100.12.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A6F3206CB; Mon, 30 Dec 2019 19:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577733349; bh=Di7rnIR7c21+Vdrdl1E5rG0N/9TZyCG7j0ogQSbim70=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gCA5m3JvAiuvkGK7SGTzVPxv3P3psUWpEKTm25af8SjUIDzgNI4CBysSlQskQ8bkL CIvYLWMpYSq9yDLL2fkaDB6WWZkaQtLvs0cFeanutrsITQ7lmRkWIB8qaifb6FWAzD DqjTgR6b1vDY6hvWhHkvt4ZGJMvwn25s5rMIWcqI= Date: Mon, 30 Dec 2019 13:15:47 -0600 From: Eric Biggers To: Kees Cook Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Ingo Molnar , Will Deacon , Elena Reshetova , Thomas Gleixner , Anna-Maria Gleixner , Sebastian Andrzej Siewior Subject: Re: [PATCH] locking/refcount: add sparse annotations to dec-and-lock functions Message-ID: <20191230191547.GA1501@zzz.localdomain> References: <20191226152922.2034-1-ebiggers@kernel.org> <20191228114918.GU2827@hirez.programming.kicks-ass.net> <201912301042.FB806E1133@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201912301042.FB806E1133@keescook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 30, 2019 at 10:43:20AM -0800, Kees Cook wrote: > On Sat, Dec 28, 2019 at 12:49:18PM +0100, Peter Zijlstra wrote: > > On Thu, Dec 26, 2019 at 09:29:22AM -0600, Eric Biggers wrote: > > > From: Eric Biggers > > > > > > Wrap refcount_dec_and_lock() and refcount_dec_and_lock_irqsave() with > > > macros using __cond_lock() so that 'sparse' doesn't report warnings > > > about unbalanced locking when using them. > > > > > > This is the same thing that's done for their atomic_t equivalents. > > > > > > Don't annotate refcount_dec_and_mutex_lock(), because mutexes don't > > > currently have sparse annotations. > > > > I so f'ing hate that __cond_lock() crap. Previously I've suggested > > fixing sparse instead of making such an atrocious trainwreck of the > > code. > > Ew, I never noticed these before. That is pretty ugly. Can't __acquire() > be used directly in the functions instead of building the nasty > wrappers? The annotation needs to go in the .h file, not the .c file, because sparse only analyzes individual translation units. It needs to be a wrapper macro because it needs to tie the acquisition of the lock to the return value being true. I.e. there's no annotation you can apply directly to the function prototype that means "if this function returns true, it acquires the lock that was passed in parameter N". - Eric