From patchwork Wed Jan 31 22:51:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13540084 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 1031BC47DB3 for ; Wed, 31 Jan 2024 22:51:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05C9A6B0088; Wed, 31 Jan 2024 17:51:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 00C796B0089; Wed, 31 Jan 2024 17:51:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3CEB6B008A; Wed, 31 Jan 2024 17:51:33 -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 D52F06B0088 for ; Wed, 31 Jan 2024 17:51:33 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AC8D212060F for ; Wed, 31 Jan 2024 22:51:33 +0000 (UTC) X-FDA: 81741104466.18.D7C62C7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id EA9E380013 for ; Wed, 31 Jan 2024 22:51:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=RRFaCJ4U; spf=none (imf02.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706741491; h=from:from:sender: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:dkim-signature; bh=VHDS8XfeqrJJCoN72ANJz9/5fJVypoPtMt3FLrR4fJQ=; b=RWPLSKFq783pPM32M7mdRuDLNUbkoC4VN80asmcpumhaoAYYjLLEdVUca8NGj5f0DRBzdq dQCy538s6Da86avZOvbqDfs/e8YcoEIZtjy/mE04KeWnMTN6J7erJrf4LpTXoBwj60HZhQ wf0VzQ0z497O2uH77z4QtZ5wVwPf0+E= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=RRFaCJ4U; spf=none (imf02.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706741491; a=rsa-sha256; cv=none; b=vccvusDtJrUSmBJCr7RfFBkIh/uPs6Cg4mNP7D0D5PRLX4Y+/gffCFs3g+xe0BP6hAtVjx iCaSN1hGOlKm/gs4ApgRKdATT1QIUK8DsSMh/NHewKdG1gdYBIdfpLYsrlQvQ2Hao/YFT5 vVSx73dm3DJGDHKdAbjP217H7Yjfqm4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=VHDS8XfeqrJJCoN72ANJz9/5fJVypoPtMt3FLrR4fJQ=; b=RRFaCJ4USpY0kDnPaF2Gol/eCH uSXwm4FGSYKqQL6L2LaiKlthJCk+UXmcoNd1huvU87/ebEx4N9F6NuJ6Xr6wmSsYva88XNpFNk6Jl 8VonDVWqHqa3NtjMQblemeLe2bJBWdLZIn/YwiXRHJ2yXZehrKiXuK6Cl8FowK0RCaEFrzF9medG7 8PgaWqykDIabwdxryzoDPb7BtJQOZ2Xwd6zmtJ5tKsvE5DoyhNEu2vzdTaWxcNJlubQV+gJFxTmtz 5bW2px9kQeGRUnIKNiFdPrrD3gER30HYudTQofdG5jkhHiqrNHXq3m6LCOzlu+ap8tr+BzqIVixew i3855xlQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVJQW-00000005kZC-3y0I; Wed, 31 Jan 2024 22:51:28 +0000 From: Luis Chamberlain To: willy@infradead.org, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, hare@suse.com, p.raghav@samsung.com, da.gomez@samsung.com, djwong@kernel.org, david@fromorbit.com, mcgrof@kernel.org Subject: [PATCH v2 1/2] test_xarray: add tests for advanced multi-index use Date: Wed, 31 Jan 2024 14:51:24 -0800 Message-ID: <20240131225125.1370598-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131225125.1370598-1-mcgrof@kernel.org> References: <20240131225125.1370598-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: EA9E380013 X-Rspam-User: X-Stat-Signature: nu655xjn4epk8zunsf64ybn3wwj83r5c X-Rspamd-Server: rspam01 X-HE-Tag: 1706741490-982747 X-HE-Meta: U2FsdGVkX18ALbXIikXvdQIGaF0A4IvxIxlp+N606uaXOZ/Vkpgj4q6ms0pkQ+HeZJQvjpvqhnFcY12tXjAzGuXANFA9wGB39OJ7g8mwNSetpvpycpyq8PRxC6OjshYJM5CC4eWi1pKV2txp/ZKMCVq/whF1FEbU4W7LvVDfzXZRfYUIABI0agp8rgbKgO+2pHHwa/7HqQt8/Xk/qRHSB6yS+PdR4qIKANMmOfOmHCQiJbXnltREumXkSCl6japg0WoWajrqIaT5cyk9uo3kgaPEAbicRHv+3xOapTQV3zc9UOgUmzChW5MHR3uhCRqDT98b3Ixe8Dqmz80vwfYr2Gy1JVGXhLncgh+yX4eGEtnnqr2HHRircHdzuvwVGNw5CHt8VVCffLmyjReu/mVFMk+LNqxQk6RKQZtXLj2eMSrxcb2eXX0YSmILZRIgE3evMFJFeiAJMRcmaQGU0+QYWA+8D22Lv46vpWQFSkZLVUMuitWg1VdNiChitlBRxM3wOZMyu1CedR/ttZxD9n/heAYRmTcYyFrIRK4ZF76ADduh/GM888291Weflt0FRxyQwfcxP7TXsVIL+wW+lH6en0KS/nC1n5EgEXtDsjo3MIm/9cLakg1RKoWtoqYjCBOhli5KSNRxvue2MEqf1eNuewrlTSvjgvtXoItpJPPxPfGZ+ucwXC+Ij6kM9cgAvj283XRp6TPEfA4stFq5eeeBDwrO6cwJzL+e2s3nFPFQr1QRWQhEr2P1mTEYYoKS44NIaPFq2KDpYTuzo5a/4d7K0wGFdvfUD6cmmUMzYt4Uz2rcLdyILIqWo7Nsv1dxoO2xaDwOXdSlIruFhrI8WhZwrRn7shzsM7Lt8v3KlnZcUNXNbWc8XDGF8/n2RQxBmocmN5g/Qf3FPHSCAhrYdkk4rrJ9OJ7AQDhZOOVO+CdGShqoFBlzstkYiQzGKsxRMdorbJTFwN50lSMkVNURMTZ RyeKv55q oDHNz9d7duDvVA9O3rRsE2FVMfyQUegc3LfVaBJ8CSIFGngo0bJdtYRxFW0UdkS5Q+2ioDgSByUkv0seBFAbE8Q9goBot7v2SkvqxWAWCGwSH4CuJOHWJIFjgozvooCbpuyBoyXXEzSpJT4CQB3m/2MSLTMJqwZI8FrcrVEHMf5WKJBfhhXpOKxFP3qjYcNhRfm61UGG34ZgouceXOK04AYY2XJUeBp6LM5n0ZZqGMsBl8jLm5ps0UQ69/FG8Hx6jBeY5GU8nE5i3sB0FFHcmqUIVTPqB0pF9OBi06OD4S/MHunAiSD/v62UK38SGVu2GJneTjjNb72Bfu+MyLIIJ3mhJTE4W00uv1iefKOpqD507tdmVxIqrNRmnm6eFWm7O5Jxg9jxN8mMfvyq65s6Tji8aaJJuP0GHNA+vfw5dOSRsitFeDW8QW9LoeDIH7+3Y2wdiKFz/k1TON2K0Km1IHuHVQQ== 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: The multi index selftests are great but they don't replicate how we deal with the page cache exactly, which makes it a bit hard to follow as the page cache uses the advanced API. Add tests which use the advanced API, mimicking what we do in the page cache, while at it, extend the example to do what is needed for min order support. Tested-by: Daniel Gomez Signed-off-by: Luis Chamberlain --- lib/test_xarray.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index e77d4856442c..8b23481f0e8f 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -674,6 +674,169 @@ static noinline void check_multi_store(struct xarray *xa) #endif } +#ifdef CONFIG_XARRAY_MULTI +/* mimics page cache __filemap_add_folio() */ +static noinline void check_xa_multi_store_adv_add(struct xarray *xa, + unsigned long index, + unsigned int order, + void *p) +{ + XA_STATE(xas, xa, index); + unsigned int nrpages = 1UL << order; + + /* users are responsible for index alignemnt to the order when adding */ + XA_BUG_ON(xa, index & (nrpages - 1)); + + xas_set_order(&xas, index, order); + + do { + xas_lock_irq(&xas); + + xas_store(&xas, p); + XA_BUG_ON(xa, xas_error(&xas)); + XA_BUG_ON(xa, xa_load(xa, index) != p); + + xas_unlock_irq(&xas); + } while (xas_nomem(&xas, GFP_KERNEL)); + + XA_BUG_ON(xa, xas_error(&xas)); +} + +/* mimics page_cache_delete() */ +static noinline void check_xa_multi_store_adv_del_entry(struct xarray *xa, + unsigned long index, + unsigned int order) +{ + XA_STATE(xas, xa, index); + + xas_set_order(&xas, index, order); + xas_store(&xas, NULL); + xas_init_marks(&xas); +} + +static noinline void check_xa_multi_store_adv_delete(struct xarray *xa, + unsigned long index, + unsigned int order) +{ + xa_lock_irq(xa); + check_xa_multi_store_adv_del_entry(xa, index, order); + xa_unlock_irq(xa); +} + +/* mimics page cache filemap_get_entry() */ +static noinline void *test_get_entry(struct xarray *xa, unsigned long index) +{ + XA_STATE(xas, xa, index); + void *p; + + rcu_read_lock(); +repeat: + xas_reset(&xas); + p = xas_load(&xas); + if (xas_retry(&xas, p)) + goto repeat; + rcu_read_unlock(); + + return p; +} + +static unsigned long some_val = 0xdeadbeef; +static unsigned long some_val_2 = 0xdeaddead; + +/* mimics the page cache usage */ +static noinline void check_xa_multi_store_adv(struct xarray *xa, + unsigned long pos, + unsigned int order) +{ + unsigned int nrpages = 1UL << order; + unsigned long index, base, next_index, next_next_index; + unsigned int i; + + index = pos >> PAGE_SHIFT; + base = round_down(index, nrpages); + next_index = round_down(base + nrpages, nrpages); + next_next_index = round_down(next_index + nrpages, nrpages); + + check_xa_multi_store_adv_add(xa, base, order, &some_val); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, base + i) != &some_val); + + XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL); + + /* Use order 0 for the next item */ + check_xa_multi_store_adv_add(xa, next_index, 0, &some_val_2); + XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2); + + /* Remove the next item */ + check_xa_multi_store_adv_delete(xa, next_index, 0); + + /* Now use order for a new pointer */ + check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2); + + check_xa_multi_store_adv_delete(xa, next_index, order); + check_xa_multi_store_adv_delete(xa, base, order); + XA_BUG_ON(xa, !xa_empty(xa)); + + /* starting fresh again */ + + /* let's test some holes now */ + + /* hole at base and next_next */ + check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != NULL); + + check_xa_multi_store_adv_delete(xa, next_index, order); + XA_BUG_ON(xa, !xa_empty(xa)); + + /* hole at base and next */ + + check_xa_multi_store_adv_add(xa, next_next_index, order, &some_val_2); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != NULL); + + for (i = 0; i < nrpages; i++) + XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != &some_val_2); + + check_xa_multi_store_adv_delete(xa, next_next_index, order); + XA_BUG_ON(xa, !xa_empty(xa)); +} +#endif + +static noinline void check_multi_store_advanced(struct xarray *xa) +{ +#ifdef CONFIG_XARRAY_MULTI + unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; + unsigned long end = ULONG_MAX/2; + unsigned long pos, i; + + /* + * About 117 million tests below. + */ + for (pos = 7; pos < end; pos = (pos * pos) + 564) { + for (i = 0; i < max_order; i++) { + check_xa_multi_store_adv(xa, pos, i); + check_xa_multi_store_adv(xa, pos + 157, i); + } + } +#endif +} + static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) { int i; @@ -1804,6 +1967,7 @@ static int xarray_checks(void) check_reserve(&array); check_reserve(&xa0); check_multi_store(&array); + check_multi_store_advanced(&array); check_get_order(&array); check_xa_alloc(); check_find(&array); From patchwork Wed Jan 31 22:51:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13540083 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 E874FC47258 for ; Wed, 31 Jan 2024 22:51:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69D606B0087; Wed, 31 Jan 2024 17:51:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 64E0F6B0088; Wed, 31 Jan 2024 17:51:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53C696B0089; Wed, 31 Jan 2024 17:51:33 -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 4107E6B0087 for ; Wed, 31 Jan 2024 17:51:33 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E61E440D8D for ; Wed, 31 Jan 2024 22:51:32 +0000 (UTC) X-FDA: 81741104424.24.546614B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf03.hostedemail.com (Postfix) with ESMTP id DAD8020015 for ; Wed, 31 Jan 2024 22:51:30 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=NmXI91H0; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf03.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706741491; a=rsa-sha256; cv=none; b=hPnj2LrRJK2Off8ElK84urQu2+lXD0WkvP4CBqiqj80cGdFftF9fdX+iH6bm1dL/KDygLr 3LcZ3m4QFskSPvtLUuYh7qqmEn66pZiKNl9FVH4SJby+p5k0unY3OirQScxnUXIUOw6sOG q8HOGuhtzryhvGRK8gy4k+zMZuXlfd4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=NmXI91H0; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf03.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706741491; h=from:from:sender: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:dkim-signature; bh=VZT786wUdytPkTuVNcY7ycnwPOjLKqn3LYNeNzmf2tQ=; b=01TxklyBDz5coxIblVg5pA95nRIAWogJiN7Ba0GHvccyVTzINE/2aTN/p1Pj3Mbq84Cpbz btHQSurv81/3auavfefP8J8bTcNcJkjTBbVQNXjQ/way1I7+6LZ3lSTivqSo9OrcsMOCy1 lkKfoxnitOCK0+c251SwGedvp0Uz2oU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=VZT786wUdytPkTuVNcY7ycnwPOjLKqn3LYNeNzmf2tQ=; b=NmXI91H0BewXk5PAb2p7VcWRBJ Er4y9xuUWXKmfOmg1A5hRZJL/GmdGaqZyt+Wy3JEmc6Ch65MSW365/US2qyMPeCVsjyvaDwsKYuqY ALhJ4zco7qdbHL+dfbdDyuw/njFd0vBGVNfwNTpuv6PUhBfHEfiE3g/2Qym5nt3q98RU0UgMdXLPQ /n37ZsZkxZbqI1Z9aLclAYD9pPeE7nUg6d7Q8YXokCInsbtdBWK8dl4HsEkWMqkjiXiMVrEbL8Uie z4QSZ66rSqzh9k5Jz84Qn3nBy45BSnHkxfqsyn5XzHO/YyWMd3FQN4S1X8WBB4alKipfR8xlhC2uK Sf7w58ZA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVJQW-00000005kZE-49GO; Wed, 31 Jan 2024 22:51:28 +0000 From: Luis Chamberlain To: willy@infradead.org, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, hare@suse.com, p.raghav@samsung.com, da.gomez@samsung.com, djwong@kernel.org, david@fromorbit.com, mcgrof@kernel.org Subject: [PATCH v2 2/2] XArray: add cmpxchg order test Date: Wed, 31 Jan 2024 14:51:25 -0800 Message-ID: <20240131225125.1370598-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131225125.1370598-1-mcgrof@kernel.org> References: <20240131225125.1370598-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DAD8020015 X-Stat-Signature: xe361e4xex39dy3ja5jojhr4cwn9okuu X-HE-Tag: 1706741490-600771 X-HE-Meta: U2FsdGVkX19MmuSbi3kg3uHUtABt6BpXvfkl3UUvr6nwQ8aI8nE6+77OhYxKWaWGqA84J/U+6jAvjpnvM6JmF03hnHEbniw/HDmB8qsPYoPbcP2DeZWamqvcq2e9kvQKrr/4rLlwP0vzMVF7s4lDzqVbFGfQ9OA338u6g4yoyrLnEs92O1j5+tDe4HqgwgpbZ4WIzcmh+o3Wbm+leab9BkjwzPHd2gO0h+Aw+gpNQZmhPHk60h7CSv1HapAhJExC35EDVnmt2p7nKNALK1DG72cLcs+feGuQXLEwNVR/48RheTYutKUqObowaeBlzLLqE4BtAm6Qk5tjGJCFSdxiSF3AW6SrZduE4xKALlvbqeO24dptQgLnaggV6nHJAKQDoHAwPRHINespqGxafQBv5zgu9TPvOShSFNUL69jQ3qxyVhdSw7ebyjJqcOc0PfkXbOiNYyUTUbgFrLiDbmX8617u5D7+X2qA+mkHRqga5J6Ec8+BgebVZCtuiDljJcLRZrcWOs2vYskG802myn9CJ7beHaYHm4s9f0syhKo0njJylcuYMZLW4S+7vXH50KZwk0rdCoXCGPx4KDxw99ckYguEOuqb5AfZY9wSaBzAPk3pkx2baC3h1Lmv/jONz/EpccK2MsGYQNuk7ef+SVyCYsdkNqN26j3CNlEuuJhbMUaQFXkrqSUGSnCWhs5FeRXcf43/oPpu5TE/VYncMhlWQpNHRNc3FK4DIDzEUtju1j5Su+tTXr4FPdrGKwlQEWLTGjeKOepb/LJG1T+2E+n5JGav3yMOQRJj/ZbSz+TZqFhzVQ6ibJkf6lmETdzAp8pKolAz9smIiuqk8cpPNIQXtOsrDZGc3V3zSkoYul/dtBCjVqFu6LvcQ3ImhBfxfL91LS5Kki9g7WmpYyY5scQOCWuwAurXswcwp2zs8zzPaflxMcsSBLY/t8YJPCNwPLKSTSPqKIJh0vLVFNVIpRA hEp7P8WV YK8l5rts8iaEE4U1jdSIkhBElj3NQCeVFzFC2pvfM9Mce8ddm8HC6FIFwGcbXLnsH59/bug0D4wnTZ79WxUp4MaagJivYadjkpOP7yCkYrJKASF6BSyAB6aADoQ== 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: From: Daniel Gomez XArray multi-index entries do not keep track of the order stored once the entry is being marked as used with cmpxchg (conditionally replaced with NULL). Add a test to check the order is actually lost. The test also verifies the order and entries for all the tied indexes before and after the NULL replacement with xa_cmpxchg. Add another entry at 1 << order that keeps the node around and the order information for the NULL-entry after xa_cmpxchg. Signed-off-by: Daniel Gomez Signed-off-by: Luis Chamberlain --- lib/test_xarray.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/lib/test_xarray.c b/lib/test_xarray.c index 8b23481f0e8f..d4e55b4867dc 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c @@ -423,6 +423,59 @@ static noinline void check_cmpxchg(struct xarray *xa) XA_BUG_ON(xa, !xa_empty(xa)); } +static noinline void check_cmpxchg_order(struct xarray *xa) +{ +#ifdef CONFIG_XARRAY_MULTI + void *FIVE = xa_mk_value(5); + unsigned int i, order = 3; + + XA_BUG_ON(xa, xa_store_order(xa, 0, order, FIVE, GFP_KERNEL)); + + /* Check entry FIVE has the order saved */ + XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != order); + + /* Check all the tied indexes have the same entry and order */ + for (i = 0; i < (1 << order); i++) { + XA_BUG_ON(xa, xa_load(xa, i) != FIVE); + XA_BUG_ON(xa, xa_get_order(xa, i) != order); + } + + /* Ensure that nothing is stored at index '1 << order' */ + XA_BUG_ON(xa, xa_load(xa, 1 << order) != NULL); + + /* + * Additionally, keep the node information and the order at + * '1 << order' + */ + XA_BUG_ON(xa, xa_store_order(xa, 1 << order, order, FIVE, GFP_KERNEL)); + for (i = (1 << order); i < (1 << order) + (1 << order) - 1; i++) { + XA_BUG_ON(xa, xa_load(xa, i) != FIVE); + XA_BUG_ON(xa, xa_get_order(xa, i) != order); + } + + /* Conditionally replace FIVE entry at index '0' with NULL */ + XA_BUG_ON(xa, xa_cmpxchg(xa, 0, FIVE, NULL, GFP_KERNEL) != FIVE); + + /* Verify the order is lost at FIVE (and old) entries */ + XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != 0); + + /* Verify the order and entries are lost in all the tied indexes */ + for (i = 0; i < (1 << order); i++) { + XA_BUG_ON(xa, xa_load(xa, i) != NULL); + XA_BUG_ON(xa, xa_get_order(xa, i) != 0); + } + + /* Verify node and order are kept at '1 << order' */ + for (i = (1 << order); i < (1 << order) + (1 << order) - 1; i++) { + XA_BUG_ON(xa, xa_load(xa, i) != FIVE); + XA_BUG_ON(xa, xa_get_order(xa, i) != order); + } + + xa_store_order(xa, 0, BITS_PER_LONG - 1, NULL, GFP_KERNEL); + XA_BUG_ON(xa, !xa_empty(xa)); +#endif +} + static noinline void check_reserve(struct xarray *xa) { void *entry; @@ -1964,6 +2017,7 @@ static int xarray_checks(void) check_xas_erase(&array); check_insert(&array); check_cmpxchg(&array); + check_cmpxchg_order(&array); check_reserve(&array); check_reserve(&xa0); check_multi_store(&array);