From patchwork Mon Nov 28 12:20:10 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: 9449467 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 901FA600CB for ; Mon, 28 Nov 2016 12:20:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80EBC27BE5 for ; Mon, 28 Nov 2016 12:20:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 756C627BFF; Mon, 28 Nov 2016 12:20:42 +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 3496927BE5 for ; Mon, 28 Nov 2016 12:20:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BFDB66E2C4; Mon, 28 Nov 2016 12:20:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x241.google.com (mail-wj0-x241.google.com [IPv6:2a00:1450:400c:c01::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6292D6E2BD for ; Mon, 28 Nov 2016 12:20:32 +0000 (UTC) Received: by mail-wj0-x241.google.com with SMTP id xy5so13848205wjc.1 for ; Mon, 28 Nov 2016 04:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BFKZSr9cQ1l+JjEW3cJwxmRD25R8ejEvLSnOyYXW70M=; b=x3EHVpQxC8k5V2Gx7yfYGQHwqJk84tdtOVQiTsnR1oj4CVW/FBhJ++1BQyyGQ1NE8c NoxjcnphtWQoxRctzCvajjQn7DRRhNmvF+C2uidegPBTMiVYCYwkWFUFyJXNRL746HOq lm8IbiyXi7r2xccLmRqeP+mzE4eI4Vc96is4k6poMSMWmUE6eWQ7SHJ00Q5qGtoncNfu laZNnL2+lKC+j62Yj747tpaduMFwZ+ZEhB/ZIYsLQo7hFUHXGfvpzDG7NqUvLJjC3OS/ kUj8T4ilcjSsaZ2Pry2NmPgMN9KwwWNvBMoVJIoSiV7B0a63oCwxEcU2b0lXBwyqn5aJ IBfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BFKZSr9cQ1l+JjEW3cJwxmRD25R8ejEvLSnOyYXW70M=; b=LRTTzzOOJJ7pRWYCxoqSZ2fPxmNO8J6SqQgeiCBDsah0+RovMyCbEyh8bWXmPAmDaT usUgxqAvEFDciSdJnR1P9O9L/tLf7aXlK60R7XmJs/4rDBQzA/pJUW2R/wjub79jbpfk KUzcTZQXmdAJm1MFjCnfcYTxrBm9MuiEv4zEzmpUAdLLs7wAKodzllbao7AccWS6ko+p r4OZTjIuOL8fOEukWCY5VPxqkP6wnjH0Ndogh4OM0WGhykOU0jOqcySH0AWCouV7FYk2 Esa4o4rqnOM3N70aoqKdOeil5BdC/szwh9vyUTYxx8Ui5OgmGn8h2q5jnrByrgNU7Z78 Ktww== X-Gm-Message-State: AKaTC03K4WCA6cD93wHW07dH/2SbesFVA44jsM/FxlKiGQ0TYWkCWgLMm2oeQH4MPNjjqQ== X-Received: by 10.194.26.170 with SMTP id m10mr18594165wjg.152.1480335630789; Mon, 28 Nov 2016 04:20:30 -0800 (PST) Received: from cassiopeia.fritz.box ([2001:a61:1119:dc01:d88b:9432:f601:27ed]) by smtp.gmail.com with ESMTPSA id a13sm28830511wma.18.2016.11.28.04.20.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Nov 2016 04:20:30 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: linux-kernel@vger.kernel.org Subject: [PATCH 09/11] locking/mutex: Initialize mutex_waiter::ww_ctx with poison when debugging Date: Mon, 28 Nov 2016 13:20:10 +0100 Message-Id: <1480335612-12069-10-git-send-email-nhaehnle@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480335612-12069-1-git-send-email-nhaehnle@gmail.com> References: <1480335612-12069-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 1e4da21..ee84007 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -783,6 +783,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);