Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1686058 > unrolled thread

Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler

Started byRadim Krčmář <rkrcmar@redhat.com>
First post2017-07-12 23:50 +0200
Last post2017-07-14 03:50 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit  handler Radim Krčmář <rkrcmar@redhat.com> - 2017-07-12 23:50 +0200
    Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler Wanpeng Li <kernellwp@gmail.com> - 2017-07-13 03:40 +0200
    Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit  handler Radim Krčmář <rkrcmar@redhat.com> - 2017-07-13 17:30 +0200
      Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler Wanpeng Li <kernellwp@gmail.com> - 2017-07-14 03:50 +0200

#1686058 — Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler

FromRadim Krčmář <rkrcmar@redhat.com>
Date2017-07-12 23:50 +0200
SubjectRe: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler
Message-ID<u2xGa-59T-17@gated-at.bofh.it>
2017-06-28 20:01-0700, Wanpeng Li:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
> 
> This patch adds the L1 guest async page fault #PF vmexit handler, such
> #PF is converted into vmexit from L2 to L1 on #PF which is then handled
> by L1 similar to ordinary async page fault.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---

This patch breaks SVM, so I've taken the series off kvm/queue for now;
I'll look into it tomorrow.  The error is:

 BUG: unable to handle kernel paging request at ffffffffc0735ad2
 IP: report_bug+0x94/0x120
 PGD 43e14067 
 P4D 43e14067 
 PUD 43e16067 
 PMD 2164bf067 
 PTE 80000002181fc161

 Oops: 0003 [#1] SMP
 Modules linked in: kvm_amd(OE) kvm(OE) irqbypass(E) xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack libcrc32c tun bridge stp llc ebtable_filter ebtables ip6table_filter ip6_tables sunrpc snd_hda_codec_realtek snd_hda_codec_generic snd_hda_codec_hdmi snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core snd_seq snd_seq_device snd_pcm ppdev joydev parport_serial parport_pc snd_timer parport k10temp sky2 snd shpchp sp5100_tco acpi_cpufreq wmi soundcore i2c_piix4 amdkfd amd_iommu_v2 radeon i2c_algo_bit drm_kms_helper uas serio_raw usb_storage ttm pata_atiixp drm ata_generic pata_acpi pata_jmicron [last unloaded: irqbypass]
 CPU: 3 PID: 1868 Comm: CPU 0/KVM Tainted: G           OE   4.12.0+ #1
 Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./To be filled by O.E.M., BIOS 080014  03/07/2008
 task: ffff8bcbe3f1b140 task.stack: ffffabb481970000
 RIP: 0010:report_bug+0x94/0x120
 RSP: 0018:ffffabb481973a70 EFLAGS: 00010202
 RAX: 0000000000000907 RBX: ffffabb481973bd8 RCX: ffffffffc0735ac8
 RDX: 0000000000000001 RSI: 0000000000000ed0 RDI: 0000000000000001
 RBP: ffffabb481973a90 R08: 0000000000000001 R09: 7f9f279200000000
 R10: ffffabb4819739d0 R11: 0000000000000000 R12: ffffffffc07023d0
 R13: ffffffffc0733078 R14: 0000000000000004 R15: ffffabb481973bd8
 FS:  0000000000000000(0000) GS:ffff8bcbe7400000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: ffffffffc0735ad2 CR3: 00000002189d7000 CR4: 00000000000006e0
 Call Trace:
  ? kvm_handle_page_fault+0x1f0/0x200 [kvm]
  fixup_bug+0x2e/0x50
  do_trap+0x119/0x150
  do_error_trap+0xa3/0x160
  ? kvm_handle_page_fault+0x1f0/0x200 [kvm]
  ? trace_hardirqs_off_thunk+0x1a/0x1c
  do_invalid_op+0x20/0x30
  invalid_op+0x1e/0x30
 RIP: 0010:kvm_handle_page_fault+0x1f0/0x200 [kvm]
 RSP: 0018:ffffabb481973c80 EFLAGS: 00010202
 RAX: 0000000000000000 RBX: ffff8bcbd7550000 RCX: 0000000000000000
 RDX: 00000000fffffff0 RSI: 0000000000000014 RDI: ffff8bcbd7550000
 RBP: ffffabb481973ca0 R08: 0000000000000001 R09: 27624b3d00000000
 R10: ffffabb481973ca8 R11: ffff8bcbe3fb25f0 R12: 00000000fffffff0
 R13: 0000000000000014 R14: ffff8bcbd7550000 R15: ffff8bcbd7550000
  pf_interception+0x20/0x30 [kvm_amd]
  handle_exit+0x213/0xbb0 [kvm_amd]
  kvm_arch_vcpu_ioctl_run+0x7f1/0x1ae0 [kvm]
  kvm_vcpu_ioctl+0x2ac/0x6f0 [kvm]
  ? kvm_vcpu_ioctl+0x2ac/0x6f0 [kvm]
  ? sched_clock+0x9/0x10
  ? debug_lockdep_rcu_enabled+0x1d/0x30
  do_vfs_ioctl+0xa6/0x6c0
  SyS_ioctl+0x79/0x90
  entry_SYSCALL_64_fastpath+0x1f/0xbe
 RIP: 0033:0x7fabf6d815c7
 RSP: 002b:00007fabe87e77c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
 RAX: ffffffffffffffda RBX: 0000000000010000 RCX: 00007fabf6d815c7
 RDX: 0000000000000000 RSI: 000000000000ae80 RDI: 0000000000000010
 RBP: 000055a7cb502fe0 R08: 000055a7cb51e410 R09: 000055a7cb509390
 R10: 000055a7cdb01000 R11: 0000000000000246 R12: 000055a7cdace0a6
 R13: 0000000000000000 R14: 00007fac00621000 R15: 000055a7cdace000
 Code: 74 59 0f b7 41 0a 4c 63 69 04 0f b7 71 08 89 c7 49 01 cd 83 e7 01 a8 02 74 15 66 85 ff 74 10 a8 04 ba 01 00 00 00 75 26 83 c8 04 <66> 89 41 0a 66 85 ff 74 49 0f b6 49 0b 4c 89 e2 45 31 c9 49 89 
 RIP: report_bug+0x94/0x120 RSP: ffffabb481973a70
 CR2: ffffffffc0735ad2
 ---[ end trace aec3a1f15664a4af ]---
 BUG: sleeping function called from invalid context at ./include/linux/percpu-rwsem.h:33
 in_atomic(): 0, irqs_disabled(): 1, pid: 1868, name: CPU 0/KVM
 INFO: lockdep is turned off.
 irq event stamp: 1868
 hardirqs last  enabled at (1867): [<ffffffffa398eaab>] restore_regs_and_iret+0x0/0x1d
 hardirqs last disabled at (1868): [<ffffffffa398f7dc>] error_entry+0x7c/0xd0
 softirqs last  enabled at (1834): [<ffffffffa3992f62>] __do_softirq+0x382/0x4ed
 softirqs last disabled at (1817): [<ffffffffa30b9a2f>] irq_exit+0x10f/0x120
 CPU: 3 PID: 1868 Comm: CPU 0/KVM Tainted: G      D    OE   4.12.0+ #1
 Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./To be filled by O.E.M., BIOS 080014  03/07/2008
 Call Trace:
  dump_stack+0x8e/0xcd
  ___might_sleep+0x164/0x250
  __might_sleep+0x4a/0x80
  exit_signals+0x33/0x240
  do_exit+0xb4/0xd20
  ? SyS_ioctl+0x79/0x90
  rewind_stack_do_exit+0x17/0x20
 RIP: 0033:0x7fabf6d815c7
 RSP: 002b:00007fabe87e77c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
 RAX: ffffffffffffffda RBX: 0000000000010000 RCX: 00007fabf6d815c7
 RDX: 0000000000000000 RSI: 000000000000ae80 RDI: 0000000000000010
 RBP: 000055a7cb502fe0 R08: 000055a7cb51e410 R09: 000055a7cb509390
 R10: 000055a7cdb01000 R11: 0000000000000246 R12: 000055a7cdace0a6
 R13: 0000000000000000 R14: 00007fac00621000 R15: 000055a7cdace000

[toc] | [next] | [standalone]


#1686173 — Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler

FromWanpeng Li <kernellwp@gmail.com>
Date2017-07-13 03:40 +0200
SubjectRe: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler
Message-ID<u2BgJ-7th-11@gated-at.bofh.it>
In reply to#1686058
2017-07-13 5:44 GMT+08:00 Radim Krčmář <rkrcmar@redhat.com>:
> 2017-06-28 20:01-0700, Wanpeng Li:
>> From: Wanpeng Li <wanpeng.li@hotmail.com>
>>
>> This patch adds the L1 guest async page fault #PF vmexit handler, such
>> #PF is converted into vmexit from L2 to L1 on #PF which is then handled
>> by L1 similar to ordinary async page fault.
>>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: Radim Krčmář <rkrcmar@redhat.com>
>> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
>> ---
>
> This patch breaks SVM, so I've taken the series off kvm/queue for now;

> I'll look into it tomorrow.

Thanks for the help. :)

