From owner-dev-commits-src-main@freebsd.org Mon Jan 18 20:45:50 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 79E624F54B0; Mon, 18 Jan 2021 20:45:50 +0000 (UTC) (envelope-from melifaro@ipfw.ru) Received: from forward500o.mail.yandex.net (forward500o.mail.yandex.net [37.140.190.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DKP243nHjz3DFS; Mon, 18 Jan 2021 20:45:47 +0000 (UTC) (envelope-from melifaro@ipfw.ru) Received: from iva5-13ec62da2ad0.qloud-c.yandex.net (iva5-13ec62da2ad0.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:9304:0:640:13ec:62da]) by forward500o.mail.yandex.net (Yandex) with ESMTP id 19B5960110; Mon, 18 Jan 2021 23:45:45 +0300 (MSK) Received: from localhost (localhost [::1]) by iva5-13ec62da2ad0.qloud-c.yandex.net (mxback/Yandex) with ESMTP id EidJDCiEPG-jhDqGMDh; Mon, 18 Jan 2021 23:45:44 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfw.ru; s=mail; t=1611002744; bh=FY2uM8aG/C3fcCDpCyDRVtnjfgBD18lDQfu6PGQkRCk=; h=References:Date:Message-Id:Subject:In-Reply-To:To:From; b=vieUefFSPQD6+k2qh3B03w9TsvR2ZX04XO1YV5dPASmhhq/NL7EGY78ZTlC8UbWD6 SI70JtcjFrbc+2GpnvtMplkH0U/XuBz50CWSBHRFFpUvMw0cWG17BtzBmc8WktXSgi U8yc0sW1DheRHNI/KzHnv7+x6NSfr4xh1J0fna2o= Received: by iva4-57c3b416b70c.qloud-c.yandex.net with HTTP; Mon, 18 Jan 2021 23:45:43 +0300 From: Alexander V. Chernikov To: Konstantin Belousov , "src-committers@FreeBSD.org" , "dev-commits-src-all@FreeBSD.org" , "dev-commits-src-main@FreeBSD.org" In-Reply-To: <202101171729.10HHTsHk099908@gitrepo.freebsd.org> References: <202101171729.10HHTsHk099908@gitrepo.freebsd.org> Subject: Re: git: 3b15beb30b3b - main - Implement malloc_domainset_aligned(9). MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 18 Jan 2021 20:45:43 +0000 Message-Id: <124361611001207@mail.yandex.ru> Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 X-Rspamd-Queue-Id: 4DKP243nHjz3DFS X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=ipfw.ru header.s=mail header.b=vieUefFS; dmarc=none; spf=pass (mx1.freebsd.org: domain of melifaro@ipfw.ru designates 37.140.190.195 as permitted sender) smtp.mailfrom=melifaro@ipfw.ru X-Spamd-Result: default: False [-3.50 / 15.00]; TO_DN_EQ_ADDR_SOME(0.00)[]; RWL_MAILSPIKE_VERYGOOD(0.00)[37.140.190.195:from]; R_DKIM_ALLOW(-0.20)[ipfw.ru:s=mail]; FREEFALL_USER(0.00)[melifaro]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; R_SPF_ALLOW(-0.20)[+ip4:37.140.128.0/18]; ARC_NA(0.00)[]; DMARC_NA(0.00)[ipfw.ru]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; DKIM_TRACE(0.00)[ipfw.ru:+]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCVD_IN_DNSWL_NONE(0.00)[37.140.190.195:from]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:13238, ipnet:37.140.128.0/18, country:RU]; MAILMAN_DEST(0.00)[dev-commits-src-all,dev-commits-src-main] X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jan 2021 20:45:50 -0000 17.01.2021, 17:30, "Konstantin Belousov" : > The branch main has been updated by kib: > > URL: https://cgit.FreeBSD.org/src/commit/?id=3b15beb30b3b4ba17bae3d1d43c8c04ff862bb57 > > commit 3b15beb30b3b4ba17bae3d1d43c8c04ff862bb57 > Author: Konstantin Belousov > AuthorDate: 2021-01-14 03:59:34 +0000 > Commit: Konstantin Belousov > 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 cpuid = 1 time = 2 KDB: stack backtrace: db_trace_self_urapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe004d6345c0 vpanic() at vpanic+0x181 /frame 0xfffffe004d634610 panic() at panic+0x43/frame 0xfffffe004d634670 malloc_domainset_aligned() at malloc_domainset_aligned+0x8e/frame 0xfffffe004d6346a0 bounce_bus_dmamem_alloc() at bounce_bus_dmamem_alloc+0xde/frame 0xfffffe004d6346d0 usb_pc_alloc_mem() at usb_pc_alloc_mem+0x7c/frame 0xfffffe004d634730 usbd_transfer_setup_sub_malloc() at usbd_transfer_setup_sub_malloc+0x2fc/frame 0xfffffe004d6347c0 uhci_xfer_setup() at uhci_xfer_setup+0x1c9/frame 0xfffffe004d634840 usbd_transfer_setup() at usbd_transfer_setup+0x64a/frame 0xfffffe004d634910 usbd_ctr l_transfer_setup() at usbd_ctrl_transfer_setup+0xad/frame 0xfffffe004d634960 usbd_do_reguest_flags() at usbd_do_reguest_flags+0x220/frame 0xfffffe004d6349f0 usbd_reg_set_addressO at usbd_reg_set_address+0x9d/frame 0xfffffe004d634a30 usb_alloc_device() at usb_alloc_device+0x50e/frame 0xfffffe004d634ae0 uhub_explore() at uhub_explore+0x584/frame 0xfffffe004d634b60 usb_bus_explore() at usb_bus_explore+0x117/frame 0xfffffe004d634b80 usb_process() at usb_process+0xf3/frame 0xfffffe004d634bb0 fork_exit() at fork_exit+0x80/frame 0xfffffe004d634bf0 fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe004d634bf0 After converting KASSERT to printf: malloc_domainset_aligned: result not aligned 0xfffff80005309a80 size 0x180 align 0x100 bus_dmamem_alloc failed to align memory properly. malloc_domainset_aligned: result not aligned 0xfffff80005309a80 size 0x180 align 0x100 bus_dmamem_alloc failed to align memory properly. ugen0.2: at usbus0 Root mount waiting for: CAM usbus0 usbus1 malloc_domainset_aligned: result not aligned 0xfffff80005309780 size 0x180 align 0x100 bus_dmamem_alloc failed to align memory properly. malloc_domainset_aligned: result not aligned 0xfffff80005309780 size 0x180 align 0x100 bus_dmamem_alloc failed to align memory properly. ugen0.3: at usbus0 uhub2 on uhub0 uhub2: on usbus0 malloc_domainset_aligned: result not aligned 0xfffff80005309480 size 0x180 align 0x100 bus_dmamem_alloc failed to align memory properly. malloc_domainset_aligned: result not aligned 0xfffff80005309180 size 0x180 align 0x100 bus_dmamem_alloc failed to align memory properly. > >     Change the power-of-two malloc zones to require alignment equal to the >     size [*]. Current uma allocator already provides such alignment, so in >     fact this change does not change anything except providing future-proof >     setup. > >     Suggested by: markj [*] >     Reviewed by: andrew, jah, markj >     Tested by: pho >     MFC after: 1 week >     Sponsored by: The FreeBSD Foundation >     Differential Revision: https://reviews.freebsd.org/D28147 > --- >  sys/kern/kern_malloc.c | 28 +++++++++++++++++++++++++++- >  sys/sys/malloc.h | 3 +++ >  2 files changed, 30 insertions(+), 1 deletion(-) > > diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c > index f79352f2fbfd..232472708b9b 100644 > --- a/sys/kern/kern_malloc.c > +++ b/sys/kern/kern_malloc.c > @@ -763,6 +763,28 @@ malloc_domainset_exec(size_t size, struct malloc_type *mtp, struct domainset *ds >          return (malloc_large(&size, mtp, ds, flags DEBUG_REDZONE_ARG)); >  } > > +void * > +malloc_domainset_aligned(size_t size, size_t align, > + struct malloc_type *mtp, struct domainset *ds, int flags) > +{ > + void *res; > + > + KASSERT(align != 0 && powerof2(align), > + ("malloc_domainset_aligned: wrong align %#zx size %#zx", > + align, size)); > + KASSERT(align <= kmemzones[nitems(kmemzones) - 2].kz_size, > + ("malloc_domainset_aligned: align %#zx (size %#zx) too large", > + align, size)); > + > + if (size < align) > + size = align; > + res = malloc_domainset(size, 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)); > + return (res); > +} > + >  void * >  mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags) >  { > @@ -1146,8 +1168,12 @@ mallocinit(void *dummy) >          for (i = 0, indx = 0; kmemzones[indx].kz_size != 0; indx++) { >                  int size = kmemzones[indx].kz_size; >                  const char *name = kmemzones[indx].kz_name; > + size_t align; >                  int subzone; > > + align = UMA_ALIGN_PTR; > + if (powerof2(size) && size > sizeof(void *)) > + align = size - 1; >                  for (subzone = 0; subzone < numzones; subzone++) { >                          kmemzones[indx].kz_zone[subzone] = >                              uma_zcreate(name, size, > @@ -1156,7 +1182,7 @@ mallocinit(void *dummy) >  #else >                              NULL, NULL, NULL, NULL, >  #endif > - UMA_ALIGN_PTR, UMA_ZONE_MALLOC); > + align, UMA_ZONE_MALLOC); >                  } >                  for (;i <= size; i+= KMEM_ZBASE) >                          kmemsize[i >> KMEM_ZSHIFT] = indx; > diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h > index bf87e3168e01..a11dd767efc5 100644 > --- a/sys/sys/malloc.h > +++ b/sys/sys/malloc.h > @@ -261,6 +261,9 @@ void *realloc(void *addr, size_t size, struct malloc_type *type, int flags) >              __result_use_check __alloc_size(2); >  void *reallocf(void *addr, size_t size, struct malloc_type *type, int flags) >              __result_use_check __alloc_size(2); > +void *malloc_domainset_aligned(size_t size, size_t align, > + struct malloc_type *mtp, struct domainset *ds, int flags) > + __malloc_like __result_use_check __alloc_size(1); > >  struct malloc_type *malloc_desc2type(const char *desc);