Re: [Devel] [RH7 PATCH] ext4: drop pfcache csum on fallocate V2

2015-09-29 Thread Maxim Patlasov

ACK.

Dima, this is very minor, but nevertheless -- please write short 
description of what changed next time. (it takes a while for a reader to 
find out that s/EXT4_STATE_CSUM/EXT4_STATE_PFCACHE_CSUM is the only 
change you did since v1)


Thanks,
Maxim

On 09/29/2015 03:38 AM, Dmitry Monakhov wrote:

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [PATCH rh7] tcache: do not try to create node if we are not going to store page

2015-09-29 Thread Kirill Tkhai


On 25.09.2015 15:14, Vladimir Davydov wrote:
> Currently, we try to create a tcache node even if we are not going to
> actually store a page in tcache (tcache is disabled or we are called by
> global reclaimer). This is suboptimal, because we will drop the node
> anyway then.
> 
> Signed-off-by: Vladimir Davydov 

Reviewed-by: Kirill Tkhai 

> ---
>  mm/tcache.c | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/tcache.c b/mm/tcache.c
> index b078c84f9564..ce5b0edd8253 100644
> --- a/mm/tcache.c
> +++ b/mm/tcache.c
> @@ -835,10 +835,15 @@ static void tcache_cleancache_put_page(int pool_id,
>  {
>   struct tcache_node *node;
>   struct page *cache_page = NULL;
> + bool may_put = ACCESS_ONCE(tcache_active);
>  
> - node = tcache_get_node_and_pool(pool_id, &key, true);
> + /* It makes no sense to populate tcache when we are short on memory */
> + if (current->flags & PF_MEMALLOC)
> + may_put = false;
> +
> + node = tcache_get_node_and_pool(pool_id, &key, may_put);
>   if (node) {
> - if (tcache_active && !(current->flags & PF_MEMALLOC))
> + if (may_put)
>   cache_page = tcache_alloc_page();
>   if (cache_page) {
>   copy_highpage(cache_page, page);
> 
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [RH7 PATCH] ext4: drop pfcache csum on fallocate V2

2015-09-29 Thread Konstantin Khorenko

Maxim, please review the patch.

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 09/29/2015 01:38 PM, Dmitry Monakhov wrote:

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [RH7 PATCH] ext4: drop pfcache csum on fallocate V2

2015-09-29 Thread Dmitry Monakhov
>From 83ea3af40033e4214383a9846d8180d9c096c2e0 Mon Sep 17 00:00:00 2001
From: Dmitry Monakhov 
Date: Tue, 29 Sep 2015 14:35:25 +0400
Subject: [RH7 PATCH] ext4: drop pfcache csum on fallocate v2

If fallocate will change file's data we have to drop csum.

https://jira.sw.ru/browse/PSBM-33644

Signed-off-by: Dmitry Monakhov 
---
 fs/ext4/extents.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 08b0709..bac9339 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5062,6 +5062,11 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 		 FALLOC_FL_CONVERT_AND_EXTEND))
 		return -EOPNOTSUPP;
 
+	/* If data is about to change we must drop csum */
+	if (ext4_test_inode_state(inode, EXT4_STATE_PFCACHE_CSUM) &&
+	((mode & ~FALLOC_FL_KEEP_SIZE)  || !(mode & FALLOC_FL_KEEP_SIZE)))
+		ext4_truncate_data_csum(inode, -1);
+
 	if (mode & FALLOC_FL_PUNCH_HOLE)
 		return ext4_punch_hole(inode, offset, len);
 
-- 
1.7.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [RH7 PATCH] ext4: drop pfcache csum on fallocate

2015-09-29 Thread Dmitry Monakhov
Dmitry Monakhov  writes:

Please ignore this patch, use second version instead
> If fallocate will change file's data we have to drop csum.
>
> Signed-off-by: Dmitry Monakhov 
> ---
>  fs/ext4/extents.c |5 +
>  1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 08b0709..fe95102 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -5062,6 +5062,11 @@ long ext4_fallocate(struct file *file, int mode, 
> loff_t offset, loff_t len)
>FALLOC_FL_CONVERT_AND_EXTEND))
>   return -EOPNOTSUPP;
>  
> + /* If data is about to change we must drop csum */
> + if (ext4_test_inode_state(inode, EXT4_STATE_CSUM) &&
> + ((mode & ~FALLOC_FL_KEEP_SIZE)  || !(mode & FALLOC_FL_KEEP_SIZE)))
> + ext4_truncate_data_csum(inode, -1);
> +
>   if (mode & FALLOC_FL_PUNCH_HOLE)
>   return ext4_punch_hole(inode, offset, len);
>  
> -- 
> 1.7.1


