All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: fix DR6 delivery for emulated hardware breakpoint
@ 2020-05-05 11:34 Paolo Bonzini
  2020-05-05 14:15 ` Peter Xu
  2020-05-06  0:33   ` kbuild test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-05-05 11:34 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: jmattson, peterx

Go through kvm_queue_exception_p so that the payload is correctly delivered
through the exit qualification, and add a kvm_update_dr6 call to
kvm_deliver_exception_payload that is needed on AMD.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/x86.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c5835f9cb9ad..8f61cb15f147 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -473,6 +473,7 @@ void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu)
 		 * breakpoint), it is reserved and must be zero in DR6.
 		 */
 		vcpu->arch.dr6 &= ~BIT(12);
+		kvm_update_dr6(vcpu);
 		break;
 	case PF_VECTOR:
 		vcpu->arch.cr2 = payload;
@@ -6731,9 +6732,7 @@ static bool kvm_vcpu_check_breakpoint(struct kvm_vcpu *vcpu, int *r)
 					   vcpu->arch.db);
 
 		if (dr6 != 0) {
-			vcpu->arch.dr6 &= ~DR_TRAP_BITS;
-			vcpu->arch.dr6 |= dr6 | DR6_RTM;
-			kvm_queue_exception(vcpu, DB_VECTOR);
+			kvm_queue_exception_p(vcpu, DB_VECTOR, dr6);
 			*r = 1;
 			return true;
 		}
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: x86: fix DR6 delivery for emulated hardware breakpoint
  2020-05-05 11:34 [PATCH] KVM: x86: fix DR6 delivery for emulated hardware breakpoint Paolo Bonzini
@ 2020-05-05 14:15 ` Peter Xu
  2020-05-06  0:33   ` kbuild test robot
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Xu @ 2020-05-05 14:15 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm, jmattson

On Tue, May 05, 2020 at 07:34:49AM -0400, Paolo Bonzini wrote:
> Go through kvm_queue_exception_p so that the payload is correctly delivered
> through the exit qualification, and add a kvm_update_dr6 call to
> kvm_deliver_exception_payload that is needed on AMD.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

I still think we could also change this in handle_exception_nmi() and
handle_dr() as mentioned in the other thread, but no strong opinion:

Reviewed-by: Peter Xu <peterx@redhat.com>

Thanks,

-- 
Peter Xu


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: x86: fix DR6 delivery for emulated hardware breakpoint
  2020-05-05 11:34 [PATCH] KVM: x86: fix DR6 delivery for emulated hardware breakpoint Paolo Bonzini
@ 2020-05-06  0:33   ` kbuild test robot
  2020-05-06  0:33   ` kbuild test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2020-05-06  0:33 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm, jmattson, peterx; +Cc: kbuild-all, jmattson

