Re: [Qemu-devel] [PATCH 2/3] qemu: Implement virtio-pstore device

2016-09-22 Thread Namhyung Kim
On Thu, Sep 22, 2016 at 01:23:16PM +0100, Stefan Hajnoczi wrote:
> On Sun, Sep 04, 2016 at 11:38:59PM +0900, Namhyung Kim wrote:
> > +static void virtio_pstore_handle_io(VirtIODevice *vdev, VirtQueue *vq)
> > +{
> > +VirtIOPstore *s = VIRTIO_PSTORE(vdev);
> > +VirtQueueElement *elem;
> > +struct virtio_pstore_req req;
> > +struct virtio_pstore_res res;
> > +ssize_t len = 0;
> > +int ret;
> > +
> > +for (;;) {
> > +elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
> > +if (!elem) {
> > +return;
> > +}
> > +
> > +if (elem->out_num < 1 || elem->in_num < 1) {
> > +error_report("request or response buffer is missing");
> > +exit(1);
> 
> The new virtio_error() function might be available, depending on when
> this patch series is merged.  virtio_error() should be used instead of
> exit(1).  See "[PATCH v5 0/9] virtio: avoid exit() when device enters
> invalid states" on qemu-devel.

Thanks for the info, will take a look.

> 
> > +}
> > +
> > +if (elem->out_num > 2 || elem->in_num > 3) {
> > +error_report("invalid number of input/output buffer");
> > +exit(1);
> > +}
> 
> The VIRTIO specification requires that flexible framing is supported.
> The device cannot make assumptions about the scatter-gather list.  It
> must support any layout (e.g. even multiple 1-byte iovecs making up the
> buffer).

Ok.

> 
> > +
> > +len = iov_to_buf(elem->out_sg, elem->out_num, 0, , 
> > sizeof(req));
> > +if (len != (ssize_t)sizeof(req)) {
> > +error_report("invalid request size: %ld", (long)len);
> > +exit(1);
> > +}
> > +res.cmd  = req.cmd;
> > +res.type = req.type;
> > +
> > +switch (le16_to_cpu(req.cmd)) {
> > +case VIRTIO_PSTORE_CMD_OPEN:
> > +ret = virtio_pstore_do_open(s);
> > +break;
> > +case VIRTIO_PSTORE_CMD_CLOSE:
> > +ret = virtio_pstore_do_close(s);
> > +break;
> > +case VIRTIO_PSTORE_CMD_ERASE:
> > +ret = virtio_pstore_do_erase(s, );
> > +break;
> > +case VIRTIO_PSTORE_CMD_READ:
> > +ret = virtio_pstore_do_read(s, elem);
> > +if (ret == 1) {
> > +/* async channel io */
> > +continue;
> > +}
> > +break;
> > +case VIRTIO_PSTORE_CMD_WRITE:
> > +ret = virtio_pstore_do_write(s, elem, );
> > +if (ret == 1) {
> > +/* async channel io */
> > +continue;
> > +}
> > +break;
> > +default:
> > +ret = -1;
> > +break;
> > +}
> > +
> > +res.ret = ret;
> 
> Missing cpu_to_le()?

Right!

> 
> > +static void pstore_set_bufsize(Object *obj, Visitor *v,
> > +   const char *name, void *opaque,
> > +   Error **errp)
> > +{
> > +VirtIOPstore *s = opaque;
> > +Error *error = NULL;
> > +uint64_t value;
> > +
> > +visit_type_size(v, name, , );
> > +if (error) {
> > +error_propagate(errp, error);
> > +return;
> > +}
> > +
> > +if (value < 4096) {
> > +error_setg(, "Warning: too small buffer size: %"PRIu64, 
> > value);
> 
> This is an error, not a warning.  Please remove "Warning:" so it's clear
> to the user that this message caused QEMU to fail.

Will do.

Thanks,
Namhyung



Re: [Qemu-devel] [PATCH 1/3] virtio: Basic implementation of virtio pstore driver

2016-09-22 Thread Namhyung Kim
Hi Stefan,

On Thu, Sep 22, 2016 at 12:57:44PM +0100, Stefan Hajnoczi wrote:
> On Sun, Sep 04, 2016 at 11:38:58PM +0900, Namhyung Kim wrote:
> > The virtio pstore driver provides interface to the pstore subsystem so
> > that the guest kernel's log/dump message can be saved on the host
> > machine.  Users can access the log file directly on the host, or on the
> > guest at the next boot using pstore filesystem.  It currently deals with
> > kernel log (printk) buffer only, but we can extend it to have other
> > information (like ftrace dump) later.
> > 
> > It supports legacy PCI device using a 16K buffer by default and it's
> > configurable.  It uses two virtqueues - one for (sync) read and another
> > for (async) write.  Since it cannot wait for write finished, it supports
> > up to 128 concurrent IO.
> 
> Please document the locks that this code relies on.  It is generally not
> safe to call virtqueue_*() from multiple threads.  I also wonder about
> locking for virtio_pstore->req_id and other fields.  Are locks missing
> or is something in pstore ensuring safety?

Ok, I should use atomic inc for pstore->req_id.  The open-read-close
are serialized by the read_mutex of pstore_info.  Write can happend
anytime so I gave it a dedicate queue.

Erase is a problem though, normally it's only doable after mount
operation is done so no contention to the open-read-close.  But if the
pstore_update_ms is set, timer routine can schedule a work to do the
open-read-close loop which might contend to erase.

I'm not sure how useful pstore_update_ms is and the descriptoin saids

  "milliseconds before pstore updates its content "
  "(default is -1, which means runtime updates are disabled; "
  "enabling this option is not safe, it may lead to further "
  "corruption on Oopses)")


> 
> > +static int virt_pstore_open(struct pstore_info *psi)
> > +{
> > +   struct virtio_pstore *vps = psi->data;
> > +   struct virtio_pstore_req *req;
> > +   struct virtio_pstore_res *res;
> > +   struct scatterlist sgo[1], sgi[1];
> > +   struct scatterlist *sgs[2] = { sgo, sgi };
> > +   unsigned int len;
> > +
> > +   virt_pstore_get_reqs(vps, , );
> > +
> > +   req->cmd = cpu_to_le16(VIRTIO_PSTORE_CMD_OPEN);
> > +
> > +   sg_init_one(sgo, req, sizeof(*req));
> > +   sg_init_one(sgi, res, sizeof(*res));
> > +   virtqueue_add_sgs(vps->vq[0], sgs, 1, 1, vps, GFP_KERNEL);
> > +   virtqueue_kick(vps->vq[0]);
> > +
> > +   wait_event(vps->acked, virtqueue_get_buf(vps->vq[0], ));
> > +   return le32_to_cpu(res->ret);
> 
> This assumes the device puts compatible Linux errno values in res->ret.
> The function doesn't need to return -errno if I'm reading fs/pstore/
> code correctly.  You could return -1 on error to avoid making this
> assumption.  The same applies to other res->ret usage below.

Ok.

> 
> > +}
> > +
> > +static int virt_pstore_close(struct pstore_info *psi)
> > +{
> > +   struct virtio_pstore *vps = psi->data;
> > +   struct virtio_pstore_req *req = >req[vps->req_id];
> > +   struct virtio_pstore_res *res = >res[vps->req_id];
> 
> Assigning >req[vps->req_id]/>res[vps->req_id] is unnecessary,
> virt_pstore_get_reqs() handles that below.

Ah, right.

> 
> > +   struct scatterlist sgo[1], sgi[1];
> > +   struct scatterlist *sgs[2] = { sgo, sgi };
> > +   unsigned int len;
> > +
> > +   virt_pstore_get_reqs(vps, , );
> > +
> > +   req->cmd = cpu_to_le16(VIRTIO_PSTORE_CMD_CLOSE);
> > +
> > +   sg_init_one(sgo, req, sizeof(*req));
> > +   sg_init_one(sgi, res, sizeof(*res));
> > +   virtqueue_add_sgs(vps->vq[0], sgs, 1, 1, vps, GFP_KERNEL);
> > +   virtqueue_kick(vps->vq[0]);
> > +
> > +   wait_event(vps->acked, virtqueue_get_buf(vps->vq[0], ));
> > +   return le32_to_cpu(res->ret);
> > +}
> > +
> > +static ssize_t virt_pstore_read(u64 *id, enum pstore_type_id *type,
> > +   int *count, struct timespec *time,
> > +   char **buf, bool *compressed,
> > +   ssize_t *ecc_notice_size,
> > +   struct pstore_info *psi)
> > +{
> > +   struct virtio_pstore *vps = psi->data;
> > +   struct virtio_pstore_req *req;
> > +   struct virtio_pstore_res *res;
> > +   struct virtio_pstore_fileinfo info;
> > +   struct scatterlist sgo[1], sgi[3];
> > +   struct scatterlist *sgs[2] = { sgo, sgi };
> > +   unsigned int len;
> > +   unsigned int flags;
> > +   int ret;
> > +   void *bf;
> > +
> > +   virt_pstore_get_reqs(vps, , );
> > +
> > +   req->cmd = cpu_to_le16(VIRTIO_PSTORE_CMD_READ);
> > +
> > +   sg_init_one(sgo, req, sizeof(*req));
> > +   sg_init_table(sgi, 3);
> > +   sg_set_buf([0], res, sizeof(*res));
> > +   sg_set_buf([1], , sizeof(info));
> > +   sg_set_buf([2], psi->buf, psi->bufsize);
> > +   virtqueue_add_sgs(vps->vq[0], sgs, 1, 1, vps, GFP_KERNEL);
> > +   virtqueue_kick(vps->vq[0]);
> > +
> > +   wait_event(vps->acked, virtqueue_get_buf(vps->vq[0], ));
> > +   if (len < sizeof(*res) + sizeof(info))
> > +   return -1;
> > +
> > +   ret = 

Re: [Qemu-devel] [PATCH] imx_fec: fix error in qemu_send_packet argument

2016-09-22 Thread Jason Wang



On 2016年09月22日 22:28, Paolo Bonzini wrote:

This uses the wrong frame size for packets composed of multiple
descriptors.

Signed-off-by: Paolo Bonzini 
---
  hw/net/imx_fec.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
index 1c415ab..50c7564 100644
--- a/hw/net/imx_fec.c
+++ b/hw/net/imx_fec.c
@@ -429,7 +429,7 @@ static void imx_fec_do_tx(IMXFECState *s)
  frame_size += len;
  if (bd.flags & ENET_BD_L) {
  /* Last buffer in frame.  */
-qemu_send_packet(qemu_get_queue(s->nic), frame, len);
+qemu_send_packet(qemu_get_queue(s->nic), frame, frame_size);
  ptr = frame;
  frame_size = 0;
  s->regs[ENET_EIR] |= ENET_INT_TXF;


Applied, thanks.



Re: [Qemu-devel] [PATCH] tcg: increase MAX_OP_PER_INSTR to 395

2016-09-22 Thread Laurent Desnogues
Hello,

On Fri, Sep 23, 2016 at 1:53 AM, Joseph Myers  wrote:
> MAX_OP_PER_INSTR is currently 266, reported in commit
> 14dcdac82f398cbac874c8579b9583fab31c67bf to be the worst case for the
> ARM A64 decoder.
>
> Whether or not it was in fact the worst case at that time in 2014, I'm
> observing the instruction 0x4c006020 (st1 {v0.16b-v2.16b}, [x1])
> generate 386 ops from disas_ldst_multiple_struct with current sources,

Something's odd, I get exactly half of that with 193.

That being said st1 {v0.16b-v3.16b}, [x1], #64 generates even more ops with 258.

Thanks,

Laurent

> plus one op from the call to tcg_gen_insn_start in the loop in
> gen_intermediate_code_a64.  Furthermore, I see six ops generated after
> the loop in gen_intermediate_code_a64, and at least two added
> subsequently in optimization, so MAX_OP_PER_INSTR needs to be at least
> 395.  I do not know whether other instructions, or code during or
> after the loop in gen_intermediate_code_a64, might actually require
> the value to be bigger than 395 (possibly depending on the
> instructions translated before the one generating 386 ops), just that
> 395 is definitely needed for a GCC testcase that generates that
> particular instruction.  So if there is a reliable methodology to
> determine the maximum number of ops that might be generated in (one
> pass through that loop, plus the code after that loop, plus
> optimization), it should be used instead, and might result in a higher
> figure (or maybe a higher figure would be safer anyway).
>
> Signed-off-by: Joseph Myers 
>
> ---
>
> diff --git a/tcg/tcg.h b/tcg/tcg.h
> index c9949aa..a7fa452 100644
> --- a/tcg/tcg.h
> +++ b/tcg/tcg.h
> @@ -32,7 +32,7 @@
>  #include "tcg-target.h"
>
>  /* XXX: make safe guess about sizes */
> -#define MAX_OP_PER_INSTR 266
> +#define MAX_OP_PER_INSTR 395
>
>  #if HOST_LONG_BITS == 32
>  #define MAX_OPC_PARAM_PER_ARG 2
>
> --
> Joseph S. Myers
> jos...@codesourcery.com
>



Re: [Qemu-devel] [PATCH for-2.8 00/18] pc: q35: x2APIC support in kvm_apic mode

2016-09-22 Thread Peter Xu
On Thu, Sep 22, 2016 at 12:34:36PM +0800, Chao Gao wrote:
> Hi, we had 3 problems left here.
> 1. IRQremapping can't work with x2apic_cluster mode.
> 2. apic_id > 255 can't receive devices interrupts.
> 3. windows crash when present IRQremapping capability to it.

For (3), I don't know whether it's urgent or not - I've put it into my
todo list (assuming this is for HPC and mostly we are using Linux
guests?).

For (1-2), again we may need to wait for Radim's patches.

Thanks.

-- peterx



[Qemu-devel] [PATCH v2] x86: ioapic: boost default version to 0x20

2016-09-22 Thread Peter Xu
It's 2.8 now, and maybe it's time to switch IOAPIC default version to
0x20.

Signed-off-by: Peter Xu 
---

V2:
- keep compatible for qemu version <= 2.7 [Paolo]

 hw/intc/ioapic.c| 2 +-
 include/hw/compat.h | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c
index 31791b0..fd9208f 100644
--- a/hw/intc/ioapic.c
+++ b/hw/intc/ioapic.c
@@ -416,7 +416,7 @@ static void ioapic_realize(DeviceState *dev, Error **errp)
 }
 
 static Property ioapic_properties[] = {
-DEFINE_PROP_UINT8("version", IOAPICCommonState, version, 0x11),
+DEFINE_PROP_UINT8("version", IOAPICCommonState, version, 0x20),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/compat.h b/include/hw/compat.h
index a1d6694..46412b2 100644
--- a/include/hw/compat.h
+++ b/include/hw/compat.h
@@ -6,6 +6,10 @@
 .driver   = "virtio-pci",\
 .property = "page-per-vq",\
 .value= "on",\
+},{\
+.driver   = "ioapic",\
+.property = "version",\
+.value= "0x11",\
 },
 
 #define HW_COMPAT_2_6 \
-- 
2.7.4




Re: [Qemu-devel] [PATCH 0/7] e1000e: A few fixes for RX data path

2016-09-22 Thread Jason Wang



On 2016年09月15日 14:14, Dmitry Fleytman wrote:

This series contains a few RX logic fixes for e1000e.

These fixes improve compliance to HW device specification
and fix occasional interruptions of RX traffic with
the latest linux driver.

Dmitry Fleytman (7):
   e1000e: Flush all receive queues on receive enable
   e1000e: Flush receive queue on link up
   e1000e: Fix CTRL_EXT.EIAME behavior
   e1000e: Fix PBACLR implementation
   e1000e: Fix OTHER interupts processing for MSI-X
   e1000e: Fix spurious RX TCP ACK interrupts
   e1000e: Fix EIAC register implementation

  hw/net/e1000e.c  |  2 +-
  hw/net/e1000e_core.c | 30 +++---
  hw/net/e1000e_core.h |  3 +++
  hw/net/trace-events  |  2 +-
  4 files changed, 24 insertions(+), 13 deletions(-)



Applied, thanks.



Re: [Qemu-devel] [V0 1/1] virtio crypto device specification: asymmetric crypto service

2016-09-22 Thread Zeng, Xin
On Wednesday, September 21, 2016 3:03 PM, Gonglei (Arei) Wrote:
> > -Original Message-
> > From: Xin Zeng [mailto:xin.z...@intel.com]
> > Sent: Wednesday, September 21, 2016 1:15 PM
> > To: virtio-...@lists.oasis-open.org; qemu-devel@nongnu.org; Gonglei
> (Arei)
> > Cc: m...@redhat.com; brian.a.keat...@intel.com; john.grif...@intel.com;
> > liang.j...@intel.com; Huangweidong (C); Xin Zeng
> > Subject: [V0 1/1] virtio crypto device specification: asymmetric crypto
> service
> >
> > This patch introduces asymmetric crypto service into virtio crypto
> > device. The asymmetric crypto service can be referred as signature,
> > verification, encryption, decryption, key generation and key exchange.
> > This patch depends on another virtio crypto device spec patch:
> > https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg04563.html.
> >
> > Signed-off-by: Xin Zeng 
> > ---
> >  virtio-crypto.tex | 932
> > +-
> >  1 file changed, 931 insertions(+), 1 deletion(-)
> >
> > diff --git a/virtio-crypto.tex b/virtio-crypto.tex
> > index c3554e3..699d8dc 100644
> > --- a/virtio-crypto.tex
> > +++ b/virtio-crypto.tex
> > @@ -46,6 +46,7 @@ struct virtio_crypto_config {
> >  le32 kdf_algo;
> >  le32 aead_algo;
> >  le32 primitive_algo;
> > +le32 rsa_padding;
> 
> The structure doesn't 64-bit aligned now. Please add a padding.
> 

Yes. We also need remove some fields for now as Michael suggested in another 
mail.

> >  };
> >  \end{lstlisting}
> >
> > @@ -67,6 +68,7 @@ The following services are defined:
> >  #define VIRTIO_CRYPTO_SERVICE_HASH   (1) /* HASH service */
> >  #define VIRTIO_CRYPTO_SERVICE_MAC(2) /* MAC (Message
> > Authentication Codes) service */
> >  #define VIRTIO_CRYPTO_SERVICE_AEAD   (3) /* AEAD (Authenticated
> > Encryption with Associated Data) service */
> > +#define VIRTIO_CRYPTO_SERVICE_ASYM  (4) /* Asymmetric crypto
> service*/
> >  \end{lstlisting}
> >
> >  The last driver-read-only fields specify detailed algorithms masks
> > @@ -140,6 +142,28 @@ The following AEAD algorithms are defined:
> >  #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305  3
> >  \end{lstlisting}
> >
> > +The following asymmetric algorithms are defined:
> > +
> > +\begin{lstlisting}
> > +#define VIRTIO_CRYPTO_ASYM_NONE0
> > +#define VIRTIO_CRYPTO_ASYM_RSA 1
> > +#define VIRTIO_CRYPTO_ASYM_DSA 2
> > +#define VIRTIO_CRYPTO_ASYM_DH  3
> > +#define VIRTIO_CRYPTO_ASYM_ECDSA   4
> > +#define VIRTIO_CRYPTO_ASYM_ECDH   5
> > +\end{lstlisting}
> > +
> > +The following rsa padding capabilities are defined:
> > +
> > +\begin{lstlisting}
> > +#define VIRTIO_CRYPTO_RSA_NO_PADDING 0
> > +#define VIRTIO_CRYPTO_RSA_PKCS1_PADDING  1
> > +#define VIRTIO_CRYPTO_RSA_SSLV23_PADDING 2
> > +#define VIRTIO_CRYPTO_RSA_PKCS1_OAEP_PADDING 3
> > +#define VIRTIO_CRYPTO_RSA_X931_PADDING   4
> > +#define VIRTIO_CRYPTO_RSA_PKCS1_PSS_PADDING  5
> > +\end{lstlisting}
> > +
> >  \begin{note}
> >  More algorithms will be defined in the future.
> >  \end{note}
> > @@ -238,6 +262,18 @@ struct virtio_crypto_op_header {
> >  VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00)
> >  #define VIRTIO_CRYPTO_AEAD_DECRYPT \
> >  VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01)
> > +#define VIRTIO_CRYPTO_ASYM_SIGN\
> > +VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_ASYM, 0x00)
> > +#define VIRTIO_CRYPTO_ASYM_VERIFY \
> > +VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_ASYM, 0x01)
> > +#define VIRTIO_CRYPTO_ASYM_ENCRYPT  \
> > +VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_ASYM, 0x02)
> > +#define VIRTIO_CRYPTO_ASYM_DECRYPT  \
> > +VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_ASYM, 0x03)
> > +#define VIRTIO_CRYPTO_ASYM_KEY_GEN  \
> > +VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_ASYM, 0x04)
> > +#define VIRTIO_CRYPTO_ASYM_KEY_EXCHG \
> > +VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_ASYM, 0x05)
> >  le32 opcode;
> >  /* algo should be service-specific algorithms */
> >  le32 algo;
> > @@ -540,6 +576,26 @@ struct virtio_crypto_op_data_req {
> >  struct virtio_crypto_hash_data_req  hash_req;
> >  struct virtio_crypto_mac_data_req   mac_req;
> >  struct virtio_crypto_aead_data_req  aead_req;
> > +struct virtio_crypto_ecdsa_sign_req ecdsa_sign_req;
> > +struct virtio_crypto_dsa_sign_req dsa_sign_req;
> > +struct virtio_crypto_rsa_sign_req rsa_sign_req;
> > +
> > +struct virtio_crypto_ecdsa_verify_req ecdsa_verify_req;
> > +struct virtio_crypto_dsa_verify_req dsa_verify_req;
> > +struct virtio_crypto_rsa_verify_req rsa_verify_req;
> > +
> > +struct virtio_crypto_rsa_enc_req rsa_enc_req
> > +struct virtio_crypto_rsa_dec_req rsa_dec_req;
> > +
> > +struct virtio_crypto_rsa_keygen_req rsa_keygen_req;
> > +struct virtio_crypto_dsa_keygen_req dsa_keygen_req;
> > +struct 

Re: [Qemu-devel] [PATCH v2] net: mcf: limit buffer descriptor count

2016-09-22 Thread Jason Wang



On 2016年09月22日 18:33, Paolo Bonzini wrote:


On 22/09/2016 12:32, P J P wrote:

From: Prasad J Pandit 

ColdFire Fast Ethernet Controller uses buffer descriptors to manage
data flow to/fro receive & transmit queues. While transmitting
packets, it could continue to read buffer descriptors if a buffer
descriptor has length of zero and has crafted values in bd.flags.
Set upper limit to number of buffer descriptors.

Reported-by: Li Qiang 
Signed-off-by: Prasad J Pandit 
---
  hw/net/mcf_fec.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

Update per
   -> https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg05284.html

diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c
index 7c0398e..6d3418e 100644
--- a/hw/net/mcf_fec.c
+++ b/hw/net/mcf_fec.c
@@ -23,6 +23,7 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0)
  #define DPRINTF(fmt, ...) do {} while(0)
  #endif
  
+#define FEC_MAX_DESC 1024

  #define FEC_MAX_FRAME_SIZE 2032
  
  typedef struct {

@@ -149,7 +150,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
  uint32_t addr;
  mcf_fec_bd bd;
  int frame_size;
-int len;
+int len, descnt = 0;
  uint8_t frame[FEC_MAX_FRAME_SIZE];
  uint8_t *ptr;
  
@@ -157,7 +158,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)

  ptr = frame;
  frame_size = 0;
  addr = s->tx_descriptor;
-while (1) {
+while (descnt++ < FEC_MAX_DESC) {
  mcf_fec_read_bd(, addr);
  DPRINTF("tx_bd %x flags %04x len %d data %08x\n",
  addr, bd.flags, bd.length, bd.data);


Reviewed-by: Paolo Bonzini 


Applied, thanks.



Re: [Qemu-devel] [PATCH v2] net: imx: limit buffer descriptor count

2016-09-22 Thread Jason Wang



On 2016年09月22日 18:32, Paolo Bonzini wrote:


On 22/09/2016 12:31, P J P wrote:

From: Prasad J Pandit 

i.MX Fast Ethernet Controller uses buffer descriptors to manage
data flow to/fro receive & transmit queues. While transmitting
packets, it could continue to read buffer descriptors if a buffer
descriptor has length of zero and has crafted values in bd.flags.
Set an upper limit to number of buffer descriptors.

Reported-by: Li Qiang 
Signed-off-by: Prasad J Pandit 
---
  hw/net/imx_fec.c | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

Update per
   -> https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg05284.html

diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
index e60e338..547fa99 100644
--- a/hw/net/imx_fec.c
+++ b/hw/net/imx_fec.c
@@ -94,6 +94,8 @@ static const VMStateDescription vmstate_imx_fec = {
  #define PHY_INT_PARFAULT(1 << 2)
  #define PHY_INT_AUTONEG_PAGE(1 << 1)
  
+#define IMX_MAX_DESC1024

+
  static void imx_fec_update(IMXFECState *s);
  
  /*

@@ -264,12 +266,12 @@ static void imx_fec_update(IMXFECState *s)
  
  static void imx_fec_do_tx(IMXFECState *s)

  {
-int frame_size = 0;
+int frame_size = 0, descnt = 0;
  uint8_t frame[FEC_MAX_FRAME_SIZE];
  uint8_t *ptr = frame;
  uint32_t addr = s->tx_descriptor;
  
-while (1) {

+while (descnt++ < IMX_MAX_DESC) {
  IMXFECBufDesc bd;
  int len;
  


Reviewed-by: Paolo Bonzini 


Applied, thanks.



[Qemu-devel] [PULL 16/23] docker: Generate /packages.txt in fedora image

2016-09-22 Thread Fam Zheng
Put the list of package names in an environment, and output their
package names to the target file in the end.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-3-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/dockerfiles/fedora.docker | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tests/docker/dockerfiles/fedora.docker 
b/tests/docker/dockerfiles/fedora.docker
index 1d26a8e..b414e88 100644
--- a/tests/docker/dockerfiles/fedora.docker
+++ b/tests/docker/dockerfiles/fedora.docker
@@ -1,7 +1,17 @@
 FROM fedora:23
-RUN dnf install -y \
+ENV PACKAGES \
 ccache git tar PyYAML sparse flex bison \
 glib2-devel pixman-devel zlib-devel SDL-devel libfdt-devel \
 gcc gcc-c++ clang make perl which bc findutils \
-
mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config,gtk2,gtk3,gnutls,nettle,libtasn1,libjpeg-turbo,libpng,curl,libssh2,bzip2}
+mingw32-pixman mingw32-glib2 mingw32-gmp mingw32-SDL mingw32-pkg-config \
+mingw32-gtk2 mingw32-gtk3 mingw32-gnutls mingw32-nettle mingw32-libtasn1 \
+mingw32-libjpeg-turbo mingw32-libpng mingw32-curl mingw32-libssh2 \
+mingw32-bzip2 \
+mingw64-pixman mingw64-glib2 mingw64-gmp mingw64-SDL mingw64-pkg-config \
+mingw64-gtk2 mingw64-gtk3 mingw64-gnutls mingw64-nettle mingw64-libtasn1 \
+mingw64-libjpeg-turbo mingw64-libpng mingw64-curl mingw64-libssh2 \
+mingw64-bzip2
+
+RUN dnf install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
 ENV FEATURES mingw clang pyyaml
-- 
2.7.4




[Qemu-devel] [PULL 22/23] docker: Terminate instances at SIGTERM and SIGHUP

2016-09-22 Thread Fam Zheng
Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-9-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/docker.py | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 71b0d27..37d8319 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -21,6 +21,7 @@ import uuid
 import argparse
 import tempfile
 import re
+import signal
 from tarfile import TarFile, TarInfo
 from StringIO import StringIO
 from shutil import copy, rmtree
@@ -101,6 +102,8 @@ class Docker(object):
 self._command = _guess_docker_command()
 self._instances = []
 atexit.register(self._kill_instances)
+signal.signal(signal.SIGTERM, self._kill_instances)
+signal.signal(signal.SIGHUP, self._kill_instances)
 
 def _do(self, cmd, quiet=True, infile=None, **kwargs):
 if quiet:
@@ -133,7 +136,7 @@ class Docker(object):
 self._do_kill_instances(False, False)
 return 0
 
-def _kill_instances(self):
+def _kill_instances(self, *args, **kwargs):
 return self._do_kill_instances(True)
 
 def _output(self, cmd, **kwargs):
-- 
2.7.4




[Qemu-devel] [PULL 21/23] docker: Support showing environment information

2016-09-22 Thread Fam Zheng
Add a make variable SHOW_ENV. When it's set to non empty, print the
package information and environment variables.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-8-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/Makefile.include |  2 +-
 tests/docker/run  | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index 19d4cc7..2fcc3c6 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -117,7 +117,7 @@ docker-run-%: docker-qemu-src
$(if $(DEBUG),-i,--net=none) \
-e TARGET_LIST=$(TARGET_LIST) \
-e EXTRA_CONFIGURE_OPTS=$(EXTRA_CONFIGURE_OPTS) 
\
-   -e V=$V -e J=$J -e DEBUG=$(DEBUG)\
+   -e V=$V -e J=$J -e DEBUG=$(DEBUG) -e 
SHOW_ENV=$(SHOW_ENV)\
-e CCACHE_DIR=/var/tmp/ccache \
-v $$(readlink -e 
$(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
-v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
diff --git a/tests/docker/run b/tests/docker/run
index d85d49a..ed7dd31 100755
--- a/tests/docker/run
+++ b/tests/docker/run
@@ -40,6 +40,17 @@ for p in dtc pixman; do
 fi
 done
 
+if test -n "$SHOW_ENV"; then
+if test -f /packages.txt; then
+echo "Packages installed:"
+cat /packages.txt
+echo
+fi
+echo "Environment variables:"
+env
+echo
+fi
+
 export QEMU_SRC="$TEST_DIR/src"
 
 cd "$QEMU_SRC/tests/docker"
-- 
2.7.4




[Qemu-devel] [PULL 18/23] docker: Update fedora image to latest

2016-09-22 Thread Fam Zheng
Now that 23 is becoming an "old" release with 24 available. Fedora has a
quick release cycle, so use latest to follow more closely.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-5-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/dockerfiles/fedora.docker | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/docker/dockerfiles/fedora.docker 
b/tests/docker/dockerfiles/fedora.docker
index b414e88..478163b 100644
--- a/tests/docker/dockerfiles/fedora.docker
+++ b/tests/docker/dockerfiles/fedora.docker
@@ -1,4 +1,4 @@
-FROM fedora:23
+FROM fedora:latest
 ENV PACKAGES \
 ccache git tar PyYAML sparse flex bison \
 glib2-devel pixman-devel zlib-devel SDL-devel libfdt-devel \
-- 
2.7.4




[Qemu-devel] [PULL 19/23] docker: Flatten default target list in test-quick

2016-09-22 Thread Fam Zheng
Previously it is expanded to a whitespace separated list which is not
the most appropriate format. Since it's only two items, flatten it.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-6-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/test-quick | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/docker/test-quick b/tests/docker/test-quick
index 07cdc59..7885dfa 100755
--- a/tests/docker/test-quick
+++ b/tests/docker/test-quick
@@ -13,7 +13,7 @@
 
 . common.rc
 
-DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)"
+DEF_TARGET_LIST="x86_64-softmmu,aarch64-softmmu"
 TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \
 build_qemu
 make check $MAKEFLAGS
-- 
2.7.4




Re: [Qemu-devel] [PATCH] mcf_fec: fix error in qemu_send_packet argument

2016-09-22 Thread Jason Wang



On 2016年09月22日 22:28, Paolo Bonzini wrote:

This uses the wrong frame size for packets composed of multiple
descriptors.

Signed-off-by: Paolo Bonzini 
---
  hw/net/mcf_fec.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c
index 0ee8ad9..5a5fc69 100644
--- a/hw/net/mcf_fec.c
+++ b/hw/net/mcf_fec.c
@@ -176,7 +176,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
  if (bd.flags & FEC_BD_L) {
  /* Last buffer in frame.  */
  DPRINTF("Sending packet\n");
-qemu_send_packet(qemu_get_queue(s->nic), frame, len);
+qemu_send_packet(qemu_get_queue(s->nic), frame, frame_size);
  ptr = frame;
  frame_size = 0;
  s->eir |= FEC_INT_TXF;


Applied, thanks.



[Qemu-devel] [PULL 15/23] docker: Generate /packages.txt in centos6 image

2016-09-22 Thread Fam Zheng
Put the list of package names in an environment, and output their
package names to the target file in the end.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-2-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/dockerfiles/centos6.docker | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/docker/dockerfiles/centos6.docker 
b/tests/docker/dockerfiles/centos6.docker
index 8f4fe46..34e0d3b 100644
--- a/tests/docker/dockerfiles/centos6.docker
+++ b/tests/docker/dockerfiles/centos6.docker
@@ -1,6 +1,8 @@
 FROM centos:6
-RUN yum install -y \
+RUN yum install -y epel-release
+ENV PACKAGES libfdt-devel ccache \
 tar git make gcc g++ \
 zlib-devel glib2-devel SDL-devel pixman-devel \
 epel-release
-RUN yum install -y libfdt-devel ccache
+RUN yum install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
-- 
2.7.4




[Qemu-devel] [PULL 17/23] docker: Generate /packages.txt in ubuntu image

2016-09-22 Thread Fam Zheng
Put the list of package names in an environment, and output their
package names to the target file in the end.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-4-git-send-email-f...@redhat.com>
Reviewed-by: Daniel. P. Berrange 
---
 tests/docker/dockerfiles/ubuntu.docker | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/docker/dockerfiles/ubuntu.docker 
b/tests/docker/dockerfiles/ubuntu.docker
index a8b88c3..a360a05 100644
--- a/tests/docker/dockerfiles/ubuntu.docker
+++ b/tests/docker/dockerfiles/ubuntu.docker
@@ -2,10 +2,12 @@ FROM ubuntu:14.04
 RUN echo "deb http://archive.ubuntu.com/ubuntu/ trusty universe multiverse" >> 
\
 /etc/apt/sources.list
 RUN apt-get update
-RUN apt-get -y install flex bison \
+ENV PACKAGES flex bison \
 libusb-1.0-0-dev libiscsi-dev librados-dev libncurses5-dev \
 libseccomp-dev libgnutls-dev libssh2-1-dev  libspice-server-dev \
 libspice-protocol-dev libnss3-dev libfdt-dev \
 libgtk-3-dev libvte-2.90-dev libsdl1.2-dev libpng12-dev libpixman-1-dev \
 git make ccache python-yaml gcc clang sparse
+RUN apt-get -y install $PACKAGES
+RUN dpkg -l $PACKAGES | sort > /packages.txt
 ENV FEATURES clang pyyaml
-- 
2.7.4




[Qemu-devel] [PULL 11/23] uuid: Tighten uuid parse

2016-09-22 Thread Fam Zheng
sscanf is relatively loose (tolerate) on some invalid formats that we
should fail instead of generating a wrong uuid structure, like with
whitespaces and short strings.

Add and use a helper function to first check the format.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-11-git-send-email-f...@redhat.com>
---
 util/uuid.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/util/uuid.c b/util/uuid.c
index 4701903..dd6b5fd 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -61,12 +61,34 @@ char *qemu_uuid_unparse_strdup(const QemuUUID *uuid)
uu[13], uu[14], uu[15]);
 }
 
+static bool qemu_uuid_is_valid(const char *str)
+{
+int i;
+
+for (i = 0; i < strlen(str); i++) {
+const char c = str[i];
+if (i == 8 || i == 13 || i == 18 || i == 23) {
+if (str[i] != '-') {
+return false;
+}
+} else {
+if ((c >= '0' && c <= '9') ||
+(c >= 'A' && c <= 'F') ||
+(c >= 'a' && c <= 'f')) {
+continue;
+}
+return false;
+}
+}
+return i == 36;
+}
+
 int qemu_uuid_parse(const char *str, QemuUUID *uuid)
 {
 unsigned char *uu = >data[0];
 int ret;
 
-if (strlen(str) != 36) {
+if (!qemu_uuid_is_valid(str)) {
 return -1;
 }
 
-- 
2.7.4




[Qemu-devel] [PULL 23/23] docker: exec $CMD

2016-09-22 Thread Fam Zheng
This is the last command to run (unless DEBUG), make it 'exec' to
simplify the process tree.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-10-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/run | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tests/docker/run b/tests/docker/run
index ed7dd31..c1e4513 100755
--- a/tests/docker/run
+++ b/tests/docker/run
@@ -57,14 +57,17 @@ cd "$QEMU_SRC/tests/docker"
 
 CMD="$QEMU_SRC/tests/docker/$@"
 
-if test -n "$DEBUG"; then
-echo "* Prepared to run command:"
-echo "  $CMD"
-echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
-echo
-$SHELL
+if test -z "$DEBUG"; then
+exec $CMD
 fi
 
+# DEBUG workflow
+echo "* Prepared to run command:"
+echo "  $CMD"
+echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
+echo
+$SHELL
+
 if "$CMD"; then
 exit 0
 elif test -n "$DEBUG"; then
-- 
2.7.4




[Qemu-devel] [PULL 14/23] tests: Ignore test-uuid

2016-09-22 Thread Fam Zheng
Signed-off-by: Fam Zheng 
Message-Id: <1474432046-325-14-git-send-email-f...@redhat.com>
Reviewed-by: Jeff Cody 
Reviewed-by: Daniel P. Berrange 
---
 tests/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/.gitignore b/tests/.gitignore
index b4a9cfc..24ac6cf 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -70,6 +70,7 @@ test-string-output-visitor
 test-thread-pool
 test-throttle
 test-timed-average
+test-uuid
 test-visitor-serialization
 test-vmstate
 test-write-threshold
-- 
2.7.4




[Qemu-devel] [PULL 12/23] tests: Add uuid tests

2016-09-22 Thread Fam Zheng
Signed-off-by: Fam Zheng 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-12-git-send-email-f...@redhat.com>
---
 tests/Makefile.include |   2 +
 tests/test-uuid.c  | 177 +
 2 files changed, 179 insertions(+)
 create mode 100644 tests/test-uuid.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 6052a38..7dcd5d2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -115,6 +115,7 @@ check-unit-y += tests/test-logging$(EXESUF)
 check-unit-$(CONFIG_REPLICATION) += tests/test-replication$(EXESUF)
 check-unit-y += tests/test-bufferiszero$(EXESUF)
 gcov-files-check-bufferiszero-y = util/bufferiszero.c
+check-unit-y += tests/test-uuid$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -658,6 +659,7 @@ tests/test-filter-mirror$(EXESUF): 
tests/test-filter-mirror.o $(qtest-obj-y)
 tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o 
$(qtest-obj-y)
 tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o 
contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y)
 tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
+tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y)
 
 tests/migration/stress$(EXESUF): tests/migration/stress.o
$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< 
,"  LINK  $(TARGET_DIR)$@")
diff --git a/tests/test-uuid.c b/tests/test-uuid.c
new file mode 100644
index 000..77dcdc4
--- /dev/null
+++ b/tests/test-uuid.c
@@ -0,0 +1,177 @@
+/*
+ * QEMU UUID Library
+ *
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/uuid.h"
+
+struct {
+const char *uuidstr;
+QemuUUID uuid;
+bool uuidstr_is_valid;
+bool check_unparse;
+} uuid_test_data[] = {
+{/* Normal */
+"586ece27-7f09-41e0-9e74-e901317e9d42",
+{ { {
+ 0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
+ 0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42,
+} } },
+true, true,
+}, { /* NULL */
+"----",
+{ },
+true, true,
+}, { /* Upper case */
+"0CC6C752-3961-4028-A286-C05CC616D396",
+{ { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+} } },
+true, false,
+}, { /* Mixed case */
+"0CC6C752-3961-4028-a286-c05cc616D396",
+{ { {
+ 0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
+ 0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
+} } },
+true, false,
+}, { /* Empty */
+""
+}, { /* Too short */
+"abc",
+}, { /* Non-hex */
+"abcdefgh----",
+}, { /* No '-' */
+"0cc6c75239614028a286c05cc616d396",
+}, { /* '-' in wrong position */
+"0cc6c-7523961-4028-a286-c05cc616d396",
+}, { /* Double '-' */
+"0cc6c752--3961-4028-a286-c05cc616d396",
+}, { /* Too long */
+"00",
+}, { /* Invalid char in the beginning */
+")cc6c752-3961-4028-a286-c05cc616d396",
+}, { /* Invalid char in the beginning, in extra */
+")0cc6c752-3961-4028-a286-c05cc616d396",
+}, { /* Invalid char in the middle */
+"0cc6c752-39*1-4028-a286-c05cc616d396",
+}, { /* Invalid char in the middle, in extra */
+"0cc6c752-39*61-4028-a286-c05cc616d396",
+}, { /* Invalid char in the end */
+"0cc6c752-3961-4028-a286-c05cc616d39&",
+}, { /* Invalid char in the end, in extra */
+"0cc6c752-3961-4028-a286-c05cc616d396&",
+}, { /* Short end and trailing space */
+"0cc6c752-3961-4028-a286-c05cc616d39 ",
+}, { /* Leading space and short end */
+" 0cc6c752-3961-4028-a286-c05cc616d39",
+},
+};
+
+static inline bool uuid_is_valid(QemuUUID *uuid)
+{
+return qemu_uuid_is_null(uuid) ||
+((uuid->data[6] & 0xf0) == 0x40 && (uuid->data[8] & 0xc0) == 0x80);
+}
+
+static void test_uuid_generate(void)
+{
+QemuUUID uuid;
+int i;
+
+for (i = 0; i < 100; ++i) {
+qemu_uuid_generate();
+g_assert(uuid_is_valid());
+}
+}
+
+static 

[Qemu-devel] [PULL 04/23] vhdx: Use QEMU UUID API

2016-09-22 Thread Fam Zheng
This removes our dependency to libuuid, so that the driver can always be
built.

Similar to how we handled data plane configure options, --enable-vhdx
and --disable-vhdx are also changed to a nop with a message saying it's
obsolete.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-4-git-send-email-f...@redhat.com>
---
 block/Makefile.objs |  2 +-
 block/vhdx-endian.c |  3 ---
 block/vhdx.c|  9 -
 configure   | 27 +++
 4 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index cb158e9..7d4031d 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -2,7 +2,7 @@ block-obj-y += raw_bsd.o qcow.o vdi.o vmdk.o cloop.o bochs.o 
vpc.o vvfat.o dmg.o
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
-block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
+block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o
 block-obj-y += quorum.o
 block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o
 block-obj-y += block-backend.o snapshot.o qapi.o
diff --git a/block/vhdx-endian.c b/block/vhdx-endian.c
index c306b90..429d755 100644
--- a/block/vhdx-endian.c
+++ b/block/vhdx-endian.c
@@ -21,9 +21,6 @@
 #include "qemu/bswap.h"
 #include "block/vhdx.h"
 
-#include 
-
-
 /*
  * All the VHDX formats on disk are little endian - the following
  * are helper import/export functions to correctly convert
diff --git a/block/vhdx.c b/block/vhdx.c
index 75ef2b1..0ba2f0a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -25,8 +25,7 @@
 #include "qemu/bswap.h"
 #include "block/vhdx.h"
 #include "migration/migration.h"
-
-#include 
+#include "qemu/uuid.h"
 
 /* Options for VHDX creation */
 
@@ -213,11 +212,11 @@ bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, 
int crc_offset)
  */
 void vhdx_guid_generate(MSGUID *guid)
 {
-uuid_t uuid;
+QemuUUID uuid;
 assert(guid != NULL);
 
-uuid_generate(uuid);
-memcpy(guid, uuid, sizeof(MSGUID));
+qemu_uuid_generate();
+memcpy(guid, , sizeof(MSGUID));
 }
 
 /* Check for region overlaps inside the VHDX image */
diff --git a/configure b/configure
index 2efc338..e4f70f1 100755
--- a/configure
+++ b/configure
@@ -317,7 +317,6 @@ vte=""
 virglrenderer=""
 tpm="yes"
 libssh2=""
-vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
@@ -1103,6 +1102,9 @@ for opt do
   --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
   echo "$0: $opt is obsolete, virtio-blk data-plane is always on" >&2
   ;;
+  --enable-vhdx|--disable-vhdx)
+  echo "$0: $opt is obsolete, VHDX driver is always built" >&2
+  ;;
   --disable-gtk) gtk="no"
   ;;
   --enable-gtk) gtk="yes"
@@ -1143,10 +1145,6 @@ for opt do
   ;;
   --enable-libssh2) libssh2="yes"
   ;;
-  --enable-vhdx) vhdx="yes"
-  ;;
-  --disable-vhdx) vhdx="no"
-  ;;
   --disable-numa) numa="no"
   ;;
   --enable-numa) numa="yes"
@@ -1389,7 +1387,6 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   archipelago Archipelago backend
   tpm TPM support
   libssh2 ssh block device support
-  vhdxsupport for the Microsoft VHDX image format
   numalibnuma support
   tcmalloctcmalloc support
   jemallocjemalloc support
@@ -2690,19 +2687,6 @@ EOF
   fi
 fi
 
-if test "$vhdx" = "yes" ; then
-if test "$uuid" = "no" ; then
-error_exit "uuid required for VHDX support"
-fi
-elif test "$vhdx" != "no" ; then
-if test "$uuid" = "yes" ; then
-vhdx=yes
-else
-vhdx=no
-fi
-fi
-
-##
 # xfsctl() probe, used for raw-posix
 if test "$xfs" != "no" ; then
   cat > $TMPC << EOF
@@ -4917,7 +4901,6 @@ echo "TPM support   $tpm"
 echo "libssh2 support   $libssh2"
 echo "TPM passthrough   $tpm_passthrough"
 echo "QOM debugging $qom_cast_debug"
-echo "vhdx  $vhdx"
 echo "lzo support   $lzo"
 echo "snappy support$snappy"
 echo "bzip2 support $bzip2"
@@ -5443,10 +5426,6 @@ if test "$libssh2" = "yes" ; then
   echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak
 fi
 
-if test "$vhdx" = "yes" ; then
-  echo "CONFIG_VHDX=y" >> $config_host_mak
-fi
-
 # USB host support
 if test "$libusb" = "yes"; then
   echo "HOST_USB=libusb legacy" >> $config_host_mak
-- 
2.7.4




[Qemu-devel] [PULL 05/23] vdi: Use QEMU UUID API

2016-09-22 Thread Fam Zheng
The UUID operations we need from libuuid are fully supported by QEMU UUID
implementation. Use it, and remove the unused code.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-5-git-send-email-f...@redhat.com>
---
 block/vdi.c | 73 ++---
 1 file changed, 17 insertions(+), 56 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index 8a1cf97..96b78d5 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -58,14 +58,7 @@
 #include "migration/migration.h"
 #include "qemu/coroutine.h"
 #include "qemu/cutils.h"
-
-#if defined(CONFIG_UUID)
-#include 
-#else
-/* TODO: move uuid emulation to some central place in QEMU. */
-#include "sysemu/sysemu.h" /* UUID_FMT */
-typedef unsigned char uuid_t[16];
-#endif
+#include "qemu/uuid.h"
 
 /* Code configuration options. */
 
@@ -140,28 +133,6 @@ typedef unsigned char uuid_t[16];
 #define VDI_DISK_SIZE_MAX((uint64_t)VDI_BLOCKS_IN_IMAGE_MAX * \
   (uint64_t)DEFAULT_CLUSTER_SIZE)
 
-#if !defined(CONFIG_UUID)
-static inline void uuid_generate(uuid_t out)
-{
-memset(out, 0, sizeof(uuid_t));
-}
-
-static inline int uuid_is_null(const uuid_t uu)
-{
-uuid_t null_uuid = { 0 };
-return memcmp(uu, null_uuid, sizeof(uuid_t)) == 0;
-}
-
-# if defined(CONFIG_VDI_DEBUG)
-static inline void uuid_unparse(const uuid_t uu, char *out)
-{
-snprintf(out, 37, UUID_FMT,
-uu[0], uu[1], uu[2], uu[3], uu[4], uu[5], uu[6], uu[7],
-uu[8], uu[9], uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
-}
-# endif
-#endif
-
 typedef struct {
 char text[0x40];
 uint32_t signature;
@@ -182,10 +153,10 @@ typedef struct {
 uint32_t block_extra;   /* unused here */
 uint32_t blocks_in_image;
 uint32_t blocks_allocated;
-uuid_t uuid_image;
-uuid_t uuid_last_snap;
-uuid_t uuid_link;
-uuid_t uuid_parent;
+QemuUUID uuid_image;
+QemuUUID uuid_last_snap;
+QemuUUID uuid_link;
+QemuUUID uuid_parent;
 uint64_t unused2[7];
 } QEMU_PACKED VdiHeader;
 
@@ -206,16 +177,6 @@ typedef struct {
 Error *migration_blocker;
 } BDRVVdiState;
 
-/* Change UUID from little endian (IPRT = VirtualBox format) to big endian
- * format (network byte order, standard, see RFC 4122) and vice versa.
- */
-static void uuid_convert(uuid_t uuid)
-{
-bswap32s((uint32_t *)[0]);
-bswap16s((uint16_t *)[4]);
-bswap16s((uint16_t *)[6]);
-}
-
 static void vdi_header_to_cpu(VdiHeader *header)
 {
 le32_to_cpus(>signature);
@@ -234,10 +195,10 @@ static void vdi_header_to_cpu(VdiHeader *header)
 le32_to_cpus(>block_extra);
 le32_to_cpus(>blocks_in_image);
 le32_to_cpus(>blocks_allocated);
-uuid_convert(header->uuid_image);
-uuid_convert(header->uuid_last_snap);
-uuid_convert(header->uuid_link);
-uuid_convert(header->uuid_parent);
+qemu_uuid_bswap(>uuid_image);
+qemu_uuid_bswap(>uuid_last_snap);
+qemu_uuid_bswap(>uuid_link);
+qemu_uuid_bswap(>uuid_parent);
 }
 
 static void vdi_header_to_le(VdiHeader *header)
@@ -258,10 +219,10 @@ static void vdi_header_to_le(VdiHeader *header)
 cpu_to_le32s(>block_extra);
 cpu_to_le32s(>blocks_in_image);
 cpu_to_le32s(>blocks_allocated);
-uuid_convert(header->uuid_image);
-uuid_convert(header->uuid_last_snap);
-uuid_convert(header->uuid_link);
-uuid_convert(header->uuid_parent);
+qemu_uuid_bswap(>uuid_image);
+qemu_uuid_bswap(>uuid_last_snap);
+qemu_uuid_bswap(>uuid_link);
+qemu_uuid_bswap(>uuid_parent);
 }
 
 #if defined(CONFIG_VDI_DEBUG)
@@ -469,11 +430,11 @@ static int vdi_open(BlockDriverState *bs, QDict *options, 
int flags,
(uint64_t)header.blocks_in_image * header.block_size);
 ret = -ENOTSUP;
 goto fail;
-} else if (!uuid_is_null(header.uuid_link)) {
+} else if (!qemu_uuid_is_null(_link)) {
 error_setg(errp, "unsupported VDI image (non-NULL link UUID)");
 ret = -ENOTSUP;
 goto fail;
-} else if (!uuid_is_null(header.uuid_parent)) {
+} else if (!qemu_uuid_is_null(_parent)) {
 error_setg(errp, "unsupported VDI image (non-NULL parent UUID)");
 ret = -ENOTSUP;
 goto fail;
@@ -821,8 +782,8 @@ static int vdi_create(const char *filename, QemuOpts *opts, 
Error **errp)
 if (image_type == VDI_TYPE_STATIC) {
 header.blocks_allocated = blocks;
 }
-uuid_generate(header.uuid_image);
-uuid_generate(header.uuid_last_snap);
+qemu_uuid_generate(_image);
+qemu_uuid_generate(_last_snap);
 /* There is no need to set header.uuid_link or header.uuid_parent here. */
 #if defined(CONFIG_VDI_DEBUG)
 vdi_header_print();
-- 
2.7.4




[Qemu-devel] [PULL 13/23] Add UUID files to MAINTAINERS

2016-09-22 Thread Fam Zheng
I understand that we've been keeping eyes on the uncovered files. Since
I'm adding some more files I volunteer to look after them in the futuer.

Signed-off-by: Fam Zheng 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-13-git-send-email-f...@redhat.com>
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 09d13bf..bc44663 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1342,6 +1342,13 @@ F: include/qemu/throttle.h
 F: util/throttle.c
 L: qemu-bl...@nongnu.org
 
+UUID
+M: Fam Zheng 
+S: Supported
+F: util/uuid.c
+F: include/qemu/uuid.h
+F: tests/test-uuid.c
+
 Usermode Emulation
 --
 Overall
-- 
2.7.4




[Qemu-devel] [PULL 20/23] docker: Print used options before doing configure

2016-09-22 Thread Fam Zheng
This makes the configure command more obvious which usually has useful
information.

Signed-off-by: Fam Zheng 
Message-Id: <1474429768-25027-7-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/docker/common.rc | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tests/docker/common.rc b/tests/docker/common.rc
index 0c6d8d5..510a3ad 100755
--- a/tests/docker/common.rc
+++ b/tests/docker/common.rc
@@ -23,11 +23,13 @@ requires()
 
 build_qemu()
 {
-$QEMU_SRC/configure \
---enable-werror \
-${TARGET_LIST:+"--target-list=${TARGET_LIST}"} \
---prefix="$PWD/install" \
-$EXTRA_CONFIGURE_OPTS \
-"$@"
+config_opts="--enable-werror \
+ ${TARGET_LIST:+--target-list=${TARGET_LIST}} \
+ --prefix=$PWD/install \
+ $EXTRA_CONFIGURE_OPTS \
+ $@"
+echo "Configure options:"
+echo $config_opts
+$QEMU_SRC/configure $config_opts
 make $MAKEFLAGS
 }
-- 
2.7.4




[Qemu-devel] [PULL 08/23] tests: No longer dependent on CONFIG_UUID

2016-09-22 Thread Fam Zheng
crypto now uses built-in uuid implementation, so this check is not
needed.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-8-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 tests/test-crypto-block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test-crypto-block.c b/tests/test-crypto-block.c
index a38110d..1957a86 100644
--- a/tests/test-crypto-block.c
+++ b/tests/test-crypto-block.c
@@ -28,7 +28,7 @@
 #include 
 #endif
 
-#if defined(CONFIG_UUID) && (defined(_WIN32) || defined RUSAGE_THREAD)
+#if (defined(_WIN32) || defined RUSAGE_THREAD)
 #define TEST_LUKS
 #else
 #undef TEST_LUKS
-- 
2.7.4




[Qemu-devel] [PULL 09/23] configure: Remove detection code for UUID

2016-09-22 Thread Fam Zheng
All code now uses built-in UUID implementation. Remove the code of
libuuid and make --enable-uuid and --disable-uuid only print a message.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-9-git-send-email-f...@redhat.com>
---
 configure | 43 ---
 1 file changed, 4 insertions(+), 39 deletions(-)

diff --git a/configure b/configure
index e4f70f1..8fa62ad 100755
--- a/configure
+++ b/configure
@@ -212,7 +212,6 @@ sdlabi=""
 virtfs=""
 vnc="yes"
 sparse="no"
-uuid=""
 vde=""
 vnc_sasl=""
 vnc_jpeg=""
@@ -886,10 +885,6 @@ for opt do
   ;;
   --disable-slirp) slirp="no"
   ;;
-  --disable-uuid) uuid="no"
-  ;;
-  --enable-uuid) uuid="yes"
-  ;;
   --disable-vde) vde="no"
   ;;
   --enable-vde) vde="yes"
@@ -1105,6 +1100,9 @@ for opt do
   --enable-vhdx|--disable-vhdx)
   echo "$0: $opt is obsolete, VHDX driver is always built" >&2
   ;;
+  --enable-uuid|--disable-uuid)
+  echo "$0: $opt is obsolete, UUID support is always built" >&2
+  ;;
   --disable-gtk) gtk="no"
   ;;
   --enable-gtk) gtk="yes"
@@ -1363,7 +1361,6 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   bluez   bluez stack connectivity
   kvm KVM acceleration support
   rdmaRDMA-based migration support
-  uuiduuid support
   vde support for vde network
   netmap  support for netmap network
   linux-aio   Linux AIO support
@@ -2659,34 +2656,6 @@ if compile_prog "" "" ; then
 fi
 
 ##
-# uuid_generate() probe, used for vdi block driver
-# Note that on some systems (notably MacOSX) no extra library
-# need be linked to get the uuid functions.
-if test "$uuid" != "no" ; then
-  uuid_libs="-luuid"
-  cat > $TMPC << EOF
-#include 
-int main(void)
-{
-uuid_t my_uuid;
-uuid_generate(my_uuid);
-return 0;
-}
-EOF
-  if compile_prog "" "" ; then
-uuid="yes"
-  elif compile_prog "" "$uuid_libs" ; then
-uuid="yes"
-libs_softmmu="$uuid_libs $libs_softmmu"
-libs_tools="$uuid_libs $libs_tools"
-  else
-if test "$uuid" = "yes" ; then
-  feature_not_found "uuid" "Install libuuid devel"
-fi
-uuid=no
-  fi
-fi
-
 # xfsctl() probe, used for raw-posix
 if test "$xfs" != "no" ; then
   cat > $TMPC << EOF
@@ -4059,7 +4028,7 @@ EOF
   if compile_prog "$vss_win32_include" "" ; then
 guest_agent_with_vss="yes"
 QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
-libs_qga="-lole32 -loleaut32 -lshlwapi -luuid -lstdc++ 
-Wl,--enable-stdcall-fixup $libs_qga"
+libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++ -Wl,--enable-stdcall-fixup 
$libs_qga"
 qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"
   else
 if test "$vss_win32_sdk" != "" ; then
@@ -4867,7 +4836,6 @@ echo "preadv support$preadv"
 echo "fdatasync $fdatasync"
 echo "madvise   $madvise"
 echo "posix_madvise $posix_madvise"
-echo "uuid support  $uuid"
 echo "libcap-ng support $cap_ng"
 echo "vhost-net support $vhost_net"
 echo "vhost-scsi support $vhost_scsi"
@@ -5057,9 +5025,6 @@ fi
 if test "$fnmatch" = "yes" ; then
   echo "CONFIG_FNMATCH=y" >> $config_host_mak
 fi
-if test "$uuid" = "yes" ; then
-  echo "CONFIG_UUID=y" >> $config_host_mak
-fi
 if test "$xfs" = "yes" ; then
   echo "CONFIG_XFS=y" >> $config_host_mak
 fi
-- 
2.7.4




[Qemu-devel] [PULL 10/23] vl: Switch qemu_uuid to QemuUUID

2016-09-22 Thread Fam Zheng
Update all qemu_uuid users as well, especially get rid of the duplicated
low level g_strdup_printf, sscanf and snprintf calls with QEMU UUID API.

