linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] lib/test_rhashtable: Make test_insert_dup() allocate its hash table dynamically
@ 2019-01-17  0:23 Bart Van Assche
  2019-01-18  4:48 ` kbuild test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2019-01-17  0:23 UTC (permalink / raw)
  To: David Miller; +Cc: tgraf, herbert, netdev, linux-kernel, Bart Van Assche

The test_insert_dup() function from lib/test_rhashtable.c passes a
pointer to a stack object to rhltable_init(). Allocate the hash table
dynamically to avoid that the following is reported with object
debugging enabled:

ODEBUG: object (ptrval) is on stack (ptrval), but NOT annotated.
WARNING: CPU: 0 PID: 1 at lib/debugobjects.c:368 __debug_object_init+0x312/0x480
Modules linked in:
EIP: __debug_object_init+0x312/0x480
Call Trace:
 ? debug_object_init+0x1a/0x20
 ? __init_work+0x16/0x30
 ? rhashtable_init+0x1e1/0x460
 ? sched_clock_cpu+0x57/0xe0
 ? rhltable_init+0xb/0x20
 ? test_insert_dup+0x32/0x20f
 ? trace_hardirqs_on+0x38/0xf0
 ? ida_dump+0x10/0x10
 ? jhash+0x130/0x130
 ? my_hashfn+0x30/0x30
 ? test_rht_init+0x6aa/0xab4
 ? ida_dump+0x10/0x10
 ? test_rhltable+0xc5c/0xc5c
 ? do_one_initcall+0x67/0x28e
 ? trace_hardirqs_off+0x22/0xe0
 ? restore_all_kernel+0xf/0x70
 ? trace_hardirqs_on_thunk+0xc/0x10
 ? restore_all_kernel+0xf/0x70
 ? kernel_init_freeable+0x142/0x213
 ? rest_init+0x230/0x230
 ? kernel_init+0x10/0x110
 ? schedule_tail_wrapper+0x9/0xc
 ? ret_from_fork+0x19/0x24

Cc: Thomas Graf <tgraf@suug.ch>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---

Changes compared to v1: instead of modifying rhashtable_init(), modify its
   caller.

 lib/test_rhashtable.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c
index 6a8ac7626797..ee5f591f145e 100644
--- a/lib/test_rhashtable.c
+++ b/lib/test_rhashtable.c
@@ -541,38 +541,45 @@ static unsigned int __init print_ht(struct rhltable *rhlt)
 static int __init test_insert_dup(struct test_obj_rhl *rhl_test_objects,
 				  int cnt, bool slow)
 {
-	struct rhltable rhlt;
+	struct rhltable *rhlt;
 	unsigned int i, ret;
 	const char *key;
 	int err = 0;
 
-	err = rhltable_init(&rhlt, &test_rht_params_dup);
-	if (WARN_ON(err))
+	rhlt = kmalloc(sizeof(*rhlt), GFP_KERNEL);
+	if (WARN_ON(!rhlt))
+		return -EINVAL;
+
+	err = rhltable_init(rhlt, &test_rht_params_dup);
+	if (WARN_ON(err)) {
+		kfree(rhlt);
 		return err;
+	}
 
 	for (i = 0; i < cnt; i++) {
 		rhl_test_objects[i].value.tid = i;
-		key = rht_obj(&rhlt.ht, &rhl_test_objects[i].list_node.rhead);
+		key = rht_obj(rhlt.ht, &rhl_test_objects[i].list_node.rhead);
 		key += test_rht_params_dup.key_offset;
 
 		if (slow) {
-			err = PTR_ERR(rhashtable_insert_slow(&rhlt.ht, key,
+			err = PTR_ERR(rhashtable_insert_slow(rhlt.ht, key,
 							     &rhl_test_objects[i].list_node.rhead));
 			if (err == -EAGAIN)
 				err = 0;
 		} else
-			err = rhltable_insert(&rhlt,
+			err = rhltable_insert(rhlt,
 					      &rhl_test_objects[i].list_node,
 					      test_rht_params_dup);
 		if (WARN(err, "error %d on element %d/%d (%s)\n", err, i, cnt, slow? "slow" : "fast"))
 			goto skip_print;
 	}
 
-	ret = print_ht(&rhlt);
+	ret = print_ht(rhlt);
 	WARN(ret != cnt, "missing rhltable elements (%d != %d, %s)\n", ret, cnt, slow? "slow" : "fast");
 
 skip_print:
-	rhltable_destroy(&rhlt);
+	rhltable_destroy(rhlt);
+	kfree(rhlt);
 
 	return 0;
 }
-- 
2.20.1.97.g81188d93c3-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] lib/test_rhashtable: Make test_insert_dup() allocate its hash table dynamically
  2019-01-17  0:23 [PATCH v2] lib/test_rhashtable: Make test_insert_dup() allocate its hash table dynamically Bart Van Assche
@ 2019-01-18  4:48 ` kbuild test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2019-01-18  4:48 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: kbuild-all, David Miller, tgraf, herbert, netdev, linux-kernel,
	Bart Van Assche

