[PATCH] arch: mips: kvm: Enable after disabling interrupt

2015-02-22 Thread Tapasweni Pathak
Enable disabled interrupt, on unsuccessful operation.

Found by Coccinelle.

Signed-off-by: Tapasweni Pathak 
Acked-by: Julia Lawall 
---
 arch/mips/kvm/tlb.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/kvm/tlb.c b/arch/mips/kvm/tlb.c
index bbcd822..b6beb0e 100644
--- a/arch/mips/kvm/tlb.c
+++ b/arch/mips/kvm/tlb.c
@@ -216,6 +216,7 @@ int kvm_mips_host_tlb_write(struct kvm_vcpu *vcpu, unsigned 
long entryhi,
if (idx > current_cpu_data.tlbsize) {
kvm_err("%s: Invalid Index: %d\n", __func__, idx);
kvm_mips_dump_host_tlbs();
+   local_irq_restore(flags);
return -1;
}

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [nVMX] With 3.20.0-0.rc0.git5.1 on L0, booting L2 guest results in L1 *rebooting*

2015-02-22 Thread Kashyap Chamarthy
Radim,

I just tested with your patch[1] in this thread. I built a Fedora
Kernel[2] with it, and installed (and booted into) it on both L0 and L1. 

Result: I don't have good news, I'm afraid: L1 *still* reboots when an
L2 guest is booted. And, L0 throws the stack trace that was
previously noted on this thread:

. . .
[<   57.747345>] [ cut here ]
[<0.004638>] WARNING: CPU: 5 PID: 50206 at arch/x86/kvm/vmx.c:8962 
nested_vmx_vmexit+0x7ee/0x880 [kvm_intel]()
[<0.009903>] Modules linked in: vhost_net vhost macvtap macvlan xt_CHECKSUM 
iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 
nf_nat nf_conntrack_ipv4 nf_defra
g_ipv4 xt_conntrack nf_conntrack tun bridge stp llc ebtable_filter ebtables 
ip6table_filter ip6_tables kvm_intel coretemp iTCO_wdt kvm ipmi_devintf 
iTCO_vendor_support i7core_edac gpio_ich c
rc32c_intel serio_raw edac_core ipmi_si dcdbas shpchp tpm_tis lpc_ich mfd_core 
tpm ipmi_msghandler wmi acpi_power_meter acpi_cpufreq nfsd auth_rpcgss nfs_acl 
lockd grace sunrpc mgag200 i2c_algo_bit drm_kms_helper ttm drm ata_generic 
megaraid_sas bnx2 pata_acpi [last unloaded: kvm_intel]
[<0.060404>] CPU: 5 PID: 50206 Comm: qemu-system-x86 Not tainted 
3.18.7-200.fc21.x86_64 #1
[  +0.008220] Hardware name: Dell Inc. PowerEdge R910/0P658H, BIOS 2.8.2 
10/25/2012
[  +0.007526]   a30d0ba3 883f2489fc48 
8175e686
[  +0.007688]    883f2489fc88 
810991d1
[  +0.007613]  883f2489fc98 88bece1ba000  
0014
[  +0.007611] Call Trace:
[  +0.002518]  [] dump_stack+0x46/0x58
[  +0.005202]  [] warn_slowpath_common+0x81/0xa0
[  +0.006055]  [] warn_slowpath_null+0x1a/0x20
[  +0.005889]  [] nested_vmx_vmexit+0x7ee/0x880 [kvm_intel]
[  +0.007014]  [] ? vmx_handle_exit+0x1bf/0xaa0 [kvm_intel]
[  +0.007015]  [] vmx_queue_exception+0xfc/0x150 [kvm_intel]
[  +0.007130]  [] kvm_arch_vcpu_ioctl_run+0xd9d/0x1290 [kvm]
[  +0.007111]  [] ? kvm_arch_vcpu_load+0x58/0x220 [kvm]
[  +0.006670]  [] kvm_vcpu_ioctl+0x32c/0x5c0 [kvm]
[  +0.006236]  [] ? put_prev_entity+0x5b/0x400
[  +0.005887]  [] ? set_next_entity+0x67/0x80
[  +0.005802]  [] ? pick_next_task_fair+0x6c9/0x8c0
[  +0.006324]  [] ? __switch_to+0x1d6/0x5f0
[  +0.005626]  [] do_vfs_ioctl+0x2d0/0x4b0
[  +0.005543]  [] ? __schedule+0x2f4/0x8a0
[  +0.005537]  [] SyS_ioctl+0x81/0xa0
[  +0.005106]  [] system_call_fastpath+0x12/0x17
[  +0.006056] ---[ end trace 646ed2360b84865c ]---
[  +7.000298] kvm [50179]: vcpu0 unhandled rdmsr: 0x1c9
[  +0.005061] kvm [50179]: vcpu0 unhandled rdmsr: 0x1a6
[  +0.005053] kvm [50179]: vcpu0 unhandled rdmsr: 0x3f6
. . .



  [1] http://article.gmane.org/gmane.comp.emulators.kvm.devel/132937
  [2] http://koji.fedoraproject.org/koji/taskinfo?taskID=9004708

-- 
/kashyap
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] KVM: PPC: BOOK3S: HV: remove rma related variables from code.

