From patchwork Tue Feb 20 12:58:26 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: 10229997 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 F2D78602A7 for ; Tue, 20 Feb 2018 12:58:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E179E28464 for ; Tue, 20 Feb 2018 12:58:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3AB0285B7; Tue, 20 Feb 2018 12:58:34 +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 4B48C28464 for ; Tue, 20 Feb 2018 12:58:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 306CD6E3EF; Tue, 20 Feb 2018 12:58:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 613E26E3ED; Tue, 20 Feb 2018 12:58:32 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id o76so14093246wrb.7; Tue, 20 Feb 2018 04:58:32 -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=hoOnD1nPzYW5z1Y0mC3+zXF78Hr0ZSYTx28rkDI7hTalHA4/XxKmsZpbK5xaVmnGOn rc0ejrSzftW3qOuLjOA5v2DfvUIw3nsKbwxngVgcxVMycTcwn/7vqWD6c+gJvp1LdnxC iReRFtodnze6zuYlpangcYa3S/wVqcMdMZHnIQn9bHhkjbgConKkVZaAuNI7i0AHKg/w DhXgdWgyjFLpDpYBbUDbhpkT3TJ2oX+4fWzxjZ9dCm4GPeBsdXvgZJtaMDhdVcas2FFy 4JsoJqqQJzRNVwYGIhiNdQxMdNKtKQHX47cBjTpX/wpyAzo8gD0fL8qp/qIIuEzhQw5A SN2g== X-Gm-Message-State: APf1xPAaqI6UeWQwmXUCXMu4w/j1T+ZWpZXZc8qntx2JjYStXalkS4db Q0IQ5ZiDsVoR3E8SBXDJWEmWZw== X-Google-Smtp-Source: AH8x226GI528+7JpHxNN70Wg2tqUGxYphL7mxV9Qu13f92whz/5ryrIjXPYW15hcJ9rpKqm3VmfCdQ== 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 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. v2: split amdgpu changes into separate patch as suggested by Alex v3: change logic as suggested by Daniel Signed-off-by: Christian König Reviewed-by: Daniel Vetter --- 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