[-- Attachment #1: Type: text/plain, Size: 2739 bytes --]

Hi Bart,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc2 next-20190116]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Bart-Van-Assche/lib-test_rhashtable-Make-test_insert_dup-allocate-its-hash-table-dynamically/20190118-081736
config: i386-randconfig-b0-01181042 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   lib/test_rhashtable.c: In function 'test_insert_dup':
>> lib/test_rhashtable.c:561:21: error: request for member 'ht' in something not a structure or union
      key = rht_obj(rhlt.ht, &rhl_test_objects[i].list_node.rhead);
                        ^
   lib/test_rhashtable.c:565:45: error: request for member 'ht' in something not a structure or union
       err = PTR_ERR(rhashtable_insert_slow(rhlt.ht, key,
                                                ^

vim +/ht +561 lib/test_rhashtable.c

   540	
   541	static int __init test_insert_dup(struct test_obj_rhl *rhl_test_objects,
   542					  int cnt, bool slow)
   543	{
   544		struct rhltable *rhlt;
   545		unsigned int i, ret;
   546		const char *key;
   547		int err = 0;
   548	
   549		rhlt = kmalloc(sizeof(*rhlt), GFP_KERNEL);
   550		if (WARN_ON(!rhlt))
   551			return -EINVAL;
   552	
   553		err = rhltable_init(rhlt, &test_rht_params_dup);
   554		if (WARN_ON(err)) {
   555			kfree(rhlt);
   556			return err;
   557		}
   558	
   559		for (i = 0; i < cnt; i++) {
   560			rhl_test_objects[i].value.tid = i;
 > 561			key = rht_obj(rhlt.ht, &rhl_test_objects[i].list_node.rhead);
   562			key += test_rht_params_dup.key_offset;
   563	
   564			if (slow) {
   565				err = PTR_ERR(rhashtable_insert_slow(rhlt.ht, key,
   566								     &rhl_test_objects[i].list_node.rhead));
   567				if (err == -EAGAIN)
   568					err = 0;
   569			} else
   570				err = rhltable_insert(rhlt,
   571						      &rhl_test_objects[i].list_node,
   572						      test_rht_params_dup);
   573			if (WARN(err, "error %d on element %d/%d (%s)\n", err, i, cnt, slow? "slow" : "fast"))
   574				goto skip_print;
   575		}
   576	
   577		ret = print_ht(rhlt);
   578		WARN(ret != cnt, "missing rhltable elements (%d != %d, %s)\n", ret, cnt, slow? "slow" : "fast");
   579	
   580	skip_print:
   581		rhltable_destroy(rhlt);
   582		kfree(rhlt);
   583	
   584		return 0;
   585	}
   586	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33891 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-18  4:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17  0:23 [PATCH v2] lib/test_rhashtable: Make test_insert_dup() allocate its hash table dynamically Bart Van Assche
2019-01-18  4:48 ` kbuild test robot

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).