From patchwork Mon Feb 19 09:56:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10227345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96749602DC for ; Mon, 19 Feb 2018 09:56:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8888F2884F for ; Mon, 19 Feb 2018 09:56:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ABA72897F; Mon, 19 Feb 2018 09:56:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 125D92884F for ; Mon, 19 Feb 2018 09:56:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 99D5C6E054; Mon, 19 Feb 2018 09:56:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 58FF289F8E; Mon, 19 Feb 2018 09:56:13 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id k87so13972703wmi.0; Mon, 19 Feb 2018 01:56:13 -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=DXjVS2wnz6PsEVqDGGU/VmleVDRNc7UxZWvu1Du4fPvkBj5CjGH4V22l75gM2gwFr6 HMaAraPBcSTRNoGWPk9sGl0mb9W9fr5wnwtjYfARc/9hPyBRd5n+BMHy+lnRXvayBsJT Qgz5028eogWKFLjFMw8ucaXuKMDkNx0VDuI78+u6N79ycUXzjKGFzIvq/7N6EkBFtjXM q8ag9g7n0SVPn+ZVlbLXJff/B4ltljwTJs+RMHP883VMbC/8lOR8RzW46UZ1NEP4nL7r CkOQ4QnmbmlNmagpfeqtsM1hG4MV/N6qALHmUrnjAfYDf66Yuk2nF2mikc3dgxLFhH9H s2fg== X-Gm-Message-State: APf1xPCT5vAkhZl8nYVZRvrv1GFEJ35vdI/OslH3YOJayBR/AxLkaTzN nVkT+zjE0W6DPNs/xrL2Ix5bEQ== X-Google-Smtp-Source: AH8x227TDge1jKAv1tD5Oi5pYa/bj3AArKmwYUu4IUD0RcLCdp/il/fSLKI2IUk2u/Bh1LA0axNcEQ== 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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