Regards,
Wanpeng Li

[toc] | [prev] | [next] | [standalone]


#1686627

FromRadim Krčmář <rkrcmar@redhat.com>
Date2017-07-13 17:30 +0200
Message-ID<u2OdX-7kO-5@gated-at.bofh.it>
In reply to#1686058
2017-07-12 23:44+0200, Radim Krčmář:
> 2017-06-28 20:01-0700, Wanpeng Li:
> > From: Wanpeng Li <wanpeng.li@hotmail.com>
> > 
> > This patch adds the L1 guest async page fault #PF vmexit handler, such
> > #PF is converted into vmexit from L2 to L1 on #PF which is then handled
> > by L1 similar to ordinary async page fault.
> > 
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: Radim Krčmář <rkrcmar@redhat.com>
> > Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> > ---
> 
> This patch breaks SVM, so I've taken the series off kvm/queue for now;

The error is triggered by 'WARN_ON_ONCE(tdp_enabled);', because
pf_interception() handles both cases.  (The bizzare part is that it
doesn't warn.)

I think this hunk on top of the patch would be good.  It makes the
WARN_ON_ONCE specific to VMX and also preserves the parameters that SVM
had before.

(Passes basic tests, haven't done the nested async_pf test yet.)


diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index f37c0307dcb0..338cb4c8cbb9 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3782,17 +3782,16 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
 }
 
 int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
-				u64 fault_address)
+				u64 fault_address, char *insn, int insn_len,
+				bool need_unprotect)
 {
 	int r = 1;
 
 	switch (vcpu->arch.apf.host_apf_reason) {
 	default:
-		/* TDP won't cause page fault directly */
-		WARN_ON_ONCE(tdp_enabled);
 		trace_kvm_page_fault(fault_address, error_code);
 
-		if (kvm_event_needs_reinjection(vcpu))
+		if (need_unprotect && kvm_event_needs_reinjection(vcpu))
 			kvm_mmu_unprotect_page_virt(vcpu, fault_address);
 		r = kvm_mmu_page_fault(vcpu, fault_address, error_code, NULL, 0);
 		break;
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 270d9adaa039..d7d248a000dd 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -78,7 +78,8 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly,
 			     bool accessed_dirty);
 bool kvm_can_do_async_pf(struct kvm_vcpu *vcpu);
 int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
-				u64 fault_address);
+				u64 fault_address, char *insn, int insn_len,
+				bool need_unprotect);
 
 static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm)
 {
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 659b610c4711..fb23497cf915 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2123,7 +2123,9 @@ static int pf_interception(struct vcpu_svm *svm)
 	u64 fault_address = svm->vmcb->control.exit_info_2;
 	u64 error_code = svm->vmcb->control.exit_info_1;
 
-	return kvm_handle_page_fault(&svm->vcpu, error_code, fault_address);
+	return kvm_handle_page_fault(&svm->vcpu, error_code, fault_address,
+			svm->vmcb->control.insn_bytes,
+			svm->vmcb->control.insn_len, !npt_enabled);
 }
 
 static int db_interception(struct vcpu_svm *svm)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index ab33eace4f66..2e8cfb2f1371 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -5699,7 +5699,10 @@ static int handle_exception(struct kvm_vcpu *vcpu)
 
 	if (is_page_fault(intr_info)) {
 		cr2 = vmcs_readl(EXIT_QUALIFICATION);
-		return kvm_handle_page_fault(vcpu, error_code, cr2);
+		/* TDP won't cause page fault directly */
+		WARN_ON_ONCE(!vcpu->arch.apf.host_apf_reason && tdp_enabled);
+		return kvm_handle_page_fault(vcpu, error_code, cr2, NULL, 0,
+				true);
 	}
 
 	ex_no = intr_info & INTR_INFO_VECTOR_MASK;

