PERFORCE change 1192318 for review
John Baldwin
jhb at FreeBSD.org
Thu Mar 27 20:14:13 UTC 2014
http://p4web.freebsd.org/@@1192318?ac=10
Change 1192318 by jhb at jhb_jhbbsd on 2014/03/27 20:14:00
IFC @1192317
Affected files ...
.. //depot/projects/pci/sys/amd64/amd64/machdep.c#15 integrate
.. //depot/projects/pci/sys/amd64/include/metadata.h#4 integrate
.. //depot/projects/pci/sys/amd64/include/vmm.h#11 integrate
.. //depot/projects/pci/sys/amd64/include/vmm_dev.h#8 integrate
.. //depot/projects/pci/sys/amd64/vmm/amd/amdv.c#7 integrate
.. //depot/projects/pci/sys/amd64/vmm/intel/vmx.c#15 integrate
.. //depot/projects/pci/sys/amd64/vmm/vmm.c#13 integrate
.. //depot/projects/pci/sys/amd64/vmm/vmm_dev.c#9 integrate
.. //depot/projects/pci/sys/cam/ctl/README.ctl.txt#4 integrate
.. //depot/projects/pci/sys/cam/ctl/ctl_frontend_cam_sim.c#5 integrate
.. //depot/projects/pci/sys/cam/ctl/ctl_frontend_internal.c#5 integrate
.. //depot/projects/pci/sys/cam/ctl/ctl_frontend_iscsi.c#3 integrate
.. //depot/projects/pci/sys/cam/ctl/ctl_mem_pool.c#3 delete
.. //depot/projects/pci/sys/cam/ctl/ctl_mem_pool.h#3 delete
.. //depot/projects/pci/sys/conf/files#24 integrate
.. //depot/projects/pci/sys/dev/vt/hw/efifb/efifb.c#2 integrate
.. //depot/projects/pci/sys/dev/vt/vt_core.c#5 integrate
.. //depot/projects/pci/sys/ia64/acpica/OsdEnvironment.c#3 integrate
.. //depot/projects/pci/sys/ia64/ia64/clock.c#8 integrate
.. //depot/projects/pci/sys/ia64/ia64/dump_machdep.c#8 integrate
.. //depot/projects/pci/sys/ia64/ia64/efi.c#6 integrate
.. //depot/projects/pci/sys/ia64/ia64/iodev_machdep.c#3 integrate
.. //depot/projects/pci/sys/ia64/ia64/machdep.c#11 integrate
.. //depot/projects/pci/sys/ia64/ia64/nexus.c#7 integrate
.. //depot/projects/pci/sys/ia64/ia64/pmap.c#16 integrate
.. //depot/projects/pci/sys/ia64/ia64/sal.c#4 integrate
.. //depot/projects/pci/sys/ia64/ia64/trap.c#6 integrate
.. //depot/projects/pci/sys/ia64/include/efi.h#5 delete
.. //depot/projects/pci/sys/modules/ctl/Makefile#4 integrate
.. //depot/projects/pci/sys/netinet/if_ether.c#12 integrate
.. //depot/projects/pci/sys/netinet/in.c#13 integrate
.. //depot/projects/pci/sys/sys/efi.h#1 branch
.. //depot/projects/pci/sys/x86/acpica/madt.c#7 integrate
Differences ...
==== //depot/projects/pci/sys/amd64/amd64/machdep.c#15 (text+ko) ====
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/amd64/amd64/machdep.c 263620 2014-03-22 10:26:09Z bdrewery $");
+__FBSDID("$FreeBSD: head/sys/amd64/amd64/machdep.c 263822 2014-03-27 18:23:02Z emaste $");
#include "opt_atpic.h"
#include "opt_compat.h"
@@ -63,6 +63,7 @@
#include <sys/callout.h>
#include <sys/cons.h>
#include <sys/cpu.h>
+#include <sys/efi.h>
#include <sys/eventhandler.h>
#include <sys/exec.h>
#include <sys/imgact.h>
@@ -1431,10 +1432,105 @@
}
}
+#define efi_next_descriptor(ptr, size) \
+ ((struct efi_md *)(((uint8_t *) ptr) + size))
+
+static void
+add_efi_map_entries(struct efi_map_header *efihdr, vm_paddr_t *physmap,
+ int *physmap_idx)
+{
+ struct efi_md *map, *p;
+ const char *type;
+ size_t efisz;
+ int ndesc, i;
+
+ static const char *types[] = {
+ "Reserved",
+ "LoaderCode",
+ "LoaderData",
+ "BootServicesCode",
+ "BootServicesData",
+ "RuntimeServicesCode",
+ "RuntimeServicesData",
+ "ConventionalMemory",
+ "UnusableMemory",
+ "ACPIReclaimMemory",
+ "ACPIMemoryNVS",
+ "MemoryMappedIO",
+ "MemoryMappedIOPortSpace",
+ "PalCode"
+ };
+
+ /*
+ * Memory map data provided by UEFI via the GetMemoryMap
+ * Boot Services API.
+ */
+ efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
+ map = (struct efi_md *)((uint8_t *)efihdr + efisz);
+
+ if (efihdr->descriptor_size == 0)
+ return;
+ ndesc = efihdr->memory_size / efihdr->descriptor_size;
+
+ if (boothowto & RB_VERBOSE)
+ printf("%23s %12s %12s %8s %4s\n",
+ "Type", "Physical", "Virtual", "#Pages", "Attr");
+
+ for (i = 0, p = map; i < ndesc; i++,
+ p = efi_next_descriptor(p, efihdr->descriptor_size)) {
+ if (boothowto & RB_VERBOSE) {
+ if (p->md_type <= EFI_MD_TYPE_PALCODE)
+ type = types[p->md_type];
+ else
+ type = "<INVALID>";
+ printf("%23s %012lx %12p %08lx ", type, p->md_phys,
+ p->md_virt, p->md_pages);
+ if (p->md_attr & EFI_MD_ATTR_UC)
+ printf("UC ");
+ if (p->md_attr & EFI_MD_ATTR_WC)
+ printf("WC ");
+ if (p->md_attr & EFI_MD_ATTR_WT)
+ printf("WT ");
+ if (p->md_attr & EFI_MD_ATTR_WB)
+ printf("WB ");
+ if (p->md_attr & EFI_MD_ATTR_UCE)
+ printf("UCE ");
+ if (p->md_attr & EFI_MD_ATTR_WP)
+ printf("WP ");
+ if (p->md_attr & EFI_MD_ATTR_RP)
+ printf("RP ");
+ if (p->md_attr & EFI_MD_ATTR_XP)
+ printf("XP ");
+ if (p->md_attr & EFI_MD_ATTR_RT)
+ printf("RUNTIME");
+ printf("\n");
+ }
+
+ switch (p->md_type) {
+ case EFI_MD_TYPE_CODE:
+ case EFI_MD_TYPE_DATA:
+ case EFI_MD_TYPE_BS_CODE:
+ case EFI_MD_TYPE_BS_DATA:
+ case EFI_MD_TYPE_FREE:
+ /*
+ * We're allowed to use any entry with these types.
+ */
+ break;
+ default:
+ continue;
+ }
+
+ if (!add_physmap_entry(p->md_phys, (p->md_pages * PAGE_SIZE),
+ physmap, physmap_idx))
+ break;
+ }
+}
+
static void
native_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx)
{
struct bios_smap *smap;
+ struct efi_map_header *efihdr;
u_int32_t size;
/*
@@ -1445,13 +1541,19 @@
* ie: an int32_t immediately precedes smap.
*/
+ efihdr = (struct efi_map_header *)preload_search_info(kmdp,
+ MODINFO_METADATA | MODINFOMD_EFI_MAP);
smap = (struct bios_smap *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_SMAP);
- if (smap == NULL)
- panic("No BIOS smap info from loader!");
- size = *((u_int32_t *)smap - 1);
+ if (efihdr == NULL && smap == NULL)
+ panic("No BIOS smap or EFI map info from loader!");
- bios_add_smap_entries(smap, size, physmap, physmap_idx);
+ if (efihdr != NULL) {
+ add_efi_map_entries(efihdr, physmap, physmap_idx);
+ } else {
+ size = *((u_int32_t *)smap - 1);
+ bios_add_smap_entries(smap, size, physmap, physmap_idx);
+ }
}
/*
==== //depot/projects/pci/sys/amd64/include/metadata.h#4 (text+ko) ====
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/amd64/include/metadata.h 250840 2013-05-21 03:05:49Z marcel $
+ * $FreeBSD: head/sys/amd64/include/metadata.h 263826 2014-03-27 19:43:38Z emaste $
*/
#ifndef _MACHINE_METADATA_H_
@@ -32,5 +32,25 @@
#define MODINFOMD_SMAP 0x1001
#define MODINFOMD_SMAP_XATTR 0x1002
#define MODINFOMD_DTBP 0x1003
+#define MODINFOMD_EFI_MAP 0x1004
+#define MODINFOMD_EFI_FB 0x1005
+
+struct efi_map_header {
+ size_t memory_size;
+ size_t descriptor_size;
+ uint32_t descriptor_version;
+};
+
+struct efi_fb {
+ uint64_t fb_addr;
+ uint64_t fb_size;
+ int fb_height;
+ int fb_width;
+ int fb_stride;
+ uint32_t fb_mask_red;
+ uint32_t fb_mask_green;
+ uint32_t fb_mask_blue;
+ uint32_t fb_mask_reserved;
+};
#endif /* !_MACHINE_METADATA_H_ */
==== //depot/projects/pci/sys/amd64/include/vmm.h#11 (text+ko) ====
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/amd64/include/vmm.h 263744 2014-03-25 19:20:34Z tychon $
+ * $FreeBSD: head/sys/amd64/include/vmm.h 263780 2014-03-26 23:34:27Z neel $
*/
#ifndef _VMM_H_
@@ -53,7 +53,8 @@
typedef void (*vmm_resume_func_t)(void);
typedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap);
typedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip,
- struct pmap *pmap, void *rendezvous_cookie);
+ struct pmap *pmap, void *rendezvous_cookie,
+ void *suspend_cookie);
typedef void (*vmi_cleanup_func_t)(void *vmi);
typedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num,
uint64_t *retval);
@@ -114,6 +115,7 @@
int vm_set_seg_desc(struct vm *vm, int vcpu, int reg,
struct seg_desc *desc);
int vm_run(struct vm *vm, struct vm_run *vmrun);
+int vm_suspend(struct vm *vm);
int vm_inject_nmi(struct vm *vm, int vcpu);
int vm_nmi_pending(struct vm *vm, int vcpuid);
void vm_nmi_clear(struct vm *vm, int vcpuid);
@@ -158,6 +160,13 @@
return (*(uintptr_t *)rendezvous_cookie != 0);
}
+static __inline int
+vcpu_suspended(void *suspend_cookie)
+{
+
+ return (*(int *)suspend_cookie);
+}
+
/*
* Return 1 if device indicated by bus/slot/func is supposed to be a
* pci passthrough device.
@@ -311,6 +320,7 @@
VM_EXITCODE_SPINDOWN_CPU,
VM_EXITCODE_RENDEZVOUS,
VM_EXITCODE_IOAPIC_EOI,
+ VM_EXITCODE_SUSPENDED,
VM_EXITCODE_MAX
};
==== //depot/projects/pci/sys/amd64/include/vmm_dev.h#8 (text+ko) ====
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/amd64/include/vmm_dev.h 263035 2014-03-11 16:56:00Z tychon $
+ * $FreeBSD: head/sys/amd64/include/vmm_dev.h 263780 2014-03-26 23:34:27Z neel $
*/
#ifndef _VMM_DEV_H_
@@ -165,6 +165,7 @@
IOCNUM_RUN = 1,
IOCNUM_SET_CAPABILITY = 2,
IOCNUM_GET_CAPABILITY = 3,
+ IOCNUM_SUSPEND = 4,
/* memory apis */
IOCNUM_MAP_MEMORY = 10,
@@ -212,6 +213,8 @@
#define VM_RUN \
_IOWR('v', IOCNUM_RUN, struct vm_run)
+#define VM_SUSPEND \
+ _IO('v', IOCNUM_SUSPEND)
#define VM_MAP_MEMORY \
_IOWR('v', IOCNUM_MAP_MEMORY, struct vm_memory_segment)
#define VM_GET_MEMORY_SEG \
==== //depot/projects/pci/sys/amd64/vmm/amd/amdv.c#7 (text+ko) ====
@@ -23,11 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/amd64/vmm/amd/amdv.c 262506 2014-02-26 00:52:05Z neel $
+ * $FreeBSD: head/sys/amd64/vmm/amd/amdv.c 263780 2014-03-26 23:34:27Z neel $
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/amd64/vmm/amd/amdv.c 262506 2014-02-26 00:52:05Z neel $");
+__FBSDID("$FreeBSD: head/sys/amd64/vmm/amd/amdv.c 263780 2014-03-26 23:34:27Z neel $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -67,7 +67,8 @@
}
static int
-amdv_vmrun(void *arg, int vcpu, register_t rip, struct pmap *pmap, void *cookie)
+amdv_vmrun(void *arg, int vcpu, register_t rip, struct pmap *pmap,
+ void *rptr, void *sptr)
{
printf("amdv_vmrun: not implemented\n");
==== //depot/projects/pci/sys/amd64/vmm/intel/vmx.c#15 (text+ko) ====
@@ -23,11 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/amd64/vmm/intel/vmx.c 263211 2014-03-15 23:09:34Z tychon $
+ * $FreeBSD: head/sys/amd64/vmm/intel/vmx.c 263780 2014-03-26 23:34:27Z neel $
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/amd64/vmm/intel/vmx.c 263211 2014-03-15 23:09:34Z tychon $");
+__FBSDID("$FreeBSD: head/sys/amd64/vmm/intel/vmx.c 263780 2014-03-26 23:34:27Z neel $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -2038,6 +2038,16 @@
}
static __inline int
+vmx_exit_suspended(struct vmx *vmx, int vcpu, struct vm_exit *vmexit)
+{
+
+ vmexit->rip = vmcs_guest_rip();
+ vmexit->inst_length = 0;
+ vmexit->exitcode = VM_EXITCODE_SUSPENDED;
+ return (UNHANDLED);
+}
+
+static __inline int
vmx_exit_inst_error(struct vmxctx *vmxctx, int rc, struct vm_exit *vmexit)
{
@@ -2097,7 +2107,7 @@
static int
vmx_run(void *arg, int vcpu, register_t startrip, pmap_t pmap,
- void *rendezvous_cookie)
+ void *rendezvous_cookie, void *suspend_cookie)
{
int rc, handled, launched;
struct vmx *vmx;
@@ -2154,9 +2164,9 @@
* pmap_invalidate_ept().
*/
disable_intr();
- if (curthread->td_flags & (TDF_ASTPENDING | TDF_NEEDRESCHED)) {
+ if (vcpu_suspended(suspend_cookie)) {
enable_intr();
- handled = vmx_exit_astpending(vmx, vcpu, vmexit);
+ handled = vmx_exit_suspended(vmx, vcpu, vmexit);
break;
}
@@ -2166,6 +2176,12 @@
break;
}
+ if (curthread->td_flags & (TDF_ASTPENDING | TDF_NEEDRESCHED)) {
+ enable_intr();
+ handled = vmx_exit_astpending(vmx, vcpu, vmexit);
+ break;
+ }
+
vmx_inject_interrupts(vmx, vcpu, vlapic);
vmx_run_trace(vmx, vcpu);
rc = vmx_enter_guest(vmxctx, vmx, launched);
==== //depot/projects/pci/sys/amd64/vmm/vmm.c#13 (text+ko) ====
@@ -23,11 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/amd64/vmm/vmm.c 263744 2014-03-25 19:20:34Z tychon $
+ * $FreeBSD: head/sys/amd64/vmm/vmm.c 263780 2014-03-26 23:34:27Z neel $
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm.c 263744 2014-03-25 19:20:34Z tychon $");
+__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm.c 263780 2014-03-26 23:34:27Z neel $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -139,6 +139,9 @@
cpuset_t rendezvous_done_cpus;
void *rendezvous_arg;
vm_rendezvous_func_t rendezvous_func;
+
+ int suspend;
+ volatile cpuset_t suspended_cpus;
};
static int vmm_initialized;
@@ -149,8 +152,8 @@
#define VMM_RESUME() (ops != NULL ? (*ops->resume)() : 0)
#define VMINIT(vm, pmap) (ops != NULL ? (*ops->vminit)(vm, pmap): NULL)
-#define VMRUN(vmi, vcpu, rip, pmap, rptr) \
- (ops != NULL ? (*ops->vmrun)(vmi, vcpu, rip, pmap, rptr) : ENXIO)
+#define VMRUN(vmi, vcpu, rip, pmap, rptr, sptr) \
+ (ops != NULL ? (*ops->vmrun)(vmi, vcpu, rip, pmap, rptr, sptr) : ENXIO)
#define VMCLEANUP(vmi) (ops != NULL ? (*ops->vmcleanup)(vmi) : NULL)
#define VMSPACE_ALLOC(min, max) \
(ops != NULL ? (*ops->vmspace_alloc)(min, max) : NULL)
@@ -1019,7 +1022,8 @@
* These interrupts could have happened any time after we
* returned from VMRUN() and before we grabbed the vcpu lock.
*/
- if (!vm_nmi_pending(vm, vcpuid) &&
+ if (vm->rendezvous_func == NULL &&
+ !vm_nmi_pending(vm, vcpuid) &&
(intr_disabled || !vlapic_pending_intr(vcpu->vlapic, NULL))) {
t = ticks;
vcpu_require_state_locked(vcpu, VCPU_SLEEPING);
@@ -1152,7 +1156,72 @@
return (error);
}
+static int
+vm_handle_suspend(struct vm *vm, int vcpuid, bool *retu)
+{
+ int i, done;
+ struct vcpu *vcpu;
+
+ done = 0;
+ vcpu = &vm->vcpu[vcpuid];
+
+ CPU_SET_ATOMIC(vcpuid, &vm->suspended_cpus);
+
+ /*
+ * Wait until all 'active_cpus' have suspended themselves.
+ *
+ * Since a VM may be suspended at any time including when one or
+ * more vcpus are doing a rendezvous we need to call the rendezvous
+ * handler while we are waiting to prevent a deadlock.
+ */
+ vcpu_lock(vcpu);
+ while (1) {
+ if (CPU_CMP(&vm->suspended_cpus, &vm->active_cpus) == 0) {
+ VCPU_CTR0(vm, vcpuid, "All vcpus suspended");
+ break;
+ }
+
+ if (vm->rendezvous_func == NULL) {
+ VCPU_CTR0(vm, vcpuid, "Sleeping during suspend");
+ vcpu_require_state_locked(vcpu, VCPU_SLEEPING);
+ msleep_spin(vcpu, &vcpu->mtx, "vmsusp", hz);
+ vcpu_require_state_locked(vcpu, VCPU_FROZEN);
+ } else {
+ VCPU_CTR0(vm, vcpuid, "Rendezvous during suspend");
+ vcpu_unlock(vcpu);
+ vm_handle_rendezvous(vm, vcpuid);
+ vcpu_lock(vcpu);
+ }
+ }
+ vcpu_unlock(vcpu);
+
+ /*
+ * Wakeup the other sleeping vcpus and return to userspace.
+ */
+ for (i = 0; i < VM_MAXCPU; i++) {
+ if (CPU_ISSET(i, &vm->suspended_cpus)) {
+ vcpu_notify_event(vm, i, false);
+ }
+ }
+
+ *retu = true;
+ return (0);
+}
+
int
+vm_suspend(struct vm *vm)
+{
+
+ if (atomic_cmpset_int(&vm->suspend, 0, 1)) {
+ VM_CTR0(vm, "virtual machine suspended");
+ return (0);
+ } else {
+ VM_CTR0(vm, "virtual machine already suspended");
+ return (EALREADY);
+ }
+}
+
+int
vm_run(struct vm *vm, struct vm_run *vmrun)
{
int error, vcpuid;
@@ -1162,12 +1231,15 @@
struct vm_exit *vme;
bool retu, intr_disabled;
pmap_t pmap;
+ void *rptr, *sptr;
vcpuid = vmrun->cpuid;
if (vcpuid < 0 || vcpuid >= VM_MAXCPU)
return (EINVAL);
+ rptr = &vm->rendezvous_func;
+ sptr = &vm->suspend;
pmap = vmspace_pmap(vm->vmspace);
vcpu = &vm->vcpu[vcpuid];
vme = &vcpu->exitinfo;
@@ -1187,7 +1259,7 @@
restore_guest_fpustate(vcpu);
vcpu_require_state(vm, vcpuid, VCPU_RUNNING);
- error = VMRUN(vm->cookie, vcpuid, rip, pmap, &vm->rendezvous_func);
+ error = VMRUN(vm->cookie, vcpuid, rip, pmap, rptr, sptr);
vcpu_require_state(vm, vcpuid, VCPU_FROZEN);
save_guest_fpustate(vcpu);
@@ -1200,6 +1272,9 @@
if (error == 0) {
retu = false;
switch (vme->exitcode) {
+ case VM_EXITCODE_SUSPENDED:
+ error = vm_handle_suspend(vm, vcpuid, &retu);
+ break;
case VM_EXITCODE_IOAPIC_EOI:
vioapic_process_eoi(vm, vcpuid,
vme->u.ioapic_eoi.vector);
==== //depot/projects/pci/sys/amd64/vmm/vmm_dev.c#9 (text+ko) ====
@@ -23,11 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/amd64/vmm/vmm_dev.c 263035 2014-03-11 16:56:00Z tychon $
+ * $FreeBSD: head/sys/amd64/vmm/vmm_dev.c 263780 2014-03-26 23:34:27Z neel $
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm_dev.c 263035 2014-03-11 16:56:00Z tychon $");
+__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm_dev.c 263780 2014-03-26 23:34:27Z neel $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -239,6 +239,9 @@
vmrun = (struct vm_run *)data;
error = vm_run(sc->vm, vmrun);
break;
+ case VM_SUSPEND:
+ error = vm_suspend(sc->vm);
+ break;
case VM_STAT_DESC: {
statdesc = (struct vm_stat_desc *)data;
error = vmm_stat_desc_copy(statdesc->index,
==== //depot/projects/pci/sys/cam/ctl/README.ctl.txt#4 (text+ko) ====
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/sys/cam/ctl/README.ctl.txt 249009 2013-04-02 09:42:42Z trasz $ */
+/* $FreeBSD: head/sys/cam/ctl/README.ctl.txt 263811 2014-03-27 11:10:13Z trasz $ */
CTL - CAM Target Layer Description
@@ -394,14 +394,6 @@
This defines all ioctls available through the CTL character device, and
the data structures needed for those ioctls.
-ctl_mem_pool.c
-ctl_mem_pool.h:
---------------
-
-Generic memory pool implementation. This is currently only used by the
-internal frontend. The internal frontend can probably be rewritten to use
-UMA zones and this can be removed.
-
ctl_private.h:
-------------
==== //depot/projects/pci/sys/cam/ctl/ctl_frontend_cam_sim.c#5 (text+ko) ====
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_cam_sim.c 256843 2013-10-21 12:00:26Z mav $");
+__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_cam_sim.c 263811 2014-03-27 11:10:13Z trasz $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -65,7 +65,6 @@
#include <cam/ctl/ctl.h>
#include <cam/ctl/ctl_frontend.h>
#include <cam/ctl/ctl_frontend_internal.h>
-#include <cam/ctl/ctl_mem_pool.h>
#include <cam/ctl/ctl_debug.h>
#define io_ptr spriv_ptr1
==== //depot/projects/pci/sys/cam/ctl/ctl_frontend_internal.c#5 (text+ko) ====
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_internal.c 253987 2013-08-06 10:42:18Z trasz $");
+__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_internal.c 263811 2014-03-27 11:10:13Z trasz $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -62,6 +62,7 @@
#include <sys/queue.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
+#include <vm/uma.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_da.h>
#include <cam/ctl/ctl_io.h>
@@ -73,7 +74,6 @@
#include <cam/ctl/ctl_util.h>
#include <cam/ctl/ctl_ha.h>
#include <cam/ctl/ctl_private.h>
-#include <cam/ctl/ctl_mem_pool.h>
#include <cam/ctl/ctl_debug.h>
#include <cam/ctl/ctl_scsi_all.h>
#include <cam/ctl/ctl_error.h>
@@ -118,7 +118,6 @@
cfi_tasktype tasktype;
cfi_mt_status status;
union cfi_taskinfo taskinfo;
- struct ctl_mem_element *element;
void *cfi_context;
STAILQ_ENTRY(cfi_metatask) links;
};
@@ -153,7 +152,6 @@
int blocksize_powerof2;
uint32_t cur_tag_num;
cfi_lun_state state;
- struct ctl_mem_element *element;
struct cfi_softc *softc;
STAILQ_HEAD(, cfi_lun_io) io_list;
STAILQ_ENTRY(cfi_lun) links;
@@ -181,12 +179,13 @@
cfi_flags flags;
STAILQ_HEAD(, cfi_lun) lun_list;
STAILQ_HEAD(, cfi_metatask) metatask_list;
- struct ctl_mem_pool lun_pool;
- struct ctl_mem_pool metatask_pool;
};
MALLOC_DEFINE(M_CTL_CFI, "ctlcfi", "CTL CFI");
+static uma_zone_t cfi_lun_zone;
+static uma_zone_t cfi_metatask_zone;
+
static struct cfi_softc fetd_internal_softc;
int cfi_init(void);
@@ -275,48 +274,15 @@
if (ctl_frontend_register(fe, (softc->flags & CTL_FLAG_MASTER_SHELF)) != 0)
{
printf("%s: internal frontend registration failed\n", __func__);
- retval = 1;
- goto bailout;
+ return (0);
}
- if (ctl_init_mem_pool(&softc->lun_pool,
- sizeof(struct cfi_lun),
- CTL_MEM_POOL_PERM_GROW, /*grow_inc*/ 3,
- /* initial_pool_size */ CTL_MAX_LUNS) != 0) {
- printf("%s: can't initialize LUN memory pool\n", __func__);
- retval = 1;
- goto bailout_error;
- }
+ cfi_lun_zone = uma_zcreate("cfi_lun", sizeof(struct cfi_lun),
+ NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
+ cfi_metatask_zone = uma_zcreate("cfi_metatask", sizeof(struct cfi_metatask),
+ NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
- if (ctl_init_mem_pool(&softc->metatask_pool,
- sizeof(struct cfi_metatask),
- CTL_MEM_POOL_PERM_GROW, /*grow_inc*/ 3,
- /*initial_pool_size*/ 10) != 0) {
- printf("%s: can't initialize metatask memory pool\n", __func__);
- retval = 2;
- goto bailout_error;
- }
-bailout:
-
return (0);
-
-bailout_error:
-
- switch (retval) {
- case 3:
- ctl_shrink_mem_pool(&softc->metatask_pool);
- /* FALLTHROUGH */
- case 2:
- ctl_shrink_mem_pool(&softc->lun_pool);
- /* FALLTHROUGH */
- case 1:
- ctl_frontend_deregister(fe);
- break;
- default:
- break;
- }
-
- return (ENOMEM);
}
void
@@ -332,11 +298,8 @@
if (ctl_frontend_deregister(&softc->fe) != 0)
printf("%s: ctl_frontend_deregister() failed\n", __func__);
- if (ctl_shrink_mem_pool(&softc->lun_pool) != 0)
- printf("%s: error shrinking LUN pool\n", __func__);
-
- if (ctl_shrink_mem_pool(&softc->metatask_pool) != 0)
- printf("%s: error shrinking LUN pool\n", __func__);
+ uma_zdestroy(cfi_lun_zone);
+ uma_zdestroy(cfi_metatask_zone);
}
static int
@@ -398,7 +361,6 @@
static int
cfi_lun_enable(void *arg, struct ctl_id target_id, int lun_id)
{
- struct ctl_mem_element *element;
struct cfi_softc *softc;
struct cfi_lun *lun;
int found;
@@ -423,16 +385,12 @@
if (found != 0)
return (0);
- element = ctl_alloc_mem_element(&softc->lun_pool, /*can_wait*/ 0);
-
- if (element == NULL) {
+ lun = uma_zalloc(cfi_lun_zone, M_NOWAIT | M_ZERO);
+ if (lun == NULL) {
printf("%s: unable to allocate LUN structure\n", __func__);
return (1);
}
- lun = (struct cfi_lun *)element->bytes;
-
- lun->element = element;
lun->target_id = target_id;
lun->lun_id = lun_id;
lun->cur_tag_num = 0;
@@ -485,7 +443,7 @@
return (1);
}
- ctl_free_mem_element(lun->element);
+ uma_zfree(cfi_lun_zone, lun);
return (0);
}
@@ -1682,106 +1640,20 @@
}
}
-#ifdef oldapi
-void
-cfi_shutdown_shelf(cfi_cb_t callback, void *callback_arg)
-{
- struct ctl_mem_element *element;
- struct cfi_softc *softc;
- struct cfi_metatask *metatask;
-
- softc = &fetd_internal_softc;
-
- element = ctl_alloc_mem_element(&softc->metatask_pool, /*can_wait*/ 0);
- if (element == NULL) {
- callback(callback_arg,
- /*status*/ CFI_MT_ERROR,
- /*sluns_found*/ 0,
- /*sluns_complete*/ 0,
- /*sluns_failed*/ 0);
- return;
- }
-
- metatask = (struct cfi_metatask *)element->bytes;
-
- memset(metatask, 0, sizeof(*metatask));
- metatask->tasktype = CFI_TASK_SHUTDOWN;
- metatask->status = CFI_MT_NONE;
- metatask->taskinfo.startstop.callback = callback;
- metatask->taskinfo.startstop.callback_arg = callback_arg;
- metatask->element = element;
-
- cfi_action(softc, metatask);
-
- /*
- * - send a report luns to lun 0, get LUN list.
- * - send an inquiry to each lun
- * - send a stop/offline to each direct access LUN
- * - if we get a reservation conflict, reset the LUN and then
- * retry sending the stop/offline
- * - return status back to the caller
- */
-}
-
-void
-cfi_start_shelf(cfi_cb_t callback, void *callback_arg)
-{
- struct ctl_mem_element *element;
- struct cfi_softc *softc;
- struct cfi_metatask *metatask;
-
- softc = &fetd_internal_softc;
-
- element = ctl_alloc_mem_element(&softc->metatask_pool, /*can_wait*/ 0);
- if (element == NULL) {
- callback(callback_arg,
- /*status*/ CFI_MT_ERROR,
- /*sluns_found*/ 0,
- /*sluns_complete*/ 0,
- /*sluns_failed*/ 0);
- return;
- }
-
- metatask = (struct cfi_metatask *)element->bytes;
-
- memset(metatask, 0, sizeof(*metatask));
- metatask->tasktype = CFI_TASK_STARTUP;
- metatask->status = CFI_MT_NONE;
- metatask->taskinfo.startstop.callback = callback;
- metatask->taskinfo.startstop.callback_arg = callback_arg;
- metatask->element = element;
-
- cfi_action(softc, metatask);
-
- /*
- * - send a report luns to lun 0, get LUN list.
- * - send an inquiry to each lun
- * - send a stop/offline to each direct access LUN
- * - if we get a reservation conflict, reset the LUN and then
- * retry sending the stop/offline
- * - return status back to the caller
- */
-}
-
-#endif
-
struct cfi_metatask *
cfi_alloc_metatask(int can_wait)
{
- struct ctl_mem_element *element;
struct cfi_metatask *metatask;
struct cfi_softc *softc;
softc = &fetd_internal_softc;
- element = ctl_alloc_mem_element(&softc->metatask_pool, can_wait);
- if (element == NULL)
+ metatask = uma_zalloc(cfi_metatask_zone,
+ (can_wait ? M_WAITOK : M_NOWAIT) | M_ZERO);
+ if (metatask == NULL)
return (NULL);
- metatask = (struct cfi_metatask *)element->bytes;
- memset(metatask, 0, sizeof(*metatask));
metatask->status = CFI_MT_NONE;
- metatask->element = element;
return (metatask);
}
@@ -1789,7 +1661,8 @@
void
cfi_free_metatask(struct cfi_metatask *metatask)
{
- ctl_free_mem_element(metatask->element);
+
+ uma_zfree(cfi_metatask_zone, metatask);
}
/*
==== //depot/projects/pci/sys/cam/ctl/ctl_frontend_iscsi.c#3 (text+ko) ====
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 263745 2014-03-25 19:28:40Z trasz $
+ * $FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 263810 2014-03-27 10:15:35Z trasz $
*/
/*
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 263745 2014-03-25 19:28:40Z trasz $");
+__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend_iscsi.c 263810 2014-03-27 10:15:35Z trasz $");
#include <sys/param.h>
#include <sys/capsicum.h>
@@ -2315,8 +2315,8 @@
const struct iscsi_bhs_scsi_command *bhssc;
struct iscsi_bhs_data_in *bhsdi;
struct ctl_sg_entry ctl_sg_entry, *ctl_sglist;
- size_t copy_len, len, off;
- const char *addr;
+ size_t len, expected_len, sg_len, buffer_offset;
+ const char *sg_addr;
int ctl_sg_count, error, i;
request = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
@@ -2338,26 +2338,49 @@
}
/*
- * We need to record it so that we can properly report
+ * This is the total amount of data to be transferred within the current
+ * SCSI command. We need to record it so that we can properly report
* underflow/underflow.
*/
PDU_TOTAL_TRANSFER_LEN(request) = io->scsiio.kern_total_len;
/*
- * This is the offset within the current SCSI command;
- * i.e. for the first call of datamove(), it will be 0,
- * and for subsequent ones it will be the sum of lengths
- * of previous ones.
+ * This is the offset within the current SCSI command; for the first
+ * call to cfiscsi_datamove() it will be 0, and for subsequent ones
+ * it will be the sum of lengths of previous ones. It's being
+ * incremented as we append data to the data segment.
+ */
+ buffer_offset = io->scsiio.kern_rel_offset;
+
+ /*
+ * This is the transfer length expected by the initiator. In theory,
+ * it could be different from the correct amount of data from the SCSI
+ * point of view, even if that doesn't make any sense.
*/
- off = htonl(io->scsiio.kern_rel_offset);
+ expected_len = ntohl(bhssc->bhssc_expected_data_transfer_length);
+#if 0
+ if (expected_len != io->scsiio.kern_total_len)
+ CFISCSI_SESSION_DEBUG(cs, "expected transfer length = %zd, "
+ "actual length = %zd", expected_len,
+ io->scsiio.kern_total_len);
+#endif
+
+ if (buffer_offset >= expected_len) {
+#if 0
+ CFISCSI_SESSION_DEBUG(cs, "buffer_offset = %zd, "
+ "already sent the expected len", buffer_offset);
+#endif
+ io->scsiio.ext_data_filled = io->scsiio.kern_total_len;
+ io->scsiio.be_move_done(io);
+ return;
+ }
i = 0;
- addr = NULL;
- len = 0;
+ sg_addr = NULL;
+ sg_len = 0;
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list