Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp31378ybl; Tue, 7 Jan 2020 01:30:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxalydNfXAON/Zzc5eybD0Oxv760ErMaNyhBUde4E303AiykAV+2uFFSEkV6wgiJl7UvB3Y X-Received: by 2002:a05:6830:1607:: with SMTP id g7mr120995431otr.320.1578389453670; Tue, 07 Jan 2020 01:30:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578389453; cv=none; d=google.com; s=arc-20160816; b=nal4NgIIEAfEx8JLz+R+81dCNdtBG4O66llSgDVP2GdDWQ0KrecjUiHJB5H/5rv+Op 5GH+MQbeJYzr2VT5XipQftdP/98o1SK6dnUEq9Iy8fu0b02YxGD0d4BqYZuAql9nuB3a 66eD/vvtHcyq+nU3tAg7CWGzFKr+fusGaRWKnGuIrFSQQGCo/5aWIR+CJE7iKUpwIEme 5Q6qlONGvcNwEHJZ8Jh8ELaQJQrF4iGbLJYfTmV7z9/EARt00TMyjP4yP/i4m+q5TLBV DBxcMsM1GIFLY+hLnYjXNOysEMOnQQwoyXpWZ887MHyY2bGrVS8nHMg8czwPoiHFsSI+ juqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=sZXc/SFe/LDxQMr1tMtTHpfYzLnb842y8KpXben4b1s=; b=HZO6FCX2DWRSx5SgegUeq9j3C9zxybO8YJD5f5fWb5yvndtD2iesVemv227Qfv1oMR dRTLFTjSmDZ4mUH2zkqcddfTBX6NcgD/WvUGan729oGa7L+Qbm1jEr2APHNQ/n2wcBkJ v32mZImiPyFAJwq7g4zsz3LTMZjkFZmPWkJLabCa6zgzxf9SAknm4SseLnttwK00Gbhv DyFYSIFiRaAxFaSLZuUbh6JS/Mx9RWq7vMsRs56hFOghQft+iTpz/wWTeTovczo35SXD VHbYLLGp1n+7RkcPvdoXNuq5UhkpZ/EGh/TgfDb+DCncjRJURlktPpBVHJKWx9wHBGqY F2pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="btXi/8aB"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si37355441otp.70.2020.01.07.01.30.40; Tue, 07 Jan 2020 01:30:53 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="btXi/8aB"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbgAGJ3m (ORCPT + 99 others); Tue, 7 Jan 2020 04:29:42 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:41508 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727154AbgAGJ3l (ORCPT ); Tue, 7 Jan 2020 04:29:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=sZXc/SFe/LDxQMr1tMtTHpfYzLnb842y8KpXben4b1s=; b=btXi/8aBR87eesFRk9rVTf7MA Lo11ZldNjZKAaB6/9zJZ1gf9NCJZvkST1Vwo004YnQHoByFcCJfif+5Fqu4TzIXw5U0tGlHGJWd+a uAbdPGF/hE+gJrM45w6VbyVJMLfvZdman1WMvJ7duagTokTpaTco+9foSyaY6KC4KEi1apyy3gt3Z MyFzxQQ4CQ3HjQ7Ly+3LO79dRGmdWpV/ITVmEE62USnSeM4Sul7t2Qc2rcdQVThRujD+TAPDdf8sE Ls2wHFbHxc87Oh04zt8FDYANAYG0ibCN0a0J7L1coZDrTWqb/7TS0AcaWpbj9k4F209mloCRCp9DM w5WzTTcmg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iolBA-0000AU-Tt; Tue, 07 Jan 2020 09:29:37 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A39A4304A59; Tue, 7 Jan 2020 10:28:02 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 24B232B5FBC95; Tue, 7 Jan 2020 10:29:35 +0100 (CET) Date: Tue, 7 Jan 2020 10:29:35 +0100 From: Peter Zijlstra To: Luc Van Oostenryck Cc: Kees Cook , Eric Biggers , linux-kernel@vger.kernel.org, Ingo Molnar , Will Deacon , Elena Reshetova , Thomas Gleixner , Anna-Maria Gleixner , Sebastian Andrzej Siewior , linux-sparse@vger.kernel.org Subject: Re: [PATCH] locking/refcount: add sparse annotations to dec-and-lock functions Message-ID: <20200107092935.GU2844@hirez.programming.kicks-ass.net> References: <20191226152922.2034-1-ebiggers@kernel.org> <20191228114918.GU2827@hirez.programming.kicks-ass.net> <201912301042.FB806E1133@keescook> <20191230191547.GA1501@zzz.localdomain> <201912301131.2C7C51E8C6@keescook> <20191230233814.2fgmsgtnhruhklnu@ltop.local> <20200106154119.GV2810@hirez.programming.kicks-ass.net> <20200106175459.tjuhmdrsusax3s4z@ltop.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200106175459.tjuhmdrsusax3s4z@ltop.local> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 06, 2020 at 06:54:59PM +0100, Luc Van Oostenryck wrote: > On Mon, Jan 06, 2020 at 04:41:19PM +0100, Peter Zijlstra wrote: > > extern bool spin_trylock(spinlock_t *lock) __attribute__((context(lock, 0, spin_trylock(lock)); > > Well, allowing arbitrary conditions would be hard/impossible but you're > only asking to have the *return value* as condition, right? That looks > as reasonably feasible. Just the return value would cover all the known cases yes. At the time I might have been somewhat over ambitious.. > > Basically have sparse do a transform on its own expression tree and > > inject the very same crud we now do manually. This avoids cluttering the > > kernel tree with this nonsense. > > So, a call of a function declared with __acquires() or releases() is > interpreted by Sparse as if the call is immediately followed by an > increase or a decrease of the context. It wouldn't be very hard to > add a new attribute (something like __cond_context) and let Sparse do > as if a call to a function with such attribute is directly followed > by a test of its return value and a corresponding change in the context. > It would boil down to: > > extern bool spin_trylock(lock) __cond_context(lock); > > if (spin_trylock(lock)) { > /* do crap */ > spin_unlock(); > } > > behaving like the following code currently would: > > extern bool spin_trylock(lock); > > if (spin_trylock(lock)) { > __acquire(lock); > /* do crap */ > spin_unlock(); > } > > > Would something like this be satisfactory? Very much so, Thanks!