[toc] | [prev] | [next] | [standalone]


#1687022 — Re: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler

FromWanpeng Li <kernellwp@gmail.com>
Date2017-07-14 03:50 +0200
SubjectRe: [PATCH v7 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler
Message-ID<u2XTZ-4Tk-13@gated-at.bofh.it>
In reply to#1686627
2017-07-13 23:29 GMT+08:00 Radim Krčmář <rkrcmar@redhat.com>:
> 2017-07-12 23:44+0200, Radim Krčmář:
>> 2017-06-28 20:01-0700, Wanpeng Li:
>> > From: Wanpeng Li <wanpeng.li@hotmail.com>
>> >
>> > This patch adds the L1 guest async page fault #PF vmexit handler, such
>> > #PF is converted into vmexit from L2 to L1 on #PF which is then handled
>> > by L1 similar to ordinary async page fault.
>> >
>> > Cc: Paolo Bonzini <pbonzini@redhat.com>
>> > Cc: Radim Krčmář <rkrcmar@redhat.com>
>> > Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
>> > ---
>>
>> This patch breaks SVM, so I've taken the series off kvm/queue for now;
>
> The error is triggered by 'WARN_ON_ONCE(tdp_enabled);', because
> pf_interception() handles both cases.  (The bizzare part is that it
> doesn't warn.)
>
> I think this hunk on top of the patch would be good.  It makes the

Thanks Radim! The work is really appreciated. :)

> WARN_ON_ONCE specific to VMX and also preserves the parameters that SVM
> had before.

I replace the tdp_enabled by enable_ept in VMX since there is a
warning: "tdp_enabled" in [kvm-intel.ko] undefined! Btw, I just sent
out v8, hope both
the v8 and vm86 stuff can catch the end of the merge window. :)

