Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp772881pxb; Thu, 23 Sep 2021 10:14:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSuVobPfzUPd+5GlC/MWmLJ9EKXRE4cUnhtaywFVCZNsDvscSIhfoud7YtRvpUKpXPvUi/ X-Received: by 2002:a05:6e02:2167:: with SMTP id s7mr3082936ilv.113.1632417265396; Thu, 23 Sep 2021 10:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632417265; cv=none; d=google.com; s=arc-20160816; b=vV/mABox9qeMzRh7KJXRjviBOI4rwqOFb+pww/k7jV6T9pCeJBggj/zTA3092fo3zJ qBFmbDLHA6TPuWvWxkgf+aD9HDJWzBbE47WI1nZJkNw8YcgcnTWVyPNiip0vCc+lqb0u yLluH15hpMQl6Y10VPRHNp5p45lZbYF+IsKuNamVA0zFHyuU5Pf+IZNyJU4jqZpeFOgJ dKtF16lpr09PXC17NNTyfKBs57OOnafutEI+23AcY3gGcFbuG/IvS7Io8OWm6j4ySn3T 6YKHao+zx0VB2f1ofRYHm90A0l4959Pgx2hdyWV3tOT/VeAlSbbyIhfgSvpi262jniTm 1niQ== 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; bh=7WBCj6r4ntL+uXb8Flmbzkk2sZq/pxZ2lXrE2uDNSB4=; b=O0JPdIfV2YC9jiTk+GCf3GegxO8MuosskSemzJw3TeH/hBbHa9OFFfo9glIJxaVGSj n5dklY3KGoMjK3m072P6njGsx2EsCo0QdqxBgwcgZozdyacZqXBmRrxjex6tzWtZ+tPB GT93TWGqNKbGW4AEzTv4jnwwRRANNA1XUoWyr5VrgukHS5AL/b6eHfL5f73t7J44gHHf 04D2fXwXef5Sr+55gqrfCTQKDDRoceLmJK+7LpR1CeEITOilyZkZj1HD2MI6jahas7xL 6B8OpeVnXL2p1nozwbe+Nk6qRv80Q4TUxP/PAZJ/rmX43XiC3S13ksP6JUEca8HpiP0/ pxag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r18si6550051ilj.49.2021.09.23.10.14.12; Thu, 23 Sep 2021 10:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242383AbhIWROQ (ORCPT + 99 others); Thu, 23 Sep 2021 13:14:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242617AbhIWROF (ORCPT ); Thu, 23 Sep 2021 13:14:05 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE771C061766; Thu, 23 Sep 2021 10:12:33 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id D8C1A1F4460F From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , linux-kernel@vger.kernel.org, Steven Rostedt , Sebastian Andrzej Siewior Cc: kernel@collabora.com, krisman@collabora.com, linux-api@vger.kernel.org, libc-alpha@sourceware.org, mtk.manpages@gmail.com, Davidlohr Bueso , Arnd Bergmann , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v2 15/22] futex: Simplify double_lock_hb() Date: Thu, 23 Sep 2021 14:11:04 -0300 Message-Id: <20210923171111.300673-16-andrealmeid@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210923171111.300673-1-andrealmeid@collabora.com> References: <20210923171111.300673-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra We need to make sure that all requeue operations take the hash bucket locks in the same order to avoid deadlock. Simplify the current double_lock_hb implementation by making sure hb1 is always the "smallest" bucket to avoid extra checks. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: André Almeida [André: Add commit description] Signed-off-by: André Almeida --- kernel/futex/futex.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h index fe847f57dad5..465f7bd5caef 100644 --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -239,14 +239,12 @@ extern int fixup_pi_owner(u32 __user *uaddr, struct futex_q *q, int locked); static inline void double_lock_hb(struct futex_hash_bucket *hb1, struct futex_hash_bucket *hb2) { - if (hb1 <= hb2) { - spin_lock(&hb1->lock); - if (hb1 < hb2) - spin_lock_nested(&hb2->lock, SINGLE_DEPTH_NESTING); - } else { /* hb1 > hb2 */ - spin_lock(&hb2->lock); - spin_lock_nested(&hb1->lock, SINGLE_DEPTH_NESTING); - } + if (hb1 > hb2) + swap(hb1, hb2); + + spin_lock(&hb1->lock); + if (hb1 != hb2) + spin_lock_nested(&hb2->lock, SINGLE_DEPTH_NESTING); } static inline void -- 2.33.0