+ lib-rhashtable-reorder-some-inititalization-sequences.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: lib/rhashtable: reorder some inititalization sequences
has been added to the -mm tree.  Its filename is
     lib-rhashtable-reorder-some-inititalization-sequences.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/lib-rhashtable-reorder-some-inititalization-sequences.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/lib-rhashtable-reorder-some-inititalization-sequences.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Davidlohr Bueso <dave@xxxxxxxxxxxx>
Subject: lib/rhashtable: reorder some inititalization sequences

rhashtable_init() allocates memory at the very end of the call, once
everything is setup; with the exception of the nelems parameter.  However,
unless the user is doing something bogus with params for which -EINVAL is
returned, memory allocation is the only operation that can trigger the
call to fail.

Thus move bucket_table_alloc() up such that we fail back to the caller
asap, instead of doing useless checks.  This is safe as the the table
allocation isn't using the halfly setup 'ht' structure and
bucket_table_alloc() call chain only ends up using the ht->nulls_base
member in INIT_RHT_NULLS_HEAD.

Also move the locking initialization down to the end.

Link: http://lkml.kernel.org/r/20180514151332.31352-1-dave@xxxxxxxxxxxx
Signed-off-by: Davidlohr Bueso <dbueso@xxxxxxx>
Reviewed-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Thomas Graf <tgraf@xxxxxxx>
Cc: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 lib/rhashtable.c |   22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff -puN lib/rhashtable.c~lib-rhashtable-reorder-some-inititalization-sequences lib/rhashtable.c
--- a/lib/rhashtable.c~lib-rhashtable-reorder-some-inititalization-sequences
+++ a/lib/rhashtable.c
@@ -981,8 +981,6 @@ int rhashtable_init(struct rhashtable *h
 	struct bucket_table *tbl;
 	size_t size;
 
-	size = HASH_DEFAULT_SIZE;
-
 	if ((!params->key_len && !params->obj_hashfn) ||
 	    (params->obj_hashfn && !params->obj_cmpfn))
 		return -EINVAL;
@@ -991,10 +989,17 @@ int rhashtable_init(struct rhashtable *h
 		return -EINVAL;
 
 	memset(ht, 0, sizeof(*ht));
-	mutex_init(&ht->mutex);
-	spin_lock_init(&ht->lock);
 	memcpy(&ht->p, params, sizeof(*params));
 
+	if (!params->nelem_hint)
+		size = HASH_DEFAULT_SIZE;
+	else
+		size = rounded_hashtable_size(&ht->p);
+
+	tbl = bucket_table_alloc(ht, size, GFP_KERNEL);
+	if (tbl == NULL)
+		return -ENOMEM;
+
 	if (params->min_size)
 		ht->p.min_size = roundup_pow_of_two(params->min_size);
 
@@ -1009,9 +1014,6 @@ int rhashtable_init(struct rhashtable *h
 
 	ht->p.min_size = max_t(u16, ht->p.min_size, HASH_MIN_SIZE);
 
-	if (params->nelem_hint)
-		size = rounded_hashtable_size(&ht->p);
-
 	if (params->locks_mul)
 		ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);
 	else
@@ -1027,10 +1029,8 @@ int rhashtable_init(struct rhashtable *h
 		}
 	}
 
-	tbl = bucket_table_alloc(ht, size, GFP_KERNEL);
-	if (tbl == NULL)
-		return -ENOMEM;
-
+	mutex_init(&ht->mutex);
+	spin_lock_init(&ht->lock);
 	atomic_set(&ht->nelems, 0);
 
 	RCU_INIT_POINTER(ht->tbl, tbl);
_

Patches currently in -mm which might be from dave@xxxxxxxxxxxx are

lib-rhashtable-reorder-some-inititalization-sequences.patch
ipc-sem-mitigate-semnum-index-against-spectre-v1.patch
revert-ipc-shm-fix-shmat-mmap-nil-page-protection.patch
ipc-shm-fix-shmat-nil-address-after-round-down-when-remapping.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux