Received: by 10.223.185.116 with SMTP id b49csp672920wrg; Tue, 20 Feb 2018 06:05:29 -0800 (PST) X-Google-Smtp-Source: AH8x224/6B85jo7/BzjkrTxqU08dELeCI0h+9zn4YWyMFVxPAq5t5Nke2TF0MnQ78CejQ0H+kFV9 X-Received: by 10.98.211.1 with SMTP id q1mr17188550pfg.199.1519135529430; Tue, 20 Feb 2018 06:05:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519135529; cv=none; d=google.com; s=arc-20160816; b=1HOTY6dFVDYpKJEFEpmk+iqweT5XOL9cIJDxqXOtHoR/dpyNul+v/cAZrxhk7NuyFH 2rydv7S11Rp8Xu+0XMxaPe3n+6dgxBjEpSarrkzunbJM8CF2aMjUxmIRJOLAszPVBXp5 BLbPnbyim/bEEIA6x/JbEpUkOpIWAX1o/SNb7PEynpML6GE6iItOPX8is5UkJBZjUCDz 6xRwMNw/yh+yh7aNa1sH7myNnSh1q1xRl+ZQq+tZ5Zv+rnHdGpSwgfo6w+eSEdPMn61u KYCOS/GaWKoWYqpfLF2Pp4ARyff0szLeFspatBODAO0i5OBnAOKPdUa1EKjmLJw4h5rr H6zg== 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:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=QGWJhBBtCfWZuzKblDWH6es4tvThfupmfq/eQcdX30U=; b=PG3r43HKxhWKMjnPB6BzDZ4R4W80NGeXlsaJqWrl5m7ln1Kl5qfzcwcAPOZCnTaG7b mJArKSvLHKNc0TeT6rxKxpA4Lbvx6zQr1RnwEukaAdZe0mzTvzEOAPGmmpFz1b1iqlvj JEKZmrfZX5Iy935mBTSgiUWJxBaTOtoMSrZowteDDzAgDYCAJ2MQ5e2GoiRtt2v5BCH/ 4TePpxczkt9kqaWTH7onj0Id5vqjZr4O7vPNV9lYVJr2n8f6VdPXLXOe2DTe57rkOf7X m48Rf1kSsSQCkpBsN3wLxZj5P6e77lzQsq10LB59lrSH+ahaflRkO+T8L3jXqHLaavYX JybQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=jIILPu56; 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 a82si1914534pfj.256.2018.02.20.06.05.09; Tue, 20 Feb 2018 06:05:29 -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=@ffwll.ch header.s=google header.b=jIILPu56; 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 S1751517AbeBTOC5 (ORCPT + 99 others); Tue, 20 Feb 2018 09:02:57 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:43174 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750985AbeBTOC4 (ORCPT ); Tue, 20 Feb 2018 09:02:56 -0500 Received: by mail-wr0-f194.google.com with SMTP id u49so10042963wrc.10 for ; Tue, 20 Feb 2018 06:02:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:cc:subject:message-id:mail-followup-to :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=QGWJhBBtCfWZuzKblDWH6es4tvThfupmfq/eQcdX30U=; b=jIILPu565pUvu4VEpNnYq9ICK1djGnS/zFLjmNWs4I2TJFDnmALty5j+C9lFNJYoEJ Q+Zj3EVLMIFWYwjyNX4p+TaEQxXaE7qFqHUBiB4/aflraG2H5YTuMKmKVbJ3RYiY4+uv mmWS3mNE+oGzg1mcqxb383gg3314C1jVyA4r0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=QGWJhBBtCfWZuzKblDWH6es4tvThfupmfq/eQcdX30U=; b=KKz4qNkvOBXfNSKNO5LTv6z9iEDH9TvZzjkvCuxzheiLO9vxiz1EJ52d0QjUpu+gTY F5AqlNJ6ZkY2IpzOh4HpnDV5vVtsD1MZl9TMKpQECNLXcU+gziQJ5RF5YvAWq7Ig7zbR 7PmB8L3JF5exFkRFsn+JodM16f4OCgaRCnmfwX+ovODV2P+SMBZ3hPYUxViM6+1H5lRB CYidGHSblLFW4wpR0KqcR3qZDYm30sbdJYVq/iW90I0UeZbe7MOKjaPOs1ZArNqjdSis CqhLMg52EnvLxBeUAkMm6r5GwioBYZJVPf3r5fWiQU0stneYPMLejLWhcV3p7XbUJ0tB OKMg== X-Gm-Message-State: APf1xPBZy3PVZwiOb/qlF/jR+PImndF5MbfjAHR7r7E1fXng9YQ+WDis AzUiiOtszC75i13BS6zJb9HGEg== X-Received: by 10.80.148.101 with SMTP id q34mr464337eda.70.1519135375138; Tue, 20 Feb 2018 06:02:55 -0800 (PST) Received: from phenom.ffwll.local (212-51-149-109.fiber7.init7.net. [212.51.149.109]) by smtp.gmail.com with ESMTPSA id q19sm7770970edd.86.2018.02.20.06.02.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Feb 2018 06:02:54 -0800 (PST) Date: Tue, 20 Feb 2018 15:02:52 +0100 From: Daniel Vetter 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: <20180220140252.GU22199@phenom.ffwll.local> Mail-Followup-To: Christian =?iso-8859-1?Q?K=F6nig?= , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org 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> X-Operating-System: Linux phenom 4.14.0-3-amd64 User-Agent: Mutt/1.9.3 (2018-01-21) 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. > > v2: split amdgpu changes into separate patch as suggested by Alex > v3: change logic as suggested by Daniel > > Signed-off-by: Christian K?nig > --- > 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. This is a bit much how and not so much why, but I couldn't come up with a concise text what was materially better. Reviewed-by: Daniel Vetter > + */ > +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); > +} > + > #endif > -- > 2.14.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch