Received: by 10.223.185.116 with SMTP id b49csp899430wrg; Fri, 16 Feb 2018 08:58:18 -0800 (PST) X-Google-Smtp-Source: AH8x224EdqR7qZiXOvGGBhXKVso7rTSwjxk46GxEx1/kg0qIgk989VISISc8dJffZGooTzGzAo9J X-Received: by 2002:a17:902:a585:: with SMTP id az5-v6mr6481388plb.167.1518800298394; Fri, 16 Feb 2018 08:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518800298; cv=none; d=google.com; s=arc-20160816; b=0ODI67dWLGvfU8/IZ2shUM0KxcOXc1lSAxnsdMtgTWNtLfy8E7X8Yc0FxE8Gm5TAgx mHFaRifwwKu1VoorKwL4dnrJ1KdW7CPF8S+KWQ2ZI5qPVOCPIMFwapUFaaEmTvQGerhy M+ELG7HgaGd98aftZxCXqYmwVxmt+LcuqbhxNMjePVMal2HBlsNpnTitecaaSmx1jUNc dFuULLFPNb/QCQoZPl6yWTZEYeU0WSYGl5wtE6Le/t+xpQp+5mIV7uJ7tyWcePQlINAE aoahh6YIfG+6FjsO669BmNjnVITVHiCnon3rY+BjDx7jAh12WSUy+m4kzlsvRLCgunCo g8EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=lmoRuDRopz3YPSdOISJxVxhopj2V3AKRYo7L7/Guzz4=; b=Vz3XuIV2ZTNwY3FgGrJCkrTB9j8qL/xCWzjPEwKAZpqEiC7tyMzbZT1EydKEgrd32i WyHtGFdlo0KuWrVLApL5iQ8J51do9iSKWahl8J2z9YP8vaDzsExswgARjQhOEEr/rj+V sH6nbFQe0OBXY6rqdP09YP6GDTtiqsVDCgQ9z5J044BPbsHFnepWXbaB1OrPZJaEUNa/ 1wYXs5YUDlXCXuPk64d+zTEnYy//x7y8ifWCJ3+hw1CjVxii/z1Pa3yLWz8as4PtoqKt KFvXsgBWCMx/aar5L2THlbjjVM4/tKa0XLEdBzx0X+Wt8fHIdWEL6vgyJagr6gBRxUvV DuTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MbaIcb3f; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h73si691855pfk.231.2018.02.16.08.58.04; Fri, 16 Feb 2018 08:58:18 -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=pass header.i=@gmail.com header.s=20161025 header.b=MbaIcb3f; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033580AbeBOUgK (ORCPT + 99 others); Thu, 15 Feb 2018 15:36:10 -0500 Received: from mail-yw0-f195.google.com ([209.85.161.195]:35988 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755821AbeBOUgJ (ORCPT ); Thu, 15 Feb 2018 15:36:09 -0500 Received: by mail-yw0-f195.google.com with SMTP id t129so693962ywc.3 for ; Thu, 15 Feb 2018 12:36:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=lmoRuDRopz3YPSdOISJxVxhopj2V3AKRYo7L7/Guzz4=; b=MbaIcb3fEFLufnCE4utYD55nN1slR0E1hM99Nhfyb98TExzm6Di74KpF83N/yXJfl6 NX2tJHvfBT0yqby6sFnHMgnnj9yl+3IzJewQR4AE62Zpk0nGJqQMKfY26F0vyTNPFzWD s+VIinbs83a9KlabTSby77BSKO34VT8vbcIJDBO8QWoQRLQPXFsvFIbqpz6d3R0Jxu6z ftXRcy2sylCMfC1FXAK1KIHadO1S6R8T65gGOheLwGgq/6dezExu2UKZvqvOPtia5NZb nQdXWblNPIxiX9zH31V5waMdRcrhUY/TccUmDf1p+ZAitn9kkcfLk8dA/QPcsTEHXRHZ fQIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=lmoRuDRopz3YPSdOISJxVxhopj2V3AKRYo7L7/Guzz4=; b=BG3Fzke48qkKS6TLCA4OKPjJBZdIUl52ScxKVH0h7bEnxJ9yOgvjls2KjudDX4Fh7y OnfRqBwRMs156yzIl2O4Xb+2Tvv6FDDPn7X8O9qTxc+sWxioulGw4kZsaaaY9fWppVZW z1tEQRCKKFJnFOCb2TEQXT0MmSRs8d+nSPILBT39snXVDfs6xXorc6ieLOPLeD7KpK0Q LMioFrQ+miJjz8+Ac6+a9btZyfFDc1OyK7wxZ0ykCg/yTJoCSuS319TTnx+PNVnJfTWi tSYL9w2otTydB2Jv3zzzrGQiMYspqqi+/5vd3uBvq/oGv5S1I4/2e2Oj+3lRDBzHaQl4 kJwQ== X-Gm-Message-State: APf1xPByitGFwRSkSivCQxaNb+UBOgm0s6mBceOle9nvPKn0WLpy5HSF wo7Jbj/I+RcZWjE7BcMyaZpc2A353Jp86GeXQHM= X-Received: by 10.37.174.19 with SMTP id a19mr3104387ybj.87.1518726968420; Thu, 15 Feb 2018 12:36:08 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a25:6785:0:0:0:0:0 with HTTP; Thu, 15 Feb 2018 12:36:08 -0800 (PST) In-Reply-To: <20180215141944.4332-1-christian.koenig@amd.com> References: <20180215141944.4332-1-christian.koenig@amd.com> From: Alex Deucher Date: Thu, 15 Feb 2018 15:36:08 -0500 Message-ID: Subject: Re: [PATCH 1/3] locking/ww_mutex: cleanup lock->ctx usage in amdgpu To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Maling list - DRI developers , amd-gfx list , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 15, 2018 at 9:19 AM, Christian K=C3=B6nig wrote: > amdgpu needs to verify if userspace sends us valid addresses and the simp= lest > way of doing this is to check if the buffer object is locked with the tic= ket > 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=C3=B6nig Shouldn't this be two patches? One to add the new ww_mutex code and one to update amdgpu? Alex > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++- > include/linux/ww_mutex.h | 17 +++++++++++++++++ > 2 files changed, 19 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd= /amdgpu/amdgpu_cs.c > index eaa3cb0c3ad1..4c04b560e358 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c > @@ -1594,7 +1594,8 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser = *parser, > *map =3D mapping; > > /* Double check that the BO is reserved by this CS */ > - if (READ_ONCE((*bo)->tbo.resv->lock.ctx) !=3D &parser->ticket) > + if (!ww_mutex_is_owned_by(&(*bo)->tbo.resv->lock, current, > + &parser->ticket)) > return -EINVAL; > > if (!((*bo)->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)) { > diff --git a/include/linux/ww_mutex.h b/include/linux/ww_mutex.h > index 39fda195bf78..dd580db289e8 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_mute= x *lock) > return mutex_is_locked(&lock->base); > } > > +/** > + * ww_mutex_is_owned_by - is the w/w mutex locked by this task in that c= ontext > + * @lock: the mutex to be queried > + * @task: the task structure to check > + * @ctx: the w/w acquire context to test > + * > + * Returns true if the mutex is locked in the context by the given task,= false > + * otherwise. > + */ > +static inline bool ww_mutex_is_owned_by(struct ww_mutex *lock, > + struct task_struct *task, > + struct ww_acquire_ctx *ctx) > +{ > + return likely(__mutex_owner(&lock->base) =3D=3D task) && > + READ_ONCE(lock->ctx) =3D=3D ctx; > +} > + > #endif > -- > 2.14.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel