Index: amd64/amd64/mp_machdep.c =================================================================== RCS file: /usr/cvs/src/sys/amd64/amd64/mp_machdep.c,v retrieving revision 1.294 diff -u -r1.294 mp_machdep.c --- amd64/amd64/mp_machdep.c 28 Sep 2008 18:34:14 -0000 1.294 +++ amd64/amd64/mp_machdep.c 6 Oct 2008 16:35:55 -0000 @@ -783,13 +783,20 @@ /* wait for pending status end */ lapic_ipi_wait(-1); - /* do an INIT IPI: deassert RESET */ - lapic_ipi_raw(APIC_DEST_ALLESELF | APIC_TRIGMOD_LEVEL | - APIC_LEVEL_DEASSERT | APIC_DESTMODE_PHY | APIC_DELMODE_INIT, 0); - - /* wait for pending status end */ - DELAY(10000); /* wait ~10mS */ - lapic_ipi_wait(-1); + /* + * do an INIT IPI: deassert RESET on older systems to reset APIC ID + * arbitration. XXX: Should we only do this once? + */ + if (strcmp(cpu_vendor, "GenuineIntel") != 0 || + (cpu_id & 0xf00) != 0xf00) { + lapic_ipi_raw(APIC_DEST_ALLESELF | APIC_TRIGMOD_LEVEL | + APIC_LEVEL_DEASSERT | APIC_DESTMODE_PHY | APIC_DELMODE_INIT, + 0); + + /* wait for pending status end */ + DELAY(10000); /* wait ~10mS */ + lapic_ipi_wait(-1); + } /* * next we do a STARTUP IPI: the previous INIT IPI might still be Index: amd64/pci/pci_cfgreg.c =================================================================== RCS file: /usr/cvs/src/sys/amd64/pci/pci_cfgreg.c,v retrieving revision 1.113 diff -u -r1.113 pci_cfgreg.c --- amd64/pci/pci_cfgreg.c 11 Sep 2008 21:42:11 -0000 1.113 +++ amd64/pci/pci_cfgreg.c 6 Oct 2008 16:35:58 -0000 @@ -117,11 +117,17 @@ static uint32_t pci_docfgregread(int bus, int slot, int func, int reg, int bytes) { + uint32_t val1, val2; if (cfgmech == CFGMECH_PCIE && - (bus != 0 || !(1 << slot & pcie_badslots))) - return (pciereg_cfgread(bus, slot, func, reg, bytes)); - else + (bus != 0 || !(1 << slot & pcie_badslots))) { + val1 = pciereg_cfgread(bus, slot, func, reg, bytes); + val2 = pcireg_cfgread(bus, slot, func, reg, bytes); + if (val1 != val2) + panic("pci_cfgread(%d:%d:%d, %d, %d) => %#x, %#x", + bus, slot, func, reg, bytes, val1, val2); + return (val1); + } else return (pcireg_cfgread(bus, slot, func, reg, bytes)); } Index: compat/freebsd32/freebsd32_misc.c =================================================================== RCS file: /usr/cvs/src/sys/compat/freebsd32/freebsd32_misc.c,v retrieving revision 1.83 diff -u -r1.83 freebsd32_misc.c --- compat/freebsd32/freebsd32_misc.c 10 Nov 2008 23:36:20 -0000 1.83 +++ compat/freebsd32/freebsd32_misc.c 11 Nov 2008 18:44:47 -0000 @@ -147,11 +147,14 @@ } #ifdef COMPAT_FREEBSD4 -static void +static int copy_statfs(struct statfs *in, struct statfs32 *out) { + int error; - statfs_scale_blocks(in, INT32_MAX); + error = statfs_scale_blocks(in, INT32_MAX); + if (error) + return (error); bzero(out, sizeof(*out)); CP(*in, *out, f_bsize); out->f_iosize = MIN(in->f_iosize, INT32_MAX); @@ -159,21 +162,25 @@ CP(*in, *out, f_bfree); CP(*in, *out, f_bavail); out->f_files = MIN(in->f_files, INT32_MAX); - out->f_ffree = MIN(in->f_ffree, INT32_MAX); + if (in->f_ffree < 0) + out->f_ffree = MAX(in->f_ffree, INT32_MIN); + else + out->f_ffree = MIN(in->f_ffree, INT32_MAX); CP(*in, *out, f_fsid); CP(*in, *out, f_owner); CP(*in, *out, f_type); CP(*in, *out, f_flags); - out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX); - out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX); + CP(*in, *out, f_syncwrites); + CP(*in, *out, f_asyncwrites); strlcpy(out->f_fstypename, in->f_fstypename, MFSNAMELEN); strlcpy(out->f_mntonname, in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN)); - out->f_syncreads = MIN(in->f_syncreads, INT32_MAX); - out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX); + CP(*in, *out, f_syncreads); + CP(*in, *out, f_asyncreads); strlcpy(out->f_mntfromname, in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN)); + return (0); } #endif @@ -193,7 +200,9 @@ count = td->td_retval[0]; sp = buf; while (count > 0 && error == 0) { - copy_statfs(sp, &stat32); + error = copy_statfs(sp, &stat32); + if (error) + break; error = copyout(&stat32, uap->buf, sizeof(stat32)); sp++; uap->buf++; @@ -1306,7 +1315,9 @@ error = kern_statfs(td, uap->path, UIO_USERSPACE, &s); if (error) return (error); - copy_statfs(&s, &s32); + error = copy_statfs(&s, &s32); + if (error) + return (error); return (copyout(&s32, uap->buf, sizeof(s32))); } #endif @@ -1322,7 +1333,9 @@ error = kern_fstatfs(td, uap->fd, &s); if (error) return (error); - copy_statfs(&s, &s32); + error = copy_statfs(&s, &s32); + if (error) + return (error); return (copyout(&s32, uap->buf, sizeof(s32))); } #endif @@ -1341,7 +1354,9 @@ error = kern_fhstatfs(td, fh, &s); if (error) return (error); - copy_statfs(&s, &s32); + error = copy_statfs(&s, &s32); + if (error) + return (error); return (copyout(&s32, uap->buf, sizeof(s32))); } #endif Index: compat/svr4/imgact_svr4.c =================================================================== RCS file: /usr/cvs/src/sys/compat/svr4/imgact_svr4.c,v retrieving revision 1.28 diff -u -r1.28 imgact_svr4.c --- compat/svr4/imgact_svr4.c 13 Jan 2008 14:44:01 -0000 1.28 +++ compat/svr4/imgact_svr4.c 14 Jan 2008 20:46:08 -0000 @@ -55,6 +55,8 @@ #include +#define DEBUG + static int exec_svr4_imgact(struct image_params *iparams); static int @@ -69,9 +71,11 @@ unsigned long bss_size; int error; + printf("%s: checking magic value\n", __func__); if (((a_out->a_magic >> 16) & 0xff) != 0x64) return -1; + printf("%s: determining file/virtual offsets\n", __func__); /* * Set file/virtual offset based on a.out variant. */ @@ -92,6 +96,7 @@ printf("imgact: text: %08lx, data: %08lx, bss: %08lx\n", (u_long)a_out->a_text, (u_long)a_out->a_data, bss_size); #endif + printf("%s: validating header\n", __func__); /* * Check various fields in header for validity/bounds. */ @@ -100,9 +105,11 @@ a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK) return (-1); + printf("%s: comparing text + data size against file size\n", __func__); /* text + data can't exceed file size */ if (a_out->a_data + a_out->a_text > imgp->attr->va_size) return (EFAULT); + printf("%s: checking text and data against limits\n", __func__); /* * text/data/bss must not exceed limits */ @@ -133,6 +140,7 @@ #ifdef DEBUG printf("imgact: Non page aligned binary %lu\n", file_offset); #endif + printf("%s: vm_map_find\n", __func__); /* * Map text+data+bss read/write/execute */ @@ -143,6 +151,7 @@ if (error) goto fail; + printf("%s: vm_mmap\n", __func__); error = vm_mmap(kernel_map, &buffer, round_page(a_out->a_text + a_out->a_data + file_offset), VM_PROT_READ, VM_PROT_READ, 0, @@ -150,6 +159,7 @@ if (error) goto fail; + printf("%s: copyout\n", __func__); error = copyout((caddr_t)(buffer + file_offset), (caddr_t)vmaddr, a_out->a_text + a_out->a_data); @@ -159,6 +169,7 @@ if (error) goto fail; + printf("%s: vm_map_protect\n", __func__); /* * remove write enable on the 'text' part */ @@ -174,6 +185,7 @@ #ifdef DEBUG printf("imgact: Page aligned binary %lu\n", file_offset); #endif + printf("%s: vm_mmap\n", __func__); /* * Map text+data read/execute */ @@ -191,6 +203,7 @@ printf("imgact: startaddr=%08lx, length=%08lx\n", (u_long)vmaddr, (u_long)a_out->a_text + a_out->a_data); #endif + printf("%s: vm_map_protect\n", __func__); /* * allow read/write of data */ @@ -206,6 +219,7 @@ * Allocate anon demand-zeroed area for uninitialized data */ if (bss_size != 0) { + printf("%s: BSS vm_map_find\n", __func__); vmaddr = virtual_offset + a_out->a_text + a_out->a_data; error = vm_map_find(&vmspace->vm_map, NULL, 0, &vmaddr, bss_size, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0); Index: dev/acpica/acpi_hpet.c =================================================================== RCS file: /usr/cvs/src/sys/dev/acpica/acpi_hpet.c,v retrieving revision 1.14 diff -u -r1.14 acpi_hpet.c --- dev/acpica/acpi_hpet.c 16 Jan 2008 18:47:07 -0000 1.14 +++ dev/acpica/acpi_hpet.c 17 Jan 2008 18:45:30 -0000 @@ -59,7 +59,7 @@ static char *hpet_ids[] = { "PNP0103", NULL }; -#define DEV_HPET(x) (acpi_get_magic(x) == (uintptr_t)&acpi_hpet_devclass) +#define DEV_HPET(x) (acpi_get_handle(x) == NULL) struct timecounter hpet_timecounter = { .tc_get_timecount = hpet_get_timecount, @@ -96,7 +96,7 @@ } /* Discover the HPET via the ACPI table of the same name. */ -static void +static void acpi_hpet_identify(driver_t *driver, device_t parent) { ACPI_TABLE_HPET *hpet; @@ -128,8 +128,6 @@ return; } - /* Record a magic value so we can detect this device later. */ - acpi_set_magic(child, (uintptr_t)&acpi_hpet_devclass); bus_set_resource(child, SYS_RES_MEMORY, 0, hpet->Address.Address, HPET_MEM_WIDTH); } Index: dev/isp/isp_pci.c =================================================================== RCS file: /usr/cvs/src/sys/dev/isp/isp_pci.c,v retrieving revision 1.148 diff -u -r1.148 isp_pci.c --- dev/isp/isp_pci.c 26 Jun 2007 23:08:57 -0000 1.148 +++ dev/isp/isp_pci.c 6 May 2008 20:30:12 -0000 @@ -859,13 +859,12 @@ irq = regs = NULL; rgd = rtp = iqd = 0; - cmd = pci_read_config(dev, PCIR_COMMAND, 2); - if (cmd & m1) { + if (m1) { rtp = (m1 == PCIM_CMD_MEMEN)? SYS_RES_MEMORY : SYS_RES_IOPORT; rgd = (m1 == PCIM_CMD_MEMEN)? MEM_MAP_REG : IO_MAP_REG; regs = bus_alloc_resource_any(dev, rtp, &rgd, RF_ACTIVE); } - if (regs == NULL && (cmd & m2)) { + if (regs == NULL && m2) { rtp = (m2 == PCIM_CMD_MEMEN)? SYS_RES_MEMORY : SYS_RES_IOPORT; rgd = (m2 == PCIM_CMD_MEMEN)? MEM_MAP_REG : IO_MAP_REG; regs = bus_alloc_resource_any(dev, rtp, &rgd, RF_ACTIVE); @@ -1066,6 +1065,7 @@ * Make sure that SERR, PERR, WRITE INVALIDATE and BUSMASTER * are set. */ + cmd = pci_read_config(dev, PCIR_COMMAND, 2); cmd |= PCIM_CMD_SEREN | PCIM_CMD_PERRESPEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_INVEN; Index: dev/pci/pci.c =================================================================== RCS file: /usr/cvs/src/sys/dev/pci/pci.c,v retrieving revision 1.365 diff -u -r1.365 pci.c --- dev/pci/pci.c 21 Oct 2008 21:53:55 -0000 1.365 +++ dev/pci/pci.c 24 Oct 2008 14:53:42 -0000 @@ -2357,6 +2357,8 @@ * respond oddly to having these bits enabled. Let the user * be able to turn them off (since pci_enable_io_modes is 1 by * default). + * + * XXX: We probably shouldn't do this until after programming the BAR. */ if (pci_enable_io_modes) { /* Turn on resources that have been left off by a lazy BIOS */ Index: dev/tx/if_tx.c =================================================================== RCS file: /usr/cvs/src/sys/dev/tx/if_tx.c,v retrieving revision 1.99 diff -u -r1.99 if_tx.c --- dev/tx/if_tx.c 12 Sep 2008 14:41:53 -0000 1.99 +++ dev/tx/if_tx.c 6 Oct 2008 16:36:50 -0000 @@ -1289,9 +1289,12 @@ CSR_WRITE_4(sc, PTCDAR, sc->tx_addr); /* Put node address to EPIC. */ - CSR_WRITE_4(sc, LAN0, ((u_int16_t *)IF_LLADDR(sc->ifp))[0]); - CSR_WRITE_4(sc, LAN1, ((u_int16_t *)IF_LLADDR(sc->ifp))[1]); - CSR_WRITE_4(sc, LAN2, ((u_int16_t *)IF_LLADDR(sc->ifp))[2]); + CSR_WRITE_4(sc, LAN0, IF_LLADDR(sc->ifp)[0] | + IF_LLADDR(sc->ifp)[1] << 8); + CSR_WRITE_4(sc, LAN1, IF_LLADDR(sc->ifp)[2] | + IF_LLADDR(sc->ifp)[3] << 8); + CSR_WRITE_4(sc, LAN2, IF_LLADDR(sc->ifp)[4] | + IF_LLADDR(sc->ifp)[5] << 8); /* Set tx mode, includeing transmit threshold. */ epic_set_tx_mode(sc); Index: i386/i386/local_apic.c =================================================================== RCS file: /usr/cvs/src/sys/i386/i386/local_apic.c,v retrieving revision 1.51 diff -u -r1.51 local_apic.c --- i386/i386/local_apic.c 27 Oct 2008 21:06:16 -0000 1.51 +++ i386/i386/local_apic.c 11 Nov 2008 18:45:37 -0000 @@ -860,6 +860,7 @@ ("No ISR handler for vector %u", vector)); setidt(vector, ioint_handlers[vector / 32], SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL)); + smp_rendezvous(NULL, NULL, NULL, NULL); } void Index: i386/i386/mp_machdep.c =================================================================== RCS file: /usr/cvs/src/sys/i386/i386/mp_machdep.c,v retrieving revision 1.289 diff -u -r1.289 mp_machdep.c --- i386/i386/mp_machdep.c 28 Sep 2008 18:34:14 -0000 1.289 +++ i386/i386/mp_machdep.c 6 Oct 2008 16:37:01 -0000 @@ -898,13 +898,20 @@ /* wait for pending status end */ lapic_ipi_wait(-1); - /* do an INIT IPI: deassert RESET */ - lapic_ipi_raw(APIC_DEST_ALLESELF | APIC_TRIGMOD_LEVEL | - APIC_LEVEL_DEASSERT | APIC_DESTMODE_PHY | APIC_DELMODE_INIT, 0); - - /* wait for pending status end */ - DELAY(10000); /* wait ~10mS */ - lapic_ipi_wait(-1); + /* + * do an INIT IPI: deassert RESET on older systems to reset APIC ID + * arbitration. XXX: Should we only do this once? + */ + if (strcmp(cpu_vendor, "GenuineIntel") != 0 || + (cpu_id & 0xf00) != 0xf00) { + lapic_ipi_raw(APIC_DEST_ALLESELF | APIC_TRIGMOD_LEVEL | + APIC_LEVEL_DEASSERT | APIC_DESTMODE_PHY | APIC_DELMODE_INIT, + 0); + + /* wait for pending status end */ + DELAY(10000); /* wait ~10mS */ + lapic_ipi_wait(-1); + } /* * next we do a STARTUP IPI: the previous INIT IPI might still be Index: i386/pci/pci_cfgreg.c =================================================================== RCS file: /usr/cvs/src/sys/i386/pci/pci_cfgreg.c,v retrieving revision 1.132 diff -u -r1.132 pci_cfgreg.c --- i386/pci/pci_cfgreg.c 11 Sep 2008 21:42:11 -0000 1.132 +++ i386/pci/pci_cfgreg.c 6 Oct 2008 16:37:03 -0000 @@ -204,11 +204,17 @@ static uint32_t pci_docfgregread(int bus, int slot, int func, int reg, int bytes) { + uint32_t val1, val2; if (cfgmech == CFGMECH_PCIE && - (bus != 0 || !(1 << slot & pcie_badslots))) - return (pciereg_cfgread(bus, slot, func, reg, bytes)); - else + (bus != 0 || !(1 << slot & pcie_badslots))) { + val1 = pciereg_cfgread(bus, slot, func, reg, bytes); + val2 = pcireg_cfgread(bus, slot, func, reg, bytes); + if (val1 != val2) + panic("pci_cfgread(%d:%d:%d, %d, %d) => %#x, %#x", + bus, slot, func, reg, bytes, val1, val2); + return (val1); + } else return (pcireg_cfgread(bus, slot, func, reg, bytes)); } Index: kern/sched_ule.c =================================================================== RCS file: /usr/cvs/src/sys/kern/sched_ule.c,v retrieving revision 1.248 diff -u -r1.248 sched_ule.c --- kern/sched_ule.c 2 Nov 2008 23:11:20 -0000 1.248 +++ kern/sched_ule.c 11 Nov 2008 18:45:43 -0000 @@ -946,7 +946,7 @@ static void tdq_notify(struct tdq *tdq, struct thread *td) { - int cpri; + struct thread *ctd; int pri; int cpu; @@ -954,10 +954,10 @@ return; cpu = td->td_sched->ts_cpu; pri = td->td_priority; - cpri = pcpu_find(cpu)->pc_curthread->td_priority; - if (!sched_shouldpreempt(pri, cpri, 1)) + ctd = pcpu_find(cpu)->pc_curthread; + if (!sched_shouldpreempt(pri, ctd->td_priority, 1)) return; - if (TD_IS_IDLETHREAD(td)) { + if (TD_IS_IDLETHREAD(ctd)) { /* * If the idle thread is still 'running' it's probably * waiting on us to release the tdq spinlock already. No Index: kern/subr_witness.c =================================================================== RCS file: /usr/cvs/src/sys/kern/subr_witness.c,v retrieving revision 1.262 diff -u -r1.262 subr_witness.c --- kern/subr_witness.c 23 Oct 2008 20:26:15 -0000 1.262 +++ kern/subr_witness.c 11 Nov 2008 18:45:44 -0000 @@ -1043,26 +1043,45 @@ class->lc_name, lock->lo_name, file, line); /* - * If this is the first lock acquired then just return as - * no order checking is needed. + * If this is the first lock acquired then just return + * as no order checking is needed. */ +<<<<<<< subr_witness.c + lock_list = td->td_sleeplocks; + if (lock_list->ll_count == 0) +======= lock_list = td->td_sleeplocks; if (lock_list == NULL || lock_list->ll_count == 0) +>>>>>>> 1.260 return; } else { /* * If this is the first lock, just return as no order +<<<<<<< subr_witness.c + * checking is needed. We have to disable migration + * while doing this check. If we have another spin + * lock already, it will protect the list for the rest + * of this routine. +======= * checking is needed. Avoid problems with thread * migration pinning the thread while checking if * spinlocks are held. If at least one spinlock is held * the thread is in a safe path and it is allowed to * unpin it. +>>>>>>> 1.260 */ +<<<<<<< subr_witness.c + sched_pin(); + lock_list = PCPU_GET(spinlocks); + if (lock_list->ll_count == 0) { + sched_unpin(); +======= sched_pin(); lock_list = PCPU_GET(spinlocks); if (lock_list == NULL || lock_list->ll_count == 0) { sched_unpin(); +>>>>>>> 1.260 return; } sched_unpin(); @@ -1099,11 +1118,15 @@ */ plock = &lock_list->ll_children[lock_list->ll_count - 1]; if (interlock != NULL && plock->li_lock == interlock) { +<<<<<<< subr_witness.c + if (lock_list->ll_count == 1) { +======= if (lock_list->ll_count > 1) plock = &lock_list->ll_children[lock_list->ll_count - 2]; else { lle = lock_list->ll_next; +>>>>>>> 1.260 /* * The interlock is the only lock we hold, so @@ -1113,6 +1136,10 @@ return; plock = &lle->ll_children[lle->ll_count - 1]; } +<<<<<<< subr_witness.c + plock = &lock_list->ll_children[lock_list->ll_count - 2]; +======= +>>>>>>> 1.260 } /* Index: kern/sysv_shm.c =================================================================== RCS file: /usr/cvs/src/sys/kern/sysv_shm.c,v retrieving revision 1.113 diff -u -r1.113 sysv_shm.c --- kern/sysv_shm.c 12 Feb 2008 20:55:03 -0000 1.113 +++ kern/sysv_shm.c 25 Aug 2008 22:05:10 -0000 @@ -276,7 +276,7 @@ return (EINVAL); shmmap_s->shmid = -1; shmseg->u.shm_dtime = time_second; - if ((--shmseg->u.shm_nattch <= 0) && + if ((--shmseg->nattach <= 0) && (shmseg->u.shm_perm.mode & SHMSEG_REMOVED)) { shm_deallocate_segment(shmseg); shm_last_free = segnum; @@ -381,6 +381,11 @@ if (error != 0) goto done2; #endif + if (shmseg->nattach >= USHORT_MAX - 1) { + /* XXX: This may not be the best error value. */ + error = EMFILE; + goto done2; + } for (i = 0; i < shminfo.shmseg; i++) { if (shmmap_s->shmid == -1) break; @@ -435,7 +440,7 @@ shmmap_s->shmid = shmid; shmseg->u.shm_lpid = p->p_pid; shmseg->u.shm_atime = time_second; - shmseg->u.shm_nattch++; + shmseg->nattach++; td->td_retval[0] = attach_va; done2: mtx_unlock(&Giant); @@ -500,7 +505,7 @@ outbuf.shm_segsz = shmseg->u.shm_segsz; outbuf.shm_cpid = shmseg->u.shm_cpid; outbuf.shm_lpid = shmseg->u.shm_lpid; - outbuf.shm_nattch = shmseg->u.shm_nattch; + outbuf.shm_nattch = MIN(USHORT_MAX, shmseg->nattach); outbuf.shm_atime = shmseg->u.shm_atime; outbuf.shm_dtime = shmseg->u.shm_dtime; outbuf.shm_ctime = shmseg->u.shm_ctime; @@ -594,6 +599,7 @@ error = ipcperm(td, &shmseg->u.shm_perm, IPC_R); if (error) goto done2; + shmseg->u.shm_nattch = MIN(USHORT_MAX, shmseg->nattach); memcpy(buf, &shmseg->u, sizeof(struct shmid_ds)); if (bufsz) *bufsz = sizeof(struct shmid_ds); @@ -621,7 +627,7 @@ goto done2; shmseg->u.shm_perm.key = IPC_PRIVATE; shmseg->u.shm_perm.mode |= SHMSEG_REMOVED; - if (shmseg->u.shm_nattch <= 0) { + if (shmseg->nattach <= 0) { shm_deallocate_segment(shmseg); shm_last_free = IPCID_TO_IX(shmid); } @@ -791,7 +797,7 @@ (mode & ACCESSPERMS) | SHMSEG_ALLOCATED; shmseg->u.shm_segsz = uap->size; shmseg->u.shm_cpid = td->td_proc->p_pid; - shmseg->u.shm_lpid = shmseg->u.shm_nattch = 0; + shmseg->u.shm_lpid = shmseg->nattach = 0; shmseg->u.shm_atime = shmseg->u.shm_dtime = 0; #ifdef MAC mac_sysvshm_create(cred, shmseg); @@ -886,7 +892,7 @@ p2->p_vmspace->vm_shm = shmmap_s; for (i = 0; i < shminfo.shmseg; i++, shmmap_s++) if (shmmap_s->shmid != -1) - shmsegs[IPCID_TO_IX(shmmap_s->shmid)].u.shm_nattch++; + shmsegs[IPCID_TO_IX(shmmap_s->shmid)].nattach++; mtx_unlock(&Giant); } Index: kern/vfs_syscalls.c =================================================================== RCS file: /usr/cvs/src/sys/kern/vfs_syscalls.c,v retrieving revision 1.465 diff -u -r1.465 vfs_syscalls.c --- kern/vfs_syscalls.c 5 Nov 2008 19:40:36 -0000 1.465 +++ kern/vfs_syscalls.c 11 Nov 2008 18:45:46 -0000 @@ -225,7 +225,7 @@ * that 'max_size' should be a bitmask, i.e. 2^n - 1 for some non-zero * value of 'n'. */ -void +int statfs_scale_blocks(struct statfs *sf, long max_size) { uint64_t count; @@ -245,19 +245,27 @@ count = sf->f_bavail; count = MAX(sf->f_blocks, MAX(sf->f_bfree, count)); if (count <= max_size) - return; + return (0); + + if (sf->f_bsize >= max_size) + return (EOVERFLOW); count >>= flsl(max_size); shift = 0; while (count > 0) { shift++; - count >>=1; + count >>= 1; } + /* XXX: What if this overflows? */ + if (sf->f_bsize << shift > max_size || sf->f_bsize << shift == 0) + return (EOVERFLOW); + sf->f_bsize <<= shift; sf->f_blocks >>= shift; sf->f_bfree >>= shift; sf->f_bavail >>= shift; + return (0); } /* @@ -553,7 +561,7 @@ /* * Get old format filesystem statistics. */ -static void cvtstatfs(struct statfs *, struct ostatfs *); +static int cvtstatfs(struct statfs *, struct ostatfs *); #ifndef _SYS_SYSPROTO_H_ struct freebsd4_statfs_args { @@ -576,7 +584,9 @@ error = kern_statfs(td, uap->path, UIO_USERSPACE, &sf); if (error) return (error); - cvtstatfs(&sf, &osb); + error = cvtstatfs(&sf, &osb); + if (error) + return (error); return (copyout(&osb, uap->buf, sizeof(osb))); } @@ -604,7 +614,9 @@ error = kern_fstatfs(td, uap->fd, &sf); if (error) return (error); - cvtstatfs(&sf, &osb); + error = cvtstatfs(&sf, &osb); + if (error) + return (error); return (copyout(&osb, uap->buf, sizeof(osb))); } @@ -639,7 +651,9 @@ count = td->td_retval[0]; sp = buf; while (count > 0 && error == 0) { - cvtstatfs(sp, &osb); + error = cvtstatfs(sp, &osb); + if (error) + break; error = copyout(&osb, uap->buf, sizeof(osb)); sp++; uap->buf++; @@ -678,20 +692,25 @@ error = kern_fhstatfs(td, fh, &sf); if (error) return (error); - cvtstatfs(&sf, &osb); + error = cvtstatfs(&sf, &osb); + if (error) + return (error); return (copyout(&osb, uap->buf, sizeof(osb))); } /* * Convert a new format statfs structure to an old format statfs structure. */ -static void +static int cvtstatfs(nsp, osp) struct statfs *nsp; struct ostatfs *osp; { + int error; - statfs_scale_blocks(nsp, LONG_MAX); + error = statfs_scale_blocks(nsp, LONG_MAX); + if (error) + return (error); bzero(osp, sizeof(*osp)); osp->f_bsize = nsp->f_bsize; osp->f_iosize = MIN(nsp->f_iosize, LONG_MAX); @@ -699,14 +718,17 @@ osp->f_bfree = nsp->f_bfree; osp->f_bavail = nsp->f_bavail; osp->f_files = MIN(nsp->f_files, LONG_MAX); - osp->f_ffree = MIN(nsp->f_ffree, LONG_MAX); + if (nsp->f_ffree < 0) + osp->f_ffree = MAX(nsp->f_ffree, LONG_MIN); + else + osp->f_ffree = MIN(nsp->f_ffree, LONG_MAX); osp->f_owner = nsp->f_owner; osp->f_type = nsp->f_type; osp->f_flags = nsp->f_flags; - osp->f_syncwrites = MIN(nsp->f_syncwrites, LONG_MAX); - osp->f_asyncwrites = MIN(nsp->f_asyncwrites, LONG_MAX); - osp->f_syncreads = MIN(nsp->f_syncreads, LONG_MAX); - osp->f_asyncreads = MIN(nsp->f_asyncreads, LONG_MAX); + osp->f_syncwrites = nsp->f_syncwrites; + osp->f_asyncwrites = nsp->f_asyncwrites; + osp->f_syncreads = nsp->f_syncreads; + osp->f_asyncreads = nsp->f_asyncreads; strlcpy(osp->f_fstypename, nsp->f_fstypename, MIN(MFSNAMELEN, OMFSNAMELEN)); strlcpy(osp->f_mntonname, nsp->f_mntonname, @@ -714,6 +736,7 @@ strlcpy(osp->f_mntfromname, nsp->f_mntfromname, MIN(MNAMELEN, OMNAMELEN)); osp->f_fsid = nsp->f_fsid; + return (0); } #endif /* COMPAT_FREEBSD4 */ Index: netsmb/smb_conn.c =================================================================== RCS file: /usr/cvs/src/sys/netsmb/smb_conn.c,v retrieving revision 1.23 diff -u -r1.23 smb_conn.c --- netsmb/smb_conn.c 2 Nov 2008 23:15:32 -0000 1.23 +++ netsmb/smb_conn.c 11 Nov 2008 18:46:21 -0000 @@ -210,8 +210,11 @@ error = smb_smb_treeconnect(ssp, scred); if (error == 0) vcspec->ssp = ssp; - else + else { + smb_vc_put(vcp, scred); + vcp = NULL; smb_share_put(ssp, scred); + } out: smb_sm_unlockvclist(); if (error == 0) @@ -349,6 +352,7 @@ if (smb_co_lockstatus(cp) == LK_EXCLUSIVE && (flags & LK_CANRECURSE) == 0) { SMBERROR("recursive lock for object %d\n", cp->co_level); + panic("recursive lock for object %p", cp); return 0; } return lockmgr(&cp->co_lock, flags, &cp->co_interlock); Index: opencrypto/crypto.c =================================================================== RCS file: /usr/cvs/src/sys/opencrypto/crypto.c,v retrieving revision 1.28 diff -u -r1.28 crypto.c --- opencrypto/crypto.c 20 Oct 2007 23:23:22 -0000 1.28 +++ opencrypto/crypto.c 10 Mar 2008 21:05:03 -0000 @@ -99,7 +99,8 @@ * Not tagged fields are read-only. */ struct cryptocap { - device_t cc_dev; /* (d) device/driver */ + struct kobj *cc_dev; /* (d) device/driver */ + const char *cc_name; /* (d) device name */ u_int32_t cc_sessions; /* (d) # of sessions */ u_int32_t cc_koperations; /* (d) # os asym operations */ /* @@ -476,7 +477,7 @@ * support for the algorithms they handle. */ int32_t -crypto_get_driverid(device_t dev, int flags) +crypto_get_driverid(struct kobj *dev, const char *name, int flags) { struct cryptocap *newdrv; int i; @@ -538,7 +539,7 @@ /* * Lookup a driver by name. We match against the full device * name and unit, and against just the name. The latter gives - * us a simple widlcarding by device name. On success return the + * us a simple wildcarding by device name. On success return the * driver/hardware identifier; otherwise return -1. */ int @@ -548,12 +549,17 @@ CRYPTO_DRIVER_LOCK(); for (i = 0; i < crypto_drivers_num; i++) { - device_t dev = crypto_drivers[i].cc_dev; - if (dev == NULL || + if (crypto_drivers[i].cc_dev == NULL || (crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP)) continue; - if (strncmp(match, device_get_nameunit(dev), len) == 0 || - strncmp(match, device_get_name(dev), len) == 0) + /* + * Previously this did two checks. However, the second + * check was never relevant. If the user asked for just + * "foo" then 'len' will be 3 and the 'strncmp()' will + * match "foo0" just fine without requiring a separate + * match against "foo". + */ + if (strncmp(match, cc->cc_name, len) == 0) break; } CRYPTO_DRIVER_UNLOCK(); @@ -563,6 +569,8 @@ /* * Return the device_t for the specified driver or NULL * if the driver identifier is invalid. + * + * XXX: This needs to change to copy the name into a caller-supplied buffer. */ device_t crypto_find_device_byhid(int hid) @@ -605,7 +613,7 @@ cap->cc_kalg[kalg] = flags | CRYPTO_ALG_FLAG_SUPPORTED; if (bootverbose) printf("crypto: %s registers key alg %u flags %u\n" - , device_get_nameunit(cap->cc_dev) + , cap->cc_name , kalg , flags ); @@ -644,7 +652,7 @@ cap->cc_max_op_len[alg] = maxoplen; if (bootverbose) printf("crypto: %s registers alg %u flags %u maxoplen %u\n" - , device_get_nameunit(cap->cc_dev) + , cap->cc_name , alg , flags , maxoplen @@ -1454,7 +1462,7 @@ if (cap->cc_dev == NULL) continue; db_printf("%-12s %4u %4u %08x %2u %2u\n" - , device_get_nameunit(cap->cc_dev) + , cap->cc_name , cap->cc_sessions , cap->cc_koperations , cap->cc_flags Index: opencrypto/cryptosoft.c =================================================================== RCS file: /usr/cvs/src/sys/opencrypto/cryptosoft.c,v retrieving revision 1.21 diff -u -r1.21 cryptosoft.c --- opencrypto/cryptosoft.c 30 Oct 2008 16:11:07 -0000 1.21 +++ opencrypto/cryptosoft.c 11 Nov 2008 18:46:23 -0000 @@ -61,7 +61,7 @@ static int swcr_encdec(struct cryptodesc *, struct swcr_data *, caddr_t, int); static int swcr_authcompute(struct cryptodesc *, struct swcr_data *, caddr_t, int); static int swcr_compdec(struct cryptodesc *, struct swcr_data *, caddr_t, int); -static int swcr_freesession(device_t dev, u_int64_t tid); +static int swcr_freesession(struct kobj *kobj, u_int64_t tid); /* * Apply a symmetric encryption/decryption algorithm. @@ -588,7 +588,7 @@ * Generate a new software session. */ static int -swcr_newsession(device_t dev, u_int32_t *sid, struct cryptoini *cri) +swcr_newsession(struct kobj *kobj, u_int32_t *sid, struct cryptoini *cri) { struct swcr_data **swd; struct auth_hash *axf; @@ -797,7 +797,7 @@ * Free a session. */ static int -swcr_freesession(device_t dev, u_int64_t tid) +swcr_freesession(struct kobj *kobj, u_int64_t tid) { struct swcr_data *swd; struct enc_xform *txf; @@ -886,7 +886,7 @@ * Process a software request. */ static int -swcr_process(device_t dev, struct cryptop *crp, int hint) +swcr_process(struct kobj *kobj, struct cryptop *crp, int hint) { struct cryptodesc *crd; struct swcr_data *sw; @@ -980,33 +980,33 @@ return 0; } -static void -swcr_identify(device_t *dev, device_t parent) -{ - /* NB: order 10 is so we get attached after h/w devices */ - if (device_find_child(parent, "cryptosoft", -1) == NULL && - BUS_ADD_CHILD(parent, 10, "cryptosoft", -1) == 0) - panic("cryptosoft: could not attach"); -} +static struct kobj_method swcr_methods[] = { + KOBJMETHOD(cryptodev_newsession, swcr_newsession), + KOBJMETHOD(cryptodev_freesession, swcr_freesession), + KOBJMETHOD(cryptodev_process, swcr_process), -static int -swcr_probe(device_t dev) -{ - device_set_desc(dev, "software crypto"); - return (0); -} + {0, 0}, +}; -static int -swcr_attach(device_t dev) +DEFINE_CLASS(cryptosoft, swcr_methods, 0); + +static struct kobj *swcr_kobj; + +static void +swcr_init(void) { + + kobj_class_compile(&cryptosoft_class); + kobj_init(&swcr_kobj, &cryptosoft_class); + swcr_kobj = kobj_create(&cryptosoft_class, M_CRYPTO_DATA, M_WAITOK); memset(hmac_ipad_buffer, HMAC_IPAD_VAL, HMAC_MAX_BLOCK_LEN); memset(hmac_opad_buffer, HMAC_OPAD_VAL, HMAC_MAX_BLOCK_LEN); - swcr_id = crypto_get_driverid(dev, + swcr_id = crypto_get_driverid(swcr_kobj, "cryptosoft0", CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_SYNC); if (swcr_id < 0) { - device_printf(dev, "cannot initialize!"); - return ENOMEM; + printf("cryptosoft0: cannot initialize!"); + return; } #define REGISTER(alg) \ crypto_register(swcr_id, alg, 0,0) @@ -1031,38 +1031,25 @@ REGISTER(CRYPTO_CAMELLIA_CBC); REGISTER(CRYPTO_DEFLATE_COMP); #undef REGISTER - - return 0; } static void -swcr_detach(device_t dev) +swcr_destroy(void) { crypto_unregister_all(swcr_id); if (swcr_sessions != NULL) +<<<<<<< cryptosoft.c + FREE(swcr_sessions, M_CRYPTO_DATA); + if (swcr_kobj != NULL) { + kobj_delete(swcr_kobj, M_CRYPTO_DATA); + swcr_kobj = NULL; + kobj_class_free(&cryptosoft_class); + } +======= free(swcr_sessions, M_CRYPTO_DATA); +>>>>>>> 1.21 } -static device_method_t swcr_methods[] = { - DEVMETHOD(device_identify, swcr_identify), - DEVMETHOD(device_probe, swcr_probe), - DEVMETHOD(device_attach, swcr_attach), - DEVMETHOD(device_detach, swcr_detach), - - DEVMETHOD(cryptodev_newsession, swcr_newsession), - DEVMETHOD(cryptodev_freesession,swcr_freesession), - DEVMETHOD(cryptodev_process, swcr_process), - - {0, 0}, -}; - -static driver_t swcr_driver = { - "cryptosoft", - swcr_methods, - 0, /* NB: no softc */ -}; -static devclass_t swcr_devclass; - /* * NB: We explicitly reference the crypto module so we * get the necessary ordering when built as a loadable @@ -1071,7 +1058,35 @@ * normal module dependencies would handle things). */ extern int crypto_modevent(struct module *, int, void *); -/* XXX where to attach */ -DRIVER_MODULE(cryptosoft, nexus, swcr_driver, swcr_devclass, crypto_modevent,0); + +static int +swcr_modevent(struct module *module, int cmd, void *arg) +{ + int error; + + switch (cmd) { + case MOD_LOAD: + error = crypto_modevent(module, cmd, arg); + if (error) + return (error); + swcr_init(); + return (0); + case MOD_UNLOAD: + swcr_destroy(); + return (crypto_modevent(module, cmd, arg)); + case MOD_QUIESCE: + return (crypto_modevent(module, cmd, arg)); + default: + return (EOPNOTSUPP); + } +} + +static moduledata_t cryptosoft_module = { + "cryptosoft", + swcr_modevent, + 0 +}; + +DECLARE_MODULE(cryptosoft, cryptosoft_module, SI_SUB_DRIVER, SI_ORDER_ANY); MODULE_VERSION(cryptosoft, 1); MODULE_DEPEND(cryptosoft, crypto, 1, 1, 1); Index: sys/mount.h =================================================================== RCS file: /usr/cvs/src/sys/sys/mount.h,v retrieving revision 1.237 diff -u -r1.237 mount.h --- sys/mount.h 3 Nov 2008 20:00:35 -0000 1.237 +++ sys/mount.h 11 Nov 2008 18:46:34 -0000 @@ -692,7 +692,7 @@ struct mntarg *mount_argb(struct mntarg *ma, int flag, const char *name); struct mntarg *mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...); struct mntarg *mount_argsu(struct mntarg *ma, const char *name, const void *val, int len); -void statfs_scale_blocks(struct statfs *sf, long max_size); +int statfs_scale_blocks(struct statfs *sf, long max_size); struct vfsconf *vfs_byname(const char *); struct vfsconf *vfs_byname_kld(const char *, struct thread *td, int *); void vfs_mount_destroy(struct mount *); Index: sys/queue.h =================================================================== RCS file: /usr/cvs/src/sys/sys/queue.h,v retrieving revision 1.69 diff -u -r1.69 queue.h --- sys/queue.h 22 May 2008 14:40:03 -0000 1.69 +++ sys/queue.h 4 Aug 2008 16:22:30 -0000 @@ -95,7 +95,7 @@ * _INSERT_BEFORE - + - + * _INSERT_AFTER + + + + * _INSERT_TAIL - - + + - * _CONCAT - - + + + * _CONCAT + - + + * _REMOVE_HEAD + - + - * _REMOVE_NEXT + - + - * _REMOVE + + + + @@ -153,6 +153,14 @@ /* * Singly-linked List functions. */ +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + #define SLIST_EMPTY(head) ((head)->slh_first == NULL) #define SLIST_FIRST(head) ((head)->slh_first) Index: sys/shm.h =================================================================== RCS file: /usr/cvs/src/sys/sys/shm.h,v retrieving revision 1.25 diff -u -r1.25 shm.h --- sys/shm.h 12 Feb 2008 20:55:03 -0000 1.25 +++ sys/shm.h 25 Aug 2008 20:37:29 -0000 @@ -108,6 +108,7 @@ struct shmid_kernel { struct shmid_ds u; struct label *label; /* MAC label */ + int nattach; }; extern struct shminfo shminfo; Index: vm/vm_phys.c =================================================================== RCS file: /usr/cvs/src/sys/vm/vm_phys.c,v retrieving revision 1.9 diff -u -r1.9 vm_phys.c --- vm/vm_phys.c 6 Apr 2008 18:09:28 -0000 1.9 +++ vm/vm_phys.c 6 May 2008 18:39:52 -0000 @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD: src/sys/vm/vm_phys.c,v 1.9 2008/04/06 18:09:28 alc Exp $"); #include "opt_ddb.h" +#include "opt_sched.h" #include #include @@ -40,7 +41,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -551,6 +554,14 @@ vm_phys_unfree_page(m_tmp); cnt.v_free_count--; mtx_unlock(&vm_page_queue_free_mtx); +#ifndef PREEMPTION + if (sched_runnable()) { + thread_lock(curthread); + mi_switch(SW_VOL | SWT_IDLE, + NULL); + thread_unlock(curthread); + } +#endif pmap_zero_page_idle(m_tmp); m_tmp->flags |= PG_ZERO; mtx_lock(&vm_page_queue_free_mtx); Index: vm/vm_zeroidle.c =================================================================== RCS file: /usr/cvs/src/sys/vm/vm_zeroidle.c,v retrieving revision 1.53 diff -u -r1.53 vm_zeroidle.c --- vm/vm_zeroidle.c 3 Aug 2008 14:26:15 -0000 1.53 +++ vm/vm_zeroidle.c 4 Aug 2008 16:22:31 -0000 @@ -35,8 +35,6 @@ #include __FBSDID("$FreeBSD: src/sys/vm/vm_zeroidle.c,v 1.53 2008/08/03 14:26:15 trhodes Exp $"); -#include - #include #include #include @@ -124,13 +122,6 @@ for (;;) { if (vm_page_zero_check()) { vm_page_zero_idle(); -#ifndef PREEMPTION - if (sched_runnable()) { - thread_lock(curthread); - mi_switch(SW_VOL | SWT_IDLE, NULL); - thread_unlock(curthread); - } -#endif } else { wakeup_needed = TRUE; msleep(&zero_state, &vm_page_queue_free_mtx, 0,