From patchwork Wed Dec 21 18:46:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Nicolai_H=C3=A4hnle?= X-Patchwork-Id: 9483657 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 40531601D3 for ; Wed, 21 Dec 2016 18:47:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3543627D85 for ; Wed, 21 Dec 2016 18:47:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A29527F9E; Wed, 21 Dec 2016 18:47:58 +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 DED2C27D85 for ; Wed, 21 Dec 2016 18:47:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F1A8C6F0D8; Wed, 21 Dec 2016 18:47:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A1CB89CB2 for ; Wed, 21 Dec 2016 18:47:01 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id l2so6524106wml.2 for ; Wed, 21 Dec 2016 10:47:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XYD2hzPJ+ryDiSoxC+tzdo3dSiZ2u+m+/lI/p1bEgMs=; b=kewwCDPwC15K5qCeWjobBVeUwiQdYCATCe/HMGxMYi8dGNzWrU6HBL49weHZ5gvHtc biM8lkSXd3nmOdREqXHeUuVSbEX56W8WXkZda0eQf4LLgEjerN/xKQSEsZdzsObuKgGz zgiXaN++Qiksm/HXYRexppm0f4DAUGyF15zX6zt7KunV1K+cfnf8e7+YCNQmD4WJ2jXj 9OY2xRhEe3hN42hMYuUgk8nPa5LdSLiBwl2nNNmZGGT9hs1WcJL08FOHVXen/9RSLdZb 4mBlZJNYjxjv6HFgWURtFn0JBwOHMH6rRryw7bzvAuMJ3FA5oGWI6rjoMNbtTjHqWzpZ RJ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XYD2hzPJ+ryDiSoxC+tzdo3dSiZ2u+m+/lI/p1bEgMs=; b=Jm1YTyzCCTH90dFkS2FksC2b4JNoh6l10AOAnIOprJgopDItd0O9qnCITTHwzsG0KM HJTxtjgk/u29+Vgpk6kI6eqshIU2Xz7kEQ44e+cb2AUEgiODyWW5hGff+ugDP26GHuFG q+C2BZz+fy6jOETVlo/m8EWlyQcJgtMDHy6FrqAcrXb7qel2PNkJL+jk4fYJtYnpAUcO AY+It/+GbjuWaWvSxACZtzjHfivMZMm0H8sqk6txdkI2sEakXM+AfPzOdzfreMDpHunI sQDvJJbcvOHtVQwa7hidxqHr8xAlvDM+mFE+6M/0eC4b4LkNmIe9cUSzdBwF2huyLdcV JQ9A== X-Gm-Message-State: AIkVDXI71pN1o6OtRyPuZym/+pnXzikeBwEgKLZF75bEomd8eFyWAyhVCZyR+XgH+oFJUQ== X-Received: by 10.28.30.146 with SMTP id e140mr6316410wme.112.1482346019805; Wed, 21 Dec 2016 10:46:59 -0800 (PST) Received: from cassiopeia.fritz.box ([2001:a61:110a:1701:2511:6687:1ba5:b45b]) by smtp.gmail.com with ESMTPSA id ke6sm31840526wjb.21.2016.12.21.10.46.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Dec 2016 10:46:59 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: linux-kernel@vger.kernel.org Subject: [PATCH v3 11/12] locking/mutex: Initialize mutex_waiter::ww_ctx with poison when debugging Date: Wed, 21 Dec 2016 19:46:39 +0100 Message-Id: <1482346000-9927-12-git-send-email-nhaehnle@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482346000-9927-1-git-send-email-nhaehnle@gmail.com> References: <1482346000-9927-1-git-send-email-nhaehnle@gmail.com> MIME-Version: 1.0 Cc: Maarten Lankhorst , =?UTF-8?q?Nicolai=20H=C3=A4hnle?= , Peter Zijlstra , dri-devel@lists.freedesktop.org, Ingo Molnar X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 From: Nicolai Hähnle Help catch cases where mutex_lock is used directly on w/w mutexes, which otherwise result in the w/w tasks reading uninitialized data. Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Maarten Lankhorst Cc: Daniel Vetter Cc: Chris Wilson Cc: dri-devel@lists.freedesktop.org Signed-off-by: Nicolai Hähnle --- include/linux/poison.h | 1 + kernel/locking/mutex.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/linux/poison.h b/include/linux/poison.h index 51334ed..a395403 100644 --- a/include/linux/poison.h +++ b/include/linux/poison.h @@ -80,6 +80,7 @@ /********** kernel/mutexes **********/ #define MUTEX_DEBUG_INIT 0x11 #define MUTEX_DEBUG_FREE 0x22 +#define MUTEX_POISON_WW_CTX ((void *) 0x500 + POISON_POINTER_DELTA) /********** lib/flex_array.c **********/ #define FLEX_ARRAY_FREE 0x6c /* for use-after-free poisoning */ diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 0bafb37..3e46a12 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -791,6 +791,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, if (!use_ww_ctx) { /* add waiting tasks to the end of the waitqueue (FIFO): */ list_add_tail(&waiter.list, &lock->wait_list); + +#ifdef CONFIG_DEBUG_MUTEXES + waiter.ww_ctx = MUTEX_POISON_WW_CTX; +#endif } else { /* Add in stamp order, waking up waiters that must back off. */ ret = __ww_mutex_add_waiter(&waiter, lock, ww_ctx);