From mboxrd@z Thu Jan 1 00:00:00 1970 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 A56ACC369DC for ; Tue, 29 Apr 2025 15:53:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3386F6B0005; Tue, 29 Apr 2025 11:53:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E93D6B000A; Tue, 29 Apr 2025 11:53:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B2B96B000C; Tue, 29 Apr 2025 11:53:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F11A96B0005 for ; Tue, 29 Apr 2025 11:53:06 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3EEF616088B for ; Tue, 29 Apr 2025 15:53:07 +0000 (UTC) X-FDA: 83387525214.24.7C2C588 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by imf14.hostedemail.com (Postfix) with ESMTP id 43592100009 for ; Tue, 29 Apr 2025 15:53:05 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="R5AcFs/v"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of surenb@google.com designates 209.85.160.177 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745941985; a=rsa-sha256; cv=none; b=s58GBNuJsUhhXXDlnQGngumH36qlUfvYc+BS8UcsY0EFsKVsJCEWC/dNPomj51MnQvi7JB 1Z6hNezHvmHdlVJIcI89VlkywRsygsnB3W/LwPbupCbKEJocbD23YxKSHvSsmElSagND4q qO0daf4QrCHz09+uBWmw9wYlrwY30i4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="R5AcFs/v"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of surenb@google.com designates 209.85.160.177 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745941985; h=from:from:sender: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:dkim-signature; bh=tR4G/oE7lDV+SqdB3MLGFRpZBNejLhq+cnMM4fvc76s=; b=a9H1vCkzPhoMqW0ddVJQ/HiAu1gKiuJBdoI27lz+EBVAMcLCzdsa1fGxfcD9mn3q2DKZ58 Z+myPJJE3NteqH2pGUsygZM1YTD2avCfjFcENSX4DDa6qnmIpuTfgo796D2RUGzd1FjI/F 8WjiUCSNCbwsXHjqDxoOVfW9C2FvyiU= Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-4774611d40bso262661cf.0 for ; Tue, 29 Apr 2025 08:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745941984; x=1746546784; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tR4G/oE7lDV+SqdB3MLGFRpZBNejLhq+cnMM4fvc76s=; b=R5AcFs/vmSgxEJ9rmgO16vVX063K+wcIIIJUGJWW/QmTCdOyx5cSbpnlVfj8s0hRiF zpgvZ8TaL4aARWVX/Lj5bex7pZsFsRSwPh9NCyL0Hv+HMvVWKyvb1+vzhE5QNGWP0KyM k3i0gDfKHQGEW22sgpuePwP7oeBIRVV/XGlykdtVI1rHKOhLr/N9r4kIVgRB/uD3/H57 0zbBjQ6KLnj0Wv4W4uKjkfoT+G5TZ6UjD39PT7BLG04kVU1+aRvAAT9xhXLaWxfvFu9u by7TRuZRYYiI+mQLuHGdS8oPjVfmcbP/O1p/LVloCRqWTckoP1IOoQpGLhq5T5LjJq+0 d/fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745941984; x=1746546784; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tR4G/oE7lDV+SqdB3MLGFRpZBNejLhq+cnMM4fvc76s=; b=uHqGtp61USTyEncWsqfYNiiqjEIRGDH6hH1+PKe2dHK5vag1r1QKIa590MFBWBYmBE vjYIvL7e3H2YJVdIQeApqdy0XaYM3bZMqwjQ4V0ULHPnAWSANwVG/Wpzv/q4RAvWAoeV rzdFf3ckjAPE10ssSvxK/JfIZ0YysjWb0P5mOoeqbB0BKVvziQefHitbjfwup7a6x/IQ LoFtHm7cSf+jPd5EQRF6NXKFSsgMwc1UnOFBIbBoMN/P5ZY4nkHhADPaD4MRbb9TzYGq u1Eje0RgieAgNFxkKvVTKfCjRHZuF9ImeWufLf3AT96gl1pHKkvPpOOY8utA8owtTdfZ NEsA== X-Forwarded-Encrypted: i=1; AJvYcCX6beNPeKnysSXHzfI76ZeLiWIRrNrEiO9l30+jJ+omya59o794UMG1Tz1iDgX/i+1yghn5bndktQ==@kvack.org X-Gm-Message-State: AOJu0YxNpEiEPVB7GyXI16SXHMLwcFrruzau7fGnibKV/yMRgI8ZmoKC ZNZVBxWg/bElTj9EVceWnG8Z+FCgrdaxRk6NB+RR65/bWO3/1MMOsH/N+g0pXpcFVoPeCIWZo0q gErxyD8erBeCxk6jbB2u8chXQXUHwUos+UMWSYPpQl5d0OZHo67ah X-Gm-Gg: ASbGncvHIy9/kKDFQld8qRLlRDyqwHZY7kvkALZB+Ki/PTxYQMHJm9G7bI/qTODVPvo YdnC9uEz5HguCAAGXmJjiTBUx+A6oZe9hPZY6RpjMk4TCtnaU42H2tGqPWFvZ/7BJ2Mu6QolwLH bVK/cp+1ocIVlOVTiVTJdUcLA/2V3cifTYkTZnY0GlxBhdt5UJh/plZpOR19Iaokk= X-Google-Smtp-Source: AGHT+IGUq0/bI6iWrr9yZSSFf6tf5FG9S03JekqmQqENCmT+EVGlFWDUhQvyd0VduyAxZKvqcwn9zVZ9YpU7aaw47qI= X-Received: by 2002:a05:622a:1822:b0:47e:ad75:c1a7 with SMTP id d75a77b69052e-4885f13f423mr5274211cf.18.1745941984053; Tue, 29 Apr 2025 08:53:04 -0700 (PDT) MIME-Version: 1.0 References: <20250429014754.1479118-1-Liam.Howlett@oracle.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 29 Apr 2025 08:52:52 -0700 X-Gm-Features: ATxdqUFtkPoy459ruNkC4oHR_d__4et9mgSOFxeAb9dS-Stp0Dg4GrMRRqwCwKk Message-ID: Subject: Re: [RFC PATCH v6.6] maple_tree: Fix MA_STATE_PREALLOC flag in mas_preallocate() To: Hailong Liu Cc: "Liam R. Howlett" , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhaoyang Huang , Lorenzo Stoakes , "zhangpeng . 00 @ bytedance . com" , Steve Kang , Matthew Wilcox , Sidhartha Kumar Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 43592100009 X-Stat-Signature: ubmjyjzuxntz3kcqs85q8ekc61dews1q X-Rspam-User: X-HE-Tag: 1745941985-962429 X-HE-Meta: U2FsdGVkX192rurfYhhkIkivzFGq9SaDe9qI1WUYvNfULLGRTkkCimcp7tIExRVpHU2XilOs4Z3VJlg6XtFkhoEg20MHzKogEs0g1AABbpycqYwcEhyjyxZUkKPGOCoipjZbrM9LDDdFUBWCG1d0lc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NpmdsvY2g+5DFU3zUaTUKwaPOe/XyWXrlTVY4l4b00NgytAHmf9WY8ExCZFDr9S04eM6BM4OTXaCMofJZ0jM+LJPQlARuhBpkn4qclTEZfIf4CYmgLUAlrfLwhYNcrJSGlee56A9JlomJYZO8Vpn781YvQZK60/vqXEpeu8HwzQzaOlTStL3FPJuTAm8u/YglmXPvRc1nrlnh5499pgRhK9heVkl/zCnrInWXt 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: List-Subscribe: List-Unsubscribe: On Tue, Apr 29, 2025 at 12:48=E2=80=AFAM Hailong Liu = wrote: > > On 4/29/2025 9:47 AM, Liam R. Howlett wrote: > > Temporarily clear the preallocation flag when explicitly requesting > > allocations. Pre-existing allocations are already counted against the > > request through mas_node_count_gfp(), but the allocations will not > > happen if the MA_STATE_PREALLOC flag is set. This flag is meant to > > avoid re-allocating in bulk allocation mode, and to detect issues with > > preallocation calculations. > > > > The MA_STATE_PREALLOC flag should also always be set on zero allocation= s > > so that detection of underflow allocations will print a WARN_ON() durin= g > > consumption. > > > > User visible effect of this flaw is a WARN_ON() followed by a null > > pointer dereference when subsequent requests for larger number of nodes > > is ignored, such as the vma merge retry in mmap_region() caused by > > drivers altering the vma flags. > > > > Reported-by: Zhaoyang Huang > > Reported-by: Hailong Liu > > Fixes: 54a611b605901 ("Maple Tree: add new data structure") > > Link: https://lore.kernel.org/all/1652f7eb-a51b-4fee-8058-c73af63bacd1@= oppo.com/ > > Link: https://lore.kernel.org/all/20250428184058.1416274-1-Liam.Howlett= @oracle.com/ > > Cc: Lorenzo Stoakes > > Cc: Suren Baghdasaryan > > Cc: Hailong Liu > > Cc: zhangpeng.00@bytedance.com > > Cc: Steve Kang > > Cc: Matthew Wilcox > > Cc: Sidhartha Kumar > > Signed-off-by: Liam R. Howlett > > --- > > lib/maple_tree.c | 14 +++++++++----- > > 1 file changed, 9 insertions(+), 5 deletions(-) > > > > Only the MA_STATE_PREALLOC flag needs to be fixed to avoid the vma > > iterator issue. Doing the minimum change here mitigates risk in the > > stable kernels. > > > > If this fixes the issue, I'll resend without the RFC and add Stable to > > the Cc list. > > > > Thanks again, Hailong for the work on this issue. Your testcase helped > > me narrow the bug down in the end. I appreciate all the work and > > support provided by the Android partners, especially the involvement on > > the mailing list! > That's my pleasure. I also learned a lot from you :) > > > > diff --git a/lib/maple_tree.c b/lib/maple_tree.c > > index 4eda949063602..d9975b870dadc 100644 > > --- a/lib/maple_tree.c > > +++ b/lib/maple_tree.c > > @@ -5508,7 +5508,7 @@ int mas_preallocate(struct ma_state *mas, void *e= ntry, gfp_t gfp) > > /* At this point, we are at the leaf node that needs to be altere= d. */ > > /* Exact fit, no nodes needed. */ > > if (wr_mas.r_min =3D=3D mas->index && wr_mas.r_max =3D=3D mas->la= st) > > - return 0; > > + goto ask_zero; > > > > mas_wr_end_piv(&wr_mas); > > node_size =3D mas_wr_new_end(&wr_mas); > > @@ -5517,10 +5517,11 @@ int mas_preallocate(struct ma_state *mas, void = *entry, gfp_t gfp) > > if (node_size =3D=3D wr_mas.node_end) { > > /* reuse node */ > > if (!mt_in_rcu(mas->tree)) > > - return 0; > > + goto ask_zero; > > + > > /* shifting boundary */ > > if (wr_mas.offset_end - mas->offset =3D=3D 1) > > - return 0; > > + goto ask_zero; > > } > > > > if (node_size >=3D mt_slots[wr_mas.type]) { > > @@ -5539,10 +5540,13 @@ int mas_preallocate(struct ma_state *mas, void = *entry, gfp_t gfp) > > > > /* node store, slot store needs one node */ > > ask_now: > > + mas->mas_flags &=3D ~MA_STATE_PREALLOC; > > mas_node_count_gfp(mas, request, gfp); > > - mas->mas_flags |=3D MA_STATE_PREALLOC; > > - if (likely(!mas_is_err(mas))) > > + if (likely(!mas_is_err(mas))) { > > +ask_zero: > > + mas->mas_flags |=3D MA_STATE_PREALLOC; > > return 0; > > + } > > > > mas_set_alloc_req(mas, 0); > > ret =3D xa_err(mas->node); > Passed local test, planned to aging test. I also confirmed the issue is not reproducible with your patch. Thanks! > > Brs, > Hailong. >