From mboxrd@z Thu Jan 1 00:00:00 1970 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 85AB7C5B543 for ; Wed, 4 Jun 2025 04:15:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99C976B042E; Wed, 4 Jun 2025 00:15:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9747B6B042F; Wed, 4 Jun 2025 00:15:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B19F6B0430; Wed, 4 Jun 2025 00:15:46 -0400 (EDT) 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 6BD3B6B042E for ; Wed, 4 Jun 2025 00:15:46 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C4959C01E7 for ; Wed, 4 Jun 2025 04:15:45 +0000 (UTC) X-FDA: 83516404650.11.8DAF97B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id C42691A0008 for ; Wed, 4 Jun 2025 04:15:43 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749010544; 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:references; bh=aFe+HQNaM4WJErJgVq3Als1XEtT8VELHMME6WlUmFNQ=; b=1UhCAnE2iRp4csBlGdauggpo1GkV62fahNa/1+SjJMQhrQjI+w2ay69EEJm/U2MZsV3E2u iqpgc4OHMyu/X+t6KotoR/jX+1sLEANQH7zTxcpGjD32QHKNqpEHABWQ4vC19/gXs2tlCA iiEOFZG/BYNSXiTYu588JuZvIqNz0X8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749010544; a=rsa-sha256; cv=none; b=IE9gJdCHtSddOQvSywgPycilCI3mVZAtFKF8iE0abfZwuf75yqRj4YtHgoGIPfeltv1TjW uRjHvo0NSJ1MD190xcVrYnLO+CKEbvecJp5cQzybEIUnig1m1uUydkdYP3yduRfSAtbv+O rqy08zy3rQZiHfJZIptaFTkn+Tdhxhw= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AFB641756; Tue, 3 Jun 2025 21:15:25 -0700 (PDT) Received: from MacBook-Pro.blr.arm.com (MacBook-Pro.blr.arm.com [10.164.18.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 731363F673; Tue, 3 Jun 2025 21:15:39 -0700 (PDT) From: Dev Jain To: akpm@linux-foundation.org, willy@infradead.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, anshuman.khandual@arm.com, ryan.roberts@arm.com, ziy@nvidia.com, aneesh.kumar@kernel.org, Dev Jain Subject: [PATCH v2] xarray: Add a BUG_ON() to ensure caller is not sibling Date: Wed, 4 Jun 2025 09:45:33 +0530 Message-Id: <20250604041533.91198-1-dev.jain@arm.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: e68yt6p3z6jsxyj5cepedbxm7krryq5r X-Rspamd-Queue-Id: C42691A0008 X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1749010543-752401 X-HE-Meta: U2FsdGVkX18loDoa6o9d9XPpQ91UrcoUJUQRGq1eNdurYDQLgLbypOC34jdH4U9GU5k1GTVZAn7GNWfpqZN49j3EWsdJl1GUNQzpojr5LcnXXYTkxBkbIfSfIN8Np53yFQ8/qjN4Bea+nOMNq4n2sdiRO2+vBbSbkhfzGgwE7JjQ2OuWwjJZuJJyBGYU4moAjhomIOK5tevIyrK1owjp6cPFC+gayQvDgz9XLBxeIoow+ofD7xld2MVZZTktsdEjydHizp/NIafJbAllKmUBpqnpRnkuzn3Ns10H2bAbPeHoBbiMFDK8fET3dgTbUH77WbcV46dhwzeOB7E6saLylTjpY2JPwOHQJVhlYBN0oPX6rgRKr0157m8+Wd/0PrO6tI62Azrq703OBmgo8NRo9t7NdElUKIP5Ep63n6Czhi/5BgxQIGgh2FazX74TmFsEsDj756nHP7jcabPtT2RsR3Ub63dgsHa04jO1sm4E6grME1FJGUTSUT9+Da7eAH722lQV9dq2Z91Fs/walcTLwAiUS0yppmreO5qqqBgf7mhdSCTOakyhH5hJCjPnhE0UgdAKWuWlXP/6kEN7ZiDLYpCOncmP5SxNLaxohY7LoNGwFueftE9NoDM27QfA2JPid8xV0mTAVqcoa1UR2DmexPPOiVLCwMWutBZcKHNmz7Zg5PPttW3po+JQmCRoMS0WwuacxaCdsHzfK6JRlT/vFzdAtfaNJDE115Khl9nOgCCmFrUHtaZ5BtArSQ0VxceI1KlyJM7X5zfrTo/uue9qdzrrE+sK7IbZYaE+LzwvIxW/em+3Zvcw78uTT4+GRFeiG56UrfhEbLSmSYXh/HAaBjgMYeMtB8SgOfrikqHgh+hSTbG432LXz0I1fYgxMfT9VHlN4wK7T7915upKa32nJ016xFSs4FU7nWpnB9/lPMlPr8n+8C2c5TGPGNzIHrnPLM1Ilqk6LUAcStWRRp/ rwV0FYE6 chDr7eePHGfBQNIPB2IIu2U1vxs0UzPOmIRDRGimNxZFtgsY19O4Z2kA+imQdDKevn6Go74q9qWP+Ck5DbyHtvespq+5F/CjdcIWZY9FxMMQkE04G3I7fM7Y9YU+sQREr47hZ7fBZQNesYhwsZL0/W2TYl7X4+laflSzIMRCIr5xoc8DcxouWf9BL3FndPOqGJU8nylao2OBzT6WAxITe6emMg/OHvCX8Vxr3O7j8KtAXZJU= 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: Suppose xas is pointing somewhere near the end of the multi-entry batch. Then it may happen that the computed slot already falls beyond the batch, thus breaking the loop due to !xa_is_sibling(), and computing the wrong order. For example, suppose we have a shift-6 node having an order-9 entry => 8 - 1 = 7 siblings, so assume the slots are at offset 0 till 7 in this node. If xas->xa_offset is 6, then the code will compute order as 1 + xas->xa_node->shift = 7. Therefore, the order computation must start from the beginning of the multi-slot entries, that is, the non-sibling entry. Thus ensure that the caller is aware of this by triggering a BUG when the entry is a sibling entry. Note that this BUG_ON() is only active while running selftests, so there is no overhead in a running kernel. Signed-off-by: Dev Jain --- v1->v2: - Expand changelog, add comment Based on Torvalds' master branch. lib/xarray.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/xarray.c b/lib/xarray.c index 76dde3a1cacf..ae3d80f4b4ee 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1910,6 +1910,7 @@ EXPORT_SYMBOL(xa_store_range); * @xas: XArray operation state. * * Called after xas_load, the xas should not be in an error state. + * The xas should not be pointing to a sibling entry. * * Return: A number between 0 and 63 indicating the order of the entry. */ @@ -1920,6 +1921,8 @@ int xas_get_order(struct xa_state *xas) if (!xas->xa_node) return 0; + XA_NODE_BUG_ON(xas->xa_node, xa_is_sibling(xa_entry(xas->xa, + xas->xa_node, xas->xa_offset))); for (;;) { unsigned int slot = xas->xa_offset + (1 << order); -- 2.30.2