Received: by 10.223.185.116 with SMTP id b49csp606941wrg; Tue, 20 Feb 2018 05:00:49 -0800 (PST) X-Google-Smtp-Source: AH8x225r13jBIE5gunFwyl/Ha2RTK6HEKIgSaRd36LC4hNsmgp51ZYEvZOH41IWOi+pLtRyy/ASK X-Received: by 10.98.105.199 with SMTP id e190mr18082445pfc.70.1519131649796; Tue, 20 Feb 2018 05:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519131649; cv=none; d=google.com; s=arc-20160816; b=lTMEqYvVRFGsjtRHze1IbJYlQYe9Y3nGFtHZwelVsoyzEX6Qd8Wdiju8vEeXiZz0Mb tBWqOeePeU6UcMNOPzFKeJGj5yDNKDgHN1WhLjvJf0O/B/RhFM8ua6f7YPuFxjs+y2GW S7GeqTxganBnXRkMvO0UVVgrPcbRWlWjikRPLjgymC6foR3wB7qrE2q2cPbj/K+B/UUl s35aUYDJ+P9zIX933lV/DerW6kJuUUE8pkR7E0YV7q/chLiXVZqkZqeProBb6z8Kmoy0 WioMLNPsRmyQDTtouq7qITYIQK2y7XwuJUqn5HBjvS5t9LO+tUgvZZDM3A70Ob9Qy1SY 4sIg== 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=hjfDMV8VULoxdmCvORSw+iUr1yC0LpeXWvlanbu148k=; b=Yhvjm02sk/k6Wul7K+wmw5t4LkwBT/dTGbkc6ngRtpVAUEeIyH0Ileu0zCqhU92W8C 5fKCNnGN2hZ6+4CbvKrf5ng4ZK+g2wnbsf6h4PRBRLZ0xX1G/G6nHa2d6ewfn6nJr6qo Wbkgn5SEMlyrt93+AiWZFJMz0ijd1trF/Rtlaop+YQZSuVOOmocHdAPLDRtkoTcLNu0R Yb7liFUwHI2GZ5ASzNq+pP/9OELhpzddyHZ/gy0KQzjsPX3POMt3QxT1jR9rHm0Jwkp5 +zqr0glS+0j7D95QcBOfbeoJwcZn5mDpi7mbwPS8KPB1g6cttfc+8i+IEiAc1MqzKWvE 53ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cAla5aas; 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 w10si10497820pgr.136.2018.02.20.05.00.34; Tue, 20 Feb 2018 05:00:49 -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=cAla5aas; 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 S1751878AbeBTM6d (ORCPT + 99 others); Tue, 20 Feb 2018 07:58:33 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39396 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751712AbeBTM6b (ORCPT ); Tue, 20 Feb 2018 07:58:31 -0500 Received: by mail-wr0-f194.google.com with SMTP id w77so14095524wrc.6 for ; Tue, 20 Feb 2018 04:58:31 -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=hjfDMV8VULoxdmCvORSw+iUr1yC0LpeXWvlanbu148k=; b=cAla5aasgM8nKGly8KjsBq3ePVkqO2+jm3GIWo6dzTwD9r4mgT0H2hKoX0b6kS/sOx qEXCaCDRDjLTtNqwrTiX2O4YnlgXyVMTvmATc9NWC1ijjpOR8cmvdtgEgnMpc1WJDBXO n8bpsHVEEJYsmPHer10rslOAvTLZ7MwXLcjIbipHDvt6usSgmr5j18ACJ3CM2INjcmi2 cfmSKuBhxnjLkFWq//qx4kn7aIXtkpk552m38r1YrTSFnwryqvPQoGVVyGsqYO0pGOcA l0TxyPI/hR1/YYSorpSRl+necfiMVemQTX/tO4HK66WEiuMftCIGrTWEQGk3wFdTqXoj s6yg== 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=hjfDMV8VULoxdmCvORSw+iUr1yC0LpeXWvlanbu148k=; b=qlERq2jlVu6EzS1X1whYecgCbpSQmsuKm0tr313Zw2ixz1gChPiq4NmEYFXE8uOzAo OLVgQsDtuo9Zx+HGwnm7q+K8O5OaUzE8ElMARuoKiIeQXsQwb82NmU85ZxUeCi0MKlFN 9xDircEtmAHrUdCKWxtaWBPMDJtlocPBUpWyLt4Mv/ImRipMKl0L8Tk5zsHT1bM4jkQ+ mb4JAgcchluKF8yAYf0LD7d+a7OKwWwuXGIh+LOQ+VxGBG9iHpFn6eVUSGXFtQLNSxXu r7oOql29DrzPf+x3sEF44sPPvauS8b/f2tdTTeH6Qcpmud47VK2XTM/1sVEtRpKx44zW /+WQ== X-Gm-Message-State: APf1xPAwcXHHFvFDFHHmS5ZNAiGfgRuATWSpI0RbpukpOKN0ZX2AfuOh qvx0T2GVDWGc7z7tIMD6spY= X-Received: by 10.223.158.193 with SMTP id b1mr17240627wrf.156.1519131510856; Tue, 20 Feb 2018 04:58:30 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:7008:2819:5c1a:982d]) by smtp.gmail.com with ESMTPSA id 32sm24179502wrm.14.2018.02.20.04.58.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Feb 2018 04:58:30 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] locking/ww_mutex: add ww_mutex_is_owned_by function v3 Date: Tue, 20 Feb 2018 13:58:26 +0100 Message-Id: <20180220125829.27060-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. v2: split amdgpu changes into separate patch as suggested by Alex v3: change logic as suggested by Daniel 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..14e4149d3d9d 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 + * @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. + */ +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); + else + return likely(__mutex_owner(&lock->base) == current); +} + #endif -- 2.14.1