signature.asc
Description: PGP signature
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7 7/7] ms/kvm/x86: add sending hyper-v crash notification to user space

2015-09-29 Thread Andrey Smetanin
Sending of notification is done by exiting vcpu to user space
if KVM_REQ_HV_CRASH is enabled for vcpu. At exit to user space
the kvm_run structure contains system_event with type
KVM_SYSTEM_EVENT_CRASH to notify about guest crash occurred.

ms commit - 2ce7918990641b07e70e1b25752d666369e2016e

Signed-off-by: Andrey Smetanin 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Peter Hornyack 
CC: Paolo Bonzini 
CC: Gleb Natapov 
Signed-off-by: Paolo Bonzini 
---
 Documentation/virtual/kvm/api.txt | 1 +
 arch/x86/kvm/x86.c| 6 ++
 include/uapi/linux/kvm.h  | 1 +
 3 files changed, 8 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 9ae0e53..f919ff6 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2687,6 +2687,7 @@ should put the acknowledged interrupt vector into the 
'epr' field.
struct {
 #define KVM_SYSTEM_EVENT_SHUTDOWN   1
 #define KVM_SYSTEM_EVENT_RESET  2
+#define KVM_SYSTEM_EVENT_CRASH  3
__u32 type;
__u64 flags;
} system_event;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index eeb63f7..db1017b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5787,6 +5787,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
vcpu_scan_ioapic(vcpu);
if (kvm_check_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu))
kvm_vcpu_reload_apic_access_page(vcpu);
+   if (kvm_check_request(KVM_REQ_HV_CRASH, vcpu)) {
+   vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+   vcpu->run->system_event.type = KVM_SYSTEM_EVENT_CRASH;
+   r = 0;
+   goto out;
+   }
}
 
if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) {
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index c35227f..d2ea15d 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -306,6 +306,7 @@ struct kvm_run {
struct {
 #define KVM_SYSTEM_EVENT_SHUTDOWN   1
 #define KVM_SYSTEM_EVENT_RESET  2
+#define KVM_SYSTEM_EVENT_CRASH  3
__u32 type;
__u64 flags;
} system_event;
-- 
1.8.3.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7 6/7] ms/KVM: Add KVM_EXIT_SYSTEM_EVENT to user space API header

2015-09-29 Thread Andrey Smetanin
From: Anup Patel 

Currently, we don't have an exit reason to notify user space about
a system-level event (for e.g. system reset or shutdown) triggered
by the VCPU. This patch adds exit reason KVM_EXIT_SYSTEM_EVENT for
this purpose. We can also inform user space about the 'type' and
architecture specific 'flags' of a system-level event using the
kvm_run structure.

This newly added KVM_EXIT_SYSTEM_EVENT will be used by KVM ARM/ARM64
in-kernel PSCI v0.2 support to reset/shutdown VMs.

Signed-off-by: Anup Patel 
Signed-off-by: Pranavkumar Sawargaonkar 
Reviewed-by: Christoffer Dall 
Reviewed-by: Marc Zyngier 
Signed-off-by: Christoffer Dall 
---
 Documentation/virtual/kvm/api.txt | 15 +++
 include/uapi/linux/kvm.h  |  8 
 2 files changed, 23 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 455e552..9ae0e53 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2683,6 +2683,21 @@ It gets triggered whenever both KVM_CAP_PPC_EPR are 
enabled and an
 external interrupt has just been delivered into the guest. User space
 should put the acknowledged interrupt vector into the 'epr' field.
 
+   /* KVM_EXIT_SYSTEM_EVENT */
+   struct {
+#define KVM_SYSTEM_EVENT_SHUTDOWN   1
+#define KVM_SYSTEM_EVENT_RESET  2
+   __u32 type;
+   __u64 flags;
+   } system_event;
+
+If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
+a system-level event using some architecture specific mechanism (hypercall
+or some special instruction). In case of ARM/ARM64, this is triggered using
+HVC instruction based PSCI call from the vcpu. The 'type' field describes
+the system-level event type. The 'flags' field describes architecture
+specific flags for the system-level event.
+
/* Fix the size of the union. */
char padding[256];
};
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index b6f604c..c35227f 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -171,6 +171,7 @@ struct kvm_pit_config {
 #define KVM_EXIT_WATCHDOG 21
 #define KVM_EXIT_S390_TSCH22
 #define KVM_EXIT_EPR  23
+#define KVM_EXIT_SYSTEM_EVENT 24
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -301,6 +302,13 @@ struct kvm_run {
struct {
__u32 epr;
} epr;
+   /* KVM_EXIT_SYSTEM_EVENT */
+   struct {
+#define KVM_SYSTEM_EVENT_SHUTDOWN   1
+#define KVM_SYSTEM_EVENT_RESET  2
+   __u32 type;
+   __u64 flags;
+   } system_event;
/* Fix the size of the union. */
char padding[256];
};
-- 
1.8.3.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7 5/7] ms/kvm/x86: added hyper-v crash msrs into kvm hyperv context

2015-09-29 Thread Andrey Smetanin
Added kvm Hyper-V context hv crash variables as storage
of Hyper-V crash msrs.

ms commit - e7d9513b60e87f62e41090fa3a26eca796924346

Signed-off-by: Andrey Smetanin 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Peter Hornyack 
CC: Paolo Bonzini 
CC: Gleb Natapov 
Signed-off-by: Paolo Bonzini 
---
 arch/x86/include/asm/kvm_host.h |  4 +++
 arch/x86/kvm/hyperv.c   | 76 +++--
 arch/x86/kvm/hyperv.h   |  2 +-
 arch/x86/kvm/x86.c  | 11 --
 include/linux/kvm_host.h|  1 +
 5 files changed, 88 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 2d36d39..7c36f68 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -557,6 +557,10 @@ struct kvm_hv {
u64 hv_guest_os_id;
u64 hv_hypercall;
u64 hv_tsc_page;
+
+   /* Hyper-v based guest crash (NT kernel bugcheck) parameters */
+   u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS];
+   u64 hv_crash_ctl;
 };
 
 struct kvm_arch {
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 740e046..625223b 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -38,6 +38,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
case HV_X64_MSR_HYPERCALL:
case HV_X64_MSR_REFERENCE_TSC:
case HV_X64_MSR_TIME_REF_COUNT:
+   case HV_X64_MSR_CRASH_CTL:
+   case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
r = true;
break;
}
@@ -45,7 +47,63 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
return r;
 }
 
-static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
+u32 index, u64 *pdata)
+{
+   struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+   if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
+   return -EINVAL;
+
+   *pdata = hv->hv_crash_param[index];
+   return 0;
+}
+
+static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
+{
+   struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+   *pdata = hv->hv_crash_ctl;
+   return 0;
+}
+
+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data, bool host)
+{
+   struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+   if (host)
+   hv->hv_crash_ctl = data & HV_X64_MSR_CRASH_CTL_NOTIFY;
+
+   if (!host && (data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {
+
+   vcpu_debug(vcpu, "hv crash (0x%llx 0x%llx 0x%llx 0x%llx 
0x%llx)\n",
+ hv->hv_crash_param[0],
+ hv->hv_crash_param[1],
+ hv->hv_crash_param[2],
+ hv->hv_crash_param[3],
+ hv->hv_crash_param[4]);
+
+   /* Send notification about crash to user space */
+   kvm_make_request(KVM_REQ_HV_CRASH, vcpu);
+   }
+
+   return 0;
+}
+
+static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
+u32 index, u64 data)
+{
+   struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
+
+   if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
+   return -EINVAL;
+
+   hv->hv_crash_param[index] = data;
+   return 0;
+}
+
+static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,
+bool host)
 {
struct kvm *kvm = vcpu->kvm;
struct kvm_hv *hv = &kvm->arch.hyperv;
@@ -95,6 +153,12 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data)
mark_page_dirty(kvm, gfn);
break;
}
+   case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
+   return kvm_hv_msr_set_crash_data(vcpu,
+msr - HV_X64_MSR_CRASH_P0,
+data);
+   case HV_X64_MSR_CRASH_CTL:
+   return kvm_hv_msr_set_crash_ctl(vcpu, data, host);
default:
vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
"data 0x%llx\n", msr, data);
@@ -166,6 +230,12 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 *pdata)
case HV_X64_MSR_REFERENCE_TSC:
data = hv->hv_tsc_page;
break;
+   case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
+   return kvm_hv_msr_get_crash_data(vcpu,
+msr - HV_X64_MSR_CRASH_P0,
+pdata);
+   case HV_X64_MSR_CRASH_CTL:
+   return kvm_hv_msr_get_crash_ctl(vcpu, pdata);
default:
vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
return 1;
@@ -209,12 +279,12 @@ static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, 
u64 *pdata)
retur

[Devel] [PATCH rh7 4/7] ms/kvm/x86: Move Hyper-V specific fields into new per vm/vcpu Hyper-V structures

2015-09-29 Thread Andrey Smetanin
ms commit - e83d58874ba1de74c13d3c6b05f95a023c860d25

Signed-off-by: Andrey Smetanin 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Peter Hornyack 
CC: Paolo Bonzini 
CC: Gleb Natapov 
Signed-off-by: Paolo Bonzini 

---
 arch/x86/include/asm/kvm_host.h | 20 ++--
 arch/x86/kvm/hyperv.c   | 33 +++--
 arch/x86/kvm/lapic.h|  2 +-
 3 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 150e96b..2d36d39 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -337,6 +337,11 @@ enum {
KVM_DEBUGREG_WONT_EXIT = 2,
 };
 
