From patchwork Thu Dec 1 14:06:52 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: 9456229 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 A01E160235 for ; Thu, 1 Dec 2016 14:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 937A6284D9 for ; Thu, 1 Dec 2016 14:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 885ED284DE; Thu, 1 Dec 2016 14:07:35 +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 3CD77284D9 for ; Thu, 1 Dec 2016 14:07:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 47A266E809; Thu, 1 Dec 2016 14:07: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 72F8C6E7F6 for ; Thu, 1 Dec 2016 14:07:12 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id m203so34329324wma.3 for ; Thu, 01 Dec 2016 06:07:12 -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=V7nrmdOhPbAzDOfjPVKK5dwVQs1ieonZeFFtbGCJRb4=; b=0gC1ogFc8lQpMeBpHyg6RqwukBSnwBl0D2i0bHxGGz7r1xVUhXv72vxCPGB8idaB6L CzQh6euXVVhvYui9GvmUkfgz7eAnWSm7iobRFCabYNAuf+jauFvr4mgPWy5wnfJtkPg6 MPzWj9gbjhafic11VrgSmlX0eBeUHWxMhwb7oFFFYFwn0jlDYVuxVVvMOiG1HMGUjbaS 2iA97aIW1oAOTMX7TYgw3/bZAEo7H0yIsfCQbOXqZJmFVkWzzYpuL5TzD48wtG2sJDBy MIU3D48HuiNOE4pDyC5hgFmUAYqYYUOXxTzdaIYuuRLwNG8ozKnhDvphOYadW5C6BpPU MULQ== 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=V7nrmdOhPbAzDOfjPVKK5dwVQs1ieonZeFFtbGCJRb4=; b=f8UAqQBf8raL7GyWPJeW2wvv9P1FqDuAOpeMuXiHwjyuQ3JiQyTOGpP7DZPfwQov6U hpLHnMdHy71+gi6JKicPvCnYxCkHKDtAv6vwtK4/7rJEw7qQWpU5PYOoVcz/K0yzw4be cHIvX38ERghalN/59L/O8hMD7UTAciuSh4YbGvjHY+IFC40Pc1zmZdE+YOZvJK2xQqks pAF2DXwvHSKtavk7DJOAskpjaYX1D7cuSMARMvO2A98gfDxJwEfelcpCDli8BH0mtesu orDPZOB2KZEibV3hfEiCdrS9m1UZemt7FFFtaU13zqmjQ8OUOAnwT/UFvRXSo6fH6eRd djNA== X-Gm-Message-State: AKaTC02tu9BSydD64BjXr4Qs3CRrrOAxOY+CuDd7pM+dbLBPXyy7sxoc7QaNeWhlm7NUKA== X-Received: by 10.28.14.66 with SMTP id 63mr31470369wmo.127.1480601230765; Thu, 01 Dec 2016 06:07:10 -0800 (PST) Received: from cassiopeia.fritz.box ([2001:a61:116e:7d01:dc12:8e88:ab9d:8694]) by smtp.gmail.com with ESMTPSA id vr9sm411514wjc.35.2016.12.01.06.07.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Dec 2016 06:07:10 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: linux-kernel@vger.kernel.org Subject: [PATCH v2 09/11] locking/mutex: Initialize mutex_waiter::ww_ctx with poison when debugging Date: Thu, 1 Dec 2016 15:06:52 +0100 Message-Id: <1480601214-26583-10-git-send-email-nhaehnle@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480601214-26583-1-git-send-email-nhaehnle@gmail.com> References: <1480601214-26583-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 296605c..38d173c 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -794,6 +794,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);