Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Jan 2021 23:19:42 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        "Alexander V. Chernikov" <melifaro@ipfw.ru>
Cc:        Konstantin Belousov <kib@freebsd.org>, "src-committers@FreeBSD.org" <src-committers@freebsd.org>, "dev-commits-src-all@FreeBSD.org" <dev-commits-src-all@freebsd.org>, "dev-commits-src-main@FreeBSD.org" <dev-commits-src-main@freebsd.org>
Subject:   Re: git: 3b15beb30b3b - main - Implement malloc_domainset_aligned(9).
Message-ID:  <YAX7bvKGJDLqGz2B@kib.kiev.ua>
In-Reply-To: <124361611001207@mail.yandex.ru>
References:  <202101171729.10HHTsHk099908@gitrepo.freebsd.org> <124361611001207@mail.yandex.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 18, 2021 at 08:45:43PM +0000, Alexander V. Chernikov wrote:
> 17.01.2021, 17:30, "Konstantin Belousov" <kib@freebsd.org>:
> > The branch main has been updated by kib:
> >
> > URL: https://cgit.FreeBSD.org/src/commit/?id=3b15beb30b3b4ba17bae3d1d43c8c04ff862bb57
> >
> > commit 3b15beb30b3b4ba17bae3d1d43c8c04ff862bb57
> > Author: Konstantin Belousov <kib@FreeBSD.org>
> > AuthorDate: 2021-01-14 03:59:34 +0000
> > Commit: Konstantin Belousov <kib@FreeBSD.org>
> > CommitDate: 2021-01-17 17:29:05 +0000
> >
> >     Implement malloc_domainset_aligned(9).
> Hi Kostik,
> 
> This change makes my vm panic in usb code. No dump, as dumpdev not mounted yet.
> 
> Note: the below lines have been OCR'ed, so there may be some errors.
> 
> Root mount waiting for: CAM usbus0 usbus1
> panic: malloc_domainset_aligned: result not aligned 0xfffff8000551ca80 size 0x180 align 0x100

Try this.

diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 232472708b9b..7c4cb0f465b2 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -768,20 +768,25 @@ malloc_domainset_aligned(size_t size, size_t align,
     struct malloc_type *mtp, struct domainset *ds, int flags)
 {
 	void *res;
+	size_t asize;
 
 	KASSERT(align != 0 && powerof2(align),
 	    ("malloc_domainset_aligned: wrong align %#zx size %#zx",
 	    align, size));
-	KASSERT(align <= kmemzones[nitems(kmemzones) - 2].kz_size,
+	KASSERT(align <= PAGE_SIZE,
 	    ("malloc_domainset_aligned: align %#zx (size %#zx) too large",
 	    align, size));
 
 	if (size < align)
-		size = align;
-	res = malloc_domainset(size, mtp, ds, flags);
+		asize = align;
+	else if (!powerof2(size))
+		asize = roundup2(size, align);
+	else
+		asize = size;
+	res = malloc_domainset(asize, mtp, ds, flags);
 	KASSERT(res == NULL || ((uintptr_t)res & (align - 1)) == 0,
 	    ("malloc_domainset_aligned: result not aligned %p size %#zx "
-	    "align %#zx", res, size, align));
+	    "allocsize %#zx align %#zx", res, size, asize, align));
 	return (res);
 }
 
@@ -1173,7 +1178,7 @@ mallocinit(void *dummy)
 
 		align = UMA_ALIGN_PTR;
 		if (powerof2(size) && size > sizeof(void *))
-			align = size - 1;
+			align = (size <= PAGE_SIZE ? size : PAGE_SIZE) - 1;
 		for (subzone = 0; subzone < numzones; subzone++) {
 			kmemzones[indx].kz_zone[subzone] =
 			    uma_zcreate(name, size,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YAX7bvKGJDLqGz2B>