+/* Hyper-V per vcpu emulation context */
+struct kvm_vcpu_hv {
+   u64 hv_vapic;
+};
+
 struct kvm_vcpu_arch {
/*
 * rip and regs accesses must go through
@@ -485,8 +490,7 @@ struct kvm_vcpu_arch {
/* used for guest single stepping over the given code position */
unsigned long singlestep_rip;
 
-   /* fields used by HYPER-V emulation */
-   u64 hv_vapic;
+   struct kvm_vcpu_hv hyperv;
 
cpumask_var_t wbinvd_dirty_mask;
 
@@ -548,6 +552,13 @@ struct kvm_apic_map {
struct kvm_lapic *logical_map[16][16];
 };
 
+/* Hyper-V emulation context */
+struct kvm_hv {
+   u64 hv_guest_os_id;
+   u64 hv_hypercall;
+   u64 hv_tsc_page;
+};
+
 struct kvm_arch {
unsigned int n_used_mmu_pages;
unsigned int n_requested_mmu_pages;
@@ -602,10 +613,7 @@ struct kvm_arch {
 
struct kvm_xen_hvm_config xen_hvm_config;
 
-   /* fields used by HYPER-V emulation */
-   u64 hv_guest_os_id;
-   u64 hv_hypercall;
-   u64 hv_tsc_page;
+   struct kvm_hv hyperv;
 
#ifdef CONFIG_KVM_MMU_AUDIT
int audit_point;
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index d9d43bc..740e046 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -48,13 +48,14 @@ static bool kvm_hv_msr_partition_wide(u32 msr)
 static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
struct kvm *kvm = vcpu->kvm;
+   struct kvm_hv *hv = &kvm->arch.hyperv;
 
switch (msr) {
case HV_X64_MSR_GUEST_OS_ID:
-   kvm->arch.hv_guest_os_id = data;
+   hv->hv_guest_os_id = data;
/* setting guest os id to zero disables hypercall page */
-   if (!kvm->arch.hv_guest_os_id)
-   kvm->arch.hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+   if (!hv->hv_guest_os_id)
+   hv->hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
break;
case HV_X64_MSR_HYPERCALL: {
u64 gfn;
@@ -62,10 +63,10 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data)
u8 instructions[4];
 
/* if guest os id is not set hypercall should remain disabled */
-   if (!kvm->arch.hv_guest_os_id)
+   if (!hv->hv_guest_os_id)
break;
if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
-   kvm->arch.hv_hypercall = data;
+   hv->hv_hypercall = data;
break;
}
gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
@@ -76,7 +77,7 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, 
u64 data)
((unsigned char *)instructions)[3] = 0xc3; /* ret */
if (__copy_to_user((void __user *)addr, instructions, 4))
return 1;
-   kvm->arch.hv_hypercall = data;
+   hv->hv_hypercall = data;
mark_page_dirty(kvm, gfn);
break;
}
@@ -84,7 +85,7 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, 
u64 data)
u64 gfn;
HV_REFERENCE_TSC_PAGE tsc_ref;
memset(&tsc_ref, 0, sizeof(tsc_ref));
-   kvm->arch.hv_tsc_page = data;
+   hv->hv_tsc_page = data;
if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
break;
gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
@@ -104,13 +105,15 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data)
 
 static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
