From patchwork Mon Feb 27 17:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153969 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 BB550C7EE2E for ; Mon, 27 Feb 2023 17:36:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 077096B0082; Mon, 27 Feb 2023 12:36:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E7DDF6B0083; Mon, 27 Feb 2023 12:36:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA7BB6B0085; Mon, 27 Feb 2023 12:36:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BE2106B0082 for ; Mon, 27 Feb 2023 12:36:54 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 82440A0ABE for ; Mon, 27 Feb 2023 17:36:54 +0000 (UTC) X-FDA: 80513777148.04.C26B60D Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf16.hostedemail.com (Postfix) with ESMTP id 9F72B18000B for ; Mon, 27 Feb 2023 17:36:52 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J5wmcAzy; spf=pass (imf16.hostedemail.com: domain of 3NOr8YwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3NOr8YwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.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=1677519412; 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=SQNoSLNi/WgstuG55kXE7+m1dHKl+fKKDPrkCWl/DCo=; b=gusseYEb66HRvhGrNWw/KT5rRKgvter5whv/6zCe3ZnMSsED0UAX6lu73U9hg72eIs290P ceotOeZL3gaJQg7N3rjciBf78H23QdXwwnUkQAP9zGI8pXm64SnvIoB2H71BXCrj8BEuRy rnV26CzqLcUyaD6xzz9mZMEPyR9drHs= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J5wmcAzy; spf=pass (imf16.hostedemail.com: domain of 3NOr8YwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3NOr8YwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.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=1677519412; a=rsa-sha256; cv=none; b=0Jf4AwW0XzxNcoYzSTUy5WqyWU6B7KoaH9kWYbiZE3T/LeRXgmPp9fFHnL1QtC5ya8bn3V Zbw7Ouoc4kKnKroAyRKDad12JKE8Pb7JV2ioGMWGmrE+cag4QfoSkYqxeq+wNDPaOZ0XrT dCQ8SLrq0B/iGMOitZmwFIP5nNVWyXY= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-536bbaa701aso152703017b3.3 for ; Mon, 27 Feb 2023 09:36:52 -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=SQNoSLNi/WgstuG55kXE7+m1dHKl+fKKDPrkCWl/DCo=; b=J5wmcAzyDZcatSwztTuxgzaYtke6kriIvYIqPT/BFwSZWL+3VmHsJK6pm6uqTXXs0k hQBQeTTqtZMXoydWH2EraS1BwJQMWApBWO4fGke8/Jq0OvUOu4cfdsRQ8dDM68VxgizQ ztRQr+1fezpVtAc0lp78wCnDR/PHSs/vBVo6WXbM19HIw+eJAf+OKImpXbbC44F1OdAA e9ipoEkHKuhTw98suQdXekAHWIPjjRBuGbOkaPOXnZpP2dJYchLjizYibUTfDcgNqsor BtPgKlPExQUuIZmGBr+b23UCrNVwj01MSEdyN/KRD26rWer10z6tKSB96K/CBsjdr3nr Dy4w== 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=SQNoSLNi/WgstuG55kXE7+m1dHKl+fKKDPrkCWl/DCo=; b=eLiK6XXxCFok9zQY/Z0p0ANbfc2NL4+bxk2kOtDTkEwcvIvDt2/Ly3hZ/igZqnYXFR Yoe5Vl7iOZG2Iy2qyNFlcNvC2pOYhqlNKO7qxPt9PyI5WfygfW9yzJIxRoNnso2S7ik2 GNt/fWHRGhp2QGjrbUsxNz2qQ86CDBr2pggHB+Snfn4SNdfTBBgWrbS7gfJJqFnawpeD F9PChhGst2yRECMFtGjO826p5TJnxvw6g2T+YXgbWutUgE/I+DcgaXgMgub5C26Wec3f 6XwJncI7qFiBl02bEAU/w0wtDyt1VW1VXzzJM20EwhHqvXP9MG1IrlNyh+xxqfJgiw00 WhNA== X-Gm-Message-State: AO0yUKU2vIxO0uk8I++LF3iDyp+RyxPBP+8Jp46YoPy4wz2KtYfkr7Qj MJenTgkzB1iBn547hD41YpIrMaI3QyM= X-Google-Smtp-Source: AK7set9MzLoXjLMA6aezNIGpaaorfvcTajbjU3PQe8ye5Rv3C1xsvBgDWbku9hWg2h6JXcwKW/yoJy8kVAo= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a25:e805:0:b0:a5f:0:bf12 with SMTP id k5-20020a25e805000000b00a5f0000bf12mr3637071ybd.13.1677519412049; Mon, 27 Feb 2023 09:36:52 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:05 -0800 In-Reply-To: <20230227173632.3292573-1-surenb@google.com> Mime-Version: 1.0 References: <20230227173632.3292573-1-surenb@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230227173632.3292573-7-surenb@google.com> Subject: [PATCH v4 06/33] 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, paulmck@kernel.org, mingo@redhat.com, will@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, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.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, "Liam R. Howlett" , Suren Baghdasaryan X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9F72B18000B X-Stat-Signature: 9utrq9b1hh95acrybxx74tawumyyn3qs X-Rspam-User: X-HE-Tag: 1677519412-999791 X-HE-Meta: U2FsdGVkX1/IPHMXCLcxJoIKEHIid4YV5RlOu+QprsIVZcUOrBvx3C4cewVxv1hdnkivvWMSUu5YEbO3t8DNSop6GHo+MVVH6u3ybV7wrrht59KZqJzBTzPA8P6nhis1V4svcTBNdDztlyYePOM/J5rdGkAxg04I97BVU01lUtzYwhgyUrG8rYMMmjR35IpVtwDUfEJIw5YvbP+C1d6+dDFUpnx+TT1ux+8ogXnl6T3E95SkmNc/3TWfJsM5mRNm0EY2usigCytsbJH2nbJoXM+vESb6v5pK0VpSBrVS8FRvjOBLNFHy8yQxRiyt6XFelOYbzoeipeuj6wN6oPrBzYaSXAJTmscEXPfr4pkQnhGySq09/rqKYZW5p6Hw8/RILiFGc77bQQOhXGh5ZXA6FhfM5uRZkO+COBroqce3muTSEFMV52p3Z6riqfJmiyfMZoEk49CH3kl4I0+zu2nDFwijpGujk8IvQrlqAbBYn6366C4CKEo18K7xsb5VlYtoEyuFWRcrHLTEUuaIp+1dTYrKyQbG3q9i9k1ZFOkNNBoaWUjXhztu4I48gqZ0EZQjeiS7xd6N97wgea6QQHs6+3Yv4kMclhlKLU/lSkFZs5wsxpEtXMFwzkgN3ck+PB1SFMaFGvuE/FdBsTcPxnnhdNSTIopX3j1UW0IAsbDOE19xjMLQ03nhymr3CsJUKXmvdb34ZHJGYWgEwjtay2IXUOaXXErD+/nYEBpVN0fwsITyre2xHFw80YAjj3r3VTwMLEHsCpWZ4ztvBGyScoFRPq8lvXuQQ16QGiVnQKb92YePxuuL20GToihrCzBpxK1CsnZqYezucConuEYC8yi4r13LEdxG8S4WR1B14YNptsKOwnAaYGv6T/5gmfXkpYPNEix5dZRPDAs5AXTUBS6pzzWX02XZ8fBRuhaB77nMQnDqoIlUL09zhJrwf5fgJxrxM3ZVJ6GRJSnQG4fkvkN 2TtSu31C DhoC5lBAfFsBvceOQuIKVw7rqD4KdPd0vlx+Kj/hcvEje5sMsJJQOhBLjlaXAcwsnSuQUf/hxgeHZmRt1F95l5x5/xzfw+kQDp2gw+Gjfjen9C0fMmqsv3DmnXS4GqWrbbtQPb2TjZFbhKkwHMKAIfPoZ2hU02r+dbS1zmSZHcm1N7VB+cor6pfVH6dI6uwgtzSqqTatnauF2J3lwCG9u+4di2xhCOy5pc1KzJ1VAzyFBjO0Z8J7WMxybta1fee00DisWWFtokfP8pAj9LF3DYpC/TQ5rKtclTo+gd9+YpiAKzO93KWpAcAG1iP10dvL+Qvo2cOudNcZG4Na6YsYijbcAtT+NNpoNnjgUqnyPsEYJHzxslOc+2KTJ9/AKkiV+6gysKqklz9smPrKGqSZKh19QltGb2rd+F2tDw9dwAOR3uwjPob7bfTRs4QLGp3G6mcnw6m1wRSqqq/0/pyxgTMoO8kzHyNw0ufPQXOhGMOjPwZ7GIqAP6XP9mLurLAJ4iyqlEGth9QuE0wEZaGbuVT4xpZ7kxXBjNkB8RKOw1RmY/+Dt9mgtLTYZmljsmCvnmomD/FjNfA6uHkuWlatcYYMH4wHBIwAEltfXT90kEqUCHIZrQ8aflyFNopqbpD/EccUY2Ne5/eR1FDQLc9XT7U7Zj6Y/fPtrqSpbmSfmrr+qY7vPX2cbqpyyfMIbsEiKGIET 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: 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 6b6eddadd9d2..8ad2d1669fad 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -539,9 +539,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); } @@ -556,6 +558,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); }