freebsd-skq/sys
Mark Johnston 6351771b7c vmem: Allocate btags before looping in vmem_xalloc()
BT_MAXALLOC (4) is the number of boundary tags required to complete an
allocation in the worst case: two to clip a free segment, and two to
import from a parent arena.  vmem_xalloc() preallocates four boundary
tags before attempting a search to simplify the segment allocation code.
It implements a loop that:
1) ensures that BT_MAXALLOC boundary tags are available,
2) attempts to find and clip a free segment satisfying the allocation
   constraints, and failing that,
3) attempts to import a segment.

On !UMA_MD_SMALL_ALLOC platforms the btag zone has to handle recusion:
it needs boundary tags to allocate boundary tags.  Thus we reserve
2 * BT_MAXALLOC * mp_ncpus tags for use when recursing: the factor of 2
is because there are two layers of vmem arenas, the per-domain arena and
global arena.  For a single thread, 2 * BT_MAXALLOC tags should be
sufficient.

Because of the way the loop is structured, BT_MAXALLOC tags are not
sufficient.  The first bt_fill() call may allocate BT_MAXALLOC tags,
then import a segment (consuming two tags), then attempt to top up the
preallocation before carving into the imported free segment, thus
requiring up to six tags in the worst case.  Because we don't
preallocate that many, this bug can cause deadlocks in rare scenarios.

Fix the problem by moving the preallocation out the loop.  This assumes
that only a single import is ever required to satisfy an allocation
request.

Thanks to manu, emaste and lwhsu for helping test debug patches.

Reported by:	Jenkins (hardware CI lab)
Reviewed by:	alc, kib, rlibby
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26770
2020-10-19 16:54:06 +00:00
..
amd64 vmx: Implement pmap (de)activation in C 2020-10-19 15:24:35 +00:00
arm Simplify preload_dump() condition 2020-10-15 20:21:15 +00:00
arm64 Remove unused labels from the arm64 casueword* 2020-10-19 15:52:42 +00:00
bsm
cam Fix sbuf_finish() error code check in user-space. 2020-10-13 23:29:06 +00:00
cddl Update OpenZFS to 2.0.0-rc3-gfc5966 2020-10-17 01:06:04 +00:00
compat Add compat.linux.dummy_rlimits, and disable by default. 2020-10-18 15:58:16 +00:00
conf [zfs] Remove a non-existent directory in the build infra 2020-10-18 22:37:58 +00:00
contrib Update OpenZFS to 2.0.0-rc3-gfc5966 2020-10-17 01:06:04 +00:00
crypto Add support for ESN in AES-NI crypto driver 2020-10-16 11:21:56 +00:00
ddb ddb: clean up empty lines in .c and .h files 2020-09-01 22:14:30 +00:00
dev Assign the reserved apic region (GAS entry) to the iommu domain msi_entry. 2020-10-19 15:50:58 +00:00
dts Brand our DTS with the Linux version it was imported from 2020-10-10 07:18:51 +00:00
fs Bump pseudofs size limit from 128kB to 1MB. The old limit could result 2020-10-16 09:58:10 +00:00
gdb gdb(4): Don't escape GDB special characters at application layer 2020-09-30 14:55:54 +00:00
geom Make g_attach() return ENXIO for orphaned providers; update various 2020-10-18 16:24:08 +00:00
gnu Brand our DTS with the Linux version it was imported from 2020-10-10 07:18:51 +00:00
i386 Fix for mis-interpretation of PCB_KERNFPU. 2020-10-14 23:01:41 +00:00
isa
kern vmem: Allocate btags before looping in vmem_xalloc() 2020-10-19 16:54:06 +00:00
kgssapi State kgssapi dependency on xdr. 2020-09-17 22:29:38 +00:00
libkern arc4random(9): Integrate with RANDOM_FENESTRASX push-reseed 2020-10-10 21:48:06 +00:00
mips Avoid dump_avail[] redefinition. 2020-10-14 22:51:40 +00:00
modules Update OpenZFS to 2.0.0-rc3-gfc5966 2020-10-17 01:06:04 +00:00
net Implement flowid calculation for outbound connections to balance 2020-10-18 17:15:47 +00:00
net80211 net80211: factor out the priv(9) checks into OS specifc code. 2020-10-18 21:34:04 +00:00
netgraph ng_l2tp: Fix callout synchronization in the rexmit timeout handler 2020-09-25 18:55:50 +00:00
netinet Implement flowid calculation for outbound connections to balance 2020-10-18 17:15:47 +00:00
netinet6 Implement flowid calculation for outbound connections to balance 2020-10-18 17:15:47 +00:00
netipsec Trigger soft lifetime expiration on sequence number 2020-10-16 11:27:01 +00:00
netpfil Add IPv4 fragments reassembling to NAT64LSN. 2020-10-13 18:57:42 +00:00
netsmb net: clean up empty lines in .c and .h files 2020-09-01 21:19:14 +00:00
nfs nfs: clean up empty lines in .c and .h files 2020-09-01 21:25:39 +00:00
nfsclient nfs: clean up empty lines in .c and .h files 2020-09-01 21:25:39 +00:00
nfsserver nfs: clean up empty lines in .c and .h files 2020-09-01 21:25:39 +00:00
nlm nlm: clean up empty lines in .c and .h files 2020-09-01 22:14:52 +00:00
ofed Allow IP over IB to work with multiple FIBs. 2020-10-13 20:41:51 +00:00
opencrypto Add support for ESN in cryptosoft 2020-10-16 11:18:13 +00:00
powerpc Avoid dump_avail[] redefinition. 2020-10-14 22:51:40 +00:00
riscv riscv: zero reserved PTE bits for L2 PTEs 2020-10-17 17:31:06 +00:00
rpc Fix a potential memory leak in the NFS over TLS handling code. 2020-09-05 00:50:52 +00:00
security mac_framework.h: fix build with DEBUG_VFS_LOCKS and !MAC 2020-09-03 20:30:52 +00:00
sys Manage MSI iommu pages. 2020-10-19 13:10:21 +00:00
teken Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
tests Add small tool to invoke kernel test framework tests. 2020-09-02 09:20:40 +00:00
tools Brand our DTS with the Linux version it was imported from 2020-10-10 07:18:51 +00:00
ufs Do not leak B_BARRIER. 2020-10-08 22:41:02 +00:00
vm Avoid dump_avail[] redefinition. 2020-10-14 22:51:40 +00:00
x86 Assign the reserved apic region (GAS entry) to the iommu domain msi_entry. 2020-10-19 15:50:58 +00:00
xdr xdr: clean up empty lines in .c and .h files 2020-09-01 22:13:28 +00:00
xen xen: clean up empty lines in .c and .h files 2020-09-01 21:21:55 +00:00
Makefile