NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/57979: kern.ipc.shmmax default size, loss of precision in calculation
>Number: 57979
>Category: kern
>Synopsis: kern.ipc.shmmax default size, loss of precision in calculation
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Mar 02 02:35:00 +0000 2024
>Originator: Patrik Andersin
>Release: netbsd-10-0-RC5
>Organization:
>Environment:
NetBSD savannah.cat.iki.fi 10.0_RC5 NetBSD 10.0_RC5 (XEN3_DOM0) #7: Sat Mar 2 02:50:54 EET 2024 root%savannah.cat.iki.fi@localhost:/usr/obj/sys/arch/amd64/compile/XEN3_DOM0 amd64
>Description:
I stumbled on a problem in calculating default kern.ipc.shmmax value.
Multiplying a uint64_t with uint32_t (PAGE_SIZE) leads to loss of precision.
Setting memory of xen dom0 machine to 16G results in:
# sysctl -a | grep shm
kern.ipc.sysvshm = 1
kern.ipc.shmmax = 0
kern.ipc.shmmni = 128
kern.ipc.shmseg = 128
kern.ipc.shmmaxpgs = 0
kern.ipc.shm_use_phys = 0
With 16GB memory, value of physmem is 4194304. This divided by 4 and multiplied by 4096 is 4294967296 dec and in hex 0x01 00 00 00 00. This gets truncated to 32 bits and result to 0x00.
I also tested this with GENERIC kernel running on xen hvm domu machine.
Setting memory of domu to 16393 (~16GB) results in:
kern.ipc.sysvshm = 1
kern.ipc.shmmax = 159744
kern.ipc.shmmni = 128
kern.ipc.shmseg = 128
kern.ipc.shmmaxpgs = 39
kern.ipc.shm_use_phys = 0
>How-To-Repeat:
Boot xen dom0 machine with following line in /boot.cfg
menu=Xen:load /netbsd-XEN3_DOM0 root=raid0a console=pc;multiboot /xen.gz dom0_mem=16G
>Fix:
Index: sysv_shm.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sysv_shm.c,v
retrieving revision 1.141
diff -u -r1.141 sysv_shm.c
--- sysv_shm.c 9 Oct 2019 17:47:13 -0000 1.141
+++ sysv_shm.c 2 Mar 2024 01:49:21 -0000
@@ -961,7 +961,7 @@
ALIGN(shminfo.shmmni * sizeof(struct shmid_ds)));
if (shminfo.shmmax == 0)
- shminfo.shmmax = uimax(physmem / 4, 1024) * PAGE_SIZE;
+ shminfo.shmmax = uimax(physmem / 4, 1024) * (uint64_t)PAGE_SIZE;
else
shminfo.shmmax *= PAGE_SIZE;
shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
Home |
Main Index |
Thread Index |
Old Index