Since qemu_uuid_parse is quite tangled with qemu_uuid, its switching to
QemuUUID is done here too to keep everything in sync and avoid code
churn.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-10-git-send-email-f...@redhat.com>
---
 hw/ipmi/ipmi_bmc_sim.c |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/ppc/spapr.c |  7 +--
 hw/ppc/spapr_rtas.c|  3 ++-
 hw/smbios/smbios.c | 12 ++--
 hw/xenpv/xen_domainbuild.c |  6 +-
 include/qemu/uuid.h|  2 +-
 include/sysemu/sysemu.h|  3 ++-
 qmp.c  | 10 ++
 ui/spice-core.c|  2 +-
 util/uuid.c| 11 ++-
 vl.c   |  6 +++---
 12 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index dc9c14c..17c7c0e 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -1773,7 +1773,7 @@ static void ipmi_sim_realize(DeviceState *dev, Error 
**errp)
 ibs->acpi_power_state[1] = 0;
 
 if (qemu_uuid_set) {
-memcpy(>uuid, qemu_uuid, 16);
+memcpy(>uuid, _uuid, 16);
 } else {
 memset(>uuid, 0, 16);
 }
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 1776b1b..92aa563 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -883,7 +883,7 @@ static void fw_cfg_init1(DeviceState *dev)
 qdev_init_nofail(dev);
 
 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4);
-fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
+fw_cfg_add_bytes(s, FW_CFG_UUID, _uuid, 16);
 fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)!machine->enable_graphics);
 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
 fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index ca77bb0..bdb689c 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -332,12 +332,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
 g_free(buf);
 }
 
-buf = g_strdup_printf(UUID_FMT, qemu_uuid[0], qemu_uuid[1],
-  qemu_uuid[2], qemu_uuid[3], qemu_uuid[4],
-  qemu_uuid[5], qemu_uuid[6], qemu_uuid[7],
-  qemu_uuid[8], qemu_uuid[9], qemu_uuid[10],
-  qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
-  qemu_uuid[14], qemu_uuid[15]);
+buf = qemu_uuid_unparse_strdup(_uuid);
 
 _FDT((fdt_property_string(fdt, "vm,uuid", buf)));
 if (qemu_uuid_set) {
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 27b5ad4..02ce273 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -303,7 +303,8 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
 break;
 }
 case RTAS_SYSPARM_UUID:
-ret = sysparm_st(buffer, length, qemu_uuid, (qemu_uuid_set ? 16 : 0));
+ret = sysparm_st(buffer, length, (unsigned char *)_uuid,
+ (qemu_uuid_set ? 16 : 0));
 break;
 default:
 ret = RTAS_OUT_NOT_SUPPORTED;
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 0705eb1..9a6552a 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -80,7 +80,7 @@ static struct {
 
 static struct {
 const char *manufacturer, *product, *version, *serial, *sku, *family;
-/* uuid is in qemu_uuid[] */
+/* uuid is in qemu_uuid */
 } type1;
 
 static struct {
@@ -409,7 +409,7 @@ static void smbios_build_type_1_fields(void)
  * BIOS.
  */
 smbios_add_field(1, offsetof(struct smbios_type_1, uuid),
- qemu_uuid, 16);
+ _uuid, 16);
 }
 }
 
@@ -484,9 +484,9 @@ static void smbios_build_type_0_table(void)
 /* Encode UUID from the big endian encoding described on RFC4122 to the wire
  * format specified by SMBIOS version 2.6.
  */
-static void smbios_encode_uuid(struct smbios_uuid *uuid, const uint8_t *buf)
+static void smbios_encode_uuid(struct smbios_uuid *uuid, QemuUUID *in)
 {
-memcpy(uuid, buf, 16);
+memcpy(uuid, , 16);
 if (smbios_uuid_encoded) {
 uuid->time_low = bswap32(uuid->time_low);
 uuid->time_mid = bswap16(uuid->time_mid);
@@ -503,7 +503,7 @@ static void smbios_build_type_1_table(void)
 SMBIOS_TABLE_SET_STR(1, version_str, type1.version);
 SMBIOS_TABLE_SET_STR(1, serial_number_str, type1.serial);
 if (qemu_uuid_set) {
-smbios_encode_uuid(>uuid, qemu_uuid);
+smbios_encode_uuid(>uuid, _uuid);
 } else {
 memset(>uuid, 0, 16);
 }
@@ -1002,7 +1002,7 @@ void smbios_entry_add(QemuOpts *opts)
 
 val = qemu_opt_get(opts, "uuid");
 if (val) {
-if (qemu_uuid_parse(val, 

[Qemu-devel] [PULL 07/23] crypto: Switch to QEMU UUID API

2016-09-22 Thread Fam Zheng
The uuid generation doesn't return error, so update the function
signature and calling code accordingly.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-7-git-send-email-f...@redhat.com>
Reviewed-by: Daniel P. Berrange 
---
 crypto/block-luks.c | 26 +++---
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index a848232..4530f82 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -29,10 +29,7 @@
 #include "crypto/pbkdf.h"
 #include "crypto/secret.h"
 #include "crypto/random.h"
-
-#ifdef CONFIG_UUID
-#include 
-#endif
+#include "qemu/uuid.h"
 
 #include "qemu/coroutine.h"
 
@@ -877,18 +874,12 @@ qcrypto_block_luks_open(QCryptoBlock *block,
 }
 
 
-static int
-qcrypto_block_luks_uuid_gen(uint8_t *uuidstr, Error **errp)
+static void
+qcrypto_block_luks_uuid_gen(uint8_t *uuidstr)
 {
-#ifdef CONFIG_UUID
-uuid_t uuid;
-uuid_generate(uuid);
-uuid_unparse(uuid, (char *)uuidstr);
-return 0;
-#else
-error_setg(errp, "Unable to generate uuids on this platform");
-return -1;
-#endif
+QemuUUID uuid;
+qemu_uuid_generate();
+qemu_uuid_unparse(, (char *)uuidstr);
 }
 
 static int
@@ -965,10 +956,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,
  * it out to disk
  */
 luks->header.version = QCRYPTO_BLOCK_LUKS_VERSION;
-if (qcrypto_block_luks_uuid_gen(luks->header.uuid,
-errp) < 0) {
-goto error;
-}
+qcrypto_block_luks_uuid_gen(luks->header.uuid);
 
 cipher_alg = qcrypto_block_luks_cipher_alg_lookup(luks_opts.cipher_alg,
   errp);
-- 
2.7.4




[Qemu-devel] [PULL 01/23] docker: Handle exceptions when looking for docker command

2016-09-22 Thread Fam Zheng
From: Eduardo Habkost 

When trying to run docker tests on a host without the docker
command,  we get the following Python backtrace:

  $ make docker-test-quick@centos6 V=1
  .../qemu/tests/docker/docker.py build qemu:centos6 
.../qemu/tests/docker/dockerfiles/centos6.docker
  Traceback (most recent call last):
File ".../qemu/tests/docker/docker.py", line 339, in 
  sys.exit(main())
File ".../qemu/tests/docker/docker.py", line 336, in main
  return args.cmdobj.run(args, argv)
File ".../qemu/tests/docker/docker.py", line 231, in run
  dkr = Docker()
File ".../qemu/tests/docker/docker.py", line 98, in __init__
  self._command = _guess_docker_command()
File ".../qemu/tests/docker/docker.py", line 41, in _guess_docker_command
  stdout=DEVNULL, stderr=DEVNULL) == 0:
File "/usr/lib64/python2.7/subprocess.py", line 523, in call
  return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
  errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1343, in _execute_child
  raise child_exception
  OSError: [Errno 2] No such file or directory
  .../qemu/tests/docker/Makefile.include:47: recipe for target 
'docker-image-centos6' failed
  make: *** [docker-image-centos6] Error 1

Change _guess_docker_command() to handle OSError exceptions
raised by subprocess.call(), so we will keep looking for other
commands and print a better error message.

New output will be:

  $ make docker-test-quick@centos6 V=1
  .../qemu/tests/docker/docker.py build qemu:centos6 
.../qemu/tests/docker/dockerfiles/centos6.docker
  Traceback (most recent call last):
File ".../qemu/tests/docker/docker.py", line 343, in 
  sys.exit(main())
File ".../qemu/tests/docker/docker.py", line 340, in main
  return args.cmdobj.run(args, argv)
File ".../qemu/tests/docker/docker.py", line 235, in run
  dkr = Docker()
File ".../qemu/tests/docker/docker.py", line 102, in __init__
  self._command = _guess_docker_command()
File ".../qemu/tests/docker/docker.py", line 49, in _guess_docker_command
  commands_txt)
  Exception: Cannot find working docker command. Tried:
docker
sudo -n docker
  .../qemu/tests/docker/Makefile.include:47: recipe for target 
'docker-image-centos6' failed
  make: *** [docker-image-centos6] Error 1

Signed-off-by: Eduardo Habkost 
Message-Id: <1474369559-16903-1-git-send-email-ehabk...@redhat.com>
[exceptions.OSError -> OSError and drop the import. - Fam]
Signed-off-by: Fam Zheng 
---
 tests/docker/docker.py | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index b85c165..71b0d27 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -37,9 +37,12 @@ def _guess_docker_command():
 """ Guess a working docker command or raise exception if not found"""
 commands = [["docker"], ["sudo", "-n", "docker"]]
 for cmd in commands:
-if subprocess.call(cmd + ["images"],
-   stdout=DEVNULL, stderr=DEVNULL) == 0:
-return cmd
+try:
+if subprocess.call(cmd + ["images"],
+   stdout=DEVNULL, stderr=DEVNULL) == 0:
+return cmd
+except OSError:
+pass
 commands_txt = "\n".join(["  " + " ".join(x) for x in commands])
 raise Exception("Cannot find working docker command. Tried:\n%s" % \
 commands_txt)
-- 
2.7.4




[Qemu-devel] [PULL 02/23] util: Add UUID API

2016-09-22 Thread Fam Zheng
A number of different places across the code base use CONFIG_UUID. Some
of them are soft dependency, some are not built if libuuid is not
available, some come with dummy fallback, some throws runtime error.

It is hard to maintain, and hard to reason for users.

Since UUID is a simple standard with only a small number of operations,
it is cleaner to have a central support in libqemuutil. This patch adds
qemu_uuid_* functions that all uuid users in the code base can
rely on. Except for qemu_uuid_generate which is new code, all other
functions are just copy from existing fallbacks from other files.

Note that qemu_uuid_parse is moved without updating the function
signature to use QemuUUID, to keep this patch simple.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-2-git-send-email-f...@redhat.com>
---
 arch_init.c | 19 ---
 block/iscsi.c   |  2 +-
 hw/smbios/smbios.c  |  1 +
 include/qemu/uuid.h | 59 
 include/sysemu/sysemu.h |  4 ---
 qmp.c   |  1 +
 stubs/uuid.c|  2 +-
 util/Makefile.objs  |  1 +
 util/uuid.c | 91 +
 vl.c|  1 +
 10 files changed, 156 insertions(+), 25 deletions(-)
 create mode 100644 include/qemu/uuid.h
 create mode 100644 util/uuid.c

diff --git a/arch_init.c b/arch_init.c
index fa05973..5cc58b2 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -235,25 +235,6 @@ void audio_init(void)
 }
 }
 
-int qemu_uuid_parse(const char *str, uint8_t *uuid)
-{
-int ret;
-
-if (strlen(str) != 36) {
-return -1;
-}
-
-ret = sscanf(str, UUID_FMT, [0], [1], [2], [3],
- [4], [5], [6], [7], [8], [9],
- [10], [11], [12], [13], [14],
- [15]);
-
-if (ret != 16) {
-return -1;
-}
-return 0;
-}
-
 void do_acpitable_option(const QemuOpts *opts)
 {
 #ifdef TARGET_I386
diff --git a/block/iscsi.c b/block/iscsi.c
index c4a0937..40f88a2 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -36,7 +36,7 @@
 #include "block/block_int.h"
 #include "block/scsi.h"
 #include "qemu/iov.h"
-#include "sysemu/sysemu.h"
+#include "qemu/uuid.h"
 #include "qmp-commands.h"
 #include "qapi/qmp/qstring.h"
 #include "crypto/secret.h"
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 74c7102..0705eb1 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -20,6 +20,7 @@
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
+#include "qemu/uuid.h"
 #include "sysemu/cpus.h"
 #include "hw/smbios/smbios.h"
 #include "hw/loader.h"
diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
new file mode 100644
index 000..bc0601e
--- /dev/null
+++ b/include/qemu/uuid.h
@@ -0,0 +1,59 @@
+/*
+ *  QEMU UUID functions
+ *
+ *  Copyright 2016 Red Hat, Inc.
+ *
+ *  Authors:
+ *   Fam Zheng 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+
+#ifndef QEMU_UUID_H
+#define QEMU_UUID_H
+
+#include "qemu-common.h"
+
+/* Version 4 UUID (pseudo random numbers), RFC4122 4.4. */
+
+typedef struct {
+union {
+unsigned char data[16];
+struct {
+/* Generated in BE endian, can be swapped with qemu_uuid_bswap. */
+uint32_t time_low;
+uint16_t time_mid;
+uint16_t time_high_and_version;
+uint8_t  clock_seq_and_reserved;
+uint8_t  clock_seq_low;
+uint8_t  node[6];
+} fields;
+};
+} QemuUUID;
+
+#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \
+ "%02hhx%02hhx-%02hhx%02hhx-" \
+ "%02hhx%02hhx-" \
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
+#define UUID_FMT_LEN 36
+
+#define UUID_NONE "----"
+
+void qemu_uuid_generate(QemuUUID *out);
+
+int qemu_uuid_is_null(const QemuUUID *uu);
+
+void qemu_uuid_unparse(const QemuUUID *uuid, char *out);
+
+char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
+
+int qemu_uuid_parse(const char *str, uint8_t *uuid);
+
+void qemu_uuid_bswap(QemuUUID *uuid);
+
+#endif
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index ee7c760..6111950 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -18,10 +18,6 @@ extern const char *bios_name;
 extern const char *qemu_name;
 extern uint8_t qemu_uuid[];
 extern bool qemu_uuid_set;
-int qemu_uuid_parse(const char *str, uint8_t *uuid);
-
-#define UUID_FMT 
"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-#define UUID_NONE "----"
 
 bool 

[Qemu-devel] [PULL 03/23] uuid: Make null_uuid static

2016-09-22 Thread Fam Zheng
So that it doesn't have to be zeroed at each call.

Suggested-by: Eric Blake 
Signed-off-by: Fam Zheng 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-3-git-send-email-f...@redhat.com>
---
 util/uuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/uuid.c b/util/uuid.c
index 6815904..f0c1eeb 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -40,7 +40,7 @@ void qemu_uuid_generate(QemuUUID *uuid)
 
 int qemu_uuid_is_null(const QemuUUID *uu)
 {
-QemuUUID null_uuid = { 0 };
+static QemuUUID null_uuid;
 return memcmp(uu, _uuid, sizeof(QemuUUID)) == 0;
 }
 
-- 
2.7.4




[Qemu-devel] [PULL 00/23] Various patches

2016-09-22 Thread Fam Zheng
The following changes since commit 430da7a81d356e368ccd88dcca60f38da9aa5b9a:

  Merge remote-tracking branch 'remotes/riku/tags/pull-linux-user-20160915' 
into staging (2016-09-22 15:39:54 +0100)

are available in the git repository at:

  g...@github.com:famz/qemu tags/various-pull-request

for you to fetch changes up to 9b77336d83b73f7585cc2dbc565d377940905191:

  docker: exec $CMD (2016-09-23 11:48:32 +0800)



This includes my UUID clean ups, docker SHOW_ENV feature and Eduardo's
docker.py improvement.



Eduardo Habkost (1):
  docker: Handle exceptions when looking for docker command

Fam Zheng (22):
  util: Add UUID API
  uuid: Make null_uuid static
  vhdx: Use QEMU UUID API
  vdi: Use QEMU UUID API
  vpc: Use QEMU UUID API
  crypto: Switch to QEMU UUID API
  tests: No longer dependent on CONFIG_UUID
  configure: Remove detection code for UUID
  vl: Switch qemu_uuid to QemuUUID
  uuid: Tighten uuid parse
  tests: Add uuid tests
  Add UUID files to MAINTAINERS
  tests: Ignore test-uuid
  docker: Generate /packages.txt in centos6 image
  docker: Generate /packages.txt in fedora image
  docker: Generate /packages.txt in ubuntu image
  docker: Update fedora image to latest
  docker: Flatten default target list in test-quick
  docker: Print used options before doing configure
  docker: Support showing environment information
  docker: Terminate instances at SIGTERM and SIGHUP
  docker: exec $CMD

 MAINTAINERS |   7 ++
 arch_init.c |  19 
 block/Makefile.objs |   2 +-
 block/iscsi.c   |   2 +-
 block/vdi.c |  73 +++--
 block/vhdx-endian.c |   3 -
 block/vhdx.c|   9 +-
 block/vpc.c |  10 +-
 configure   |  70 ++---
 crypto/block-luks.c |  26 ++---
 hw/ipmi/ipmi_bmc_sim.c  |   2 +-
 hw/nvram/fw_cfg.c   |   2 +-
 hw/ppc/spapr.c  |   7 +-
 hw/ppc/spapr_rtas.c |   3 +-
 hw/smbios/smbios.c  |  13 +--
 hw/xenpv/xen_domainbuild.c  |   6 +-
 include/qemu/uuid.h |  59 +++
 include/sysemu/sysemu.h |   7 +-
 qmp.c   |  11 +-
 stubs/uuid.c|   2 +-
 tests/.gitignore|   1 +
 tests/Makefile.include  |   2 +
 tests/docker/Makefile.include   |   2 +-
 tests/docker/common.rc  |  14 +--
 tests/docker/docker.py  |  14 ++-
 tests/docker/dockerfiles/centos6.docker |   6 +-
 tests/docker/dockerfiles/fedora.docker  |  16 ++-
 tests/docker/dockerfiles/ubuntu.docker  |   4 +-
 tests/docker/run|  26 +++--
 tests/docker/test-quick |   2 +-
 tests/test-crypto-block.c   |   2 +-
 tests/test-uuid.c   | 177 
 ui/spice-core.c |   2 +-
 util/Makefile.objs  |   1 +
 util/uuid.c | 114 
 vl.c|   7 +-
 36 files changed, 486 insertions(+), 237 deletions(-)
 create mode 100644 include/qemu/uuid.h
 create mode 100644 tests/test-uuid.c
 create mode 100644 util/uuid.c

-- 
2.7.4




[Qemu-devel] [PULL 06/23] vpc: Use QEMU UUID API

2016-09-22 Thread Fam Zheng
Previously we conditionally generated footer->uuid, when libuuid was
available. Now that we have a built-in implementation, we can switch to
it.

Signed-off-by: Fam Zheng 
Reviewed-by: Eric Blake 
Reviewed-by: Jeff Cody 
Message-Id: <1474432046-325-6-git-send-email-f...@redhat.com>
---
 block/vpc.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 43707ed..8d5886f 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -30,9 +30,7 @@
 #include "qemu/module.h"
 #include "migration/migration.h"
 #include "qemu/bswap.h"
-#if defined(CONFIG_UUID)
-#include 
-#endif
+#include "qemu/uuid.h"
 
 /**/
 
@@ -89,7 +87,7 @@ typedef struct vhd_footer {
 uint32_tchecksum;
 
 /* UUID used to identify a parent hard disk (backing file) */
-uint8_t uuid[16];
+QemuUUIDuuid;
 
 uint8_t in_saved_state;
 } QEMU_PACKED VHDFooter;
@@ -980,9 +978,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, 
Error **errp)
 
 footer->type = cpu_to_be32(disk_type);
 
-#if defined(CONFIG_UUID)
-uuid_generate(footer->uuid);
-#endif
+qemu_uuid_generate(>uuid);
 
 footer->checksum = cpu_to_be32(vpc_checksum(buf, HEADER_SIZE));
 
-- 
2.7.4




[Qemu-devel] [PATCH v7 3/3] intel_iommu: allow UNMAP notifiers

2016-09-22 Thread Peter Xu
Intel vIOMMU is still lacking of a complete IOMMU notifier mechanism.
Before that is achieved, let's open a door for vhost DMAR support, which
only requires cache invalidations (UNMAP operations).

Meanwhile, converting hw_error() to error_report() and exit(1), to make
the error messages clean and obvious (so no CPU registers will be
dumped).

Reviewed-by: David Gibson 
Signed-off-by: Peter Xu 
---
 hw/i386/intel_iommu.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 9d49be7..e4c3681 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1980,10 +1980,14 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion 
*iommu,
 {
 VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
 
-hw_error("Device at bus %s addr %02x.%d requires iommu notifier which "
- "is currently not supported by intel-iommu emulation",
- vtd_as->bus->qbus.name, PCI_SLOT(vtd_as->devfn),
- PCI_FUNC(vtd_as->devfn));
+if (new & IOMMU_NOTIFIER_MAP) {
+error_report("Device at bus %s addr %02x.%d requires iommu "
+ "notifier which is currently not supported by "
+ "intel-iommu emulation",
+ vtd_as->bus->qbus.name, PCI_SLOT(vtd_as->devfn),
+ PCI_FUNC(vtd_as->devfn));
+exit(1);
+}
 }
 
 static const VMStateDescription vtd_vmstate = {
-- 
2.7.4




[Qemu-devel] [PATCH v7 2/3] memory: introduce IOMMUOps.notify_flag_changed

2016-09-22 Thread Peter Xu
The new interface can be used to replace the old notify_started() and
notify_stopped(). Meanwhile it provides explicit flags so that IOMMUs
can know what kind of notifications it is requested for.

Acked-by: David Gibson 
Signed-off-by: Peter Xu 
---
 hw/i386/intel_iommu.c |  6 --
 hw/ppc/spapr_iommu.c  | 18 ++
 include/exec/memory.h |  9 +
 memory.c  | 29 +
 4 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 28c31a2..9d49be7 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1974,7 +1974,9 @@ static IOMMUTLBEntry vtd_iommu_translate(MemoryRegion 
*iommu, hwaddr addr,
 return ret;
 }
 
-static void vtd_iommu_notify_started(MemoryRegion *iommu)
+static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu,
+  IOMMUNotifierFlag old,
+  IOMMUNotifierFlag new)
 {
 VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
 
@@ -2348,7 +2350,7 @@ static void vtd_init(IntelIOMMUState *s)
 memset(s->womask, 0, DMAR_REG_SIZE);
 
 s->iommu_ops.translate = vtd_iommu_translate;
-s->iommu_ops.notify_started = vtd_iommu_notify_started;
+s->iommu_ops.notify_flag_changed = vtd_iommu_notify_flag_changed;
 s->root = 0;
 s->root_extended = false;
 s->dmar_enabled = false;
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index f20b0b8..ae30bbe 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -156,14 +156,17 @@ static uint64_t spapr_tce_get_min_page_size(MemoryRegion 
*iommu)
 return 1ULL << tcet->page_shift;
 }
 
-static void spapr_tce_notify_started(MemoryRegion *iommu)
+static void spapr_tce_notify_flag_changed(MemoryRegion *iommu,
+  IOMMUNotifierFlag old,
+  IOMMUNotifierFlag new)
 {
-spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), true);
-}
+struct sPAPRTCETable *tbl = container_of(iommu, sPAPRTCETable, iommu);
 
-static void spapr_tce_notify_stopped(MemoryRegion *iommu)
-{
-spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), false);
+if (old == IOMMU_NOTIFIER_NONE && new != IOMMU_NOTIFIER_NONE) {
+spapr_tce_set_need_vfio(tbl, true);
+} else if (old != IOMMU_NOTIFIER_NONE && new == IOMMU_NOTIFIER_NONE) {
+spapr_tce_set_need_vfio(tbl, false);
+}
 }
 
 static int spapr_tce_table_post_load(void *opaque, int version_id)
@@ -246,8 +249,7 @@ static const VMStateDescription vmstate_spapr_tce_table = {
 static MemoryRegionIOMMUOps spapr_iommu_ops = {
 .translate = spapr_tce_translate_iommu,
 .get_min_page_size = spapr_tce_get_min_page_size,
-.notify_started = spapr_tce_notify_started,
-.notify_stopped = spapr_tce_notify_stopped,
+.notify_flag_changed = spapr_tce_notify_flag_changed,
 };
 
 static int spapr_tce_table_realize(DeviceState *dev)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 14cda67..a3f988b 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -174,10 +174,10 @@ struct MemoryRegionIOMMUOps {
 IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool 
is_write);
 /* Returns minimum supported page size */
 uint64_t (*get_min_page_size)(MemoryRegion *iommu);
-/* Called when the first notifier is set */
-void (*notify_started)(MemoryRegion *iommu);
-/* Called when the last notifier is removed */
-void (*notify_stopped)(MemoryRegion *iommu);
+/* Called when IOMMU Notifier flag changed */
+void (*notify_flag_changed)(MemoryRegion *iommu,
+IOMMUNotifierFlag old_flags,
+IOMMUNotifierFlag new_flags);
 };
 
 typedef struct CoalescedMemoryRange CoalescedMemoryRange;
@@ -223,6 +223,7 @@ struct MemoryRegion {
 unsigned ioeventfd_nb;
 MemoryRegionIoeventfd *ioeventfds;
 QLIST_HEAD(, IOMMUNotifier) iommu_notify;
+IOMMUNotifierFlag iommu_notify_flags;
 };
 
 /**
diff --git a/memory.c b/memory.c
index 69d9d9a..27a3f2f 100644
--- a/memory.c
+++ b/memory.c
@@ -1414,6 +1414,7 @@ void memory_region_init_iommu(MemoryRegion *mr,
 mr->iommu_ops = ops,
 mr->terminates = true;  /* then re-forwards */
 QLIST_INIT(>iommu_notify);
+mr->iommu_notify_flags = IOMMU_NOTIFIER_NONE;
 }
 
 static void memory_region_finalize(Object *obj)
@@ -1508,16 +1509,31 @@ bool memory_region_is_logging(MemoryRegion *mr, uint8_t 
client)
 return memory_region_get_dirty_log_mask(mr) & (1 << client);
 }
 
