From patchwork Mon Nov 11 21:53:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13870696 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 78D95D2E9E3 for ; Mon, 11 Nov 2024 12:55:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA8276B0089; Mon, 11 Nov 2024 07:55:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D574F6B008C; Mon, 11 Nov 2024 07:55:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD1DC6B0089; 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 9F7F26B007B for ; Mon, 11 Nov 2024 07:55:07 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 58962816EF for ; Mon, 11 Nov 2024 12:55:07 +0000 (UTC) X-FDA: 82773807732.27.63BBB1E Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf23.hostedemail.com (Postfix) with ESMTP id CFE3F140017 for ; Mon, 11 Nov 2024 12:54:35 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.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=1731329474; 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=xc/oxACnMqcXbQlGVAuXnI+BvNhV2gjX2/T1F73aeMs=; b=RntAUVXQhKdPgcnw8hPs3ZmfXGVU5iFmjlA4J2AjShO2Yo8yXHen8nUqB97WWV+VDNGehl uCmjaYiX96umnVNUeqWybTsXdxVcfTEgYNu4x8ZB5CKttoqUyRS6iEiH7ntFqQiQEy+5FI naSBhc2H41c004Oq/jn8PwSbxUfCqeQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.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=1731329474; a=rsa-sha256; cv=none; b=c1/Z5z0naYvFWzQOAk9ouFDQjam+nzu95Z3/E6LtIWV0otRY5gkYBzv0Sj2Vpkp/zB2YVN /nCv7ixKU9KMZUAMAJHnmDtDcjPSxs8+VfTpD4KtNJTaEGdfhY09I6HTBCKt7vDGO6+7Lk iR3fNEt1UE/g/cRyxUkrMhzFqx7+O64= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Xn8dT6F3gz4f3nb8 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 E3A2C1A0568 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--.36628S5; 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 3/5] Xarray: move forward index correctly in xas_pause() Date: Tue, 12 Nov 2024 05:53:57 +0800 Message-Id: <20241111215359.246937-4-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--.36628S5 X-Coremail-Antispam: 1UD129KBjvJXoWxuFyUWFWxCF4fJFyrAFy5Arb_yoW5Gr1UpF WDGryFyw18Jr1I9rnIqa18uw1Fg3WrKa13trWfGr1ftrZxGr9Fy3Wjkr98XF9xWa18Aa47 CF4rWrn8Ga1DJ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPFb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI 0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUaTKu UUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CFE3F140017 X-Stat-Signature: qceupc6d3xf3xkrpr1tdsshk1apmbwhw X-Rspam-User: X-HE-Tag: 1731329675-728302 X-HE-Meta: U2FsdGVkX1+7OKWHZKk2rRedH/d319nK4L9vuI5dFfzTkIX9xBTivWsc4iZ0hxaGSHZdxJ5ERnlHr2yb/JqLU0Hj+6zFF3XwBkzme4FpGvyZ/KjFTv2BB2G5FWTdQya8QKbMXpPL02sCCNapLa+RZ9HpYIz0ad0IKLvHL7iXG1tmhG6oLriOZm0jzMA3SEO6ec9oOVw7eJ0WoBEgnO3gpVdiiR7ApWUvjylwAYEr+gdg3P+DQkeLgBKTPfNshhUMZbU3YvbPXfOzS85/mLqpjaumJbQGj9u8ChWWTsfM3tIkANdkVA+kR1hGN1JvSgNUnUgwhE0inO7VfXVJ1yZLsy+FSZEqbLGVkic4QpRa4DHt9q31cucZSdw3X+2C4QRFZCniMekKTHnePhOcftT3WpXApA6xG0pfnpJtkTsOt498vb4qkuMLd9sIYIqyHwW02k4T28FbvCwSxyh9Q1D8bfNUAm5EZp5zEpFzgQykAOPuiMt2JXQyy8zt+tw5npDtOP1ZxAkCd3t04nsnWfgxmQlrgdrqFxnqMd+qrpjt8O7V+7+j2/qgUHodHjweTcCY+v+DQp+2CORZNqxq4VyYaFO2FB5Z2gKqQQjCU/82H1AlvuARXgaQe1PT2tJk70SNHQ86II5js8OF6QoqVrklchLY31eHntC2NREyOF+WDOb3p03hnHx6oE1iyQF27flu5Yi1NdWn7V+pGKnXpEQA7kWQUAF7DuVraO7opCShhGZV3wlbaaq4twRqgNgUPwLRNmVQCWV3yciPFBmYcLw393+xHiO5PkJjxU44YWISIlCrvsKNHzv2HMgnU+BJZUFFHCAklKKbuV3ZvIfuiAYZ+1D1Ju2i9w1u43w2gAcMYhgWkZr/tDpOLY9zQ0k9lpjL/ocAdaYn6logR7jHbIKexsbxy0F0v0Gr4ZYSlD7RHsbJASU0grMZIr9nQhFNwlTjvxyNf3QqmmGXiAAAGLj LIO8Dn5/ /YPuk84Zc+jI3SG0Nx/bM4KH71pRdu/gPR2ZbOozN2MNBtvw4rAdugyc8jr6bS2BR4psuxUrJxiBqsQnzqV3IayUDi80Mxj32tRTHkjbsWrC4u6EVjwID6VHAQnydy2YUz+uP23VzaqPQcmxE6PHGeVMEg6KDmL3s5gKYwnpm8XszKjaKthe65z26JxiO6iligJiknxPK1jkfHS2UQLKxpWrYMg== 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(). 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 b9fd321a02ad..3fac3f2cea9d 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;