From patchwork Mon Feb 1 10:01:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 374225 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp1120307jah; Mon, 1 Feb 2021 02:04:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+6FmEPQdN4KrVzbkhG4l2/nlGtTOz6n8QsFdfHD1gfBMOMtfv4nKsGBh4c51EBhbkkOOw X-Received: by 2002:a05:6402:13c8:: with SMTP id a8mr17757784edx.191.1612173896957; Mon, 01 Feb 2021 02:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612173896; cv=none; d=google.com; s=arc-20160816; b=atNrWkGXF1w531PvcM8sGohD8kHlV5PWmPGplm1Qpon6o+OZuRh8zSzBfADYtTh3Ps QatazgTbaz0BL/9fjUoJ0gAiaA4ixdsvjDnRErl+vSQC4AMTqZSv8rlDBKjMJSLBJAAV MQhrBqrGTdyEX9lfjVOt0Ppl2KwrRohSdN5l5uxRcQuveSVDbj0ZnsgJQnYpIy1QB7Qt TVu7wBoXSP/CEA+/X6ClV4zQ6JXE60pstFQflqFUL80dK8a6zG0A146EAyC1Q67CHyqQ 0FEK5OmAF8xxv50hK/L6jLGBzJvJejvfIucnV6HnZLfHk2KtwLhJYQ7HRwaS3wShOiAx ADLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xnIHaUcaGnvu4d6/FdlgyP+cy+Y5o5wrHg5QIdWEM68=; b=yuQHemY8MC0T+pPqUX3qb1kg+CEYOJOyPgiWCLrw/mjS5JVfR5Lh+NcAFkwS4a+I9i 7WXCoAH8PgH+bT11uZT4pK1zUC+50LJXl/ztzi8L0cD2dQdjqLquhVzdJV8EeDH1h+Ra 0cf+iDuAHRMpNVjD0cQ2Lzyj+3hqJ8cQCmSEfkvTya6ZzuobeQQG78fb/XbLp0paXeYZ barxT8w5kUmbsQFtRgF/nPhzZH+LFRvOQOwXuLgV5peoRadWnsPwKKHnQAk/RXNjy8Yu +kBrawyFo/wxr73n/+CXSujmO3s1gOTbwn8tdfB0wVYW2AYpgMaXBbIXPpwGrDzpcSg5 pbog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YjLwUqCD; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m6si13120787ejl.643.2021.02.01.02.04.56; Mon, 01 Feb 2021 02:04:56 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YjLwUqCD; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232995AbhBAKDf (ORCPT + 13 others); Mon, 1 Feb 2021 05:03:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233009AbhBAKDd (ORCPT ); Mon, 1 Feb 2021 05:03:33 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA727C06178C for ; Mon, 1 Feb 2021 02:02:21 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id g10so15884928wrx.1 for ; Mon, 01 Feb 2021 02:02:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xnIHaUcaGnvu4d6/FdlgyP+cy+Y5o5wrHg5QIdWEM68=; b=YjLwUqCDzZLfeAElCV+0/ULjcstLNC/MoLRRObgnQFsRBftrxwI1ybQ0vUegpLMn6u w6JnJ4zL2gd9Fn9zHKcL9TH5FdxwM70HSRuaL+9qmERWmViUeIEHpF8Z2CnJrDFO6cLm O45+a4z0atnQyjafTZBc5LzGVXAawwy5LJeJR4P+y/3t4hC+dxkchxrnumivMAudYoYm N8tp3w+PzNrAJRexiYn5Hcw0eFN+UVW1mtkdg9AE4mxTYkzcvHwrABvwG7sscdKaZ9fy oS0Na9+/fKfRtW4fXEPbXdUptsqCyeIsuUM+v+VobKm7sKQCRJugxYGL1+rGR2QmqcD6 PG8w== 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=xnIHaUcaGnvu4d6/FdlgyP+cy+Y5o5wrHg5QIdWEM68=; b=n99Vm6FUV4s1YLP8Wy7+KAn7Q5fJ6dsfBBG2jr7AmNoXD+Ku+iYqd3DtT45+k+Ukk+ xmPy2iT4izFBByUAE9hmHb1rkMcO7Lh+Yke895HyWXiUcrf2T1yVww76k7HG1W/vUEP/ 8jsboc33mrR+BMTzUgBQVqi33b3fn6nNc6Ho1YBC+IB28mgG1sQBzXG0vPZ/it3NptNE t09Z/0zCXzDzZsYxfdUaTGzsCflsyNq3Nb99IWLYJaMMXmKJkKgfQNdj0nwvbrXVWFCb C66GoUyQY0eTP8VjCnWSfmkj4U3LUaqtnNFy5+Vuw+WjfjohpB4p9LPY6HJ+m4S0WPOh GWqA== X-Gm-Message-State: AOAM533ekzc+LEXICDSvDqE5UdyrUzaofPcWZSeYS7xymtWWAkzNfR9m 2VmtFfsT0s4c6N5UDN2Ih1nLz6CCl2AARuqx X-Received: by 2002:a05:6000:1202:: with SMTP id e2mr5596646wrx.328.1612173740097; Mon, 01 Feb 2021 02:02:20 -0800 (PST) Received: from dell.default ([91.110.221.188]) by smtp.gmail.com with ESMTPSA id p15sm26151387wrt.15.2021.02.01.02.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 02:02:19 -0800 (PST) From: Lee Jones To: stable@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Greg Kroah-Hartman , Lee Jones Subject: [PATCH 08/12] futex: Sanitize exit state handling Date: Mon, 1 Feb 2021 10:01:39 +0000 Message-Id: <20210201100143.2028618-9-lee.jones@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210201100143.2028618-1-lee.jones@linaro.org> References: <20210201100143.2028618-1-lee.jones@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thomas Gleixner commit 4a8e991b91aca9e20705d434677ac013974e0e30 upstream. Instead of having a smp_mb() and an empty lock/unlock of task::pi_lock move the state setting into to the lock section. Signed-off-by: Thomas Gleixner Reviewed-by: Ingo Molnar Acked-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20191106224556.645603214@linutronix.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Lee Jones --- kernel/futex.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) -- 2.25.1 diff --git a/kernel/futex.c b/kernel/futex.c index 482000996b983..f1e8ba64fe8ae 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -3311,16 +3311,19 @@ void futex_exit_recursive(struct task_struct *tsk) void futex_exit_release(struct task_struct *tsk) { - tsk->futex_state = FUTEX_STATE_EXITING; - /* - * Ensure that all new tsk->pi_lock acquisitions must observe - * FUTEX_STATE_EXITING. Serializes against attach_to_pi_owner(). - */ - smp_mb(); /* - * Ensure that we must observe the pi_state in exit_pi_state_list(). + * Switch the state to FUTEX_STATE_EXITING under tsk->pi_lock. + * + * This ensures that all subsequent checks of tsk->futex_state in + * attach_to_pi_owner() must observe FUTEX_STATE_EXITING with + * tsk->pi_lock held. + * + * It guarantees also that a pi_state which was queued right before + * the state change under tsk->pi_lock by a concurrent waiter must + * be observed in exit_pi_state_list(). */ raw_spin_lock_irq(&tsk->pi_lock); + tsk->futex_state = FUTEX_STATE_EXITING; raw_spin_unlock_irq(&tsk->pi_lock); futex_exec_release(tsk);