linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 4.17 39/63] lib/rhashtable: consider param->min_size when setting initial table size
Date: Mon, 23 Jul 2018 14:24:45 +0200	[thread overview]
Message-ID: <20180723122447.857706794@linuxfoundation.org> (raw)
In-Reply-To: <20180723122446.351334162@linuxfoundation.org>

4.17-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Davidlohr Bueso <dave@stgolabs.net>

[ Upstream commit 107d01f5ba10f4162c38109496607eb197059064 ]

rhashtable_init() currently does not take into account the user-passed
min_size parameter unless param->nelem_hint is set as well. As such,
the default size (number of buckets) will always be HASH_DEFAULT_SIZE
even if the smallest allowed size is larger than that. Remediate this
by unconditionally calling into rounded_hashtable_size() and handling
things accordingly.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 lib/rhashtable.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -923,8 +923,16 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_stop);
 
 static size_t rounded_hashtable_size(const struct rhashtable_params *params)
 {
-	return max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
-		   (unsigned long)params->min_size);
+	size_t retsize;
+
+	if (params->nelem_hint)
+		retsize = max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
+			      (unsigned long)params->min_size);
+	else
+		retsize = max(HASH_DEFAULT_SIZE,
+			      (unsigned long)params->min_size);
+
+	return retsize;
 }
 
 static u32 rhashtable_jhash2(const void *key, u32 length, u32 seed)
@@ -981,8 +989,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;
@@ -1009,8 +1015,7 @@ 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);
+	size = rounded_hashtable_size(&ht->p);
 
 	if (params->locks_mul)
 		ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);



  parent reply	other threads:[~2018-07-23 12:27 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-23 12:24 [PATCH 4.17 00/63] 4.17.10-stable review Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 01/63] scsi: sd_zbc: Fix variable type and bogus comment Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 02/63] scsi: qla2xxx: Fix inconsistent DMA mem alloc/free Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 03/63] scsi: qla2xxx: Fix kernel crash due to late workqueue allocation Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 04/63] scsi: qla2xxx: Fix NULL pointer dereference for fcport search Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 06/63] KVM: irqfd: fix race between EPOLLHUP and irq_bypass_register_consumer Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 07/63] KVM: VMX: Mark VMXArea with revision_id of physical CPU even when eVMCS enabled Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 08/63] x86/kvm/vmx: dont read current->thread.{fs,gs}base of legacy tasks Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 11/63] x86/events/intel/ds: Fix bts_interrupt_threshold alignment Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 12/63] x86/MCE: Remove min interval polling limitation Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 13/63] fat: fix memory allocation failure handling of match_strdup() Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 14/63] ALSA: rawmidi: Change resized buffers atomically Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 15/63] ALSA: hda/realtek - Add Panasonic CF-SZ6 headset jack quirk Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 16/63] ALSA: hda/realtek - Yet another Clevo P950 quirk entry Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 17/63] ALSA: hda: add mute led support for HP ProBook 455 G5 Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 18/63] ARCv2: [plat-hsdk]: Save accl reg pair by default Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 19/63] ARC: Fix CONFIG_SWAP Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 20/63] ARC: configs: Remove CONFIG_INITRAMFS_SOURCE from defconfigs Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 21/63] ARC: mm: allow mprotect to make stack mappings executable Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 22/63] mm: memcg: fix use after free in mem_cgroup_iter() Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 23/63] mm/huge_memory.c: fix data loss when splitting a file pmd Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 24/63] cpufreq: intel_pstate: Register when ACPI PCCH is present Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 25/63] vfio/pci: Fix potential Spectre v1 Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 26/63] vfio/spapr: Use IOMMU pageshift rather than pagesize Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 27/63] stop_machine: Disable preemption when waking two stopper threads Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 28/63] powerpc/powernv: Fix save/restore of SPRG3 on entry/exit from stop (idle) Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 31/63] Revert "drm/amd/display: Dont return ddc result and read_bytes in same return value" Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 32/63] drm/nouveau: Remove bogus crtc check in pmops_runtime_idle Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 33/63] drm/nouveau: Use drm_connector_list_iter_* for iterating connectors Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 34/63] drm/nouveau: Avoid looping through fake MST connectors Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 36/63] ipv4: Return EINVAL when ping_group_range sysctl doesnt map to user ns Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 37/63] ipv6: fix useless rol32 call on hash Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 38/63] ipv6: ila: select CONFIG_DST_CACHE Greg Kroah-Hartman
2018-07-23 12:24 ` Greg Kroah-Hartman [this message]
2018-07-23 12:24 ` [PATCH 4.17 40/63] net: diag: Dont double-free TCP_NEW_SYN_RECV sockets in tcp_abort Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 41/63] net: Dont copy pfmemalloc flag in __copy_skb_header() Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 42/63] skbuff: Unconditionally copy pfmemalloc in __skb_clone() Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 43/63] net/ipv4: Set oif in fib_compute_spec_dst Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 44/63] net/ipv6: Do not allow device only routes via the multipath API Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 45/63] net: phy: fix flag masking in __set_phy_supported Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 46/63] ptp: fix missing break in switch Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 48/63] rhashtable: add restart routine in rhashtable_free_and_destroy() Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 49/63] sch_fq_codel: zero q->flows_cnt when fq_codel_init fails Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 50/63] tg3: Add higher cpu clock for 5762 Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 51/63] net: ip6_gre: get ipv6hdr after skb_cow_head() Greg Kroah-Hartman
2018-07-23 12:24 ` [PATCH 4.17 52/63] sctp: introduce sctp_dst_mtu Greg Kroah-Hartman
2018-07-25 19:19   ` Marcelo Ricardo Leitner
2018-07-23 12:24 ` [PATCH 4.17 53/63] sctp: fix the issue that pathmtu may be set lower than MINSEGMENT Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 54/63] hv_netvsc: Fix napi reschedule while receive completion is busy Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 55/63] net: aquantia: vlan unicast address list correct handling Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 56/63] net/mlx4_en: Dont reuse RX page when XDP is set Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 57/63] net: systemport: Fix CRC forwarding check for SYSTEMPORT Lite Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 58/63] ipv6: make DAD fail with enhanced DAD when nonce length differs Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 59/63] net: usb: asix: replace mii_nway_restart in resume path Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 60/63] alpha: fix osf_wait4() breakage Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 61/63] drm_mode_create_lease_ioctl(): fix open-coded filp_clone_open() Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 62/63] cxl_getfile(): fix double-iput() on alloc_file() failures Greg Kroah-Hartman
2018-07-23 12:25 ` [PATCH 4.17 63/63] xhci: Fix perceived dead host due to runtime suspend race with event handler Greg Kroah-Hartman
2018-07-24  7:38 ` [PATCH 4.17 00/63] 4.17.10-stable review Naresh Kamboju
2018-07-24  8:58   ` Greg Kroah-Hartman
2018-07-24 15:58 ` Guenter Roeck
2018-07-25  7:46   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180723122447.857706794@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=dbueso@suse.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).