linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH RESEND v4 2/2] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
@ 2018-06-17  2:37 gengdongjiu
  0 siblings, 0 replies; 15+ messages in thread
From: gengdongjiu @ 2018-06-17  2:37 UTC (permalink / raw)
  To: James Morse
  Cc: rkrcmar, corbet, christoffer.dall, marc.zyngier, linux,
	catalin.marinas, will.deacon, kvm, linux-doc, linux-arm-kernel,
	linux-kernel, linux-acpi

> 
> > >>>>> --- a/arch/arm/include/uapi/asm/kvm.h
> > >>>>> +++ b/arch/arm/include/uapi/asm/kvm.h
> > >>>>> @@ -124,6 +124,18 @@ struct kvm_sync_regs {  struct
> > >>>>> kvm_arch_memory_slot {  };
> > >>>>>
> > >>>>> +/* for KVM_GET/SET_VCPU_EVENTS */ struct kvm_vcpu_events {
> > >>>>> +	struct {
> > >>>>> +		__u8 serror_pending;
> > >>>>> +		__u8 serror_has_esr;
> > >>>>> +		/* Align it to 8 bytes */
> > >>>>> +		__u8 pad[6];
> > >>>>> +		__u64 serror_esr;
> > >>>>> +	} exception;
> > >>>>> +	__u32 reserved[12];
> > >>>>> +};
> > >>>>> +
> > >>>>
> > >>>> You haven't defined __KVM_HAVE_VCPU_EVENTS for 32bit, so
> > >>>> presumably this struct will never be used. Why is it here?
> > >>
> > >>>   if not add it for 32 bits. the 32 arm platform will build Fail, whether you have good
> > >>>    idea to avoid this Failure if not add this struct for the 32 bit?
> > >>
> > >> How does this 32bit code build without this patch?
> > >> If do you provide the struct, how will that code build with older headers?
> > >>
> > >> As far as I can see, this is what the __KVM_HAVE_VCPU_EVENTS define is for.
> > >>
> > >> This should be both, or neither. Having just the struct is useless.
> > > It because the caller of kvm_arm_vcpu_get/set_events() is in "virt/kvm/arm/arm.c".
> > > the virt/kvm/arm/arm.c will used by both arm64 and arm.
> > > so It needs to add kvm_arm_vcpu_get/set_events() for the 32 bits,
> > > however, kvm_arm_vcpu_get/set_events() will directly return,
> >
> > So you are adding a uapi struct that user-space can't actually use, to avoid a kernel build-error. Fine, it just looks really strange.
> >
> > 32bit user-space shouldn't try to call this as check-extension reports
> > it as not present. If it does, it gets -EINVAL back, which is also the default for kvm_arch_vcpu_ioctl().

Just think out a method to avoid adding the structure for the arm32.

Using below methods:

#Ifdef __KVM_HAVE_VCPU_EVENTS
	xxxxxxxxxxxxxxxxxxxxx
#else
	Xxxxxxxxxxxxxxxx
#endif

> 
> It indeed looks strange. Because "virt/kvm/arm/arm.c" is shared by arm64 and arm32, if not adding, it will build-error. Do you have a better
> idea to avoid adding in arm32?
> I still not think out a good method. 32 user-space will not call this KVM_GET/SET_VCPU_EVENTS IOCTL as check-extension reports it as not
> present.
> 
> >
> >
> > Thanks,
> >
> > James

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH RESEND v4 2/2] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
@ 2018-06-18  8:24 gengdongjiu
  0 siblings, 0 replies; 15+ messages in thread
From: gengdongjiu @ 2018-06-18  8:24 UTC (permalink / raw)
  To: James Morse
  Cc: rkrcmar, corbet, christoffer.dall, marc.zyngier, linux,
	catalin.marinas, will.deacon, kvm, linux-doc, linux-arm-kernel,
	linux-kernel, linux-acpi

