From patchwork Thu Apr 21 19:05:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 12822279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0E02C433EF for ; Thu, 21 Apr 2022 19:05:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 437B16B0072; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BF666B0073; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 210666B0074; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 0C0C66B0072 for ; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id AF687121791 for ; Thu, 21 Apr 2022 19:05:53 +0000 (UTC) X-FDA: 79381815786.19.36B4643 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 9C20440027 for ; Thu, 21 Apr 2022 19:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650567952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AmYL0y+hCk1491gF9Io/zt26uV8J/a8ENaiSiyYWeXE=; b=US67dKAykGHeilAvg4PrEzZLpli1baWt6J9IhFG/NLMvpGpLk/zqrzmKWdTabrvyn4AS3d JpjqA5deyv8M/WOFps2cA/ksFsH/N9+g4VSGMMW2BV+36E7b4EQivN1d1Lii1RudXXFNN9 TsSk3XMnVtbm32x8C+4Yipevl9yYHqw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-325-NMYJwTonP3e0DVRyVtnEXg-1; Thu, 21 Apr 2022 15:05:49 -0400 X-MC-Unique: NMYJwTonP3e0DVRyVtnEXg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E83BA85A5BC; Thu, 21 Apr 2022 19:05:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.22.16.253]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E8CAC2812A; Thu, 21 Apr 2022 19:05:48 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , =?utf-8?q?Andr=C3=A9_Almeida?= , Arjan van de Ven , Ulrich Drepper Subject: [RFC 2/3] futex: exit: Print a warning when futex_cleanup fails Date: Thu, 21 Apr 2022 15:05:32 -0400 Message-Id: <20220421190533.1601879-3-npache@redhat.com> In-Reply-To: <20220421190533.1601879-1-npache@redhat.com> References: <20220421190533.1601879-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Rspam-User: X-Rspamd-Queue-Id: 9C20440027 X-Stat-Signature: odobt66jkuxibwswtxkiijm4gotszcwd Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=US67dKAy; spf=none (imf12.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-HE-Tag: 1650567949-691232 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The futex_cleanup routines currently fails silently. Allow the futex_cleanup routines to fail more verbosely so we can leave a message behind for easier debugging/error detecting. Fixes: 0771dfefc9e5 ("[PATCH] lightweight robust futexes: core") Cc: Andrew Morton Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Darren Hart Cc: Davidlohr Bueso Cc: "André Almeida" Cc: Arjan van de Ven Cc: Ulrich Drepper Signed-off-by: Nico Pache --- kernel/futex/core.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/kernel/futex/core.c b/kernel/futex/core.c index b22ef1efe751..8a62eb1b5d77 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -760,9 +760,9 @@ static inline int fetch_robust_entry(struct robust_list __user **entry, * Walk curr->robust_list (very carefully, it's a userspace list!) * and mark any locks found there dead, and notify any waiters. * - * We silently return on any sign of list-walking problem. + * We return false on any sign of list-walking problem. */ -static void exit_robust_list(struct task_struct *curr) +static bool exit_robust_list(struct task_struct *curr) { struct robust_list_head __user *head = curr->robust_list; struct robust_list __user *entry, *next_entry, *pending; @@ -771,23 +771,25 @@ static void exit_robust_list(struct task_struct *curr) unsigned long futex_offset; int rc; + if (!futex_cmpxchg_enabled) + return false; /* * Fetch the list head (which was registered earlier, via * sys_set_robust_list()): */ if (fetch_robust_entry(&entry, &head->list.next, &pi)) - return; + return false; /* * Fetch the relative futex offset: */ if (get_user(futex_offset, &head->futex_offset)) - return; + return false; /* * Fetch any possibly pending lock-add first, and handle it * if it exists: */ if (fetch_robust_entry(&pending, &head->list_op_pending, &pip)) - return; + return false; next_entry = NULL; /* avoid warning with gcc */ while (entry != &head->list) { @@ -803,10 +805,10 @@ static void exit_robust_list(struct task_struct *curr) if (entry != pending) { if (handle_futex_death((void __user *)entry + futex_offset, curr, pi, HANDLE_DEATH_LIST)) - return; + return false; } if (rc) - return; + return false; entry = next_entry; pi = next_pi; /* @@ -819,9 +821,10 @@ static void exit_robust_list(struct task_struct *curr) } if (pending) { - handle_futex_death((void __user *)pending + futex_offset, + return handle_futex_death((void __user *)pending + futex_offset, curr, pip, HANDLE_DEATH_PENDING); } + return true; } #ifdef CONFIG_COMPAT @@ -854,9 +857,9 @@ compat_fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **ent * Walk curr->robust_list (very carefully, it's a userspace list!) * and mark any locks found there dead, and notify any waiters. * - * We silently return on any sign of list-walking problem. + * We return false on any sign of list-walking problem. */ -static void compat_exit_robust_list(struct task_struct *curr) +static bool compat_exit_robust_list(struct task_struct *curr) { struct compat_robust_list_head __user *head = curr->compat_robust_list; struct robust_list __user *entry, *next_entry, *pending; @@ -866,24 +869,26 @@ static void compat_exit_robust_list(struct task_struct *curr) compat_long_t futex_offset; int rc; + if (!futex_cmpxchg_enabled) + return false; /* * Fetch the list head (which was registered earlier, via * sys_set_robust_list()): */ if (compat_fetch_robust_entry(&uentry, &entry, &head->list.next, &pi)) - return; + return false; /* * Fetch the relative futex offset: */ if (get_user(futex_offset, &head->futex_offset)) - return; + return false; /* * Fetch any possibly pending lock-add first, and handle it * if it exists: */ if (compat_fetch_robust_entry(&upending, &pending, &head->list_op_pending, &pip)) - return; + return false; next_entry = NULL; /* avoid warning with gcc */ while (entry != (struct robust_list __user *) &head->list) { @@ -902,10 +907,10 @@ static void compat_exit_robust_list(struct task_struct *curr) if (handle_futex_death(uaddr, curr, pi, HANDLE_DEATH_LIST)) - return; + return false; } if (rc) - return; + return false; uentry = next_uentry; entry = next_entry; pi = next_pi; @@ -920,8 +925,9 @@ static void compat_exit_robust_list(struct task_struct *curr) if (pending) { void __user *uaddr = futex_uaddr(pending, futex_offset); - handle_futex_death(uaddr, curr, pip, HANDLE_DEATH_PENDING); + return handle_futex_death(uaddr, curr, pip, HANDLE_DEATH_PENDING); } + return true; } #endif @@ -1007,13 +1013,15 @@ static inline void exit_pi_state_list(struct task_struct *curr) { } static void futex_cleanup(struct task_struct *tsk) { if (unlikely(tsk->robust_list)) { - exit_robust_list(tsk); + if (!exit_robust_list(tsk)) + pr_info("futex: exit_robust_list failed"); tsk->robust_list = NULL; } #ifdef CONFIG_COMPAT if (unlikely(tsk->compat_robust_list)) { - compat_exit_robust_list(tsk); + if (!compat_exit_robust_list(tsk)) + pr_info("futex: compat_exit_robust_list failed"); tsk->compat_robust_list = NULL; } #endif