From patchwork Wed Dec 18 15:46:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13913109 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 C2DB3E77183 for ; Wed, 18 Dec 2024 06:48:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91FB66B0092; Wed, 18 Dec 2024 01:48:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76A3F6B009A; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 439AA6B0098; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E8D9E6B0096 for ; Wed, 18 Dec 2024 01:48:17 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A1AC1160B31 for ; Wed, 18 Dec 2024 06:48:17 +0000 (UTC) X-FDA: 82907149164.19.ED6601F Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf25.hostedemail.com (Postfix) with ESMTP id CDEC7A0002 for ; Wed, 18 Dec 2024 06:47:50 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734504475; 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=iu0wCSvHGOTioJPqw7DFuRYH/gM4yKHJPZZS9oXegso=; b=sPCCxnvttyrIwwfThFk0vaRkknYBzwHH9olBRqm+DzL6ikoC9IjRpF1oJPAwsQcOFQKGnb FkVZIWWzsGuas0g7jtO3Eko26M+cvpvCaBokv69/bflNnATIffiwfBkWlVKJ1Thw50Y3fa g5ZBmOKqEhkIhSYsRMMTSZ6IoeJNu6g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734504475; a=rsa-sha256; cv=none; b=W81WGTj45qCbxX+8L42jKJJQyD07srk2SPsdHDuLLFtpz0DGM9Moj9lPhwRJyb2Nr/F0Sc 8yUb2AliBTHdOucThY6NjvzUQmVuELOqyKeeJrR1kvoieCuVw6fN50U5sdz8qUDezdRXY2 njgXZwoTji7/0B7plpXH1e+exIswyX4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YCklF4YPdz4f3jqP for ; Wed, 18 Dec 2024 14:47:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 1AB211A018D for ; Wed, 18 Dec 2024 14:48:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA33a4mcGJnxKU7Ew--.4083S3; Wed, 18 Dec 2024 14:48:08 +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, linux-nfs@vger.kernel.org Subject: [PATCH v4 1/5] Xarray: Do not return sibling entries from xas_find_marked() Date: Wed, 18 Dec 2024 23:46:09 +0800 Message-Id: <20241218154613.58754-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241218154613.58754-1-shikemeng@huaweicloud.com> References: <20241218154613.58754-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgA33a4mcGJnxKU7Ew--.4083S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZFyfJw18Wr15Cw43Kr15Arb_yoWrCF45pF W8GFykKr4xtr4UArykAayUXFWru34UXFWayFWrG34av3Z8J3WjkF1j9FyjqF9rZrWDZF4f ZF40v3yUZ3WDC3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPYb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxV WUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jfAwsU UUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CDEC7A0002 X-Stat-Signature: ds7pwf83pw13pqkxrpctt53tgk31a8hm X-Rspam-User: X-HE-Tag: 1734504470-978643 X-HE-Meta: U2FsdGVkX1/p+trJ8H/0YEj0hbuOb2qX8bxjski3tRkHtu0oBv6xTUMRM5HuUdlcmqbaUz4txOnl8bnMdD0ObA2TK8eImcfWMziAh9mcGmPNNVhzmbz+xGrShFJYqQwTs+9wyfjN09wFqRWYik5eFMhzInGMtomPu0ZRgGhAUZ92A0UJ0UCRYs54XRhiIXKZlpqqfZKXTOXuypeldHk5ZIiQWXVjhZkTxkq0sF9sJ6mwFtx9LO5aqgsIKU2wiLpenG6ebxmQSN+Y00tE3N+odBct5RuQwEDTX7fHIas5TaGZsEepxI2DXKb0n5wOh8ww8xddZ79e9QeTvStVnwT06YI5ZOWvilKgAkHahZabHCUnrwNMzSvIOcfXgdhWH4QQZARj82n42jdjA9xe8f6udqoHenvQzdxr4HIlpqH81BMNozkETHXB2cAlV2hYra9LYObt8aYjcDy66KurFu7Sei56KxAAvBiszTBoX8jisrYWXs52wlFjF/sFLpSM6TR0t7A+Td/Y8xwHuC1zHL+/kxFMqmo9qxwGYzxbJwfhZLw5a8SSgJejhXxhmeRn9+rzfK6DDvozp2s+N4k+kKeEQ1/zkWEy5B5eGuh5NCZDKZ2olNfB5+n/RS0IqfTBu0PiIJmy83B1wA3HoQlx6Xu/u++qagJOxxZ4PXgFkfp3ueXu6gqX8zYSkBt0FLyqh4rO+E/4dPqlOogWvhyczQM8kXXuJOa969UYFRxCECF3Z65LJiwAfg4dfNbTwvZ1zmRh1yegkKQ/7QrqZibkYcIRV5Y+2hGRU5nh49SZqEpgSmqppJg96blqTD6Ts+YSDX3dButGf0ewGAisBCUWq7kDy61exz/nFx/m7hW7vHalc93Y6wAer6KVqzwkOvuj+9t7A+glQxE6CXmDGbAxALVt04iZSK3DkGfmf0ugvr65N6PEMFWpzcnFefSUPs9LtfmbFl4vSRRrbU3tK7qkWG5 5A3uJ+b8 +MFPcCEAQx4SR0v7NxOoe/6inabSdPrxvMI1xUAuRz9f2BeLNfZ/ehDHmocAz/DWC7WtquTa5751elG9AV8rt4M4oNH765p/CYpiXVm/H1ObArC4e8ajz47Rp8YyAJh8xVkYU9PEz/LeO4izHUpcjHflbfp5dWoXdhBQSca4kCtIxLvwnzt7a/puvABtgEO7B78udeF51XrDA+/8BzfV/xpU9Qw== 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() or caller may use sibling entry as a valid entry and crash the kernel. Besides, load_race() test is modified to catch mentioned issue and modified load_race() only passes after this fix is merged. Here is an example how this bug could be triggerred in theory in nfs which enables large folio in mapping: Let's take a look at involved racer: 1. How pages could be created and dirtied in nfs. write ksys_write vfs_write new_sync_write nfs_file_write generic_perform_write nfs_write_begin fgf_set_order __filemap_get_folio nfs_write_end nfs_update_folio nfs_writepage_setup nfs_mark_request_dirty filemap_dirty_folio __folio_mark_dirty __xa_set_mark 2. How dirty pages could be deleted in nfs. ioctl do_vfs_ioctl file_ioctl ioctl_preallocate vfs_fallocate nfs42_fallocate nfs42_proc_deallocate truncate_pagecache_range truncate_inode_pages_range truncate_inode_folio filemap_remove_folio page_cache_delete xas_store(&xas, NULL); 3. How dirty pages could be lockless searched sync_file_range ksys_sync_file_range __filemap_fdatawrite_range filemap_fdatawrite_wbc do_writepages writeback_use_writepage writeback_iter writeback_get_folio filemap_get_folios_tag find_get_entry folio = xas_find_marked() folio_try_get(folio) In theory, kernel will crash as following: 1.Create 2.Search 3.Delete /* write page 2,3 */ write ... nfs_write_begin fgf_set_order __filemap_get_folio ... /* index = 2, order = 1 */ xa_store(&xas, folio) nfs_write_end ... __folio_mark_dirty /* sync page 2 and page 3 */ sync_file_range ... find_get_entry folio = xas_find_marked() /* offset will be 2 */ offset = xas_find_chunk() /* delete page 2 and page 3 */ ioctl ... xas_store(&xas, NULL); /* write page 0-3 */ write ... nfs_write_begin fgf_set_order __filemap_get_folio ... /* index = 0, order = 2 */ xa_store(&xas, folio) nfs_write_end ... __folio_mark_dirty /* get sibling entry from offset 2 */ entry = xa_entry(.., 2) /* use sibling entry as folio and crash kernel */ folio_try_get(folio) 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(); From patchwork Wed Dec 18 15:46:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13913106 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 97E2FE77183 for ; Wed, 18 Dec 2024 06:48:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 264566B009C; Wed, 18 Dec 2024 01:48:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ED0B6B0093; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B3A46B009A; Wed, 18 Dec 2024 01:48:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DB5296B0093 for ; Wed, 18 Dec 2024 01:48:17 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 93548A0BDD for ; Wed, 18 Dec 2024 06:48:17 +0000 (UTC) X-FDA: 82907149626.23.44F15A9 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf27.hostedemail.com (Postfix) with ESMTP id D8CA640002 for ; Wed, 18 Dec 2024 06:47:38 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.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=1734504466; a=rsa-sha256; cv=none; b=i2nacH3PTtnE6rwKyYmmBILK+NYA6/Jd9i9wbE8LjRwiOIsfNEeLcm0r314Q9fYGGFy4yq Luvczx0BSj4dza/bgWoueV84yuOK8GFjMiZoffrG35B4uBVJfWih5s8d39C7zWlCeH9vSj 92DxwlDpyAm+zcbaDLbFchSUrAAB4eA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.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=1734504466; 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=/AuXMPi1oysNhSY8PWEZnREB/gApuKSsr+XUbUwNOWs=; b=w9f+kZVo4lVMZfqfznw0gP5VejFObkUY/2emsWDhYON0VMVw+uCmz1PgxKnf43/mtlKke3 E9WcjiUirNPSJCaiTJDMDZu/PjS9jjNQ3Yf3N0HeSP7Oh/uoVduwWctDK+hBC9jjhEQNOZ F++7SH78f4iwEMb2rHUX3LhDmq7Psks= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YCkl76CB0z4f3lVp for ; Wed, 18 Dec 2024 14:47:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 666861A058E for ; Wed, 18 Dec 2024 14:48:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA33a4mcGJnxKU7Ew--.4083S4; Wed, 18 Dec 2024 14:48:08 +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, linux-nfs@vger.kernel.org Subject: [PATCH v4 2/5] Xarray: move forward index correctly in xas_pause() Date: Wed, 18 Dec 2024 23:46:10 +0800 Message-Id: <20241218154613.58754-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241218154613.58754-1-shikemeng@huaweicloud.com> References: <20241218154613.58754-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgA33a4mcGJnxKU7Ew--.4083S4 X-Coremail-Antispam: 1UD129KBjvJXoWxuFyUWFWxCF4fJF4DAw43Jrb_yoW5Xr1DpF WDKryFyw18Jr4I9rnIqa109w1Fg3WrKa1aqrWfGr1ftrZxGryqy3WjkrZ8ZF9xGa18Za47 CF48Wr1DGa1DJaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPYb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IE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9d4P+S7+kYzzaAMAoYuadA== 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: After xas_load(), xas->index could point to mid of found multi-index entry and xas->index's bits under node->shift maybe non-zero. The afterward xas_pause() will move forward xas->index with xa->node->shift with bits under node->shift un-masked and thus skip some index unexpectedly. Consider following case: Assume XA_CHUNK_SHIFT is 4. xa_store_range(xa, 16, 31, ...) xa_store(xa, 32, ...) XA_STATE(xas, xa, 17); xas_for_each(&xas,...) xas_load(&xas) /* xas->index = 17, xas->xa_offset = 1, xas->xa_node->xa_shift = 4 */ xas_pause() /* xas->index = 33, xas->xa_offset = 2, xas->xa_node->xa_shift = 4 */ As we can see, index of 32 is skipped unexpectedly. Fix this by mask bit under node->xa_shift when move forward index in xas_pause(). For now, this will not cause serious problems. Only minor problem like cachestat return less number of page status could happen. Signed-off-by: Kemeng Shi --- lib/test_xarray.c | 35 +++++++++++++++++++++++++++++++++++ lib/xarray.c | 1 + 2 files changed, 36 insertions(+) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index d5c5cbba33ed..6932a26f4927 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -1448,6 +1448,41 @@ static noinline void check_pause(struct xarray *xa) XA_BUG_ON(xa, count != order_limit); xa_destroy(xa); + + index = 0; + for (order = XA_CHUNK_SHIFT; order > 0; order--) { + XA_BUG_ON(xa, xa_store_order(xa, index, order, + xa_mk_index(index), GFP_KERNEL)); + index += 1UL << order; + } + + index = 0; + count = 0; + xas_set(&xas, 0); + rcu_read_lock(); + xas_for_each(&xas, entry, ULONG_MAX) { + XA_BUG_ON(xa, entry != xa_mk_index(index)); + index += 1UL << (XA_CHUNK_SHIFT - count); + count++; + } + rcu_read_unlock(); + XA_BUG_ON(xa, count != XA_CHUNK_SHIFT); + + index = 0; + count = 0; + xas_set(&xas, XA_CHUNK_SIZE / 2 + 1); + rcu_read_lock(); + xas_for_each(&xas, entry, ULONG_MAX) { + XA_BUG_ON(xa, entry != xa_mk_index(index)); + index += 1UL << (XA_CHUNK_SHIFT - count); + count++; + xas_pause(&xas); + } + rcu_read_unlock(); + XA_BUG_ON(xa, count != XA_CHUNK_SHIFT); + + xa_destroy(xa); + } static noinline void check_move_tiny(struct xarray *xa) diff --git a/lib/xarray.c b/lib/xarray.c index fa87949719a0..d0732c5b8403 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1147,6 +1147,7 @@ void xas_pause(struct xa_state *xas) if (!xa_is_sibling(xa_entry(xas->xa, node, offset))) break; } + xas->xa_index &= ~0UL << node->shift; xas->xa_index += (offset - xas->xa_offset) << node->shift; if (xas->xa_index == 0) xas->xa_node = XAS_BOUNDS; From patchwork Wed Dec 18 15:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13913107 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 CBC35E77187 for ; Wed, 18 Dec 2024 06:48:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 480C66B0093; Wed, 18 Dec 2024 01:48:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 300DA6B009A; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1772A6B0098; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DA8AC6B0092 for ; Wed, 18 Dec 2024 01:48:17 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9813EC0BEF for ; Wed, 18 Dec 2024 06:48:17 +0000 (UTC) X-FDA: 82907148408.20.2EBAE3A Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf16.hostedemail.com (Postfix) with ESMTP id 57DB5180006 for ; Wed, 18 Dec 2024 06:47:40 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734504466; a=rsa-sha256; cv=none; b=U8/9/AiBFyecCfOxSsiIt0hXVO7nT0SGXAJiFigezerRRJfOwneOC4NFCPJbAya4HQugqp 4/TYQU6Y9HUG00/KQcvY++kj8HR76hMMKl5d0viWr6Zfo+p2vxCGuDFGx7dgHdV93sGY1P ozE2+0ZF16p1+11dnyqsAC8B40ufj4E= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 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=1734504466; 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=Z4BbOlZEkt/W5xNHqln4dcqe6CQrwVZO/98XAp4h3Sw=; b=j6eJW348WQkLEvuj+4zWMW89LHNnxWJmi9ut0jSmJ0igshz+cTgKA+pDu5KrR+NDaJetdf 5JX5WE2N9Iyr1iZWY/AklN1ajBvdE3vbRW2yVM4qs5oV710lqOhFevUg0Ci2GRLEXq3UgG e9lrS/nwGIEDu+TPqtGA60UDkLLmOJ8= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YCkl91nbGz4f3jMt for ; Wed, 18 Dec 2024 14:47:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id B958C1A018D for ; Wed, 18 Dec 2024 14:48:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA33a4mcGJnxKU7Ew--.4083S5; Wed, 18 Dec 2024 14:48:08 +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, linux-nfs@vger.kernel.org Subject: [PATCH v4 3/5] Xarray: distinguish large entries correctly in xas_split_alloc() Date: Wed, 18 Dec 2024 23:46:11 +0800 Message-Id: <20241218154613.58754-4-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241218154613.58754-1-shikemeng@huaweicloud.com> References: <20241218154613.58754-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgA33a4mcGJnxKU7Ew--.4083S5 X-Coremail-Antispam: 1UD129KBjvdXoW7GF1rGr4kJF1DCr4DJw1fZwb_yoWDurg_ur 4FgF4kZr45GF4kXwnxCF4rt340kFn0kF9ruFWUJr9xW34UJrsrtr1kWrsrXa4rAFyjyFy7 AFs5Jry093yUKjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbDAYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r1rM28IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kI II0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7 xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxV WUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jvUDXU UUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Stat-Signature: re558f68i5iu31sxnwu3rnf4dbnqgy8n X-Rspam-User: X-Rspamd-Queue-Id: 57DB5180006 X-Rspamd-Server: rspam08 X-HE-Tag: 1734504460-398136 X-HE-Meta: U2FsdGVkX19z9r7EuFDHSFYxEemJgaKhXzA3ADo0h/TeY8LzQsoRoCpehqUOLfTQsK/VGrnrTj+UijbiWfwcb4jBjwYdYCAr0kAHSVSmKzWt5QTfZIYezBjqNir4pxzfkXTzY6twgq+RQ49ZUNuCo1O+iFEdvBOZuiiARIWrEbYSeol/w9R172QsDdBY4LxS9+1G1FK1JdOATgTyiPgGEbtSMkifxxuQY6iMnomoA1894cziz1Qk4cri7M5T9mPhkNch4yhIY7gOEF1WKoiLRnNFBZ+LEhozp8C7G9WM1vqgcC/5582atBfoSjSBoOeH8na51r42josrZBeBCPHTwtYVramLin240qteycdeEnDOPhZXjLK4dt/hv6d1+ChlCfMopEru9SdNG2LQesHJkNPdYPQHAi2prLGLkls2Q2QhPnGvuIsLxAzuW8Sncadidi/sNjAAdBm90Nd/x9UIaJB+TSwIijxSWHtWI9tQHZVor4DXcR1WriO3vP9w7NyJQCyN+Mjl41dQKNgnBARDhEnxe04C7RkXV9+aV5KroQWxsJ6ufDl2DW+FkrrUWfpVM3rJlichFN06Ogqw8eY6LX7Ymk/SUjb5HJlti9HP6Fu1j8SFG7tXsTgLfAH5B9vfjPd2db72otFa8uCqZuVzpqVMAwJvk3vu88iAjQT41VszgacirQax0PuABGpcc/Vpl0f24HgFZW/gtnKQpgQ35qtQtN2mfIyb+hpW9+HA/VxpAfUGxAlIxt7XWWN5Mi3mmjjw9TTQNdG9lLJ3y43nCa5VGTlmLEzUOM/rhlnh7k2ZgytGlypyUeLFjYY4gIRRKrVVIvSCzqK04DESHsSJcxs38s0xtxjvvpNIb4AGaNw9UqTch0G/Jd7eXL9k/s5E6PxX3KEVy/DKgW4ZK7HmakwFOi5VPT8TJVqFSWGySC9+uXrsWlB4gCuWE6uBSsY5/2OQjryiL5jhwsH3cL2 UTPUB5Mg hIPwYM03hXItrxnMXZYKq37GBdgVDBliTCT+w07K/CSZYjwmgdVnYasiXuSTF7CG7Q/WZAkDfeIoM1xIR2KNwww/dRHmQoTPh8EJjF8Pw2pROGnXNSFl4UjsYk6qjSVg3kn90NMWSx9+DvR3XLX1Hp4qB/VI2xbewZPvrUa3ia5LeZ2bNB7HxBZPy9s9Ee3rjabKhTfq9vx9C+xQNLMxNBf8g2g== 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: We don't support large entries which expand two more level xa_node in split. For case "xas->xa_shift + 2 * XA_CHUNK_SHIFT == order", we also need two level of xa_node to expand. Distinguish entry as large entry in case "xas->xa_shift + 2 * XA_CHUNK_SHIFT == order". As max order of folio in pagecache (MAX_PAGECACHE_ORDER) is <= (XA_CHUNK_SHIFT * 2 - 1), this change is more likely a cleanup... Signed-off-by: Kemeng Shi --- lib/xarray.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/xarray.c b/lib/xarray.c index d0732c5b8403..3fac3f2cea9d 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1022,7 +1022,7 @@ void xas_split_alloc(struct xa_state *xas, void *entry, unsigned int order, unsigned int mask = xas->xa_sibs; /* XXX: no support for splitting really large entries yet */ - if (WARN_ON(xas->xa_shift + 2 * XA_CHUNK_SHIFT < order)) + if (WARN_ON(xas->xa_shift + 2 * XA_CHUNK_SHIFT <= order)) goto nomem; if (xas->xa_shift + XA_CHUNK_SHIFT > order) return; From patchwork Wed Dec 18 15:46:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13913111 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 17386E77188 for ; Wed, 18 Dec 2024 06:48:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E48656B0099; Wed, 18 Dec 2024 01:48:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B89BE6B0098; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A226F6B0099; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 814366B0098 for ; Wed, 18 Dec 2024 01:48:18 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 43537160B31 for ; Wed, 18 Dec 2024 06:48:18 +0000 (UTC) X-FDA: 82907149374.27.C7E90D8 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf11.hostedemail.com (Postfix) with ESMTP id F1E4240003 for ; Wed, 18 Dec 2024 06:47:44 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734504475; 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=bxIw4umX4p8FjSyJOZOfGED/8t0TaNg5KTYmBw60MZs=; b=n7I2rnsKj2wQMJlCBnL4el/08QhAqtpNgBwtNnPqIehOXeLpAWM07iKAtk9E/Dwu0kTK48 IzVBSckaLRbzc8reuTkUQlvmFEnv/FfBFb1bU/1OEsDRcXKRHtuaf8RzkTyaK+KgEweiCc rnHc2SkQ+PsDS7u5W6mez7PzaoCcNB8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734504475; a=rsa-sha256; cv=none; b=VdmJJZsVKbD0I9Z3bJK87bT0V67QVbFbM4i2s9IrIj+3yS336Dqw3RDeNK1qPHZMop7mcV +fOK/DqBOczmq1ioP7BV3ZcBFjML7neP8C3hpBCjsjod1KuSiveOT+bHS01APcZWj0o6nE 0G7tkBJFbOsgLQJVDkltIkJl8a+TMAE= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YCkl94J7Jz4f3kFQ for ; Wed, 18 Dec 2024 14:47:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 1B85C1A018D for ; Wed, 18 Dec 2024 14:48:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA33a4mcGJnxKU7Ew--.4083S6; Wed, 18 Dec 2024 14:48:08 +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, linux-nfs@vger.kernel.org Subject: [PATCH v4 4/5] Xarray: remove repeat check in xas_squash_marks() Date: Wed, 18 Dec 2024 23:46:12 +0800 Message-Id: <20241218154613.58754-5-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241218154613.58754-1-shikemeng@huaweicloud.com> References: <20241218154613.58754-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgA33a4mcGJnxKU7Ew--.4083S6 X-Coremail-Antispam: 1UD129KBjvdXoWrtFWxKF1Dtr4kXFy7Xw4kCrg_yoWxtwb_Za 10yr1vyr1UCrn7XwsIkFs8tryjkryvqF9rKFW8Ja43ur10qry5WF4vqr15Aa4kZw4ayFy7 JF45Zr1Y9r15GjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbqkYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r126s0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC 64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM2 8EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq 3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7 AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw 1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r 1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07ja g4hUUUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam05 X-Stat-Signature: mffohtc6hd7og6yu9qzjfe6m5orce9z5 X-Rspamd-Queue-Id: F1E4240003 X-Rspam-User: X-HE-Tag: 1734504464-438820 X-HE-Meta: U2FsdGVkX199Yebhp+s0AMkUSU/4bLN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9Jf7+9GWHdwM+iK5/uYxQd9lppXnEWFTRdAtC9HsZ1fgUZi8CzLKB1YWjv72sWL0c64t3PoSTDbdRdfgmETzw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Caller of xas_squash_marks() has ensured xas->xa_sibs is non-zero. Just remove repeat check of xas->xa_sibs in xas_squash_marks(). Signed-off-by: Kemeng Shi --- lib/xarray.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/xarray.c b/lib/xarray.c index 3fac3f2cea9d..4231af284bd8 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -128,9 +128,6 @@ static void xas_squash_marks(const struct xa_state *xas) unsigned int mark = 0; unsigned int limit = xas->xa_offset + xas->xa_sibs + 1; - if (!xas->xa_sibs) - return; - do { unsigned long *marks = xas->xa_node->marks[mark]; if (find_next_bit(marks, limit, xas->xa_offset + 1) == limit) From patchwork Wed Dec 18 15:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13913108 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 CD4B9E77188 for ; Wed, 18 Dec 2024 06:48:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C1266B0096; Wed, 18 Dec 2024 01:48:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C3266B0095; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 261336B0092; Wed, 18 Dec 2024 01:48:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E606E6B0095 for ; Wed, 18 Dec 2024 01:48:17 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 962711C6E28 for ; Wed, 18 Dec 2024 06:48:17 +0000 (UTC) X-FDA: 82907149710.22.4F42434 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf26.hostedemail.com (Postfix) with ESMTP id B3365140002 for ; Wed, 18 Dec 2024 06:47:49 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 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=1734504481; 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=YVrUUmNB/6qCylmXgGwaFI/+5BomZYbmrTRX2XpHfnA=; b=BdfVhKTexvo5NTOWfXm53GB4YOA7Pr5RLv3bYGTV/H90EyPsTe5csKujDlP+ogZRDsCfQo RLSGLJYHVjSkY525wSlHV6HSu0sA4cTz8fEb9bsqwsFG3hEKlcUlMk8TVTcY6mBqhBfv1Z eqIBNmhTHsnOv+UsqmliWihVk3RUP5U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734504481; a=rsa-sha256; cv=none; b=yxhS4YsL2mIgaF6AAOgwwEd0gybOlU6A+WKXPkj7mgkUHJrQpqf4Lg+XwSJ/8q3I2s3j0J Iqr/EEh5CmpZNOdKuoUSFCpRuaJH5de2vBYZ51IhOsuixrIpMj5UTx+qXTwsC1AWML4wgP jTD1OjX6ui4WAxp/IUOsEdExAJ2pwEc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YCkl96lq0z4f3kFt for ; Wed, 18 Dec 2024 14:47:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6F8911A0568 for ; Wed, 18 Dec 2024 14:48:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA33a4mcGJnxKU7Ew--.4083S7; Wed, 18 Dec 2024 14:48:09 +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, linux-nfs@vger.kernel.org Subject: [PATCH v4 5/5] Xarray: use xa_mark_t in xas_squash_marks() to keep code consistent Date: Wed, 18 Dec 2024 23:46:13 +0800 Message-Id: <20241218154613.58754-6-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241218154613.58754-1-shikemeng@huaweicloud.com> References: <20241218154613.58754-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgA33a4mcGJnxKU7Ew--.4083S7 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw1UuF13JryrGFWxCFyfWFg_yoW8GrWkpF 97C3s8Ka1xA3WUKrnFvan7t345Ja1kK3yjyr4xGwnayFZ8Gr1Yqay7tryjqFnxGFy8ZFy3 Cr1Fg3y5Wa1UZw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAv FVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJw A2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE 3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr2 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2 AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAq x4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r 1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF 7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxV WUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU s3kuDUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Stat-Signature: f3azzyj4g6h3mdqi9ajpwdiio9ty47pg X-Rspamd-Queue-Id: B3365140002 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1734504469-52535 X-HE-Meta: U2FsdGVkX1+rIhkne+v5wyIOngOQINB0L7YHsXP08OM/dfmtzmMV6Z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iAD2whPcA9UGf1wvtGW8s2ZWusqhVtXwlSZsM4+Wv2RseJ/6LRuZGUJYU5qFARJ5Eg8sbhyueNw== 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: Besides xas_squash_marks(), all functions use xa_mark_t type to iterate all possible marks. Use xa_mark_t in xas_squash_marks() to keep code consistent. Signed-off-by: Kemeng Shi --- lib/xarray.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/xarray.c b/lib/xarray.c index 4231af284bd8..a74795911f1c 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -125,16 +125,20 @@ static inline void node_mark_all(struct xa_node *node, xa_mark_t mark) */ static void xas_squash_marks(const struct xa_state *xas) { - unsigned int mark = 0; + xa_mark_t mark = 0; unsigned int limit = xas->xa_offset + xas->xa_sibs + 1; - do { - unsigned long *marks = xas->xa_node->marks[mark]; - if (find_next_bit(marks, limit, xas->xa_offset + 1) == limit) - continue; - __set_bit(xas->xa_offset, marks); - bitmap_clear(marks, xas->xa_offset + 1, xas->xa_sibs); - } while (mark++ != (__force unsigned)XA_MARK_MAX); + for (;;) { + unsigned long *marks = node_marks(xas->xa_node, mark); + + if (find_next_bit(marks, limit, xas->xa_offset + 1) != limit) { + __set_bit(xas->xa_offset, marks); + bitmap_clear(marks, xas->xa_offset + 1, xas->xa_sibs); + } + if (mark == XA_MARK_MAX) + break; + mark_inc(mark); + } } /* extracts the offset within this node from the index */