Received: by 10.223.185.116 with SMTP id b49csp621934wrg; Tue, 20 Feb 2018 05:13:54 -0800 (PST) X-Google-Smtp-Source: AH8x226I5fAUsHQXfD+2J9e49bnmmgdjn/PWe4hwDk0ev3qZNguoNc55YFPlfyAbK5jgMEaXTUqF X-Received: by 10.99.95.142 with SMTP id t136mr14734044pgb.94.1519132434746; Tue, 20 Feb 2018 05:13:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519132434; cv=none; d=google.com; s=arc-20160816; b=jPlOsnjWcx1h7uvB+GMuNq0RF7vNrH9T83j/eCQ10/kQYsdcGT7Y7SrHoI64iMOzLn izL9soCvsQyxbrUOWRe8fZMPBF9CHYiV4+cB4x+gm0OGS5qeXXJ4WCdsPn9NEI3VrnK4 a/km0FxTIzh1oEjMSvvrwI1mPHES8/rDn2g14DREV8MIamv4pGkM5gm8sQd9G5Z/JldN cMvNEV2TA+QmUK8pzruhzuqiB3IR0+ySzQvghRkfJKWkNlCM5h+4syQPtkjzZHP/S+fi FXb8jcDH0iu1UxpSm035ayRFMjiu7kIx+nc7qCLpLP9ktYFdc11SAtD/vD+7gnfWDyZm MIJg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=7ni8cIRy27yfxQKrRSHUvdpdg3KPipQrdrSDFy3+MXI=; b=f/7Fewx1LBJ7+jdixNoVQlVH/+QGiHeAA/r19tYMev/RToopdbQmdggrDv5nkmK3So npjZ351EVgLxiYLP1Faqv3Wsys3iDSU1fpo6N9n3HAYh46uA5Q6OG/HwoF+XpEp7RJgB pG54aF3QtyvSKfUnA1SRm2ACIjfNWeApFxBPwkpqe2VoJymgeNP8gXDEGatHppvrqBZw 815wUsVVCaSqYXFe3UlxGkv4u4Ap3uCcYLa8PekUGhmduVszQfg0Z3BrGxrub7uiQRYz /pNv2iegJhmae0acP2DYJV9jEZkDMlWFghS+jkJkkbMc20mmqs+Jwv5gqDVxkX+rH6Pu 69gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=27L+OM3p; 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 w12-v6si2269481pld.162.2018.02.20.05.13.39; Tue, 20 Feb 2018 05:13:54 -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=merlin.20170209 header.b=27L+OM3p; 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 S1751749AbeBTNNA (ORCPT + 99 others); Tue, 20 Feb 2018 08:13:00 -0500 Received: from merlin.infradead.org ([205.233.59.134]:55754 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751587AbeBTNM7 (ORCPT ); Tue, 20 Feb 2018 08:12:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To: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=7ni8cIRy27yfxQKrRSHUvdpdg3KPipQrdrSDFy3+MXI=; b=27L+OM3pMuNp3jCgmSaluOna2f UA7zQHepajx4mXsHLfp9iLRjDAZ+PORYyyO2pGBhUGQaiCN57EDkSK/qzsQqGki+VVCkHRgyXX9r5 ZYQBhl+7b0k65sPTI0g6W+wKl1WQnXQsft/FrfF8ICH2U+8Zdws/gTbwVkLheTHbMyny2jNNETovT +XA+xdJIvzqoyGUWxf3ixmQGp63WZnXjplp3TTCQlXv16a6h7syk9bvbaq4+Xdfg60NoaAJckW6/0 Gf6ghZOhYCadHrWsALj9KQLZM/UMGgEgRgKMbEITOzDvp4caVegfUW+/IED/xcmBoQhbYz2T33b7S CkZPTokA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1eo7j4-0008An-KK; Tue, 20 Feb 2018 13:12:55 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 664CC203895C6; Tue, 20 Feb 2018 14:12:53 +0100 (CET) Date: Tue, 20 Feb 2018 14:12:53 +0100 From: Peter Zijlstra To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] locking/ww_mutex: add ww_mutex_is_owned_by function v3 Message-ID: <20180220131253.GF25314@hirez.programming.kicks-ass.net> References: <20180220125829.27060-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180220125829.27060-1-christian.koenig@amd.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 20, 2018 at 01:58:26PM +0100, Christian K?nig wrote: > amdgpu needs to verify if userspace sends us valid addresses and the simplest > way of doing this is to check if the buffer object is locked with the ticket > of the current submission. > > Clean up the access to the ww_mutex internals by providing a function > for this and extend the check to the thread owning the underlying mutex. > Signed-off-by: Christian K?nig Much thanks for Cc'ing the relevant maintainers :/ > --- > include/linux/ww_mutex.h | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/include/linux/ww_mutex.h b/include/linux/ww_mutex.h > index 39fda195bf78..14e4149d3d9d 100644 > --- a/include/linux/ww_mutex.h > +++ b/include/linux/ww_mutex.h > @@ -358,4 +358,21 @@ static inline bool ww_mutex_is_locked(struct ww_mutex *lock) > return mutex_is_locked(&lock->base); > } > > +/** > + * ww_mutex_is_owned_by - is the w/w mutex locked by this task in that context > + * @lock: the mutex to be queried > + * @ctx: the w/w acquire context to test > + * > + * If @ctx is not NULL test if the mutex is owned by this context. > + * If @ctx is NULL test if the mutex is owned by the current thread. > + */ > +static inline bool ww_mutex_is_owned_by(struct ww_mutex *lock, > + struct ww_acquire_ctx *ctx) > +{ > + if (ctx) > + return likely(READ_ONCE(lock->ctx) == ctx); > + else > + return likely(__mutex_owner(&lock->base) == current); > +} Much better than the previous version. If you want to bike-shed, you can leave out the 'else' and unindent the last line. I do worry about potential users of .ctx = NULL, though. It makes it far too easy to do recursive locking, which is something we should strongly discourage.