[-- Attachment #1: Type: text/plain, Size: 3791 bytes --]

Hi Paolo,

I love your patch! Yet something to improve:

[auto build test ERROR on kvm/linux-next]
[also build test ERROR on tip/auto-latest linus/master v5.7-rc4 next-20200505]
[cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Paolo-Bonzini/KVM-x86-fix-DR6-delivery-for-emulated-hardware-breakpoint/20200506-043817
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   arch/x86/kvm/x86.c: In function 'kvm_deliver_exception_payload':
>> arch/x86/kvm/x86.c:472:3: error: implicit declaration of function 'kvm_update_dr6'; did you mean 'kvm_update_cpuid'? [-Werror=implicit-function-declaration]
      kvm_update_dr6(vcpu);
      ^~~~~~~~~~~~~~
      kvm_update_cpuid
   arch/x86/kvm/x86.c: At top level:
>> arch/x86/kvm/x86.c:1071:13: warning: conflicting types for 'kvm_update_dr6'
    static void kvm_update_dr6(struct kvm_vcpu *vcpu)
                ^~~~~~~~~~~~~~
>> arch/x86/kvm/x86.c:1071:13: error: static declaration of 'kvm_update_dr6' follows non-static declaration
   arch/x86/kvm/x86.c:472:3: note: previous implicit declaration of 'kvm_update_dr6' was here
      kvm_update_dr6(vcpu);
      ^~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +472 arch/x86/kvm/x86.c

   432	
   433	void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu)
   434	{
   435		unsigned nr = vcpu->arch.exception.nr;
   436		bool has_payload = vcpu->arch.exception.has_payload;
   437		unsigned long payload = vcpu->arch.exception.payload;
   438	
   439		if (!has_payload)
   440			return;
   441	
   442		switch (nr) {
   443		case DB_VECTOR:
   444			/*
   445			 * "Certain debug exceptions may clear bit 0-3.  The
   446			 * remaining contents of the DR6 register are never
   447			 * cleared by the processor".
   448			 */
   449			vcpu->arch.dr6 &= ~DR_TRAP_BITS;
   450			/*
   451			 * DR6.RTM is set by all #DB exceptions that don't clear it.
   452			 */
   453			vcpu->arch.dr6 |= DR6_RTM;
   454			vcpu->arch.dr6 |= payload;
   455			/*
   456			 * Bit 16 should be set in the payload whenever the #DB
   457			 * exception should clear DR6.RTM. This makes the payload
   458			 * compatible with the pending debug exceptions under VMX.
   459			 * Though not currently documented in the SDM, this also
   460			 * makes the payload compatible with the exit qualification
   461			 * for #DB exceptions under VMX.
   462			 */
   463			vcpu->arch.dr6 ^= payload & DR6_RTM;
   464	
   465			/*
   466			 * The #DB payload is defined as compatible with the 'pending
   467			 * debug exceptions' field under VMX, not DR6. While bit 12 is
   468			 * defined in the 'pending debug exceptions' field (enabled
   469			 * breakpoint), it is reserved and must be zero in DR6.
   470			 */
   471			vcpu->arch.dr6 &= ~BIT(12);
 > 472			kvm_update_dr6(vcpu);
   473			break;
   474		case PF_VECTOR:
   475			vcpu->arch.cr2 = payload;
   476			break;
   477		}
   478	
   479		vcpu->arch.exception.has_payload = false;
   480		vcpu->arch.exception.payload = 0;
   481	}
   482	EXPORT_SYMBOL_GPL(kvm_deliver_exception_payload);
   483	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 71662 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: x86: fix DR6 delivery for emulated hardware breakpoint
@ 2020-05-06  0:33   ` kbuild test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2020-05-06  0:33 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3890 bytes --]

Hi Paolo,

I love your patch! Yet something to improve:

[auto build test ERROR on kvm/linux-next]
[also build test ERROR on tip/auto-latest linus/master v5.7-rc4 next-20200505]
[cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Paolo-Bonzini/KVM-x86-fix-DR6-delivery-for-emulated-hardware-breakpoint/20200506-043817
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   arch/x86/kvm/x86.c: In function 'kvm_deliver_exception_payload':
>> arch/x86/kvm/x86.c:472:3: error: implicit declaration of function 'kvm_update_dr6'; did you mean 'kvm_update_cpuid'? [-Werror=implicit-function-declaration]
      kvm_update_dr6(vcpu);
      ^~~~~~~~~~~~~~
      kvm_update_cpuid
   arch/x86/kvm/x86.c: At top level:
>> arch/x86/kvm/x86.c:1071:13: warning: conflicting types for 'kvm_update_dr6'
    static void kvm_update_dr6(struct kvm_vcpu *vcpu)
                ^~~~~~~~~~~~~~
>> arch/x86/kvm/x86.c:1071:13: error: static declaration of 'kvm_update_dr6' follows non-static declaration
   arch/x86/kvm/x86.c:472:3: note: previous implicit declaration of 'kvm_update_dr6' was here
      kvm_update_dr6(vcpu);
      ^~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +472 arch/x86/kvm/x86.c

   432	
   433	void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu)
   434	{
   435		unsigned nr = vcpu->arch.exception.nr;
   436		bool has_payload = vcpu->arch.exception.has_payload;
   437		unsigned long payload = vcpu->arch.exception.payload;
   438	
   439		if (!has_payload)
   440			return;
   441	
   442		switch (nr) {
   443		case DB_VECTOR:
   444			/*
   445			 * "Certain debug exceptions may clear bit 0-3.  The
   446			 * remaining contents of the DR6 register are never
   447			 * cleared by the processor".
   448			 */
   449			vcpu->arch.dr6 &= ~DR_TRAP_BITS;
   450			/*
   451			 * DR6.RTM is set by all #DB exceptions that don't clear it.
   452			 */
   453			vcpu->arch.dr6 |= DR6_RTM;
   454			vcpu->arch.dr6 |= payload;
   455			/*
   456			 * Bit 16 should be set in the payload whenever the #DB
   457			 * exception should clear DR6.RTM. This makes the payload
   458			 * compatible with the pending debug exceptions under VMX.
   459			 * Though not currently documented in the SDM, this also
   460			 * makes the payload compatible with the exit qualification
   461			 * for #DB exceptions under VMX.
   462			 */
   463			vcpu->arch.dr6 ^= payload & DR6_RTM;
   464	
   465			/*
   466			 * The #DB payload is defined as compatible with the 'pending
   467			 * debug exceptions' field under VMX, not DR6. While bit 12 is
   468			 * defined in the 'pending debug exceptions' field (enabled
   469			 * breakpoint), it is reserved and must be zero in DR6.
   470			 */
   471			vcpu->arch.dr6 &= ~BIT(12);
 > 472			kvm_update_dr6(vcpu);
   473			break;
   474		case PF_VECTOR:
   475			vcpu->arch.cr2 = payload;
   476			break;
   477		}
   478	
   479		vcpu->arch.exception.has_payload = false;
   480		vcpu->arch.exception.payload = 0;
   481	}
   482	EXPORT_SYMBOL_GPL(kvm_deliver_exception_payload);
   483	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 71662 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-06  1:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 11:34 [PATCH] KVM: x86: fix DR6 delivery for emulated hardware breakpoint Paolo Bonzini
2020-05-05 14:15 ` Peter Xu
2020-05-06  0:33 ` kbuild test robot
2020-05-06  0:33   ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.