+static void memory_region_update_iommu_notify_flags(MemoryRegion *mr)
+{
+IOMMUNotifierFlag flags = IOMMU_NOTIFIER_NONE;
+IOMMUNotifier *iommu_notifier;
+
+QLIST_FOREACH(iommu_notifier, >iommu_notify, node) {
+flags |= iommu_notifier->notifier_flags;
+   

[Qemu-devel] [PATCH v7 1/3] memory: introduce IOMMUNotifier and its caps

2016-09-22 Thread Peter Xu
IOMMU Notifier list is used for notifying IO address mapping changes.
Currently VFIO is the only user.

However it is possible that future consumer like vhost would like to
only listen to part of its notifications (e.g., cache invalidations).

This patch introduced IOMMUNotifier and IOMMUNotfierFlag bits for a
finer grained control of it.

IOMMUNotifier contains a bitfield for the notify consumer describing
what kind of notification it is interested in. Currently two kinds of
notifications are defined:

- IOMMU_NOTIFIER_MAP:for newly mapped entries (additions)
- IOMMU_NOTIFIER_UNMAP:  for entries to be removed (cache invalidates)

When registering the IOMMU notifier, we need to specify one or multiple
types of messages to listen to.

When notifications are triggered, its type will be checked against the
notifier's type bits, and only notifiers with registered bits will be
notified.

(For any IOMMU implementation, an in-place mapping change should be
 notified with an UNMAP followed by a MAP.)

Signed-off-by: Peter Xu 
---
 hw/vfio/common.c  |  4 ++--
 include/exec/memory.h | 47 ---
 include/hw/vfio/vfio-common.h |  2 +-
 memory.c  | 37 +-
 4 files changed, 71 insertions(+), 19 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index b313e7c..29188a1 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -293,11 +293,10 @@ static bool 
vfio_listener_skipped_section(MemoryRegionSection *section)
section->offset_within_address_space & (1ULL << 63);
 }
 
-static void vfio_iommu_map_notify(Notifier *n, void *data)
+static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
 {
 VFIOGuestIOMMU *giommu = container_of(n, VFIOGuestIOMMU, n);
 VFIOContainer *container = giommu->container;
-IOMMUTLBEntry *iotlb = data;
 hwaddr iova = iotlb->iova + giommu->iommu_offset;
 MemoryRegion *mr;
 hwaddr xlat;
@@ -454,6 +453,7 @@ static void vfio_listener_region_add(MemoryListener 
*listener,
section->offset_within_region;
 giommu->container = container;
 giommu->n.notify = vfio_iommu_map_notify;
+giommu->n.notifier_flags = IOMMU_NOTIFIER_ALL;
 QLIST_INSERT_HEAD(>giommu_list, giommu, giommu_next);
 
 memory_region_register_iommu_notifier(giommu->iommu, >n);
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 3e4d416..14cda67 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -67,6 +67,27 @@ struct IOMMUTLBEntry {
 IOMMUAccessFlags perm;
 };
 
+/*
+ * Bitmap for different IOMMUNotifier capabilities. Each notifier can
+ * register with one or multiple IOMMU Notifier capability bit(s).
+ */
+typedef enum {
+IOMMU_NOTIFIER_NONE = 0,
+/* Notify cache invalidations */
+IOMMU_NOTIFIER_UNMAP = 0x1,
+/* Notify entry changes (newly created entries) */
+IOMMU_NOTIFIER_MAP = 0x2,
+} IOMMUNotifierFlag;
+
+#define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP)
+
+struct IOMMUNotifier {
+void (*notify)(struct IOMMUNotifier *notifier, IOMMUTLBEntry *data);
+IOMMUNotifierFlag notifier_flags;
+QLIST_ENTRY(IOMMUNotifier) node;
+};
+typedef struct IOMMUNotifier IOMMUNotifier;
+
 /* New-style MMIO accessors can indicate that the transaction failed.
  * A zero (MEMTX_OK) response means success; anything else is a failure
  * of some kind. The memory subsystem will bitwise-OR together results
@@ -201,7 +222,7 @@ struct MemoryRegion {
 const char *name;
 unsigned ioeventfd_nb;
 MemoryRegionIoeventfd *ioeventfds;
-NotifierList iommu_notify;
+QLIST_HEAD(, IOMMUNotifier) iommu_notify;
 };
 
 /**
@@ -607,6 +628,15 @@ uint64_t 
memory_region_iommu_get_min_page_size(MemoryRegion *mr);
 /**
  * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
  *
+ * The notification type will be decided by entry.perm bits:
+ *
+ * - For UNMAP (cache invalidation) notifies: set entry.perm to IOMMU_NONE.
+ * - For MAP (newly added entry) notifies: set entry.perm to the
+ *   permission of the page (which is definitely !IOMMU_NONE).
+ *
+ * Note: for any IOMMU implementation, an in-place mapping change
+ * should be notified with an UNMAP followed by a MAP.
+ *
  * @mr: the memory region that was changed
  * @entry: the new entry in the IOMMU translation table.  The entry
  * replaces all old entries for the same virtual I/O address range.
@@ -620,11 +650,12 @@ void memory_region_notify_iommu(MemoryRegion *mr,
  * IOMMU translation entries.
  *
  * @mr: the memory region to observe
- * @n: the notifier to be added; the notifier receives a pointer to an
- * #IOMMUTLBEntry as the opaque value; the pointer ceases to be
- * valid on exit from the notifier.
+ * @n: the IOMMUNotifier to be added; the notify callback receives a
+ * pointer to an #IOMMUTLBEntry as the 

[Qemu-devel] [PATCH v7 0/3] Introduce IOMMUNotifier struct

2016-09-22 Thread Peter Xu
V7:
- add comments to memory_region_notify_iommu() to better clarify the
  interface [David]
- vfio_iommu_map_notify(): remove pointless "IOMMUTLBEntry *iotlb =
  data" [David]
- typo fix on English [David]

V6:
- use IOMMUTLBEntry directly for IOMMUNotifier.notify() [David]
- add explicit comment for patch 1 that CHANGE should be treated as a
  MAP then an UNMAP [David]
- add a-b for David on patch 2

V5:
- squash spapr_tce_notify_{started|stopped} into
  spapr_tce_notify_flag_changed [David]
- in spapr_tce_notify_flag_changed: check flags against "!=
  IOMMU_NOTIFIER_NONE", but not "== IOMMU_NOTIFIER_ALL" [David]
- add r-b for David on patch 3

V4:
- change "notifier_caps" into "notifier_flags" [David]
- rename IOMMU_NOTIFIER_{CHANGE|INVALIDATION} with MAP/UNMAP [David]
- introduce IOMMUOps.notify_flag_changed, to replace notify_started
  and notify_stopped [David, Paolo]

V3:
- use QLIST instead of embedding Notifier into IOMMUNotifier [Paolo]
- fix a build error for ppc64-softmmu

The idea originates from one of Alex's reply:

  https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg00254.html

But after further discussions, it seems that only adding a simple type
for notifier is not enough. This series introduced IOMMUNotifier
struct to replace the old Notifier interface. Along with it, we can
provide registration for one (or multiple) of the IOMMU notifications:

- cache invalidations
- entry changes

This is a support material for Jason's vhost dmar patchset.

Please read commit messages for detailed information. Thanks,

Peter Xu (3):
  memory: introduce IOMMUNotifier and its caps
  memory: introduce IOMMUOps.notify_flag_changed
  intel_iommu: allow UNMAP notifiers

 hw/i386/intel_iommu.c | 18 -
 hw/ppc/spapr_iommu.c  | 18 +++--
 hw/vfio/common.c  |  4 +--
 include/exec/memory.h | 56 
 include/hw/vfio/vfio-common.h |  2 +-
 memory.c  | 60 +--
 6 files changed, 116 insertions(+), 42 deletions(-)

-- 
2.7.4




Re: [Qemu-devel] [PATCH 4/7] e1000e: Fix PBACLR implementation

2016-09-22 Thread Jason Wang



On 2016年09月22日 17:01, Dmitry Fleytman wrote:

On 22 Sep 2016, at 09:40 AM, Jason Wang  wrote:



On 2016年09月15日 14:14, Dmitry Fleytman wrote:

This patch fixes incorrect check for
interrypt type being used.

PBSCLR register is valid for MSI-X only.

See spec. 10.2.3.13 MSI—X PBA Clear

Signed-off-by: Dmitry Fleytman 
---
  hw/net/e1000e_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
index 22765cb..c38ed10 100644
--- a/hw/net/e1000e_core.c
+++ b/hw/net/e1000e_core.c
@@ -2347,7 +2347,7 @@ e1000e_set_pbaclr(E1000ECore *core, int index, uint32_t 
val)
core->mac[PBACLR] = val & E1000_PBACLR_VALID_MASK;
  -if (msix_enabled(core->owner)) {
+if (!msix_enabled(core->owner)) {
  return;
  }
  

Spec also said "writing 0b has no effect". So we'd better implement this 
behavior too?


Hi Jason,

Not sure I understand you correctly.

With current implementation, writing 0b does nothing
except that it changes value of PBACLR being read.

I just verified that physical device behaves exactly like this.

Is this what you meant?

~Dmitry



Yes, then it looks fine to me.

Thanks




[Qemu-devel] [PATCH] KVM: x86: handle KVM_SET_VCPU_EVENTS/KVM_VCPUEVENT_VALID_SMM properly

2016-09-22 Thread herongguang
From: He Rongguang 

handle KVM_VCPUEVENT_VALID_SMM properly, or kvm-kmod/kernel will crash
in migration destination in gfn_to_rmap() since kvm_memslots_for_spte_role
is false, whilst (vcpu->arch.hflags & HF_SMM_MASK) is true

Signed-off-by: herongguang 
---
 arch/x86/kvm/x86.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 699f872..7ebcb59 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3028,6 +3028,7 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct 
kvm_vcpu *vcpu,
else
clear_bit(KVM_APIC_INIT, 
>arch.apic->pending_events);
}
+   kvm_mmu_reset_context(vcpu);
}
 
kvm_make_request(KVM_REQ_EVENT, vcpu);
-- 
1.8.3.4





Re: [Qemu-devel] [PATCH 3/3] tests/docker/Makefile.include: add a generic docker-run target

2016-09-22 Thread Fam Zheng
On Thu, 09/22 14:57, Alex Bennée wrote:
> This re-factors the docker makefile to include a docker-run target which
> can be controlled entirely from environment variables specified on the
> make command line. This allows us to run against any given docker image
> we may have in our repository, for example:
> 
> make docker-run TEST="test-quick" IMAGE="debian:arm64" \
>  EXECUTABLE=./aarch64-linux-user/qemu-aarch64
> 
> The existing docker-foo@bar targets still work but the inline
> verification has been shunted into other target prerequisites before a
> sub-make is invoked for the docker-run target.
> 
> Signed-off-by: Alex Bennée 

You probably need to rebase as a pull req is on the way that updates this file
and causes conflict.

> 
> ---
> NB: I dropped the awk magic that verifies the image exists before
> running. I couldn't get the thing to work in my shell so wasn't quite
> sure what it was doing.

Does this mean that "make docker-test" will unconditionally run
debian-bootstrap and fail if binfmt is not setup properly?

Fam

> 
> v2
>  - fix spelling on arbitrary
>  - document docker-run in help
>  - add note on docker.py update
>  - reduce noise on verifying other images
>  - revert back to using filter
> ---
>  tests/docker/Makefile.include | 88 
> ---
>  1 file changed, 65 insertions(+), 23 deletions(-)
> 
> diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
> index 19d4cc7..5f71293 100644
> --- a/tests/docker/Makefile.include
> +++ b/tests/docker/Makefile.include
> @@ -78,6 +78,7 @@ docker:
>   @echo ' "IMAGE" is one of the listed container 
> name."'
>   @echo 'docker-image:Build all images.'
>   @echo 'docker-image-IMAGE:  Build image "IMAGE".'
> + @echo 'docker-run:  For manually running a "TEST" with 
> "IMAGE"'
>   @echo
>   @echo 'Available container images:'
>   @echo '$(DOCKER_IMAGES)'
> @@ -101,31 +102,72 @@ docker:
>   @echo 'NOCACHE=1Ignore cache when build images.'
>   @echo 'EXECUTABLE=Include executable in image.'
>  
> -docker-run-%: CMD = $(shell echo '$@' | sed -e 
> 's/docker-run-\([^@]*\)@\(.*\)/\1/')
> -docker-run-%: IMAGE = $(shell echo '$@' | sed -e 
> 's/docker-run-\([^@]*\)@\(.*\)/\2/')
> -docker-run-%: docker-qemu-src
> +# This rule if for directly running against an arbitrary docker target.
> +# It is called by the expanded docker targets (e.g. make
> +# docker-test-foo@bar) which will do additional verification.
> +#
> +# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" 
> EXECUTABLE=./aarch64-linux-user/qemu-aarch64
> +#
> +docker-run: docker-qemu-src
>   @mkdir -p "$(DOCKER_CCACHE_DIR)"
> - @if test -z "$(IMAGE)" || test -z "$(CMD)"; \
> - then echo "Invalid target"; exit 1; \
> + @if test -z "$(IMAGE)" || test -z "$(TEST)"; \
> + then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
> + fi
> + $(if $(EXECUTABLE), \
> + $(call quiet-command,   \
> + $(SRC_PATH)/tests/docker/docker.py update   \
> + $(IMAGE) $(EXECUTABLE), \
> + "  COPYING $(EXECUTABLE) to $(IMAGE)"))
> + $(call quiet-command,   \
> + $(SRC_PATH)/tests/docker/docker.py run  \
> + -t  \
> + $(if $V,,--rm)  \
> + $(if $(DEBUG),-i,--net=none)\
> + -e TARGET_LIST=$(TARGET_LIST)   \
> + -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
> + -e V=$V -e J=$J -e DEBUG=$(DEBUG)   \
> + -e CCACHE_DIR=/var/tmp/ccache   \
> + -v $$(readlink -e 
> $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
> + -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z   \
> + $(IMAGE)\
> + /var/tmp/qemu/run   \
> + $(TEST), "  RUN $(TEST) in ${IMAGE}")
> +
> +#
> +# Verification targets
> +#
> +# These targets help verify the test (CMD) and docker tag (IMAGE) are
> +# part of the built in set of tests and images. You can still call the
> +# docker-run target directly for testsing against arbitary images.
> +#
> +
> +docker-verify-image-%: IMAGE = $(shell echo '$@' | sed -e 
> 's/docker-verify-image-\([^@]*\)@\(.*\)/\2/')
> +docker-verify-image-%:
> + @if test -z "$(IMAGE)"; \
> + then echo "Invalid image"; exit 1;  \
>   fi
> - 

Re: [Qemu-devel] [PATCH 2/3] tests/docker: test-build script

2016-09-22 Thread Fam Zheng
On Thu, 09/22 14:57, Alex Bennée wrote:
> Much like test-quick but only builds. This is useful for some of the
> build targets like ThreadSanitizer that don't yet pass "make check".
> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/docker/test-build | 18 ++
>  1 file changed, 18 insertions(+)
>  create mode 100755 tests/docker/test-build
> 
> diff --git a/tests/docker/test-build b/tests/docker/test-build
> new file mode 100755
> index 000..d237ead
> --- /dev/null
> +++ b/tests/docker/test-build
> @@ -0,0 +1,18 @@
> +#!/bin/bash -e
> +#
> +# Quick compiling test that everyone already does. But why not automate it?

Could you update the header to reflect the reason in the commit message?

> +#
> +# Copyright (c) 2016 Red Hat Inc.
> +#
> +# Authors:
> +#  Fam Zheng 
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +. common.rc
> +
> +DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)"

As seen in the other series I pointed out in reply to patch 1, this has been
expanded in test-quick.

> +TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \
> +build_qemu
> -- 
> 2.9.3
> 

Fam



Re: [Qemu-devel] [PATCH 1/3] tests/docker: add travis dockerfile

2016-09-22 Thread Fam Zheng
On Thu, 09/22 14:57, Alex Bennée wrote:
> This target grabs the latest Travis containers from their repository at
> quay.io and then installs QEMU's build dependencies. With this it is
> possible to run on broadly the same setup as they have on travis-ci.org.

This is nice, Thanks!

> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/docker/dockerfiles/travis.docker | 6 ++
>  1 file changed, 6 insertions(+)
>  create mode 100644 tests/docker/dockerfiles/travis.docker
> 
> diff --git a/tests/docker/dockerfiles/travis.docker 
> b/tests/docker/dockerfiles/travis.docker
> new file mode 100644
> index 000..e4983ae
> --- /dev/null
> +++ b/tests/docker/dockerfiles/travis.docker
> @@ -0,0 +1,6 @@
> +FROM quay.io/travisci/travis-ruby
> +RUN apt-get update
> +RUN apt-get -y build-dep qemu
> +RUN apt-get -y build-dep device-tree-compiler
> +RUN apt-get -y install python2.7 dh-autoreconf
> +ENV FEATURES pyyaml

Other images now have a /packages.txt listing installed packages,
that can be dumped with SHOW_ENV=1:

https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg04925.html

In this image the list is not explicit. While the file is not mandatory, is it
worth to do something like

RUN apt-rdepends --build-depends qemu > /packges.txt

?

Fam



Re: [Qemu-devel] [PATCH v5 0/3] block: allow flush on devices with open tray

2016-09-22 Thread Fam Zheng
On Thu, 09/22 21:45, John Snow wrote:
> When I said "Final re-send," I was lying. Here's a v5.
> The title is also a misnomer by now :)
> 
> The move to blk_flush altered the behavior of migration and flushing
> nodes that are not reachable via the guest, but are still reachable
> via QEMU and may or may not need to be flushed.
> 
> This is intended for 2.6.2 and/or 2.7.1, to fix problems with libvirt
> et al being unable to migrate QEMU when the CDROM tray is open.
> 
> v5:
>  Fix bracket spacing in patch 1. By one space. :(
>  Added third patch to remove blk_flush_all.
> 
> v4:
>  Commit message update.
> 
> v3:
>  Reworking approach and reinstating bdrv_flush_all at Kevin's suggestion.
> 
> 
> 
> For convenience, this branch is available at:
> https://github.com/jnsnow/qemu.git branch atapi-tray-migfix
> https://github.com/jnsnow/qemu/tree/atapi-tray-migfix
> 
> This version is tagged atapi-tray-migfix-v5:
> https://github.com/jnsnow/qemu/releases/tag/atapi-tray-migfix-v5
> 
> John Snow (3):
>   block: reintroduce bdrv_flush_all
>   qemu: use bdrv_flush_all for vm_stop et al
>   block-backend: remove blk_flush_all
> 
>  block/block-backend.c  | 22 --
>  block/io.c | 25 +
>  cpus.c |  4 ++--
>  hw/i386/xen/xen_platform.c |  2 --
>  hw/ide/piix.c  |  4 
>  include/block/block.h  |  1 +
>  include/sysemu/block-backend.h |  1 -
>  7 files changed, 32 insertions(+), 27 deletions(-)
> 
> -- 
> 2.7.4
> 
> 

Acked-by: Fam Zheng 



Re: [Qemu-devel] [PATCH v7 02/20] qapi: Add lock-mode in blockdev-add options

2016-09-22 Thread Fam Zheng
On Thu, 09/22 09:58, Eric Blake wrote:
> On 08/08/2016 08:13 AM, Fam Zheng wrote:
> > To allow overriding the default locking behavior when opening the image.
> > 
> > Signed-off-by: Fam Zheng 
> > ---
> >  qapi/block-core.json | 19 ++-
> >  1 file changed, 18 insertions(+), 1 deletion(-)
> > 
> > diff --git a/qapi/block-core.json b/qapi/block-core.json
> > index 5e2d7d7..d1eb197 100644
> > --- a/qapi/block-core.json
> > +++ b/qapi/block-core.json
> > @@ -2151,6 +2151,20 @@
> >  '*debug-level': 'int' } }
> >  
> >  ##
> > +# @BlockdevLockMode
> > +#
> > +# Describes how QEMU should lock the image.
> > +#
> > +# @off:   Disabled
> > +# @shared:Use shared lock for both RO and RW images.
> > +# @auto:  Use exclusive lock for RW images, and shared lock for RO 
> > images.
> > +#
> > +# Since: 2.7
> 
> Just a reminder to update this to 2.8 (probably throughout the series).

Good point, thanks!

> 
> > @@ -2185,7 +2201,8 @@
> >  '*cache': 'BlockdevCacheOptions',
> >  '*aio': 'BlockdevAioOptions',
> >  '*read-only': 'bool',
> > -'*detect-zeroes': 'BlockdevDetectZeroesOptions' },
> > +'*detect-zeroes': 'BlockdevDetectZeroesOptions',
> > +'*lock-mode': 'BlockdevLockMode' },
> >'discriminator': 'driver',
> >'data': {
> >'archipelago':'BlockdevOptionsArchipelago',
> > 
> 
> Will this need (yet another) rebase on top of Kevin's blockdev-add work?

Yes, I think so..

Fam



[Qemu-devel] [PATCH] hmp: fix qemu crash due to ioapic state dump w/ split irqchip

2016-09-22 Thread Wanpeng Li
From: Wanpeng Li 

The qemu will crash when info ioapic through hmp if irqchip 
is split. Below message is splat:

KVM_GET_IRQCHIP failed: Unknown error -6

This patch fix it by dumping the ioapic state from the qemu 
emulated ioapic if irqchip is split.

Cc: Paolo Bonzini 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Signed-off-by: Wanpeng Li 
---
 target-i386/monitor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target-i386/monitor.c b/target-i386/monitor.c
index fccfe40..bf1e983 100644
--- a/target-i386/monitor.c
+++ b/target-i386/monitor.c
@@ -504,7 +504,8 @@ void hmp_info_local_apic(Monitor *mon, const QDict *qdict)
 
 void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
 {
-if (kvm_irqchip_in_kernel()) {
+if (kvm_irqchip_in_kernel() &&
+!kvm_irqchip_is_split()) {
 kvm_ioapic_dump_state(mon, qdict);
 } else {
 ioapic_dump_state(mon, qdict);
-- 
1.9.1




Re: [Qemu-devel] [PATCH] pci-testdev: enhance to support new testcases

2016-09-22 Thread Peter Xu
On Thu, Sep 22, 2016 at 01:18:24PM +0200, Andrew Jones wrote:
> On Thu, Sep 22, 2016 at 02:15:08PM +0800, Peter Xu wrote:
> > pci-testdev is used mostly in kvm-unit-test for some eventfd tests.
> > However I see it a good framework for other tests as well (e.g., the
> > IOMMU unit test in the future). So enhanced it to support more
> > testcases.
> > 
> > The original memory handlers and protocol are strict and not easy to
> > change (we need to keep the old behavior of pci-testdev). So I added a
> > new parameter for the device, and memory ops will be dynamically handled
> > depending on what testcase it is configured. To specify a new test case
> > for pci-testdev, we use:
> > 
> >   -device pci-testdev,testcase=XXX
> > 
> > The default will be "eventfd", which is the original behavior for
> > pci-testdev. In the future, we can just add new testcase for pci-testdev
> > to achieve different goals.
> > 
> > Signed-off-by: Peter Xu 
> > ---
> > 
> >  This is kind-of a RFC since I am not sure whether this is a good way.
> 
> I'm not either :-) I haven't looked too closely at this test device,
> but I have been involved in reviewing a kvm-unit-tests series[*] that
> will drive it. Please take a look at that series and maybe test with
> it as well.
> 
> Thanks,
> drew
> 
> [*] https://www.spinics.net/lists/kvm/msg136892.html

Cool! Will go over. Thanks for the link. :-)

-- peterx



Re: [Qemu-devel] pseries-2.6 migration from QEMU-2.6 to QEMU-2.7 broken

2016-09-22 Thread Benjamin Herrenschmidt
On Fri, 2016-09-23 at 11:37 +1000, David Gibson wrote:
> 
> For KVM HV there's a bit of a nit: that would disallow migration
> between host cpus which aren't exactly the same model, but are close
> enough that migration will work in practice.

In that case we should use the architected PVR

Cheers,
Ben.





Re: [Qemu-devel] pseries-2.6 migration from QEMU-2.6 to QEMU-2.7 broken

2016-09-22 Thread Nikunj A Dadhania
David Gibson  writes:

> [ Unknown signature status ]
> On Thu, Sep 22, 2016 at 02:34:19PM +0530, Nikunj A Dadhania wrote:
>> Benjamin Herrenschmidt  writes:
>> 
>> > On Thu, 2016-09-22 at 11:45 +0530, Bharata B Rao wrote:
>> >> On Thu, Sep 22, 2016 at 04:07:21PM +1000, Benjamin Herrenschmidt wrote:
>> >> > 
>> >> > On Thu, 2016-09-22 at 10:51 +0530, Bharata B Rao wrote:
>> >> > > 
>> >> > > The flag values are expected to remain same for a machine version for
>> >> > > the migration to succeed, but this expectation is broken now. Should
>> >> > > we make the addition of these flags conditional on machine type
>> >> > > version ?
>> >> > > But these flags are part of POWER8 CPU definition which is common for
>> >> > > both pseries and upcoming powernv.
>> >> > 
>> >> > Does this affect KVM ? (And if yes why on earth would KVM give a flying
>> >> > f*** about the TCG instruction flags ?) ... If not, then I think we can
>> >> > safely not care.
>> >> 
>> >> Yes, KVM migration is broken.
>> >
>> > Argh then ... stupid design in QEMU. We can't fix anything without
>> > breaking migration, yay !
>> 
>> Looking back in the history of the code:
>> 
>> commit: a90db1584a00dc1d1439dc7729d99674b666b85e (target-ppc: Convert
>> ppc cpu savevm to VMStateDescription) added this:
>> 
>> +/* Sanity checking */
>> +VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
>> +VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
>> 
>> These flags weren't part of vmstate, I am not sure what was the reason
>> behind adding it though. Its a bit old, Alexey do you remember?
>> 
>> > I don't know what to do to fix that to be honest. Do we have a way to 
>> > filter
>> > what flags actually matter and filter things out when KVM is enabled ?
>> 
>> Something like this works for KVM:
>> 
>> diff --git a/target-ppc/machine.c b/target-ppc/machine.c
>> index 4820f22..1cf3779 100644
>> --- a/target-ppc/machine.c
>> +++ b/target-ppc/machine.c
>> @@ -563,8 +563,8 @@ const VMStateDescription vmstate_ppc_cpu = {
>>  
>>  /* Sanity checking */
>>  VMSTATE_UINTTL_EQUAL(env.msr_mask, PowerPCCPU),
>> -VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
>> -VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
>> +VMSTATE_UNUSED(sizeof(target_ulong)), /* was 
>> _EQUAL(env.insns_flags) */
>> +VMSTATE_UNUSED(sizeof(target_ulong)), /* was 
>> _EQUAL(env.insns_flags2) */
>>  VMSTATE_UINT32_EQUAL(env.nb_BATs, PowerPCCPU),
>>  VMSTATE_END_OF_LIST()
>>  },
>
> This looks like the right solution to me.  AFAICT this was just a
> sanity check that wasn't thought through well enough.
>
>> TCG migration still remains broken with this.
>
> Uh.. why?

Didn't debug it yet, reported on the other thread

  qemu: fatal: Trying to deliver HV exception 4 with no HV support

  NIP c00795c8   LR d074407c CTR c0079544 XER 
 CPU#0
  MSR 80009032 HID0   HF 8030 iidx 1 
didx 1
  TB 0007 32202510341 DECR 00596259

Once it just hung, without any messages.

Regards
Nikunj




Re: [Qemu-devel] [PATCH v3 08/10] ppc/pnv: add a XScomDevice to PnvCore

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 10:33:21AM +0200, Cédric Le Goater wrote:
> On 09/21/2016 08:12 AM, David Gibson wrote:
> > On Thu, Sep 15, 2016 at 02:45:58PM +0200, Cédric Le Goater wrote:
> >> Now that we are using real HW ids for the cores in PowerNV chips, we
> >> can route the XSCOM accesses to them. We just need to attach a
> >> specific XSCOM memory region to each core in the appropriate window
> >> for the core number.
> >>
> >> To start with, let's install the DTS (Digital Thermal Sensor) handlers
> >> which should return 38°C for each core.
> >>
> >> Signed-off-by: Cédric Le Goater 
> >> ---
> >>
> >>  Changes since v2:
> >>
> >>  - added a XSCOM memory region to handle access to the EX core
> >>registers   
> >>  - extended the PnvCore object with a XSCOM_INTERFACE so that we can
> >>use pnv_xscom_pcba() and pnv_xscom_addr() to handle XSCOM address
> >>translation.
> >>
> >>  hw/ppc/pnv.c   |  4 
> >>  hw/ppc/pnv_core.c  | 55 
> >> ++
> >>  include/hw/ppc/pnv_core.h  |  2 ++
> >>  include/hw/ppc/pnv_xscom.h | 19 
> >>  4 files changed, 80 insertions(+)
> >>
> >> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> >> index 7dcdf18a9e6b..6a3d1fbf8403 100644
> >> --- a/hw/ppc/pnv.c
> >> +++ b/hw/ppc/pnv.c
> >> @@ -619,6 +619,10 @@ static void pnv_chip_realize(DeviceState *dev, Error 
> >> **errp)
> >>   _fatal);
> >>  object_unref(OBJECT(pnv_core));
> >>  i++;
> >> +
> >> +memory_region_add_subregion(>xscom.xscom_mr,
> >> + 
> >> pcc->xscom_addr(PNV_XSCOM_EX_CORE_BASE(core_hwid)),
> >> + _CORE(pnv_core)->xscom_regs);
> > 
> > I think the core realize function should be doing this itself.
> 
> When working on the support of the AST2{4,5}00 SoC for qemu, these 
> are the BMC chips for the OpenPOWER systems, we were asked to do all 
> the mmio mappings for the devices at the board level. 

After a bit of thought, I agree.  Doing as you're doing here and
building any internal structure into a single MR within the device
which then gets mapped into the global address space by the machine is
a good approach.

> I think we can consider that the powernv chip is the board level for 
> the xscom address space and to all the mapping there.
> 
> This has some benefits on the view of the address space as it is 
> located in one file and not spread in multiple areas of the code.



> 
> > 
> >>  }
> >>  g_free(typename);
> >>  
> >> diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c
> >> index 6fed5a208536..81b83d0f41b3 100644
> >> --- a/hw/ppc/pnv_core.c
> >> +++ b/hw/ppc/pnv_core.c
> >> @@ -19,6 +19,7 @@
> >>  #include "qemu/osdep.h"
> >>  #include "sysemu/sysemu.h"
> >>  #include "qapi/error.h"
> >> +#include "qemu/log.h"
> >>  #include "target-ppc/cpu.h"
> >>  #include "hw/ppc/ppc.h"
> >>  #include "hw/ppc/pnv.h"
> >> @@ -57,6 +58,51 @@ static void powernv_cpu_init(PowerPCCPU *cpu, Error 
> >> **errp)
> >>  powernv_cpu_reset(cpu);
> >>  }
> >>  
> >> +/*
> >> + * These values are read by the powernv hw monitors under Linux
> >> + */
> >> +#define DTS_RESULT0 0x5
> >> +#define DTS_RESULT1 0x50001
> >> +
> >> +static uint64_t pnv_core_xscom_read(void *opaque, hwaddr addr,
> >> +unsigned int width)
> >> +{
> >> +uint32_t offset = pnv_xscom_pcba(opaque, addr);
> >> +uint64_t val = 0;
> >> +
> >> +/* The result should be 38 C */
> >> +switch (offset) {
> >> +case DTS_RESULT0:
> >> +val = 0x26f024f023full;
> >> +break;
> >> +case DTS_RESULT1:
> >> +val = 0x24full;
> >> +break;
> >> +default:
> >> +qemu_log_mask(LOG_UNIMP, "Warning: reading reg=0x%" HWADDR_PRIx,
> >> +  addr);
> >> +}
> >> +
> >> +return val;
> >> +}
> >> +
> >> +static void pnv_core_xscom_write(void *opaque, hwaddr addr, uint64_t val,
> >> + unsigned int width)
> >> +{
> >> +qemu_log_mask(LOG_UNIMP, "Warning: writing to reg=0x%" HWADDR_PRIx,
> >> +  addr);
> >> +}
> > 
> > You should double check, but I think you can implement an RO region in
> > an address space by just leaving the write function as NULL.
> 
> OK.
> 
> Thanks,
> 
> C.
> 
> >> +
> >> +static const MemoryRegionOps pnv_core_xscom_ops = {
> >> +.read = pnv_core_xscom_read,
> >> +.write = pnv_core_xscom_write,
> >> +.valid.min_access_size = 8,
> >> +.valid.max_access_size = 8,
> >> +.impl.min_access_size = 8,
> >> +.impl.max_access_size = 8,
> >> +.endianness = DEVICE_BIG_ENDIAN,
> >> +};
> >> +
> >>  static void pnv_core_realize_child(Object *child, Error **errp)
> >>  {
> >>  Error *local_err = NULL;
> >> @@ -117,6 +163,11 @@ static void pnv_core_realize(DeviceState *dev, Error 
> >> **errp)
> >>  goto err;
> >>  }
> >>  

