diff options
-rw-r--r-- | usr/src/uts/common/crypto/io/crypto.c | 7 | ||||
-rw-r--r-- | usr/src/uts/common/crypto/io/cryptoadm.c | 11 | ||||
-rw-r--r-- | usr/src/uts/common/io/bpf/bpf.c | 6 | ||||
-rw-r--r-- | usr/src/uts/common/io/iwh/iwh.c | 7 | ||||
-rw-r--r-- | usr/src/uts/common/io/srn.c | 5 | ||||
-rw-r--r-- | usr/src/uts/common/os/swapgeneric.c | 6 | ||||
-rw-r--r-- | usr/src/uts/i86pc/dboot/dboot_printf.c | 4 | ||||
-rw-r--r-- | usr/src/uts/i86pc/dboot/dboot_printf.h | 13 | ||||
-rw-r--r-- | usr/src/uts/i86pc/dboot/dboot_startkern.c | 340 | ||||
-rw-r--r-- | usr/src/uts/i86pc/dboot/dboot_xboot.h | 14 | ||||
-rw-r--r-- | usr/src/uts/intel/io/dnet/dnet.c | 49 | ||||
-rw-r--r-- | usr/src/uts/sparc/swapgeneric/Makefile | 9 |
12 files changed, 297 insertions, 174 deletions
diff --git a/usr/src/uts/common/crypto/io/crypto.c b/usr/src/uts/common/crypto/io/crypto.c index a7c89cb473..bf7616ffdd 100644 --- a/usr/src/uts/common/crypto/io/crypto.c +++ b/usr/src/uts/common/crypto/io/crypto.c @@ -1105,6 +1105,7 @@ get_all_mechanism_info(dev_t dev, caddr_t arg, int mode, int *rval) int error = 0; int rv; + req_count = 0; STRUCT_INIT(get_all_mech, mode); STRUCT_INIT(mi, mode); @@ -2790,6 +2791,7 @@ cipher(dev_t dev, caddr_t arg, int mode, int rv; boolean_t rctl_chk = B_FALSE; + do_inplace = B_FALSE; STRUCT_INIT(encrypt, mode); if ((cm = crypto_hold_minor(getminor(dev))) == NULL) { @@ -2949,6 +2951,7 @@ cipher_update(dev_t dev, caddr_t arg, int mode, int rv; boolean_t rctl_chk = B_FALSE; + do_inplace = B_FALSE; STRUCT_INIT(encrypt_update, mode); if ((cm = crypto_hold_minor(getminor(dev))) == NULL) { @@ -5538,6 +5541,7 @@ nostore_generate_key(dev_t dev, caddr_t arg, int mode, int *rval) boolean_t allocated_by_crypto_module = B_FALSE; caddr_t u_attrs = NULL; + out_count = 0; STRUCT_INIT(generate_key, mode); STRUCT_INIT(oa, mode); @@ -5844,6 +5848,8 @@ nostore_generate_key_pair(dev_t dev, caddr_t arg, int mode, int *rval) caddr_t u_pub_attrs = NULL; caddr_t u_pri_attrs = NULL; + out_pub_count = 0; + out_pri_count = 0; STRUCT_INIT(generate_key_pair, mode); STRUCT_INIT(oa, mode); @@ -6505,6 +6511,7 @@ nostore_derive_key(dev_t dev, caddr_t arg, int mode, int *rval) boolean_t allocated_by_crypto_module = B_FALSE; caddr_t u_attrs = NULL; + out_count = 0; STRUCT_INIT(derive_key, mode); STRUCT_INIT(oa, mode); diff --git a/usr/src/uts/common/crypto/io/cryptoadm.c b/usr/src/uts/common/crypto/io/cryptoadm.c index 1192f382d7..008254f610 100644 --- a/usr/src/uts/common/crypto/io/cryptoadm.c +++ b/usr/src/uts/common/crypto/io/cryptoadm.c @@ -505,6 +505,10 @@ load_dev_disabled(dev_t dev, caddr_t arg, int mode, int *rval) uint32_t rv; int error = 0; + entries = NULL; + count = 0; + instance = 0; + rv = CRYPTO_SUCCESS; if (copyin(arg, &dev_disabled, sizeof (dev_disabled)) != 0) { error = EFAULT; goto out2; @@ -580,6 +584,9 @@ load_soft_disabled(dev_t dev, caddr_t arg, int mode, int *rval) uint32_t rv; int error = 0; + entries = NULL; + count = 0; + rv = CRYPTO_SUCCESS; if (copyin(arg, &soft_disabled, sizeof (soft_disabled)) != 0) { error = EFAULT; goto out2; @@ -660,6 +667,9 @@ load_soft_config(dev_t dev, caddr_t arg, int mode, int *rval) uint32_t rv; int error = 0; + entries = NULL; + count = 0; + rv = CRYPTO_SUCCESS; if (copyin(arg, &soft_config, sizeof (soft_config)) != 0) { error = EFAULT; goto out2; @@ -736,6 +746,7 @@ unload_soft_module(dev_t dev, caddr_t arg, int mode, int *rval) uint32_t rv; int error = 0; + rv = CRYPTO_SUCCESS; if (copyin(arg, &unload_soft_module, sizeof (unload_soft_module)) != 0) { error = EFAULT; diff --git a/usr/src/uts/common/io/bpf/bpf.c b/usr/src/uts/common/io/bpf/bpf.c index 0911020cd6..2d0c266d3d 100644 --- a/usr/src/uts/common/io/bpf/bpf.c +++ b/usr/src/uts/common/io/bpf/bpf.c @@ -256,6 +256,8 @@ bpf_attachd(struct bpf_d *d, const char *ifname, int dlt) ASSERT(d->bd_mcip == (uintptr_t)NULL); zone = d->bd_zone; zonematch = B_TRUE; + error = 0; + bpr = NULL; again: mh = 0; mcip = 0; @@ -312,6 +314,10 @@ next: return (error); } + /* No providers? */ + if (bpr == NULL) + return (ENOENT); + d->bd_mac = *bpr; d->bd_mcip = mcip; d->bd_bif = mh; diff --git a/usr/src/uts/common/io/iwh/iwh.c b/usr/src/uts/common/io/iwh/iwh.c index 39b6f27e7f..db1cfba28b 100644 --- a/usr/src/uts/common/io/iwh/iwh.c +++ b/usr/src/uts/common/io/iwh/iwh.c @@ -2101,8 +2101,8 @@ iwh_mac_access_exit(iwh_sc_t *sc) * static uint32_t * iwh_mem_read(iwh_sc_t *sc, uint32_t addr) * { - * IWH_WRITE(sc, HBUS_TARG_MEM_RADDR, addr); - * return (IWH_READ(sc, HBUS_TARG_MEM_RDAT)); + * IWH_WRITE(sc, HBUS_TARG_MEM_RADDR, addr); + * return (IWH_READ(sc, HBUS_TARG_MEM_RDAT)); * } */ @@ -3085,9 +3085,10 @@ iwh_send(ieee80211com_t *ic, mblk_t *mp, uint8_t type) struct ieee80211_qosframe *qwh = NULL; int tid = WME_TID_INVALID; - if (NULL == ic) { + if (ic == NULL) { return (IWH_FAIL); } + rate = 0; sc = (iwh_sc_t *)ic; if (sc->sc_flags & IWH_F_SUSPEND) { diff --git a/usr/src/uts/common/io/srn.c b/usr/src/uts/common/io/srn.c index 9aaeeb9007..73c875e8a6 100644 --- a/usr/src/uts/common/io/srn.c +++ b/usr/src/uts/common/io/srn.c @@ -519,6 +519,7 @@ void srn_notify(int type, int event) { int clone, count; + PMD(PMD_SX, ("srn_notify entered with type %d, event 0x%x\n", type, event)); ASSERT(mutex_owned(&srn_clone_lock)); @@ -538,8 +539,8 @@ srn_notify(int type, int event) count = srn_autosx_count; break; default: - ASSERT(0); - break; + PMD(PMD_SX, ("unsupported type\n")) + return; } ASSERT(count > 0); PMD(PMD_SX, ("count %d\n", count)) diff --git a/usr/src/uts/common/os/swapgeneric.c b/usr/src/uts/common/os/swapgeneric.c index 77167149fe..6d22fa40a6 100644 --- a/usr/src/uts/common/os/swapgeneric.c +++ b/usr/src/uts/common/os/swapgeneric.c @@ -910,7 +910,7 @@ load_bootpath_drivers(char *bootpath) rval = load_boot_driver(leaf, NULL); if (rval == -1) { kmem_free(pathcopy, pathcopy_len); - return (NULL); + return (0); } } } @@ -920,7 +920,7 @@ load_bootpath_drivers(char *bootpath) cmn_err(CE_WARN, "can't bind driver for boot path <%s>", bootpath); kmem_free(pathcopy, pathcopy_len); - return (NULL); + return (0); } /* @@ -936,7 +936,7 @@ load_bootpath_drivers(char *bootpath) modloadonly("drv", "ibp") == -1) { cmn_err(CE_CONT, "ibp: cannot load platform driver\n"); kmem_free(pathcopy, pathcopy_len); - return (NULL); + return (0); } /* diff --git a/usr/src/uts/i86pc/dboot/dboot_printf.c b/usr/src/uts/i86pc/dboot/dboot_printf.c index 9d02c1943a..59d4e247f0 100644 --- a/usr/src/uts/i86pc/dboot/dboot_printf.c +++ b/usr/src/uts/i86pc/dboot/dboot_printf.c @@ -203,6 +203,10 @@ unsigned_num: dboot_putnum(x, B_FALSE, base); break; + case 'z': + size = sizeof (size_t); + goto again; + default: dboot_puts("dboot_printf(): unknown % escape\n"); } diff --git a/usr/src/uts/i86pc/dboot/dboot_printf.h b/usr/src/uts/i86pc/dboot/dboot_printf.h index 22cf561e51..94b3db92e7 100644 --- a/usr/src/uts/i86pc/dboot/dboot_printf.h +++ b/usr/src/uts/i86pc/dboot/dboot_printf.h @@ -22,32 +22,29 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2020 Joyent, Inc. */ #ifndef _DBOOT_PRINTF_H #define _DBOOT_PRINTF_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef __cplusplus extern "C" { #endif /* - * Very primitive printf. This only understands the following simple formats: - * %%, %c, %s, %d, %ld, %lld, %x, %lx, %llx, %p + * Very primitive printf. We mark this as PRINTFLIKE so we can use %z */ -/*PRINTFLIKE1*/ extern void dboot_printf(char *fmt, ...) - __KPRINTFLIKE(1); + __PRINTFLIKE(1); /* * Primitive version of panic, prints a message, waits for a keystroke, * then resets the system */ -/*PRINTFLIKE1*/ extern void dboot_panic(char *fmt, ...) - __KPRINTFLIKE(1); + __NORETURN __PRINTFLIKE(1); #ifdef __cplusplus diff --git a/usr/src/uts/i86pc/dboot/dboot_startkern.c b/usr/src/uts/i86pc/dboot/dboot_startkern.c index edd0093853..45f64f8db9 100644 --- a/usr/src/uts/i86pc/dboot/dboot_startkern.c +++ b/usr/src/uts/i86pc/dboot/dboot_startkern.c @@ -75,6 +75,10 @@ extern int have_cpuid(void); #define SHA1_ASCII_LENGTH (SHA1_DIGEST_LENGTH * 2) +#define ULL(v) ((u_longlong_t)(v)) + +static void *page_alloc(void); + /* * This file contains code that runs to transition us from either a multiboot * compliant loader (32 bit non-paging) or a XPV domain loader to @@ -105,7 +109,10 @@ x86pte_t pte_bits = PT_VALID | PT_REF | PT_WRITABLE | PT_MOD | PT_NOCONSIST; * virtual address. */ paddr_t ktext_phys; -uint32_t ksize = 2 * FOUR_MEG; /* kernel nucleus is 8Meg */ +/* + * Nucleus size is 8Mb, including text, data, and BSS. + */ +uint32_t ksize = 2 * FOUR_MEG; static uint64_t target_kernel_text; /* value to use for KERNEL_TEXT */ @@ -115,9 +122,16 @@ static uint64_t target_kernel_text; /* value to use for KERNEL_TEXT */ char stack_space[STACK_SIZE]; /* - * Used to track physical memory allocation + * The highest address we build page tables for. + */ +static paddr_t boot_map_end; + +/* + * The dboot allocator. This is a small area we use for allocating the + * kernel nucleus and pages for the identity page tables we build here. */ -static paddr_t next_avail_addr = 0; +static paddr_t alloc_addr; +static paddr_t alloc_end; #if defined(__xpv) /* @@ -127,7 +141,6 @@ static paddr_t next_avail_addr = 0; * to derive a pfn from a pointer, you subtract mfn_base. */ -static paddr_t scratch_end = 0; /* we can't write all of mem here */ static paddr_t mfn_base; /* addr corresponding to mfn_list[0] */ start_info_t *xen_info; @@ -233,6 +246,12 @@ uint_t map_debug = 0; static char noname[2] = "-"; +static boolean_t +ranges_intersect(uint64_t s1, uint64_t e1, uint64_t s2, uint64_t e2) +{ + return (s1 < e2 && e1 >= s2); +} + /* * Either hypervisor-specific or grub-specific code builds the initial * memlists. This code does the sort/merge/link for final use. @@ -288,8 +307,16 @@ sort_physinstall(void) if (prom_debug) { dboot_printf("\nFinal memlists:\n"); for (i = 0; i < memlists_used; ++i) { - dboot_printf("\t%d: addr=%" PRIx64 " size=%" - PRIx64 "\n", i, memlists[i].addr, memlists[i].size); + dboot_printf("\t%d: 0x%llx-0x%llx size=0x%llx\n", + i, ULL(memlists[i].addr), ULL(memlists[i].addr + + memlists[i].size), ULL(memlists[i].size)); + } + + dboot_printf("\nBoot modules:\n"); + for (i = 0; i < bi->bi_module_cnt; i++) { + dboot_printf("\t%d: 0x%llx-0x%llx size=0x%llx\n", + i, ULL(modules[i].bm_addr), ULL(modules[i].bm_addr + + modules[i].bm_size), ULL(modules[i].bm_size)); } } @@ -341,6 +368,8 @@ dboot_halt(void) while (--i) (void) HYPERVISOR_yield(); (void) HYPERVISOR_shutdown(SHUTDOWN_poweroff); + for (;;) + ; } /* @@ -427,7 +456,7 @@ set_pteval(paddr_t table, uint_t index, uint_t level, x86pte_t pteval) paddr_t make_ptable(x86pte_t *pteval, uint_t level) { - paddr_t new_table = (paddr_t)(uintptr_t)mem_alloc(MMU_PAGESIZE); + paddr_t new_table = (paddr_t)(uintptr_t)page_alloc(); if (level == top_level && level == 2) *pteval = pa_to_ma((uintptr_t)new_table) | PT_VALID; @@ -659,18 +688,6 @@ exclude_from_pci(uint64_t start, uint64_t end) } } -/* - * During memory allocation, find the highest address not used yet. - */ -static void -check_higher(paddr_t a) -{ - if (a < next_avail_addr) - return; - next_avail_addr = RNDUP(a + 1, MMU_PAGESIZE); - DBG(next_avail_addr); -} - static int dboot_loader_mmap_entries(void) { @@ -687,7 +704,6 @@ dboot_loader_mmap_entries(void) DBG(mb_info->mmap_addr); DBG(mb_info->mmap_length); - check_higher(mb_info->mmap_addr + mb_info->mmap_length); for (mmap_addr = mb_info->mmap_addr; mmap_addr < mb_info->mmap_addr + @@ -895,17 +911,13 @@ build_pcimemlists(void) } #if defined(__xpv) -/* - * Initialize memory allocator stuff from hypervisor-supplied start info. - */ static void -init_mem_alloc(void) +init_dboot_alloc(void) { int local; /* variables needed to find start region */ - paddr_t scratch_start; xen_memory_map_t map; - DBG_MSG("Entered init_mem_alloc()\n"); + DBG_MSG("Entered init_dboot_alloc()\n"); /* * Free memory follows the stack. There's at least 512KB of scratch @@ -914,17 +926,17 @@ init_mem_alloc(void) * allocated last and will be outside the addressible range. We'll * switch to new page tables before we unpack the kernel */ - scratch_start = RNDUP((paddr_t)(uintptr_t)&local, MMU_PAGESIZE); - DBG(scratch_start); - scratch_end = RNDUP((paddr_t)scratch_start + 512 * 1024, TWO_MEG); - DBG(scratch_end); + alloc_addr = RNDUP((paddr_t)(uintptr_t)&local, MMU_PAGESIZE); + DBG(alloc_addr); + alloc_end = RNDUP((paddr_t)alloc_addr + 512 * 1024, TWO_MEG); + DBG(alloc_end); /* * For paranoia, leave some space between hypervisor data and ours. * Use 500 instead of 512. */ - next_avail_addr = scratch_end - 500 * 1024; - DBG(next_avail_addr); + alloc_addr = alloc_end - 500 * 1024; + DBG(alloc_addr); /* * The domain builder gives us at most 1 module @@ -1272,7 +1284,6 @@ process_module(int midx) char *cmdline = dboot_multiboot_modcmdline(midx); char *p, *q; - check_higher(mod_end); if (prom_debug) { dboot_printf("\tmodule #%d: '%s' at 0x%lx, end 0x%lx\n", midx, cmdline, (ulong_t)mod_start, (ulong_t)mod_end); @@ -1436,7 +1447,6 @@ static void dboot_process_modules(void) { int i, modcount; - extern char _end[]; DBG_MSG("\nFinding Modules\n"); modcount = dboot_multiboot_modcount(); @@ -1444,11 +1454,11 @@ dboot_process_modules(void) dboot_panic("Too many modules (%d) -- the maximum is %d.", modcount, MAX_BOOT_MODULES); } + /* * search the modules to find the last used address * we'll build the module list while we're walking through here */ - check_higher((paddr_t)(uintptr_t)&_end); for (i = 0; i < modcount; ++i) { process_module(i); modules_used++; @@ -1498,8 +1508,8 @@ dboot_add_memlist(uint64_t start, uint64_t end) native_ptr_t mod_start = modules[i].bm_addr; native_ptr_t mod_end = modules[i].bm_addr + modules[i].bm_size; - if (mod_start < CORRUPT_REGION_END && - mod_end >= CORRUPT_REGION_START) { + if (ranges_intersect(mod_start, mod_end, CORRUPT_REGION_START, + CORRUPT_REGION_END)) { if (prom_debug) { dboot_printf("disabling RICHMOND-16 workaround " "due to module #%d: " @@ -1662,21 +1672,17 @@ dboot_multiboot1_highest_addr(void) return (addr); } -static void +static uint64_t dboot_multiboot_highest_addr(void) { paddr_t addr; switch (multiboot_version) { case 1: - addr = dboot_multiboot1_highest_addr(); - if (addr != (paddr_t)(uintptr_t)NULL) - check_higher(addr); + return (dboot_multiboot1_highest_addr()); break; case 2: - addr = dboot_multiboot2_highest_addr(mb2_info); - if (addr != (paddr_t)(uintptr_t)NULL) - check_higher(addr); + return (dboot_multiboot2_highest_addr(mb2_info)); break; default: dboot_panic("Unknown multiboot version: %d\n", @@ -1686,15 +1692,97 @@ dboot_multiboot_highest_addr(void) } /* - * Walk the boot loader provided information and find the highest free address. + * Set up our simple physical memory allocator. This is used to allocate both + * the kernel nucleus (ksize) and our page table pages. + * + * We need to find a contiguous region in the memlists that is below 4Gb (as + * we're 32-bit and need to use the addresses), and isn't otherwise in use by + * dboot, multiboot allocations, or boot modules. The memlist is sorted and + * merged by this point. + * + * Historically, this code always did the allocations past the end of the + * highest used address, even if there was space below. For reasons unclear, if + * we don't do this, then we get massive corruption during early kernel boot. + * + * Note that find_kalloc_start() starts its search at the end of this + * allocation. + * + * This all falls apart horribly on some EFI systems booting under iPXE, where + * we end up with boot module allocation such that there is no room between the + * highest used address and our 4Gb limit. To that end, we have an iPXE hack + * that limits the maximum address used by its allocations in an attempt to give + * us room. */ static void -init_mem_alloc(void) +init_dboot_alloc(void) { - DBG_MSG("Entered init_mem_alloc()\n"); + extern char _end[]; + + DBG_MSG("Entered init_dboot_alloc()\n"); + dboot_process_modules(); dboot_process_mmap(); - dboot_multiboot_highest_addr(); + + size_t align = FOUR_MEG; + + /* + * We need enough alloc space for the nucleus memory... + */ + size_t size = RNDUP(ksize, align); + + /* + * And enough page table pages to cover potentially 4Gb. Each leaf PT + * covers 2Mb, so we need a maximum of 2048 pages for those. Next level + * up each covers 1Gb, and so on, so we'll just add a little slop (which + * gets aligned up anyway). + */ + size += RNDUP(MMU_PAGESIZE * (2048 + 256), align); + + uint64_t start = MAX(dboot_multiboot_highest_addr(), + (paddr_t)(uintptr_t)&_end); + start = RNDUP(start, align); + + /* + * As mentioned above, only start our search after all the boot modules. + */ + for (uint_t i = 0; i < bi->bi_module_cnt; i++) { + native_ptr_t mod_end = modules[i].bm_addr + modules[i].bm_size; + + start = MAX(start, RNDUP(mod_end, MMU_PAGESIZE)); + } + + uint64_t end = start + size; + + DBG(start); + DBG(end); + + for (uint_t i = 0; i < memlists_used; i++) { + uint64_t ml_start = memlists[i].addr; + uint64_t ml_end = memlists[i].addr + memlists[i].size; + + /* + * If we're past our starting point for search, begin at this + * memlist. + */ + if (start < ml_start) { + start = RNDUP(ml_start, align); + end = start + size; + } + + if (end >= (uint64_t)UINT32_MAX) { + dboot_panic("couldn't find alloc space below 4Gb"); + } + + if (end < ml_end) { + alloc_addr = start; + alloc_end = end; + DBG(alloc_addr); + DBG(alloc_end); + return; + } + } + + dboot_panic("couldn't find alloc space in memlists"); } static int @@ -1938,77 +2026,89 @@ print_efi64(EFI_SYSTEM_TABLE64 *efi) #endif /* !__xpv */ /* - * Simple memory allocator, allocates aligned physical memory. - * Note that startup_kernel() only allocates memory, never frees. - * Memory usage just grows in an upward direction. + * Simple memory allocator for aligned physical memory from the area provided by + * init_dboot_alloc(). This is a simple bump allocator, and it's never directly + * freed by dboot. */ static void * -do_mem_alloc(uint32_t size, uint32_t align) +dboot_alloc(uint32_t size, uint32_t align) { - uint_t i; - uint64_t best; - uint64_t start; - uint64_t end; + uint32_t start = RNDUP(alloc_addr, align); - /* - * make sure size is a multiple of pagesize - */ size = RNDUP(size, MMU_PAGESIZE); - next_avail_addr = RNDUP(next_avail_addr, align); - /* - * XXPV fixme joe - * - * a really large bootarchive that causes you to run out of memory - * may cause this to blow up - */ - /* LINTED E_UNEXPECTED_UINT_PROMOTION */ - best = (uint64_t)-size; - for (i = 0; i < memlists_used; ++i) { - start = memlists[i].addr; -#if defined(__xpv) - start += mfn_base; -#endif - end = start + memlists[i].size; + if (start + size > alloc_end) { + dboot_panic("%s: couldn't allocate 0x%x bytes aligned 0x%x " + "alloc_addr = 0x%llx, alloc_end = 0x%llx", __func__, + size, align, (u_longlong_t)alloc_addr, + (u_longlong_t)alloc_end); + } - /* - * did we find the desired address? - */ - if (start <= next_avail_addr && next_avail_addr + size <= end) { - best = next_avail_addr; - goto done; - } + alloc_addr = start + size; - /* - * if not is this address the best so far? - */ - if (start > next_avail_addr && start < best && - RNDUP(start, align) + size <= end) - best = RNDUP(start, align); + if (map_debug) { + dboot_printf("%s(0x%x, 0x%x) = 0x%x\n", __func__, size, + align, start); } - /* - * We didn't find exactly the address we wanted, due to going off the - * end of a memory region. Return the best found memory address. - */ -done: - next_avail_addr = best + size; -#if defined(__xpv) - if (next_avail_addr > scratch_end) - dboot_panic("Out of mem next_avail: 0x%lx, scratch_end: " - "0x%lx", (ulong_t)next_avail_addr, - (ulong_t)scratch_end); -#endif - (void) memset((void *)(uintptr_t)best, 0, size); - return ((void *)(uintptr_t)best); + (void) memset((void *)(uintptr_t)start, 0, size); + return ((void *)(uintptr_t)start); } -void * -mem_alloc(uint32_t size) +static void * +page_alloc(void) { - return (do_mem_alloc(size, MMU_PAGESIZE)); + return (dboot_alloc(MMU_PAGESIZE, MMU_PAGESIZE)); } +/* + * This is where we tell the kernel to start physical allocations from, beyond + * the end of our allocation area and all boot modules. It might be beyond 4Gb, + * so we can't touch that area ourselves. + * + * We might set kalloc_start to the end of a memlist; if so make sure we skip it + * along to the next one. + * + * This is making the massive assumption that there is a suitably large area for + * kernel allocations past the end of the last boot module and the dboot + * allocated region. Worse, we don't have a simple way to assert that is so. + */ +static paddr_t +find_kalloc_start(void) +{ + paddr_t kalloc_start = alloc_end; + uint_t i; + + for (i = 0; i < bi->bi_module_cnt; i++) { + native_ptr_t mod_end = modules[i].bm_addr + modules[i].bm_size; + + kalloc_start = MAX(kalloc_start, RNDUP(mod_end, MMU_PAGESIZE)); + } + + boot_map_end = kalloc_start; + DBG(boot_map_end); + + for (i = 0; i < memlists_used; i++) { + uint64_t ml_start = memlists[i].addr; + uint64_t ml_end = memlists[i].addr + memlists[i].size; + + if (kalloc_start >= ml_end) + continue; + + if (kalloc_start < ml_start) + kalloc_start = ml_start; + break; + } + + if (i == memlists_used) { + dboot_panic("fell off the end of memlists finding a " + "kalloc_start value > 0x%llx", (u_longlong_t)kalloc_start); + } + + DBG(kalloc_start); + + return (kalloc_start); +} /* * Build page tables to map all of memory used so far as well as the kernel. @@ -2031,7 +2131,7 @@ build_page_tables(void) #if defined(__xpv) top_page_table = (paddr_t)(uintptr_t)xen_info->pt_base; #else /* __xpv */ - top_page_table = (paddr_t)(uintptr_t)mem_alloc(MMU_PAGESIZE); + top_page_table = (paddr_t)(uintptr_t)page_alloc(); #endif /* __xpv */ DBG((uintptr_t)top_page_table); @@ -2057,7 +2157,7 @@ build_page_tables(void) /* * The kernel will need a 1 page window to work with page tables */ - bi->bi_pt_window = (native_ptr_t)(uintptr_t)mem_alloc(MMU_PAGESIZE); + bi->bi_pt_window = (native_ptr_t)(uintptr_t)page_alloc(); DBG(bi->bi_pt_window); bi->bi_pte_to_pt_window = (native_ptr_t)(uintptr_t)find_pte(bi->bi_pt_window, NULL, 0, 0); @@ -2098,6 +2198,10 @@ build_page_tables(void) #if !defined(__xpv) + /* + * Map every valid memlist address up until boot_map_end: this will + * cover at least our alloc region and all boot modules. + */ for (i = 0; i < memlists_used; ++i) { start = memlists[i].addr; end = start + memlists[i].size; @@ -2105,11 +2209,11 @@ build_page_tables(void) if (map_debug) dboot_printf("1:1 map pa=%" PRIx64 "..%" PRIx64 "\n", start, end); - while (start < end && start < next_avail_addr) { + while (start < end && start < boot_map_end) { map_pa_at_va(start, start, 0); start += MMU_PAGESIZE; } - if (start >= next_avail_addr) + if (start >= boot_map_end) break; } @@ -2533,7 +2637,7 @@ startup_kernel(void) /* * initialize the simple memory allocator */ - init_mem_alloc(); + init_dboot_alloc(); #if !defined(__xpv) && !defined(_BOOT_TARGET_amd64) /* @@ -2587,7 +2691,7 @@ startup_kernel(void) * For grub, copy kernel bits from the ELF64 file to final place. */ DBG_MSG("\nAllocating nucleus pages.\n"); - ktext_phys = (uintptr_t)do_mem_alloc(ksize, FOUR_MEG); + ktext_phys = (uintptr_t)dboot_alloc(ksize, FOUR_MEG); if (ktext_phys == 0) dboot_panic("failed to allocate aligned kernel memory"); @@ -2598,6 +2702,8 @@ startup_kernel(void) DBG(ktext_phys); + paddr_t kalloc_start = find_kalloc_start(); + /* * Allocate page tables. */ @@ -2615,18 +2721,18 @@ startup_kernel(void) #if defined(__xpv) - bi->bi_next_paddr = next_avail_addr - mfn_base; + bi->bi_next_paddr = kalloc_start - mfn_base; DBG(bi->bi_next_paddr); - bi->bi_next_vaddr = (native_ptr_t)(uintptr_t)next_avail_addr; + bi->bi_next_vaddr = (native_ptr_t)kalloc_start; DBG(bi->bi_next_vaddr); /* * unmap unused pages in start area to make them available for DMA */ - while (next_avail_addr < scratch_end) { - (void) HYPERVISOR_update_va_mapping(next_avail_addr, + while (alloc_addr < alloc_end) { + (void) HYPERVISOR_update_va_mapping(alloc_addr, 0, UVMF_INVLPG | UVMF_LOCAL); - next_avail_addr += MMU_PAGESIZE; + alloc_addr += MMU_PAGESIZE; } bi->bi_xen_start_info = (native_ptr_t)(uintptr_t)xen_info; @@ -2636,9 +2742,9 @@ startup_kernel(void) #else /* __xpv */ - bi->bi_next_paddr = next_avail_addr; + bi->bi_next_paddr = kalloc_start; DBG(bi->bi_next_paddr); - bi->bi_next_vaddr = (native_ptr_t)(uintptr_t)next_avail_addr; + bi->bi_next_vaddr = (native_ptr_t)kalloc_start; DBG(bi->bi_next_vaddr); bi->bi_mb_version = multiboot_version; diff --git a/usr/src/uts/i86pc/dboot/dboot_xboot.h b/usr/src/uts/i86pc/dboot/dboot_xboot.h index 5c9af24325..3ec4bf409e 100644 --- a/usr/src/uts/i86pc/dboot/dboot_xboot.h +++ b/usr/src/uts/i86pc/dboot/dboot_xboot.h @@ -22,13 +22,13 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2020 Joyent, Inc. */ #ifndef _DBOOT_XBOOT_H #define _DBOOT_XBOOT_H -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/mach_mmu.h> #ifdef __cplusplus @@ -54,16 +54,14 @@ extern uint_t prom_debug; #define DBG_MSG(s) do { if (prom_debug) \ dboot_printf(s); \ - _NOTE(CONSTANTCONDITION) \ } while (0) -#define DBG(x) do { if (prom_debug) { \ - dboot_printf("%s is 0x%" PRIx64 "\n", #x, (uint64_t)(x)); \ - _NOTE(CONSTANTCONDITION) \ +#define DBG(x) do { if (prom_debug) { \ + dboot_printf("%s: %s is 0x%" PRIx64 "\n", \ + __func__, #x, (uint64_t)(x)); \ } } while (0) -extern void dboot_halt(void); -extern void *mem_alloc(uint32_t size); +extern void dboot_halt(void) __NORETURN; #define RNDUP(x, y) ((x) + ((y) - 1ul) & ~((y) - 1ul)) diff --git a/usr/src/uts/intel/io/dnet/dnet.c b/usr/src/uts/intel/io/dnet/dnet.c index e1592ad902..01e9325519 100644 --- a/usr/src/uts/intel/io/dnet/dnet.c +++ b/usr/src/uts/intel/io/dnet/dnet.c @@ -438,7 +438,7 @@ dnet_probe(dev_info_t *devinfo) static int dnet_hack(dev_info_t *devinfo) { - uchar_t vendor_info[SROM_SIZE]; + uchar_t vendor_info[SROM_SIZE]; uint32_t csr; uint16_t deviceid; ddi_acc_handle_t handle; @@ -505,12 +505,12 @@ static int dnet_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) { uint16_t revid; - struct dnetinstance *dnetp; /* Our private device info */ + struct dnetinstance *dnetp; /* Our private device info */ mac_register_t *macp; - uchar_t vendor_info[SROM_SIZE]; + uchar_t vendor_info[SROM_SIZE]; uint32_t csr; uint16_t deviceid; - ddi_acc_handle_t handle; + ddi_acc_handle_t handle; int secondary; #define DNET_PCI_RNUMBER 1 @@ -1003,7 +1003,7 @@ static int dnet_set_addr(struct dnetinstance *dnetp) { struct tx_desc_type *desc; - int current_desc; + int current_desc; uint32_t val; ASSERT(MUTEX_HELD(&dnetp->intrlock)); @@ -1032,13 +1032,13 @@ dnet_set_addr(struct dnetinstance *dnetp) desc->buffer1 = dnetp->setup_buf_paddr; desc->buffer2 = 0; - desc->desc1.buffer_size1 = SETUPBUF_SIZE; - desc->desc1.buffer_size2 = 0; + desc->desc1.buffer_size1 = SETUPBUF_SIZE; + desc->desc1.buffer_size2 = 0; desc->desc1.setup_packet = 1; desc->desc1.first_desc = 0; - desc->desc1.last_desc = 0; - desc->desc1.filter_type0 = 1; - desc->desc1.filter_type1 = 1; + desc->desc1.last_desc = 0; + desc->desc1.filter_type0 = 1; + desc->desc1.filter_type1 = 1; desc->desc1.int_on_comp = 1; desc->desc0.own = 1; @@ -1128,12 +1128,12 @@ static uint32_t hashindex(const uint8_t *address) { uint32_t crc = (uint32_t)HASH_CRC; - uint32_t const POLY = HASH_POLY; + uint32_t const POLY = HASH_POLY; uint32_t msb; - int32_t byteslength; - uint8_t currentbyte; - uint32_t index; - int32_t bit; + int32_t byteslength; + uint8_t currentbyte; + uint32_t index; + int32_t bit; int32_t shift; for (byteslength = 0; byteslength < ETHERADDRL; byteslength++) { @@ -1331,6 +1331,7 @@ dnet_send(struct dnetinstance *dnetp, mblk_t *mp) mblk_t *bp; ASSERT(MUTEX_HELD(&dnetp->txlock)); + end_index = 0; /* reclaim any xmit descriptors completed */ dnet_reclaim_Tx_desc(dnetp); @@ -1583,7 +1584,7 @@ dnet_getp(struct dnetinstance *dnetp) { int packet_length, index; mblk_t *mp; - caddr_t virtual_address; + caddr_t virtual_address; struct rx_desc_type *desc = dnetp->rx_desc; int marker = dnetp->rx_current_desc; int misses; @@ -1699,7 +1700,7 @@ dnet_getp(struct dnetinstance *dnetp) /* * If no packet errors then do: - * 1. Allocate a new receive buffer so that we can + * 1. Allocate a new receive buffer so that we can * use the current buffer as streams buffer to * avoid bcopy. * 2. If we got a new receive buffer then allocate @@ -2009,7 +2010,7 @@ set_opr(struct dnetinstance *dnetp) { uint32_t fd, mb1, sf; - int opnmode_len; + int opnmode_len; uint32_t val; media_block_t *block = dnetp->selected_media_block; @@ -2859,7 +2860,7 @@ static void dnet_read21140srom(ddi_acc_handle_t io_handle, caddr_t io_reg, uchar_t *addr, int maxlen) { - uint32_t i, j; + uint32_t i, j; uint32_t dout; uint16_t word; uint8_t rom_addr; @@ -2993,7 +2994,7 @@ get_alternative_srom_image(dev_info_t *devinfo, uchar_t *vi, int len) */ pci_regspec_t *assignp; int assign_len; - int devnum; + int devnum; int primary_devnum; primary_devnum = ddi_getprop(DDI_DEV_T_ANY, devinfo, 0, @@ -3020,10 +3021,10 @@ get_alternative_srom_image(dev_info_t *devinfo, uchar_t *vi, int len) static void set_alternative_srom_image(dev_info_t *devinfo, uchar_t *vi, int len) { - int proplen; + int proplen; pci_regspec_t *assignp; int assign_len; - int devnum; + int devnum; if (ddi_getproplen(DDI_DEV_T_ANY, devinfo, DDI_PROP_DONTPASS, "DNET_SROM", &proplen) == DDI_PROP_SUCCESS || @@ -3520,7 +3521,7 @@ enable_interrupts(struct dnetinstance *dnetp) * calls dnet_intr for each of them. * Known cards that suffer from this problem are: * All Cogent multiport cards; - * Znyx 314; + * Znyx 314; * Znyx 315. * * XXX NEEDSWORK -- see comments above get_alternative_srom_image(). This @@ -4093,7 +4094,7 @@ dnet_parse_srom(struct dnetinstance *dnetp, SROM_FORMAT *sr, uchar_t *vi) /* Section 4.2, 4.3, 4.4, 4.5 */ static void parse_controller_leaf(struct dnetinstance *dnetp, LEAF_FORMAT *leaf, - uchar_t *vi) + uchar_t *vi) { int i; diff --git a/usr/src/uts/sparc/swapgeneric/Makefile b/usr/src/uts/sparc/swapgeneric/Makefile index 7f107a95d9..cb58eb5b20 100644 --- a/usr/src/uts/sparc/swapgeneric/Makefile +++ b/usr/src/uts/sparc/swapgeneric/Makefile @@ -41,7 +41,6 @@ UTSBASE = ../.. # MODULE = swapgeneric OBJECTS = $(SWAPGENERIC_OBJS:%=$(OBJS_DIR)/%) -LINTS = $(SWAPGENERIC_OBJS:%.o=$(LINTS_DIR)/%.ln) ROOTMODULE = $(ROOT_MISC_DIR)/$(MODULE) # @@ -53,7 +52,6 @@ include $(UTSBASE)/sparc/Makefile.sparc # Define targets # ALL_TARGET = $(BINARY) -LINT_TARGET = $(MODULE).lint INSTALL_TARGET = $(BINARY) $(ROOTMODULE) # @@ -62,7 +60,6 @@ INSTALL_TARGET = $(BINARY) $(ROOTMODULE) MODSTUBS_DIR = $(OBJS_DIR) $(MODSTUBS_O) := AS_CPPFLAGS += -DSWAPGENERIC_MODULE CLEANFILES += $(MODSTUBS_O) -CFLAGS += $(CCVERBOSE) CERRWARN += -_gcc=-Wno-parentheses @@ -79,12 +76,6 @@ clean: $(CLEAN_DEPS) clobber: $(CLOBBER_DEPS) -lint: $(LINT_DEPS) - -modlintlib: $(MODLINTLIB_DEPS) - -clean.lint: $(CLEAN_LINT_DEPS) - install: $(INSTALL_DEPS) # |