From patchwork Mon Jan 9 20:53:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13094333 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E32D4C54EBD for ; Mon, 9 Jan 2023 21:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fKXpuiPV9ogXjhah4ndKGq2UvnwS7E+Gt/SNAEpWsQ0=; b=gp29u2JgGgouolxQmdb5Wl69HO boXugG+k2uC3r5LUeghQ9OH8rdGSx9AqM5bfXGQGepbbOMa2m5pAxxAGHCT8VoJHfTpD74ea5Nytk Z23waFr1KPzYemLD2NcKCfbq4nk+cIAdrgjwjjvDIP2X5GMLl3gS+pOKHZIDKdUCKCDCPgALPInmE AibUn09lpbthoeiwf8LOV6q2FjngiUWLvArihp3AhxZewWKKLaS2o9FnyiXuhVXZC0wr13Jx7nihW nZI++kT6sjhrcCNZrSLF3Ic1beiHFS3FsJkWN9cRelyB6lxQSIpbnRLNrpd/8bYrxY1Eck2iFUp14 8w3Pl+vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pEzTc-0048hc-Ga; Mon, 09 Jan 2023 21:14:40 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pEzSj-0048O0-76 for linux-arm-kernel@bombadil.infradead.org; Mon, 09 Jan 2023 21:13:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tpY24U65dxDevik5396IsQMXmVZXiLzmW2j6b7ptC2o=; b=KZPmVtvk6IzAe9kGOCjOH9znry qcFmUu9cVb+bcXqQDM8yEerKoMDxhckxveNDfdBjuIVu5rxRVeH+otPchDyFHpkn95fYhEO7oybsf tchCWlA+sDrjxCSu1fBk4oMe1NTzpEwbW9gdi6vu/zFr62NV5mHoBF3BHfVufPYHz2O/n0wyJTW+T ZQPP9bTeWbGohV0db2E9IFJk0g0/gDblklGzlINj+P7INslsn+xuoyt4HfSmREXmecTZmGmylqYyw IsNCxW5ulU49N9MR0vYRjHoHhzVSLKdXQ/gD7gma2PijMGGu83FnigtD2k+M9DcZYnsQyTx3e3VC5 piYI676A==; Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pEz9g-002sqL-3C for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2023 20:54:21 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id l194-20020a2525cb000000b007b411fbdc13so10388724ybl.23 for ; Mon, 09 Jan 2023 12:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tpY24U65dxDevik5396IsQMXmVZXiLzmW2j6b7ptC2o=; b=FGVUXzbMKsAgHtVe2H+ZGPByy9vTxmIYvrPV7ZuF76ZDV4PCOupJdRY2uHLiI7i+8R 4Fjm3rnOC/ry4DX8g5MN/0YQ4aHPdCQZYFwG7UcSZ/43mvYNjuR6DmjlzCEnl8acF7KD ERVaFO4iv0zgtEZ4MmYzhpcYCiFLTkatnznfDTOltPoYyw5CvEIb1yptgTPwDbjWQDix pGxXZ1tFpWIKQUAKj6j+gMffNX2JeuA3u7s8cWrwnHHzy9T6apLvHv6bApzCw3vZvb6B a2xiK595oO97JhT8ZQYkTmP/j11qoIyiGxI24X5jHCYtpJjinnDlcXs5UPFQKhdZ/Kdz DK0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tpY24U65dxDevik5396IsQMXmVZXiLzmW2j6b7ptC2o=; b=kwdekhXsliBVFmjkW/BHsztw2e0bKd0hltCBZDY5d8oFI16Lp5MKhQ9bdQCj3UNBKK UOJ661TbC79vt7JAMgk+ACXnuAnTc1uQud2z/glHpwcYrqmpPQLHU9NR3ez3BI6WICDz GsVlI+rnflS1fttZZvvz3kVoYFAy4M/FZ+GlaaGBdz13nj4+1qapHWvU3UwKy+EyJo/z w5VQpVBQF2qMywImmNePps0jrV7VKL+Gewa5dG9s3O2CdKuGFRuiQMl+avSJLuMlqpPa cFu1twTdEJa8mYgcDTMX6mXEzORpwxQ9w1dPEYkIuZGCfrCNdejZLP558ANOHvwQMbm6 cWNA== X-Gm-Message-State: AFqh2kpjeenJnUYlVa55ZNQt/QijlpoKTXHp2QC2UbxZjwsFU3nw/dfc iOPCt1rMkNGRYRSNEa6Fr7ruq97SB/4= X-Google-Smtp-Source: AMrXdXs5jnkdpf0WLGjSqHJja91Z23ecX2Os+zrAvpCFIdrfHWytTqhc2UPXUEbTUa59RZZK2SYuIAkg8gM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:9393:6f7a:d410:55ca]) (user=surenb job=sendgmr) by 2002:a25:2491:0:b0:7ba:cd98:5bed with SMTP id k139-20020a252491000000b007bacd985bedmr646916ybk.69.1673297636065; Mon, 09 Jan 2023 12:53:56 -0800 (PST) Date: Mon, 9 Jan 2023 12:53:01 -0800 In-Reply-To: <20230109205336.3665937-1-surenb@google.com> Mime-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109205336.3665937-7-surenb@google.com> Subject: [PATCH 06/41] maple_tree: Add smp_rmb() to dead node detection From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com, "Liam R. Howlett" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230109_205405_388754_A533AA87 X-CRM114-Status: GOOD ( 12.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Liam R. Howlett" Add an smp_rmb() before reading the parent pointer to ensure that anything read from the node prior to the parent pointer hasn't been reordered ahead of this check. The is necessary for RCU mode. Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett Signed-off-by: Suren Baghdasaryan --- lib/maple_tree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 8066fb1e8ec9..80ca28b656d3 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -535,9 +535,11 @@ static inline struct maple_node *mte_parent(const struct maple_enode *enode) */ static inline bool ma_dead_node(const struct maple_node *node) { - struct maple_node *parent = (void *)((unsigned long) - node->parent & ~MAPLE_NODE_MASK); + struct maple_node *parent; + /* Do not reorder reads from the node prior to the parent check */ + smp_rmb(); + parent = (void *)((unsigned long) node->parent & ~MAPLE_NODE_MASK); return (parent == node); } @@ -552,6 +554,8 @@ static inline bool mte_dead_node(const struct maple_enode *enode) struct maple_node *parent, *node; node = mte_to_node(enode); + /* Do not reorder reads from the node prior to the parent check */ + smp_rmb(); parent = mte_parent(enode); return (parent == node); }