Re: [Qemu-devel] pseries-2.6 migration from QEMU-2.6 to QEMU-2.7 broken

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 12:32:24PM +0200, Paolo Bonzini wrote:
> 
> 
> On 22/09/2016 12:04, Benjamin Herrenschmidt wrote:
> > On Thu, 2016-09-22 at 14:34 +0530, Nikunj A Dadhania wrote:
> >> Something like this works for KVM:
> >>
> >> diff --git a/target-ppc/machine.c b/target-ppc/machine.c
> >> index 4820f22..1cf3779 100644
> >> --- a/target-ppc/machine.c
> >> +++ b/target-ppc/machine.c
> >> @@ -563,8 +563,8 @@ const VMStateDescription vmstate_ppc_cpu = {
> >>  
> >>  /* Sanity checking */
> >>  VMSTATE_UINTTL_EQUAL(env.msr_mask, PowerPCCPU),
> >> -VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
> >> -VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
> >> +VMSTATE_UNUSED(sizeof(target_ulong)), /* was 
> >> _EQUAL(env.insns_flags) */
> >> +VMSTATE_UNUSED(sizeof(target_ulong)), /* was 
> >> _EQUAL(env.insns_flags2) */
> >>  VMSTATE_UINT32_EQUAL(env.nb_BATs, PowerPCCPU),
> >>  VMSTATE_END_OF_LIST()
> >>  },
> >>
> >> TCG migration still remains broken with this.
> > 
> > Can we have conditionally present flags and a post-load that does some
> > matching ?
> 
> Yes, you can use something like
> 
>   VMSTATE_UINT64(env.src_insns_flags, PowerPCCPU),
>   VMSTATE_UINT64(env.src_insns_flags2, PowerPCCPU),
> 
> and a post_load that compares them if kvm_enabled() only.

We could, but I'm not convinced there's any point.  I don't see that
migrating these flags actually has any value beyond a sanity check,
the consequences of which we obviously didn't think through fully.
They should just be a TCG internal matter.

> *However* a better fix would be to preserve the old flags for
> pseries-2.6, and only set the newer flags for pseries-2.7.  I'm not
> saying you have to do this, but if it's not hard (no idea) why not learn
> how to do it right.
> 
> The design is not stupid, it's just that compatibility is harder than
> you think and you are going through the same learning experiences that
> x86 went though.
> 
> Paolo
> 

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v3 10/10] ppc/pnv: add a ISA bus

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 10:44:13AM +0200, Cédric Le Goater wrote:
> 
> >> +static ISABus *pnv_isa_create(PnvChip *chip)
> >> +{
> >> +PnvLpcController *lpc = >lpc;
> >> +ISABus *isa_bus;
> >> +qemu_irq *irqs;
> >> +PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
> >> +
> >> +/* Instanciate ISA bus. let isa_bus_new() create its own bridge on
> > 
> > Instantiate has 3 't's and no 'c's; English orthography strikes again.
> 
> he :) thanks. 
> 
> >> + * sysbus otherwise devices speficied on the command line will
> >> + * fail to create.
> >> + */
> >> +isa_bus = isa_bus_new(NULL, >isa_mem, >isa_io,
> >> +  _fatal);
> > 
> > It's not clear to me if this belongs in the chip code or on the lpc
> > code - the lpc does create a device node as 'isa@', although it also
> > does some other stuff.
> 
> In fact, the isabus in the qemu model is at the machine level, see below,
> next to the 'Instanc^Htiate'.
> 
> each chip has a lpc controller but skiboot use a default one to route
> the traffic. So we choose the chip[0] one for that. 
> 
> Looking closer, I should make sure the "primary" cell is not added in the 
> device tree for chip_id != 0.

Ok, that seens sensible.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v6 3/3] intel_iommu: allow UNMAP notifiers

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 01:55:38PM +0800, Peter Xu wrote:
> On Thu, Sep 22, 2016 at 03:24:43PM +1000, David Gibson wrote:
> > On Wed, Sep 21, 2016 at 12:58:56PM +0800, Peter Xu wrote:
> > > Intel vIOMMU is still lacking of a complete IOMMU notifier mechanism.
> > > Before that is achieved, let's open a door for vhost DMAR support, which
> > > only requires cache invalidations (UNMAP operations).
> > > 
> > > Meanwhile, converting hw_error() to error_report() and exit(1), to make
> > > the error messages clean and obvious (so no CPU registers will be
> > > dumped).
> > > 
> > > Reviewed-by: David Gibson 
> > 
> > Uh.. I didn't send an R-b for this.  In fact I explicitly said I
> > didn't think it should be applied until notifications have actually
> > been implemented by the intel viommu.  I still think that, and think
> > this should just be dropped.
> 
> Please refer to:
> 
>   https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg03034.html
> 
> So this line is there since v5.
> 
> I took it an honor (and also with my thankfulness) to have added your
> r-b line here. I assume what you meant before was: the patch content
> is okay, but you would suggest to drop this patch in this series, and
> merge this until we got a real implementations for the notifiers. IMHO
> that does not mean "remove your r-b in this patch". If you meant to
> remove this line (I think not?), please confirm and I can remove it.

Fair enough.  Sorry for my crabbiness.

> I posted patch 3 just to make sure everything is coherent, and let
> Paolo decide which way to choose (since I still think it's okay
> actually... but again both are ok to me). Also it'll be easier for
> Jason to track this down as well (so when Jason sees that Paolo
> dropped patch 3, he'll naturally pick it up). If you still insist on
> dropping this patch, I'll do it in v7.
> 
> Thanks.
> 
> -- peterx
> 

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PULL 00/44] ppc-for-2.8 queue 20160922

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 03:03:50PM +0100, Peter Maydell wrote:
> On 22 September 2016 at 07:36, David Gibson <da...@gibson.dropbear.id.au> 
> wrote:
> > The following changes since commit a008535b9fa396226ff9cf78b8ac5f3584bda58e:
> >
> >   build-sys: fix make install regression (2016-09-20 11:32:43 +0100)
> >
> > are available in the git repository at:
> >
> >   git://github.com/dgibson/qemu.git tags/ppc-for-2.8-20160922
> >
> > for you to fetch changes up to 2832da4b6fc549d5feb2cf9fe53ad98cee894327:
> >
> >   monitor: fix crash for platforms without a CPU 0 (2016-09-22 15:53:01 
> > +1000)
> >
> > 
> > ppc patch queue 2016-09-22
> >
> > This is my second pull request of ppc and spapr related patches for
> > qemu-2.8.  Included here are
> > * TCG implementations for more POWER9 instructions
> > * Some preliminary XICS fixes in preparataion for the pnv machine type
> > * A significant ADB (Macintosh kbd/mouse) cleanup
> > * Some conversions to use trace instead of debug macros
> > * Fixes to correctly handle global TLB flush synchronization in
> >   TCG.  This is already a bug, but it will have much more impact
> >   when we get MTTCG
> > * Add more qtest testcases for Power
> > * Some MAINTAINERS updates
> > * Assorted bugfixes
> >
> > This touches some test files and monitor.c which are technically
> > outside the ppc code, but coming through this tree because the changes
> > are primarily of interest to ppc.
> >
> > 
> 
> I'm afraid this fails to build with clang:
> 
> /home/petmay01/linaro/qemu-for-merges/target-ppc/translate.c:532:16:
> error: unused function 'L' [-Werro
> r,-Wunused-function]
> EXTRACT_HELPER(L, 16, 2);
>^
> 1 error generated.

Drat, I wonder why travis didn't catch that for me.

Anyway, I've added an extra ifdef to address this and will send a new
pull request shortly.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v4 5/9] ppc/xics: Use a helper to add a new ICS

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 08:21:00AM +0200, Cédric Le Goater wrote:
> On 09/22/2016 01:40 AM, David Gibson wrote:
> > On Mon, Sep 19, 2016 at 11:59:33AM +0530, Nikunj A Dadhania wrote:
> >> From: Benjamin Herrenschmidt 
> >>
> >> Signed-off-by: Benjamin Herrenschmidt 
> >> [Move object allocation and adding child to the helper]
> >> Signed-off-by: Nikunj A Dadhania 
> >> Reviewed-by: David Gibson 
> >> ---
> >>  hw/intc/xics.c| 10 ++
> >>  hw/intc/xics_spapr.c  |  6 +-
> >>  include/hw/ppc/xics.h |  1 +
> >>  3 files changed, 12 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/hw/intc/xics.c b/hw/intc/xics.c
> >> index 05e938f..c7901c4 100644
> >> --- a/hw/intc/xics.c
> >> +++ b/hw/intc/xics.c
> >> @@ -109,6 +109,16 @@ static void xics_common_reset(DeviceState *d)
> >>  }
> >>  }
> >>  
> >> +void xics_add_ics(XICSState *xics)
> >> +{
> >> +ICSState *ics;
> >> +
> >> +ics = ICS(object_new(TYPE_ICS));
> >> +object_property_add_child(OBJECT(xics), "ics", OBJECT(ics), NULL);
> > 
> > You'll need to construct a name here so you don't have all the ics
> > objects called an indistinguishable "ics".
> 
> Yes, exactly, and so PowerNV does not use it because at least three ics 
> are needed : 
> 
> qemu) info qom-tree 
> /machine (powernv-machine)
>   /unattached (container)
> /sysbus (System)
> /ipmi-bt[0] (qemu:memory-region)
> /device[0] (pnv-phb3)
>   /ics-phb-lsi (ics)
>   /ics-phb-msi (phb3-msi)
> 
>   ...
> 
>   /psi (pnv-psi)
> /xscom-psi[0] (qemu:memory-region)
> /psihb[0] (qemu:memory-region)
> /ics-psi (ics)
> 
> 
> I think we can drop that patch. 
> 
> 
> However some routine like this one :
> 
> +void xics_insert_ics(XICSState *xics, ICSState *ics)
> +{
> +ics->xics = xics;
> +QLIST_INSERT_HEAD(>ics, ics, list);
> +}
> +
> 
> would be useful to hide the list details below xics :

Yes, that makes sense.

> 
> 
> /* link in the PSI ICS */
> xics_insert_ics(XICS_COMMON(>xics), >psi.ics);
> 
> 
> 
> /* insert the ICS in XICS */
> xics_insert_ics(xics, phb->lsi_ics);
> xics_insert_ics(xics, ICS_BASE(phb->msis));
> 
> 

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v6 1/3] memory: introduce IOMMUNotifier and its caps

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 03:17:46PM +0800, Peter Xu wrote:
> On Thu, Sep 22, 2016 at 03:20:48PM +1000, David Gibson wrote:
> > On Wed, Sep 21, 2016 at 12:58:54PM +0800, Peter Xu wrote:
> > > IOMMU Notifier list is used for notifying IO address mapping changes.
> > > Currently VFIO is the only user.
> > > 
> > > However it is possible that future consumer like vhost would like to
> > > only listen to part of its notifications (e.g., cache invalidations).
> > > 
> > > This patch introduced IOMMUNotifier and IOMMUNotfierFlag bits for a
> > > finer grained control of it.
> > > 
> > > IOMMUNotifier contains a bitfield for the notify consumer describing
> > > what kind of notification it is interested in. Currently two kinds of
> > > notifications are defined:
> > > 
> > > - IOMMU_NOTIFIER_MAP:for newly mapped entries (additions)
> > > - IOMMU_NOTIFIER_UNMAP:  for entries to be removed (cache invalidates)
> > > 
> > > When registering the IOMMU notifier, we need to specify one or multiple
> > > types of messages to listen to.
> > > 
> > > When notifications are triggered, its type will be checked against the
> > > notifier's type bits, and only notifiers with registered bits will be
> > > notified.
> > > 
> > > (For any IOMMU implementation, an in-place mapping change should be
> > >  notified with an UNMAP followed by a MAP.)
> > 
> > Ok, I wasn't clear.  I meant a big fat comment in the *code*, not just
> > in the commit message.  It should not be necessary to look at the
> > commit history to figure out how to use an interface correctly
> > 
> > Even a comment in the code is barely adequate, compared to designing
> > the interface signatures such that it's obvious.
> > 
> > Please bear in mind:
> > http://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html
> > and http://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html
> > 
> 
> Thanks for the links.
> 
> Maybe a better solution is to re-design the IOTLB interface. However
> that's out of the scope of this series, and another patchset can be
> opened for the refactoring work IMHO if there is a strong willingness.
> 
> For now I can add this into comments:
> 
> -8<---
> 
> @@ -607,6 +628,15 @@ uint64_t 
> memory_region_iommu_get_min_page_size(MemoryRegion *mr);
>  /**
>   * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
>   *
> + * The notification type will be decided by entry.perm bits:
> + *
> + * - For UNMAP (cache invalidation) notifies: set entry.perm to IOMMU_NONE.
> + * - For MAP (newly added entry) notifies: set entry.perm to the
> + *   permission of the page (which is definitely !IOMMU_NONE).
> + *
> + * Note: for any IOMMU implementation, an in-place mapping change
> + * should be notified with an UNMAP followed by a MAP.
> + *
>   * @mr: the memory region that was changed
>   * @entry: the new entry in the IOMMU translation table.  The entry
>   * replaces all old entries for the same virtual I/O address range.
> 
> ->8---

Thanks, that looks about as good as we can get with a comment.

> 
> [...]
> 
> > > -static void vfio_iommu_map_notify(Notifier *n, void *data)
> > > +static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *data)
> > 
> > This change leaves a now pointless IOMMUTLBEntry *iotlb = data a few
> > lines below.
> 
> Yes, will fix.
> 
> > 
> > >  {
> > >  VFIOGuestIOMMU *giommu = container_of(n, VFIOGuestIOMMU, n);
> > >  VFIOContainer *container = giommu->container;
> > > @@ -454,6 +454,7 @@ static void vfio_listener_region_add(MemoryListener 
> > > *listener,
> > > section->offset_within_region;
> > >  giommu->container = container;
> > >  giommu->n.notify = vfio_iommu_map_notify;
> > > +giommu->n.notifier_flags = IOMMU_NOTIFIER_ALL;
> > >  QLIST_INSERT_HEAD(>giommu_list, giommu, giommu_next);
> > >  
> > >  memory_region_register_iommu_notifier(giommu->iommu, >n);
> > > diff --git a/include/exec/memory.h b/include/exec/memory.h
> > > index 3e4d416..a3ec7aa 100644
> > > --- a/include/exec/memory.h
> > > +++ b/include/exec/memory.h
> > > @@ -67,6 +67,27 @@ struct IOMMUTLBEntry {
> > >  IOMMUAccessFlags perm;
> > >  };
> > >  
> > > +/*
> > > + * Bitmap for differnet IOMMUNotifier capabilities. Each notifier can
> > 
> > s/differnet/different/
> 
> Will fix. Thanks.
> 
> -- peterx
> 

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v3 07/10] ppc/pnv: add XSCOM infrastructure

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 10:25:59AM +0200, Cédric Le Goater wrote:
> >> @@ -493,6 +525,8 @@ static void pnv_chip_power9_class_init(ObjectClass 
> >> *klass, void *data)
> >>  k->chip_cfam_id = 0x100d10498000ull; /* P9 Nimbus DD1.0 */
> >>  k->cores_mask = POWER9_CORE_MASK;
> >>  k->core_pir = pnv_chip_core_pir_p9;
> >> +k->xscom_addr = pnv_chip_xscom_addr_p9;
> >> +k->xscom_pcba = pnv_chip_xscom_pcba_p9;
> > 
> > So if you do as BenH (and I) suggested and have the "scom address
> > space" actually be addressed by (pcba << 3), I think you can probably
> > avoid these.  
> 
> I will look at that option again. 
> 
> I was trying to untangle a few things at the same time. I have better
> view of the problem to solve now. The bus is gone, that's was one 
> thing. How we map these xscom regions is the next. 
> 
> Ben suggested to add some P7/P8 mangling before the dispatch in 
> the _space_xscom. This should make things cleaner. I had 
> not thought of doing that and this is why I introduced these helpers :
> 
> +uint32_t pnv_xscom_pcba(PnvXScomInterface *dev, uint64_t addr)
> +uint64_t pnv_xscom_addr(PnvXScomInterface *dev, uint32_t pcba)
> 
> which I don't really like ...
> 
> but we must make sure that we can do the mapping of the xscom 
> subregions in the _space_xscom using (pcba << 3)
> 
> 
> > Instead you can handle it in the chip or ADU realize function by either:
> > 
> > P8: * map one big subregion for the ADU into _space_memory
> > * have the handler for that subregion do the address mangling,
> >   then redispatch into the xscom address space
> >
> > P9: * Map the appropriate chunk of the xscom address space
> >   directly into address_space_memory
> 
> Yes that was my feeling for a better solution but Ben chimed in with the 
> HMER topic. I need to look at that.

Right.  Doesn't change the basic concept though - it just means you
need (slightly different) redispatchers for both P8 and P9.

> 
> 
> >>  dc->desc = "PowerNV Chip POWER9";
> >>  }
> >>  
> >> @@ -527,6 +561,16 @@ static void pnv_chip_core_sanitize(PnvChip *chip)
> >>  chip->cores_mask &= pcc->cores_mask;
> >>  }
> >>  
> >> +static void pnv_chip_init(Object *obj)
> >> +{
> >> +PnvChip *chip = PNV_CHIP(obj);
> >> +
> >> +object_initialize(>xscom, sizeof(chip->xscom), TYPE_PNV_XSCOM);
> >> +object_property_add_child(obj, "xscom", OBJECT(>xscom), NULL);
> >> +object_property_add_const_link(OBJECT(>xscom), "chip",
> >> +   OBJECT(chip), _abort);
> >> +}
> >> +
> >>  static void pnv_chip_realize(DeviceState *dev, Error **errp)
> >>  {
> >>  PnvChip *chip = PNV_CHIP(dev);
> >> @@ -540,6 +584,12 @@ static void pnv_chip_realize(DeviceState *dev, Error 
> >> **errp)
> >>  return;
> >>  }
> >>  
> >> +/* XSCOM bridge */
> >> +object_property_set_bool(OBJECT(>xscom), true, "realized",
> >> + _fatal);
> >> +sysbus_mmio_map(SYS_BUS_DEVICE(>xscom), 0,
> >> +PNV_XSCOM_BASE(chip->chip_id));
> >> +
> >>  /* Early checks on the core settings */
> >>  pnv_chip_core_sanitize(chip);
> >>  
> >> @@ -597,6 +647,7 @@ static const TypeInfo pnv_chip_info = {
> >>  .name  = TYPE_PNV_CHIP,
> >>  .parent= TYPE_SYS_BUS_DEVICE,
> >>  .class_init= pnv_chip_class_init,
> >> +.instance_init = pnv_chip_init,
> >>  .class_size= sizeof(PnvChipClass),
> >>  .abstract  = true,
> >>  };
> >> diff --git a/hw/ppc/pnv_xscom.c b/hw/ppc/pnv_xscom.c
> >> new file mode 100644
> >> index ..019cd85428de
> >> --- /dev/null
> >> +++ b/hw/ppc/pnv_xscom.c
> >> @@ -0,0 +1,308 @@
> >> +/*
> >> + * QEMU PowerPC PowerNV XSCOM bus
> >> + *
> >> + * Copyright (c) 2016, IBM Corporation.
> >> + *
> >> + * This library is free software; you can redistribute it and/or
> >> + * modify it under the terms of the GNU Lesser General Public
> >> + * License as published by the Free Software Foundation; either
> >> + * version 2 of the License, or (at your option) any later version.
> >> + *
> >> + * This library is distributed in the hope that it will be useful,
> >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> >> + * Lesser General Public License for more details.
> >> + *
> >> + * You should have received a copy of the GNU Lesser General Public
> >> + * License along with this library; if not, see 
> >> .
> >> + */
> >> +#include "qemu/osdep.h"
> >> +#include "qapi/error.h"
> >> +#include "hw/hw.h"
> >> +#include "qemu/log.h"
> >> +#include "sysemu/kvm.h"
> >> +#include "target-ppc/cpu.h"
> >> +#include "hw/sysbus.h"
> >> +
> >> +#include "hw/ppc/fdt.h"
> >> +#include "hw/ppc/pnv_xscom.h"
> >> +#include "hw/ppc/pnv.h"
> >> +
> >> +#include 
> >> +
> >> +static void xscom_complete(uint64_t hmer_bits)
> >> +{
> >> +

Re: [Qemu-devel] [Qemu-ppc] [PATCH qemu] spapr_pci: Add numa node id

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 02:49:34PM +1000, David Gibson wrote:
> On Wed, Sep 14, 2016 at 07:03:50AM -0500, Michael Roth wrote:
> > Quoting Alexey Kardashevskiy (2016-09-14 04:39:10)
> > > On 14/09/16 09:29, Michael Roth wrote:
> > > > Quoting Alexey Kardashevskiy (2016-07-27 03:03:38)
> > > >> This adds a numa id property to a PHB to allow linking passed PCI 
> > > >> device
> > > >> to CPU/memory. It is up to the management stack to do CPU/memory 
> > > >> pinning
> > > >> to the node with the actual PCI device.
> > > > 
> > > > It looks like x86 relies on PCIBus->numa_node() method (via
> > > > pci_bus_numa_node()) to encode similar PCIBus affinities
> > > > into ACPI tables, and currently exposes it via
> > > > -device pci-[-express]-expander-bus,numa_node=X.
> > > 
> > > 
> > > 
> > > Well, until we allow DMA windows per PCI bus (not per PHB as it is now),
> > > this won't make much sense for us (unless I am missing something here).
> > 
> > I didn't consider that it's not a bus-level setting; I think
> > you're right that re-using the interface to both store/retrieve doesn't
> > make much sense in that case.
> > 
> > My thought that was that since pci_bus_numa_node() could in theory come
> > to be relied upon by common PCI code, that we should use it as well. But
> > even if it doesn't make sense for us to use it, wouldn't it make sense to
> > still set PCIBus->numa_node (in addition to the PHB-wide value) in the
> > off-chance that common code does come to rely on
> > pci_bus_numa_node()?
> 
> Yes, it would be a good idea to set the PCIBus node value to inherit
> the one that's set for the host bridge, just in case any generic code
> looks at it in future.

But that can be a followup patch, I've applied this to ppc-for-2.8
now.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] pseries-2.6 migration from QEMU-2.6 to QEMU-2.7 broken

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 09:37:16PM +1000, Benjamin Herrenschmidt wrote:
> On Thu, 2016-09-22 at 13:27 +0200, Cédric Le Goater wrote:
> 
> > > TCG migration succeeds and proceeds ahead. But fails somewhere
> > > ahead in
> > > powerpc exception handler:
> > > 
> > > [qemu]$ ./ppc64-softmmu/qemu-system-ppc64  -machine pseries-
> > > 2.6,usb=off -vga none -nographic -m 2G   ../../imgs/guest.disk
> > > -monitor pty --incoming tcp:localhost: 
> > > char device redirected to /dev/pts/5 (label compat_monitor0)
> > > ppc_kvm_enabled: is kvm enabled 0
> > > get_insns_equal: 
> > > Did not match, ignore 9223477658187168481 != 9223477658187151905
> > > ppc_kvm_enabled: is kvm enabled 0
> > > get_insns_equal: 
> > > Did not match, ignore 331702 != 69558
> > > Cannot open font file True
> > > Cannot open font file True
> > > qemu: fatal: Trying to deliver HV exception 4 with no HV support
> > 
> > hmm, this is because we added MSR_HVB in msr_mask AFAICT. we should
> > have a similar vmstate op for it I think
> 
> We also need to be careful about now allowing KVM migration to/from
> wildly different CPU generations, or is that handled elsewhere ? (PVR
> match ?)

Apparently not.  We do transfer the PVR value in the migration stream
(along with all actual and potential SPRs).  However in
cpu_post_load() from target-ppc/machine.c, we overwrite the incoming
value with the PVR for the command line selected CPU model.

We should check it though - that would make for a much, well, saner,
sanity check than comparing the instruction support bitmaps.

For TCG and KVM PR, just comparing for equality should be fine -
you're supposed to match PVRs at either end of the migration, just as
you have to match the rest of the hardware configuration.

For KVM HV there's a bit of a nit: that would disallow migration
between host cpus which aren't exactly the same model, but are close
enough that migration will work in practice.


Ok.. here's what I think we need to do:

1) Remove the VMSTATE_EQUAL checks for the instruction bits, both
   in 2.8 and 2.7-stable.  That will allow migrations to work
   again, albeit requiring the user to be rather careful that the
   cpus really do match at either end.

2) In 2.8-devel, change cpu_post_load() to check that the migrated
   PVR is the same as the destination PVR.  That will properly
   verify that we have matching CPUs using architected state.  It
   might break some cases of migrating between similar but not
   identical CPUs with -cpu host and KVM HV

3) Before 2.8 is wrapped up, experiment to see just what cases (2)
   might have broken and come up with some mechanisms to re-allow
   them.

Thoughts?  Objections?

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] pseries-2.6 migration from QEMU-2.6 to QEMU-2.7 broken

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 02:34:19PM +0530, Nikunj A Dadhania wrote:
> Benjamin Herrenschmidt  writes:
> 
> > On Thu, 2016-09-22 at 11:45 +0530, Bharata B Rao wrote:
> >> On Thu, Sep 22, 2016 at 04:07:21PM +1000, Benjamin Herrenschmidt wrote:
> >> > 
> >> > On Thu, 2016-09-22 at 10:51 +0530, Bharata B Rao wrote:
> >> > > 
> >> > > The flag values are expected to remain same for a machine version for
> >> > > the migration to succeed, but this expectation is broken now. Should
> >> > > we make the addition of these flags conditional on machine type
> >> > > version ?
> >> > > But these flags are part of POWER8 CPU definition which is common for
> >> > > both pseries and upcoming powernv.
> >> > 
> >> > Does this affect KVM ? (And if yes why on earth would KVM give a flying
> >> > f*** about the TCG instruction flags ?) ... If not, then I think we can
> >> > safely not care.
> >> 
> >> Yes, KVM migration is broken.
> >
> > Argh then ... stupid design in QEMU. We can't fix anything without
> > breaking migration, yay !
> 
> Looking back in the history of the code:
> 
> commit: a90db1584a00dc1d1439dc7729d99674b666b85e (target-ppc: Convert
> ppc cpu savevm to VMStateDescription) added this:
> 
> +/* Sanity checking */
> +VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
> +VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
> 
> These flags weren't part of vmstate, I am not sure what was the reason
> behind adding it though. Its a bit old, Alexey do you remember?
> 
> > I don't know what to do to fix that to be honest. Do we have a way to filter
> > what flags actually matter and filter things out when KVM is enabled ?
> 
> Something like this works for KVM:
> 
> diff --git a/target-ppc/machine.c b/target-ppc/machine.c
> index 4820f22..1cf3779 100644
> --- a/target-ppc/machine.c
> +++ b/target-ppc/machine.c
> @@ -563,8 +563,8 @@ const VMStateDescription vmstate_ppc_cpu = {
>  
>  /* Sanity checking */
>  VMSTATE_UINTTL_EQUAL(env.msr_mask, PowerPCCPU),
> -VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
> -VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
> +VMSTATE_UNUSED(sizeof(target_ulong)), /* was _EQUAL(env.insns_flags) 
> */
> +VMSTATE_UNUSED(sizeof(target_ulong)), /* was 
> _EQUAL(env.insns_flags2) */
>  VMSTATE_UINT32_EQUAL(env.nb_BATs, PowerPCCPU),
>  VMSTATE_END_OF_LIST()
>  },

This looks like the right solution to me.  AFAICT this was just a
sanity check that wasn't thought through well enough.

> TCG migration still remains broken with this.

Uh.. why?

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v6 3/3] intel_iommu: allow UNMAP notifiers

2016-09-22 Thread David Gibson
On Thu, Sep 22, 2016 at 09:44:10AM +0200, Paolo Bonzini wrote:
> 
> 
> On 22/09/2016 07:55, Peter Xu wrote:
> > I posted patch 3 just to make sure everything is coherent, and let
> > Paolo decide which way to choose (since I still think it's okay
> > actually... but again both are ok to me). Also it'll be easier for
> > Jason to track this down as well (so when Jason sees that Paolo
> > dropped patch 3, he'll naturally pick it up). If you still insist on
> > dropping this patch, I'll do it in v7.
> 
> I think it's better to keep this patch.

Ok.  I disagree, but I won't argue.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [Qemu-ppc] [PATCH qemu] spapr_pci: Add numa node id

2016-09-22 Thread David Gibson
On Wed, Jul 27, 2016 at 06:03:38PM +1000, Alexey Kardashevskiy wrote:
> This adds a numa id property to a PHB to allow linking passed PCI device
> to CPU/memory. It is up to the management stack to do CPU/memory pinning
> to the node with the actual PCI device.
> 
> Signed-off-by: Alexey Kardashevskiy 

I've applied this to ppc-for-2.8, renaming the property to "numa_node"
to match the similar option for pxb.

> ---
>  hw/ppc/spapr_pci.c  | 13 +
>  include/hw/pci-host/spapr.h |  2 ++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 949c44f..af5394a 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -47,6 +47,7 @@
>  #include "sysemu/device_tree.h"
>  #include "sysemu/kvm.h"
>  #include "sysemu/hostmem.h"
> +#include "sysemu/numa.h"
>  
>  #include "hw/vfio/vfio.h"
>  
> @@ -1544,6 +1545,7 @@ static Property spapr_phb_properties[] = {
>  DEFINE_PROP_BOOL("ddw", sPAPRPHBState, ddw_enabled, true),
>  DEFINE_PROP_UINT64("pgsz", sPAPRPHBState, page_size_mask,
> (1ULL << 12) | (1ULL << 16)),
> +DEFINE_PROP_UINT32("node", sPAPRPHBState, numa_node, -1),
>  DEFINE_PROP_END_OF_LIST(),
>  };
>  
> @@ -1805,6 +1807,11 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,
>  cpu_to_be32(1),
>  cpu_to_be32(RTAS_IBM_RESET_PE_DMA_WINDOW)
>  };
> +uint32_t associativity[] = {cpu_to_be32(0x4),
> +cpu_to_be32(0x0),
> +cpu_to_be32(0x0),
> +cpu_to_be32(0x0),
> +cpu_to_be32(phb->numa_node)};
>  sPAPRTCETable *tcet;
>  PCIBus *bus = PCI_HOST_BRIDGE(phb)->bus;
>  sPAPRFDT s_fdt;
> @@ -1837,6 +1844,12 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,
>   _extensions, sizeof(ddw_extensions)));
>  }
>  
> +/* Advertise NUMA via ibm,associativity */
> +if (nb_numa_nodes > 1) {
> +_FDT(fdt_setprop(fdt, bus_off, "ibm,associativity", associativity,
> + sizeof(associativity)));
> +}
> +
>  /* Build the interrupt-map, this must matches what is done
>   * in pci_spapr_map_irq
>   */
> diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h
> index 5adc603..53c4b2d 100644
> --- a/include/hw/pci-host/spapr.h
> +++ b/include/hw/pci-host/spapr.h
> @@ -75,6 +75,8 @@ struct sPAPRPHBState {
>  bool ddw_enabled;
>  uint64_t page_size_mask;
>  uint64_t dma64_win_addr;
> +
> +uint32_t numa_node;
>  };
>  
>  #define SPAPR_PCI_MAX_INDEX  255

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


