From patchwork Mon Nov 11 21:53:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13870698 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 10775D2E9E6 for ; Mon, 11 Nov 2024 12:55:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42E536B0092; Mon, 11 Nov 2024 07:55:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F8756B0088; Mon, 11 Nov 2024 07:55:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03C816B008A; Mon, 11 Nov 2024 07:55:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A2D2D6B0083 for ; Mon, 11 Nov 2024 07:55:07 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 642E5AC8FA for ; Mon, 11 Nov 2024 12:55:07 +0000 (UTC) X-FDA: 82773806640.20.E0E71BB Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf18.hostedemail.com (Postfix) with ESMTP id EC5A91C000C for ; Mon, 11 Nov 2024 12:54:44 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731329619; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2DK7vPaNmdtVaqar58Rue2/gKQZM3vD+yRmZcg90Pvg=; b=bbKPMyKKJ/aSNzBztLOacjXuLNjEf4WkM3CRq5yiQ/sElI6xsY8cdC8WpwIYhqS1Wpe0O9 bsZfgpzvuMKEAp3/NAfC2Y3x8GWcVZze8LGMrnvAT0OGlXcGvfeQkTmRhNL0fm1EkHHaiP Jp2pjklcKfXRcSXG++p02J5EQsNwDwY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731329619; a=rsa-sha256; cv=none; b=jgAgJkquvSuMbHRiDNZnZe66BvI//yLbajld9EdTRFBkgKGLGJnWyWrAUO0+IUBBT6Txzn 61uf7lTSBMmZnoNS2H/oyDm+asYwSj6t1y++UlvZwIA80F/7jytZhUDLwDWW6nx4oPj+L4 OOxcws/nE0x0GHk75bZCjjQ09DZczSI= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Xn8dT264Fz4f3nTB for ; Mon, 11 Nov 2024 20:54:37 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 559801A018D for ; Mon, 11 Nov 2024 20:54:56 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgB3n4Oe_jFnllryBQ--.36628S3; Mon, 11 Nov 2024 20:54:56 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org, willy@infradead.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH RESEND V2 1/5] Xarray: Do not return sibling entries from xas_find_marked() Date: Tue, 12 Nov 2024 05:53:55 +0800 Message-Id: <20241111215359.246937-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241111215359.246937-1-shikemeng@huaweicloud.com> References: <20241111215359.246937-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgB3n4Oe_jFnllryBQ--.36628S3 X-Coremail-Antispam: 1UD129KBjvJXoW7AFyrArW8Xr4rWF17uw1xKrg_yoW8KF15pF W8Ga40gF4xtr4jyry0yayUXayF9wn8XFWFyay8Gr1SyFnxJ3W0yr4jkryDtF9rZrW5Zw43 C3WFq345Za1DJw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPFb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_Jrv_JF4l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI 0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUswZ2 DUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: EC5A91C000C X-Stat-Signature: 7bu1b696myiiiaxouaoxs4z11cb6bt1d X-HE-Tag: 1731329684-587693 X-HE-Meta: U2FsdGVkX1827dfuwNlJpFqw5Ep/8GaF4L3EfOIN5VUfzlAgNH1SskOE+SdnjAA5prjGcQqdRCf1DCbwB5WW4BE77dQzeHIXAFAy4MCAp4BWi9wS02AHv7praAiRoIrZzQwH54RB0leudpxOq8OtxPlDWUirpBjOgeK6QRl3Uyu9cSoNkliphF2Qa/oOLXzYtlsMqUjGP4i9iSdhZqq6a/OSPa7/H6ZP5snR7xun1gpn4HRWBC2QtxphXCwhG/RfeuAzjMMmQOLi3JNkH/0AoGPp0tqKkOu1ghzs2n/PYrEkSWhDF6P/BeU4c+kZBMOisFUgJiYjVRzmB5+QpCzLevjBMgKj6ufD42SCl6qykmqhoB4lnZuJYXiwLFZnulTgxoBCAkUOe7bb0onDC2qEr6o3NyNbH7pd9xjsIeaoHMrOA50ZMUqducj+kYdyT1ZyuiHsMRRhyBqtuKGpiAmFgcs17UTzCxxnFWDjCLqXuUgGscdG64JSaUNCighfY4Sdw0gdq2Wjh3aQNxA2FgkK7lVugjBpGiuEKO6MB6ZFc30nzYnJtLiYEM22OWBfnfGN9NyrTOpUzvRWvpuIQh8YnszTr01vg7ycgtOoQXWC8A/9iEbsF9sbzsvAwTUfNPX2gqI5fn0rZYqNDSrpuwoBTHQqvNRkUHT5toMPhtjGJ05cGF3qjYFk93BHWR7lBDledQUKxSCbLM0/6bbyi9UEmoA2dQNb6bnQ2w3pLVh8HTqvvzH4t/t4++H6R5AkxRKSe14mfkeLo/03arXiuBxVYNltR/vc4hu95AdLxkjiqbpmD4aY5Eh+PfBKxgi2CyaoUXeVNQ0XZcP7YMbufeC6M+lBUrXh04v4OEmOc/TNQ4QaVAewQ5syNuXDbDiCoRQEgwT15HQeRugO7thzCH1JeKwdjgqthCDBke4ZvngA+2Uwmo56LAmK/LcD6UnTD9d0Ywydtd/y8+4i4VAQDHY 8BWH1U8+ RVjZ9ggciF1c0e7iieMaL/eTFrik3ADpfLt6e8RxX31SOuRTR0DKxQGDSGN47QUaqTi1Oe5cqDdpRLWVcpcUFBvaw8UsHADXBukYhGx7/nwFBVqNcj0IYnuH66Q5st8u5m4yIPICIRgabWN97RMM5W+bU6CE0KEYwRQkbDLmfSFQnTU7/A6GN26G5yI6XpUFTnH06skhlP3ZIYvzB9GttFIjqHA6ZmlQLJkpT4rQATgDGrcJlPOSLGTKct8PgINWHtdOmEKxhXtivNTTRlEJ9cJFr0+xgVV/RdKFbi559S4wlZEcauN+QuAwGV4HH6bpyo9Xd 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: List-Subscribe: List-Unsubscribe: Similar to issue fixed in commit cbc02854331ed ("XArray: Do not return sibling entries from xa_load()"), we may return sibling entries from xas_find_marked as following: Thread A: Thread B: xa_store_range(xa, entry, 6, 7, gfp); xa_set_mark(xa, 6, mark) XA_STATE(xas, xa, 6); xas_find_marked(&xas, 7, mark); offset = xas_find_chunk(xas, advance, mark); [offset is 6 which points to a valid entry] xa_store_range(xa, entry, 4, 7, gfp); entry = xa_entry(xa, node, 6); [entry is a sibling of 4] if (!xa_is_node(entry)) return entry; Skip sibling entry like xas_find() does to protect caller from seeing sibling entry from xas_find_marked(). Besides, load_race() test is modified to catch mentioned issue and modified load_race() only passes after this fix is merged. Signed-off-by: Kemeng Shi --- lib/xarray.c | 2 ++ tools/testing/radix-tree/multiorder.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/xarray.c b/lib/xarray.c index 32d4bac8c94c..fa87949719a0 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1382,6 +1382,8 @@ void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark) entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); if (!entry && !(xa_track_free(xas->xa) && mark == XA_FREE_MARK)) continue; + if (xa_is_sibling(entry)) + continue; if (!xa_is_node(entry)) return entry; xas->xa_node = xa_to_node(entry); diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c index cffaf2245d4f..eaff1b036989 100644 --- a/tools/testing/radix-tree/multiorder.c +++ b/tools/testing/radix-tree/multiorder.c @@ -227,6 +227,7 @@ static void *load_creator(void *ptr) unsigned long index = (3 << RADIX_TREE_MAP_SHIFT) - (1 << order); item_insert_order(tree, index, order); + xa_set_mark(tree, index, XA_MARK_1); item_delete_rcu(tree, index); } } @@ -242,8 +243,11 @@ static void *load_worker(void *ptr) rcu_register_thread(); while (!stop_iteration) { + unsigned long find_index = (2 << RADIX_TREE_MAP_SHIFT) + 1; struct item *item = xa_load(ptr, index); assert(!xa_is_internal(item)); + item = xa_find(ptr, &find_index, index, XA_MARK_1); + assert(!xa_is_internal(item)); } rcu_unregister_thread();