Received: by 10.223.185.116 with SMTP id b49csp830986wrg; Tue, 20 Feb 2018 08:33:13 -0800 (PST) X-Google-Smtp-Source: AH8x224CGjY7Y5ZbxoaihjsNanUZzBgUQG1VX1Vj/nawu8hX7qZiQYmwDpWJnDje/JMzh7wbV1VE X-Received: by 2002:a17:902:724b:: with SMTP id c11-v6mr181201pll.352.1519144393259; Tue, 20 Feb 2018 08:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519144393; cv=none; d=google.com; s=arc-20160816; b=hPESTZ6S60WI9T3tAQo8JeQM+kotYblAmyB7D+ZPzIWjbJ/eZuxN9332WOZ5Yla4yL S3WCCoM72rlTT+WIp0cz6DDLPSBgDWgZ/olW3rmeiGQ5mBk80JyAuerhlnZEHlXbTpnM r37NZXOZydtVbdHLWO3jvIeegiD9IOBbYt8DbRSe65jnhmrXbnAXdBxtim2BTIJukhdB VkflmEoxtBDM/bk8u1W57fC9CnfcjHtT2nhyMwxesA97AcchM8anKeMtHIwIQp/bbuaf fRWz6JIK5d5sSvj62JfnUpHl0fwYHtxf7dviRBMywbhoRhefrvi9kALFkNc5vljNtaMm EhdA== 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=7w1hESv//BppU01jH5N+LEODMCKbiF/Uhs1j/tKmlVg=; b=DBBbpk8ZB+nkP2d9/refPsfVmQeyyiNgZ/0lJTOgbeE4fqXLOmTVJTnCsxNLICEbkP QOVFzb4a68105Hy91gmPw9pYEgKon77LnDmt7cQDO+SIXjOHELheeUx+mdEHKykCiLul KTfTtcvmHBIqnMZJLIdSSzjm/pFlQ3jAF1LpYawfLHDsoShOgNEfMcFltUrsypMv9HIl qN9udYvPV5egwllD+LkkK+fHt/n5MvJykSDq2apSNCJnTdl2N2n5ddxG/J1nt8S6gmEN ko89W/nSJJnBc+v595FRAvkz8qSFxGco4Z06FibsJ1yQ9fhjgl39OYf5ffizdKWrZkDv FbKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=gdYkfIvX; 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 x7-v6si879727plo.351.2018.02.20.08.32.55; Tue, 20 Feb 2018 08:33:13 -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=gdYkfIvX; 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 S1753260AbeBTQaW (ORCPT + 99 others); Tue, 20 Feb 2018 11:30:22 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46502 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753064AbeBTQaU (ORCPT ); Tue, 20 Feb 2018 11:30:20 -0500 Received: by mail-wr0-f193.google.com with SMTP id 34so16078781wre.13 for ; Tue, 20 Feb 2018 08:30:20 -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=7w1hESv//BppU01jH5N+LEODMCKbiF/Uhs1j/tKmlVg=; b=gdYkfIvX1TVTXUTOLZyfB53O1OLd2fVEebpQfQmZjFeVPo99L1I2g9b92KBlwdAz6L dzL3X1TkIUyDb6cTdVBJcHVfmPQ2Jw3rmMji/jEqBDOm2iweeXkGx9FRnS+S0Lonyqsv MSIxzvMKlvk26bxRsL+BD5RoSEfe2ig9e1FgU= 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=7w1hESv//BppU01jH5N+LEODMCKbiF/Uhs1j/tKmlVg=; b=ZWwss+oW2uEqTqCLX8wIT9P5v2eIKF1RGP13gRMZxVtVKPVMI2kI6RteJk4h9ojzmz ZWp+VKna4/+796626BF8UqSusTXkLCnY7X+6M6PaUEIc/HkURZ9Co6KkhvpYs9RRN6Hf 8vJstYIfB4avNMDWKkuzSoM83neUCLuR3VbJhhPmITvqdLZ9lNNq8aM/FfQ6jedHLzjl drXG+CwzTH5cB475wADILVrSasTnij2bHrdsEKrjD60ZINGZKaEKwwN8/6Gr+ZqolDZb 7CEyq/VLM6xMvCnwar45O5ugEeGqgjM1ySW93RwLaPfUBksI0V0uIrj358oZlvx8xmpQ 9cJg== X-Gm-Message-State: APf1xPD+O7eKKrkNEMfFr/9kDD4Le2Apex4TOvyZwwy40zWCAgpNs0Py 462ksn3noWYyLr0CdZ0FrXkyWExm X-Received: by 10.80.151.39 with SMTP id c36mr1060140edb.3.1519144218913; Tue, 20 Feb 2018 08:30:18 -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 s23sm21415081edd.6.2018.02.20.08.30.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Feb 2018 08:30:18 -0800 (PST) Date: Tue, 20 Feb 2018 17:30:16 +0100 From: Daniel Vetter To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: peterz@infradead.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] locking/ww_mutex: add ww_mutex_is_owned_by function v4 Message-ID: <20180220163016.GZ22199@phenom.ffwll.local> Mail-Followup-To: Christian =?iso-8859-1?Q?K=F6nig?= , peterz@infradead.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20180220144946.2510-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: <20180220144946.2510-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 03:49:46PM +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. Ok I think with the increased guarantees this needs a better kerneldoc, I think we need to at least add ".... and not locked in any context, i.e. acquired using either ww_mutex_trylock() or ww_mutex_lock() without supplying a &ww_acquire_ctx." I think with that we have a nice 1:1 mapping between the context you supply to the ww_mutex_lock function and to this one. That means generic code which takes a ctx (but can handle NULL) should dtrt no matter what. With the kerneldoc augmented: Reviewed-by: Daniel Vetter I'll probably regret this r-b too, but hey to err is human :-) Cheers, Daniel > + */ > +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; > +} > + > #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