Re: [PATCH kvmtool v3] Add emulation for CFI compatible flash memory

2020-03-18 Thread Will Deacon
On Fri, Feb 21, 2020 at 04:55:32PM +, Andre Przywara wrote:
> From: Raphael Gault 
> 
> The EDK II UEFI firmware implementation requires some storage for the EFI
> variables, which is typically some flash storage.
> Since this is already supported on the EDK II side, we add a CFI flash
> emulation to kvmtool.
> This is backed by a file, specified via the --flash or -F command line
> option. Any flash writes done by the guest will immediately be reflected
> into this file (kvmtool mmap's the file).
> The flash will be limited to the nearest power-of-2 size, so only the
> first 2 MB of a 3 MB file will be used.
> 
> This implements a CFI flash using the "Intel/Sharp extended command
> set", as specified in:
> - JEDEC JESD68.01
> - JEDEC JEP137B
> - Intel Application Note 646
> Some gaps in those specs have been filled by looking at real devices and
> other implementations (QEMU, Linux kernel driver).
> 
> At the moment this relies on DT to advertise the base address of the
> flash memory (mapped into the MMIO address space) and is only enabled
> for ARM/ARM64. The emulation itself is architecture agnostic, though.
> 
> This is one missing piece toward a working UEFI boot with kvmtool on
> ARM guests, the other is to provide writable PCI BARs, which is WIP.
> 
> Signed-off-by: Raphael Gault 
> [Andre: rewriting and fixing]
> Signed-off-by: Andre Przywra 
> ---
> Hi,
> 
> an update fixing Alexandru's review comments (many thanks for those!)
> The biggest change code-wise is the split of the MMIO handler into three
> different functions. Another significant change is the rounding *down* of
> the present flash file size to the nearest power-of-two, to match flash
> hardware chips and Linux' expectations.

Alexandru -- are you happy with this now?

Will
___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


Re: [PATCHv6 0/3] arm64: perf: Add support for ARMv8.5-PMU 64-bit counters

2020-03-18 Thread Mark Rutland
On Tue, Mar 17, 2020 at 11:14:31PM +, Will Deacon wrote:
> On Mon, Mar 02, 2020 at 06:17:49PM +, Mark Rutland wrote:
> > This is a respin of Andrew Murray's series to enable support for 64-bit
> > counters as introduced in ARMv8.5.
> > 
> > I've given this a spin on (ARMv8.2) hardware, to test that there are no
> > regressions, but I have not had the chance to test in an ARMv8.5 model 
> > (which I
> > beleive Andrew had previously tested).
> > 
> > Since v5 [1]:
> > * Don't treat perfmon ID fields as signed
> > * Fix up ID field names
> > * Explicitly compare ARMV8.5 PMU value
> 
> I'm betting on your issue being a model bug, so I've queued this on top of
> Robin's enable/disable rework. Please take a look at for-next/perf [1] in
> case I screwed it up.

>From a cursory review, that all looks good to me.

I'll poke if the issue turns out to be anything beyond a model bug. but
I agree it seems that's all it is.

Thanks,
Mark.

> 
> Thanks,
> 
> Will
> 
> [1] 
> https://git.kernel.org/pub/scm/linux/kernel/git/will/linux.git/log/?h=for-next/perf
___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


Re: [PATCH v5 20/23] KVM: arm64: GICv4.1: Plumb SGI implementation selection in the distributor

2020-03-18 Thread Zenghui Yu

Hi Marc,

On 2020/3/5 4:33, Marc Zyngier wrote:

The GICv4.1 architecture gives the hypervisor the option to let
the guest choose whether it wants the good old SGIs with an
active state, or the new, HW-based ones that do not have one.

For this, plumb the configuration of SGIs into the GICv3 MMIO
handling, present the GICD_TYPER2.nASSGIcap to the guest,
and handle the GICD_CTLR.nASSGIreq setting.

In order to be able to deal with the restore of a guest, also
apply the GICD_CTLR.nASSGIreq setting at first run so that we
can move the restored SGIs to the HW if that's what the guest
had selected in a previous life.


I'm okay with the restore path.  But it seems that we still fail to
save the pending state of vSGI - software pending_latch of HW-based
vSGIs will not be updated (and always be false) because we directly
inject them through ITS, so vgic_v3_uaccess_read_pending() can't
tell the correct pending state to user-space (the correct one should
be latched in HW).

It would be good if we can sync the hardware state into pending_latch
at an appropriate time (just before save), but not sure if we can...



Signed-off-by: Marc Zyngier 
---
  virt/kvm/arm/vgic/vgic-mmio-v3.c | 48 ++--
  virt/kvm/arm/vgic/vgic-v3.c  |  2 ++
  2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c
index de89da76a379..442f3b8c2559 100644
--- a/virt/kvm/arm/vgic/vgic-mmio-v3.c
+++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c
@@ -3,6 +3,7 @@
   * VGICv3 MMIO handling functions
   */
  
+#include 

  #include 
  #include 
  #include 
@@ -70,6 +71,8 @@ static unsigned long vgic_mmio_read_v3_misc(struct kvm_vcpu 
*vcpu,
if (vgic->enabled)
value |= GICD_CTLR_ENABLE_SS_G1;
value |= GICD_CTLR_ARE_NS | GICD_CTLR_DS;
+   if (kvm_vgic_global_state.has_gicv4_1 && vgic->nassgireq)


Looking at how we handle the GICD_CTLR.nASSGIreq setting, I think
"nassgireq==true" already indicates "has_gicv4_1==true".  So this
can be simplified.

But I wonder that should we use nassgireq to *only* keep track what
the guest had written into the GICD_CTLR.nASSGIreq.  If not, we may
lose the guest-request bit after migration among hosts with different
has_gicv4_1 settings.


The remaining patches all look good to me :-). I will wait for you to
confirm these two concerns.


Thanks,
Zenghui


+   value |= GICD_CTLR_nASSGIreq;
break;
case GICD_TYPER:
value = vgic->nr_spis + VGIC_NR_PRIVATE_IRQS;
@@ -81,6 +84,10 @@ static unsigned long vgic_mmio_read_v3_misc(struct kvm_vcpu 
*vcpu,
value |= (INTERRUPT_ID_BITS_SPIS - 1) << 19;
}
break;
+   case GICD_TYPER2:
+   if (kvm_vgic_global_state.has_gicv4_1)
+   value = GICD_TYPER2_nASSGIcap;
+   break;
case GICD_IIDR:
value = (PRODUCT_ID_KVM << GICD_IIDR_PRODUCT_ID_SHIFT) |
(vgic->implementation_rev << GICD_IIDR_REVISION_SHIFT) |
@@ -98,17 +105,43 @@ static void vgic_mmio_write_v3_misc(struct kvm_vcpu *vcpu,
unsigned long val)
  {
struct vgic_dist *dist = >kvm->arch.vgic;
-   bool was_enabled = dist->enabled;
  
  	switch (addr & 0x0c) {

-   case GICD_CTLR:
+   case GICD_CTLR: {
+   bool was_enabled, is_hwsgi;
+
+   mutex_lock(>kvm->lock);
+
+   was_enabled = dist->enabled;
+   is_hwsgi = dist->nassgireq;
+
dist->enabled = val & GICD_CTLR_ENABLE_SS_G1;
  
+		/* Not a GICv4.1? No HW SGIs */

+   if (!kvm_vgic_global_state.has_gicv4_1)
+   val &= ~GICD_CTLR_nASSGIreq;
+
+   /* Dist stays enabled? nASSGIreq is RO */
+   if (was_enabled && dist->enabled) {
+   val &= ~GICD_CTLR_nASSGIreq;
+   val |= FIELD_PREP(GICD_CTLR_nASSGIreq, is_hwsgi);
+   }
+
+   /* Switching HW SGIs? */
+   dist->nassgireq = val & GICD_CTLR_nASSGIreq;
+   if (is_hwsgi != dist->nassgireq)
+   vgic_v4_configure_vsgis(vcpu->kvm);
+
if (!was_enabled && dist->enabled)
vgic_kick_vcpus(vcpu->kvm);
+
+   mutex_unlock(>kvm->lock);
break;
+   }
case GICD_TYPER:
+   case GICD_TYPER2:
case GICD_IIDR:
+   /* This is at best for documentation purposes... */
return;
}
  }
@@ -117,10 +150,21 @@ static int vgic_mmio_uaccess_write_v3_misc(struct 
kvm_vcpu *vcpu,
   gpa_t addr, unsigned int len,
   unsigned long val)
  {
+   struct vgic_dist *dist = >kvm->arch.vgic;
+
switch (addr & 0x0c) {