* [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix
@ 2016-05-02 4:13 Hugh Dickins
2016-05-03 20:27 ` [PATCH] radix-tree: add test for radix_tree_locate_item() Ross Zwisler
2016-05-03 20:28 ` [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix Ross Zwisler
0 siblings, 2 replies; 3+ messages in thread
From: Hugh Dickins @ 2016-05-02 4:13 UTC (permalink / raw)
To: Andrew Morton; +Cc: Matthew Wilcox, Ross Zwisler, linux-kernel, linux-mm
radix_tree_locate_item() is often returning the wrong index, causing
swapoff of shmem to hang because it cannot find the swap entry there.
__locate()'s use of base is bogus, it adds an offset twice into index.
Signed-off-by: Hugh Dickins <hughd@google.com>
---
Fix to radix-tree-rewrite-radix_tree_locate_item.patch
lib/radix-tree.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
--- 4.6-rc5-mm1/lib/radix-tree.c 2016-04-30 22:55:06.067184898 -0700
+++ linux/lib/radix-tree.c 2016-05-01 18:52:06.668085420 -0700
@@ -1254,15 +1254,14 @@ struct locate_info {
static unsigned long __locate(struct radix_tree_node *slot, void *item,
unsigned long index, struct locate_info *info)
{
- unsigned long base, i;
+ unsigned long i;
do {
unsigned int shift = slot->shift;
- base = index & ~((1UL << shift) - 1);
for (i = (index >> shift) & RADIX_TREE_MAP_MASK;
i < RADIX_TREE_MAP_SIZE;
- i++, index = base + (i << shift)) {
+ i++, index += (1UL << shift)) {
struct radix_tree_node *node =
rcu_dereference_raw(slot->slots[i]);
if (node == RADIX_TREE_RETRY)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] radix-tree: add test for radix_tree_locate_item()
2016-05-02 4:13 [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix Hugh Dickins
@ 2016-05-03 20:27 ` Ross Zwisler
2016-05-03 20:28 ` [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix Ross Zwisler
1 sibling, 0 replies; 3+ messages in thread
From: Ross Zwisler @ 2016-05-03 20:27 UTC (permalink / raw)
To: linux-kernel; +Cc: Ross Zwisler, Andrew Morton, Hugh Dickins, linux-mm
Add a unit test that provides coverage for the bug fixed in the commit
entitled "radix-tree: rewrite radix_tree_locate_item fix" from Hugh
Dickins. I've verified that this test fails before his patch due to
miscalculated 'index' values in __locate() in lib/radix-tree.c, and passes
with his fix.
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
tools/testing/radix-tree/linux/init.h | 1 +
tools/testing/radix-tree/main.c | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/radix-tree/linux/init.h
diff --git a/tools/testing/radix-tree/linux/init.h b/tools/testing/radix-tree/linux/init.h
new file mode 100644
index 0000000..360cabb
--- /dev/null
+++ b/tools/testing/radix-tree/linux/init.h
@@ -0,0 +1 @@
+/* An empty file stub that allows radix-tree.c to compile. */
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c
index 65231e9..b7619ff 100644
--- a/tools/testing/radix-tree/main.c
+++ b/tools/testing/radix-tree/main.c
@@ -232,7 +232,7 @@ void copy_tag_check(void)
item_kill_tree(&tree);
}
-void __locate_check(struct radix_tree_root *tree, unsigned long index,
+static void __locate_check(struct radix_tree_root *tree, unsigned long index,
unsigned order)
{
struct item *item;
@@ -248,12 +248,25 @@ void __locate_check(struct radix_tree_root *tree, unsigned long index,
}
}
+static void __order_0_locate_check(void)
+{
+ RADIX_TREE(tree, GFP_KERNEL);
+ int i;
+
+ for (i = 0; i < 50; i++)
+ __locate_check(&tree, rand() % INT_MAX, 0);
+
+ item_kill_tree(&tree);
+}
+
static void locate_check(void)
{
RADIX_TREE(tree, GFP_KERNEL);
unsigned order;
unsigned long offset, index;
+ __order_0_locate_check();
+
for (order = 0; order < 20; order++) {
for (offset = 0; offset < (1 << (order + 3));
offset += (1UL << order)) {
--
2.5.5
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix
2016-05-02 4:13 [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix Hugh Dickins
2016-05-03 20:27 ` [PATCH] radix-tree: add test for radix_tree_locate_item() Ross Zwisler
@ 2016-05-03 20:28 ` Ross Zwisler
1 sibling, 0 replies; 3+ messages in thread
From: Ross Zwisler @ 2016-05-03 20:28 UTC (permalink / raw)
To: Hugh Dickins
Cc: Andrew Morton, Matthew Wilcox, Ross Zwisler, linux-kernel,
linux-mm
On Sun, May 01, 2016 at 09:13:18PM -0700, Hugh Dickins wrote:
> radix_tree_locate_item() is often returning the wrong index, causing
> swapoff of shmem to hang because it cannot find the swap entry there.
> __locate()'s use of base is bogus, it adds an offset twice into index.
>
> Signed-off-by: Hugh Dickins <hughd@google.com>
Thank you for the fix!
Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-03 20:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-02 4:13 [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix Hugh Dickins
2016-05-03 20:27 ` [PATCH] radix-tree: add test for radix_tree_locate_item() Ross Zwisler
2016-05-03 20:28 ` [PATCH mmotm] radix-tree: rewrite radix_tree_locate_item fix Ross Zwisler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).