[Qemu-devel] [Bug 1305402] Re: libvirt fails to start VirtualMachines

2016-09-22 Thread Leo Arias
This has just happened to me. For some reason, all my machines had 
machine='pc-i440fx-wily'.
After an update in yakkety, they stopped working.

$ qemu-system-x86_64 -enable-kvm -machine help | grep wily

So I updated the machine xml to a supported machine as Charles
suggested, and they work again.

Here's the note for my future self about how to do the update:

$ virsh dumpxml $machine-name > /tmp/machine.xml
Edit the xml.
$ virsh define /tmp/machine.xml

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1305402

Title:
  libvirt fails to start VirtualMachines

Status in QEMU:
  Invalid
Status in libvirt package in Ubuntu:
  Confirmed
Status in qemu package in Ubuntu:
  Confirmed

Bug description:
  I've created several kvm based machines using virtual machine manager.
  They have operated well over the last 4 days without issue. I did an
  apt-get upgrade, and qemu was in the list of updates.

  After upgrading, I am unable to start any of the provisioned virtual
  machines with the following error output

  virsh # start node2
  error: Failed to start domain node2
  error: internal error: process exited while connecting to monitor: 
qemu-system-x86_64: -machine trusty,accel=kvm,usb=off: Unsupported machine type
  Use -machine help to list supported machines!

  virsh # start node3
  error: Failed to start domain node3
  error: internal error: process exited while connecting to monitor: 
qemu-system-x86_64: -machine trusty,accel=kvm,usb=off: Unsupported machine type
  Use -machine help to list supported machines!

  $ dpkg -l | grep kvm
  ii  qemu-kvm 2.0.0~rc1+dfsg-0ubuntu3 
amd64QEMU Full virtualization on x86 hardware (transitional package)

  Log snippet from vm 'media' that was verified working, and fails to
  start after the upgrade.

  LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
QEMU_AUDIO_DRV=none /usr/bin/kvm-spice -name media -S -machine 
trusty,accel=kvm,usb=off -m 1548 -realtime mlock=off -smp 
1,sockets=1,cores=1,threads=1 -uuid 60b20f7b-6d20-bcb3-f4fc-808a9b2fe0d0 
-no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/media.monitor,server,nowait 
-mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown 
-boot menu=off,strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 
-drive 
file=/var/lib/libvirt/images/media.img,if=none,id=drive-virtio-disk0,format=raw 
-device 
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
 -drive 
file=/home/charles/iso/ubuntu-desktop-12.04.4-amd64.iso,if=none,id=drive-ide0-1-0,readonly=on,format=raw
 -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev 
tap,fd=24,id=hostnet0,vhost=on,vhostfd=26 -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:a0:69:d9,bus=pci.0,addr=0x3 
-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 
-vnc 127.0.0.1:1 -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
  char device redirected to /dev/pts/13 (label charserial0)
  qemu: terminating on signal 15 from pid 31688
  2014-04-10 03:36:54.593+: shutting down
  2014-04-10 03:59:25.487+: starting up
  LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
QEMU_AUDIO_DRV=none /usr/bin/kvm-spice -name media -S -machine 
trusty,accel=kvm,usb=off -m 1548 -realtime mlock=off -smp 
1,sockets=1,cores=1,threads=1 -uuid 60b20f7b-6d20-bcb3-f4fc-808a9b2fe0d0 
-no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/media.monitor,server,nowait 
-mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown 
-boot menu=off,strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 
-drive 
file=/var/lib/libvirt/images/media.img,if=none,id=drive-virtio-disk0,format=raw 
-device 
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
 -drive 
file=/home/charles/iso/ubuntu-desktop-12.04.4-amd64.iso,if=none,id=drive-ide0-1-0,readonly=on,format=raw
 -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev 
tap,fd=24,id=hostnet0,vhost=on,vhostfd=25 -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:a0:69:d9,bus=pci.0,addr=0x3 
-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 
-vnc 127.0.0.1:0 -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
  qemu-system-x86_64: -machine trusty,accel=kvm,usb=off: Unsupported machine 
type
  Use -machine help to list supported machines!
  2014-04-10 03:59:25.696+: shutting down

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1305402/+subscriptions



[Qemu-devel] [PATCH v5 0/3] block: allow flush on devices with open tray

2016-09-22 Thread John Snow
When I said "Final re-send," I was lying. Here's a v5.
The title is also a misnomer by now :)

The move to blk_flush altered the behavior of migration and flushing
nodes that are not reachable via the guest, but are still reachable
via QEMU and may or may not need to be flushed.

This is intended for 2.6.2 and/or 2.7.1, to fix problems with libvirt
et al being unable to migrate QEMU when the CDROM tray is open.

v5:
 Fix bracket spacing in patch 1. By one space. :(
 Added third patch to remove blk_flush_all.

v4:
 Commit message update.

v3:
 Reworking approach and reinstating bdrv_flush_all at Kevin's suggestion.



For convenience, this branch is available at:
https://github.com/jnsnow/qemu.git branch atapi-tray-migfix
https://github.com/jnsnow/qemu/tree/atapi-tray-migfix

This version is tagged atapi-tray-migfix-v5:
https://github.com/jnsnow/qemu/releases/tag/atapi-tray-migfix-v5

John Snow (3):
  block: reintroduce bdrv_flush_all
  qemu: use bdrv_flush_all for vm_stop et al
  block-backend: remove blk_flush_all

 block/block-backend.c  | 22 --
 block/io.c | 25 +
 cpus.c |  4 ++--
 hw/i386/xen/xen_platform.c |  2 --
 hw/ide/piix.c  |  4 
 include/block/block.h  |  1 +
 include/sysemu/block-backend.h |  1 -
 7 files changed, 32 insertions(+), 27 deletions(-)

-- 
2.7.4




[Qemu-devel] [PATCH v5 1/3] block: reintroduce bdrv_flush_all

2016-09-22 Thread John Snow
Commit fe1a9cbc moved the flush_all routine from the bdrv layer to the
block-backend layer. In doing so, however, the semantics of the routine
changed slightly such that flush_all now used blk_flush instead of
bdrv_flush.

blk_flush can fail if the attached device model reports that it is not
"available," (i.e. the tray is open.) This changed the semantics of
flush_all such that it can now fail for e.g. open CDROM drives.

Reintroduce bdrv_flush_all to regain the old semantics without having to
alter the behavior of blk_flush or blk_flush_all, which are already
'doing the right thing.'

Signed-off-by: John Snow 
Reviewed-by: Kevin Wolf 
---
 block/io.c| 25 +
 include/block/block.h |  1 +
 2 files changed, 26 insertions(+)

diff --git a/block/io.c b/block/io.c
index fdf7080..57a2eeb 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1619,6 +1619,31 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, 
int64_t offset,
BDRV_REQ_ZERO_WRITE | flags);
 }
 
+/*
+ * Flush ALL BDSes regardless of if they are reachable via a BlkBackend or not.
+ */
+int bdrv_flush_all(void)
+{
+BdrvNextIterator it;
+BlockDriverState *bs = NULL;
+int result = 0;
+
+for (bs = bdrv_first(); bs; bs = bdrv_next()) {
+AioContext *aio_context = bdrv_get_aio_context(bs);
+int ret;
+
+aio_context_acquire(aio_context);
+ret = bdrv_flush(bs);
+if (ret < 0 && !result) {
+result = ret;
+}
+aio_context_release(aio_context);
+}
+
+return result;
+}
+
+
 typedef struct BdrvCoGetBlockStatusData {
 BlockDriverState *bs;
 BlockDriverState *base;
diff --git a/include/block/block.h b/include/block/block.h
index ffecebf..5e81281 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -332,6 +332,7 @@ int bdrv_inactivate_all(void);
 /* Ensure contents are flushed to disk.  */
 int bdrv_flush(BlockDriverState *bs);
 int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
+int bdrv_flush_all(void);
 void bdrv_close_all(void);
 void bdrv_drain(BlockDriverState *bs);
 void coroutine_fn bdrv_co_drain(BlockDriverState *bs);
-- 
2.7.4




[Qemu-devel] [PATCH v5 2/3] qemu: use bdrv_flush_all for vm_stop et al

2016-09-22 Thread John Snow
Reimplement bdrv_flush_all for vm_stop. In contrast to blk_flush_all,
bdrv_flush_all does not have device model restrictions. This allows
us to flush and halt unconditionally without error.

This allows us to do things like migrate when we have a device with
an open tray, but has a node that may need to be flushed, or nodes
that aren't currently attached to any device and need to be flushed.

Specifically, this allows us to migrate when we have a CDROM with
an open tray.

Signed-off-by: John Snow 
Reviewed-by: Kevin Wolf 
---
 cpus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index e39ccb7..96d9352 100644
--- a/cpus.c
+++ b/cpus.c
@@ -751,7 +751,7 @@ static int do_vm_stop(RunState state)
 }
 
 bdrv_drain_all();
-ret = blk_flush_all();
+ret = bdrv_flush_all();
 
 return ret;
 }
@@ -1494,7 +1494,7 @@ int vm_stop_force_state(RunState state)
 bdrv_drain_all();
 /* Make sure to return an error if the flush in a previous vm_stop()
  * failed. */
-return blk_flush_all();
+return bdrv_flush_all();
 }
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH v5 3/3] block-backend: remove blk_flush_all

2016-09-22 Thread John Snow
We can teach Xen to drain and flush each device as it needs to, instead
of trying to flush ALL devices. This removes the last user of
blk_flush_all.

The function is therefore removed under the premise that any new uses
of blk_flush_all would be the wrong paradigm: either flush the single
device that requires flushing, or use an appropriate flush_all mechanism
from outside of the BlkBackend layer.

Signed-off-by: John Snow 
---
 block/block-backend.c  | 22 --
 hw/i386/xen/xen_platform.c |  2 --
 hw/ide/piix.c  |  4 
 include/sysemu/block-backend.h |  1 -
 4 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index d1349d9..bfb1ddb 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1621,28 +1621,6 @@ int blk_commit_all(void)
 return 0;
 }
 
-int blk_flush_all(void)
-{
-BlockBackend *blk = NULL;
-int result = 0;
-
-while ((blk = blk_all_next(blk)) != NULL) {
-AioContext *aio_context = blk_get_aio_context(blk);
-int ret;
-
-aio_context_acquire(aio_context);
-if (blk_is_inserted(blk)) {
-ret = blk_flush(blk);
-if (ret < 0 && !result) {
-result = ret;
-}
-}
-aio_context_release(aio_context);
-}
-
-return result;
-}
-
 
 /* throttling disk I/O limits */
 void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg)
diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
index aa78393..f85635c 100644
--- a/hw/i386/xen/xen_platform.c
+++ b/hw/i386/xen/xen_platform.c
@@ -134,8 +134,6 @@ static void platform_fixed_ioport_writew(void *opaque, 
uint32_t addr, uint32_t v
devices, and bit 2 the non-primary-master IDE devices. */
 if (val & UNPLUG_ALL_IDE_DISKS) {
 DPRINTF("unplug disks\n");
-blk_drain_all();
-blk_flush_all();
 pci_unplug_disks(pci_dev->bus);
 }
 if (val & UNPLUG_ALL_NICS) {
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index c190fca..d5777fd 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -179,6 +179,10 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev)
 if (di != NULL && !di->media_cd) {
 BlockBackend *blk = blk_by_legacy_dinfo(di);
 DeviceState *ds = blk_get_attached_dev(blk);
+
+blk_drain(blk);
+blk_flush(blk);
+
 if (ds) {
 blk_detach_dev(blk, ds);
 }
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 4808a96..3d43592 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -150,7 +150,6 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long 
int req, void *buf,
 int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int count);
 int blk_co_flush(BlockBackend *blk);
 int blk_flush(BlockBackend *blk);
-int blk_flush_all(void);
 int blk_commit_all(void);
 void blk_drain(BlockBackend *blk);
 void blk_drain_all(void);
-- 
2.7.4




Re: [Qemu-devel] [RFC/PATCH] migration: SMRAM dirty bitmap not fetched from kvm-kmod and not send to destination

2016-09-22 Thread Herongguang (Stephen)



On 2016/9/22 21:16, Herongguang (Stephen) wrote:



On 2016/9/14 17:05, Paolo Bonzini wrote:



On 14/09/2016 09:55, Herongguang (Stephen) wrote:

Hi,
We found a problem that when a redhat 6 VM reboots (in grub countdown
UI), migrating this VM will result in VM’s memory difference between
source and destination side. The difference always resides in GPA
0xA~0xC, i.e. SMRAM area.

Occasionally this result in VM instruction emulation error in
destination side.

After some digging, I think this is because in migration code, in
migration_bitmap_sync(), only memory slots in address space
address_space_memory’s dirty bitmap  fetched from kvm-kmod, while SMRAM
memory slot, in address space smram_address_space’s dirty bitmap not
fetched from kvm-kmod, thus modifications in SMRAM in source side are
not sent to destination side.

I tried following patch, and this phenomenon does not happen anymore. Do
you think this patch is OK or do you have better idea? Thanks.


Nice caatch!

I think the right solution here is to sync all RAM memory regions
instead of the address spaces.  You can do that by putting a notifier in
MemoryRegion; register the notifier in all the RAM creation functions
(basically after every mr->ram=true or mr->rom_device=true), and
unregister it in memory_region_destructor_ram.

Thanks,

Paolo



I have some concern:
1. For example, vhost does not know about as_id, I wonder if guests in SMM can 
operate disk or ether card, as in
that case vhost would not logging dirty pages correctly, without knowing as_id.

2. If a memory region is disabled/enabled/disabled frequently, since disabled 
memory regions would be removed
from memory slots in kvm-kmod, dirty pages would be discarded in kvm-kmod and 
qemu when disabled, thus missing.
Is my assumption correct?

After reviewing code, I think question 2 does not exist as qemu will sync dirty 
page before removing memory slots in kvm_set_phys_mem.



3. I agree your opinion that the right solution is to get dirty-page 
information for all memory region from
kvm-kmod. But I found it’s somewhat hard to implement since kvm_log_sync() 
expects a MemoryRegionSection*
parameter. Do you have good idea?

As to all the ram memory regions, I think they are all in the ram_list.blocks, 
so there is no need to create
a notifier, is this correct?





Re: [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts

2016-09-22 Thread Felix Janda
Riku Voipio wrote:
> Hi,
> 
> On Sat, Sep 17, 2016 at 09:20:14PM -0400, Felix Janda wrote:
> > Signed-off-by: Felix Janda 
> 
> Have you run the mremap tests of ltp with this on your host/guest
> combo? 

I have just run the tests. My host is arm and my guest is aarch64.
Without the patch all but mremap02 fail. With the patch all but
mremap04 pass. The mremap04 test indicates that shmat is broken.

> > ---
> >  linux-user/mmap.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> > index c4371d9..4882816 100644
> > --- a/linux-user/mmap.c
> > +++ b/linux-user/mmap.c
> > @@ -682,7 +682,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
> > old_size,
> >  
> >  if (flags & MREMAP_FIXED) {
> >  host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> > - old_size, new_size,
> > + (size_t) old_size, (size_t) new_size,
> >   flags,
> >   g2h(new_addr));
> >  
> > @@ -701,7 +701,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
> > old_size,
> >  host_addr = MAP_FAILED;
> >  } else {
> >  host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> > - old_size, new_size,
> > + (size_t) old_size, (size_t) 
> > new_size,
> >   flags | MREMAP_FIXED,
> >   g2h(mmap_start));
> >  if (reserved_va) {
> > -- 
> > 2.7.3
> > 



[Qemu-devel] [PATCH] tcg: increase MAX_OP_PER_INSTR to 395

2016-09-22 Thread Joseph Myers
MAX_OP_PER_INSTR is currently 266, reported in commit
14dcdac82f398cbac874c8579b9583fab31c67bf to be the worst case for the
ARM A64 decoder.

Whether or not it was in fact the worst case at that time in 2014, I'm
observing the instruction 0x4c006020 (st1 {v0.16b-v2.16b}, [x1])
generate 386 ops from disas_ldst_multiple_struct with current sources,
plus one op from the call to tcg_gen_insn_start in the loop in
gen_intermediate_code_a64.  Furthermore, I see six ops generated after
the loop in gen_intermediate_code_a64, and at least two added
subsequently in optimization, so MAX_OP_PER_INSTR needs to be at least
395.  I do not know whether other instructions, or code during or
after the loop in gen_intermediate_code_a64, might actually require
the value to be bigger than 395 (possibly depending on the
instructions translated before the one generating 386 ops), just that
395 is definitely needed for a GCC testcase that generates that
particular instruction.  So if there is a reliable methodology to
determine the maximum number of ops that might be generated in (one
pass through that loop, plus the code after that loop, plus
optimization), it should be used instead, and might result in a higher
figure (or maybe a higher figure would be safer anyway).

Signed-off-by: Joseph Myers 

---

diff --git a/tcg/tcg.h b/tcg/tcg.h
index c9949aa..a7fa452 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -32,7 +32,7 @@
 #include "tcg-target.h"
 
 /* XXX: make safe guess about sizes */
-#define MAX_OP_PER_INSTR 266
+#define MAX_OP_PER_INSTR 395
 
 #if HOST_LONG_BITS == 32
 #define MAX_OPC_PARAM_PER_ARG 2

-- 
Joseph S. Myers
jos...@codesourcery.com



Re: [Qemu-devel] [Bug 1305402] Re: libvirt fails to start VirtualMachines

2016-09-22 Thread Ryan Harper
Machine type changes may be related to:

https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1626070

There's a PPA in the bug with a fix for at least the wily machine type.

On Thu, Sep 22, 2016 at 6:05 PM, Leo Arias 
wrote:

> This has just happened to me. For some reason, all my machines had
> machine='pc-i440fx-wily'.
> After an update in yakkety, they stopped working.
>
> $ qemu-system-x86_64 -enable-kvm -machine help | grep wily
>
> So I updated the machine xml to a supported machine as Charles
> suggested, and they work again.
>
> Here's the note for my future self about how to do the update:
>
> $ virsh dumpxml $machine-name > /tmp/machine.xml
> Edit the xml.
> $ virsh define /tmp/machine.xml
>
> --
> You received this bug notification because you are subscribed to qemu in
> Ubuntu.
> https://bugs.launchpad.net/bugs/1305402
>
> Title:
>   libvirt fails to start VirtualMachines
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/qemu/+bug/1305402/+subscriptions
>

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1305402

Title:
  libvirt fails to start VirtualMachines

Status in QEMU:
  Invalid
Status in libvirt package in Ubuntu:
  Confirmed
Status in qemu package in Ubuntu:
  Confirmed

Bug description:
  I've created several kvm based machines using virtual machine manager.
  They have operated well over the last 4 days without issue. I did an
  apt-get upgrade, and qemu was in the list of updates.

  After upgrading, I am unable to start any of the provisioned virtual
  machines with the following error output

  virsh # start node2
  error: Failed to start domain node2
  error: internal error: process exited while connecting to monitor: 
qemu-system-x86_64: -machine trusty,accel=kvm,usb=off: Unsupported machine type
  Use -machine help to list supported machines!

  virsh # start node3
  error: Failed to start domain node3
  error: internal error: process exited while connecting to monitor: 
qemu-system-x86_64: -machine trusty,accel=kvm,usb=off: Unsupported machine type
  Use -machine help to list supported machines!

  $ dpkg -l | grep kvm
  ii  qemu-kvm 2.0.0~rc1+dfsg-0ubuntu3 
amd64QEMU Full virtualization on x86 hardware (transitional package)

  Log snippet from vm 'media' that was verified working, and fails to
  start after the upgrade.

  LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
QEMU_AUDIO_DRV=none /usr/bin/kvm-spice -name media -S -machine 
trusty,accel=kvm,usb=off -m 1548 -realtime mlock=off -smp 
1,sockets=1,cores=1,threads=1 -uuid 60b20f7b-6d20-bcb3-f4fc-808a9b2fe0d0 
-no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/media.monitor,server,nowait 
-mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown 
-boot menu=off,strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 
-drive 
file=/var/lib/libvirt/images/media.img,if=none,id=drive-virtio-disk0,format=raw 
-device 
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
 -drive 
file=/home/charles/iso/ubuntu-desktop-12.04.4-amd64.iso,if=none,id=drive-ide0-1-0,readonly=on,format=raw
 -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev 
tap,fd=24,id=hostnet0,vhost=on,vhostfd=26 -device 
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:a0:69:d9,bus=pci.0,addr=0x3 
-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 
-vnc 127.0.0.1:1 -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
  char device redirected to /dev/pts/13 (label charserial0)
  qemu: terminating on signal 15 from pid 31688
  2014-04-10 03:36:54.593+: shutting down
  2014-04-10 03:59:25.487+: starting up
  LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
QEMU_AUDIO_DRV=none /usr/bin/kvm-spice -name media -S -machine 
trusty,accel=kvm,usb=off -m 1548 -realtime mlock=off -smp 
1,sockets=1,cores=1,threads=1 -uuid 60b20f7b-6d20-bcb3-f4fc-808a9b2fe0d0 
-no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/media.monitor,server,nowait 
-mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown 
-boot menu=off,strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 
-drive 
file=/var/lib/libvirt/images/media.img,if=none,id=drive-virtio-disk0,format=raw 
-device 
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
 -drive 
file=/home/charles/iso/ubuntu-desktop-12.04.4-amd64.iso,if=none,id=drive-ide0-1-0,readonly=on,format=raw
 -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev 
tap,fd=24,id=hostnet0,vhost=on,vhostfd=25 -device 

Re: [Qemu-devel] [RFC PATCH v2 06/16] sev: add Secure Encrypted Virtulization (SEV) support

2016-09-22 Thread Michael S. Tsirkin
On Thu, Sep 22, 2016 at 04:12:04PM -0500, Brijesh Singh wrote:
> Hi,
> 
> On 09/22/2016 10:12 AM, Paolo Bonzini wrote:
> > 
> > 
> > > 
> > >   to use encrypted guest launch
> > >   # $QEMU \
> > >  -object sev-receive-info,id=launch0 \
> > >  -object sev-send-info,id=send0 \
> > >  -object sev-guest-info,id=sev0,launch=launch0,send=send0 \
> > >  .
> > > 
> > 
> > References to other objects should be implemented as link properties
> > (e.g. with type 'link').  Then QOM takes care of filling
> > in a QSEVGuestInfo* with the pointer to an object with the right id.
> > 
> > There is some redundancy (e.g. "flags.ks" in launch/receive vs. "ks" in
> > policy).  Can you document the full model in
> > docs/amd-memory-encryption.txt?  It's not necessary to include the
> > kernel API documentation.
> > 
> 
> The flags.ks means that hypervisor requested the key-sharing. The policy.ks
> means that key-sharing is allowed by guest owner. The values in sev-policy
> should be provided by the guest owner. The content of policy field is used
> during the measurement calculation.

We excluded the measurement part for now, so I think this can
go as well.

> If hypervisor changes anything into
> policy field without guest owners permission then measurement value will not
> match.

IMHO measurement is mostly useless with current hardware.

I suggest that for now we just assume that hypervisor is not
attacking the guest while it's booting.
Extend this later once first part is merged.

> I can think of one case where flag.ks may be used.
> 
> e.g lets say guest policy allows key sharing and this is first SEV guest in
> the system then hypervisor will set flags.ks=0. In next guest launch it can
> set flags.ks=1 and use the SEV handle from previous guest.
>
> I will add some more text to clarify it in doc and property description.
> 
> > Paolo
> > 



Re: [Qemu-devel] [PATCH] MAINTAINERS: Add some more files to the HMP section

2016-09-22 Thread Eric Blake
On 09/22/2016 02:32 PM, Thomas Huth wrote:
> The hmp-commands-info.hx, hmp.h and include/monitor/hmp-target.h
> files were classified as unmaintained. Let's add them to the
> HMP section.
> 
> Signed-off-by: Thomas Huth 
> ---
>  MAINTAINERS | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Eric Blake 

Is Luiz still the best maintainer here, though, given that he is not
listed as a maintainer on corresponding QMP changes?  But that's
unrelated to this patch.

> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9da3d09..3879e1c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1160,8 +1160,9 @@ Human Monitor (HMP)
>  M: Luiz Capitulino 
>  S: Maintained
>  F: monitor.c
> -F: hmp.c
> -F: hmp-commands.hx
> +F: hmp.[ch]
> +F: hmp-commands*.hx
> +F: include/monitor/hmp-target.h
>  T: git git://repo.or.cz/qemu/qmp-unstable.git queue/qmp
>  
>  Network device backends
> 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 2/5] apic: add send_msi() to APICCommonClass

2016-09-22 Thread Radim Krčmář
The MMIO based interface to APIC doesn't work well with MSIs that have
upper address bits set (remapped x2APIC MSIs).  A specialized interface
is a quick and dirty way to avoid the shortcoming.

Signed-off-by: Radim Krčmář 
---
 hw/i386/kvm/apic.c  | 19 +--
 hw/i386/xen/xen_apic.c  |  6 ++
 hw/intc/apic.c  |  6 ++
 include/hw/i386/apic_internal.h |  4 
 4 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
index feb00024f20c..7cc1acd63d32 100644
--- a/hw/i386/kvm/apic.c
+++ b/hw/i386/kvm/apic.c
@@ -168,6 +168,17 @@ static void kvm_apic_external_nmi(APICCommonState *s)
 run_on_cpu(CPU(s->cpu), do_inject_external_nmi, s);
 }
 
