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: 13094272 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 5D7D7C54EBD for ; Mon, 9 Jan 2023 20:53:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC8118E000A; Mon, 9 Jan 2023 15:53:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E79858E0001; Mon, 9 Jan 2023 15:53:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D19A38E000A; Mon, 9 Jan 2023 15:53:58 -0500 (EST) 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 C30AC8E0001 for ; Mon, 9 Jan 2023 15:53:58 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 91B991C65A2 for ; Mon, 9 Jan 2023 20:53:58 +0000 (UTC) X-FDA: 80336462556.14.4DEFB7B Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf02.hostedemail.com (Postfix) with ESMTP id ECAD18000A for ; Mon, 9 Jan 2023 20:53:56 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FGVUXzbM; spf=pass (imf02.hostedemail.com: domain of 35H68YwYKCPcrtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=35H68YwYKCPcrtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673297637; a=rsa-sha256; cv=none; b=D3LAfTm9hBSBSLmrKOJHc7SxPuO9n/b/Nv2sxg3AhfJqlceHYTY0OimLaKWKwHaTEh+Hz5 Q64sW2jkUmJ7yVpRRS3R201V2y/NT+UZEpSX8aCm8m5QjlVJXAuDSvdAwRi3a9R6p+o4d0 UOX+ktToZW3BRSpCdgRNFEhVcR/F30E= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FGVUXzbM; spf=pass (imf02.hostedemail.com: domain of 35H68YwYKCPcrtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=35H68YwYKCPcrtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673297637; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tpY24U65dxDevik5396IsQMXmVZXiLzmW2j6b7ptC2o=; b=8BDnCJ9FqCpwlsdPKVuprFDAVAbKMkUkVWgtnfwKfPSbjsYeuFC6ZRpIsfHChtlUfLcSdA HkXQqLiNypgsFsHYnLUNpzdx67T2yDtOC0TH/M8c8PCcY4fBAgS5XSFJ4RWsPiL+JVB5+f /QISsxaIyLKVwb7u+DdkSJyjsfs1JN0= Received: by mail-yb1-f201.google.com with SMTP id g9-20020a25bdc9000000b0073727a20239so10199864ybk.4 for ; Mon, 09 Jan 2023 12:53:56 -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=qzdBiQsZYembzc/PrLvhk7ZVRjLawfbPj/5GcoUnaeOn9CY/SiOjqZT8s1vnsI9DIS N0Dzz0ERmGujYpiJJHUL2XbbVhQKhLB7B5qAYt2FJ2iPdgaPJepu+IgYaVdGmhVcEKPz i/xY20ww/G6FCrVbWV3kjhVXQy5tYYw4/rFXzp6uO8MlQaXiaHFMfKsdhS2vvrHgzHqo u3V4yOQqfswOyPLMTxZdQMywXLlXPqIv8nERkD7A5yoUuvm2HKUDHBJEQ3W7i3nfV/I/ YC+HiX4S07CzW3vNj7e9DXqiuBKmWeKdEA9WIqmO4LvlvP1V4XRjMBRJM1Ba70lUzb7r zNLw== X-Gm-Message-State: AFqh2koLqMWFUxR1gpYvRA6GI4lmkBqiOZdwLxAod3lDa+/x5yS34ocZ dBfRO8NwSVWVT0PiC9GeY+f+o/GRWoU= 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-Rspam-User: X-Rspamd-Server: rspam03 X-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W3Vrn9lwBBq4LfJBXk82j+PatipawFeslbde1odd22qqyMQNCaVBhqO+Np8uXB/+nWjXs/b+SQYzpi1jSJfjnbJm1oA7zhXlqt+GAW+jU/XTZhRQ0xpQVHjGKqJR8Y7+py04jbQB4VvEvWE+SkuY1se6OwGAil558hKFu8rqyrubX0G6VE+uwjn3TMjXU+/MT6PqK3Ltnw/TFV421zqbWeo1MpkqGFY3shDooQjI+/ZBAw1hYq8r5vsJj43gI55LLjeaBaCPihHQyfHWUJNCWQS2LThE5agFm1pZT1S3pYtuTaLRdMPbv7Ll8rbzsTbkevRAi3E0Y2ZjUvvhw6l2UcUi/PGW7tX0jdCTkJ7DDRKvsv0nze/n6SrN6JtG+jS7zxGlaIvVAwWdXOu71Ipmslwx3ayv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); }