From owner-svn-src-head@freebsd.org Thu Sep 13 07:04:01 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B60E710A7B00; Thu, 13 Sep 2018 07:04:01 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 69FC38319E; Thu, 13 Sep 2018 07:04:01 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 64F99122A9; Thu, 13 Sep 2018 07:04:01 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w8D741Nf022529; Thu, 13 Sep 2018 07:04:01 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w8D741VT022528; Thu, 13 Sep 2018 07:04:01 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201809130704.w8D741VT022528@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Date: Thu, 13 Sep 2018 07:04:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338623 - head/sys/compat/x86bios X-SVN-Group: head X-SVN-Commit-Author: royger X-SVN-Commit-Paths: head/sys/compat/x86bios X-SVN-Commit-Revision: 338623 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Sep 2018 07:04:02 -0000 Author: royger Date: Thu Sep 13 07:04:00 2018 New Revision: 338623 URL: https://svnweb.freebsd.org/changeset/base/338623 Log: x86bios: use M_NOWAIT with mallocs Or else it triggers the following bug: APIC: CPU 6 has ACPI ID 6 APIC: CPU 7 has ACPI ID 7 panic: vm_wait in early boot cpuid = 0 time = 1 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xffffffff826ff8d0 vpanic() at vpanic+0x1a3/frame 0xffffffff826ff930 panic() at panic+0x43/frame 0xffffffff826ff990 vm_wait_domain() at vm_wait_domain+0xf9/frame 0xffffffff826ff9c0 kmem_alloc_contig_domain() at kmem_alloc_contig_domain+0x252/frame 0xffffffff826ffa50 kmem_alloc_contig() at kmem_alloc_contig+0x6c/frame 0xffffffff826ffad0 contigmalloc() at contigmalloc+0x2e/frame 0xffffffff826ffb00 x86bios_modevent() at x86bios_modevent+0x225/frame 0xffffffff826ffb20 module_register_init() at module_register_init+0xc0/frame 0xffffffff826ffb50 mi_startup() at mi_startup+0x118/frame 0xffffffff826ffb70 start_kernel() at start_kernel+0x10 While there also make x86bios_unmap_mem idempotent. Reviewed by: kib Approved by: re (gjb) Sponsored by: Citrix Systems R&D Differential revision: https://reviews.freebsd.org/D17000 Modified: head/sys/compat/x86bios/x86bios.c Modified: head/sys/compat/x86bios/x86bios.c ============================================================================== --- head/sys/compat/x86bios/x86bios.c Thu Sep 13 06:21:07 2018 (r338622) +++ head/sys/compat/x86bios/x86bios.c Thu Sep 13 07:04:00 2018 (r338623) @@ -656,17 +656,24 @@ static __inline void x86bios_unmap_mem(void) { - free(x86bios_map, M_DEVBUF); - if (x86bios_ivt != NULL) + if (x86bios_map != NULL) { + free(x86bios_map, M_DEVBUF); + x86bios_map = NULL; + } + if (x86bios_ivt != NULL) { #ifdef X86BIOS_NATIVE_ARCH pmap_unmapbios((vm_offset_t)x86bios_ivt, X86BIOS_IVT_SIZE); #else free(x86bios_ivt, M_DEVBUF); + x86bios_ivt = NULL; #endif + } if (x86bios_rom != NULL) pmap_unmapdev((vm_offset_t)x86bios_rom, X86BIOS_ROM_SIZE); - if (x86bios_seg != NULL) + if (x86bios_seg != NULL) { contigfree(x86bios_seg, X86BIOS_SEG_SIZE, M_DEVBUF); + x86bios_seg = NULL; + } } static __inline int @@ -674,7 +681,9 @@ x86bios_map_mem(void) { x86bios_map = malloc(sizeof(*x86bios_map) * X86BIOS_PAGES, M_DEVBUF, - M_WAITOK | M_ZERO); + M_NOWAIT | M_ZERO); + if (x86bios_map == NULL) + goto fail; #ifdef X86BIOS_NATIVE_ARCH x86bios_ivt = pmap_mapbios(X86BIOS_IVT_BASE, X86BIOS_IVT_SIZE); @@ -688,7 +697,9 @@ x86bios_map_mem(void) rounddown(x86bios_rom_phys, X86BIOS_PAGE_SIZE); else #else - x86bios_ivt = malloc(X86BIOS_IVT_SIZE, M_DEVBUF, M_ZERO | M_WAITOK); + x86bios_ivt = malloc(X86BIOS_IVT_SIZE, M_DEVBUF, M_NOWAIT | M_ZERO); + if (x86bios_ivt == NULL) + goto fail; #endif x86bios_rom_phys = X86BIOS_ROM_BASE; @@ -703,8 +714,10 @@ x86bios_map_mem(void) goto fail; #endif - x86bios_seg = contigmalloc(X86BIOS_SEG_SIZE, M_DEVBUF, M_WAITOK, + x86bios_seg = contigmalloc(X86BIOS_SEG_SIZE, M_DEVBUF, M_NOWAIT, X86BIOS_RAM_BASE, x86bios_rom_phys, X86BIOS_PAGE_SIZE, 0); + if (x86bios_seg == NULL) + goto fail; x86bios_seg_phys = vtophys(x86bios_seg); x86bios_set_pages((vm_offset_t)x86bios_ivt, X86BIOS_IVT_BASE,