+static void kvm_send_msi(MSIMessage *msg)
+{
+int ret;
+
+ret = kvm_irqchip_send_msi(kvm_state, *msg);
+if (ret < 0) {
+fprintf(stderr, "KVM: injection failed, MSI lost (%s)\n",
+strerror(-ret));
+}
+}
+
 static uint64_t kvm_apic_mem_read(void *opaque, hwaddr addr,
   unsigned size)
 {
@@ -178,13 +189,8 @@ static void kvm_apic_mem_write(void *opaque, hwaddr addr,
uint64_t data, unsigned size)
 {
 MSIMessage msg = { .address = addr, .data = data };
-int ret;
 
-ret = kvm_irqchip_send_msi(kvm_state, msg);
-if (ret < 0) {
-fprintf(stderr, "KVM: injection failed, MSI lost (%s)\n",
-strerror(-ret));
-}
+kvm_send_msi();
 }
 
 static const MemoryRegionOps kvm_apic_io_ops = {
@@ -231,6 +237,7 @@ static void kvm_apic_class_init(ObjectClass *klass, void 
*data)
 k->enable_tpr_reporting = kvm_apic_enable_tpr_reporting;
 k->vapic_base_update = kvm_apic_vapic_base_update;
 k->external_nmi = kvm_apic_external_nmi;
+k->send_msi = kvm_send_msi;
 }
 
 static const TypeInfo kvm_apic_info = {
diff --git a/hw/i386/xen/xen_apic.c b/hw/i386/xen/xen_apic.c
index 21d68ee04b0a..55769eba7ede 100644
--- a/hw/i386/xen/xen_apic.c
+++ b/hw/i386/xen/xen_apic.c
@@ -68,6 +68,11 @@ static void xen_apic_external_nmi(APICCommonState *s)
 {
 }
 
+static void xen_send_msi(MSIMessage *msi)
+{
+xen_hvm_inject_msi(msi->address, msi->data);
+}
+
 static void xen_apic_class_init(ObjectClass *klass, void *data)
 {
 APICCommonClass *k = APIC_COMMON_CLASS(klass);
@@ -78,6 +83,7 @@ static void xen_apic_class_init(ObjectClass *klass, void 
*data)
 k->get_tpr = xen_apic_get_tpr;
 k->vapic_base_update = xen_apic_vapic_base_update;
 k->external_nmi = xen_apic_external_nmi;
+k->send_msi = xen_send_msi;
 }
 
 static const TypeInfo xen_apic_info = {
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index 7bd1d279c463..4f3fb44d05e4 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -900,6 +900,11 @@ static void apic_unrealize(DeviceState *dev, Error **errp)
 local_apics[s->id] = NULL;
 }
 
+static void apic_send_msi_struct(MSIMessage *msi)
+{
+apic_send_msi(msi->address, msi->data);
+}
+
 static void apic_class_init(ObjectClass *klass, void *data)
 {
 APICCommonClass *k = APIC_COMMON_CLASS(klass);
@@ -913,6 +918,7 @@ static void apic_class_init(ObjectClass *klass, void *data)
 k->external_nmi = apic_external_nmi;
 k->pre_save = apic_pre_save;
 k->post_load = apic_post_load;
+k->send_msi = apic_send_msi_struct;
 }
 
 static const TypeInfo apic_info = {
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index 9ba8a5c87f90..32b083ad2926 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -146,6 +146,10 @@ typedef struct APICCommonClass
 void (*pre_save)(APICCommonState *s);
 void (*post_load)(APICCommonState *s);
 void (*reset)(APICCommonState *s);
+/* send_msi emulates an APIC bus and its proper place would be in a new
+ * device, but it's convenient to have it here for now.
+ */
+void (*send_msi)(MSIMessage *msi);
 } APICCommonClass;
 
 struct APICCommonState {
-- 
2.10.0




Re: [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp

2016-09-22 Thread Richard Henderson

On 09/15/2016 06:16 AM, Paolo Bonzini wrote:

This comes from free from unifying tcg_reg_alloc_mov and
tcg_reg_alloc_movi's handling of TEMP_VAL_CONST.  It triggers
often on moves to cc_dst, such as the following translation
of "sub $0x3c,%esp":

  before:  after:
  subl   $0x3c,%ebpsubl   $0x3c,%ebp
  movl   %ebp,0x10(%r14)   movl   %ebp,0x10(%r14)
  movl   $0x3c,%ebxmovl   $0x3c,0x2c(%r14)
  movl   %ebx,0x2c(%r14)

Signed-off-by: Paolo Bonzini 
---
 tcg/tcg.c | 56 +++-
 1 file changed, 27 insertions(+), 29 deletions(-)


Queued.  Thanks,


r~



Re: [Qemu-devel] [PATCH] MAINTAINERS: Add some more files to the HMP section

2016-09-22 Thread Luiz Capitulino
On Thu, 22 Sep 2016 21:32:38 +0200
Thomas Huth  wrote:

> The hmp-commands-info.hx, hmp.h and include/monitor/hmp-target.h
> files were classified as unmaintained. Let's add them to the
> HMP section.
> 
> Signed-off-by: Thomas Huth 

Reviewed-by: Luiz Capitulino 

I probably should downgrade the status of HMP to "Odd Fixes",
as I've not been dedicating any time for it. If anyone is
interested in taking up it let me know.

> ---
>  MAINTAINERS | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9da3d09..3879e1c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1160,8 +1160,9 @@ Human Monitor (HMP)
>  M: Luiz Capitulino 
>  S: Maintained
>  F: monitor.c
> -F: hmp.c
> -F: hmp-commands.hx
> +F: hmp.[ch]
> +F: hmp-commands*.hx
> +F: include/monitor/hmp-target.h
>  T: git git://repo.or.cz/qemu/qmp-unstable.git queue/qmp
>  
>  Network device backends




[Qemu-devel] [PATCH v4 3/3] tests: start generic qemu-qmp tests

2016-09-22 Thread Marc-André Lureau
These 2 tests exhibit two qmp bugs fixed by the previous patches.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrange 
Reviewed-by: Eric Blake 
---
 tests/test-qemu-qmp.c  | 69 ++
 tests/Makefile.include |  2 ++
 tests/.gitignore   |  1 +
 3 files changed, 72 insertions(+)
 create mode 100644 tests/test-qemu-qmp.c

diff --git a/tests/test-qemu-qmp.c b/tests/test-qemu-qmp.c
new file mode 100644
index 000..9d05829
--- /dev/null
+++ b/tests/test-qemu-qmp.c
@@ -0,0 +1,69 @@
+/*
+ * QTest testcase for qemu qmp commands
+ *
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+
+static void test_object_add_without_props(void)
+{
+QDict *ret, *error;
+const gchar *klass, *desc;
+
+ret = qmp("{'execute': 'object-add',"
+  " 'arguments': { 'qom-type': 'memory-backend-ram', 'id': 'ram1' 
} }");
+g_assert_nonnull(ret);
+
+error = qdict_get_qdict(ret, "error");
+klass = qdict_get_try_str(error, "class");
+desc = qdict_get_try_str(error, "desc");
+
+g_assert_cmpstr(klass, ==, "GenericError");
+g_assert_cmpstr(desc, ==, "can't create backend with size 0");
+
+QDECREF(ret);
+}
+
+static void test_qom_set_without_value(void)
+{
+QDict *ret, *error;
+const gchar *klass, *desc;
+
+ret = qmp("{'execute': 'qom-set',"
+  " 'arguments': { 'path': '/machine', 'property': 'rtc-time' } 
}");
+g_assert_nonnull(ret);
+
+error = qdict_get_qdict(ret, "error");
+klass = qdict_get_try_str(error, "class");
+desc = qdict_get_try_str(error, "desc");
+
+g_assert_cmpstr(klass, ==, "GenericError");
+g_assert_cmpstr(desc, ==, "Parameter 'value' is missing");
+
+QDECREF(ret);
+}
+
+int main(int argc, char **argv)
+{
+int ret;
+
+g_test_init(, , NULL);
+
+qtest_start("");
+
+qtest_add_func("/qemu-qmp/object-add-without-props",
+   test_object_add_without_props);
+qtest_add_func("/qemu-qmp/qom-set-without-value",
+   test_qom_set_without_value);
+
+ret = g_test_run();
+
+qtest_end();
+
+return ret;
+}
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 6052a38..93f2ba1 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -296,6 +296,7 @@ check-qtest-xtensaeb-y = $(check-qtest-xtensa-y)
 check-qtest-s390x-y = tests/boot-serial-test$(EXESUF)
 
 check-qtest-generic-y += tests/qom-test$(EXESUF)
+check-qtest-generic-y += tests/test-qemu-qmp$(EXESUF)
 
 qapi-schema += alternate-any.json
 qapi-schema += alternate-array.json
@@ -634,6 +635,7 @@ tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
 tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o
 tests/qom-test$(EXESUF): tests/qom-test.o
+tests/test-qemu-qmp$(EXESUF): tests/test-qemu-qmp.o
 tests/drive_del-test$(EXESUF): tests/drive_del-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/nvme-test$(EXESUF): tests/nvme-test.o
diff --git a/tests/.gitignore b/tests/.gitignore
index b4a9cfc..abf3926 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -54,6 +54,7 @@ test-qdist
 test-qga
 test-qht
 test-qht-par
+test-qemu-qmp
 test-qmp-commands
 test-qmp-commands.h
 test-qmp-event
-- 
2.10.0




[Qemu-devel] [PATCH v4 1/3] qmp: fix object-add assert() without props

2016-09-22 Thread Marc-André Lureau
Since commit ad739706bbadee49, user_creatable_add_type() expects to be
given a qdict. However, if object-add is called without props, you reach
the assert: "qemu/qom/object_interfaces.c:115: user_creatable_add_type:
Assertion `qdict' failed.", because the qdict isn't created in this
case (it's optional).

Furthermore, qmp_input_visitor_new() is not meant to be called without a
dict, and a further commit will assert in this situation.

If none given, create an empty qdict in qmp to avoid the
user_creatable_add_type() assert(qdict).

Signed-off-by: Marc-André Lureau 
Reviewed-by: Eric Blake 
---
 qmp.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/qmp.c b/qmp.c
index 6733463..b6de482 100644
--- a/qmp.c
+++ b/qmp.c
@@ -665,7 +665,7 @@ void qmp_add_client(const char *protocol, const char 
*fdname,
 void qmp_object_add(const char *type, const char *id,
 bool has_props, QObject *props, Error **errp)
 {
-const QDict *pdict = NULL;
+QDict *pdict;
 Visitor *v;
 Object *obj;
 
@@ -675,14 +675,18 @@ void qmp_object_add(const char *type, const char *id,
 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
 return;
 }
+QINCREF(pdict);
+} else {
+pdict = qdict_new();
 }
 
-v = qmp_input_visitor_new(props, true);
+v = qmp_input_visitor_new(QOBJECT(pdict), true);
 obj = user_creatable_add_type(type, id, pdict, v, errp);
 visit_free(v);
 if (obj) {
 object_unref(obj);
 }
+QDECREF(pdict);
 }
 
 void qmp_object_del(const char *id, Error **errp)
-- 
2.10.0




Re: [Qemu-devel] [PATCH v2 10/14] pc: kvm_apic: pass APIC ID depending on xAPIC/x2APIC mode

2016-09-22 Thread Radim Krčmář
2016-09-22 16:36+0200, Paolo Bonzini:
> On 22/09/2016 14:50, Igor Mammedov wrote:
>> +#ifdef KVM_CAP_X2APIC_API
>> +if (kvm_check_extension(s, KVM_CAP_X2APIC_API)) {
>> +has_x2apic_ids = !kvm_vm_enable_cap(s, KVM_CAP_X2APIC_API, 0,
>> +KVM_X2APIC_API_USE_32BIT_IDS);
>> +}
>> +#endif
>> +
> 
> Radim, whose patches are going to set
> KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK?

I added kvm_enable_x2apic() helper for intel_iommu that enables both,
because we really want to make sure that both are enabled before
allowing EIM.  (And then I didn't post those patches ... ameding that
after a rebase and a quick retest.)

We'd better forbid APIC IDs above 255 without "intel_iommu,eim=on", so
reusing kvm_enable_x2apic() and enabling both in Igor's patches would be
just a bit nicer.

Having separate KVM_X2APIC_API_USE_32BIT_IDS and
KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK isn't as useful as I thought it
would be ...



Re: [Qemu-devel] Default CPU for NMI injection (QMP and IPMI)

2016-09-22 Thread Corey Minyard

On 09/22/2016 01:42 PM, Eduardo Habkost wrote:

On Wed, Sep 21, 2016 at 03:38:25PM -0500, Corey Minyard wrote:

On 09/21/2016 03:20 PM, Eduardo Habkost wrote:

Hi,

I was looking at the monitor code handling the "current CPU", and
noticed that qmp_inject_nmi() looks suspicious: it is a QMP
command, but uses monitor_get_cpu_index().

In addition to the "inject-nmi" QMP command, qmp_inject_nmi() is
used at:
* hmp_inject_nmi()
* ipmi_do_hw_op() (IPMI_SEND_NMI operation)

This confused me, so I would like to know:

1) What exactly "default CPU" is supposed to mean in the
 "inject-nmi" QMP command documentation?
2) To which CPU(s) are NMIs supposed to be sent when triggered by
 IPMI messages? I don't know how to test the IPMI code, but it
 looks like it will crash if QEMU runs without any monitor.


It doesn't matter which CPU it goes to.

OK, so in the case of IPMI we can make it send the NMI to the
first CPU.


I haven't tested without a monitor, so I'm not sure.  Does
another interface into the NMI code need to be added?

There's another interface, already: nmi_monitor_handle() already
gets a cpu_index argument and doesn't depend on the monitor code.
We could change the IPMI code to call
nmi_monitor_handle(first_cpu->cpu_index) directly.


Ok, I'll make a change for this, unless we decide to fix it
another way.


In the case of the inject-nmi QMP command, I need to understand
what "default CPU" is supposed to mean in the inject-nmi
documentation. Maybe it can be changed to use the first CPU, too
(that's probably the existing behavior because there's no way to
change cur_mon->mon_cpu in a QMP monitor).


I looked through is a bit, and the only place I found it was used was
the x390 code.

If we remove the CPU index from this, then the IPMI device can
keep the same interface.

Thanks,

-corey




[Qemu-devel] [PATCH 5/5] intel_iommu: do not allow EIM without KVM support

2016-09-22 Thread Radim Krčmář
Cluster x2APIC cannot work without KVM's x2apic API when the maximal
APIC ID is > 8.  Make the code simpler by completely forbidding EIM
without KVM's x2apic API.

Signed-off-by: Radim Krčmář 
---
  I think it the dependency would be nicer in the eim setter, but the
  other dependency, for interrupt remapping, isn't there and I didn't
  venture for reasons.
---
 hw/i386/intel_iommu.c  |  7 +++
 target-i386/kvm-stub.c |  5 +
 target-i386/kvm.c  | 13 +
 target-i386/kvm_i386.h |  1 +
 4 files changed, 26 insertions(+)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 269e37e71af4..0304a1bf6f1d 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -32,6 +32,7 @@
 #include "hw/pci-host/q35.h"
 #include "sysemu/kvm.h"
 #include "hw/i386/apic_internal.h"
+#include "kvm_i386.h"
 
 /*#define DEBUG_INTEL_IOMMU*/
 #ifdef DEBUG_INTEL_IOMMU
@@ -2485,6 +2486,12 @@ static void vtd_realize(DeviceState *dev, Error **errp)
  "kernel-irqchip=on, please use 'split|off'.");
 exit(1);
 }
+
+if (s->eim_supported && kvm_irqchip_in_kernel() &&
+!kvm_enable_x2apic()) {
+error_report("EIM requires support from the KVM side (X2APIC_API).");
+exit(1);
+}
 }
 
 static void vtd_class_init(ObjectClass *klass, void *data)
diff --git a/target-i386/kvm-stub.c b/target-i386/kvm-stub.c
index cdf15061091d..bda4dc2f0c57 100644
--- a/target-i386/kvm-stub.c
+++ b/target-i386/kvm-stub.c
@@ -25,6 +25,11 @@ bool kvm_has_smm(void)
 return 1;
 }
 
