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 14631C83F2E for ; Thu, 31 Aug 2023 08:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 637518E0012; Thu, 31 Aug 2023 04:26:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E5718D0001; Thu, 31 Aug 2023 04:26:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4ACBC8E0012; Thu, 31 Aug 2023 04:26:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 393CA8D0001 for ; Thu, 31 Aug 2023 04:26:04 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0125C80186 for ; Thu, 31 Aug 2023 08:26:03 +0000 (UTC) X-FDA: 81183717048.27.0AC5068 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf19.hostedemail.com (Postfix) with ESMTP id 2A7541A0016 for ; Thu, 31 Aug 2023 08:26:01 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693470362; 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=3gECEIQ8q4bEKdtz9WWubbyYY9T718J8FYjKOYpkjsQ=; b=lrMfHjlJbOy+v20d9n8dRfkjANLBPPaONc7WlyHPcrfC7SrC2dSi/Ay6pz+ijGsZMY9E1J wE3pHUwidgljyuVS3GvlCHyeyI25KsIUmhUZqy0eNIAwnibEw4/8YYUq3yDAvQSmRgTp8p ZgFmDDK7YQgFkxqms251b851oBlmR+Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693470362; a=rsa-sha256; cv=none; b=wpxjJl6eyX5pb2/0Md5OVHiva/Sd5vIgT8cBK72GghKDgSsTF0AkzTqUaRdqZprlgLzGAk advZ1ytdoR7IPg5YRavcLvfI8FbMZfAQVRPGK1d1jyjlpn6dldJb1Ja0F4H/zbT0GEXD5Y 7DSoywUlfq5GxL/KMRPs27Vrv2lGows= Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-59231a1ca9eso7226687b3.1 for ; Thu, 31 Aug 2023 01:26:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693470361; x=1694075161; 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=3gECEIQ8q4bEKdtz9WWubbyYY9T718J8FYjKOYpkjsQ=; b=AaIEW8nCAYcdo9ozVusdAVp/8XW60o+3C6TEeI/w4wCnikyXpZiQjRoIQgv0Brad8E YmAVakePvImFla6IGSy4o2Tp4Ul3xR/gzvV6qaQe7Wc/3TeuMT3NSXHaT3asSckMaNCm B25Bs7Wl8odQ159aA/srrja6siDbrh+yAxgXxVKPd9ifRrJG6zg4bnrq6HxUZ64lkIsC HpQgyYApjV831CnTCpFhp+xejQfiYxoWtR7P2CaIPML1e58BEa4ycv8MSSgAmiAh3Nw+ SXmuQmjjR2MxFBqeRANB8vYNbMpieTfjBHdCh6EJqLtRG4ayHK6vyYuje+gKedkA6oME i6Ag== X-Gm-Message-State: AOJu0YwlM0mWa7YBVj0Fd4JbuxLd/im7G/aFfx1XsZNZvOMCgzfHOkv6 4hHjbTZnnG8Y+p0L8qpd+QaBB3aOMltW6g== X-Google-Smtp-Source: AGHT+IFSZ0uZ7z/hwMRCJdI6MmUIkJAf/q02Hwe4lLJQLMOsCBCsOj/5YkXtHl5hp60skczYIN8f6g== X-Received: by 2002:a0d:dfc7:0:b0:58c:c4c2:d37b with SMTP id i190-20020a0ddfc7000000b0058cc4c2d37bmr4746131ywe.2.1693470361055; Thu, 31 Aug 2023 01:26:01 -0700 (PDT) Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com. [209.85.219.181]) by smtp.gmail.com with ESMTPSA id x184-20020a0deec1000000b00576c727498dsm277779ywe.92.2023.08.31.01.26.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Aug 2023 01:26:00 -0700 (PDT) Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-d7d50ba994eso344331276.1 for ; Thu, 31 Aug 2023 01:26:00 -0700 (PDT) X-Received: by 2002:a25:f50d:0:b0:d7b:5d30:5f80 with SMTP id a13-20020a25f50d000000b00d7b5d305f80mr4093448ybe.24.1693470360206; Thu, 31 Aug 2023 01:26:00 -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> In-Reply-To: <87v8cv22jh.fsf@mail.lhotse> From: Geert Uytterhoeven Date: Thu, 31 Aug 2023 10:25:48 +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: Michael Ellerman Cc: "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-Rspamd-Queue-Id: 2A7541A0016 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 5gwbxjfxzfiem8yqup7wqqte1nndcnge X-HE-Tag: 1693470361-764528 X-HE-Meta: U2FsdGVkX1+/W/42k3Vr1dsi83F44Vz8TJ1A0fSWN974hlbEFk+hhJGBZxknfVKh1KvHs3v/ljwPCGIBGsom2N+Dfs0Yp0LWyiEw4htjwo44yX/h+2vf++jDOTfsPOLsDunNaYVstwFbcyoqMUuzqxlG9+cjgKiXfU2jjkMXJxAVJal0FYbECyDj/JS7U3x5S4HixSmwlpZrb/TcY+BouUt28RLKfva9Ib5KohrvKzxB1+ap5Xxq8eL2Q0gmkMbDKkyXLR2b1uzswFid1jFq9G8C5KyAkYO3let5PK45D2UL7uT0uDNII0DGGUPN3ug0E4NlsjMzpGC7NvecT6KTsdMv4g4qZtjHys+rRtpsRABRelSLDCJwbr/N5Y/ZfBuz2F7eW1N53Ic+Zpbv9BM8ZoWCrc2N6SB2Dk8FftZaRYnUxJQbTKnYgLtSDLK8+ZjutjpSLv5N/LclPi2FZ88VltfmMtwSHfAovNXBYg/HyjFD+QvJRyS8PE89z+jlOKieTrfXqiO0mt7p3dsr/9RnvF589a5taibMwIPPmWTslvrPW6IA/7V7GBMGYY1IQ2cCXD4R7OVwq5+YuHdIEiD9GvT6wp3WyuTJg7O3VfZQGESTQk8Am8AiVN+hRts8cdXlOPb+r5p9+eap43YcoGdheKX//kX2e43izh5qCxYCKwAd7k4H6JaPfXuYYDKw+KS4NmzBM/ZP7pSGH5w6ZjKTWh6+G9PVDLLDodPOi0PUYv6dg67hvo0M07up/ZqPjJXLvPLgyHzzn0oSg+1ko9IjONGG/8tUSGravI5fyMFCiO/+mU+uXPycFuRbVyso73ooRu5GvMqsv5HHf7Aeh2J9UG/ANhHd6k86MeQI93xw0ENsw4A+6aBc9ip/IzNJf33+ZsLwsbnDo0WQWUj7WjaW9zKb53l5LBYiVu8HVq8IyLIAsEpABR1PLF5OkO9KCs/Osx+yRC+5kFnRufVzxyr 5Zw9eU0q af4BDwqsV/DmyemTxWbP8xIk4uaVc2UFyWD9EpyktqJKIP0BMECusQZA3y+HB/V7e7tjSXoYNyfkPXhNn2Gdqutd7pPxe2nH49n+mGwvN/hf2h1wO6CMkZ0+Sdkr/R6raZxWLtstEYqXs1YUGQUo2tC5iogD7KBZahEC2sAdipj7bue0mBVvknko+0e25mE7gnLKbMfL6qJgqVy4C38B5qkil+dRCrrZKUSVlR7e03qMOfxZdTiIRA/O5Rx1FUA98i+2DzEPahyZyg+kPf/4G9juNvrhlw68Es+/xH0f07DYWJzsFuOuAAW9VafGqfvJeLUfqyOsylQewhL8xvKFsKwLPzskPDpySN+C4AnltmuK7uCn1/nfkT3vRAh3Gv27uCtnFmj4eNogmFX9HI5Rz/HD12BuxuG1MrnvGql25roMAvBysh0IxBZv8xJVw6Ug8eihU2ADh0w+IPywKBgZpoh9R7FljeQrAKdD0X3c1814cNzNNJku3aaf8KWnsJGU0/Y+/58r203Pc+kgOitqxLHJfdcByvA9LTGvK1UMTMhoBxrUl6pUrqtgJIwYqrJJfxJkN8iaq7giivq7mCcUA2q2fGA== 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 Michael, 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. Althoug= h > >> this has not been reported or seen, disable the append write operation > >> 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 incorrect r= ange > >> 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 incorrect r= ange > >> set old end pivot > >> > >> There may be other accesses that are not safe since we are now updatin= g > >> both metadata and pointers, so disabling append if there could be rcu > >> 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: 0xfffff= fff, max_idle_ns: 28958491609 ns > > sched_clock: 32 bits at 66MHz, resolution 15ns, wraps every 32537= 631224ns > > /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/0x48= 0 > > +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... 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