Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Sep 2018 07:04:01 +0000 (UTC)
From:      =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= <royger@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338623 - head/sys/compat/x86bios
Message-ID:  <201809130704.w8D741VT022528@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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,



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