Received: by 10.223.185.116 with SMTP id b49csp3556746wrg; Mon, 19 Feb 2018 01:58:17 -0800 (PST) X-Google-Smtp-Source: AH8x2270SYefUM7RR66k1CUUvNV57NZlqw459tiAjNEVDRdSAtOXrYOjpvTcc3nmUOlqZssiSjK6 X-Received: by 10.98.186.20 with SMTP id k20mr11006239pff.170.1519034297837; Mon, 19 Feb 2018 01:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519034297; cv=none; d=google.com; s=arc-20160816; b=PQx7U7gdxNDXWmkmLY+ZOYY/bh7PgM/j42i/3qQYjOE5upEXIB3NZ3NbnErI0USAWF RihNfTCfnFgCXFoERcLyQCIw8/nbnK7lyA/3SJ4gxsXkwG3Z0fF5GvJa8TNRV5NAmhqz JadP4WJFC/gIVZZk7lbXSwpLGQFW0mP42ufzKD/zWp4wteh5g2Wt7+nPjz1/CG5CVXtF xPUoEr42cyVh3ps2sXdeRHWX7bCppHWY5XnRNBllhKBLu2/XnAVaLKz5qUf7LUN/81Ps x8lX7Z2ykjIG2/Kxg9dXXhLw8tGbLQEh9X3YU8TSSrc3MBhJtJ1nvGlPKUA8pBqe19CG mg3w== 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=KlSbjJ95uEjwkxDSRhEBsGxkYwN3kslL0BHO94Q+aoM=; b=ER95I8NIyTbVmHyUZ3tAtYk00c38B0tXoUV8yp/cf+SQcKvEzwuICgaRPkAg0xTFQ0 hhBMu3L2xr4H/UDspB2iyeFMyrZdyVPwJCVLSoG7OMW/MpP+k7vwDx3DY0pcJxA4PYpc XedFokeuhdV0DIj2Z74Z4F3gO1iKRExzGuKfdF9R9UcgJJsbVumVSz1prJK3NfwgsU39 Wo0banL9CeYy4VVLW0dAO7IDymzEUJ3rr3+0b/mIE3+2Um6pNvw0Tnmvie8UilYcwT1K Utdk3alUqTXRV+g0+ZUmS7UovdUEAZjDMpnv5SSAM929+bz+KL+A3vRz/5PmiRBphmIk 7tpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cDuiAITW; 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 t199si5011325pgb.105.2018.02.19.01.58.03; Mon, 19 Feb 2018 01:58:17 -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=cDuiAITW; 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 S1752453AbeBSJ4O (ORCPT + 99 others); Mon, 19 Feb 2018 04:56:14 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39401 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752335AbeBSJ4M (ORCPT ); Mon, 19 Feb 2018 04:56:12 -0500 Received: by mail-wm0-f67.google.com with SMTP id 191so6888395wmm.4 for ; Mon, 19 Feb 2018 01:56:12 -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=KlSbjJ95uEjwkxDSRhEBsGxkYwN3kslL0BHO94Q+aoM=; b=cDuiAITW7WXwTZJNLp4N5k9pBZZX0RPX8+qj+lvS3IOIt7wRpWwxOhEWgLvAg1g1w1 WDFemYbVEfmLNKIaZs26RBhKZ3Zv8EmLS7+PiemrLXBxhfdACfhLx0dp1VAW3szrcgr6 KW77Fpv8zZUrkReRqOjP+N2xlvilLEXPNOn2RYriZ8Ij3oH/UugGi3jaafeFasi/FQZJ h1X6SX0jH4yyxq85ri9RGoiPNRvT7cjHSGBxNW+We0I//jz89e8L41fAKP+kYUPp/kAO h0TNaOYFbFKdCpbZzkbcaaopdi4B42uxFvDqRwr5cDJOUKd4yhQZxAvCpGRQcgOQg8E3 fF5w== 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=KlSbjJ95uEjwkxDSRhEBsGxkYwN3kslL0BHO94Q+aoM=; b=h8SIkMRUcnqKEddeuNC/N9XDF8SzP42JJAOIFP7Ou3knUIH17AIEsbCzCcR/2TA+g1 9iZ1OZadXPkNbFZ++3qmWJUuKi3b8D5YTRZSVMcdln0apeoGHp36arT6nbr0zREU7p/Q b7HgeQvWmr5wcAWYYTi8n3biMwxLG+w2smD9IY1H4hrdDOhlcQcZqwPXLRKzoNGADQDX 9/Aue1FQL/mjaLPeUkbl+oHXxAok9IV4Bxciky5e8YwMMHbRLVHgdW5P7lh122IgFuLX 6gixhNRcl69HqYSBI98B7RaxORBZKFNljZJJKKkQ4yA+3+OXdKNxkVlzszCCpd1jhQP5 HXXA== X-Gm-Message-State: APf1xPCpt0ZIPQkdghNx4JDqPya2TM6bdv82KZ49dEaknAc91RfZqSed mVYfdtjtXsT7LL/d0422TO4= X-Received: by 10.28.146.141 with SMTP id u135mr10548285wmd.26.1519034171588; Mon, 19 Feb 2018 01:56:11 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:9533:206a:c0b5:3ad7]) by smtp.gmail.com with ESMTPSA id z74sm22309976wmz.21.2018.02.19.01.56.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 01:56:11 -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, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 1/4] locking/ww_mutex: add ww_mutex_is_owned_by function Date: Mon, 19 Feb 2018 10:56:07 +0100 Message-Id: <20180219095610.2747-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 --- 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..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