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 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxV WUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j9739U UUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D8CA640002 X-Stat-Signature: tw85sti5mjwy5rbeou7mu7o4wi369btg X-Rspam-User: X-HE-Tag: 1734504458-188527 X-HE-Meta: U2FsdGVkX1+1tXthJ++1iouf/45OxMwaar8eOhdNZVOOZNkzdtYt3ZjDcAJ9pWvf3WIxQlMJnD+Z3IkJArfYO7NKCtIWZ5LiRN+FDouxOSkTDpeKfAcV6hCl2KMed3FesG4Y10tX3YvP7feY6skMvIKIK0GzqW8K6GxAlsQqwN4Kr+kj1MhuUBU5iuqBt9cdqdf7QMIelx8L0eLiUw0s3xtoBqJJ9qwmdN8N6Nsc73NE175AHRA0TowiGZ1L1WJKbHraUU3xDr4JtRzJOqm81aoSmMDT0tlle9ER0jEKu2lQP8UlkXIKsABnbDiD74ci1HeGnm+sdamXM5TRp+hwgq/1sEF5BN67SxUzNQwT2An3jhN7SkwGNvrGl2TKaSmEImpglwITn9uI60cL6h3F19oGr+EI+J9HQ59C9TrrXZz81rF5q6HhACyURgeeBt0CT5o2Eg5FsVa7gLpOGGfmX6vPEtcwuPyYPdYua1gRdb3Z7P5kXFc7ljhzhQ4ETgmTILC4kAW+N3VsiuczTQtYaT6K5ZUveUlD8nL+FkHNiJc2a1iR+KkFJn3ScRxlREoDMTeey/egFv+OYe9tMpWCs4qrHXJL7hEKH5vBZKzdIDXgC7UKczNzs/s8qylwUlPT652sTvDOMpwVktbaPft8Ag21xBd4doFo6I6+/1AKCZZ5ftjDsmak4s3LM0my6rJGNby4v5i1SA0uUgIeI2b4dAahN/oOzrXecsPyaKJ0PPIu0pbfDW71btKp28GIGnqQTF0KmLEd+zQT1W4X+79+aLmguBmpPfXRpS9CQ7mz0Mr65sL3Lt+f0U8wSH4XxXlTzW2njgkdT75TuPODEOOB2s2uvvmAzfDiaPur0Mvk8Wd77SHIh/POOn77eTCcdrkLh466tPtHxx6/wwFmhuT5KUt/kc0JYnK4D3mC7iNxVLyTW9T8ur057WhwlBWO3ySmTi36FDgWwyYNJSpvvgm tkAGQbGs zjIIggpA7ixwdMVWGfTRJ7AexwFzM5I48h9eHyqTj4+o8WVpUo9DxoBxup3Z78WwfNPj+1oaNTMrhAKJNs8MHxvtwna/JQ+ayQMU7CDY9jfE7eDxYJdF+VgpGoCJal/w57XvhSOI7WNMPohgDy6nC9Nd7Pugf8l0db9nsUoxaO7KnC9TLhQ2DsK8n+ntCYzTOzZTw9d4P+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;