From patchwork Fri Dec 13 12:25:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13906410 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 EAC29E7716A for ; Fri, 13 Dec 2024 03:27:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 322DE6B0089; Thu, 12 Dec 2024 22:27:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D2A26B008C; Thu, 12 Dec 2024 22:27:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1752A6B0099; Thu, 12 Dec 2024 22:27:20 -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 E6B686B008C for ; Thu, 12 Dec 2024 22:27:19 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9283C43459 for ; Fri, 13 Dec 2024 03:27:19 +0000 (UTC) X-FDA: 82888499652.18.47EB186 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf03.hostedemail.com (Postfix) with ESMTP id C3F732000F for ; Fri, 13 Dec 2024 03:27:03 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.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=1734060411; 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=/b9Tn8mDfQuFCxPT50kx4ddB+W+6Fci8uTCYUWKol1M=; b=fw1M/hV09F0Q2Ly+kPEMJReO0XIAjZg9VKXfQAA/+3xFISiNUxs45z0lnvz0oXX/j7/NOY 60CS/BB7YqHLS2u4JfYHdwMDE7IFRp88zfYOTX4Ii/1W4mT2X9uoMcY/+NFtsOVQguHkbi ZxYbD6tQIeI5j4ncbgFpRTPYGcEnH4k= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734060411; a=rsa-sha256; cv=none; b=7vbPlO2joK+dU+9PwCx+f5KZvWaXzf2M0Dooj55A1V0WxgbAA0mDiNSeQu5Ph6h+ta/gd9 jLIIzE8Aql2t5/nNWMHj3ses7//g9QwiIGj3veB5bPpWp8ROpqKV2/MwaJrLNJuyIOTfuY yzpsjcB6KkgzTe+ubY8F8HNgFFnEd4Y= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Y8ZWg4QDnz4f3jkk for ; Fri, 13 Dec 2024 11:26:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id E81551A0568 for ; Fri, 13 Dec 2024 11:27:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgBHcISMqVtnfJ3KEQ--.55430S3; Fri, 13 Dec 2024 11:27: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 Subject: [PATCH v3 1/5] Xarray: Do not return sibling entries from xas_find_marked() Date: Fri, 13 Dec 2024 20:25:19 +0800 Message-Id: <20241213122523.12764-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241213122523.12764-1-shikemeng@huaweicloud.com> References: <20241213122523.12764-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBHcISMqVtnfJ3KEQ--.55430S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZFyfJw18Wr15Cw43Kr15Arb_yoWrCF4fpF W8KFyDKr4ktr4UAr97Aay8XrWrW3y8XFWSyFWrGr1ayFnxA3WYkF1j9FyjqF9rZrWDAF4S yF40934UZF1DG3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPjb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_Jrv_JF4l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28E F7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F4 0EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_ Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r 126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AK xVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr 1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxUswZ2DUUU U X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C3F732000F X-Rspam-User: X-Stat-Signature: iqkx17xgf5x11e5xr9q7ge435stf1wi1 X-HE-Tag: 1734060423-727125 X-HE-Meta: U2FsdGVkX19qnj0gF2AffCy80SAg7wIkt2gtyZhZsRlgCSTBUF7187F+GmKxsyOpap4w7V+9j9NwCYsgDsAsH2xAMxuXG51JS8ZzuCf0/Nq05BUX/FGnfJ+5+KknpSnymkSk4Y2exd5Hw97cfRrSdRn/hMqo6ci6obuyYk8HnFe8SvfZQOP/FXsWkQdWNJf472SBkc0ic+dYwbaUALSlKu45J7KdHV40rGIJJP+fJJ/PlPjapOU0m/o434B63S/nrtxxf9FwPp0RW4VP59Gs00wQqQagPYr74LtUi6HnZIpaKji0SfElXAx28rT2t16p9/sIY8WmcUg4x0UuPH5/a17sApzDAAkfIxwxSTweD2kmvPEAh6PzTxKsSZmiDA83P3UjrJaq9ajfq8dsJYYak5qJklhfzXvfiXMHAech6Fct02pdJPNPcS2tbqlXbXdAxbOnu3zB+lvSeYPgU0f0rePv5UfOZg7DT3RoDhQRA+XfxR7hX8EN0jpnJazghedivecduma9YGs+O67K5EWL5Mzhvx+6wt/zFVB5p5/NxXqUzpOcUtPAlXwuq+al6Wi3H3As8UTOjZg2bx5QrmmMISETwDD/v6GKGSl1zws8KFHmssGFmseLkAnnp5LYRjKsIK+aVQdOwKVk+S6Wbflhd7ENLE5ddAFVGsS02NtYSaKERw9UokPtNSXZs6BCJtUDrVSiQJo4dhJh8/aWmWHZP2mnxuuEBtIFeJ7qA7wzKd+8Q3BzFZngUYbVKDLOks1toNCWStJaY+0okVzx0yCDj2kNTib6sYdaS8BrM2NCGGkvwNYs/lyrhcHkhOeqx3FKFX7bYxxTbUE0NCaBjXKQJWm6ZSkk8qOjwprAQe0irvpQ+hbdUp6u2eIxm7GklbhomLJgS/KGa1KWckCVmeaXbKVJza8BVeL1s1tQ+ozSxeBQWX3G+Pyl+19VoWH7J7ikDtjnOS8OVf1Lnq/t19l WY28620s QfgOz/5ZZaz2NE2umaiOJs/dWFDX59NE65NkPPRlRlRDF5gtpDhAMGw/z0vQ0hRUKjp6IiPmz6APFVgV71SNyntoEE4jpHxXQDg37lFY4MGhMaDCCAVLfdaEqLyBOFGF1WFjWPdYZ/EFT1UkTVX0Zyn6SusOoGaHPVBQLe+SCVb9YB5yFsXX7LcY7sl3gFzrYBFll84jyDgr4UOXkHZDyAIJqgQ== 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 tmpfs which enables large folio in mapping: Let's take a look at involved racer: 1. How pages could be created and dirtied in shmem file. write ksys_write vfs_write new_sync_write shmem_file_write_iter generic_perform_write shmem_write_begin shmem_get_folio shmem_allowable_huge_orders shmem_alloc_and_add_folios shmem_alloc_folio __folio_set_locked shmem_add_to_page_cache XA_STATE_ORDER(..., index, order) xax_store() shmem_write_end folio_mark_dirty() 2. How dirty pages could be deleted in shmem file. ioctl do_vfs_ioctl file_ioctl ioctl_preallocate vfs_fallocate shmem_fallocate shmem_truncate_range shmem_undo_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) Kernel will crash as following: 1.Create 2.Search 3.Delete /* write page 2,3 */ write ... shmem_write_begin XA_STATE_ORDER(xas, i_pages, index = 2, order = 1) xa_store(&xas, folio) shmem_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 ... shmem_write_begin XA_STATE_ORDER(xas, i_pages, index = 0, order = 2) xa_store(&xas, folio) shmem_write_end folio_mark_dirty(folio) /* 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 Fri Dec 13 12:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13906411 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 EDF3BE7717F for ; Fri, 13 Dec 2024 03:27:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 654276B0093; Thu, 12 Dec 2024 22:27:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E2E86B008C; Thu, 12 Dec 2024 22:27:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 236A16B0098; Thu, 12 Dec 2024 22:27:20 -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 E32C36B0089 for ; Thu, 12 Dec 2024 22:27:19 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8F556160B13 for ; Fri, 13 Dec 2024 03:27:19 +0000 (UTC) X-FDA: 82888498392.20.069B42F Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf07.hostedemail.com (Postfix) with ESMTP id B8D6E40007 for ; Fri, 13 Dec 2024 03:26:44 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.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=1734060414; a=rsa-sha256; cv=none; b=Ds4WPeDLgLt8AOHGmgM6VUmUDoFwkW++5Ip1vCgwqJeHcdpOKRdhhQlvTZER0+iTaKyfnx go7kj1UBoK8qCIGbUR3hrNAF+FpG5Jb7EYSHDmzCs70xnxOL59H7jMHgUp5qGHge5fIElE iKPy/MtXecYomJn0eEQ+ofTKaprPWKc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.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=1734060414; 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=7L6dmbEg+sx39mraRQ8HzmSvhK4fFRhPIEkSWs1WXQdk3RkwPMHQMNRQekgizMFAkJ4zwr PTwtZU6ngdczZlI7gkX1cn4bucqPxtw69OBWsPbNi24H6Pfu5Q4quEemgWC6dVOz+xyWbu UACYcTqNkw4HbAQ/PDYRye5y2+G+fBU= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Y8ZWZ6Hlyz4f3jXt for ; Fri, 13 Dec 2024 11:26:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 35F9E1A018C for ; Fri, 13 Dec 2024 11:27:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgBHcISMqVtnfJ3KEQ--.55430S4; Fri, 13 Dec 2024 11:27:10 +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 v3 2/5] Xarray: move forward index correctly in xas_pause() Date: Fri, 13 Dec 2024 20:25:20 +0800 Message-Id: <20241213122523.12764-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241213122523.12764-1-shikemeng@huaweicloud.com> References: <20241213122523.12764-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBHcISMqVtnfJ3KEQ--.55430S4 X-Coremail-Antispam: 1UD129KBjvJXoWxuFyUWFWxCF4fJF4DAw43Jrb_yoW5Xr1DpF WDKryFyw18Jr4I9rnIqa109w1Fg3WrKa1aqrWfGr1ftrZxGryqy3WjkrZ8ZF9xGa18Za47 CF48Wr1DGa1DJaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP0b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28E F7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F4 0EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_ Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r 126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAF wI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc4 0Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AK xVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr 1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU0K2NtUU UUU== X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Stat-Signature: 8zt89qji1djyw1cjkmqebwpqg4a4jgkt X-Rspam-User: X-Rspamd-Queue-Id: B8D6E40007 X-Rspamd-Server: rspam08 X-HE-Tag: 1734060404-714107 X-HE-Meta: U2FsdGVkX19d73hJHiRQ3vXTVdQsM/JwrcGIOie5NpRPkvxEx4NyCdPRdhcZW8EBzwZynyQNKxFFzzK2POtufc2+zk5rYxAc2GGM59hHd7ltL8PATp6EIZu7y2poaKqSZYqV6R1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=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 Fri Dec 13 12:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13906414 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 1B0E7E77180 for ; Fri, 13 Dec 2024 03:27:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FC1D6B008C; Thu, 12 Dec 2024 22:27:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C488E6B009B; Thu, 12 Dec 2024 22:27:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A759B6B008C; Thu, 12 Dec 2024 22:27:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EA7536B0092 for ; Thu, 12 Dec 2024 22:27:19 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8DE84140C09 for ; Fri, 13 Dec 2024 03:27:19 +0000 (UTC) X-FDA: 82888498392.17.32B5FFF Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id B58BDC000C for ; Fri, 13 Dec 2024 03:26:46 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1734060420; 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=ZVc6ix7Dxj+Jz6ifMnfE/B81E+loVtqmSzXMuShqEB7OhjTG58krX6g2zBWKJbePKcbEVU TAihBqNQORojQoKZn8aqnUSgSObgHNt3zk7FHvlbdsMOqPgYGsb9CW9Wg5IVGMm1Lmljc+ MLs1oZNajwhZs8eVhb1KWDKTJvXGESk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734060420; a=rsa-sha256; cv=none; b=Bz9lKE0JZmvC2E8CYHhEpKqS4i5P3krQpLzJwL4kAr7NNzFODk28u3dWdw5GGQEUcP6wFX W33u/YoyZeSctsAFhNHVENWbS2ifUek2rXJ1Gww+hWtJIKYslojF4YNSodrg1o7g1lrpI8 rTaAtv/T8DvZgs/ppQHNc1eb0JJqeh8= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Y8ZWZ1D7kz4f3lDK for ; Fri, 13 Dec 2024 11:26:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 8234C1A0568 for ; Fri, 13 Dec 2024 11:27:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgBHcISMqVtnfJ3KEQ--.55430S5; Fri, 13 Dec 2024 11:27:10 +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 v3 3/5] Xarray: distinguish large entries correctly in xas_split_alloc() Date: Fri, 13 Dec 2024 20:25:21 +0800 Message-Id: <20241213122523.12764-4-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241213122523.12764-1-shikemeng@huaweicloud.com> References: <20241213122523.12764-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBHcISMqVtnfJ3KEQ--.55430S5 X-Coremail-Antispam: 1UD129KBjvdXoW7GF1rGr4kJF1DCr4DJw1fZwb_yoWDurg_ur 4FgF4kZr45GF4kXwnxCF4rt340kFn0kF9ruFWUJr9xW34UJrsrtr1kWrsrXa4rAFyjyFy7 AFs5Jry093yUKjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbDxYFVCjjxCrM7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r1rM28IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kI II0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7 xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84AC jcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF 0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AK xVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrx kI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v2 6r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8Jw CI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUaTKuUUUU U X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam05 X-Stat-Signature: 4ceuw7drhj1bd7zcw3nehc9wb1xurs6a X-Rspamd-Queue-Id: B58BDC000C X-Rspam-User: X-HE-Tag: 1734060406-765870 X-HE-Meta: U2FsdGVkX1+fDOkiuaoLpRdcivQKNBialKzTKnUkruHpzJlBGwTl92+g57whkyxU2K+gT/C6WGWBvFtsfKD3SOxwoSeA5UeUAbUZwO5IUP4rCziUA4oiMaMveO1T0PutpdEBJEysNhF8QEPGr4OXDrb0sQQQrrgMr+uwh0dSMRWHQWQ1VNIZWiZlPU6lqLdQ2rk91wOGWZC6KMyN6TxxhTHY4kWfGd3cmiaP4PPSi0WvqUOWgtovKj0b3cWXTA54MfP9/uA1QwrT2za6IEWl8QHiM9BX7dFphqp1VoAfQgHISwfSJMssx/uoT2fGKunekfL5ZP20tTGohaqAn2/o2asomH/cNH9kej6f/oUS+A/38dcWpLVtzEJzN+M8yn82/DPDP4uMii2UR6iCu4Hd65yTG7M2FGkrTllnk0YcL/6RsDHRGM92jv4OLuWLkgZaJRzUW+1uIOTmYC/+cDN+H8NZrnz4nA3XyS+YtDsliFkYwfr5iYm4Uajd2FQy5QCAM+Cd9erOwEJTSiwTvMWX9OaTQv/aBekn5FZ7sUey+08IipZ1xD+Ynbo4gPzYlYrXy1DLUy37mrBB0m95qq+g1gGNfory7dF+nEnj3QWTZm3T+ORm581VA1+mm03jPLwVgtBRWtW4TgrBCcWEOaKltHmylcEegXUvbwiHH0OwYiMCPQaLpr/7D9Pc6jq4X2yamkNXV2SSZVEVXrvnmD5m6xzyYvd7OjJDRGNraYDJ6qPBBcH2IK4mGsn9SZHsbc0p8pF1oPNzfoF4FnI/808dk+OD7dRgi+TZqKLKyI7Ow3lwy69aw2pyGBqvSwXmNWDLeYuuYuOtGxUsxsWNyqhJCIPVDpXGtv5csE61yisCwx8gfYsldHQlwb0FwwFxLNNEc5bCL70B5Gw519VDZAbYVwVaJJORw+dSZx0vckN7WzcGCOxnp6AMB+H8R1qwH6auVopYiynWxoFegh2JycS F+gPrBj9 CjaDJrRbLTqEwO+TQNNuQAoVAbDXYFGD1NfCEx4Bu6nIIm/P+eraqNvNwt+x8YsBR0oCeSbsDag6kjPD2ELcdeJ7dAqZWzWOU25VvUxEK2BY18B2l3+W285cXZ/Y7JpfrC61HYSJz2T7RsGMHgDgalHp8tD4Taep81mqvZ0r5pI5KsgasVEchuerVtKabPEN2JMMpOyr0cpCPN62B0euhjsA/yg== 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 Fri Dec 13 12:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13906415 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 0281EE7717F for ; Fri, 13 Dec 2024 03:27:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35F3E6B0096; Thu, 12 Dec 2024 22:27:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DF7D46B0098; Thu, 12 Dec 2024 22:27:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C706B6B0096; Thu, 12 Dec 2024 22:27:20 -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 00BF96B0096 for ; Thu, 12 Dec 2024 22:27:19 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8C71680B10 for ; Fri, 13 Dec 2024 03:27:19 +0000 (UTC) X-FDA: 82888499022.19.02696DD Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf03.hostedemail.com (Postfix) with ESMTP id F181D20011 for ; Fri, 13 Dec 2024 03:27:03 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.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=1734060411; 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=DgWpRFPOUXpypNiiMJ+6V9H/eLigWcB0AC/9ewmZk0j5Pj6JjAg+jhP2ItvoGlp4/KpONw aJeBJHG3YHfijoIlqKZYoeLb0ADayk5uzJUi+oYeUKfIESYzMX7Sl1jXtgTBjp9fvGqVs9 WOqL26pd9SZly2QI3qztFkCHTUCBqFQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734060411; a=rsa-sha256; cv=none; b=HKAkpjmyrXSJomSqOmDkYvFrSHlsWpE74Z1UMbNNIJSeZWvtHn8zjPOQzaZcSrtEas5WlP lMJWOMCm0m3dTHkKBRR6nt4mPbOwgjK4hscoK6cgH/0JAxdvpIvZwI+KZDxGOH6pyd5gHD CgSxQvIyvgZ+XHXzj+pChnMlI+94NpM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.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.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Y8ZWb3bSQz4f3jdc for ; Fri, 13 Dec 2024 11:26:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id CDE0C1A018D for ; Fri, 13 Dec 2024 11:27:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgBHcISMqVtnfJ3KEQ--.55430S6; Fri, 13 Dec 2024 11:27:10 +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 v3 4/5] Xarray: remove repeat check in xas_squash_marks() Date: Fri, 13 Dec 2024 20:25:22 +0800 Message-Id: <20241213122523.12764-5-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241213122523.12764-1-shikemeng@huaweicloud.com> References: <20241213122523.12764-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBHcISMqVtnfJ3KEQ--.55430S6 X-Coremail-Antispam: 1UD129KBjvdXoWrtFWxKF1Dtr4kXFy7Xw4kCrg_yoWxtwb_Za 10yr1vyr1UCrn7XwsIkFs8tryjkryvqF9rKFW8Ja43ur10qry5WF4vqr15Aa4kZw4ayFy7 JF45Zr1Y9r15GjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbqxYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r126s0DM28IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC 64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM2 8EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0D M28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAF wI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14 v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8C rVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtw CIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x02 67AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IUnVw Z3UUUUU== X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Queue-Id: F181D20011 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 43qpjgsfr56c96cngar9nkzd66rtupey X-HE-Tag: 1734060423-157365 X-HE-Meta: U2FsdGVkX19I/z+w4kD+kgkITMAir4Y9LRMjozJnTIPFapvnaUfiCHDPz1zHcpeezsmULUwdhAhJECnfO98mdS4gsVKFYWjOQfCKqxVLo0yMKVUgB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R2ERsS2M/B+F6Q== 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: 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 Fri Dec 13 12:25:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13906413 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 18D62E7716A for ; Fri, 13 Dec 2024 03:27:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0E516B0095; Thu, 12 Dec 2024 22:27:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE9F96B009A; Thu, 12 Dec 2024 22:27:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 976B06B0099; Thu, 12 Dec 2024 22:27:20 -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 EC1D26B0095 for ; Thu, 12 Dec 2024 22:27:19 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 90F6DAF148 for ; Fri, 13 Dec 2024 03:27:19 +0000 (UTC) X-FDA: 82888499358.21.0AFF751 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf13.hostedemail.com (Postfix) with ESMTP id 626D120009 for ; Fri, 13 Dec 2024 03:26:51 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1734060420; 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=LF8+HTWahPc0W0FMadf544Y7AesIwah8r6akN/LAR6ZOJ1lJthl6CeLkZwm8IcWkkHCsot 63kXlLUznSMN9uKQ63B/Aw4Rs2ctBwFYgCg2NQ8F9zC7b9LIx1ECmbueUgYpFsM+3/b/un 5d/+LlsyIY8jHJdAZNsGPkmvpQWjKgk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1734060420; a=rsa-sha256; cv=none; b=xM67X03lq0WF87RbWEZx2wOMTWMuhwR2e/lFQcN3vOGhmaxVJpaj6gT4cRDobBVgyc3ZKh gfnI9e5ZZVSf7Em7OENR/Q+emULhNqf8H49cbQurOM4debGvgZmebGUJMVoqbzEjcW777C fu8UN6crWK2JxmqpD3J5r1Iie1k4mq0= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Y8ZWb5mBQz4f3jHy for ; Fri, 13 Dec 2024 11:26:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 244CD1A018D for ; Fri, 13 Dec 2024 11:27:11 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgBHcISMqVtnfJ3KEQ--.55430S7; Fri, 13 Dec 2024 11:27:11 +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 v3 5/5] Xarray: use xa_mark_t in xas_squash_marks() to keep code consistent Date: Fri, 13 Dec 2024 20:25:23 +0800 Message-Id: <20241213122523.12764-6-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241213122523.12764-1-shikemeng@huaweicloud.com> References: <20241213122523.12764-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBHcISMqVtnfJ3KEQ--.55430S7 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw1UuF13JryrGFWxCFyfWFg_yoW8GrWkpF 97C3s8Ka1xA3WUKrnFvan7t345Ja1kK3yjyr4xGwnayFZ8Gr1Yqay7tryjqFnxGFy8ZFy3 Cr1Fg3y5Wa1UZw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0x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-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 */