Received: by 10.223.185.116 with SMTP id b49csp2083601wrg; Thu, 15 Feb 2018 06:21:04 -0800 (PST) X-Google-Smtp-Source: AH8x224MkDP5Q4UKl3ny0F7p0JibNVq6dyJWwcREBQ3Yya78MALc9tDZBnA9+W3qZtmvZQ957Xm8 X-Received: by 2002:a17:902:788e:: with SMTP id q14-v6mr2725331pll.396.1518704464139; Thu, 15 Feb 2018 06:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518704464; cv=none; d=google.com; s=arc-20160816; b=Toy7SvfhoScG40rD+Ao9b2cit9CnJXFUqZvv+aoO6touorSybuxlY5RZh3g5g3V1RD EbcmcmvJ5fklE5BUUNtEC/61YCxfTt52GcP3/50NIlsOn3vPFumo28shHmGx32iFvjDn wwcLYkY/sN+o34heOnTK5zTjE8Gc1epFSCErg6P9w2QzkQMVqcnxaV+vyZ5f/ARlv316 R9oGC9A4fin4qKzzqQuLxBTqxA3i68scB9m0xfDM+v5FRt9a0j+3OBHnledPjS22yFHf Eg8VAs8tdY74/iA7/hdQudSm5QQ970L0Q3QyG595tVZls8MognSRD/18cds/4pABA+MT s9nQ== 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:mime-version :message-id:date:subject:to:from:dkim-signature :arc-authentication-results; bh=Eim/0zR83eNQwifirz5xjHVTk75oWWjb63kaupb636I=; b=SZCABFLeiDhIG3wU0VM8NwR1L/HuVZgAKo6vHgmdMrUkoNUf48/faBx2eLiCOr37/u 39THC8at9PeVDXjwgPh4QbLEDV9PD7XidC6PFYOtxanVsL4itwQ24Pnjd4ie06xFJGIA bx3B0efuDOriVRif7nxj8EentaZUPuwWxtr+M/2SAJJhAwG6ub4H1NaHmLZzemBHSVtH 9f5oTmZD3QorvZuUlkaEffj1EkCsLB/sZhYmBhdSDZz8IUiB/bPeRWJUVRPT/xvqHoVI yYwL0EerspnKmK5vGM6zbFxC5Q7nVvQd40+K3B25GDJsBsnCJV8srrGal7SZVN2v/Qgp yZrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Hj6/E9Q3; 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 q13si1343630pgp.262.2018.02.15.06.20.49; Thu, 15 Feb 2018 06:21:04 -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=Hj6/E9Q3; 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 S1033152AbeBOOTs (ORCPT + 99 others); Thu, 15 Feb 2018 09:19:48 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:45648 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032879AbeBOOTr (ORCPT ); Thu, 15 Feb 2018 09:19:47 -0500 Received: by mail-wr0-f194.google.com with SMTP id q16so1721214wrf.12 for ; Thu, 15 Feb 2018 06:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Eim/0zR83eNQwifirz5xjHVTk75oWWjb63kaupb636I=; b=Hj6/E9Q3G1nt1D4CJ17MaQQMFQ5g4YpLJZsD3CIQOnAH6X6eoLHY5RIXVPOijvRaC7 QkDlH7yqVMWaNM1TUFIvJ6H1iovqnhNtI9XrDUTTOmzFVgltlI61MOFQDzgVOygtqcqE 8F8pb7AQ6HWz/czheO5wkozLNtBhHw64EvSppc0tsHNiUtaJNGtkPd+tk5mw3yG6Ogab PG/Ae0aAh01f3+Ys73etIJon3CyXkO68tw0mFuOFT8IVpBEy3ObzaJX3zTSHbKS7RIAf zJNU6ckJPfoCR1Op4mrWiQT7HpsaA6hqBHtsKx8ZQNuvUcExDpraT/LFC4iEq9pChoc3 FQDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Eim/0zR83eNQwifirz5xjHVTk75oWWjb63kaupb636I=; b=LI+bB9CD39mkqbhKIj65yxY7kjf+4Q8korK2x8d5NAv+c+Ee8SLBGAlMWt/c1XFaVZ eV3b1CbCvW9XYSXe+SZG9Ah+uMdvhNZF8i88l68Z65bNe7bn9mGa6yiFpBk0AXaVOIA/ 6EtwT4/yJsggiI+xGpo2kbvdHneY8yvNzx2CI2/33Qa5l7KeoKLkKLquaE/ui6+uPGw+ 3Ta1gtGQbpLp7KyfXIJ2pZLxxnGSkUHtRbXAlFIURLr0lJjjCxD1lIEc17BJgU9TlCFI DPDz5ijQtLw0m3OPC/AP68oFTQM8jQJfLvtrPeorV0zXV8IbJEk3dtCiVvFYxxWxVMQz GWvg== X-Gm-Message-State: APf1xPBO8YNd1TtfubuVFcpBUyhtrAtuigXGBJvnjLkYKtIKCdIpqnK4 BKIb1cBAfHJqCWubriBkokc= X-Received: by 10.223.163.215 with SMTP id m23mr2844434wrb.90.1518704386213; Thu, 15 Feb 2018 06:19:46 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:3595:2adb:15ea:f8af]) by smtp.gmail.com with ESMTPSA id 19sm27382433wrv.0.2018.02.15.06.19.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 06:19:45 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] locking/ww_mutex: cleanup lock->ctx usage in amdgpu Date: Thu, 15 Feb 2018 15:19:42 +0100 Message-Id: <20180215141944.4332-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 = mapping; /* Double check that the BO is reserved by this CS */ - if (READ_ONCE((*bo)->tbo.resv->lock.ctx) != &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_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 + * @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) == task) && + READ_ONCE(lock->ctx) == ctx; +} + #endif -- 2.14.1