+bool kvm_enable_x2apic(void)
+{
+return false;
+}
+
 /* This function is only called inside conditionals which we
  * rely on the compiler to optimize out when CONFIG_KVM is not
  * defined.
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index f1ad805665ad..4c0a4df5eaea 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -128,6 +128,19 @@ bool kvm_allows_irq0_override(void)
 return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
 }
 
+static bool kvm_x2apic_api_set_flags(uint64_t flags)
+{
+KVMState *s = KVM_STATE(current_machine->accelerator);
+
+return !kvm_vm_enable_cap(s, KVM_CAP_X2APIC_API, 0, flags);
+}
+
+bool kvm_enable_x2apic(void)
+{
+return kvm_x2apic_api_set_flags(KVM_X2APIC_API_USE_32BIT_IDS |
+KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK);
+}
+
 static int kvm_get_tsc(CPUState *cs)
 {
 X86CPU *cpu = X86_CPU(cs);
diff --git a/target-i386/kvm_i386.h b/target-i386/kvm_i386.h
index 42b00af1b1c3..559dd8b5acd2 100644
--- a/target-i386/kvm_i386.h
+++ b/target-i386/kvm_i386.h
@@ -41,4 +41,5 @@ int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, 
uint32_t vector,
 int kvm_device_msix_assign(KVMState *s, uint32_t dev_id);
 int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id);
 
+bool kvm_enable_x2apic(void);
 #endif
-- 
2.10.0




Re: [Qemu-devel] [RFC PATCH v2 06/16] sev: add Secure Encrypted Virtulization (SEV) support

2016-09-22 Thread Brijesh Singh

Hi,

On 09/22/2016 10:12 AM, Paolo Bonzini wrote:





  to use encrypted guest launch
  # $QEMU \
 -object sev-receive-info,id=launch0 \
 -object sev-send-info,id=send0 \
 -object sev-guest-info,id=sev0,launch=launch0,send=send0 \
 .



References to other objects should be implemented as link properties
(e.g. with type 'link').  Then QOM takes care of filling
in a QSEVGuestInfo* with the pointer to an object with the right id.

There is some redundancy (e.g. "flags.ks" in launch/receive vs. "ks" in
policy).  Can you document the full model in
docs/amd-memory-encryption.txt?  It's not necessary to include the
kernel API documentation.



The flags.ks means that hypervisor requested the key-sharing. The 
policy.ks means that key-sharing is allowed by guest owner. The values 
in sev-policy should be provided by the guest owner. The content of 
policy field is used during the measurement calculation. If hypervisor 
changes anything into policy field without guest owners permission then 
measurement value will not match.


I can think of one case where flag.ks may be used.

e.g lets say guest policy allows key sharing and this is first SEV guest 
in the system then hypervisor will set flags.ks=0. In next guest launch 
it can set flags.ks=1 and use the SEV handle from previous guest.


I will add some more text to clarify it in doc and property description.


Paolo





[Qemu-devel] [PATCH 0/5] intel_iommu: fix EIM

2016-09-22 Thread Radim Krčmář
intel_iommu exposed EIM (extended interrupt mode) feature, which in turn
made the guest think that using x2APIC is a good idea.  It was not:
QEMU clamped all addresses to 8 bits (effectively allowing only APIC IDs
below 8 in cluster mode) and 0xff was also interpreted as x2APIC
broadcast even in physical mode.

This series forbids EIM unless KVM is configured to use full 32 bit
addresses and doesn't have the broadcast quirk.

On top of this, it would be great if we had a mechanism that enabled EIM
whenever it can be used -- it is disabled by default now.


Peter Xu (1):
  intel_iommu: add "eim" property

Radim Krčmář (4):
  apic: add global apic_get_class()
  apic: add send_msi() to APICCommonClass
  intel_iommu: pass whole remapped addresses to apic
  intel_iommu: do not allow EIM without KVM support

 hw/i386/intel_iommu.c   | 41 +
 hw/i386/kvm/apic.c  | 19 +--
 hw/i386/xen/xen_apic.c  |  6 ++
 hw/intc/apic.c  |  6 ++
 hw/intc/apic_common.c   | 14 ++
 include/hw/i386/apic_internal.h |  7 +++
 include/hw/i386/intel_iommu.h   |  1 +
 target-i386/kvm-stub.c  |  5 +
 target-i386/kvm.c   | 13 +
 target-i386/kvm_i386.h  |  1 +
 10 files changed, 95 insertions(+), 18 deletions(-)

-- 
2.10.0




Re: [Qemu-devel] [Qemu-ppc] [PULL 00/44] ppc-for-2.8 queue 20160922

2016-09-22 Thread Richard Henderson

On 09/22/2016 10:38 AM, Nikunj A Dadhania wrote:

Peter Maydell <peter.mayd...@linaro.org> writes:


On 22 September 2016 at 07:36, David Gibson <da...@gibson.dropbear.id.au> wrote:

The following changes since commit a008535b9fa396226ff9cf78b8ac5f3584bda58e:

  build-sys: fix make install regression (2016-09-20 11:32:43 +0100)

are available in the git repository at:

  git://github.com/dgibson/qemu.git tags/ppc-for-2.8-20160922

for you to fetch changes up to 2832da4b6fc549d5feb2cf9fe53ad98cee894327:

  monitor: fix crash for platforms without a CPU 0 (2016-09-22 15:53:01 +1000)


ppc patch queue 2016-09-22

This is my second pull request of ppc and spapr related patches for
qemu-2.8.  Included here are
* TCG implementations for more POWER9 instructions
* Some preliminary XICS fixes in preparataion for the pnv machine type
* A significant ADB (Macintosh kbd/mouse) cleanup
* Some conversions to use trace instead of debug macros
* Fixes to correctly handle global TLB flush synchronization in
  TCG.  This is already a bug, but it will have much more impact
  when we get MTTCG
* Add more qtest testcases for Power
* Some MAINTAINERS updates
* Assorted bugfixes

This touches some test files and monitor.c which are technically
outside the ppc code, but coming through this tree because the changes
are primarily of interest to ppc.




I'm afraid this fails to build with clang:

/home/petmay01/linaro/qemu-for-merges/target-ppc/translate.c:532:16:
error: unused function 'L' [-Werro
r,-Wunused-function]
EXTRACT_HELPER(L, 16, 2);
   ^
1 error generated.


 +/* darn */
 +static void gen_darn(DisasContext *ctx)
 +{
 +int l = L(ctx->opcode);

Used here, false positive ?


ppc vs ppc64?


r~



[Qemu-devel] [PATCH v2] build-sys: generate tests/.gitignore

2016-09-22 Thread Marc-André Lureau
It's too easy to forget about updating the .gitignore, so this is an
attempt at generating it instead.

This approach assumes that the files to clean are the one to put in
the .gitignore.

Signed-off-by: Marc-André Lureau 
---
v2:
 - fix make check-clean
 - improve adding $(QEMU_IOTESTS_HELPERS-y) in cleanfiles (it needs a patsubst 
because tests/ is present 2 times)
 - use quiet-command
 - fix cleanfiles +=

 tests/Makefile.include | 26 +---
 tests/.gitignore   | 82 --
 2 files changed, 22 insertions(+), 86 deletions(-)
 delete mode 100644 tests/.gitignore

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 6052a38..cf81fd7 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -782,8 +782,21 @@ $(patsubst %, check-%, $(check-qapi-schema-y)): 
check-%.json: $(SRC_PATH)/%.json
@perl -p -e 's|\Q$(SRC_PATH)\E/||g' $*.test.err | diff -q 
$(SRC_PATH)/$*.err -
@diff -q $(SRC_PATH)/$*.exit $*.test.exit
 
-# Consolidated targets
+tests-cleanfiles = *.o
+tests-cleanfiles += .gitignore
+tests-cleanfiles += qht-bench$(EXESUF)
+tests-cleanfiles += qapi-schema/*.test.*
+tests-cleanfiles += test-qapi-event.[ch]
+tests-cleanfiles += test-qapi-types.[ch]
+tests-cleanfiles += test-qapi-visit.[ch]
+tests-cleanfiles += test-qmp-introspect.[ch]
+tests-cleanfiles += test-qmp-commands.h
+tests-cleanfiles += test-qmp-marshal.c
+tests-cleanfiles += $(subst tests/,,$(check-unit-y))
+tests-cleanfiles += $(subst tests/,,$(check-qtest-y))
+tests-cleanfiles += $(patsubst tests/%,%,$(QEMU_IOTESTS_HELPERS-y))
 
+# Consolidated targets
 .PHONY: check-qapi-schema check-qtest check-unit check check-clean
 check-qapi-schema: $(patsubst %,check-%, $(check-qapi-schema-y))
 check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS))
@@ -792,14 +805,19 @@ check-block: $(patsubst %,check-%, $(check-block-y))
 check: check-qapi-schema check-unit check-qtest
 check-clean:
$(MAKE) -C tests/tcg clean
-   rm -rf $(check-unit-y) tests/*.o $(QEMU_IOTESTS_HELPERS-y)
-   rm -rf $(sort $(foreach target,$(SYSEMU_TARGET_LIST), 
$(check-qtest-$(target)-y)) $(check-qtest-generic-y))
-
+   (cd tests && rm -rf $(tests-cleanfiles))
 clean: check-clean
 
 # Build the help program automatically
 
 all: $(QEMU_IOTESTS_HELPERS-y)
 
+ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if 
$(MAKECMDGOALS),,fail))
+$(SRC_PATH)/tests/.gitignore:
+   $(call quiet-command, echo "$(tests-cleanfiles)" | xargs -n1 | sort > 
$@, \
+ " GEN $(@F)")
+Makefile: $(SRC_PATH)/tests/.gitignore
+endif
+
 -include $(wildcard tests/*.d)
 -include $(wildcard tests/libqos/*.d)
diff --git a/tests/.gitignore b/tests/.gitignore
deleted file mode 100644
index b4a9cfc..000
--- a/tests/.gitignore
+++ /dev/null
@@ -1,82 +0,0 @@
-check-qdict
-check-qfloat
-check-qint
-check-qjson
-check-qlist
-check-qnull
-check-qstring
-check-qom-interface
-check-qom-proplist
-qht-bench
-rcutorture
-test-aio
-test-base64
-test-bitops
-test-blockjob-txn
-test-clone-visitor
-test-coroutine
-test-crypto-afsplit
-test-crypto-block
-test-crypto-cipher
-test-crypto-hash
-test-crypto-ivgen
-test-crypto-pbkdf
-test-crypto-secret
-test-crypto-tlscredsx509
-test-crypto-tlscredsx509-work/
-test-crypto-tlscredsx509-certs/
-test-crypto-tlssession
-test-crypto-tlssession-work/
-test-crypto-tlssession-client/
-test-crypto-tlssession-server/
-test-crypto-xts
-test-cutils
-test-hbitmap
-test-int128
-test-iov
-test-io-channel-buffer
-test-io-channel-command
-test-io-channel-command.fifo
-test-io-channel-file
-test-io-channel-file.txt
-test-io-channel-socket
-test-io-channel-tls
-test-io-task
-test-logging
-test-mul64
-test-opts-visitor
-test-qapi-event.[ch]
-test-qapi-types.[ch]
-test-qapi-visit.[ch]
-test-qdev-global-props
-test-qemu-opts
-test-qdist
-test-qga
-test-qht
-test-qht-par
-test-qmp-commands
-test-qmp-commands.h
-test-qmp-event
-test-qmp-input-strict
-test-qmp-input-visitor
-test-qmp-introspect.[ch]
-test-qmp-marshal.c
-test-qmp-output-visitor
-test-rcu-list
-test-replication
-test-rfifolock
-test-string-input-visitor
-test-string-output-visitor
-test-thread-pool
-test-throttle
-test-timed-average
-test-visitor-serialization
-test-vmstate
-test-write-threshold
-test-x86-cpuid
-test-xbzrle
-test-netfilter
-test-filter-mirror
-test-filter-redirector
-*-test
-qapi-schema/*.test.*
-- 
2.10.0




Re: [Qemu-devel] [PATCH] build: handle deprecation of major() in sys/types.h

2016-09-22 Thread no-reply
Hi,

Your series failed automatic build test. Please find the testing commands and
their output below. If you have docker installed, you can probably reproduce it
locally.

Type: series
Message-id: 20160922205647.18237-1-rkrc...@redhat.com
Subject: [Qemu-devel] [PATCH] build: handle deprecation of major() in 
sys/types.h

=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
make J=8 docker-test-quick@centos6
make J=8 docker-test-mingw@fedora
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag] patchew/20160922205647.18237-1-rkrc...@redhat.com -> 
patchew/20160922205647.18237-1-rkrc...@redhat.com
Switched to a new branch 'test'
4ccefec build: handle deprecation of major() in sys/types.h

=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf'
  BUILD centos6
  ARCHIVE qemu.tgz
  ARCHIVE dtc.tgz
  COPY RUNNER
  RUN test-quick in centos6
No C++ compiler available; disabling C++ specific optional code
Install prefix/tmp/qemu-test/src/tests/docker/install
BIOS directory/tmp/qemu-test/src/tests/docker/install/share/qemu
binary directory  /tmp/qemu-test/src/tests/docker/install/bin
library directory /tmp/qemu-test/src/tests/docker/install/lib
module directory  /tmp/qemu-test/src/tests/docker/install/lib/qemu
libexec directory /tmp/qemu-test/src/tests/docker/install/libexec
include directory /tmp/qemu-test/src/tests/docker/install/include
config directory  /tmp/qemu-test/src/tests/docker/install/etc
local state directory   /tmp/qemu-test/src/tests/docker/install/var
Manual directory  /tmp/qemu-test/src/tests/docker/install/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path   /tmp/qemu-test/src
C compilercc
Host C compiler   cc
C++ compiler  
Objective-C compiler cc
ARFLAGS   rv
CFLAGS-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -pthread 
-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include   -g 
QEMU_CFLAGS   -I/usr/include/pixman-1-fPIE -DPIE -m64 -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes 
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes 
-fno-strict-aliasing -fno-common -fwrapv  -Wendif-labels -Wmissing-include-dirs 
-Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self 
-Wignored-qualifiers -Wold-style-declaration -Wold-style-definition 
-Wtype-limits -fstack-protector-all
LDFLAGS   -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
make  make
install   install
pythonpython -B
smbd  /usr/sbin/smbd
module supportno
host CPU  x86_64
host big endian   no
target list   x86_64-softmmu aarch64-softmmu
tcg debug enabled no
gprof enabled no
sparse enabledno
strip binariesyes
profiler  no
static build  no
pixmansystem
SDL support   yes (1.2.14)
GTK support   no 
GTK GL supportno
VTE support   no 
TLS priority  NORMAL
GNUTLS supportno
GNUTLS rndno
libgcrypt no
libgcrypt kdf no
nettleno 
nettle kdfno
libtasn1  no
curses supportno
virgl support no
curl support  no
mingw32 support   no
Audio drivers oss
Block whitelist (rw) 
Block whitelist (ro) 
VirtFS supportno
VNC support   yes
VNC SASL support  no
VNC JPEG support  no
VNC PNG support   no
xen support   no
brlapi supportno
bluez  supportno
Documentation no
PIE   yes
vde support   no
netmap supportno
Linux AIO support no
ATTR/XATTR support yes
Install blobs yes
KVM support   yes
RDMA support  no
TCG interpreter   no
fdt support   yes
preadv supportyes
fdatasync yes
madvise   yes
posix_madvise yes
uuid support  no
libcap-ng support no
vhost-net support yes
vhost-scsi support yes
vhost-vsock support yes
Trace backendslog
spice support no 
rbd support   no
xfsctl supportno
smartcard support no
libusbno
usb net redir no
OpenGL supportno
OpenGL dmabufsno
libiscsi support  no
libnfs supportno
build guest agent yes
QGA VSS support   no
QGA w32 disk info no
QGA MSI support   no
seccomp support   no
coroutine backend ucontext
coroutine poolyes
GlusterFS support no
Archipelago support no
gcov  gcov
gcov enabled  no
TPM support   yes
libssh2 support   no
TPM passthrough   yes
QOM debugging yes
vhdx  no
lzo support   no
snappy supportno
bzip2 support no
NUMA host support no
tcmalloc support  no
jemalloc support  no
avx2 optimization no
replication support yes
  GEN   x86_64-softmmu/config-devices.mak.tmp
  GEN   aarch64-softmmu/config-devices.mak.tmp
  GEN   config-host.h
  GEN   qemu-options.def
  GEN   qmp-commands.h
  GEN   

Re: [Qemu-devel] [PATCH] build-sys: generate .gitignore

2016-09-22 Thread Eric Blake
On 09/22/2016 03:47 PM, Marc-André Lureau wrote:

>> 
>>  # Consolidated targets
>> +tests-cleanfiles = *.o
>> +tests-cleanfiles = .gitignore
>> +tests-cleanfiles += qht-bench$(EXESUF)

Missed this on the first round: you meant to use += on the .gitignore
line.  Without it, you aren't excluding ANY .o files.

>>> +ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if
>> $(MAKECMDGOALS),,fail))
>>> +$(SRC_PATH)/tests/.gitignore:
>>> + echo "$(tests-cleanfiles)" | xargs -n1 | sort > $@
>>
>> This line is TOO noisy; you'll want to wrap it into a $(call
>> quiet-command...).
>>
> 
> Yep
> 
> 
>>
>> You could also do it with fewer processes and less typing, as:
>>
>> printf %s\\n $(tests-cleanfiles) | sort > $@
>>
> 
> Is there a way for printf to split the variable?
> 
> echo "*.o foo" | xargs -n1
> *.o
> foo
> 
> vs
> 
> pritnf %s\\n "*.o foo"
> *.o foo
> 
> If I remove the quote in the Makefile, then it will expand to all the
> non/exisiting .o files.

I thought you WANTED shell globbing; but now I see that you don't (you
want a literal glob output into the .gitignore).  I guess I got thrown
by the fact that I didn't see *.o in the generated .gitignore (never
mind that I didn't see ANY .o...), from the bug pointed out above.

Okay, so you DO want to convert make's spaces into newlines, while
avoiding globbing.  My initial thought was that 'xargs -n1' feels a bit
heavy-handed; tr ' ' '\n' would do the same thing but then you aren't
shaving off any processes or any typing.  You can temporarily disable
file globbing by playing with 'set -f', but that also feels awkward.  So
maybe your approach is best after all.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH] MAINTAINERS: Add some more files to the HMP section

2016-09-22 Thread Thomas Huth
The hmp-commands-info.hx, hmp.h and include/monitor/hmp-target.h
files were classified as unmaintained. Let's add them to the
HMP section.

Signed-off-by: Thomas Huth 
---
 MAINTAINERS | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9da3d09..3879e1c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1160,8 +1160,9 @@ Human Monitor (HMP)
 M: Luiz Capitulino 
 S: Maintained
 F: monitor.c
-F: hmp.c
-F: hmp-commands.hx
+F: hmp.[ch]
+F: hmp-commands*.hx
+F: include/monitor/hmp-target.h
 T: git git://repo.or.cz/qemu/qmp-unstable.git queue/qmp
 
 Network device backends
-- 
1.8.3.1




Re: [Qemu-devel] [PULL 00/13] AVR target

2016-09-22 Thread Bastian Koppelmann
On 09/22/2016 06:10 PM, Richard Henderson wrote:
> On 09/21/2016 11:40 PM, Thomas Huth wrote:
>> Slowly we're getting really a lot of target-something folders in the
>> main directory. Maybe we should rather introduce a singly "target"
>> folder instead and put all the targets under that folder? So we then
>> get target/avr/, target/ppc/, target/i386/ etc. in the tree instead.
>> Would look much more tidied up to me. Our main folder is IMHO still
>> too much overcrowded.
> 
> I don't feel the same overcrowding, but I wouldn't be opposed if others
> agree and if you want to do all the adjusting of the build system.
> 
> 
> r~
> 

I agree with Thomas here. There is at least RISC-V, which is about to
hit upstream.

Cheers,
Bastian



Re: [Qemu-devel] [PATCH] build: handle deprecation of major() in sys/types.h

2016-09-22 Thread Marc-André Lureau
Hi

On Fri, Sep 23, 2016 at 12:58 AM Radim Krčmář  wrote:

> GCC 6.2.1 stops the build of qga/commands-posix.c with:
>
>
It would not be only qga,  but at least:

 hw/9pfs/9p.c:major(stbuf->st_rdev), minor(stbuf->st_rdev));
linux-user/strace.c:print_raw_param("makedev(%d", major(arg2), 0);
linux-user/strace.c:print_raw_param("makedev(%d", major(arg3), 0);
qga/commands-posix.c:*devmajor = major(st.st_rdev);


  In the GNU C Library, `major' is defined by .
>   For historical compatibility, it is currently defined by
>as well, but we plan to remove this soon.
>
>   To use `major', include  directly.
>   If you did not intend to use a system-defined macro `major',
>   you should #undef it after including .
>
> Include  for all users of .
>
> Signed-off-by: Radim Krčmář 
> ---
>  include/qemu/osdep.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 9e9fa6154642..fad31c3d5b56 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -64,6 +64,7 @@ extern int daemon(int, int);
>  #include 
>  #include 
>  #include 
> +#include 
>

I doubt this will work with mingw (I didn't try, but it is not in my mingw
prefix), perhaps better in include/sysemu/os-posix.h?


>  #include 
>  #include 
>  #include 
> --
> 2.10.0
>
>
> --
Marc-André Lureau


Re: [Qemu-devel] [PATCH] build: handle deprecation of major() in sys/types.h

2016-09-22 Thread Eric Blake
On 09/22/2016 03:56 PM, Radim Krčmář wrote:
> GCC 6.2.1 stops the build of qga/commands-posix.c with:
> 
>   In the GNU C Library, `major' is defined by .
>   For historical compatibility, it is currently defined by
>as well, but we plan to remove this soon.
> 
>   To use `major', include  directly.
>   If you did not intend to use a system-defined macro `major',
>   you should #undef it after including .
> 
> Include  for all users of .
> 
> Signed-off-by: Radim Krčmář 
> ---
>  include/qemu/osdep.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 9e9fa6154642..fad31c3d5b56 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -64,6 +64,7 @@ extern int daemon(int, int);
>  #include 
>  #include 
>  #include 
> +#include 

Works for glibc; but  is non-standard and not present
on some other systems, so this may fail to build elsewhere.  You'll
probably need a configure probe.  Autoconf also says that some platforms
have  instead of  (per its AC_HEADER_MAJOR
macro).

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 4/5] intel_iommu: add "eim" property

2016-09-22 Thread Radim Krčmář
From: Peter Xu 

Adding one extra property for intel-iommu device to decide whether we
should support EIM bit for IR.

Now we are throwing high 24 bits of dest_id away directly. This will
cause interrupt issues with guests that:

- enabled x2apic with cluster mode
- have more than 8 vcpus (so dest_id[31:8] might be nonzero)

Let's make xapic the default one, and for the brave people who would
like to try EIM and know the side effects, we can do it by explicitly
enabling EIM using:

  -device intel-iommu,intremap=on,eim=on

Even after we have x2apic support, it'll still be good if we can provide
a way to switch xapic/x2apic from QEMU side for e.g. debugging purpose,
which is an alternative for tuning guest kernel boot parameters.

We can switch the default to "on" after x2apic fully supported.

Signed-off-by: Peter Xu 
---
 hw/i386/intel_iommu.c | 16 +++-
 include/hw/i386/intel_iommu.h |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 1a0961e5cf6a..269e37e71af4 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2004,6 +2004,11 @@ static const MemoryRegionOps vtd_mem_ops = {
 
 static Property vtd_properties[] = {
 DEFINE_PROP_UINT32("version", IntelIOMMUState, version, 0),
+/*
+ * TODO: currently EIM is disabled by default. We can enable this
+ * after fully support x2apic.
+ */
+DEFINE_PROP_BOOL("eim", IntelIOMMUState, eim_supported, false),
 DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -2360,7 +2365,10 @@ static void vtd_init(IntelIOMMUState *s)
 s->ecap = VTD_ECAP_QI | VTD_ECAP_IRO;
 
 if (x86_iommu->intr_supported) {
-s->ecap |= VTD_ECAP_IR | VTD_ECAP_EIM | VTD_ECAP_MHMV;
+s->ecap |= VTD_ECAP_IR | VTD_ECAP_MHMV;
+if (s->eim_supported) {
+s->ecap |= VTD_ECAP_EIM;
+}
 }
 
 vtd_reset_context_cache(s);
@@ -2464,6 +2472,12 @@ static void vtd_realize(DeviceState *dev, Error **errp)
 /* Pseudo address space under root PCI bus. */
 pcms->ioapic_as = vtd_host_dma_iommu(bus, s, Q35_PSEUDO_DEVFN_IOAPIC);
 
+/* EIM bit requires IR */
+if (s->eim_supported && !x86_iommu->intr_supported) {
+error_report("EIM (Extended Interrupt Mode) bit requires intremap=on");
+exit(1);
+}
+
 /* Currently Intel IOMMU IR only support "kernel-irqchip={off|split}" */
 if (x86_iommu->intr_supported && kvm_irqchip_in_kernel() &&
 !kvm_irqchip_is_split()) {
diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h
index a42dbd745a70..b1bc76895deb 100644
--- a/include/hw/i386/intel_iommu.h
+++ b/include/hw/i386/intel_iommu.h
@@ -289,6 +289,7 @@ struct IntelIOMMUState {
 dma_addr_t intr_root;   /* Interrupt remapping table pointer */
 uint32_t intr_size; /* Number of IR table entries */
 bool intr_eime; /* Extended interrupt mode enabled */
+bool eim_supported; /* Whether to allow EIM bit */
 };
 
 /* Find the VTD Address space associated with the given bus pointer,
-- 
2.10.0




[Qemu-devel] [Bug 1618431] Re: windows hangs after live migration with virtio

2016-09-22 Thread Dr. David Alan Gilbert
Hi WOLI,
  Note, if you pick up a new (4.8 ish) kernel you'll probably find you'll need 
to also pick up two patches that we've just posted to the qemu list:

target-i386: introduce kvm_put_one_msr
kvm: apic: set APIC base as part of kvm_apic_put

otherwise you get weird reboot hangs with Linux guests.

Dave

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1618431

Title:
  windows hangs after live migration with virtio

Status in QEMU:
  Fix Committed

Bug description:
  Several of our users reported problems with windows machines hanging
  after live migrations. The common denominator _seems_ to be virtio
  devices.
  I've managed to reproduce this reliably on a windows 10 (+
  virtio-win-0.1.118) guest, always within 1 to 5 migrations, with a
  virtio-scsi hard drive and a virtio-net network device. (When I
  replace the virtio-net device with an e1000 it takes 10 or more
  migrations, and without virtio devices I have not (yet) been able to
  reproduce this problem. I also could not reproduce this with a linux
  guest. Also spice seems to improve the situation, but doesn't solve
  it completely).

  I've tested quite a few tags from qemu-git (v2.2.0 through v2.6.1,
  and 2.6.1 with the patches mentioned on qemu-stable by Peter Lieven)
  and the behavior is the same everywhere.

  The reproducibility seems to be somewhat dependent on the host
  hardware, which makes investigating this issue that much harder.

  Symptoms:
  After the migration the windows graphics stack just hangs.
  Background processes are still running (eg. after installing an ssh
  server I could still login and get a command prompt after the hang was
  triggered... not that I'd know what to do with that on a windows
  machine...) - commands which need no GUI access work, the rest just
  hangs there on the command line, too.
  It's also capable of responding to an NMI sent via the qemu monitor:
  it then seems to "recover" and manages to show the blue sad-face
  screen that something happened, reboots successfully and is usable
  again without restarting the qemu process in between.
  From there whole the process can be repeated.

  Here's what our command line usually looks like:

  /usr/bin/qemu -daemonize \
-enable-kvm \
-chardev socket,id=qmp,path=/var/run/qemu-server/101.qmp,server,nowait 
-mon chardev=qmp,mode=control \
-pidfile /var/run/qemu-server/101.pid \
-smbios type=1,uuid=07fc916e-24c2-4eef-9827-4ab4026501d4 \
-name win10 \
-smp 6,sockets=1,cores=6,maxcpus=6 \
-nodefaults \
-boot menu=on,strict=on,reboot-timeout=1000 \
-vga std \
-vnc unix:/var/run/qemu-server/101.vnc \
-no-hpet \
-cpu 
kvm64,hv_spinlocks=0x1fff,hv_vapic,hv_time,hv_reset,hv_vpindex,hv_runtime,hv_relaxed,+lahf_lm,+sep,+kvm_pv_unhalt,+kvm_pv_eoi,enforce
 \
-m 2048 \
-device pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f \
-device pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e \
-device piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2 \
-device usb-tablet,id=tablet,bus=uhci.0,port=1 \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
-iscsi initiator-name=iqn.1993-08.org.debian:01:1ba48d46fb8 \
-drive if=none,id=drive-ide0,media=cdrom,aio=threads \
-device ide-cd,bus=ide.0,unit=0,drive=drive-ide0,id=ide0,bootindex=200 \
-device virtio-scsi-pci,id=scsihw0,bus=pci.0,addr=0x5 \
-drive 
file=/mnt/pve/data1/images/101/vm-101-disk-1.qcow2,if=none,id=drive-scsi0,cache=writeback,discard=on,format=qcow2,aio=threads,detect-zeroes=unmap
 \
-device 
scsi-hd,bus=scsihw0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0,id=scsi0,bootindex=100
 \
-netdev 
type=tap,id=net0,ifname=tap101i0,script=/var/lib/qemu-server/pve-bridge,downscript=/var/lib/qemu-server/pve-bridgedown,vhost=on
 \
-device 
virtio-net-pci,mac=F2:2B:20:37:E6:D7,netdev=net0,bus=pci.0,addr=0x12,id=net0,bootindex=300
 \
-rtc driftfix=slew,base=localtime \
-global kvm-pit.lost_tick_policy=discard

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1618431/+subscriptions



Re: [Qemu-devel] [RFC PATCH v2 04/16] monitor: use debug version of memory access apis

2016-09-22 Thread Michael S. Tsirkin
On Thu, Sep 22, 2016 at 10:52:28AM -0400, Brijesh Singh wrote:
> updates hmp monitor to use debug version of memory access apis when
> accessing the guest memory.
> 
> Signed-off-by: Brijesh Singh 

Does this cover the gdb stub as well?

> ---
>  cpus.c|2 +-
>  disas.c   |2 +-
>  monitor.c |2 +-
>  target-i386/helper.c  |   14 +++---
>  target-i386/monitor.c |   18 ++
>  5 files changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 84c3520..48dc4d1 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1725,7 +1725,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const 
> char *filename,
>  l = sizeof(buf);
>  if (l > size)
>  l = size;
> -cpu_physical_memory_read(addr, buf, l);
> +cpu_physical_memory_read_debug(addr, buf, l);
>  if (fwrite(buf, 1, l, f) != l) {
>  error_setg(errp, QERR_IO_ERROR);
>  goto exit;
> diff --git a/disas.c b/disas.c
> index 05a7a12..382cc2c 100644
> --- a/disas.c
> +++ b/disas.c
> @@ -356,7 +356,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, 
> int length,
>  CPUDebug *s = container_of(info, CPUDebug, info);
>  
>  if (monitor_disas_is_physical) {
> -cpu_physical_memory_read(memaddr, myaddr, length);
> +cpu_physical_memory_read_debug(memaddr, myaddr, length);
>  } else {
>  cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0);
>  }
> diff --git a/monitor.c b/monitor.c
> index 5c00373..4773ee1 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -1299,7 +1299,7 @@ static void memory_dump(Monitor *mon, int count, int 
> format, int wsize,
>  if (l > line_size)
>  l = line_size;
>  if (is_physical) {
> -cpu_physical_memory_read(addr, buf, l);
> +cpu_physical_memory_read_debug(addr, buf, l);
>  } else {
>  if (cpu_memory_rw_debug(mon_get_cpu(), addr, buf, l, 0) < 0) {
>  monitor_printf(mon, " Cannot access memory\n");
> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index 1c250b8..88fa4fa 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1034,13 +1034,13 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, 
> vaddr addr)
>  }
>  pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 
> 3)) &
>  env->a20_mask;
> -pml4e = x86_ldq_phys(cs, pml4e_addr);
> +pml4e = ldq_phys_debug(cs, pml4e_addr);
>  if (!(pml4e & PG_PRESENT_MASK)) {
>  return -1;
>  }
>  pdpe_addr = ((pml4e & PG_ADDRESS_MASK) +
>   (((addr >> 30) & 0x1ff) << 3)) & env->a20_mask;
> -pdpe = x86_ldq_phys(cs, pdpe_addr);
> +pdpe = ldq_phys_debug(cs, pdpe_addr);
>  if (!(pdpe & PG_PRESENT_MASK)) {
>  return -1;
>  }
> @@ -1055,14 +1055,14 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, 
> vaddr addr)
>  {
>  pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
>  env->a20_mask;
> -pdpe = x86_ldq_phys(cs, pdpe_addr);
> +pdpe = ldq_phys_debug(cs, pdpe_addr);
>  if (!(pdpe & PG_PRESENT_MASK))
>  return -1;
>  }
>  
>  pde_addr = ((pdpe & PG_ADDRESS_MASK) +
>  (((addr >> 21) & 0x1ff) << 3)) & env->a20_mask;
> -pde = x86_ldq_phys(cs, pde_addr);
> +pde = ldq_phys_debug(cs, pde_addr);
>  if (!(pde & PG_PRESENT_MASK)) {
>  return -1;
>  }
> @@ -1075,7 +1075,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr 
> addr)
>  pte_addr = ((pde & PG_ADDRESS_MASK) +
>  (((addr >> 12) & 0x1ff) << 3)) & env->a20_mask;
>  page_size = 4096;
> -pte = x86_ldq_phys(cs, pte_addr);
> +pte = ldq_phys_debug(cs, pte_addr);
>  }
>  if (!(pte & PG_PRESENT_MASK)) {
>  return -1;
> @@ -1085,7 +1085,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr 
> addr)
>  
>  /* page directory entry */
>  pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & 
> env->a20_mask;
> -pde = x86_ldl_phys(cs, pde_addr);
> +pde = ldl_phys_debug(cs, pde_addr);
>  if (!(pde & PG_PRESENT_MASK))
>  return -1;
>  if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
> @@ -1094,7 +1094,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr 
> addr)
>  } else {
>  /* page directory entry */
>  pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & 
> env->a20_mask;
> -pte = x86_ldl_phys(cs, pte_addr);
> +pte = ldl_phys_debug(cs, pte_addr);
>  if (!(pte & PG_PRESENT_MASK)) {
>  

[Qemu-devel] [PATCH 1/5] apic: add global apic_get_class()

2016-09-22 Thread Radim Krčmář
Every configuration has only up to one APIC class and we'll be extending
the class with a function that can be called without an instanced
object, so a direct access to the class is convenient.

Signed-off-by: Radim Krčmář 
---
 hw/intc/apic_common.c   | 14 ++
 include/hw/i386/apic_internal.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index 14ac43c18666..86ef9c43e6df 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -18,6 +18,7 @@
  * License along with this library; if not, see 
  */
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -296,6 +297,13 @@ static int apic_load_old(QEMUFile *f, void *opaque, int 
version_id)
 
 static const VMStateDescription vmstate_apic_common;
 
+APICCommonClass *apic_class;
+
+APICCommonClass *apic_get_class(void)
+{
+return apic_class;
+}
+
 static void apic_common_realize(DeviceState *dev, Error **errp)
 {
 APICCommonState *s = APIC_COMMON(dev);
@@ -306,6 +314,12 @@ static void apic_common_realize(DeviceState *dev, Error 
**errp)
 info = APIC_COMMON_GET_CLASS(s);
 info->realize(dev, errp);
 
+if (apic_class && apic_class != info) {
+error_report("All APICs must be of the same class.");
+exit(1);
+}
+apic_class = info;
+
 /* Note: We need at least 1M to map the VAPIC option ROM */
 if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK &&
 ram_size >= 1024 * 1024) {
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index 06c4e9f6f95b..9ba8a5c87f90 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -222,4 +222,7 @@ static inline int apic_get_bit(uint32_t *tab, int index)
 return !!(tab[i] & mask);
 }
 
+
+APICCommonClass *apic_get_class(void);
+
 #endif /* QEMU_APIC_INTERNAL_H */
-- 
2.10.0




[Qemu-devel] [PATCH 3/5] intel_iommu: pass whole remapped addresses to apic

2016-09-22 Thread Radim Krčmář
The MMIO interface to APIC only allowed 8 bit addresses, which is not
enough for 32 bit addresses from EIM remapping.
Intel stored upper 24 bits in the high MSI address, so use the same
technique. The technique is also used in KVM MSI interface.
Other APICs are unlikely to handle those upper bits.

Signed-off-by: Radim Krčmář 
---
 hw/i386/intel_iommu.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 28c31a2cdfa3..1a0961e5cf6a 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -31,6 +31,7 @@
 #include "hw/i386/x86-iommu.h"
 #include "hw/pci-host/q35.h"
 #include "sysemu/kvm.h"
+#include "hw/i386/apic_internal.h"
 
 /*#define DEBUG_INTEL_IOMMU*/
 #ifdef DEBUG_INTEL_IOMMU
@@ -279,18 +280,16 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t 
source_id,
 static void vtd_generate_interrupt(IntelIOMMUState *s, hwaddr mesg_addr_reg,
hwaddr mesg_data_reg)
 {
-hwaddr addr;
-uint32_t data;
+MSIMessage msi;
 
 assert(mesg_data_reg < DMAR_REG_SIZE);
 assert(mesg_addr_reg < DMAR_REG_SIZE);
 
-addr = vtd_get_long_raw(s, mesg_addr_reg);
-data = vtd_get_long_raw(s, mesg_data_reg);
+msi.address = vtd_get_long_raw(s, mesg_addr_reg);
+msi.data = vtd_get_long_raw(s, mesg_data_reg);
 
 VTD_DPRINTF(FLOG, "msi: addr 0x%"PRIx64 " data 0x%"PRIx32, addr, data);
-address_space_stl_le(_space_memory, addr, data,
- MEMTXATTRS_UNSPECIFIED, NULL);
+apic_get_class()->send_msi();
 }
 
 /* Generate a fault event to software via MSI if conditions are met.
@@ -2127,6 +2126,7 @@ static void vtd_generate_msi_message(VTDIrq *irq, 
MSIMessage *msg_out)
 msg.dest_mode = irq->dest_mode;
 msg.redir_hint = irq->redir_hint;
 msg.dest = irq->dest;
+msg.__addr_hi = irq->dest & 0xff00;
 msg.__addr_head = cpu_to_le32(0xfee);
 /* Keep this from original MSI address bits */
 msg.__not_used = irq->msi_addr_last_bits;
@@ -2275,11 +2275,7 @@ static MemTxResult vtd_mem_ir_write(void *opaque, hwaddr 
addr,
 " for device sid 0x%04x",
 to.address, to.data, sid);
 
-if (dma_memory_write(_space_memory, to.address,
- , size)) {
-VTD_DPRINTF(GENERAL, "error: fail to write 0x%"PRIx64
-" value 0x%"PRIx32, to.address, to.data);
-}
+apic_get_class()->send_msi();
 
 return MEMTX_OK;
 }
-- 
2.10.0




Re: [Qemu-devel] pseries-2.6 migration from QEMU-2.6 to QEMU-2.7 broken

2016-09-22 Thread Nikunj A Dadhania
Cédric Le Goater  writes:

> On 09/22/2016 01:07 PM, Nikunj A Dadhania wrote:
>> Benjamin Herrenschmidt  writes:
>> 
>>> On Thu, 2016-09-22 at 14:34 +0530, Nikunj A Dadhania wrote:
 Something like this works for KVM:

 diff --git a/target-ppc/machine.c b/target-ppc/machine.c
 index 4820f22..1cf3779 100644
 --- a/target-ppc/machine.c
 +++ b/target-ppc/machine.c
 @@ -563,8 +563,8 @@ const VMStateDescription vmstate_ppc_cpu = {
  
  /* Sanity checking */
  VMSTATE_UINTTL_EQUAL(env.msr_mask, PowerPCCPU),
 -VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
 -VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
 +VMSTATE_UNUSED(sizeof(target_ulong)), /* was 
 _EQUAL(env.insns_flags) */
 +VMSTATE_UNUSED(sizeof(target_ulong)), /* was 
 _EQUAL(env.insns_flags2) */
  VMSTATE_UINT32_EQUAL(env.nb_BATs, PowerPCCPU),
  VMSTATE_END_OF_LIST()
  },

 TCG migration still remains broken with this.
>>>
>>> Can we have conditionally present flags and a post-load that does some
>>> matching ?
>> 
>> I think its possible like this:
>> 
>> diff --git a/target-ppc/machine.c b/target-ppc/machine.c
>> index 4820f22..dc4704e 100644
>> --- a/target-ppc/machine.c
>> +++ b/target-ppc/machine.c
>> @@ -528,6 +528,42 @@ static const VMStateDescription vmstate_tlbmas = {
>>  }
>>  };
>>  
>> +static bool ppc_kvm_enabled(void *opaque, int version_id)
>> +{
>> +printf("%s: is kvm enabled %d\n", __func__, kvm_enabled());
>> +return !kvm_enabled();
>> +}
>> +
>> +static int get_insns_equal(QEMUFile *f, void *pv, size_t size)
>> +{
>> +uint64_t *v = pv;
>> +uint64_t v2;
>> +qemu_get_be64s(f, );
>> +
>> +printf("%s: \n", __func__);
>> +
>> +if (*v == v2) {
>> +return 0;
>> +}
>> +printf("Did not match, ignore %" PRIu64 " != %" PRIu64 "\n", *v, v2);
>> +return 0;
>> +}
>> +
>> +static void put_insns(QEMUFile *f, void *pv, size_t size)
>> +{
>> +uint64_t *v = pv;
>> +qemu_put_be64s(f, v);
>> +}
>> +
>> +const VMStateInfo vmstate_info_insns_equal = {
>> +.name = "insns equal",
>> +.get  = get_insns_equal,
>> +.put  = put_insns,
>> +};
>> +
>> +#define VMSTATE_INSNS_EQUAL(_f, _s, _t) \
>> +VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_insns_equal, uint64_t)
>> +
>>  const VMStateDescription vmstate_ppc_cpu = {
>>  .name = "cpu",
>>  .version_id = 5,
>> @@ -563,8 +599,8 @@ const VMStateDescription vmstate_ppc_cpu = {
>>  
>>  /* Sanity checking */
>>  VMSTATE_UINTTL_EQUAL(env.msr_mask, PowerPCCPU),
>> -VMSTATE_UINT64_EQUAL(env.insns_flags, PowerPCCPU),
>> -VMSTATE_UINT64_EQUAL(env.insns_flags2, PowerPCCPU),
>> +VMSTATE_INSNS_EQUAL(env.insns_flags, PowerPCCPU, ppc_kvm_enabled),
>> +VMSTATE_INSNS_EQUAL(env.insns_flags2, PowerPCCPU, ppc_kvm_enabled),
>>  VMSTATE_UINT32_EQUAL(env.nb_BATs, PowerPCCPU),
>>  VMSTATE_END_OF_LIST()
>>  },
>> 
>> 
>> TCG migration succeeds and proceeds ahead. But fails somewhere ahead in
>> powerpc exception handler:
>> 
>> [qemu]$ ./ppc64-softmmu/qemu-system-ppc64  -machine pseries-2.6,usb=off -vga 
>> none -nographic -m 2G   ../../imgs/guest.disk -monitor pty --incoming 
>> tcp:localhost: 
>> char device redirected to /dev/pts/5 (label compat_monitor0)
>> ppc_kvm_enabled: is kvm enabled 0
>> get_insns_equal: 
>> Did not match, ignore 9223477658187168481 != 9223477658187151905
>> ppc_kvm_enabled: is kvm enabled 0
>> get_insns_equal: 
>> Did not match, ignore 331702 != 69558
>> Cannot open font file True
>> Cannot open font file True
>> qemu: fatal: Trying to deliver HV exception 4 with no HV support
>
> hmm, this is because we added MSR_HVB in msr_mask AFAICT. we should have 
> a similar vmstate op for it I think

Not sure how will vmstate op help here. As vmstate is migrated
successfully. Do we need to copy msr features of source ?

Regards
Nikunj




[Qemu-devel] [PATCH] build: handle deprecation of major() in sys/types.h

2016-09-22 Thread Radim Krčmář
GCC 6.2.1 stops the build of qga/commands-posix.c with:

  In the GNU C Library, `major' is defined by .
  For historical compatibility, it is currently defined by
   as well, but we plan to remove this soon.

  To use `major', include  directly.
  If you did not intend to use a system-defined macro `major',
  you should #undef it after including .

Include  for all users of .

Signed-off-by: Radim Krčmář 
---
 include/qemu/osdep.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 9e9fa6154642..fad31c3d5b56 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -64,6 +64,7 @@ extern int daemon(int, int);
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.10.0




Re: [Qemu-devel] [RFC PATCH v2 04/16] monitor: use debug version of memory access apis

2016-09-22 Thread Brijesh Singh

Hi,

On 09/22/2016 02:24 PM, Michael S. Tsirkin wrote:

On Thu, Sep 22, 2016 at 10:52:28AM -0400, Brijesh Singh wrote:

updates hmp monitor to use debug version of memory access apis when
accessing the guest memory.

Signed-off-by: Brijesh Singh 


Does this cover the gdb stub as well?


Yes, gdb stub works. gdb was already wired to use debug version of api

target_memory_rw_debug
  cpu_memory_rw_debug

Only part which i needed to take care was to ensure that page table walk 
to find a physical address for a given virtual address goes through the 
debug version of apis. changes in target-i386/helper.c takes care of this.


-Brijesh






  1   2   3   4   5   6   7   >