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 68306C83F01 for ; Thu, 31 Aug 2023 09:43:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D00758E0015; Thu, 31 Aug 2023 05:43:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB0988D0001; Thu, 31 Aug 2023 05:43:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B78328E0015; Thu, 31 Aug 2023 05:43:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A5C478D0001 for ; Thu, 31 Aug 2023 05:43:43 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 40FA9801B4 for ; Thu, 31 Aug 2023 09:43:43 +0000 (UTC) X-FDA: 81183912726.07.4F23118 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) by imf03.hostedemail.com (Postfix) with ESMTP id 3B96C20031 for ; Thu, 31 Aug 2023 09:43:41 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.219.179 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693475021; a=rsa-sha256; cv=none; b=AOGQ5B1yL9wFVyk5o65uJl2KiKqK4VgST1oiZQP0U7MNDcgM1BXC0rvbue2Zokk/mP4l+W 20pAw02JZwQ0jMs4oFAgjQY5P9V92ASLaodEUCpvGKf8s1CGsa3ONC8Fw0SyYbsdqzNuL3 7MvKJObQHIJjcHu52pvFok9fM1pQuH4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.219.179 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693475021; 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; bh=15fJYkK70EO/L01pQbhlxvsvLOdh5C+6wf2tECW+cxA=; b=U7muD8rcY+EaEjptD5H1MT+dIzWQ1ZRrg0amWE/mxQwI5iBAfkFqi27Y9oLK4z37wcwrKb 0J8zCaTPmVve6jopu1WHpt+21g+bp9XBrkpqQYDySwbaPOFKcv+3OIgMCZVtE+r5j1zvp0 c6rCd+2O5uYpfJGSsirCw7piTXcQlfE= Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-d7bae413275so1957059276.0 for ; Thu, 31 Aug 2023 02:43:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693475020; x=1694079820; 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=15fJYkK70EO/L01pQbhlxvsvLOdh5C+6wf2tECW+cxA=; b=Q/gc0XpFRHH/uObxGwcRLrp2ZTpQCFF/ibRAUw7IaZowVOrVaf0BxrFQVvi3P/ge66 LRKCTPDFrQ+aSpzS2aeOvwTvlTjpKXWfLb3ePy/ZAVqIxOAQhV3xtED128EwTCRfvB6b Ecx86XNsD1wIZ8ixmG4TEOPH0PGnLmVWQfMXIcKQ1KK8vBSwClZhoLUKrNZjAk1NPz5Z ka2vGyZ0MDdRJf9Usu4FPOVT/R09wv1oCUJl28viD98Be8N+KgFyVaiiPlOOgajyHorF CYX9SRJOOvvlm62A7IInYCVG0FLjOMJ+VqRiD0EaPGCAWETQ8VhjAjPm5l0hyxpDe9il S/Hw== X-Gm-Message-State: AOJu0YxWkr10j7XsmcPWxuKuZk2plEIdIowoxQ6zM0QB+OWoQFzzdYRb zuFMO3fQZFAPrwxwGVr9SL8ra96mk+m7dg== X-Google-Smtp-Source: AGHT+IEsM8AnatytbQMS/tWCsSN5QGDryJbU1Gy5jv5PMgUL+pSRe61qMUCtYPz2/loNZ+6pTEUGBw== X-Received: by 2002:a0d:ead7:0:b0:56c:f0c7:7d72 with SMTP id t206-20020a0dead7000000b0056cf0c77d72mr2164919ywe.4.1693475019930; Thu, 31 Aug 2023 02:43:39 -0700 (PDT) Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com. [209.85.219.179]) by smtp.gmail.com with ESMTPSA id p7-20020a0de607000000b00586ba973bddsm304081ywe.110.2023.08.31.02.43.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Aug 2023 02:43:39 -0700 (PDT) Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-d7bae413275so1957038276.0 for ; Thu, 31 Aug 2023 02:43:39 -0700 (PDT) X-Received: by 2002:a25:fc10:0:b0:d71:7d2f:c548 with SMTP id v16-20020a25fc10000000b00d717d2fc548mr2178292ybd.15.1693475018810; Thu, 31 Aug 2023 02:43:38 -0700 (PDT) MIME-Version: 1.0 References: <20230819004356.1454718-1-Liam.Howlett@oracle.com> <20230819004356.1454718-2-Liam.Howlett@oracle.com> <3f86d58e-7f36-c6b4-c43a-2a7bcffd3bd@linux-m68k.org> <87v8cv22jh.fsf@mail.lhotse> <6f663185-2ef1-5075-99c9-e16050329d74@bytedance.com> In-Reply-To: <6f663185-2ef1-5075-99c9-e16050329d74@bytedance.com> From: Geert Uytterhoeven Date: Thu, 31 Aug 2023 11:43:25 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] maple_tree: Disable mas_wr_append() when other readers are possible To: Peng Zhang Cc: Michael Ellerman , "Liam R. Howlett" , Andrew Morton , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-renesas-soc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3B96C20031 X-Stat-Signature: a6if8cxxhng3j6uzqb9ugh1iose9t816 X-HE-Tag: 1693475021-70901 X-HE-Meta: U2FsdGVkX1/xK9YwhS6+b2WATah9EsQqNBHIfnSEOXsPLcduvkbFZXvV2xpEXJq+FoMamiBT1uqBO+cNVnaqIGwcUrnAeDTAOr4TBmq389UfaGOo4ribwhPy/oWDU0hQqj9M6FGgXQidKkgQt9JoUHv56mDUjQqDE8tHwz/QRo7bCdHcT7Qg8b2MZDrqzIs1h0U79f+WNkfUFcR61/2euXegrLBMazD7TifrkRkNj6Gn3707tE1NV1yQ58w1igpYAqGqWuJFu9Ahs1Tf3lJgutX8vgfOquvn7zEBFzJace/f/2d0r/sv8fJDq3tdYxXQAuKggqcCxEtJIn/pcT7rnwg3YdbMxWconQRnirH44iLObdW66Eh68GPm2S1Zvvew4M30Rg58rAePp886NPcqoKGqLKzGqeFJwf3Nff2oPhg2ZUOXRwgVvZzWrZ6c9ieN/nk4XieQalBu4Tjf4zPqOx2K7D1d+5kwyPJfe5FdFZ/ilelhLlHsSyWtiwUJ5wBXlblaPTl/9eUGZav00A6WXu/1yY+f7m6pzRLmvIwvUrIdvBr4zOjFyCUYUk5IMZsUcl0lwgjBn3tIodInsgolLEfvLgIP8pfuBBUobSZcEyvQiduxQ0M1uZdrGA/jujmQLN4wMQyCijwu47tw05ywdJ6dNXUtn+2oQF7P/fgE8jCJU/mZane45vOQjlZ7r6Dqyn2QrVzPLBCEnD9vYVVT/FXIk7APWJIxVJIgJQVmPXirjHpUbOxPJaZEjQ6oi0qqPPRZ+nMUsfVSYiEDl+CpuHt898JxmHdJ9C25F1ZXRE6OVUoo75F0MWhFZi4JyM41ZXx7AoeTGVv5h4nzDv/JTkfKJvZ5iZKw3q9AFTVzI7m0MtYeTcvao7Bx5/tLE2gM7J2ntxPtAMkZ6t/+KiLd/KwDoeRbTvPdcaVin9zVO+ujdYHU/YaAQ1phcax25/Kj0zfVKua05uvCcuJKyvr aQduuJJl EPNTmbC205gm2NlDzWxUS5a7kKXQgKu9yboBJ3/OU94ofLHyFHfF91ulkUmUlxGjXjDqCoPX3vkuSAMIIFYlDd1IMyDnzZwZf7wxnbvLqU8tCz3mZyCOx3Wov8NGVqMCJYSMA9+th+hmqAWuQg7v6OaPIywM+a6j9Szr6Asucillbpc+5PoX0sL9UO6gIxey6TglHyDJfv16oEy0NKxjzK+MUq3ts5LRHlAEPKGFsklOuS+Subh5mQOsn1XYASbOqkdbqWE3yyqvT54/mrIrqhbXQj2U0Hx5W780I4ZErPG30RdQFc4IeEvbGBzT7tgszdlOmrTFBDQ1JUbk6Yfaq0Jl4kvGCuSsuTqYkJqIK5Ycxxw1mZF0E80Nb7FkoB2w/5pTvkJZj1C1wPzlk2ECBAGj0U03LfxqnXPjFvvJ5hH5H1Hw/u2CBmNyFfxI3bFM4TyvNXMciIPCzWcHHIc4MzQunEnVMFTsES5zVwSc75J2T/AbbLUz81SWoE2mDPy5+obC3rmJaQOZ3oeTaNIvpQbwg3PabHWp9F+VkmIrfeSeFV0SwvYgzSj5dElx7FhiJF9xom33akEaN6kD4/UV8RU5PdvQT7eHTblXuiTBdHyEYHLyaqiStnq/pUFrSkDg821KPCZIPzQdOUag= 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: Hi Peng, On Thu, Aug 31, 2023 at 10:45=E2=80=AFAM Peng Zhang wrote: > =E5=9C=A8 2023/8/31 16:25, Geert Uytterhoeven =E5=86=99=E9=81=93: > > On Thu, Aug 31, 2023 at 7:39=E2=80=AFAM Michael Ellerman wrote: > >> Geert Uytterhoeven writes: > >>> On Fri, 18 Aug 2023, Liam R. Howlett wrote: > >>>> The current implementation of append may cause duplicate data and/or > >>>> incorrect ranges to be returned to a reader during an update. Altho= ugh > >>>> this has not been reported or seen, disable the append write operati= on > >>>> while the tree is in rcu mode out of an abundance of caution. > >>>> > >>>> During the analysis of the mas_next_slot() the following was > >>>> artificially created by separating the writer and reader code: > >>>> > >>>> Writer: reader: > >>>> mas_wr_append > >>>> set end pivot > >>>> updates end metata > >>>> Detects write to last slot > >>>> last slot write is to start of slot > >>>> store current contents in slot > >>>> overwrite old end pivot > >>>> mas_next_slot(): > >>>> read end metadata > >>>> read old end pivot > >>>> return with incorrec= t range > >>>> store new value > >>>> > >>>> Alternatively: > >>>> > >>>> Writer: reader: > >>>> mas_wr_append > >>>> set end pivot > >>>> updates end metata > >>>> Detects write to last slot > >>>> last lost write to end of slot > >>>> store value > >>>> mas_next_slot(): > >>>> read end metadata > >>>> read old end pivot > >>>> read new end pivot > >>>> return with incorrec= t range > >>>> set old end pivot > >>>> > >>>> There may be other accesses that are not safe since we are now updat= ing > >>>> both metadata and pointers, so disabling append if there could be rc= u > >>>> readers is the safest action. > >>>> > >>>> Fixes: 54a611b60590 ("Maple Tree: add new data structure") > >>>> Cc: stable@vger.kernel.org > >>>> Signed-off-by: Liam R. Howlett > >>> > >>> Thanks for your patch, which is now commit cfeb6ae8bcb96ccf > >>> ("maple_tree: disable mas_wr_append() when other readers are > >>> possible") in v6.5, and is being backported to stable. > >>> > >>> On Renesas RZ/A1 and RZ/A2 (single-core Cortex-A9), this causes the > >>> following warning: > >>> > >>> clocksource: timer@e803b000: mask: 0xffffffff max_cycles: 0xff= ffffff, max_idle_ns: 28958491609 ns > >>> sched_clock: 32 bits at 66MHz, resolution 15ns, wraps every 32= 537631224ns > >>> /soc/timer@e803b000: used for clocksource > >>> /soc/timer@e803c000: used for clock events > >>> +------------[ cut here ]------------ > >>> +WARNING: CPU: 0 PID: 0 at init/main.c:992 start_kernel+0x2f0/0= x480 > >>> +Interrupts were enabled early > >> ... > >>> > >>> I do not see this issue on any other platform > >>> (arm/arm64/risc-v/mips/sh/m68k), several of them use the same > >>> RCU configuration. > >> > >> There's something similar on pmac32 / mac99. > >> > >>> Do you have a clue? > >> > >> It seems something in the maple tree code is setting TIF_NEED_RESCHED, > >> and that causes a subsequent call to cond_resched() to call schedule() > >> and enable interrupts. > >> > >> On pmac32 enabling CONFIG_DEBUG_ATOMIC_SLEEP fixes/hides the problem. > >> But I don't see why. > > > > Enabling CONFIG_DEBUG_ATOMIC_SLEEP on RZ/A1 and RZ/A2 does > > fix the problem. > > But there must be more to it, as some of my test configs had it enabled= , > > and others hadn't, while only RZ/A showed the issue. > > I tried disabling it on R-Car M2-W (arm32) and R-Car H3 (arm64), and > > that did not cause the problem to happen... > > I guess this patch triggers a potential problem with the maple tree. > I don't have the environment to trigger the problem. Can you apply the > following patch to see if the problem still exists? This can help locate > the root cause. At least narrow down the scope of the code that has bug. Thanks for your suggestion! > diff --git a/lib/maple_tree.c b/lib/maple_tree.c > index f723024e1426..1b4b6f6e3095 100644 > --- a/lib/maple_tree.c > +++ b/lib/maple_tree.c > @@ -4351,9 +4351,6 @@ static inline void mas_wr_modify(struct > ma_wr_state *wr_mas) > if (new_end =3D=3D wr_mas->node_end && mas_wr_slot_store(wr_mas)) > return; > > - if (mas_wr_node_store(wr_mas, new_end)) > - return; > - > if (mas_is_err(mas)) > return; Unfortunately removing these lines does not help. Gr{oetje,eeting}s, Geert --=20 Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k= .org In personal conversations with technical people, I call myself a hacker. Bu= t when I'm talking to journalists I just say "programmer" or something like t= hat. -- Linus Torvalds