2015-02-22 Thread Aneesh Kumar K.V
We don't support real-mode areas now that 970 support is removed.
Remove the remaining details of rma from the code. Also rename
rma_setup_done to hpte_setup_done to better reflect the changes.

Signed-off-by: Aneesh Kumar K.V 
---
 arch/powerpc/include/asm/kvm_host.h |  3 +--
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 28 ++--
 arch/powerpc/kvm/book3s_hv.c| 10 +-
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 7efd666a3fa7..833486a5734a 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -227,9 +227,8 @@ struct kvm_arch {
int tlbie_lock;
unsigned long lpcr;
unsigned long rmor;
-   struct kvm_rma_info *rma;
unsigned long vrma_slb_v;
-   int rma_setup_done;
+   int hpte_setup_done;
u32 hpt_order;
atomic_t vcpus_running;
u32 online_vcores;
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 534acb3c6c3d..dbf127168ca4 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -116,12 +116,12 @@ long kvmppc_alloc_reset_hpt(struct kvm *kvm, u32 
*htab_orderp)
long order;
 
mutex_lock(&kvm->lock);
-   if (kvm->arch.rma_setup_done) {
-   kvm->arch.rma_setup_done = 0;
-   /* order rma_setup_done vs. vcpus_running */
+   if (kvm->arch.hpte_setup_done) {
+   kvm->arch.hpte_setup_done = 0;
+   /* order hpte_setup_done vs. vcpus_running */
smp_mb();
if (atomic_read(&kvm->arch.vcpus_running)) {
-   kvm->arch.rma_setup_done = 1;
+   kvm->arch.hpte_setup_done = 1;
goto out;
}
}
@@ -1339,20 +1339,20 @@ static ssize_t kvm_htab_write(struct file *file, const 
char __user *buf,
unsigned long tmp[2];
ssize_t nb;
long int err, ret;
-   int rma_setup;
+   int hpte_setup;
 
if (!access_ok(VERIFY_READ, buf, count))
return -EFAULT;
 
/* lock out vcpus from running while we're doing this */
mutex_lock(&kvm->lock);
-   rma_setup = kvm->arch.rma_setup_done;
-   if (rma_setup) {
-   kvm->arch.rma_setup_done = 0;   /* temporarily */
-   /* order rma_setup_done vs. vcpus_running */
+   hpte_setup = kvm->arch.hpte_setup_done;
+   if (hpte_setup) {
+   kvm->arch.hpte_setup_done = 0;  /* temporarily */
+   /* order hpte_setup_done vs. vcpus_running */
smp_mb();
if (atomic_read(&kvm->arch.vcpus_running)) {
-   kvm->arch.rma_setup_done = 1;
+   kvm->arch.hpte_setup_done = 1;
mutex_unlock(&kvm->lock);
return -EBUSY;
}
@@ -1405,7 +1405,7 @@ static ssize_t kvm_htab_write(struct file *file, const 
char __user *buf,
   "r=%lx\n", ret, i, v, r);
goto out;
}
-   if (!rma_setup && is_vrma_hpte(v)) {
+   if (!hpte_setup && is_vrma_hpte(v)) {
unsigned long psize = hpte_base_page_size(v, r);
unsigned long senc = slb_pgsize_encoding(psize);
unsigned long lpcr;
@@ -1414,7 +1414,7 @@ static ssize_t kvm_htab_write(struct file *file, const 
char __user *buf,
(VRMA_VSID << SLB_VSID_SHIFT_1T);
lpcr = senc << (LPCR_VRMASD_SH - 4);
kvmppc_update_lpcr(kvm, lpcr, LPCR_VRMASD);
-   rma_setup = 1;
+   hpte_setup = 1;
}
++i;
hptp += 2;
@@ -1430,9 +1430,9 @@ static ssize_t kvm_htab_write(struct file *file, const 
char __user *buf,
}
 
  out:
-   /* Order HPTE updates vs. rma_setup_done */
+   /* Order HPTE updates vs. hpte_setup_done */
smp_wmb();
-   kvm->arch.rma_setup_done = rma_setup;
+   kvm->arch.hpte_setup_done = hpte_setup;
mutex_unlock(&kvm->lock);
 
if (err)
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index de4018a1bc4b..34e79b8e855c 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2032,11 +2032,11 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, 
struct kvm_vcpu *vcpu)
}
 
atomic_inc(&vcpu->kvm->arch.vcpus_running);
-   /* Order vcpus_running vs. rma_setup_done, see kvmppc_alloc_reset_hpt */
+   /* Order vcpus_running vs. hpte_setup_done, see kvmppc_alloc_reset_hpt 
*/
smp_mb();
 
/* 

Re: [PATCH 0/3] vhost_net: support for cross endian guests

2015-02-22 Thread Michael S. Tsirkin
On Fri, Feb 20, 2015 at 11:07:24AM +0100, Greg Kurz wrote:
> Hi,
> 
> This patchset allows vhost_net to be used with legacy virtio
> when guest and host have a different endianness. It is based
> on previous work by Cédric Le Goater:
> 
> https://www.mail-archive.com/kvm-ppc@vger.kernel.org/msg09848.html
> 
> As suggested by MST:
> - the API now asks for a specific format (big endian) instead of the hint
>   whether byteswap is needed or not (patch 1)
> - rebased on top of the virtio-1 accessors (patch 2)
> 
> Patch 3 is a separate fix: I think it is also valid for virtio-1.

I don't think so. See e.g. this code in tun:
gso.csum_offset = cpu_to_tun16(tun, skb->csum_offset);
looks like it has the correct endian-ness for virtio-1.



> Please comment.
> 
> ---
> 
> Greg Kurz (3):
>   vhost: add VHOST_VRING_F_LEGACY_BIG_ENDIAN flag
>   vhost: add support for legacy virtio
>   vhost_net: fix virtio_net header endianness
> 
> 
>  drivers/vhost/net.c|   32 ++--
>  drivers/vhost/vhost.c  |6 +-
>  drivers/vhost/vhost.h  |   23 +--
>  include/uapi/linux/vhost.h |2 ++
>  4 files changed, 50 insertions(+), 13 deletions(-)
> 
> --
> Greg
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] vhost: add VHOST_VRING_F_LEGACY_BIG_ENDIAN flag

2015-02-22 Thread Michael S. Tsirkin
On Fri, Feb 20, 2015 at 11:07:39AM +0100, Greg Kurz wrote:
> The VHOST_VRING_F_LEGACY_BIG_ENDIAN flag informs the kernel that the
> associated device is big endian. Of course, this only makes sense for
> legacy virtio devices since modern virtio devices are always little
> endian.
> 
> It will be used by the vhost memory accessors to byteswap vring data when
> we have a legacy device, in case host and guest endianness differ.
> 
> Signed-off-by: Greg Kurz 
> ---
>  drivers/vhost/vhost.c  |6 +-
>  drivers/vhost/vhost.h  |3 +++
>  include/uapi/linux/vhost.h |2 ++
>  3 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 2ee2826..dad3c37 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -199,6 +199,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
>   vq->call = NULL;
>   vq->log_ctx = NULL;
>   vq->memory = NULL;
> + vq->legacy_big_endian = false;
>  }
>  
>  static int vhost_worker(void *data)
> @@ -701,7 +702,8 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, 
> void __user *argp)
>   r = -EFAULT;
>   break;
>   }
> - if (a.flags & ~(0x1 << VHOST_VRING_F_LOG)) {
> + if (a.flags & ~(0x1 << VHOST_VRING_F_LOG|
> + 0x1 << VHOST_VRING_F_LEGACY_BIG_ENDIAN)) {

whitespace damage here

>   r = -EOPNOTSUPP;
>   break;
>   }

need to also make sure LEGACY_BIG_ENDIAN isn't set with VERSION_1.


> @@ -751,6 +753,8 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, 
> void __user *argp)
>   vq->avail = (void __user *)(unsigned long)a.avail_user_addr;
>   vq->log_addr = a.log_guest_addr;
>   vq->used = (void __user *)(unsigned long)a.used_user_addr;
> + vq->legacy_big_endian =
> + !!(a.flags & (0x1 << VHOST_VRING_F_LEGACY_BIG_ENDIAN));
>   break;
>   case VHOST_SET_VRING_KICK:
>   if (copy_from_user(&f, argp, sizeof f)) {
> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index 8c1c792..ce2c68e 100644
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -106,6 +106,9 @@ struct vhost_virtqueue {
>   /* Log write descriptors */
>   void __user *log_base;
>   struct vhost_log *log;
> +
> + /* We need to know the device endianness with legacy virtio. */
> + bool legacy_big_endian;
>  };
>  
>  struct vhost_dev {
> diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
> index bb6a5b4..0bf4491 100644
> --- a/include/uapi/linux/vhost.h
> +++ b/include/uapi/linux/vhost.h
> @@ -34,6 +34,8 @@ struct vhost_vring_addr {
>   /* Flag values: */
>   /* Whether log address is valid. If set enables logging. */
>  #define VHOST_VRING_F_LOG 0
> + /* Whether we have a big-endian legacy virtio device. */
> +#define VHOST_VRING_F_LEGACY_BIG_ENDIAN 1
>  
>   /* Start of array of descriptors (virtually contiguous) */
>   __u64 desc_user_addr;
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] vhost: add support for legacy virtio

2015-02-22 Thread Michael S. Tsirkin
On Fri, Feb 20, 2015 at 11:14:47AM +0100, Greg Kurz wrote:
> Signed-off-by: Greg Kurz 
> ---
>  drivers/vhost/vhost.h |   20 ++--
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> Michael,
> 
> The vhost_is_little_endian() helper adds unconditionnal overhead to fixed
> endian architectures: that is all architectures except arm and ppc64. This
> was addressed in QEMU with a TARGET_IS_BIENDIAN macro. Please give an
> advice about how to address this in the vhost code.
> 
> Thanks.

I suggest creating a config option for this, default to off.
When disabled the flag won't be set so userspace
can discover it's availability.


> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index ce2c68e..21e7d6a 100644
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -176,34 +176,42 @@ static inline bool vhost_has_feature(struct 
> vhost_virtqueue *vq, int bit)
>   return vq->acked_features & (1ULL << bit);
>  }
>  
> +static inline bool vhost_is_little_endian(struct vhost_virtqueue *vq)
> +{
> + if (vhost_has_feature(vq, VIRTIO_F_VERSION_1))
> + return true;
> + else
> + return !vq->legacy_big_endian;
> +}
> +
>  /* Memory accessors */
>  static inline u16 vhost16_to_cpu(struct vhost_virtqueue *vq, __virtio16 val)
>  {
> - return __virtio16_to_cpu(vhost_has_feature(vq, VIRTIO_F_VERSION_1), 
> val);
> + return __virtio16_to_cpu(vhost_is_little_endian(vq), val);
>  }
>  
>  static inline __virtio16 cpu_to_vhost16(struct vhost_virtqueue *vq, u16 val)
>  {
> - return __cpu_to_virtio16(vhost_has_feature(vq, VIRTIO_F_VERSION_1), 
> val);
> + return __cpu_to_virtio16(vhost_is_little_endian(vq), val);
>  }
>  
>  static inline u32 vhost32_to_cpu(struct vhost_virtqueue *vq, __virtio32 val)
>  {
> - return __virtio32_to_cpu(vhost_has_feature(vq, VIRTIO_F_VERSION_1), 
> val);
> + return __virtio32_to_cpu(vhost_is_little_endian(vq), val);
>  }
>  
>  static inline __virtio32 cpu_to_vhost32(struct vhost_virtqueue *vq, u32 val)
>  {
> - return __cpu_to_virtio32(vhost_has_feature(vq, VIRTIO_F_VERSION_1), 
> val);
> + return __cpu_to_virtio32(vhost_is_little_endian(vq), val);
>  }
>  
>  static inline u64 vhost64_to_cpu(struct vhost_virtqueue *vq, __virtio64 val)
>  {
> - return __virtio64_to_cpu(vhost_has_feature(vq, VIRTIO_F_VERSION_1), 
> val);
> + return __virtio64_to_cpu(vhost_is_little_endian(vq), val);
>  }
>  
>  static inline __virtio64 cpu_to_vhost64(struct vhost_virtqueue *vq, u64 val)
>  {
> - return __cpu_to_virtio64(vhost_has_feature(vq, VIRTIO_F_VERSION_1), 
> val);
> + return __cpu_to_virtio64(vhost_is_little_endian(vq), val);
>  }
>  #endif
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] vhost_net: fix virtio_net header endianness

2015-02-22 Thread Michael S. Tsirkin
On Fri, Feb 20, 2015 at 11:15:05AM +0100, Greg Kurz wrote:
> Without this patch, packets are being silently dropped by the tap backend.
> 
> Signed-off-by: Greg Kurz 

I think it's the wrong place to fix this.  You want a tun/macvtap ioctl
to enable legacy big endian stuff.  Treat it same way as vhost, with a
config option to enable.

> ---
>  drivers/vhost/net.c |   32 ++--
>  1 file changed, 26 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index afa06d2..2923eee 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -288,6 +288,16 @@ static void vhost_zerocopy_callback(struct ubuf_info 
> *ubuf, bool success)
>   rcu_read_unlock_bh();
>  }
>  
> +static void fix_virtio_net_hdr(struct vhost_virtqueue *vq)
> +{
> + struct virtio_net_hdr *hdr = vq->iov[0].iov_base;
> +
> + hdr->hdr_len = vhost16_to_cpu(vq, hdr->hdr_len);
> + hdr->gso_size = vhost16_to_cpu(vq, hdr->gso_size);
> + hdr->csum_start  = vhost16_to_cpu(vq, hdr->csum_start);
> + hdr->csum_offset = vhost16_to_cpu(vq, hdr->csum_offset);
> +}
> +
>  /* Expects to be always run from workqueue - which acts as
>   * read-size critical section for our kind of RCU. */
>  static void handle_tx(struct vhost_net *net)
> @@ -352,6 +362,10 @@ static void handle_tx(struct vhost_net *net)
>  "out %d, int %d\n", out, in);
>   break;
>   }
> +
> + if (!hdr_size)
> + fix_virtio_net_hdr(vq);
> +
>   /* Skip header. TODO: support TSO. */
>   len = iov_length(vq->iov, out);
>   iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len);
> @@ -609,12 +623,18 @@ static void handle_rx(struct vhost_net *net)
>   continue;
>   }
>   /* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */
> - if (unlikely(vhost_hlen) &&
> - copy_to_iter(&hdr, sizeof(hdr), &fixup) != sizeof(hdr)) {
> - vq_err(vq, "Unable to write vnet_hdr at addr %p\n",
> -vq->iov->iov_base);
> - break;
> - }
> + if (unlikely(vhost_hlen)) {
> + size_t len = copy_to_iter(&hdr, sizeof(hdr), &fixup);
> +
> + if (len != sizeof(hdr)) {
> + vq_err(vq,
> +"Unable to write vnet_hdr at addr %p\n",
> +vq->iov->iov_base);
> + break;
> + }
> + } else
> + fix_virtio_net_hdr(vq);
> +
>   /* TODO: Should check and handle checksum. */
>  
>   num_buffers = cpu_to_vhost16(vq, headcount);
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html