Regards,
Wanpeng Li

>
> (Passes basic tests, haven't done the nested async_pf test yet.)
>
>
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index f37c0307dcb0..338cb4c8cbb9 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -3782,17 +3782,16 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
>  }
>
>  int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
> -                               u64 fault_address)
> +                               u64 fault_address, char *insn, int insn_len,
> +                               bool need_unprotect)
>  {
>         int r = 1;
>
>         switch (vcpu->arch.apf.host_apf_reason) {
>         default:
> -               /* TDP won't cause page fault directly */
> -               WARN_ON_ONCE(tdp_enabled);
>                 trace_kvm_page_fault(fault_address, error_code);
>
> -               if (kvm_event_needs_reinjection(vcpu))
> +               if (need_unprotect && kvm_event_needs_reinjection(vcpu))
>                         kvm_mmu_unprotect_page_virt(vcpu, fault_address);
>                 r = kvm_mmu_page_fault(vcpu, fault_address, error_code, NULL, 0);
>                 break;
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index 270d9adaa039..d7d248a000dd 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -78,7 +78,8 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly,
>                              bool accessed_dirty);
>  bool kvm_can_do_async_pf(struct kvm_vcpu *vcpu);
>  int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
> -                               u64 fault_address);
> +                               u64 fault_address, char *insn, int insn_len,
> +                               bool need_unprotect);
>
>  static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm)
>  {
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 659b610c4711..fb23497cf915 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -2123,7 +2123,9 @@ static int pf_interception(struct vcpu_svm *svm)
>         u64 fault_address = svm->vmcb->control.exit_info_2;
>         u64 error_code = svm->vmcb->control.exit_info_1;
>
> -       return kvm_handle_page_fault(&svm->vcpu, error_code, fault_address);
> +       return kvm_handle_page_fault(&svm->vcpu, error_code, fault_address,
> +                       svm->vmcb->control.insn_bytes,
> +                       svm->vmcb->control.insn_len, !npt_enabled);
>  }
>
>  static int db_interception(struct vcpu_svm *svm)
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index ab33eace4f66..2e8cfb2f1371 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -5699,7 +5699,10 @@ static int handle_exception(struct kvm_vcpu *vcpu)
>
>         if (is_page_fault(intr_info)) {
>                 cr2 = vmcs_readl(EXIT_QUALIFICATION);
> -               return kvm_handle_page_fault(vcpu, error_code, cr2);
> +               /* TDP won't cause page fault directly */
> +               WARN_ON_ONCE(!vcpu->arch.apf.host_apf_reason && tdp_enabled);
> +               return kvm_handle_page_fault(vcpu, error_code, cr2, NULL, 0,
> +                               true);
>         }
>
>         ex_no = intr_info & INTR_INFO_VECTOR_MASK;

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web