From patchwork Mon Feb 1 15:12:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 374269 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp1383120jah; Mon, 1 Feb 2021 07:16:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyp67qqm5qaGcFkgQqJznus81zTSPjRbDIw4l35MjAJI3FD3zhalNW6yh9XAU9z7m7tx7S9 X-Received: by 2002:a17:906:b047:: with SMTP id bj7mr18425757ejb.335.1612192569370; Mon, 01 Feb 2021 07:16:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612192569; cv=none; d=google.com; s=arc-20160816; b=A42vUz+zbtL/dHisQF0nwmV6hg9xEHLsdYW2uFDnVfYB3GVUiAp+wS7uNjN5TXt9F1 lPr/5Rz8byj8RqOy5UEe3PLZJsEGpWuuoJEvZcnXWG4wFQxI5FcvshQYQcHXVqqIflnc h39ggujBcifJU5W8wgmD5YalYku9HZRUHvwsZjdy7yXwtbpUDzG+IMbEo7stQ3PBTcuc /OJjwjzAW5XEAElls9qBj9TJHdYLjq3kTHbpgPcYo8JjZ1ZT85gK+U/SaLD/QvNjusMa eX5a87buuT+6eYeVxQIj6DaGmTZj08m2R9Zdu9AcIt82m8oXwD7m54h2bgrVA88NIpKx Tv2Q== 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=XpuIWF2HW9dIBgX/Ld0+OKyOSiCvAVgygw7iJWAFZGs=; b=YWDbgKOkT49UINlCeGaFDiAPhf5cQIZEzselRkeRwvoMWi7qGmj1y7C4ioda72xx25 chxKzMNe+nMviwScALerl5Qv0HctNe7sfJjMycXuW94qJ2kiNuUvArjj9RPkz1Lg4EsU TRdITEX4oCpM0En30mGmQfI4cIuvuSwnsfWX6pcRzsGzQL5IMOpcaX673DuYpng+MxrT vMJLdaS4cApkgQcFiK6WMyE0/j01e0GIezBwT5wb71fM68eQlu19k8ZjXyzGh002jna+ QK8nRL6s9FBDZgbAzskz5S67yYvEGG2bR4jIOJ8qlzDHWDBzeDi77mbXWqmDqmeI6ygg BAcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IWN4UOeg; 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 f29si11574766edj.297.2021.02.01.07.16.09; Mon, 01 Feb 2021 07:16:09 -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=IWN4UOeg; 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 S231292AbhBAPO7 (ORCPT + 13 others); Mon, 1 Feb 2021 10:14:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231376AbhBAPOz (ORCPT ); Mon, 1 Feb 2021 10:14:55 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68402C06178C for ; Mon, 1 Feb 2021 07:13:44 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id c127so13472345wmf.5 for ; Mon, 01 Feb 2021 07:13:44 -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=XpuIWF2HW9dIBgX/Ld0+OKyOSiCvAVgygw7iJWAFZGs=; b=IWN4UOegACrcqKI3wDyqv54yB5lKHxlCgWlnzDfxAFCvoNZwStXF57Ez5Bi7LfCps0 FJJQrbw2tK6cwO/zw4QAs+4UWRguf3Lt7a3SfVd0k01kOvCMxUOQ0kQ2rs+cXA2cvyg4 PDCBR25VlCVQfwupiGjTWsKjvdiDDkiwx6TV/TbQpOTY3GCbzj8OgXdKxJEEFNIg6OJY zAE7/Q4VqgQKETPQ2foFtiiCVlK22BdJCp9O3qUQZFrnUHjDwQm8V4vMcX/c3WUhKwDJ vJqS6JMgauD9aL6d3moCVpUBqupaR0EeYAup7qPB+Z2Vx22AH+tD7ZmDyJULu4v4Kt25 rBeQ== 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=XpuIWF2HW9dIBgX/Ld0+OKyOSiCvAVgygw7iJWAFZGs=; b=OVzpBSoFVgFRSkPdEK90/petiJ6JXfHMk9Vm8V3xtClwMoJWVx38EKA54ZXOwoxm7y wVv9PgjwmiOKiUiLuq4hOnfg7gpJZs3ZBt7luMvWNoodQc7pVguV2fjvqDU3FMQdF6a2 aNnwU9F04v6XVGvvgCWdhpPrb4ydu5IXPm4kcif2rIvXxIxiZFpb60TlkmGuOJ2rc7qJ jJoIrwWXtb0zhJtsYKyNvO6J6cucSFGXTuOXWmOFGQseguF+h26C6tm/I+QW/k7drzb1 gK5tYDNNE1jmu2UUT8vEHIbvm3zqFDPMGG2SErasxQ6Sy1nWSe3XG/b6f1DxtktKRYoD aXHA== X-Gm-Message-State: AOAM531mAX/admf7/t531vdv1NaL9WanSnBnZnATeq0KyDpO5ZinEoim T9Way+aRqh2dsrqugPFwXv6mG+gtmoFK5/BT X-Received: by 2002:a7b:c8c3:: with SMTP id f3mr15560824wml.110.1612192422859; Mon, 01 Feb 2021 07:13:42 -0800 (PST) Received: from dell.default ([91.110.221.188]) by smtp.gmail.com with ESMTPSA id 192sm23323381wme.27.2021.02.01.07.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 07:13:42 -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 15:12:10 +0000 Message-Id: <20210201151214.2193508-9-lee.jones@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210201151214.2193508-1-lee.jones@linaro.org> References: <20210201151214.2193508-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 5bd3afee4e139..0efcb55455c2a 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -3276,16 +3276,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);