NetBSD Problem Report #57979
From www@netbsd.org Sat Mar 2 02:31:55 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 91A1F1A9239
for <gnats-bugs@gnats.NetBSD.org>; Sat, 2 Mar 2024 02:31:55 +0000 (UTC)
Message-Id: <20240302023154.0530B1A923A@mollari.NetBSD.org>
Date: Sat, 2 Mar 2024 02:31:53 +0000 (UTC)
From: cat@iki.fi
Reply-To: cat@iki.fi
To: gnats-bugs@NetBSD.org
Subject: kern.ipc.shmmax default size, loss of precision in calculation
X-Send-Pr-Version: www-1.0
>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: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Mar 02 02:35:00 +0000 2024
>Closed-Date: Mon Mar 11 22:24:29 +0000 2024
>Last-Modified: Mon Mar 11 22:24:29 +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:/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;
>Release-Note:
>Audit-Trail:
From: "Michael van Elst" <mlelstv@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57979 CVS commit: src/sys/kern
Date: Sat, 2 Mar 2024 08:59:47 +0000
Module Name: src
Committed By: mlelstv
Date: Sat Mar 2 08:59:47 UTC 2024
Modified Files:
src/sys/kern: sysv_shm.c
Log Message:
Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979
To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/kern/sysv_shm.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 02 Mar 2024 22:36:16 +0000
State-Changed-Why:
Looks like this should apply cleanly to 10 and 9, and with a small
additional patch to 8.
State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Mon, 11 Mar 2024 01:09:05 +0000
State-Changed-Why:
pullup-10 #626
pullup-9 #1814
pullup-8 #1945
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57979 CVS commit: [netbsd-10] src/sys/kern
Date: Mon, 11 Mar 2024 18:00:06 +0000
Module Name: src
Committed By: martin
Date: Mon Mar 11 18:00:06 UTC 2024
Modified Files:
src/sys/kern [netbsd-10]: sysv_shm.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #626):
sys/kern/sysv_shm.c: revision 1.142
Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979
To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.141.26.1 src/sys/kern/sysv_shm.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57979 CVS commit: [netbsd-9] src/sys/kern
Date: Mon, 11 Mar 2024 18:01:48 +0000
Module Name: src
Committed By: martin
Date: Mon Mar 11 18:01:48 UTC 2024
Modified Files:
src/sys/kern [netbsd-9]: sysv_shm.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1814):
sys/kern/sysv_shm.c: revision 1.142
Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979
To generate a diff of this commit:
cvs rdiff -u -r1.135.2.4 -r1.135.2.5 src/sys/kern/sysv_shm.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57979 CVS commit: [netbsd-8] src/sys/kern
Date: Mon, 11 Mar 2024 18:04:54 +0000
Module Name: src
Committed By: martin
Date: Mon Mar 11 18:04:54 UTC 2024
Modified Files:
src/sys/kern [netbsd-8]: sysv_shm.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1945):
sys/kern/sysv_shm.c: revision 1.142 (patch)
Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979
To generate a diff of this commit:
cvs rdiff -u -r1.131.10.2 -r1.131.10.3 src/sys/kern/sysv_shm.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Mon, 11 Mar 2024 22:24:29 +0000
State-Changed-Why:
fixed and pulled up
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.