Skip to content

Commit

Permalink
refashioned
Browse files Browse the repository at this point in the history
  • Loading branch information
ddk50 committed Sep 8, 2010
1 parent 29c3fdc commit f64815c
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 185 deletions.
11 changes: 2 additions & 9 deletions kvm/kernel/include/linux/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,11 @@ struct kvm_dirty_log {
/*
* for WinKVM
*/
#define WINKVM_GET_HUGE_NONPAGEAREA _IOW(KVMIO, 19, unsigned long)
#define WINKVM_NOPAGE _IOW(KVMIO, 20, unsigned long)
#define WINKVM_INIT_TESTMAP _IO(KVMIO, 30)
#define WINKVM_TESTMAP _IOW(KVMIO, 31, unsigned long)
#define WINKVM_RELEASE_TESTMAP _IO(KVMIO, 32)
#define WINKVM_EXECUTE_TEST _IO(KVMIO, 33)
#define WINKVM_PUT_VCPU _IO(KVMIO, 34)

#define WINKVM_READ_GUEST _IO(KVMIO, 35)
#define WINKVM_WRITE_GUEST _IO(KVMIO, 36)
#define WINKVM_MAPMEM_INITIALIZE _IOWR(KVMIO, 37, struct winkvm_mapmem_initialize)
#define WINKVM_MAPMEM_GETPVMAP _IOWR(KVMIO, 38, struct winkvm_getpvmap)
#define WINKVM_UNMAPMEM_GETPVMAP _IOWR(KVMIO, 39, struct winkvm_getpvmap)
#define WINKVM_MAPMEM_RELEASE _IOWR(KVMIO, 39, struct winkvm_getpvmap)

#endif

11 changes: 2 additions & 9 deletions vcproj/include/linux/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,11 @@ struct kvm_dirty_log {
/*
* for WinKVM
*/
#define WINKVM_GET_HUGE_NONPAGEAREA _IOW(KVMIO, 19, unsigned long)
#define WINKVM_NOPAGE _IOW(KVMIO, 20, unsigned long)
#define WINKVM_INIT_TESTMAP _IO(KVMIO, 30)
#define WINKVM_TESTMAP _IOW(KVMIO, 31, unsigned long)
#define WINKVM_RELEASE_TESTMAP _IO(KVMIO, 32)
#define WINKVM_EXECUTE_TEST _IO(KVMIO, 33)
#define WINKVM_PUT_VCPU _IO(KVMIO, 34)

#define WINKVM_READ_GUEST _IO(KVMIO, 35)
#define WINKVM_WRITE_GUEST _IO(KVMIO, 36)
#define WINKVM_MAPMEM_INITIALIZE _IOWR(KVMIO, 37, struct winkvm_mapmem_initialize)
#define WINKVM_MAPMEM_GETPVMAP _IOWR(KVMIO, 38, struct winkvm_getpvmap)
#define WINKVM_UNMAPMEM_GETPVMAP _IOWR(KVMIO, 39, struct winkvm_getpvmap)
#define WINKVM_MAPMEM_RELEASE _IOWR(KVMIO, 39, struct winkvm_getpvmap)

#endif

27 changes: 27 additions & 0 deletions vcproj/kernel/desc_emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define _DESC_H_

#include <linux/winkvm.h>
#include "init.h"

#define MAX_FD_SLOT 50
#define MAX_INODE_SLOT 50
Expand All @@ -25,4 +26,30 @@ struct fd_slot {
struct file *file;
};

#define MAX_MUTEX_COUNT 50
#define MAX_SPINLOCK_COUNT 50

#define SMPF_SLOTNUM 20

struct mutex_emulater_slot {
int used;
FAST_MUTEX mutex;
};

struct spinlock_emulater_slot {
int used;
KIRQL IrqL;
KSPIN_LOCK spinlock;
};

/*
* for smp_call_function;
* per cpu;
*/
struct smpf_data {
void (_cdecl *func)(void *info);
void *info;
int mycpu_num;
};

#endif
8 changes: 8 additions & 0 deletions vcproj/kernel/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ typedef struct _WINKVM_DEVICE_EXTENSION {
struct file_slot file_slot[MAX_FILE_SLOT];
struct fd_slot fd_slot[MAX_FD_SLOT];
FAST_MUTEX fd_slot_mutex;
/* mutex and spinlock */
struct mutex_emulater_slot mutex_slot[MAX_MUTEX_COUNT];
struct spinlock_emulater_slot spinlock_slot[MAX_SPINLOCK_COUNT];
struct smpf_data smpf_data_slot[SMPF_SLOTNUM];
int mutex_emulater_initialized;
int spinlock_emulater_initialized;
FAST_MUTEX emulater_mutex;
FAST_MUTEX emulater_spinlock;
} WINKVM_DEVICE_EXTENSION;

typedef WINKVM_DEVICE_EXTENSION* PWINKVM_DEVICE_EXTENSION;
Expand Down
69 changes: 8 additions & 61 deletions vcproj/kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ __winkvmstab_ioctl(IN PDEVICE_OBJECT DeviceObject,
break;
} /* end KVM_RUN */

/* There are specific ioctl handlers for WinKVM */
/* Specific ioctl handlers for WinKVM as follow: */
case WINKVM_READ_GUEST:
{
struct winkvm_transfer_mem trans_mem;
Expand Down Expand Up @@ -604,11 +604,7 @@ __winkvmstab_ioctl(IN PDEVICE_OBJECT DeviceObject,
CloseUserMapping(mapMemInfo->npages, init.slot, mapMemInfo);
}

ntStatus = CreateUserMapping(
init.npages,
init.slot,
mapMemInfo);

ntStatus = CreateUserMapping(init.npages, init.slot, mapMemInfo);
if (!NT_SUCCESS(ntStatus)) {
init.mapUserVA = NULL;
init.npages = 0;
Expand All @@ -618,68 +614,19 @@ __winkvmstab_ioctl(IN PDEVICE_OBJECT DeviceObject,
init.mapUserVA = (__u8*)mapMemInfo->userVAaddress;
mapMemInfo->npages = init.npages;
mapMemInfo->base_gfn = init.base_gfn;
printk(KERN_ALERT "slot [%d] memory mapping: %llx ... %llx (%d [pages])\n",
printk(KERN_ALERT
"slot [%d] memory mapping: %x (PN) ... %x (PN) (%d [pages])\n",
init.slot,
(u64)mapMemInfo->base_gfn << PAGE_SHIFT,
(u64)(mapMemInfo->base_gfn + mapMemInfo->npages) << PAGE_SHIFT,
mapMemInfo->base_gfn,
mapMemInfo->base_gfn + mapMemInfo->npages,
mapMemInfo->npages);
}
} RtlCopyMemory(outBuf, &init, sizeof(init));
Irp->IoStatus.Information = sizeof(init);
break;
} /* end WINKVM_MAPMEM_INITIALIZE */

case WINKVM_MAPMEM_GETPVMAP:
{
unsigned int i;
unsigned long addr;
unsigned long RetLength;
struct winkvm_getpvmap pvmap;
struct winkvm_getpvmap *p;
PVOID sysAddr;

printk(KERN_ALERT "Call WINKVM_MAPMEM_GETPVMAP\n");

RtlCopyMemory(&pvmap, inBuf, sizeof(pvmap));
{
if (pvmap.slot >= MAX_MEMMAP_SLOT) {
ntStatus = STATUS_UNSUCCESSFUL;
break;
}
if (pvmap.tablesize == 0) {
p = &pvmap;
RetLength = sizeof(pvmap);
pvmap.tablesize =
(__u32)(extension->mapMemInfo[pvmap.slot].npages)
* sizeof(struct winkvm_pfmap);
printk(KERN_ALERT "pvmap table size: %d\n", pvmap.tablesize);
} else {
/* get system address */

sysAddr = MmGetSystemAddressForMdlSafe(
extension->mapMemInfo[pvmap.slot].apMdl[0],
NormalPagePriority);

SAFE_ASSERT(sysAddr != NULL);

p = (struct winkvm_getpvmap*)inBuf;
RetLength = p->tablesize + sizeof(struct winkvm_pfmap);

for (i = 0 ; i < (p->tablesize / sizeof(struct winkvm_pfmap)) ; i++) {
addr = (unsigned long)((__u8*)extension->mapMemInfo[p->slot].userVAaddress + i * PAGE_SIZE);
p->maptable[i].virt = addr;
p->maptable[i].phys = (unsigned long)__pa(addr);
RtlZeroMemory((__u8*)sysAddr + i * PAGE_SIZE, PAGE_SIZE);
}
}
} RtlCopyMemory(outBuf, p, RetLength);
Irp->IoStatus.Information = RetLength;
ntStatus = STATUS_SUCCESS;

break;
} /* end WINKVM_MAPMEM_GETPVMAP */

case WINKVM_UNMAPMEM_GETPVMAP:
case WINKVM_MAPMEM_RELEASE:
{
struct winkvm_getpvmap pvmap;

Expand All @@ -696,7 +643,7 @@ __winkvmstab_ioctl(IN PDEVICE_OBJECT DeviceObject,
Irp->IoStatus.Information = sizeof(pvmap);

ntStatus = STATUS_SUCCESS;
} /* end WINKVM_UNMAPMEM_GETPVMAP */
} /* end WINKVM_MAPMEM_RELEASE */

default:
ntStatus = STATUS_UNSUCCESSFUL;
Expand Down
2 changes: 1 addition & 1 deletion vcproj/kernel/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ get_mapmem_slot(unsigned long gfn)
return NULL;
}

static dump_page(struct page *page)
static void dump_page(struct page *page)
{
static char *page_type[] = {
"PAGE_NOT_USED",
Expand Down
Loading

0 comments on commit f64815c

Please sign in to comment.