> On 12/06/18 15:50, gengdongjiu wrote:
> > On 2018/6/11 21:36, James Morse wrote:
> >> On 08/06/18 20:48, Dongjiu Geng wrote:
> >>> For the migrating VMs, user space may need to know the exception
> >>> state. For example, in the machine A, KVM make an SError pending,
> >>> when migrate to B, KVM also needs to pend an SError.
> >>>
> >>> This new IOCTL exports user-invisible states related to SError.
> >>> Together with appropriate user space changes, user space can get/set
> >>> the SError exception state to do migrate/snapshot/suspend.
> 
> 
> >>> diff --git a/arch/arm/include/uapi/asm/kvm.h
> >>> b/arch/arm/include/uapi/asm/kvm.h index caae484..c3e6975 100644
> >>> --- a/arch/arm/include/uapi/asm/kvm.h
> >>> +++ b/arch/arm/include/uapi/asm/kvm.h
> >>> @@ -124,6 +124,18 @@ struct kvm_sync_regs {  struct
> >>> kvm_arch_memory_slot {  };
> >>>
> >>> +/* for KVM_GET/SET_VCPU_EVENTS */
> >>> +struct kvm_vcpu_events {
> >>> +	struct {
> >>> +		__u8 serror_pending;
> >>> +		__u8 serror_has_esr;
> >>> +		/* Align it to 8 bytes */
> >>> +		__u8 pad[6];
> >>> +		__u64 serror_esr;
> >>> +	} exception;
> >>> +	__u32 reserved[12];
> >>> +};
> >>> +
> >>
> >> You haven't defined __KVM_HAVE_VCPU_EVENTS for 32bit, so presumably
> >> this struct will never be used. Why is it here?
> 
> >   if not add it for 32 bits. the 32 arm platform will build Fail, whether you have good
> >    idea to avoid this Failure if not add this struct for the 32 bit?
> 
> How does this 32bit code build without this patch?
> If do you provide the struct, how will that code build with older headers?
> 
> As far as I can see, this is what the __KVM_HAVE_VCPU_EVENTS define is for.
> 
> This should be both, or neither. Having just the struct is useless.
> 
> 
> >>> +int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
> >>> +			struct kvm_vcpu_events *events)
> >>> +{
> >>> +	bool serror_pending = events->exception.serror_pending;
> >>> +	bool has_esr = events->exception.serror_has_esr;
> >>> +
> >>> +	if (serror_pending && has_esr) {
> >>> +		if (!cpus_have_const_cap(ARM64_HAS_RAS_EXTN))
> >>> +			return -EINVAL;
> >>> +
> >>> +		kvm_set_sei_esr(vcpu, events->exception.serror_esr);
> >>
> >> kvm_set_sei_esr() will silently discard the top 40 bits of
> >> serror_esr, (which is correct, we shouldn't copy them into hardware without know what they do).
> >>
> >> Could we please force user-space to zero these bits, we can advertise
> >> extra CAPs if new features turn up in that space, instead of
> >> user-space passing <something> and relying on the kernel to remove it.
> >
> >   yes, I can zero these bits in the  user-space and not depend on kernel to remove it.
> 
> But the kernel must check that user-space did zero those bits. Otherwise user-space may start using them when a future version of the

For this comments, how about add below kernel check that user-space did zero those bits? Thanks.

+               if (!((events->exception.serror_esr) & ~ESR_ELx_ISS_MASK))
+                       kvm_set_sei_esr(vcpu, events->exception.serror_esr);
+               else
+                       return -EINVAL;


> architecture gives them a meaning, but an older kernel version doesn't know it has to do extra work, but still lets the bits from user-space
> through into the hardware.
> 
> If new bits do turn up, we can advertise a CAP that says that KVM supports whatever that feature is.
> 
> 
> >> (Background: VSESR is a 64bit register that holds the value to go in
> >> a 32bit register. I suspect the top-half could get re-used for
> >> control values or something we don't want to give user-space)
> 
> >   do you mean when user-space get the VSESR value through
> > KVM_GET_VCPU_EVENTS it only return the low-half 32 bits?
> 
> No, the kernel will only ever set a 24bit value here. If we force user-space to only provide a 24bit value then we don't need to check it on
> read. We never read the value back from hardware.
> 
> These high bits are RES0 at the moment, they may get used for something in the future. As we are exposing this via a user-space ABI we
> need to make sure we only expose the bits we understand today.

Ok

> 
> 
> Thanks,
> 
> James

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH RESEND v4 2/2] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS
@ 2018-06-17  1:30 gengdongjiu
  0 siblings, 0 replies; 15+ messages in thread
From: gengdongjiu @ 2018-06-17  1:30 UTC (permalink / raw)
  To: James Morse
  Cc: rkrcmar, corbet, christoffer.dall, marc.zyngier, linux,
	catalin.marinas, will.deacon, kvm, linux-doc, linux-arm-kernel,
	linux-kernel, linux-acpi

> >>>>> --- a/arch/arm/include/uapi/asm/kvm.h
> >>>>> +++ b/arch/arm/include/uapi/asm/kvm.h
> >>>>> @@ -124,6 +124,18 @@ struct kvm_sync_regs {  struct
> >>>>> kvm_arch_memory_slot {  };
> >>>>>
> >>>>> +/* for KVM_GET/SET_VCPU_EVENTS */ struct kvm_vcpu_events {
> >>>>> +	struct {
> >>>>> +		__u8 serror_pending;
> >>>>> +		__u8 serror_has_esr;
> >>>>> +		/* Align it to 8 bytes */
> >>>>> +		__u8 pad[6];
> >>>>> +		__u64 serror_esr;
> >>>>> +	} exception;
> >>>>> +	__u32 reserved[12];
> >>>>> +};
> >>>>> +
> >>>>
> >>>> You haven't defined __KVM_HAVE_VCPU_EVENTS for 32bit, so presumably
> >>>> this struct will never be used. Why is it here?
> >>
> >>>   if not add it for 32 bits. the 32 arm platform will build Fail, whether you have good
> >>>    idea to avoid this Failure if not add this struct for the 32 bit?
> >>
> >> How does this 32bit code build without this patch?
> >> If do you provide the struct, how will that code build with older headers?
> >>
> >> As far as I can see, this is what the __KVM_HAVE_VCPU_EVENTS define is for.
> >>
> >> This should be both, or neither. Having just the struct is useless.
> > It because the caller of kvm_arm_vcpu_get/set_events() is in "virt/kvm/arm/arm.c".
> > the virt/kvm/arm/arm.c will used by both arm64 and arm.
> > so It needs to add kvm_arm_vcpu_get/set_events() for the 32 bits,
> > however, kvm_arm_vcpu_get/set_events() will directly return,
> 
> So you are adding a uapi struct that user-space can't actually use, to avoid a kernel build-error. Fine, it just looks really strange.
> 
> 32bit user-space shouldn't try to call this as check-extension reports it as not present. If it does, it gets -EINVAL back, which is also the
> default for kvm_arch_vcpu_ioctl().

It indeed looks strange. Because "virt/kvm/arm/arm.c" is shared by arm64 and arm32, if not adding, it will build-error. Do you have a better idea to avoid adding in arm32? 
I still not think out a good method. 32 user-space will not call this KVM_GET/SET_VCPU_EVENTS IOCTL as check-extension reports it as not present.

> 
> 
> Thanks,
> 
> James

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH RESEND v4 0/2] support exception state migration and set VSESR_EL2 by user space
@ 2018-06-08 19:48 Dongjiu Geng
  2018-06-08 19:48 ` [PATCH RESEND v4 2/2] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS Dongjiu Geng
  0 siblings, 1 reply; 15+ messages in thread
From: Dongjiu Geng @ 2018-06-08 19:48 UTC (permalink / raw)
  To: rkrcmar, corbet, christoffer.dall, marc.zyngier, linux,
	catalin.marinas, will.deacon, kvm, linux-doc, james.morse,
	gengdongjiu, linux-arm-kernel, linux-kernel, linux-acpi

This series patch is separated from https://www.spinics.net/lists/kvm/msg168917.html

1. Detect whether KVM can set set guest SError syndrome
2. Support to Set VSESR_EL2 and inject SError by user space.
3. Support live migration to keep SError pending state and VSESR_EL2 value

The user space patch is here: https://www.mail-archive.com/qemu-devel@nongnu.org/msg539534.html

Dongjiu Geng (2):
  arm64: KVM: export the capability to set guest SError syndrome
  arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS

 Documentation/virtual/kvm/api.txt    | 42 +++++++++++++++++++++++++++++++++---
 arch/arm/include/asm/kvm_host.h      |  6 ++++++
 arch/arm/include/uapi/asm/kvm.h      | 12 +++++++++++
 arch/arm/kvm/guest.c                 | 12 +++++++++++
 arch/arm64/include/asm/kvm_emulate.h |  5 +++++
 arch/arm64/include/asm/kvm_host.h    |  7 ++++++
 arch/arm64/include/uapi/asm/kvm.h    | 13 +++++++++++
 arch/arm64/kvm/guest.c               | 36 +++++++++++++++++++++++++++++++
 arch/arm64/kvm/inject_fault.c        |  6 +++---
 arch/arm64/kvm/reset.c               |  4 ++++
 include/uapi/linux/kvm.h             |  1 +
 virt/kvm/arm/arm.c                   | 19 ++++++++++++++++
 12 files changed, 157 insertions(+), 6 deletions(-)

-- 
2.7.4

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

end of thread, other threads:[~2018-06-18  8:25 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-17  2:37 [PATCH RESEND v4 2/2] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS gengdongjiu
  -- strict thread matches above, loose matches on Subject: below --
2018-06-18  8:24 gengdongjiu
2018-06-17  1:30 gengdongjiu
2018-06-08 19:48 [PATCH RESEND v4 0/2] support exception state migration and set VSESR_EL2 by user space Dongjiu Geng
2018-06-08 19:48 ` [PATCH RESEND v4 2/2] arm/arm64: KVM: Add KVM_GET/SET_VCPU_EVENTS Dongjiu Geng
2018-06-09 11:17   ` Christoffer Dall
2018-06-12 12:42     ` gengdongjiu
2018-06-09 12:40   ` Marc Zyngier
2018-06-11 13:36     ` James Morse
2018-06-12 14:53       ` gengdongjiu
2018-06-12 13:06     ` gengdongjiu
2018-06-11 13:36   ` James Morse
2018-06-12 14:50     ` gengdongjiu
2018-06-12 15:29       ` James Morse
2018-06-12 15:48         ` gengdongjiu
2018-06-15 15:57           ` James Morse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).