+   struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
+
switch (msr) {
case HV_X64_MSR_APIC_ASSIST_PAGE: {
u64 gfn;
unsigned long addr;
 
if (!(data & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
-   vcpu->arch.hv_vapic = data;
+   hv->hv_vapic = data;
if (kvm_lapic_enable_pv_eoi(vcpu, 0))
return 1;
break;
@@ -121,7 +124,7 @@ static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, 
u64 

[Devel] [PATCH rh7 3/7] ms/kvm: introduce vcpu_debug = kvm_debug + vcpu context

2015-09-29 Thread Andrey Smetanin
vcpu_debug is useful macro like kvm_debug but additionally
includes vcpu context inside output.

ms commit - ee86dbc6e327062396748162b95309388c19faab

Signed-off-by: Andrey Smetanin 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Peter Hornyack 
CC: Paolo Bonzini 
CC: Gleb Natapov 
Signed-off-by: Paolo Bonzini 
---
 include/linux/kvm_host.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 9be71a0..43a9a0f 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -406,6 +406,9 @@ struct kvm {
 #define vcpu_unimpl(vcpu, fmt, ...)\
kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
 
+#define vcpu_debug(vcpu, fmt, ...) \
+   kvm_debug("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
+
 static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
 {
smp_rmb();
-- 
1.8.3.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7 2/7] ms/kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file

2015-09-29 Thread Andrey Smetanin
This patch introduce Hyper-V related source code file - hyperv.c and
per vm and per vcpu hyperv context structures.
All Hyper-V MSR's and hypercall code moved into hyperv.c.
All Hyper-V kvm/vcpu fields moved into appropriate hyperv context
structures. Copyrights and authors information copied from x86.c
to hyperv.c.

ms commit - e83d58874ba1de74c13d3c6b05f95a023c860d25

Signed-off-by: Andrey Smetanin 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Peter Hornyack 
CC: Paolo Bonzini 
CC: Gleb Natapov 
Signed-off-by: Paolo Bonzini 
---
 arch/x86/kvm/Makefile |   3 +-
 arch/x86/kvm/hyperv.c | 296 ++
 arch/x86/kvm/hyperv.h |  32 ++
 arch/x86/kvm/x86.c| 271 +
 arch/x86/kvm/x86.h|   9 ++
 5 files changed, 342 insertions(+), 269 deletions(-)
 create mode 100644 arch/x86/kvm/hyperv.c
 create mode 100644 arch/x86/kvm/hyperv.h

diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index 25d22b2..a893d11 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -14,7 +14,8 @@ kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT)   += 
$(KVM)/assigned-dev.o $(KVM)/iommu.o
 kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
 
 kvm-y  += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
-  i8254.o cpuid.o pmu.o
+  i8254.o cpuid.o pmu.o hyperv.o
+
 kvm-intel-y+= vmx.o
 kvm-amd-y  += svm.o
 
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
new file mode 100644
index 000..d9d43bc
--- /dev/null
+++ b/arch/x86/kvm/hyperv.c
@@ -0,0 +1,296 @@
+/*
+ * KVM Microsoft Hyper-V emulation
+ *
+ * derived from arch/x86/kvm/x86.c
+ *
+ * Copyright (C) 2006 Qumranet, Inc.
+ * Copyright (C) 2008 Qumranet, Inc.
+ * Copyright IBM Corporation, 2008
+ * Copyright 2010 Red Hat, Inc. and/or its affiliates.
+ * Copyright (C) 2015 Andrey Smetanin 
+ *
+ * Authors:
+ *   Avi Kivity   
+ *   Yaniv Kamay  
+ *   Amit Shah
+ *   Ben-Ami Yassour 
+ *   Andrey Smetanin 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "x86.h"
+#include "lapic.h"
+#include "hyperv.h"
+
+#include 
+#include 
+
+#include "trace.h"
+
+static bool kvm_hv_msr_partition_wide(u32 msr)
+{
+   bool r = false;
+   switch (msr) {
+   case HV_X64_MSR_GUEST_OS_ID:
+   case HV_X64_MSR_HYPERCALL:
+   case HV_X64_MSR_REFERENCE_TSC:
+   case HV_X64_MSR_TIME_REF_COUNT:
+   r = true;
+   break;
+   }
+
+   return r;
+}
+
+static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
+{
+   struct kvm *kvm = vcpu->kvm;
+
+   switch (msr) {
+   case HV_X64_MSR_GUEST_OS_ID:
+   kvm->arch.hv_guest_os_id = data;
+   /* setting guest os id to zero disables hypercall page */
+   if (!kvm->arch.hv_guest_os_id)
+   kvm->arch.hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
+   break;
+   case HV_X64_MSR_HYPERCALL: {
+   u64 gfn;
+   unsigned long addr;
+   u8 instructions[4];
+
+   /* if guest os id is not set hypercall should remain disabled */
+   if (!kvm->arch.hv_guest_os_id)
+   break;
+   if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
+   kvm->arch.hv_hypercall = data;
+   break;
+   }
+   gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+   addr = gfn_to_hva(kvm, gfn);
+   if (kvm_is_error_hva(addr))
+   return 1;
+   kvm_x86_ops->patch_hypercall(vcpu, instructions);
+   ((unsigned char *)instructions)[3] = 0xc3; /* ret */
+   if (__copy_to_user((void __user *)addr, instructions, 4))
+   return 1;
+   kvm->arch.hv_hypercall = data;
+   mark_page_dirty(kvm, gfn);
+   break;
+   }
+   case HV_X64_MSR_REFERENCE_TSC: {
+   u64 gfn;
+   HV_REFERENCE_TSC_PAGE tsc_ref;
+   memset(&tsc_ref, 0, sizeof(tsc_ref));
+   kvm->arch.hv_tsc_page = data;
+   if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
+   break;
+   gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
+   if (kvm_write_guest(kvm, gfn << 
HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT,
+   &tsc_ref, sizeof(tsc_ref)))
+   return 1;
+   mark_page_dirty(kvm, gfn);
+   break;
+   }
+   default:
+   vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
+   "data 0x%llx\n", msr, data);
+   return 1;
+   }
+   return 0;
+}
+
+static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data

[Devel] [PATCH rh7 1/7] ms/kvm: add hyper-v crash msrs values

2015-09-29 Thread Andrey Smetanin
Added Hyper-V crash msrs values - HV_X64_MSR_CRASH*.

ms commit - a88464a8b0ffb2f8dfb69d3ab982169578b50f22

Signed-off-by: Andrey Smetanin 
Signed-off-by: Denis V. Lunev 
Reviewed-by: Peter Hornyack 
CC: Paolo Bonzini 
CC: Gleb Natapov 
Signed-off-by: Paolo Bonzini 
---
 arch/x86/include/uapi/asm/hyperv.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/x86/include/uapi/asm/hyperv.h 
b/arch/x86/include/uapi/asm/hyperv.h
index 462efe7..1808792 100644
--- a/arch/x86/include/uapi/asm/hyperv.h
+++ b/arch/x86/include/uapi/asm/hyperv.h
@@ -187,6 +187,16 @@
 #define HV_X64_MSR_SINT14  0x409E
 #define HV_X64_MSR_SINT15  0x409F
 
+/* Hyper-V guest crash notification MSR's */
+#define HV_X64_MSR_CRASH_P00x4100
+#define HV_X64_MSR_CRASH_P10x4101
+#define HV_X64_MSR_CRASH_P20x4102
+#define HV_X64_MSR_CRASH_P30x4103
+#define HV_X64_MSR_CRASH_P40x4104
+#define HV_X64_MSR_CRASH_CTL   0x4105
+#define HV_X64_MSR_CRASH_CTL_NOTIFY(1ULL << 63)
+#define HV_X64_MSR_CRASH_PARAMS\
+   (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
 
 #define HV_X64_MSR_HYPERCALL_ENABLE0x0001
 #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT12
-- 
1.8.3.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7 0/7] Hyper-V pvpanic equivalent

2015-09-29 Thread Andrey Smetanin
Windows 2012 guests can notify hypervisor about occurred guest crash
(Windows bugcheck(BSOD)) by writing specific Hyper-V msrs. This patch does
handling of this MSR's by KVM and sending notification to user space that
allows to gather Windows guest crash dump by QEMU/LIBVIRT.

The idea is to provide functionality equal to pvpanic device without
QEMU guest agent for Windows.

The idea is borrowed from Linux HyperV bus driver and validated against
Windows 2k12.

Andrey Smetanin (6):
  kvm: add hyper-v crash msrs values
  kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file
  kvm: introduce vcpu_debug = kvm_debug + vcpu context
  kvm/x86: Move Hyper-V specific fields into new per vm/vcpu Hyper-V
structures
  kvm/x86: added hyper-v crash msrs into kvm hyperv context
  kvm/x86: add sending hyper-v crash notification to user space

Anup Patel (1):
  KVM: Add KVM_EXIT_SYSTEM_EVENT to user space API header

 Documentation/virtual/kvm/api.txt  |  16 ++
 arch/x86/include/asm/kvm_host.h|  24 ++-
 arch/x86/include/uapi/asm/hyperv.h |  10 +
 arch/x86/kvm/Makefile  |   3 +-
 arch/x86/kvm/hyperv.c  | 371 +
 arch/x86/kvm/hyperv.h  |  32 
 arch/x86/kvm/lapic.h   |   2 +-
 arch/x86/kvm/x86.c | 286 ++--
 arch/x86/kvm/x86.h |   9 +
 include/linux/kvm_host.h   |   4 +
 include/uapi/linux/kvm.h   |   9 +
 11 files changed, 489 insertions(+), 277 deletions(-)
 create mode 100644 arch/x86/kvm/hyperv.c
 create mode 100644 arch/x86/kvm/hyperv.h

-- 
1.8.3.1

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel