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+zk5rYxAc2GGM59hHd7ltL8PATp6EIZu7y2poaKqSZYqV6R1ZW9KXUiSZBeIHS8B7uPqy6AFM/XcrUen9bUWHkqKwMfPU+wD7zqih45P4BgzfvjO98VJmmd4YySJA9n8Bfo3JFKOVGqnNcKa+vC5siiyP71V4MQF0Xpd04vBP62KSHpBYYk7UFoJHv65XFj9/MJDNqGRe1NU5EQCBFJaA66JM1P/+JBUcpwPKOFrDy0MeunyUZiUAtyMqLmpZq8NDyyYZYi6MSb+q82YmDQGYEMAuLHgpoGCj4jVq3+tuMD7IA8o+jPp9zw3CvXtUfL57xsgDbUpSE/wOHCmFrXDp+HPrzgyaUvQXl31X6VEacLQNk6ObjXpLMVpABeEGbg5rO37MFDFXkKDGq4y6c//RTf6RgHgb9zemFuHm6tXmb+imQZAtqDe3eV54DbQkvJAO0mV/UOSdbNNwkWDMMGbLyAQ8y8Al2McaqseToU6lTsgmy95rKM5eWUYoIQfU0/8CL1/tQDNal9yuqAupotnvL6C/ph2ydF2QEY5r0L3yfJyQCAQ+y8+eAqDXweIEu+cfuG7WteOSYXqLYXthriwn/anZBHyEr7eNeLRajwlFLVtxoFUg2uIQVuBFmAw2aDOK/6tJQzOOXqnTZtV51dgBUJ4AknNhYREb1WI9oTRMKt5rKDXKD63ixcduvp/YJx95EFt20vhIRxcBgvuDsae7CFpFcLuGHnzO0xZab/keaZfnrw92WYsMiPmkacU66pPUkQYX4FPUYBgc+AV1ol7vs/nwm+5uqWw0y0uF7qIFMw7UTKUn/ONzCNclpiVNzOXSmbWo60An9nVflMa6DtDdaw1bvYJ976mqEYUvy9J0pGaTIp2avTiC4ONQG/p bwnnABTx 6Wma0aSn04qrsDXeLDZa4KGLWYwgIs6jrxxlhv4nf7uO6UDe5dCMaHDKFiPCyWKTXu81axhTWrfywnfl8uro+3rwTFE38G2zk7bbirVJGz8UspEo6GXU3nQw2bSs70IEyh/wkJ4kugpDyGVol3nGARYLft2lrNDF3lVNqdBV9JQsV+NnP6TqzkpkPP26sGVHLkRcXaeAdMLoWxV6nURmW0mvxzw== 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;