From patchwork Thu Sep 23 17:11:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 45384 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3F253857C4A for ; Thu, 23 Sep 2021 17:23:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3F253857C4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632417822; bh=7WBCj6r4ntL+uXb8Flmbzkk2sZq/pxZ2lXrE2uDNSB4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ADfSVjKCmjeec2uSr8l2i8SZk/quaR6F4fwfh1iG4hjTJnshkyDSZT7w+zWfZj1oE 1XbX6UDLyFX47bvzaYiPJ3dcJ2TVNe6kjE6IBKMdwaf+QzNeVB3r7m8semNpGc+CuM avtytOis25FYSQKMRUlUWlyu6AcqB+jOnvtDGkHk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id 83C243858430 for ; Thu, 23 Sep 2021 17:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83C243858430 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id D8C1A1F4460F To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , linux-kernel@vger.kernel.org, Steven Rostedt , Sebastian Andrzej Siewior 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 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_MANYTO, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Andr=C3=A9_Almeida_via_Libc-alpha?= From: =?utf-8?q?Andr=C3=A9_Almeida?= Reply-To: =?utf-8?q?Andr=C3=A9_Almeida?= Cc: Davidlohr Bueso , libc-alpha@sourceware.org, linux-api@vger.kernel.org, mtk.manpages@gmail.com, =?utf-8?q?Andr=C3=A9_Alm?= =?utf-8?q?eida?= , kernel@collabora.com, krisman@collabora.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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