Received: by 10.223.185.116 with SMTP id b49csp759890wrg; Tue, 20 Feb 2018 07:27:02 -0800 (PST) X-Google-Smtp-Source: AH8x225h3oNTBD3izoHvHNqmSno1AojogGAdXGLjB3V3fZFWaPg6JGxdriIdgqf1Bf0PV1EeH2dG X-Received: by 10.98.11.194 with SMTP id 63mr9156pfl.172.1519140422404; Tue, 20 Feb 2018 07:27:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519140422; cv=none; d=google.com; s=arc-20160816; b=nUV+SHrEIcaUo9naSlUF5AE3rL0JWnK2r00NL8kb3HUkkTJAstM9gN5egfeEHIJqrQ oYeE5hzHWVQw/Ap0qGF2dWJ64pbwR779tuDhRF65iOzKv+7HoGV8EtWNeU2MR3yqvimc hNvy2UfEptuhqtkzchp9Obnah3uD2coidEiaT4IuEzBaPNtbzdsehH+xAxCweu5pTVX8 HL/AFYdoXu23SGK9mDBrrlbPIC4BcSWCb7oyOj0+KQtCqp0OGNhUhvMsGtBZ+fDhygPF 2/lTQOHkT0MTPX6KFQw5MEc5d17wIz5cDMOIBcTAxCWmZtEDDdRU5jUlbjBQU8E/Y2xh KZAw== 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 :arc-authentication-results; bh=DZT06XcNIBTFNg5rDkd+sTBziKs5PDvZgEW7YwSBdPM=; b=beEmavhrB+qbP7dZ/CYiuvSKtsIBqELXmfrBfGqyXUAYv6Mw0zIbMHEPY7TX7TGDGB 3PdhqcgpM/RTXpXUeoDzEQOQhQXM431rrKCvPuz++hr0QT+TT/AlPgJnY2y7faL+hjHU b71ayYc8ydsfHZ7dxV6FF/gPa/j8nFw3VTrBogmz/aF5Q5hVi7JotMioI+IcLOklldkc lHe7DdJkYb0gLGNHtVr83SjY3MDtUqHepFzFy+w+syGnRnqMW1akgENnSJpjXAuTdlpX R7g1+pMyC4aFX647gj+Lv5TSwrHCCJQYcmsZQogdExMEDHMEpCAeaMEez2NyRrAyVWzd hMyw== ARC-Authentication-Results: i=1; mx.google.com; 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 s19si4776602pfk.260.2018.02.20.07.26.47; Tue, 20 Feb 2018 07:27:02 -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; 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 S1752444AbeBTP0E (ORCPT + 99 others); Tue, 20 Feb 2018 10:26:04 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:62485 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752007AbeBTP0D (ORCPT ); Tue, 20 Feb 2018 10:26:03 -0500 X-Greylist: delayed 920 seconds by postgrey-1.27 at vger.kernel.org; Tue, 20 Feb 2018 10:26:02 EST Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id B8A53F3A7C599; Tue, 20 Feb 2018 15:10:36 +0000 (GMT) Received: from imgtec.com (10.60.4.28) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 20 Feb 2018 15:10:40 +0000 Date: Tue, 20 Feb 2018 15:10:40 +0000 From: Eric Engestrom To: Christian =?utf-8?B?S8O2bmln?= CC: , , , Subject: Re: [PATCH] locking/ww_mutex: add ww_mutex_is_owned_by function v4 Message-ID: <20180220151040.rmnxftdwrkooelob@imgtec.com> References: <20180220144946.2510-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180220144946.2510-1-christian.koenig@amd.com> User-Agent: NeoMutt/20171215 X-Originating-IP: [10.60.4.28] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday, 2018-02-20 15:49:46 +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 > v4: fix test in case ctx is NULL > > Signed-off-by: Christian König > --- > include/linux/ww_mutex.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/include/linux/ww_mutex.h b/include/linux/ww_mutex.h > index 39fda195bf78..fea4acc0bcbc 100644 > --- a/include/linux/ww_mutex.h > +++ b/include/linux/ww_mutex.h > @@ -358,4 +358,23 @@ 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 and not > + * locked in any context. > + */ > +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); > + > + return likely(__mutex_owner(&lock->base) == current) && > + likely(READ_ONCE(lock->ctx) == NULL; typo: ) > +} > + > #endif > -- > 2.14.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel