[Qemu-devel] [PULL 09/25] virtio-scsi: Fix build with gcc 9

2019-03-08 Thread Paolo Bonzini
From: Greg Kurz 

Build fails with gcc 9:

  CC  ppc64-softmmu/hw/scsi/virtio-scsi.o
hw/scsi/virtio-scsi.c: In function ‘virtio_scsi_do_tmf’:
hw/scsi/virtio-scsi.c:265:39: error: taking address of packed member of 
‘struct virtio_scsi_ctrl_tmf_req’ may result in an unaligned pointer value 
[-Werror=address-of-packed-member]
  265 | virtio_tswap32s(VIRTIO_DEVICE(s), &req->req.tmf.subtype);
  |   ^
cc1: all warnings being treated as errors

All the fields in struct virtio_scsi_ctrl_tmf_req are naturally aligned,
so we could in theory drop QEMU_PACKED. Unfortunately, the header file
is imported from linux which already has the packed attribute. Trying to
fix that in the update-linux-headers.sh script is likely to produce
ugliness. Turn the call to virtio_tswap32s() into an assignment instead.

Signed-off-by: Greg Kurz 
Message-Id: <155137678223.44753.5438092367451176318.st...@bahia.lan>
Signed-off-by: Paolo Bonzini 
---
 hw/scsi/virtio-scsi.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index ce99d28..839f120 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -262,7 +262,13 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq 
*req)
 /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE".  */
 req->resp.tmf.response = VIRTIO_SCSI_S_OK;
 
-virtio_tswap32s(VIRTIO_DEVICE(s), &req->req.tmf.subtype);
+/*
+ * req->req.tmf has the QEMU_PACKED attribute. Don't use virtio_tswap32s()
+ * to avoid compiler errors.
+ */
+req->req.tmf.subtype =
+virtio_tswap32(VIRTIO_DEVICE(s), req->req.tmf.subtype);
+
 switch (req->req.tmf.subtype) {
 case VIRTIO_SCSI_T_TMF_ABORT_TASK:
 case VIRTIO_SCSI_T_TMF_QUERY_TASK:
-- 
1.8.3.1





[Qemu-devel] [PULL 21/25] lsi: use enum type for s->waiting

2019-03-08 Thread Paolo Bonzini
From: Sven Schnelle 

This makes the code easier to read - no functional change.

Signed-off-by: Sven Schnelle 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20190305195519.24303-3-sv...@stackframe.org>
---
 hw/scsi/lsi53c895a.c | 42 +++---
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index 402b785..c17bb4f 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -194,6 +194,13 @@ typedef struct lsi_request {
 QTAILQ_ENTRY(lsi_request) next;
 } lsi_request;
 
+enum {
+LSI_NOWAIT, /* SCRIPTS are running or stopped */
+LSI_WAIT_RESELECT, /* Wait Reselect instruction has been issued */
+LSI_DMA_SCRIPTS, /* processing DMA from lsi_execute_script */
+LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
+};
+
 typedef struct {
 /*< private >*/
 PCIDevice parent_obj;
@@ -212,10 +219,6 @@ typedef struct {
 int msg_action;
 int msg_len;
 uint8_t msg[LSI_MAX_MSGIN_LEN];
-/* 0 if SCRIPTS are running or stopped.
- * 1 if a Wait Reselect instruction has been issued.
- * 2 if processing DMA from lsi_execute_script.
- * 3 if a DMA operation is in progress.  */
 int waiting;
 SCSIBus bus;
 int current_lun;
@@ -322,7 +325,7 @@ static void lsi_soft_reset(LSIState *s)
 
 s->msg_action = 0;
 s->msg_len = 0;
-s->waiting = 0;
+s->waiting = LSI_NOWAIT;
 s->dsa = 0;
 s->dnad = 0;
 s->dbc = 0;
@@ -564,10 +567,10 @@ static void lsi_bad_phase(LSIState *s, int out, int 
new_phase)
 static void lsi_resume_script(LSIState *s)
 {
 if (s->waiting != 2) {
-s->waiting = 0;
+s->waiting = LSI_NOWAIT;
 lsi_execute_script(s);
 } else {
-s->waiting = 0;
+s->waiting = LSI_NOWAIT;
 }
 }
 
@@ -744,7 +747,7 @@ static int lsi_queue_req(LSIState *s, SCSIRequest *req, 
uint32_t len)
Since no interrupt stacking is implemented in the emulation, it
is also required that there are no pending interrupts waiting
for service from the device driver. */
-if (s->waiting == 1 ||
+if (s->waiting == LSI_WAIT_RESELECT ||
 (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON) &&
  !(s->istat0 & (LSI_ISTAT0_SIP | LSI_ISTAT0_DIP {
 /* Reselect device.  */
@@ -789,7 +792,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t 
len)
 int out;
 
 assert(req->hba_private);
-if (s->waiting == 1 || req->hba_private != s->current ||
+if (s->waiting == LSI_WAIT_RESELECT || req->hba_private != s->current ||
 (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON))) {
 if (lsi_queue_req(s, req, len)) {
 return;
@@ -803,7 +806,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t 
len)
 s->current->dma_len = len;
 s->command_complete = 1;
 if (s->waiting) {
-if (s->waiting == 1 || s->dbc == 0) {
+if (s->waiting == LSI_WAIT_RESELECT || s->dbc == 0) {
 lsi_resume_script(s);
 } else {
 lsi_do_dma(s, out);
@@ -1093,7 +1096,7 @@ static void lsi_wait_reselect(LSIState *s)
 lsi_reselect(s, p);
 }
 if (s->current == NULL) {
-s->waiting = 1;
+s->waiting = LSI_WAIT_RESELECT;
 }
 }
 
@@ -1202,16 +1205,16 @@ again:
 s->dnad64 = addr_high;
 switch (s->sstat1 & 0x7) {
 case PHASE_DO:
-s->waiting = 2;
+s->waiting = LSI_DMA_SCRIPTS;
 lsi_do_dma(s, 1);
 if (s->waiting)
-s->waiting = 3;
+s->waiting = LSI_DMA_IN_PROGRESS;
 break;
 case PHASE_DI:
-s->waiting = 2;
+s->waiting = LSI_DMA_SCRIPTS;
 lsi_do_dma(s, 0);
 if (s->waiting)
-s->waiting = 3;
+s->waiting = LSI_DMA_IN_PROGRESS;
 break;
 case PHASE_CMD:
 lsi_do_command(s);
@@ -1278,6 +1281,7 @@ again:
 }
 s->sbcl |= LSI_SBCL_BSY;
 lsi_set_phase(s, PHASE_MO);
+s->waiting = LSI_NOWAIT;
 break;
 case 1: /* Disconnect */
 trace_lsi_execute_script_io_disconnect();
@@ -1544,7 +1548,7 @@ again:
 }
 }
 }
-if (insn_processed > 1 && !s->waiting) {
+if (insn_processed > 1 && s->waiting == LSI_NOWAIT) {
 /* Some windows drivers make the device spin waiting for a memory
location to change.  If we have been executed a lot of code then
assume this is the case and force an unexpected device disconnect.
@@ -1556,7 +1560,7 @@ again:
 }
 lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
 lsi_disconnect(s);
-} else if (s->istat1 & LSI_ISTAT1_SRUN && !s->waiting) {
+} else if (s->istat1 & LSI_ISTAT1_SRUN && s->waiting == LSI_NOWAIT) {
 if (s->dcntl & LSI_DCNTL_S

[Qemu-devel] [PULL 06/25] configure: Enable werror for git worktrees

2019-03-08 Thread Paolo Bonzini
From: Alexey Kardashevskiy 

The configure script checks multiple times whether it works in a git
repository and it does this by "test -e "${source_path}/.git" in 4 cases
but in one case where it tries to enable werror "-d" is used there which
fails on git worktrees as .git is a file then and not a directory.

This changes the test to "-e" as other occurrences.

Signed-off-by: Alexey Kardashevskiy 
Message-Id: <20190228043503.68494-1-...@ozlabs.ru>
Signed-off-by: Paolo Bonzini 
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 79453a6..c9a260c 100755
--- a/configure
+++ b/configure
@@ -1836,7 +1836,7 @@ fi
 # Consult white-list to determine whether to enable werror
 # by default.  Only enable by default for git builds
 if test -z "$werror" ; then
-if test -d "$source_path/.git" && \
+if test -e "$source_path/.git" && \
 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
 werror="yes"
 else
-- 
1.8.3.1





[Qemu-devel] [PULL 17/25] oslib-posix: Ignore fcntl("/dev/null", F_SETFL, O_NONBLOCK) failure

2019-03-08 Thread Paolo Bonzini
From: Philippe Mathieu-Daudé 

Previous to OpenBSD 6.3 [1], fcntl(F_SETFL) is not permitted on
memory devices.
Trying this call sets errno to ENODEV ("not a memory device"):

  19 ENODEV Operation not supported by device.
An attempt was made to apply an inappropriate function to a device,
for example, trying to read a write-only device such as a printer.

Do not assert fcntl failures in this specific case (errno set to ENODEV)
on OpenBSD. This fixes:

  $ lm32-softmmu/qemu-system-lm32
  assertion "f != -1" failed: file "util/oslib-posix.c", line 247, function 
"qemu_set_nonblock"
  Abort trap (core dumped)

[1] The fix seems https://github.com/openbsd/src/commit/c2a35b387f9d3c
  "fcntl(F_SETFL) invokes the FIONBIO and FIOASYNC ioctls internally, so
  the memory devices (/dev/null, /dev/zero, etc) need to permit them."

Reviewed-by: Peter Maydell 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <20190307142822.8531-2-phi...@redhat.com>
Signed-off-by: Paolo Bonzini 
Signed-off-by: Philippe Mathieu-Daudé 
---
 util/oslib-posix.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 37c5854..326d92d 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -244,7 +244,19 @@ void qemu_set_nonblock(int fd)
 f = fcntl(fd, F_GETFL);
 assert(f != -1);
 f = fcntl(fd, F_SETFL, f | O_NONBLOCK);
+#ifdef __OpenBSD__
+if (f == -1) {
+/*
+ * Previous to OpenBSD 6.3, fcntl(F_SETFL) is not permitted on
+ * memory devices and sets errno to ENODEV.
+ * It's OK if we fail to set O_NONBLOCK on devices like /dev/null,
+ * because they will never block anyway.
+ */
+assert(errno == ENODEV);
+}
+#else
 assert(f != -1);
+#endif
 }
 
 int socket_set_fast_reuse(int fd)
-- 
1.8.3.1





[Qemu-devel] [PULL 14/25] build: remove unnecessary assignments from Makefile.target

2019-03-08 Thread Paolo Bonzini
It is only necessary to clear block-obj-y because Makefile.objs
uses "+=" instead of "="; fix that and remove the assignment.
The other variables need not be cleared at all.

Signed-off-by: Paolo Bonzini 
---
 Makefile.objs   | 2 +-
 Makefile.target | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index acc53aa..31a84b7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -13,7 +13,7 @@ authz-obj-y = authz/
 ###
 # block-obj-y is code used by both qemu system emulation and qemu-img
 
-block-obj-y += nbd/
+block-obj-y = nbd/
 block-obj-y += block.o blockjob.o job.o
 block-obj-y += block/ scsi/
 block-obj-y += qemu-io-cmds.o
diff --git a/Makefile.target b/Makefile.target
index a458506..441ace6 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -175,9 +175,6 @@ endif # CONFIG_SOFTMMU
 dummy := $(call unnest-vars,,obj-y)
 all-obj-y := $(obj-y)
 
-block-obj-y :=
-common-obj-y :=
-chardev-obj-y :=
 include $(SRC_PATH)/Makefile.objs
 dummy := $(call unnest-vars,.., \
authz-obj-y \
-- 
1.8.3.1





[Qemu-devel] [PULL 10/25] lsi: implement basic SBCL functionality

2019-03-08 Thread Paolo Bonzini
From: Sven Schnelle 

HP-UX checks this register after sending data to the target. If there's no valid
information present, it assumes the client disconnected because the kernel sent
to much data. Implement at least some of the SBCL functionality that is possible
without having a real SCSI bus.

Signed-off-by: Sven Schnelle 
Message-Id: <20190215194021.20543-1-sv...@stackframe.org>
Signed-off-by: Paolo Bonzini 
---
 hw/scsi/lsi53c895a.c | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index 89def14..8ba07f8 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -160,6 +160,11 @@ static const char *names[] = {
 #define LSI_CCNTL1_DDAC  0x08
 #define LSI_CCNTL1_ZMOD  0x80
 
+#define LSI_SBCL_ATN 0x08
+#define LSI_SBCL_BSY 0x20
+#define LSI_SBCL_ACK 0x40
+#define LSI_SBCL_REQ 0x80
+
 /* Enable Response to Reselection */
 #define LSI_SCID_RRE  0x60
 
@@ -258,6 +263,7 @@ typedef struct {
 uint8_t sdid;
 uint8_t ssid;
 uint8_t sfbr;
+uint8_t sbcl;
 uint8_t stest1;
 uint8_t stest2;
 uint8_t stest3;
@@ -356,6 +362,7 @@ static void lsi_soft_reset(LSIState *s)
 s->socl = 0;
 s->sdid = 0;
 s->ssid = 0;
+s->sbcl = 0;
 s->stest1 = 0;
 s->stest2 = 0;
 s->stest3 = 0;
@@ -530,6 +537,8 @@ static void lsi_script_dma_interrupt(LSIState *s, int stat)
 
 static inline void lsi_set_phase(LSIState *s, int phase)
 {
+s->sbcl &= ~PHASE_MASK;
+s->sbcl |= phase | LSI_SBCL_REQ;
 s->sstat1 = (s->sstat1 & ~PHASE_MASK) | phase;
 }
 
@@ -567,6 +576,7 @@ static void lsi_disconnect(LSIState *s)
 {
 s->scntl1 &= ~LSI_SCNTL1_CON;
 s->sstat1 &= ~PHASE_MASK;
+s->sbcl = 0;
 }
 
 static void lsi_bad_selection(LSIState *s, uint32_t id)
@@ -1265,7 +1275,9 @@ again:
 s->scntl1 |= LSI_SCNTL1_CON;
 if (insn & (1 << 3)) {
 s->socl |= LSI_SOCL_ATN;
+s->sbcl |= LSI_SBCL_ATN;
 }
+s->sbcl |= LSI_SBCL_BSY;
 lsi_set_phase(s, PHASE_MO);
 break;
 case 1: /* Disconnect */
@@ -1297,8 +1309,14 @@ again:
 insn & (1 << 10) ? " CC" : "");
 if (insn & (1 << 3)) {
 s->socl |= LSI_SOCL_ATN;
+s->sbcl |= LSI_SBCL_ATN;
 lsi_set_phase(s, PHASE_MO);
 }
+
+if (insn & (1 << 6)) {
+s->sbcl |= LSI_SBCL_ACK;
+}
+
 if (insn & (1 << 9)) {
 qemu_log_mask(LOG_UNIMP,
 "lsi_scsi: Target mode not implemented\n");
@@ -1314,7 +1332,13 @@ again:
 insn & (1 << 10) ? " CC" : "");
 if (insn & (1 << 3)) {
 s->socl &= ~LSI_SOCL_ATN;
+s->sbcl &= ~LSI_SBCL_ATN;
 }
+
+if (insn & (1 << 6)) {
+s->sbcl &= ~LSI_SBCL_ACK;
+}
+
 if (insn & (1 << 10))
 s->carry = 0;
 break;
@@ -1591,9 +1615,7 @@ static uint8_t lsi_reg_readb(LSIState *s, int offset)
 ret = s->ssid;
 break;
 case 0xb: /* SBCL */
-/* ??? This is not correct. However it's (hopefully) only
-   used for diagnostics, so should be ok.  */
-ret = 0;
+ret = s->sbcl;
 break;
 case 0xc: /* DSTAT */
 ret = s->dstat | LSI_DSTAT_DFE;
@@ -2143,7 +2165,7 @@ static int lsi_post_load(void *opaque, int version_id)
 
 static const VMStateDescription vmstate_lsi_scsi = {
 .name = "lsiscsi",
-.version_id = 0,
+.version_id = 1,
 .minimum_version_id = 0,
 .pre_save = lsi_pre_save,
 .post_load = lsi_post_load,
@@ -2202,6 +2224,7 @@ static const VMStateDescription vmstate_lsi_scsi = {
 VMSTATE_UINT8(stime0, LSIState),
 VMSTATE_UINT8(respid0, LSIState),
 VMSTATE_UINT8(respid1, LSIState),
+VMSTATE_UINT8_V(sbcl, LSIState, 1),
 VMSTATE_UINT32(mmrs, LSIState),
 VMSTATE_UINT32(mmws, LSIState),
 VMSTATE_UINT32(sfs, LSIState),
-- 
1.8.3.1





[Qemu-devel] [PULL 07/25] target-i386: add kvm stubs to user-mode emulators

2019-03-08 Thread Paolo Bonzini
The CPUID code will call kvm_arch_get_supported_cpuid() and, even though
it is undef kvm_enabled() so it never runs for user-mode emulators,
sometimes clang will not optimize it out at -O0.

That could be considered a compiler bug, however at -O0 we give it
a pass and just add the stubs.

Reported-by: Kamil Rytarowski 
Tested-by: Kamil Rytarowski 
Signed-off-by: Paolo Bonzini 
---
 target/i386/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/Makefile.objs b/target/i386/Makefile.objs
index cb9c265..48e0c28 100644
--- a/target/i386/Makefile.objs
+++ b/target/i386/Makefile.objs
@@ -3,10 +3,10 @@ obj-$(CONFIG_TCG) += translate.o
 obj-$(CONFIG_TCG) += bpt_helper.o cc_helper.o excp_helper.o fpu_helper.o
 obj-$(CONFIG_TCG) += int_helper.o mem_helper.o misc_helper.o mpx_helper.o
 obj-$(CONFIG_TCG) += seg_helper.o smm_helper.o svm_helper.o
+obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
 ifeq ($(CONFIG_SOFTMMU),y)
 obj-y += machine.o arch_memory_mapping.o arch_dump.o monitor.o
 obj-$(CONFIG_KVM) += kvm.o
-obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
 obj-$(CONFIG_HYPERV) += hyperv.o
 obj-$(call lnot,$(CONFIG_HYPERV)) += hyperv-stub.o
 ifeq ($(CONFIG_WIN32),y)
-- 
1.8.3.1





[Qemu-devel] [PULL 15/25] build: clean trace/generated-helpers.c

2019-03-08 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini 
---
 Makefile.target | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Makefile.target b/Makefile.target
index 441ace6..d8048aa 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -222,6 +222,7 @@ clean: clean-target
rm -f *.a *~ $(PROGS)
rm -f $(shell find . -name '*.[od]')
rm -f hmp-commands.h gdbstub-xml.c
+   rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
 ifdef CONFIG_TRACE_SYSTEMTAP
rm -f *.stp
 endif
-- 
1.8.3.1





[Qemu-devel] [PULL 08/25] i386: extended the cpuid_level when Intel PT is enabled

2019-03-08 Thread Paolo Bonzini
From: Luwei Kang 

Intel Processor Trace required CPUID[0x14] but the cpuid_level
have no change when create a kvm guest with
e.g. "-cpu qemu64,+intel-pt".

Signed-off-by: Eduardo Habkost 
Signed-off-by: Luwei Kang 
Message-Id: <1548805979-12321-1-git-send-email-luwei.k...@intel.com>
Signed-off-by: Paolo Bonzini 
---
 hw/i386/pc.c  | 1 +
 target/i386/cpu.c | 9 +
 target/i386/cpu.h | 3 +++
 3 files changed, 13 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9c8f833..c6d047b 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -136,6 +136,7 @@ GlobalProperty pc_compat_3_1[] = {
 { "Icelake-Client" "-" TYPE_X86_CPU,  "mpx", "on" },
 { "Icelake-Server" "-" TYPE_X86_CPU,  "mpx", "on" },
 { "Cascadelake-Server" "-" TYPE_X86_CPU, "stepping", "5" },
+{ TYPE_X86_CPU, "x-intel-pt-auto-level", "off" },
 };
 const size_t pc_compat_3_1_len = G_N_ELEMENTS(pc_compat_3_1);
 
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index d3aa6a8..d90c01a 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5031,6 +5031,13 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error 
**errp)
 x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX);
 x86_cpu_adjust_feat_level(cpu, FEAT_SVM);
 x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE);
+
+/* Intel Processor Trace requires CPUID[0x14] */
+if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
+ kvm_enabled() && cpu->intel_pt_auto_level) {
+x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
+}
+
 /* SVM requires CPUID[0x800A] */
 if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
 x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x800A);
@@ -5824,6 +5831,8 @@ static Property x86_cpu_properties[] = {
 DEFINE_PROP_INT32("x-hv-max-vps", X86CPU, hv_max_vps, -1),
 DEFINE_PROP_BOOL("x-hv-synic-kvm-only", X86CPU, hyperv_synic_kvm_only,
  false),
+DEFINE_PROP_BOOL("x-intel-pt-auto-level", X86CPU, intel_pt_auto_level,
+ true),
 DEFINE_PROP_END_OF_LIST()
 };
 
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 95112b9..83fb522 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1454,6 +1454,9 @@ struct X86CPU {
 /* Enable auto level-increase for all CPUID leaves */
 bool full_cpuid_auto_level;
 
+/* Enable auto level-increase for Intel Processor Trace leave */
+bool intel_pt_auto_level;
+
 /* if true fill the top bits of the MTRR_PHYSMASKn variable range */
 bool fill_mtrr_mask;
 
-- 
1.8.3.1





[Qemu-devel] [PULL 05/25] contrib/elf2dmp: add kernel start address checking

2019-03-08 Thread Paolo Bonzini
From: Viktor Prutyanov 

Before this patch, if elf2dmp failed to find NT kernel PE magic in
allowed virtual address range, then it assumes NULL as NT kernel
address and cause segfault.

This patch fix the problem described above by checking NT kernel address
before futher processing.

Signed-off-by: Viktor Prutyanov 
Message-Id: <20190219211936.6466-1-viktor.prutya...@phystech.edu>
Signed-off-by: Paolo Bonzini 
---
 contrib/elf2dmp/main.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index 1a45eaf..1bfeb89 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -524,6 +524,12 @@ int main(int argc, char *argv[])
 }
 }
 
+if (!nt_start_addr) {
+eprintf("Failed to find NT kernel image\n");
+err = 1;
+goto out_ps;
+}
+
 printf("KernBase = 0x%016"PRIx64", signature is \'%.2s\'\n", KernBase,
 (char *)nt_start_addr);
 
-- 
1.8.3.1





[Qemu-devel] [PULL 04/25] block/iscsi: Restrict Linux-specific code

2019-03-08 Thread Paolo Bonzini
From: Philippe Mathieu-Daudé 

Some Linux specific code is missing guards, leading to
build failure on OSX:

  $ sudo brew install libiscsi
  $ ./configure && make
  [...]
CC  block/iscsi.o
  qemu/block/iscsi.c:338:24: error: 'iscsi_aiocb_info' defined but not used 
[-Werror=unused-const-variable=]
   static const AIOCBInfo iscsi_aiocb_info = {
  ^~~~
  qemu/block/iscsi.c:168:1: error: 'iscsi_schedule_bh' defined but not used 
[-Werror=unused-function]
   iscsi_schedule_bh(IscsiAIOCB *acb)
   ^
  cc1: all warnings being treated as errors

Add guards to restrict this code for Linux.

Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <2019022553.28438-1-phi...@redhat.com>
Signed-off-by: Paolo Bonzini 
Signed-off-by: Philippe Mathieu-Daudé 
---
 block/iscsi.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/block/iscsi.c b/block/iscsi.c
index a0c0084..f31c612 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -145,6 +145,8 @@ static const unsigned iscsi_retry_times[] = {8, 32, 128, 
512, 2048, 8192, 32768}
  * unallocated. */
 #define ISCSI_CHECKALLOC_THRES 64
 
+#ifdef __linux__
+
 static void
 iscsi_bh_cb(void *p)
 {
@@ -172,6 +174,8 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
 qemu_bh_schedule(acb->bh);
 }
 
+#endif
+
 static void iscsi_co_generic_bh_cb(void *opaque)
 {
 struct IscsiTask *iTask = opaque;
@@ -290,6 +294,8 @@ static void iscsi_co_init_iscsitask(IscsiLun *iscsilun, 
struct IscsiTask *iTask)
 };
 }
 
+#ifdef __linux__
+
 /* Called (via iscsi_service) with QemuMutex held. */
 static void
 iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void 
*command_data,
@@ -338,6 +344,7 @@ static const AIOCBInfo iscsi_aiocb_info = {
 .cancel_async   = iscsi_aio_cancel,
 };
 
+#endif
 
 static void iscsi_process_read(void *arg);
 static void iscsi_process_write(void *arg);
-- 
1.8.3.1





[Qemu-devel] [PULL 13/25] build: get rid of target-obj-y

2019-03-08 Thread Paolo Bonzini
It is possible to specify the trace/ directory already in objs-y;
there is no need to have a separate unnest-vars invocation.

Signed-off-by: Paolo Bonzini 
---
 Makefile.objs   | 1 -
 Makefile.target | 7 ++-
 trace/Makefile.objs | 4 ++--
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index ef65a6c..acc53aa 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -101,7 +101,6 @@ version-obj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.o
 ##
 # tracing
 util-obj-y +=  trace/
-target-obj-y += trace/
 
 ##
 # guest agent
diff --git a/Makefile.target b/Makefile.target
index 40830c5..a458506 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -105,6 +105,8 @@ all: $(PROGS) stap
 # Dummy command so that make thinks it has done something
@true
 
+obj-y += trace/
+
 #
 # cpu emulator library
 obj-y += exec.o
@@ -173,13 +175,10 @@ endif # CONFIG_SOFTMMU
 dummy := $(call unnest-vars,,obj-y)
 all-obj-y := $(obj-y)
 
-target-obj-y :=
 block-obj-y :=
 common-obj-y :=
 chardev-obj-y :=
 include $(SRC_PATH)/Makefile.objs
-dummy := $(call unnest-vars,,target-obj-y)
-target-obj-y-save := $(target-obj-y)
 dummy := $(call unnest-vars,.., \
authz-obj-y \
block-obj-y \
@@ -191,9 +190,7 @@ dummy := $(call unnest-vars,.., \
io-obj-y \
common-obj-y \
common-obj-m)
-target-obj-y := $(target-obj-y-save)
 all-obj-y += $(common-obj-y)
-all-obj-y += $(target-obj-y)
 all-obj-y += $(qom-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y)
diff --git a/trace/Makefile.objs b/trace/Makefile.objs
index afd571c..c544509 100644
--- a/trace/Makefile.objs
+++ b/trace/Makefile.objs
@@ -36,7 +36,7 @@ $(obj)/generated-helpers.c-timestamp: 
$(SRC_PATH)/trace-events $(BUILD_DIR)/conf
 
 $(obj)/generated-helpers.o: $(obj)/generated-helpers.c
 
-target-obj-y += generated-helpers.o
+obj-y += generated-helpers.o
 
 
 $(obj)/generated-tcg-tracers.h: $(obj)/generated-tcg-tracers.h-timestamp
@@ -55,5 +55,5 @@ $(obj)/generated-tcg-tracers.h-timestamp: 
$(SRC_PATH)/trace-events $(BUILD_DIR)/
 util-obj-$(CONFIG_TRACE_SIMPLE) += simple.o
 util-obj-$(CONFIG_TRACE_FTRACE) += ftrace.o
 util-obj-y += control.o
-target-obj-y += control-target.o
+obj-y += control-target.o
 util-obj-y += qmp.o
-- 
1.8.3.1





[Qemu-devel] [PULL 01/25] memory: Do not update coalesced IO range in the case of NOP

2019-03-08 Thread Paolo Bonzini
From: Jagannathan Raman 

Do not add/del coalesced IO ranges in the case where the
same FlatRanges are present in both old and new FlatViews

Fixes: 3ac7d43a6fbb ("memory: update coalesced_range on transaction_commit")
Signed-off-by: Jagannathan Raman 
Message-Id: 
<59572a7353830be4b7aa57d79ccb7ad6b72f0dda.1549406119.git.jag.ra...@oracle.com>
Signed-off-by: Paolo Bonzini 
---
 memory.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/memory.c b/memory.c
index 61d66e4..e49369d 100644
--- a/memory.c
+++ b/memory.c
@@ -932,9 +932,7 @@ static void address_space_update_topology_pass(AddressSpace 
*as,
 } else if (frold && frnew && flatrange_equal(frold, frnew)) {
 /* In both and unchanged (except logging may have changed) */
 
-if (!adding) {
-flat_range_coalesced_io_del(frold, as);
-} else {
+if (adding) {
 MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, region_nop);
 if (frnew->dirty_log_mask & ~frold->dirty_log_mask) {
 MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, 
log_start,
@@ -946,7 +944,6 @@ static void address_space_update_topology_pass(AddressSpace 
*as,
   frold->dirty_log_mask,
   frnew->dirty_log_mask);
 }
-flat_range_coalesced_io_add(frnew, as);
 }
 
 ++iold;
-- 
1.8.3.1





[Qemu-devel] [PULL 02/25] vfio-pci: enable by default

2019-03-08 Thread Paolo Bonzini
CONFIG_VFIO_PCI was not "default y" - and once you do that, it is also
important to disable it if PCI is not there.

Reported-by: Alex Williamson 
Tested-by: Alex Williamson 
Signed-off-by: Paolo Bonzini 
---
 hw/vfio/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/vfio/Kconfig b/hw/vfio/Kconfig
index ebda9fd..34da2a3 100644
--- a/hw/vfio/Kconfig
+++ b/hw/vfio/Kconfig
@@ -4,8 +4,9 @@ config VFIO
 
 config VFIO_PCI
 bool
+default y
 select VFIO
-depends on LINUX
+depends on LINUX && PCI
 
 config VFIO_CCW
 bool
-- 
1.8.3.1





[Qemu-devel] [PULL 03/25] hw/i386/pc: run the multiboot loader before the PVH loader

2019-03-08 Thread Paolo Bonzini
From: Stefano Garzarella 

Some multiboot images could be in the ELF format. In the current
implementation QEMU fails because we try to load these images
as a PVH image.

In order to fix this issue, we should try multiboot first (we
already check the multiboot magic header before to load it).
If it is not a multiboot image, we can try the PVH loader.

Fixes: ab969087da6 ("pvh: Boot uncompressed kernel using direct boot ABI", 
2019-01-15)
Reported-by: Paolo Bonzini 
Signed-off-by: Stefano Garzarella 
Message-Id: <20190214180216.246707-1-sgarz...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 hw/i386/pc.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4212818..9c8f833 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1210,6 +1210,17 @@ static void load_linux(PCMachineState *pcms,
 protocol = lduw_p(header+0x206);
 } else {
 /*
+ * This could be a multiboot kernel. If it is, let's stop treating it
+ * like a Linux kernel.
+ * Note: some multiboot images could be in the ELF format (the same of
+ * PVH), so we try multiboot first since we check the multiboot magic
+ * header before to load it.
+ */
+if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
+   kernel_cmdline, kernel_size, header)) {
+return;
+}
+/*
  * Check if the file is an uncompressed kernel file (ELF) and load it,
  * saving the PVH entry point used by the x86/HVM direct boot ABI.
  * If load_elfboot() is successful, populate the fw_cfg info.
@@ -1262,12 +1273,6 @@ static void load_linux(PCMachineState *pcms,
 
 return;
 }
-/* This looks like a multiboot kernel. If it is, let's stop
-   treating it like a Linux kernel. */
-if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
-   kernel_cmdline, kernel_size, header)) {
-return;
-}
 protocol = 0;
 }
 
-- 
1.8.3.1





[Qemu-devel] [PULL 00/25] Misc patches for QEMU 4.0 soft freeze

2019-03-08 Thread Paolo Bonzini
The following changes since commit 62cfabb52210139843e26c95434356f73a0631b9:

  Merge remote-tracking branch 'remotes/rth/tags/pull-hppa-20190307' into 
staging (2019-03-08 15:17:01 +)

are available in the git repository at:


  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to d7fa7c30d45c375fb7d9ad6f58462a64c3317037:

  exec: streamline flatview_add_to_dispatch (2019-03-09 08:46:56 +0100)


* allow building QEMU without TCG or KVM support (Anthony)
* update AMD IOMMU copyright (David)
* compilation fixes for GCC and BSDs (Alexey, David, Paolo, Philippe)
* coalesced I/O bugfix (Jagannathan)
* Processor Tracing cpuid fix (Luwei)
* Kconfig fix (Paolo)
* Cleanups (Paolo)
* PVH vs. multiboot fix (Stefano)
* LSI bugfixes (Sven)
* elf2dmp Coverity fix (Victor)
* scsi-disk fix (Zhengui)


Alexey Kardashevskiy (1):
  configure: Enable werror for git worktrees

Anthony PERARD (1):
  accel: Allow to build QEMU without TCG or KVM support

David Kiarie (1):
  update copyright notice

Greg Kurz (1):
  virtio-scsi: Fix build with gcc 9

Jagannathan Raman (1):
  memory: Do not update coalesced IO range in the case of NOP

Luwei Kang (1):
  i386: extended the cpuid_level when Intel PT is enabled

Paolo Bonzini (6):
  vfio-pci: enable by default
  target-i386: add kvm stubs to user-mode emulators
  build: get rid of target-obj-y
  build: remove unnecessary assignments from Makefile.target
  build: clean trace/generated-helpers.c
  exec: streamline flatview_add_to_dispatch

Philippe Mathieu-Daudé (3):
  block/iscsi: Restrict Linux-specific code
  oslib-posix: Ignore fcntl("/dev/null", F_SETFL, O_NONBLOCK) failure
  configure: Disable W^X on OpenBSD

Stefano Garzarella (1):
  hw/i386/pc: run the multiboot loader before the PVH loader

Sven Schnelle (7):
  lsi: implement basic SBCL functionality
  lsi: check if SIGP bit is already set in Wait reselect
  lsi: use ldn_le_p()/stn_le_p()
  lsi: use enum type for s->waiting
  lsi: use enum type for s->msg_action
  lsi: use SCSI phase names instead of numbers in trace
  lsi: return dfifo value

Viktor Prutyanov (1):
  contrib/elf2dmp: add kernel start address checking

Zhengui Li (1):
  scsi-disk: Fix crash if request is invaild or disk is no medium

 Makefile.objs |   3 +-
 Makefile.target   |  11 +---
 accel/accel.c |   4 +-
 block/iscsi.c |   7 ++
 configure |  13 +++-
 contrib/elf2dmp/main.c|   6 ++
 exec.c|  34 +-
 hw/i386/amd_iommu.c   |   2 +-
 hw/i386/amd_iommu.h   |   2 +-
 hw/i386/pc.c  |  18 +++--
 hw/scsi/lsi53c895a.c  | 163 --
 hw/scsi/scsi-disk.c   |  37 +++
 hw/scsi/trace-events  |   6 +-
 hw/scsi/virtio-scsi.c |   8 ++-
 hw/vfio/Kconfig   |   3 +-
 memory.c  |   5 +-
 target/i386/Makefile.objs |   2 +-
 target/i386/cpu.c |   9 +++
 target/i386/cpu.h |   3 +
 trace/Makefile.objs   |   4 +-
 util/oslib-posix.c|  12 
 21 files changed, 227 insertions(+), 125 deletions(-)
-- 
1.8.3.1




[Qemu-devel] 'make check' error

2019-03-08 Thread Li Qiang
Hi all, 

Today I ‘git clone’ && configure && make && make check 

And get following error, 

fp-test.c:50:10: fatal error: fail.h: No such file or directory
 #include "fail.h"
  ^~~~

I look at the commit:
https://git.qemu.org/?p=qemu.git;a=commitdiff;h=3ac1f81329f4dfdc10a51e180f9cf28dbcb02a3c;hp=b44b5abeae4a3b54ccbd7137f59c0a8923cecec9

Seems it’s old commit, I think I got ‘make check’ work after this commit.
So I don’t know anywhere wrong.

Any hints?

Thanks,
Li Qiang




[Qemu-devel] [Bug 1535497] Re: Guest can not boot up when assigned more than 20 vcpus with option "-no-acpi"

2019-03-08 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

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

Title:
  Guest can not boot up when assigned more than 20 vcpus with option
  "-no-acpi"

Status in QEMU:
  Expired

Bug description:
  Environment:
   ---
   KVM commit/branch: da3f7ca3/next
   Qemu commit/branch: 7b8a354d/master
   Host OS: RHEL7.2 ia32e
   Host Kernel: 4.4-rc2
   Guest OS: RHEL7.2 ia32e

  Description:
   
  When assign more than 20 vpcus with option "-no-acpi", guest can not boot up.

  Reproduce:
   
   1.qemu-system-x86_64 --enable-kvm -m 1024 -smp 20 -no-acpi -device 
virtio-net-pci,netdev=nic0,mac=00:16:3e:17:9b:4c -netdev 
tap,id=nic0,script=/etc/kvm/qemu-ifup -drive 
file=/root/7u2.qcow2,if=none,id=virtio-disk0 -device 
virtio-blk-pci,drive=virtio-disk0

  
  Bisect show the bad commit is 9ee2e2625 of seabios.

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



[Qemu-devel] [Bug 1530386] Re: command.com on win95 throws video mode out

2019-03-08 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

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

Title:
  command.com on win95 throws video mode out

Status in QEMU:
  Expired

Bug description:
  on a presumed-good copy of Windows 95 obtained from http://forum.xda-
  developers.com/showthread.php?t=1960870, the operating system boots
  successfully and shows up fine, but as soon as I double-click the MS-
  DOS icon, the window, while remaining the same size, goes to a
  different resolution and only shows a small portion of what it did,
  with strange colors and artifacts. tried first with the Debian 2.5
  package, then with latest cvs sources, then with the 2.5.0 release,
  all the same problem.

  jcomeau@aspire:/usr/src/qemu-2.5.0/build$ cd /tmp/win95/SDL/
  jcomeau@aspire:/tmp/win95/SDL$ 
/usr/src/qemu-2.5.0/build/i386-softmmu/qemu-system-i386 c.img 
  jcomeau@aspire:/tmp/win95/SDL$ 
/usr/src/qemu-2.5.0/build/i386-softmmu/qemu-system-i386 --version
  QEMU emulator version 2.5.0, Copyright (c) 2003-2008 Fabrice Bellard

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



[Qemu-devel] [Bug 1534382] Re: loadvm makes Windows 7 x86 guest crash with some CPUs

2019-03-08 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

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

Title:
  loadvm makes Windows 7 x86 guest crash with some CPUs

Status in QEMU:
  Expired

Bug description:
  Running qemu with kvm enabled and -cpu set to some of the more "modern" CPUs,
  and having Windows 7 x86 as the guest.

  After guest OS loads, start some app (I started "cmd"), then do "savevm".
  After that, do some more activity (I closed cmd window and opened IE),
  then do "loadvm" of the previously saved snapshot.

  loadvm shows briefly the state that the system was in at the snapshot time,
  then guest OS crashes (blue screen).

  Originally I saw this problem on qemu 1.4.0,
  then I also tried qemu 2.5.0 and found the same problem.

  The CPUs that I tried were mostly those that support NX bit (core2duo, 
  qemu64, kvm64, Nehalem, etc.)

  If I use the default CPU, or some other like qemu32/kvm32,
  the problem does not occur.

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



Re: [Qemu-devel] [PATCH v4 1/2] hw/arm/acpi: simplify AML bit and/or statement

2019-03-08 Thread Heyi Guo




On 2019/3/7 0:34, Igor Mammedov wrote:

On Wed, 6 Mar 2019 21:36:56 +0800
Heyi Guo  wrote:


The last argument of AML bit and/or statement is the target variable,
so we don't need to use a NULL target and then an additional store
operation; a single bit and/or statement is enough.

s: a single bit and/or : using just aml_and() or aml_and() "

With commit message fixed up:

Reviewed-by: Igor Mammedov 

Thanks; have fixed it in v5.

Heyi




Cc: Shannon Zhao 
Cc: Peter Maydell 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Suggested-by: Igor Mammedov 
Signed-off-by: Heyi Guo 
---
  hw/arm/virt-acpi-build.c | 16 
  1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index d7e2e48..cebec4c 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -265,17 +265,17 @@ static void acpi_dsdt_add_pci(Aml *scope, const 
MemMapEntry *memmap,
  aml_create_dword_field(aml_arg(3), aml_int(8), "CDW3"));
  aml_append(ifctx, aml_store(aml_name("CDW2"), aml_name("SUPP")));
  aml_append(ifctx, aml_store(aml_name("CDW3"), aml_name("CTRL")));
-aml_append(ifctx, aml_store(aml_and(aml_name("CTRL"), aml_int(0x1D), NULL),
-aml_name("CTRL")));
+aml_append(ifctx, aml_and(aml_name("CTRL"), aml_int(0x1D),
+  aml_name("CTRL")));
  
  ifctx1 = aml_if(aml_lnot(aml_equal(aml_arg(1), aml_int(0x1;

-aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x08), NULL),
- aml_name("CDW1")));
+aml_append(ifctx1, aml_or(aml_name("CDW1"), aml_int(0x08),
+  aml_name("CDW1")));
  aml_append(ifctx, ifctx1);
  
  ifctx1 = aml_if(aml_lnot(aml_equal(aml_name("CDW3"), aml_name("CTRL";

-aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x10), NULL),
- aml_name("CDW1")));
+aml_append(ifctx1, aml_or(aml_name("CDW1"), aml_int(0x10),
+  aml_name("CDW1")));
  aml_append(ifctx, ifctx1);
  
  aml_append(ifctx, aml_store(aml_name("CTRL"), aml_name("CDW3")));

@@ -283,8 +283,8 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry 
*memmap,
  aml_append(method, ifctx);
  
  elsectx = aml_else();

-aml_append(elsectx, aml_store(aml_or(aml_name("CDW1"), aml_int(4), NULL),
-  aml_name("CDW1")));
+aml_append(elsectx, aml_or(aml_name("CDW1"), aml_int(4),
+   aml_name("CDW1")));
  aml_append(elsectx, aml_return(aml_arg(3)));
  aml_append(method, elsectx);
  aml_append(dev, method);


.







[Qemu-devel] [PATCH v5 2/2] hw/arm/acpi: enable SHPC native hot plug

2019-03-08 Thread Heyi Guo
After the introduction of generic PCIe root port and PCIe-PCI bridge,
we will also have SHPC controller on ARM, so just enable SHPC native
hot plug.

Cc: Shannon Zhao 
Cc: Peter Maydell 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 
Signed-off-by: Heyi Guo 
---
 hw/arm/virt-acpi-build.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index cebec4c..b6fef28 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -265,7 +265,12 @@ static void acpi_dsdt_add_pci(Aml *scope, const 
MemMapEntry *memmap,
 aml_create_dword_field(aml_arg(3), aml_int(8), "CDW3"));
 aml_append(ifctx, aml_store(aml_name("CDW2"), aml_name("SUPP")));
 aml_append(ifctx, aml_store(aml_name("CDW3"), aml_name("CTRL")));
-aml_append(ifctx, aml_and(aml_name("CTRL"), aml_int(0x1D),
+
+/*
+ * Allow OS control for all 5 features:
+ * PCIeHotplug SHPCHotplug PME AER PCIeCapability.
+ */
+aml_append(ifctx, aml_and(aml_name("CTRL"), aml_int(0x1F),
   aml_name("CTRL")));
 
 ifctx1 = aml_if(aml_lnot(aml_equal(aml_arg(1), aml_int(0x1;
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 1/2] hw/arm/acpi: simplify AML bit and/or statement

2019-03-08 Thread Heyi Guo
The last argument of AML bit and/or statement is the target variable,
so we don't need to use a NULL target and then an additional store
operation; using just aml_and() or aml_or() statement is enough.

Cc: Shannon Zhao 
Cc: Peter Maydell 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Suggested-by: Igor Mammedov 
Reviewed-by: Igor Mammedov 
Signed-off-by: Heyi Guo 
---
 hw/arm/virt-acpi-build.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index d7e2e48..cebec4c 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -265,17 +265,17 @@ static void acpi_dsdt_add_pci(Aml *scope, const 
MemMapEntry *memmap,
 aml_create_dword_field(aml_arg(3), aml_int(8), "CDW3"));
 aml_append(ifctx, aml_store(aml_name("CDW2"), aml_name("SUPP")));
 aml_append(ifctx, aml_store(aml_name("CDW3"), aml_name("CTRL")));
-aml_append(ifctx, aml_store(aml_and(aml_name("CTRL"), aml_int(0x1D), NULL),
-aml_name("CTRL")));
+aml_append(ifctx, aml_and(aml_name("CTRL"), aml_int(0x1D),
+  aml_name("CTRL")));
 
 ifctx1 = aml_if(aml_lnot(aml_equal(aml_arg(1), aml_int(0x1;
-aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x08), NULL),
- aml_name("CDW1")));
+aml_append(ifctx1, aml_or(aml_name("CDW1"), aml_int(0x08),
+  aml_name("CDW1")));
 aml_append(ifctx, ifctx1);
 
 ifctx1 = aml_if(aml_lnot(aml_equal(aml_name("CDW3"), aml_name("CTRL";
-aml_append(ifctx1, aml_store(aml_or(aml_name("CDW1"), aml_int(0x10), NULL),
- aml_name("CDW1")));
+aml_append(ifctx1, aml_or(aml_name("CDW1"), aml_int(0x10),
+  aml_name("CDW1")));
 aml_append(ifctx, ifctx1);
 
 aml_append(ifctx, aml_store(aml_name("CTRL"), aml_name("CDW3")));
@@ -283,8 +283,8 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry 
*memmap,
 aml_append(method, ifctx);
 
 elsectx = aml_else();
-aml_append(elsectx, aml_store(aml_or(aml_name("CDW1"), aml_int(4), NULL),
-  aml_name("CDW1")));
+aml_append(elsectx, aml_or(aml_name("CDW1"), aml_int(4),
+   aml_name("CDW1")));
 aml_append(elsectx, aml_return(aml_arg(3)));
 aml_append(method, elsectx);
 aml_append(dev, method);
-- 
1.8.3.1




[Qemu-devel] [PATCH v5 0/2] arm/acpi: simplify aml code and enable SHPC

2019-03-08 Thread Heyi Guo
After the introduction of generic PCIe root port and PCIe-PCI bridge, we will
also have SHPC controller on ARM, and we don't support ACPI hot plug, so just
enable SHPC native hot plug.

Igor also spotted the store operation outside of bit and/or is not necessary, so
simply the code at first.

v5:
- Refine commit message of patch 1/2

v4:
- Improve the code indention.

Cc: Shannon Zhao 
Cc: Peter Maydell 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 



Heyi Guo (2):
  hw/arm/acpi: simplify AML bit and/or statement
  hw/arm/acpi: enable SHPC native hot plug

 hw/arm/virt-acpi-build.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

-- 
1.8.3.1




Re: [Qemu-devel] [PATCH 06/10] roms/Makefile: replace the $(EFIROM) target with "edk2-basetools"

2019-03-08 Thread Philippe Mathieu-Daudé
On 3/9/19 2:32 AM, Philippe Mathieu-Daudé wrote:
> Hi Laszlo,
> 
> On 3/9/19 1:48 AM, Laszlo Ersek wrote:
>> We don't (can't) have a recipe for building just $(EFIROM); therefore,
>> while we call the target $(EFIROM), we actually build all of the edk2
>> BaseTools. Rename the target to edk2-basetools, and update the iPXE
>> prerequisite accordingly. This will let other targets depend on
>> "edk2-basetools", where an $(EFIROM) pre-requisite would be misleading.
>>
>> Signed-off-by: Laszlo Ersek 
>> ---
>>  roms/Makefile | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/roms/Makefile b/roms/Makefile
>> index 78d5dd18c301..2e83ececa25a 100644
>> --- a/roms/Makefile
>> +++ b/roms/Makefile
>> @@ -102,7 +102,7 @@ pxe-rom-%: build-pxe-roms
>>  
>>  efirom: $(patsubst %,efi-rom-%,$(pxerom_variants))
>>  
>> -efi-rom-%: build-pxe-roms build-efi-roms $(EFIROM)
>> +efi-rom-%: build-pxe-roms build-efi-roms edk2-basetools
>>  $(EFIROM) -f "0x$(VID)" -i "0x$(DID)" -l 0x02 \
>>  -b ipxe/src/bin/$(VID)$(DID).rom \
>>  -ec ipxe/src/bin-i386-efi/$(VID)$(DID).efidrv \
>> @@ -120,7 +120,7 @@ build-efi-roms: build-pxe-roms
>>  $(patsubst %,bin-i386-efi/%.efidrv,$(pxerom_targets)) \
>>  $(patsubst %,bin-x86_64-efi/%.efidrv,$(pxerom_targets))
>>  
>> -$(EFIROM):
>> +edk2-basetools:
> 
> Should we add:
> 
> $(MAKE) -f Makefile.edk2 submodules
> 
> from your next patch?
> 
> There might be a circular dependency else, if the user doesn't init the
> submodules manually.
> 
> The next patch add a make dependency 'efi' -> 'edk2-basetools', but
> 'edk2-basetools' build the BaseTools within edk2/.
> 

OK I mixed, the Makefile.edk2's submodules rules is for the edk2
repository submodules, while by 'the user submodules' I mean the QEMU
submodules...

So the user has to initialize the roms/edk2 submodule previous to run
both efi/edk2-basetools rules of this Makefile.

>>  $(MAKE) -C edk2/BaseTools
>>  
>>  slof:
>>



Re: [Qemu-devel] [Qemu-block] [PATCH] tcmu: Introduce qemu-tcmu utility

2019-03-08 Thread Yaowei Bai
> 
> I'm not sure what check you mean. Case 2 would need to find an existing
> export with the given name, of course, and would return an error if no
> such export exists yet.
> 
> But for care 1, isn't the image explicitly opened when the target is
> configured? And if it can't be opened, -1 is returned to libtcmu?

Yes it is. I misunderstood your meaning, forget about this.

> 
> > Actually we thought about qemu-tcmu working like case2, but felt is's quite 
> > less
> > flexible. With case2, e.g. when we want to export another new image file 
> > with
> > one qemu-tcmu already running, we have to run another qemu-tcmu with
> > the configuration of the new image file in commandline, or through QMP of 
> > the
> > running qemu-tcmu, and then configure it with targetcli. So anyway,
> > there's one more step for case2 to export a new image file. While for case1 
> > you just need to run qemu-tcmu once and all other operations will be done
> > within targetcli, which is more friendly to users i think.
> 
> Some users may call it more convenient (even though it's really the
> same, just moved to a different command, in the simple case that case 2
> supports). But it's actually not very flexible.
> 
> If we implement case 1, you can define your configuration exactly as
> with QEMU, including multiple -blockdev and -object options, and select
> the exact block node that you want to export.
> 
> In case 2, you only have a single string, which comes with many
> downsides:
> 
> * You cannot get the semantics of block nodes defined individually with
>   separate -blockdev options, but only a single tree that is managed as
>   a single unit.
> 
> * Additional objects such as iothreads or secrets cannot be included in
>   the config string, so you must split the configuration and pass some
>   parts directly to qemu-tcmu and other parts to targetcli. This is
>   inconsistent.
> 
> * You need a way to represent a possible options of a node in a string.
>   QEMU -drive already caused trouble by giving commas a special meaning.
>   This patch adds @ as a special character, without an option to escape
>   it. If you have a filename that contains @, there is no way to use it.
> 
> * For the not yet implemented QMP part: You can export only images that
>   are newly opened. You cannot export images that are already opened and
>   in use. But exporting images that are in use by the VM is the main use
>   of even having a QMP interface.
> 
> If I think a bit longer, I'm sure I can come up with more points. Case 2
> just doesn't feel right, it is like drives were configured in QEMU 0.10,
> not in 4.0, and we moved away from it for many reasons, most of which
> probably apply here, too.

Thanks for explaining the background. It comes to my mind that actually we
talked about these two cases with Fam a bit long time ago and decided to
support both these two cases. The reason why we implement case2 first is
currently we care more about exporting new opened images and it's a bit
more convenient, exporting from a VM or QMP can be added in the later
release. Do you think it's reasonable/acceptable that we support both
cases and use case2 for normal new opened images and case1 for the
circumstances you mention above?

> 





[Qemu-devel] [Bug 1817239] Re: add '--targets' option to qemu-binfmt-conf.sh

2019-03-08 Thread umarcor
I submitted a first version some days ago, which homogeneized the
implementation, as suggested by Laurent Vivier. It received some
feedback from Eric Blake. A patchset (v3) is ready for review:
https://patchew.org/QEMU/20190306031221.GA53@03612eec87fc/#

The feature requested in this issue is included in the patchset:

[Qemu-devel] [PATCH v3 6/10] qemu-binfmt-conf.sh: generalize  to 
positional  
https://patchew.org/QEMU/20190306031221.GA53@03612eec87fc/20190306045019.GF75@03612eec87fc/

Note that, instead of adding a parameter named `--target`, positional
arguments are used, which where not being processed at all.

** Changed in: qemu
   Status: New => In Progress

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

Title:
  add '--targets' option to qemu-binfmt-conf.sh

Status in QEMU:
  In Progress

Bug description:
  I'd like to ask for the addition of option '--targets' to scripts
  /qemu-binfmt-conf.sh, in order to allow registering the interpreters
  for the given list of architectures only, instead of using all of the
  ones defined in qemu_target_list. The following is a possible patch
  that implements it:

   qemu-binfmt-conf.sh | 9 -
   1 file changed, 8 insertions(+), 1 deletion(-)

  diff --git a/qemu-binfmt-conf.sh b/qemu-binfmt-conf.sh
  index b5a1674..be4a19b 100644
  --- a/qemu-binfmt-conf.sh
  +++ b/qemu-binfmt-conf.sh
  @@ -170,6 +170,7 @@ usage() {
   Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU]
  [--help][--credential yes|no][--exportdir PATH]
  [--persistent yes|no][--qemu-suffix SUFFIX]
  +   [--targets TARGETS]

  Configure binfmt_misc to use qemu interpreter

  @@ -189,6 +190,8 @@ Usage: qemu-binfmt-conf.sh [--qemu-path 
PATH][--debian][--systemd CPU]
  --persistent:  if yes, the interpreter is loaded when binfmt is
 configured and remains in memory. All future uses
 are cloned from the open file.
  +   --targets: comma-separated list of targets. If provided, only
  +  the targets in the list are registered.

   To import templates with update-binfmts, use :

  @@ -324,7 +327,7 @@ CREDENTIAL=no
   PERSISTENT=no
   QEMU_SUFFIX=""

  -options=$(getopt -o ds:Q:S:e:hc:p: -l 
debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent: 
-- "$@")
  +options=$(getopt -o ds:Q:S:e:hc:p:t: -l 
debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent:,targets:
 -- "$@")
   eval set -- "$options"

   while true ; do
  @@ -380,6 +383,10 @@ while true ; do
   shift
   PERSISTENT="$1"
   ;;
  +-t|--targets)
  +shift
  +qemu_target_list="$(echo "$1" | tr ',' ' ')"
  +;;
   *)
   break
   ;;
  --
  2.20.1

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



Re: [Qemu-devel] [PATCH 06/10] roms/Makefile: replace the $(EFIROM) target with "edk2-basetools"

2019-03-08 Thread Philippe Mathieu-Daudé
Hi Laszlo,

On 3/9/19 1:48 AM, Laszlo Ersek wrote:
> We don't (can't) have a recipe for building just $(EFIROM); therefore,
> while we call the target $(EFIROM), we actually build all of the edk2
> BaseTools. Rename the target to edk2-basetools, and update the iPXE
> prerequisite accordingly. This will let other targets depend on
> "edk2-basetools", where an $(EFIROM) pre-requisite would be misleading.
> 
> Signed-off-by: Laszlo Ersek 
> ---
>  roms/Makefile | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/roms/Makefile b/roms/Makefile
> index 78d5dd18c301..2e83ececa25a 100644
> --- a/roms/Makefile
> +++ b/roms/Makefile
> @@ -102,7 +102,7 @@ pxe-rom-%: build-pxe-roms
>  
>  efirom: $(patsubst %,efi-rom-%,$(pxerom_variants))
>  
> -efi-rom-%: build-pxe-roms build-efi-roms $(EFIROM)
> +efi-rom-%: build-pxe-roms build-efi-roms edk2-basetools
>   $(EFIROM) -f "0x$(VID)" -i "0x$(DID)" -l 0x02 \
>   -b ipxe/src/bin/$(VID)$(DID).rom \
>   -ec ipxe/src/bin-i386-efi/$(VID)$(DID).efidrv \
> @@ -120,7 +120,7 @@ build-efi-roms: build-pxe-roms
>   $(patsubst %,bin-i386-efi/%.efidrv,$(pxerom_targets)) \
>   $(patsubst %,bin-x86_64-efi/%.efidrv,$(pxerom_targets))
>  
> -$(EFIROM):
> +edk2-basetools:

Should we add:

$(MAKE) -f Makefile.edk2 submodules

from your next patch?

There might be a circular dependency else, if the user doesn't init the
submodules manually.

The next patch add a make dependency 'efi' -> 'edk2-basetools', but
'edk2-basetools' build the BaseTools within edk2/.

>   $(MAKE) -C edk2/BaseTools
>  
>  slof:
> 



Re: [Qemu-devel] [PATCH 00/10] bundle edk2 platform firmware with QEMU

2019-03-08 Thread Philippe Mathieu-Daudé
On 3/9/19 1:48 AM, Laszlo Ersek wrote:
> Repo:   https://github.com/lersek/qemu.git
> Branch: edk2_build
> 
> This series advances the roms/edk2 submodule to the "edk2-stable201903"
> release, and builds and captures platform firmware binaries from that
> release. At this point they are meant to be used by both end-users and
> by Igor's ACPI unit tests in qtest ("make check").
> 
> Previous discussion:
> 
>   [Qemu-devel] bundling edk2 platform firmware images with QEMU
>   80f0bae3-e79a-bb68-04c4-1c9c684d95b8@redhat.com">http://mid.mail-archive.com/80f0bae3-e79a-bb68-04c4-1c9c684d95b8@redhat.com
>   https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg02601.html
> 
> Note that the series was formatted with "--no-binary" (affecting patch
> #8), therefore it cannot be applied with "git-am". See the remote
> repo/branch reference near the top instead.
> 
> Thanks,
> Laszlo
> 
> Laszlo Ersek (10):
>   roms: lift "edk2-funcs.sh" from "tests/uefi-test-tools/build.sh"
>   roms/edk2-funcs.sh: require gcc-4.8+ for building i386 and x86_64
>   tests/uefi-test-tools/build.sh: work around TianoCore#1607
>   roms/edk2: advance to tag edk2-stable201903
>   roms/edk2-funcs.sh: add the qemu_edk2_get_thread_count() function
>   roms/Makefile: replace the $(EFIROM) target with "edk2-basetools"
>   roms: build edk2 firmware binaries and variable store templates
>   pc-bios: add edk2 firmware binaries and variable store templates
>   pc-bios: document the edk2 firmware images; add firmware descriptors
>   Makefile: install the edk2 firmware images and their descriptors
> 
>  Makefile   |  17 +-
>  pc-bios/README |  11 +
>  pc-bios/descriptors/50-edk2-i386-secure.json   |  34 +++
>  pc-bios/descriptors/50-edk2-x86_64-secure.json |  35 +++
>  pc-bios/descriptors/60-edk2-aarch64.json   |  31 +++
>  pc-bios/descriptors/60-edk2-arm.json   |  31 +++
>  pc-bios/descriptors/60-edk2-i386.json  |  33 +++
>  pc-bios/descriptors/60-edk2-x86_64.json|  34 +++
>  pc-bios/edk2-aarch64-code.fd   | Bin 0 -> 67108864 bytes
>  pc-bios/edk2-arm-code.fd   | Bin 0 -> 67108864 bytes
>  pc-bios/edk2-arm-vars.fd   | Bin 0 -> 67108864 bytes

GitHub moans here:

remote: warning: GH001: Large files detected. You may want to try Git
Large File Storage - https://git-lfs.github.com.
remote: warning: See http://git.io/iEPt8g for more information.
remote: warning: File pc-bios/edk2-arm-vars.fd is 64.00 MB; this is
larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File pc-bios/edk2-arm-code.fd is 64.00 MB; this is
larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File pc-bios/edk2-aarch64-code.fd is 64.00 MB; this is
larger than GitHub's recommended maximum file size of 50.00 MB

>  pc-bios/edk2-i386-code.fd  | Bin 0 -> 3653632 bytes
>  pc-bios/edk2-i386-secure-code.fd   | Bin 0 -> 3653632 bytes
>  pc-bios/edk2-i386-vars.fd  | Bin 0 -> 540672 bytes
>  pc-bios/edk2-licenses.txt  | 209 
>  pc-bios/edk2-x86_64-code.fd| Bin 0 -> 3653632 bytes
>  pc-bios/edk2-x86_64-secure-code.fd | Bin 0 -> 3653632 bytes
>  roms/Makefile  |   9 +-
>  roms/Makefile.edk2 | 138 +++
>  roms/edk2  |   2 +-
>  roms/edk2-build.sh |  55 +
>  roms/edk2-funcs.sh | 253 
>  tests/uefi-test-tools/build.sh | 100 +---
>  23 files changed, 897 insertions(+), 95 deletions(-)
>  create mode 100644 pc-bios/descriptors/50-edk2-i386-secure.json
>  create mode 100644 pc-bios/descriptors/50-edk2-x86_64-secure.json
>  create mode 100644 pc-bios/descriptors/60-edk2-aarch64.json
>  create mode 100644 pc-bios/descriptors/60-edk2-arm.json
>  create mode 100644 pc-bios/descriptors/60-edk2-i386.json
>  create mode 100644 pc-bios/descriptors/60-edk2-x86_64.json
>  create mode 100644 pc-bios/edk2-aarch64-code.fd
>  create mode 100644 pc-bios/edk2-arm-code.fd
>  create mode 100644 pc-bios/edk2-arm-vars.fd
>  create mode 100644 pc-bios/edk2-i386-code.fd
>  create mode 100644 pc-bios/edk2-i386-secure-code.fd
>  create mode 100644 pc-bios/edk2-i386-vars.fd
>  create mode 100644 pc-bios/edk2-licenses.txt
>  create mode 100644 pc-bios/edk2-x86_64-code.fd
>  create mode 100644 pc-bios/edk2-x86_64-secure-code.fd
>  create mode 100644 roms/Makefile.edk2
>  create mode 100755 roms/edk2-build.sh
>  create mode 100644 roms/edk2-funcs.sh
> 



Re: [Qemu-devel] [PATCH] Added periodic IRQ support for bcm2836_control local timer

2019-03-08 Thread bzt
Hi,

Thanks for your answers. If I don't clear the INTENABLE flag, then the
IRQ would keep firing constantly. This is not how the real hardware
works: it triggers the IRQ once, and then it inhibits. The timer won't
trigger the IRQ again until you acknowledge it by writing the INTFLAG
into the ack register. My solution emulates this behaviour. That's
what the triggered flag was for in my original patch. Should I bring
that flag back or is the current solution acceptable knowing this?

About keeping the INTFLAG on control write that's to avoid an instant
IRQ, but that's OK. I'll modify that.

Thanks,
bzt


On 3/7/19, Peter Maydell  wrote:
> On Thu, 7 Mar 2019 at 15:57, bzt  wrote:
>>
>> Nope. I meant the second patch, sent on 4th Mar, which had all the
>> things fixed you listed in your review.
>>
>> But here's the modification for your latest query. This one controls
>> the timer depending on ENABLE bit. It sets the INTFLAG even if
>> INTENABLE is not set, and only raises the IRQ if both are set.
>
> Thanks. I've listed a couple of minor things below
> which I think are not quite handling the flags right,
> but the rest looks good.
>
>> @@ -78,6 +94,17 @@ static void bcm2836_control_update(BCM2836ControlState
>> *s)
>>  s->fiqsrc[s->route_gpu_fiq] |= (uint32_t)1 << IRQ_GPU;
>>  }
>>
>> +/* handle THE local timer interrupt for one of the cores' IRQ/FIQ */
>> +if ((s->local_timer_control & LOCALTIMER_INTENABLE) &&
>> +(s->local_timer_control & LOCALTIMER_INTFLAG)) {
>> +if (s->route_localtimer & 4) {
>> +s->fiqsrc[(s->route_localtimer & 3)] |= (uint32_t)1 <<
>> IRQ_TIMER;
>> +} else {
>> +s->irqsrc[(s->route_localtimer & 3)] |= (uint32_t)1 <<
>> IRQ_TIMER;
>> +}
>> +s->local_timer_control &= ~LOCALTIMER_INTENABLE;
>
> This shouldn't clear the INTENABLE flag.
>
>> +}
>> +
>>  for (i = 0; i < BCM2836_NCORES; i++) {
>>  /* handle local timer interrupts for this core */
>>  if (s->timerirqs[i]) {
>> @@ -162,6 +189,55 @@ static void bcm2836_control_set_gpu_fiq(void
>> *opaque, int irq, int level)
>>  bcm2836_control_update(s);
>>  }
>
>> +static void bcm2836_control_local_timer_control(void *opaque, uint32_t
>> val)
>> +{
>> +BCM2836ControlState *s = opaque;
>> +
>> +s->local_timer_control = val & ~LOCALTIMER_INTFLAG;
>
> This will clear the LOCALTIMER_INTFLAG if it was already
> set -- you want to preserve it, something like
>s->local_timer_control = (s->local_timer_control & LOCALTIMER_INTFLAG) |
>  (val & ~LOCALTIMER_INTFLAG);
>
>> +if (val & LOCALTIMER_ENABLE) {
>> +bcm2836_control_local_timer_set_next(s);
>> +} else {
>> +timer_del(&s->timer);
>> +}
>> +}
>> +
>> +static void bcm2836_control_local_timer_ack(void *opaque, uint32_t val)
>> +{
>> +BCM2836ControlState *s = opaque;
>> +
>> +if (val & LOCALTIMER_INTFLAG) {
>> +s->local_timer_control |= LOCALTIMER_INTENABLE;
>> +s->local_timer_control &= ~LOCALTIMER_INTFLAG;
>
> This should just clear the INTFLAG, it doesn't affect INTENABLE.
>
>> +}
>> +if ((val & LOCALTIMER_RELOAD) &&
>> +(s->local_timer_control & LOCALTIMER_ENABLE)) {
>> +bcm2836_control_local_timer_set_next(s);
>> +}
>> +}
>
> thanks
> -- PMM
>



Re: [Qemu-devel] [PATCH 3/9] tcg: Use extract2 in tcg_gen_shifti_i64

2019-03-08 Thread Philippe Mathieu-Daudé
Hi Richard,

On 3/7/19 3:41 PM, Richard Henderson wrote:
> Signed-off-by: Richard Henderson 
> ---
>  tcg/tcg-op.c | 47 ---
>  1 file changed, 24 insertions(+), 23 deletions(-)
> 
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index deacc63e3b..34e0dbc6e0 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -1355,31 +1355,32 @@ static inline void tcg_gen_shifti_i64(TCGv_i64 ret, 
> TCGv_i64 arg1,
>  tcg_gen_shli_i32(TCGV_HIGH(ret), TCGV_LOW(arg1), c);
>  tcg_gen_movi_i32(TCGV_LOW(ret), 0);
>  }
> -} else {
> -TCGv_i32 t0, t1;
> -
> -t0 = tcg_temp_new_i32();
> -t1 = tcg_temp_new_i32();
> -if (right) {
> -tcg_gen_shli_i32(t0, TCGV_HIGH(arg1), 32 - c);
> -if (arith) {
> -tcg_gen_sari_i32(t1, TCGV_HIGH(arg1), c);
> -} else {
> -tcg_gen_shri_i32(t1, TCGV_HIGH(arg1), c);
> -}
> -tcg_gen_shri_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
> -tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t0);
> -tcg_gen_mov_i32(TCGV_HIGH(ret), t1);
> +} else if (right) {
> +if (TCG_TARGET_HAS_extract2_i32) {
> +tcg_gen_extract2_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
> + TCGV_HIGH(arg1), c);
>  } else {
> -tcg_gen_shri_i32(t0, TCGV_LOW(arg1), 32 - c);
> -/* Note: ret can be the same as arg1, so we use t1 */
> -tcg_gen_shli_i32(t1, TCGV_LOW(arg1), c);
> -tcg_gen_shli_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
> -tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t0);
> -tcg_gen_mov_i32(TCGV_LOW(ret), t1);
> +tcg_gen_shri_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
> +tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(ret),
> +TCGV_HIGH(arg1), 32 - c, c);
>  }
> -tcg_temp_free_i32(t0);
> -tcg_temp_free_i32(t1);
> +if (arith) {
> +tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
> +} else {
> +tcg_gen_shri_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
> +}
> +} else {
> +if (TCG_TARGET_HAS_extract2_i32) {
> +tcg_gen_extract2_i32(TCGV_HIGH(ret), TCGV_LOW(arg1),
> + TCGV_HIGH(arg1), 32 - c);
> +} else {
> +TCGv_i32 t0 = tcg_temp_new_i32();
> +tcg_gen_shri_i32(t0, TCGV_LOW(arg1), 32 - c);
> +tcg_gen_deposit_i32(TCGV_HIGH(ret), t0,
> +TCGV_HIGH(arg1), c, 32 - c);
> +tcg_temp_free_i32(t0);
> +}
> +tcg_gen_shli_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
>  }
>  }

I find this patch quite hard to review because you somehow do more than
simply use extract2, you also reordered part of this function.

I find it easier to review as split in 2 commits:

1/ reorder; the code movement is way easier to follow:

-- >8 --
@@ -1355,31 +1355,22 @@ static inline void tcg_gen_shifti_i64(TCGv_i64
ret, TCGv_i64 arg1,
 tcg_gen_shli_i32(TCGV_HIGH(ret), TCGV_LOW(arg1), c);
 tcg_gen_movi_i32(TCGV_LOW(ret), 0);
 }
-} else {
-TCGv_i32 t0, t1;
-
-t0 = tcg_temp_new_i32();
-t1 = tcg_temp_new_i32();
-if (right) {
-tcg_gen_shli_i32(t0, TCGV_HIGH(arg1), 32 - c);
-if (arith) {
-tcg_gen_sari_i32(t1, TCGV_HIGH(arg1), c);
-} else {
-tcg_gen_shri_i32(t1, TCGV_HIGH(arg1), c);
-}
-tcg_gen_shri_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
-tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t0);
-tcg_gen_mov_i32(TCGV_HIGH(ret), t1);
+} else if (right) {
+tcg_gen_shri_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
+tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(ret),
+TCGV_HIGH(arg1), 32 - c, c);
+if (arith) {
+tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
 } else {
-tcg_gen_shri_i32(t0, TCGV_LOW(arg1), 32 - c);
-/* Note: ret can be the same as arg1, so we use t1 */
-tcg_gen_shli_i32(t1, TCGV_LOW(arg1), c);
-tcg_gen_shli_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
-tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t0);
-tcg_gen_mov_i32(TCGV_LOW(ret), t1);
+tcg_gen_shri_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
 }
+} else {
+TCGv_i32 t0 = tcg_temp_new_i32();
+tcg_gen_shri_i32(t0, TCGV_LOW(arg1), 32 - c);
+tcg_gen_deposit_i32(TCGV_HIGH(ret), t0,
+TCGV_HIGH(arg1), c, 32 - c);
 tcg_temp_free_i32(t0);
-tcg_temp_free_i32(t1);
+tcg_gen_shli_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
 }
 }
---

2/ use extract2:

-- >8 --
@@ -1356,20 +1356,30 @@ static inline void tcg_gen_shift

Re: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

2019-03-08 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20190307144126.31847-1-richard.hender...@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190307144126.31847-1-richard.hender...@linaro.org
Subject: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]
patchew/20190307144126.31847-1-richard.hender...@linaro.org -> 
patchew/20190307144126.31847-1-richard.hender...@linaro.org
Switched to a new branch 'test'
a7913aa23f target/arm: Simplify BFXIL expansion
39046cd16f target/arm: Use extract2 for EXTR
896fc67f40 tcg/aarch64: Support INDEX_op_extract2_{i32, i64}
a4d81fe0bf tcg/arm: Support INDEX_op_extract2_i32
e4d782a991 tcg/i386: Support INDEX_op_extract2_{i32, i64}
c614b0e300 tcg: Use extract2 in tcg_gen_deposit_{i32, i64}
c3d7ab05b4 tcg: Use extract2 in tcg_gen_shifti_i64
6ab392e136 tcg: Add INDEX_op_extract2_{i32,i64}
ed214d13db tcg: Implement tcg_gen_extract2_{i32, i64}

=== OUTPUT BEGIN ===
1/9 Checking commit ed214d13dbba (tcg: Implement tcg_gen_extract2_{i32, i64})
2/9 Checking commit 6ab392e1361b (tcg: Add INDEX_op_extract2_{i32,i64})
ERROR: spaces required around that ':' (ctx:VxE)
#109: FILE: tcg/optimize.c:1205:
+CASE_OP_32_64(extract2):
^

total: 1 errors, 0 warnings, 199 lines checked

Patch 2/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

3/9 Checking commit c3d7ab05b49c (tcg: Use extract2 in tcg_gen_shifti_i64)
4/9 Checking commit c614b0e30007 (tcg: Use extract2 in tcg_gen_deposit_{i32, 
i64})
5/9 Checking commit e4d782a99180 (tcg/i386: Support INDEX_op_extract2_{i32, 
i64})
ERROR: spaces required around that ':' (ctx:VxE)
#48: FILE: tcg/i386/tcg-target.inc.c:2591:
+OP_32_64(extract2):
   ^

total: 1 errors, 0 warnings, 51 lines checked

Patch 5/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

6/9 Checking commit a4d81fe0bf4b (tcg/arm: Support INDEX_op_extract2_i32)
7/9 Checking commit 896fc67f40fa (tcg/aarch64: Support INDEX_op_extract2_{i32, 
i64})
8/9 Checking commit 39046cd16fe9 (target/arm: Use extract2 for EXTR)
9/9 Checking commit a7913aa23f53 (target/arm: Simplify BFXIL expansion)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190307144126.31847-1-richard.hender...@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH v2 00/12] pc: Support firmware configuration with -blockdev

2019-03-08 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20190307172401.29451-1-arm...@redhat.com/



Hi,

This series failed the docker-mingw@fedora build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  CC  hw/char/nrf51_uart.o
  CC  hw/char/parallel.o
/tmp/qemu-test/src/hw/block/pflash_cfi02.c: In function 
'pflash_cfi02_unrealize':
/tmp/qemu-test/src/hw/block/pflash_cfi02.c:698:5: error: unknown type name 
'pflash_t'; did you mean 'fpos_t'?
 pflash_t *pfl = CFI_PFLASH02(dev);
 ^~~~
 fpos_t
/tmp/qemu-test/src/hw/block/pflash_cfi02.c:698:21: error: implicit declaration 
of function 'CFI_PFLASH02'; did you mean 'HW_FLASH_H'? 
[-Werror=implicit-function-declaration]
 pflash_t *pfl = CFI_PFLASH02(dev);
 ^~~~
 HW_FLASH_H
/tmp/qemu-test/src/hw/block/pflash_cfi02.c:698:21: error: nested extern 
declaration of 'CFI_PFLASH02' [-Werror=nested-externs]
/tmp/qemu-test/src/hw/block/pflash_cfi02.c:698:21: error: initialization of 
'int *' from 'int' makes pointer from integer without a cast 
[-Werror=int-conversion]
/tmp/qemu-test/src/hw/block/pflash_cfi02.c:699:19: error: request for member 
'timer' in something not a structure or union
 timer_del(&pfl->timer);
   ^~
cc1: all warnings being treated as errors


The full log is available at
http://patchew.org/logs/20190307172401.29451-1-arm...@redhat.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

[Qemu-devel] [PATCH 07/10] roms: build edk2 firmware binaries and variable store templates

2019-03-08 Thread Laszlo Ersek
Add the "efi" target to "Makefile".

Introduce "Makefile.edk2" for building and cleaning the firmware images
and varstore templates.

Collect the common bits from the recipes in the helper script
"edk2-build.sh".

Signed-off-by: Laszlo Ersek 
---
 roms/Makefile  |   5 +
 roms/Makefile.edk2 | 138 
 roms/edk2-build.sh |  55 
 3 files changed, 198 insertions(+)

diff --git a/roms/Makefile b/roms/Makefile
index 2e83ececa25a..054b432834ba 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -61,6 +61,7 @@ default:
@echo "  skiboot-- update skiboot.lid"
@echo "  u-boot.e500-- update u-boot.e500"
@echo "  u-boot.sam460  -- update u-boot.sam460"
+   @echo "  efi-- update UEFI (edk2) platform firmware"
 
 bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
@@ -143,6 +144,9 @@ skiboot:
$(MAKE) -C skiboot CROSS=$(powerpc64_cross_prefix)
cp skiboot/skiboot.lid ../pc-bios/skiboot.lid
 
+efi: edk2-basetools
+   $(MAKE) -f Makefile.edk2
+
 clean:
rm -rf seabios/.config seabios/out seabios/builds
$(MAKE) -C sgabios clean
@@ -153,3 +157,4 @@ clean:
rm -rf u-boot/build.e500
$(MAKE) -C u-boot-sam460ex distclean
$(MAKE) -C skiboot clean
+   $(MAKE) -f Makefile.edk2 clean
diff --git a/roms/Makefile.edk2 b/roms/Makefile.edk2
new file mode 100644
index ..ad6fff044cd6
--- /dev/null
+++ b/roms/Makefile.edk2
@@ -0,0 +1,138 @@
+# Makefile for building firmware binaries and variable store templates for a
+# number of virtual platforms in edk2.
+#
+# Copyright (C) 2019, Red Hat, Inc.
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License that accompanies this
+# distribution. The full text of the license may be found at
+# .
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+toolchain = $(shell source ./edk2-funcs.sh && qemu_edk2_get_toolchain $(1))
+
+licenses := \
+   edk2/License.txt \
+   edk2/OvmfPkg/License.txt \
+   edk2/CryptoPkg/Library/OpensslLib/openssl/LICENSE
+
+# The "edk2-arm-vars.fd" varstore template is suitable for aarch64 as well.
+# Similarly, the "edk2-i386-vars.fd" varstore template is suitable for x86_64
+# as well, independently of "secure" too.
+all: \
+   ../pc-bios/edk2-aarch64-code.fd \
+   ../pc-bios/edk2-arm-code.fd \
+   ../pc-bios/edk2-i386-code.fd \
+   ../pc-bios/edk2-i386-secure-code.fd \
+   ../pc-bios/edk2-x86_64-code.fd \
+   ../pc-bios/edk2-x86_64-secure-code.fd \
+   \
+   ../pc-bios/edk2-arm-vars.fd \
+   ../pc-bios/edk2-i386-vars.fd \
+   \
+   ../pc-bios/edk2-licenses.txt
+
+submodules:
+   cd edk2 && git submodule update --init --force
+
+# See notes on the ".NOTPARALLEL" target and the "+" indicator in
+# "tests/uefi-test-tools/Makefile".
+.NOTPARALLEL:
+
+../pc-bios/edk2-aarch64-code.fd: submodules
+   +./edk2-build.sh \
+   aarch64 \
+   --arch=AARCH64 \
+   --platform=ArmVirtPkg/ArmVirtQemu.dsc \
+   -D NETWORK_IP6_ENABLE \
+   -D HTTP_BOOT_ENABLE
+   cp edk2/Build/ArmVirtQemu-AARCH64/DEBUG_$(call 
toolchain,aarch64)/FV/QEMU_EFI.fd \
+   $@
+   truncate --size=64M $@
+
+../pc-bios/edk2-arm-code.fd: submodules
+   +./edk2-build.sh \
+   arm \
+   --arch=ARM \
+   --platform=ArmVirtPkg/ArmVirtQemu.dsc \
+   -D NETWORK_IP6_ENABLE \
+   -D HTTP_BOOT_ENABLE
+   cp edk2/Build/ArmVirtQemu-ARM/DEBUG_$(call 
toolchain,arm)/FV/QEMU_EFI.fd \
+   $@
+   truncate --size=64M $@
+
+../pc-bios/edk2-i386-code.fd: submodules
+   +./edk2-build.sh \
+   i386 \
+   --arch=IA32 \
+   --platform=OvmfPkg/OvmfPkgIa32.dsc \
+   -D NETWORK_IP6_ENABLE \
+   -D HTTP_BOOT_ENABLE \
+   -D TLS_ENABLE \
+   -D TPM2_ENABLE \
+   -D TPM2_CONFIG_ENABLE
+   cp edk2/Build/OvmfIa32/DEBUG_$(call toolchain,i386)/FV/OVMF_CODE.fd $@
+
+../pc-bios/edk2-i386-secure-code.fd: submodules
+   +./edk2-build.sh \
+   i386 \
+   --arch=IA32 \
+   --platform=OvmfPkg/OvmfPkgIa32.dsc \
+   -D NETWORK_IP6_ENABLE \
+   -D HTTP_BOOT_ENABLE \
+   -D TLS_ENABLE \
+   -D TPM2_ENABLE \
+   -D TPM2_CONFIG_ENABLE \
+   -D SECURE_BOOT_ENABLE \
+   -D SMM_REQUIRE
+   cp edk2/Build/OvmfIa32/DEBUG_$(call toolchain,i386)/FV/OVMF_CODE.fd $@
+
+../pc-bios/edk2-x86_64-code.fd: submodules
+   +./edk2-build.sh \
+   x8

[Qemu-devel] [PATCH 08/10] pc-bios: add edk2 firmware binaries and variable store templates

2019-03-08 Thread Laszlo Ersek
Add the files built by the last patch: binaries, and the cumulative
license text that covers them.

Signed-off-by: Laszlo Ersek 
---
 pc-bios/edk2-licenses.txt  | 209 
 pc-bios/edk2-aarch64-code.fd   | Bin 0 -> 67108864 bytes
 pc-bios/edk2-arm-code.fd   | Bin 0 -> 67108864 bytes
 pc-bios/edk2-arm-vars.fd   | Bin 0 -> 67108864 bytes
 pc-bios/edk2-i386-code.fd  | Bin 0 -> 3653632 bytes
 pc-bios/edk2-i386-secure-code.fd   | Bin 0 -> 3653632 bytes
 pc-bios/edk2-i386-vars.fd  | Bin 0 -> 540672 bytes
 pc-bios/edk2-x86_64-code.fd| Bin 0 -> 3653632 bytes
 pc-bios/edk2-x86_64-secure-code.fd | Bin 0 -> 3653632 bytes
 9 files changed, 209 insertions(+)

diff --git a/pc-bios/edk2-licenses.txt b/pc-bios/edk2-licenses.txt
new file mode 100644
index ..8bdb1abc993e
--- /dev/null
+++ b/pc-bios/edk2-licenses.txt
@@ -0,0 +1,209 @@
+==> edk2/License.txt <==
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+Copyright (c) 2011 - 2015, ARM Limited. All rights reserved.
+Copyright (c) 2014 - 2015, Linaro Limited. All rights reserved.
+Copyright (c) 2013 - 2015, Red Hat, Inc.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+  notice, this list of conditions and the following disclaimer in
+  the documentation and/or other materials provided with the
+  distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+==> edk2/OvmfPkg/License.txt <==
+Copyright (c) 2012, Intel Corporation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+  notice, this list of conditions and the following disclaimer in
+  the documentation and/or other materials provided with the
+  distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+
+Some files are subject to the following license, the MIT license. Those files
+are located in:
+- OvmfPkg/Include/IndustryStandard/Xen/
+- OvmfPkg/XenBusDxe/
+- OvmfPkg/XenPvBlkDxe/
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

[Qemu-devel] [PATCH 05/10] roms/edk2-funcs.sh: add the qemu_edk2_get_thread_count() function

2019-03-08 Thread Laszlo Ersek
The edk2 "build" utility natively supports building modules (that is, INF
files) in parallel. The feature is not useful when building a single
module (with the "-m" option), but it is useful for platform firmware
builds (which include many modules). Add a function that determines the
"-n" option argument for "build", from the MAKEFLAGS variable (i.e. based
on the presence of a make job server).

Signed-off-by: Laszlo Ersek 
---
 roms/edk2-funcs.sh | 25 
 1 file changed, 25 insertions(+)

diff --git a/roms/edk2-funcs.sh b/roms/edk2-funcs.sh
index 22a5dc8f6ab6..7fc62f074c59 100644
--- a/roms/edk2-funcs.sh
+++ b/roms/edk2-funcs.sh
@@ -226,3 +226,28 @@ qemu_edk2_set_cross_env()
 
   eval "export $cross_prefix_var=\$cross_prefix"
 }
+
+
+# Determine the "-n" option argument (that is, the number of modules to build
+# in parallel) for the edk2 "build" utility. Print the result to the standard
+# output.
+#
+# Parameters:
+#   $1: the value of the MAKEFLAGS variable
+qemu_edk2_get_thread_count()
+{
+  local makeflags="$1"
+
+  if [[ "$makeflags" == *--jobserver-auth=* ]] ||
+ [[ "$makeflags" == *--jobserver-fds=* ]]; then
+# If there is a job server, allow the edk2 "build" utility to parallelize
+# as many module builds as there are logical CPUs in the system. The "make"
+# instances forked by "build" are supposed to limit themselves through the
+# job server. The zero value below causes the edk2 "build" utility to fetch
+# the logical CPU count with Python's multiprocessing.cpu_count() method.
+printf '0\n'
+  else
+# Build a single module at a time.
+printf '1\n'
+  fi
+}
-- 
2.19.1.3.g30247aa5d201





[Qemu-devel] [PATCH 10/10] Makefile: install the edk2 firmware images and their descriptors

2019-03-08 Thread Laszlo Ersek
Signed-off-by: Laszlo Ersek 
---
 Makefile | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index d2463c92371f..a29dc5f87a3d 100644
--- a/Makefile
+++ b/Makefile
@@ -714,9 +714,16 @@ spapr-rtas.bin slof.bin skiboot.lid \
 palcode-clipper \
 u-boot.e500 u-boot-sam460-20100605.bin \
 qemu_vga.ndrv \
-hppa-firmware.img
+hppa-firmware.img \
+edk2-aarch64-code.fd edk2-arm-code.fd edk2-i386-code.fd \
+edk2-i386-secure-code.fd edk2-x86_64-code.fd edk2-x86_64-secure-code.fd \
+edk2-arm-vars.fd edk2-i386-vars.fd edk2-licenses.txt
+
+DESCS=50-edk2-i386-secure.json 50-edk2-x86_64-secure.json \
+60-edk2-aarch64.json 60-edk2-arm.json 60-edk2-i386.json 60-edk2-x86_64.json
 else
 BLOBS=
+DESCS=
 endif
 
 define install-manual =
@@ -797,6 +804,14 @@ ifneq ($(BLOBS),)
set -e; for x in $(BLOBS); do \
$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x 
"$(DESTDIR)$(qemu_datadir)"; \
done
+   $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/firmware"
+   set -e; tmpf=$$(mktemp); trap 'rm -f -- "$$tmpf"' EXIT; \
+   for x in $(DESCS); do \
+   sed -e 's,@DATADIR@,$(DESTDIR)$(qemu_datadir),' \
+   "$(SRC_PATH)/pc-bios/descriptors/$$x" > "$$tmpf"; \
+   $(INSTALL_DATA) "$$tmpf" \
+   "$(DESTDIR)$(qemu_datadir)/firmware/$$x"; \
+   done
 endif
for s in $(ICON_SIZES); do \
mkdir -p "$(DESTDIR)/$(qemu_icondir)/hicolor/$${s}/apps"; \
-- 
2.19.1.3.g30247aa5d201




[Qemu-devel] [PATCH 04/10] roms/edk2: advance to tag edk2-stable201903

2019-03-08 Thread Laszlo Ersek
Update the roms/edk2 submodule hash from edk2-stable201811 to
edk2-stable201903. The release notes are available at
.

$ git shortlog edk2-stable201811..edk2-stable201903

Achin Gupta (9):
  ArmPkg: Add PCDs needed for MM communication driver.
  ArmPkg/Drivers: Add EFI_MM_COMMUNICATION_PROTOCOL DXE driver.
  ArmPkg/Include: Add MM interface SVC return codes.
  ArmPkg/ArmMmuLib: Add MMU Library suitable for use in S-EL0.
  StandaloneMmPkg: Add missing dependency on PL011UartClockLib
  StandaloneMmPkg: Enforce alignment check for AArch64
  StandaloneMmPkg: Zero data structure explicitly
  StandaloneMmPkg: Replace dependency on ArmMmuLib
  StandaloneMmPkg: Update dependency on PeCoffExtraActionLib

Albecki, Mateusz (1):
  MdeModulePkg/SdMmcPciHcDxe Fix eMMC HS400 switch sequence

Alex James (2):
  StdLib/sys/termios: Define cc_t as unsigned
  StdLib/Environs: Avoid infinite recursion in _Exit

Antoine Coeur (5):
  ArmVirtPkg: Fix various typos
  CryptoPkg: Fix various typos
  CorebootPayloadPkg: Fix various typos
  CorebootModulePkg: Fix various typos
  BaseTools: Various typo

Ard Biesheuvel (116):
  MdePkg/BaseIoLibIntrinsicArmVirt ARM: avoid double word loads and stores
  ArmPkg/ArmGicDxe ARM: fix encoding for GICv3 interrupt acknowledge
  ArmPlatformPkg: clear frame pointer in startup code
  ArmVirtPkg/PrePi: clear frame pointer in startup code
  ArmPkg/ArmSmcPsciResetSystemLib: add missing call to ExitBootServices()
  ArmPkg: remove now unused BsdLib.h
  ArmPlatformPkg/NorFlashDxe: prepare for devicepath format change
  ArmPlatformPkg/NorFlashDxe: use one GUID plus index to identify flash 
banks
  ArmVirtPkg/FdtClientDxe: take DT node 'status' properties into account
  ArmVirtPkg/NorFlashQemuLib: discover NOR flash banks dynamically
  ArmPlatformPkg/NorFlashPlatformLib: remove unused Guid member from struct
  ArmPkg/ArmPkg.dsc: move ArmMmuStandaloneMmLib.inf to AARCH64 section
  EmbeddedPkg/TemplateSec: remove unused module
  EmbeddedPkg/PrePiHobLib: drop CreateHobList() from library
  ArmVirtPkg/FdtPciHostBridgeLib: map ECAM and I/O spaces in GCD memory map
  ArmVirtPkg/QemuVirtMemInfoLib: remove 1:1 mapping of top of PA range
  MdePkg/ProcessorBind.h AARCH64: limit MAX_ADDRESS to 48 bits
  ArmPkg/ArmLib: add support for reading the max physical address space size
  ArmVirtPkg/XenVirtMemInfoLib: refactor reading of the PA space size
  ArmPkg/ArmMmuLib: take the CPU supported maximum PA space into account
  ArmPkg/CpuPei: base GCD memory space size on CPU's PA range
  ArmPlatformPkg/PrePi: base GCD memory space size on CPU's PA range
  ArmVirtPkg/PrePi: base GCD memory space size on CPU's PA range
  BeagleBoardPkg/PrePi: base GCD memory space size on CPU's PA range
  ArmPlatformPkg/PlatformPei: drop unused PCD references
  EmbeddedPkg/PrePiLib: drop unused PCD reference
  ArmVirtPkg: drop PcdPrePiCpuMemorySize assignments from all platforms
  EmbeddedPkg/EmbeddedPkg.dec: drop PcdPrePiCpuMemorySize declarations
  ArmPkg/ArmMmuLib ARM: handle unmapped section in GetMemoryRegion()
  ArmPkg/ArmMmuLib ARM: handle unmapped sections when updating permissions
  ArmVirtPkg/NorFlashQemuLib: disregard our primary FV
  ArmVirtPkg/QemuVirtMemInfoLib: trim the MMIO region mapping
  BaseTools/CommonLib: avoid using 'native' word size in IP address handling
  BaseTools/CommonLib: use explicit 64-bit type in Strtoi()
  BaseTools/DevicePath: use explicit 64-bit number parsing routines
  BaseTools/CommonLib: add definition of MAX_UINT32
  BaseTools/DevicePath: use MAX_UINT32 as default device path max size
  BaseTools/CommonLib: get rid of 'native' type string parsing routines
  BaseTools/CommonLib: drop definition of MAX_UINTN
  BaseTools/CommonLib: drop the use of MAX_ADDRESS
  Revert "MdePkg/ProcessorBind.h AARCH64: limit MAX_ADDRESS to 48 bits"
  MdeModulePkg/FileExplorerLib: avoid packed struct for program data
  BaseTools/tools_def AARCH64 RELEASE: move GCC49/GGC5 to 4 KB alignment
  ArmVirtPkg/ArmVirtQemuKernel ARM: make some PCD settings apply to ARM
  ArmVirtPkg/PrePiUniCoreRelocatable CLANG38: work around build issues
  BaseTools/GenFw ARM: don't permit R_ARM_GOT_PREL relocations
  MdePkg/BaseMemoryLibOptDxe ARM: add missing function annotations
  BaseTools/tools_def ARM CLANG35: work around -mno-movt option name change
  ArmVirtPkg/PrePi ARM CLANG35: drop incompatible command line option
  ArmVirtPkg/ArmVirt.dsc.inc: define TcpIoLib resolution unconditionally
  ArmPkg: remove redundant _ARM_PLATFORM_FLAGS overrides
  EmbeddedPkg: remove GdbDebugAgent library
  BaseTools/tools_def ARM: emit PIC veneers
  ArmPkg/DefaultExceptionHandlerLib ARM: avoid endless loop in RELEA

[Qemu-devel] [PATCH 06/10] roms/Makefile: replace the $(EFIROM) target with "edk2-basetools"

2019-03-08 Thread Laszlo Ersek
We don't (can't) have a recipe for building just $(EFIROM); therefore,
while we call the target $(EFIROM), we actually build all of the edk2
BaseTools. Rename the target to edk2-basetools, and update the iPXE
prerequisite accordingly. This will let other targets depend on
"edk2-basetools", where an $(EFIROM) pre-requisite would be misleading.

Signed-off-by: Laszlo Ersek 
---
 roms/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/roms/Makefile b/roms/Makefile
index 78d5dd18c301..2e83ececa25a 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -102,7 +102,7 @@ pxe-rom-%: build-pxe-roms
 
 efirom: $(patsubst %,efi-rom-%,$(pxerom_variants))
 
-efi-rom-%: build-pxe-roms build-efi-roms $(EFIROM)
+efi-rom-%: build-pxe-roms build-efi-roms edk2-basetools
$(EFIROM) -f "0x$(VID)" -i "0x$(DID)" -l 0x02 \
-b ipxe/src/bin/$(VID)$(DID).rom \
-ec ipxe/src/bin-i386-efi/$(VID)$(DID).efidrv \
@@ -120,7 +120,7 @@ build-efi-roms: build-pxe-roms
$(patsubst %,bin-i386-efi/%.efidrv,$(pxerom_targets)) \
$(patsubst %,bin-x86_64-efi/%.efidrv,$(pxerom_targets))
 
-$(EFIROM):
+edk2-basetools:
$(MAKE) -C edk2/BaseTools
 
 slof:
-- 
2.19.1.3.g30247aa5d201





[Qemu-devel] [PATCH 09/10] pc-bios: document the edk2 firmware images; add firmware descriptors

2019-03-08 Thread Laszlo Ersek
Update the README file with information on the images added previously,
and provide firmware descriptor documents that conform to
"docs/interop/firmware.json".

Signed-off-by: Laszlo Ersek 
---
 pc-bios/descriptors/50-edk2-i386-secure.json   | 34 +++
 pc-bios/descriptors/50-edk2-x86_64-secure.json | 35 
 pc-bios/descriptors/60-edk2-aarch64.json   | 31 +
 pc-bios/descriptors/60-edk2-arm.json   | 31 +
 pc-bios/descriptors/60-edk2-i386.json  | 33 ++
 pc-bios/descriptors/60-edk2-x86_64.json| 34 +++
 pc-bios/README | 11 ++
 7 files changed, 209 insertions(+)

diff --git a/pc-bios/descriptors/50-edk2-i386-secure.json 
b/pc-bios/descriptors/50-edk2-i386-secure.json
new file mode 100644
index ..d7108c1da05a
--- /dev/null
+++ b/pc-bios/descriptors/50-edk2-i386-secure.json
@@ -0,0 +1,34 @@
+{
+"description": "UEFI firmware for i386, with Secure Boot and SMM",
+"interface-types": [
+"uefi"
+],
+"mapping": {
+"device": "flash",
+"executable": {
+"filename": "@DATADIR@/edk2-i386-secure-code.fd",
+"format": "raw"
+},
+"nvram-template": {
+"filename": "@DATADIR@/edk2-i386-vars.fd",
+"format": "raw"
+}
+},
+"targets": [
+{
+"architecture": "i386",
+"machines": [
+"pc-q35-*"
+]
+}
+],
+"features": [
+"acpi-s3",
+"requires-smm",
+"secure-boot",
+"verbose-dynamic"
+],
+"tags": [
+
+]
+}
diff --git a/pc-bios/descriptors/50-edk2-x86_64-secure.json 
b/pc-bios/descriptors/50-edk2-x86_64-secure.json
new file mode 100644
index ..387eb356236b
--- /dev/null
+++ b/pc-bios/descriptors/50-edk2-x86_64-secure.json
@@ -0,0 +1,35 @@
+{
+"description": "UEFI firmware for x86_64, with Secure Boot and SMM",
+"interface-types": [
+"uefi"
+],
+"mapping": {
+"device": "flash",
+"executable": {
+"filename": "@DATADIR@/edk2-x86_64-secure-code.fd",
+"format": "raw"
+},
+"nvram-template": {
+"filename": "@DATADIR@/edk2-i386-vars.fd",
+"format": "raw"
+}
+},
+"targets": [
+{
+"architecture": "x86_64",
+"machines": [
+"pc-q35-*"
+]
+}
+],
+"features": [
+"acpi-s3",
+"amd-sev",
+"requires-smm",
+"secure-boot",
+"verbose-dynamic"
+],
+"tags": [
+
+]
+}
diff --git a/pc-bios/descriptors/60-edk2-aarch64.json 
b/pc-bios/descriptors/60-edk2-aarch64.json
new file mode 100644
index ..800a21bda691
--- /dev/null
+++ b/pc-bios/descriptors/60-edk2-aarch64.json
@@ -0,0 +1,31 @@
+{
+"description": "UEFI firmware for aarch64",
+"interface-types": [
+"uefi"
+],
+"mapping": {
+"device": "flash",
+"executable": {
+"filename": "@DATADIR@/edk2-aarch64-code.fd",
+"format": "raw"
+},
+"nvram-template": {
+"filename": "@DATADIR@/edk2-arm-vars.fd",
+"format": "raw"
+}
+},
+"targets": [
+{
+"architecture": "aarch64",
+"machines": [
+"virt-*"
+]
+}
+],
+"features": [
+"verbose-static"
+],
+"tags": [
+
+]
+}
diff --git a/pc-bios/descriptors/60-edk2-arm.json 
b/pc-bios/descriptors/60-edk2-arm.json
new file mode 100644
index ..d5f1bba6cc82
--- /dev/null
+++ b/pc-bios/descriptors/60-edk2-arm.json
@@ -0,0 +1,31 @@
+{
+"description": "UEFI firmware for arm",
+"interface-types": [
+"uefi"
+],
+"mapping": {
+"device": "flash",
+"executable": {
+"filename": "@DATADIR@/edk2-arm-code.fd",
+"format": "raw"
+},
+"nvram-template": {
+"filename": "@DATADIR@/edk2-arm-vars.fd",
+"format": "raw"
+}
+},
+"targets": [
+{
+"architecture": "arm",
+"machines": [
+"virt-*"
+]
+}
+],
+"features": [
+"verbose-static"
+],
+"tags": [
+
+]
+}
diff --git a/pc-bios/descriptors/60-edk2-i386.json 
b/pc-bios/descriptors/60-edk2-i386.json
new file mode 100644
index ..2f8dec74fecb
--- /dev/null
+++ b/pc-bios/descriptors/60-edk2-i386.json
@@ -0,0 +1,33 @@
+{
+"description": "UEFI firmware for i386",
+"interface-types": [
+"uefi"
+],
+"mapping": {
+"device": "flash",
+"executable": {
+"filename": "@DATADIR@/edk2-i386-code.fd",
+"format": "raw"
+},
+"nvram-template": {
+"filename": "@DATADIR@/edk2-i386-v

[Qemu-devel] [PATCH 02/10] roms/edk2-funcs.sh: require gcc-4.8+ for building i386 and x86_64

2019-03-08 Thread Laszlo Ersek
Adapt the qemu_edk2_get_toolchain() function in "roms/edk2-funcs.sh" in
advance to edk2 commit 8d7cdfae8cb8 ("OvmfPkg: require GCC48 or later",
2019-01-08), which is part of the "edk2-stable201903" tag.

Signed-off-by: Laszlo Ersek 
---
 roms/edk2-funcs.sh | 14 +-
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/roms/edk2-funcs.sh b/roms/edk2-funcs.sh
index 908c7665c6ed..22a5dc8f6ab6 100644
--- a/roms/edk2-funcs.sh
+++ b/roms/edk2-funcs.sh
@@ -149,23 +149,11 @@ qemu_edk2_get_toolchain()
   # Run "git-blame" on "OvmfPkg/build.sh" in edk2 for more information on
   # the mapping below.
   case "$gcc_version" in
-([1-3].*|4.[0-3].*)
+([1-3].*|4.[0-7].*)
   printf '%s: unsupported gcc version "%s"\n' \
 "$program_name" "$gcc_version" >&2
   return 1
   ;;
-(4.4.*)
-  printf 'GCC44\n'
-  ;;
-(4.5.*)
-  printf 'GCC45\n'
-  ;;
-(4.6.*)
-  printf 'GCC46\n'
-  ;;
-(4.7.*)
-  printf 'GCC47\n'
-  ;;
 (4.8.*)
   printf 'GCC48\n'
   ;;
-- 
2.19.1.3.g30247aa5d201





[Qemu-devel] [PATCH 03/10] tests/uefi-test-tools/build.sh: work around TianoCore#1607

2019-03-08 Thread Laszlo Ersek
The edk2-stabe201903 release introduced Python3 support to edk2's
BaseTools; however the Python3 enablement breaks in a corner case (which
is nevertheless supported by the edk2 community), namely the in-module
parallelization that we utilize.

This is tracked under
. For now, work
around the issue (in advance) by forcing Python2. (The workaround is a
no-op before we move to edk2-stabe201903 in the roms/edk2 submodule.)

Signed-off-by: Laszlo Ersek 
---
 tests/uefi-test-tools/build.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/uefi-test-tools/build.sh b/tests/uefi-test-tools/build.sh
index e2b52c855c39..8aa7935c43bb 100755
--- a/tests/uefi-test-tools/build.sh
+++ b/tests/uefi-test-tools/build.sh
@@ -29,6 +29,9 @@ export PACKAGES_PATH=$(realpath -- "$edk2_dir")
 export WORKSPACE=$PWD
 mkdir -p Conf
 
+# Work around .
+export PYTHON_COMMAND=python2
+
 # Source "edksetup.sh" carefully.
 set +e +u +C
 source "$PACKAGES_PATH/edksetup.sh"
-- 
2.19.1.3.g30247aa5d201





[Qemu-devel] [PATCH 00/10] bundle edk2 platform firmware with QEMU

2019-03-08 Thread Laszlo Ersek
Repo:   https://github.com/lersek/qemu.git
Branch: edk2_build

This series advances the roms/edk2 submodule to the "edk2-stable201903"
release, and builds and captures platform firmware binaries from that
release. At this point they are meant to be used by both end-users and
by Igor's ACPI unit tests in qtest ("make check").

Previous discussion:

  [Qemu-devel] bundling edk2 platform firmware images with QEMU
  80f0bae3-e79a-bb68-04c4-1c9c684d95b8@redhat.com">http://mid.mail-archive.com/80f0bae3-e79a-bb68-04c4-1c9c684d95b8@redhat.com
  https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg02601.html

Note that the series was formatted with "--no-binary" (affecting patch
#8), therefore it cannot be applied with "git-am". See the remote
repo/branch reference near the top instead.

Thanks,
Laszlo

Laszlo Ersek (10):
  roms: lift "edk2-funcs.sh" from "tests/uefi-test-tools/build.sh"
  roms/edk2-funcs.sh: require gcc-4.8+ for building i386 and x86_64
  tests/uefi-test-tools/build.sh: work around TianoCore#1607
  roms/edk2: advance to tag edk2-stable201903
  roms/edk2-funcs.sh: add the qemu_edk2_get_thread_count() function
  roms/Makefile: replace the $(EFIROM) target with "edk2-basetools"
  roms: build edk2 firmware binaries and variable store templates
  pc-bios: add edk2 firmware binaries and variable store templates
  pc-bios: document the edk2 firmware images; add firmware descriptors
  Makefile: install the edk2 firmware images and their descriptors

 Makefile   |  17 +-
 pc-bios/README |  11 +
 pc-bios/descriptors/50-edk2-i386-secure.json   |  34 +++
 pc-bios/descriptors/50-edk2-x86_64-secure.json |  35 +++
 pc-bios/descriptors/60-edk2-aarch64.json   |  31 +++
 pc-bios/descriptors/60-edk2-arm.json   |  31 +++
 pc-bios/descriptors/60-edk2-i386.json  |  33 +++
 pc-bios/descriptors/60-edk2-x86_64.json|  34 +++
 pc-bios/edk2-aarch64-code.fd   | Bin 0 -> 67108864 bytes
 pc-bios/edk2-arm-code.fd   | Bin 0 -> 67108864 bytes
 pc-bios/edk2-arm-vars.fd   | Bin 0 -> 67108864 bytes
 pc-bios/edk2-i386-code.fd  | Bin 0 -> 3653632 bytes
 pc-bios/edk2-i386-secure-code.fd   | Bin 0 -> 3653632 bytes
 pc-bios/edk2-i386-vars.fd  | Bin 0 -> 540672 bytes
 pc-bios/edk2-licenses.txt  | 209 
 pc-bios/edk2-x86_64-code.fd| Bin 0 -> 3653632 bytes
 pc-bios/edk2-x86_64-secure-code.fd | Bin 0 -> 3653632 bytes
 roms/Makefile  |   9 +-
 roms/Makefile.edk2 | 138 +++
 roms/edk2  |   2 +-
 roms/edk2-build.sh |  55 +
 roms/edk2-funcs.sh | 253 
 tests/uefi-test-tools/build.sh | 100 +---
 23 files changed, 897 insertions(+), 95 deletions(-)
 create mode 100644 pc-bios/descriptors/50-edk2-i386-secure.json
 create mode 100644 pc-bios/descriptors/50-edk2-x86_64-secure.json
 create mode 100644 pc-bios/descriptors/60-edk2-aarch64.json
 create mode 100644 pc-bios/descriptors/60-edk2-arm.json
 create mode 100644 pc-bios/descriptors/60-edk2-i386.json
 create mode 100644 pc-bios/descriptors/60-edk2-x86_64.json
 create mode 100644 pc-bios/edk2-aarch64-code.fd
 create mode 100644 pc-bios/edk2-arm-code.fd
 create mode 100644 pc-bios/edk2-arm-vars.fd
 create mode 100644 pc-bios/edk2-i386-code.fd
 create mode 100644 pc-bios/edk2-i386-secure-code.fd
 create mode 100644 pc-bios/edk2-i386-vars.fd
 create mode 100644 pc-bios/edk2-licenses.txt
 create mode 100644 pc-bios/edk2-x86_64-code.fd
 create mode 100644 pc-bios/edk2-x86_64-secure-code.fd
 create mode 100644 roms/Makefile.edk2
 create mode 100755 roms/edk2-build.sh
 create mode 100644 roms/edk2-funcs.sh

-- 
2.19.1.3.g30247aa5d201




[Qemu-devel] [PATCH 01/10] roms: lift "edk2-funcs.sh" from "tests/uefi-test-tools/build.sh"

2019-03-08 Thread Laszlo Ersek
Extract the dense logic for architecture and toolchain massaging from
"tests/uefi-test-tools/build.sh", to a set of small functions. We'll reuse
these functions for building full platform firmware images.

Signed-off-by: Laszlo Ersek 
---
 roms/edk2-funcs.sh | 240 
 tests/uefi-test-tools/build.sh |  97 +---
 2 files changed, 246 insertions(+), 91 deletions(-)

diff --git a/roms/edk2-funcs.sh b/roms/edk2-funcs.sh
new file mode 100644
index ..908c7665c6ed
--- /dev/null
+++ b/roms/edk2-funcs.sh
@@ -0,0 +1,240 @@
+# Shell script that defines functions for determining some environmental
+# characteristics for the edk2 "build" utility.
+#
+# This script is meant to be sourced.
+#
+# Copyright (C) 2019, Red Hat, Inc.
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License that accompanies this
+# distribution. The full text of the license may be found at
+# .
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+
+# Verify whether the QEMU system emulation target is supported by the UEFI spec
+# and edk2. Print a message to the standard error, and return with nonzero
+# status, if verification fails.
+#
+# Parameters:
+#   $1: QEMU system emulation target
+qemu_edk2_verify_arch()
+{
+  local emulation_target="$1"
+  local program_name=$(basename -- "$0")
+
+  case "$emulation_target" in
+(arm|aarch64|i386|x86_64)
+  ;;
+(*)
+  printf '%s: unknown/unsupported QEMU system emulation target "%s"\n' \
+"$program_name" "$emulation_target" >&2
+  return 1
+  ;;
+  esac
+}
+
+
+# Translate the QEMU system emulation target to the edk2 architecture
+# identifier. Print the result to the standard output.
+#
+# Parameters:
+#   $1: QEMU system emulation target
+qemu_edk2_get_arch()
+{
+  local emulation_target="$1"
+
+  if ! qemu_edk2_verify_arch "$emulation_target"; then
+return 1
+  fi
+
+  case "$emulation_target" in
+(arm)
+  printf 'ARM\n'
+  ;;
+(aarch64)
+  printf 'AARCH64\n'
+  ;;
+(i386)
+  printf 'IA32\n'
+  ;;
+(x86_64)
+  printf 'X64\n'
+  ;;
+  esac
+}
+
+
+# Translate the QEMU system emulation target to the gcc cross-compilation
+# architecture identifier. Print the result to the standard output.
+#
+# Parameters:
+#   $1: QEMU system emulation target
+qemu_edk2_get_gcc_arch()
+{
+  local emulation_target="$1"
+
+  if ! qemu_edk2_verify_arch "$emulation_target"; then
+return 1
+  fi
+
+  case "$emulation_target" in
+(arm|aarch64|x86_64)
+  printf '%s\n' "$emulation_target"
+  ;;
+(i386)
+  printf 'i686\n'
+  ;;
+  esac
+}
+
+
+# Determine the gcc cross-compiler prefix (if any) for use with the edk2
+# toolchain. Print the result to the standard output.
+#
+# Parameters:
+#   $1: QEMU system emulation target
+qemu_edk2_get_cross_prefix()
+{
+  local emulation_target="$1"
+  local gcc_arch
+  local host_arch
+
+  if ! gcc_arch=$(qemu_edk2_get_gcc_arch "$emulation_target"); then
+return 1
+  fi
+
+  host_arch=$(uname -m)
+
+  if [ "$gcc_arch" == "$host_arch" ] ||
+ ( [ "$gcc_arch" == i686 ] && [ "$host_arch" == x86_64 ] ); then
+# no cross-compiler needed
+:
+  else
+printf '%s-linux-gnu-\n' "$gcc_arch"
+  fi
+}
+
+
+# Determine the edk2 toolchain tag for the QEMU system emulation target. Print
+# the result to the standard output. Print a message to the standard error, and
+# return with nonzero status, if the (conditional) gcc version check fails.
+#
+# Parameters:
+#   $1: QEMU system emulation target
+qemu_edk2_get_toolchain()
+{
+  local emulation_target="$1"
+  local program_name=$(basename -- "$0")
+  local cross_prefix
+  local gcc_version
+
+  if ! qemu_edk2_verify_arch "$emulation_target"; then
+return 1
+  fi
+
+  case "$emulation_target" in
+(arm|aarch64)
+  printf 'GCC5\n'
+  ;;
+
+(i386|x86_64)
+  if ! cross_prefix=$(qemu_edk2_get_cross_prefix "$emulation_target"); then
+return 1
+  fi
+
+  gcc_version=$("${cross_prefix}gcc" -v 2>&1 | tail -1 | awk '{print $3}')
+  # Run "git-blame" on "OvmfPkg/build.sh" in edk2 for more information on
+  # the mapping below.
+  case "$gcc_version" in
+([1-3].*|4.[0-3].*)
+  printf '%s: unsupported gcc version "%s"\n' \
+"$program_name" "$gcc_version" >&2
+  return 1
+  ;;
+(4.4.*)
+  printf 'GCC44\n'
+  ;;
+(4.5.*)
+  printf 'GCC45\n'
+  ;;
+(4.6.*)
+  printf 'GCC46\n'
+  ;;
+(4.7.*)
+  printf 'GCC47\n'
+  ;;
+(4.8.*)
+  printf 'GCC48\n'
+  ;;
+(4.9.*|6.[0-2].*)
+  printf 'GCC49\n'
+  ;;
+(*)
+  printf 'GCC5\n

Re: [Qemu-devel] [Qemu-arm] [PATCH 9/9] target/arm: Simplify BFXIL expansion

2019-03-08 Thread Philippe Mathieu-Daudé
On 3/7/19 3:41 PM, Richard Henderson wrote:
> The mask implied by the extract is redundant with the one
> implied by the deposit.  Also, fix spelling of BFXIL.

This spelling fix also help understanding the context!

> 
> Cc: qemu-...@nongnu.org 
> Cc: Peter Maydell  
> Signed-off-by: Richard Henderson 
> ---
>  target/arm/translate-a64.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
> index 54fe94c436..39e0512d21 100644
> --- a/target/arm/translate-a64.c
> +++ b/target/arm/translate-a64.c
> @@ -4043,8 +4043,8 @@ static void disas_bitfield(DisasContext *s, uint32_t 
> insn)
>  tcg_gen_extract_i64(tcg_rd, tcg_tmp, ri, len);
>  return;
>  }
> -/* opc == 1, BXFIL fall through to deposit */
> -tcg_gen_extract_i64(tcg_tmp, tcg_tmp, ri, len);
> +/* opc == 1, BFXIL fall through to deposit */
> +tcg_gen_shri_i64(tcg_tmp, tcg_tmp, ri);
>  pos = 0;
>  } else {
>  /* Handle the ri > si case with a deposit
> @@ -4062,7 +4062,7 @@ static void disas_bitfield(DisasContext *s, uint32_t 
> insn)
>  len = ri;
>  }
>  
> -if (opc == 1) { /* BFM, BXFIL */
> +if (opc == 1) { /* BFM, BFXIL */
>  tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, pos, len);

Fall through and use deposit of len indeed. So the previous SHRI is enough.

Reviewed-by: Philippe Mathieu-Daudé 

This function uses hardcore optimizations btw, un chef d'oeuvre :)

>  } else {
>  /* SBFM or UBFM: We start with zero, and we haven't modified
> 



Re: [Qemu-devel] [PATCH 4/9] tcg: Use extract2 in tcg_gen_deposit_{i32, i64}

2019-03-08 Thread Philippe Mathieu-Daudé
On 3/7/19 3:41 PM, Richard Henderson wrote:
> Signed-off-by: Richard Henderson 
> ---
>  tcg/tcg-op.c | 28 ++--
>  1 file changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 34e0dbc6e0..caee80235e 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -614,6 +614,18 @@ void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, 
> TCGv_i32 arg2,
>  mask = (1u << len) - 1;

FWIW you can move 'mask' ...

>  t1 = tcg_temp_new_i32();
>  
> +if (TCG_TARGET_HAS_extract2_i32) {
> +if (ofs + len == 32) {
> +tcg_gen_shli_i32(t1, arg1, len);
> +tcg_gen_extract2_i32(ret, t1, arg2, len);
> +goto done;
> +}
> +if (ofs == 0) {
> +tcg_gen_extract2_i32(ret, arg1, arg2, len);
> +tcg_gen_rotli_i32(ret, ret, len);
> +goto done;
> +}
> +}

... here, saving few instr if TCG_TARGET_HAS_extract2_i32 ;)

>  if (ofs + len < 32) {
>  tcg_gen_andi_i32(t1, arg2, mask);
>  tcg_gen_shli_i32(t1, t1, ofs);
> @@ -622,7 +634,7 @@ void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, 
> TCGv_i32 arg2,
>  }
>  tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
>  tcg_gen_or_i32(ret, ret, t1);
> -
> + done:
>  tcg_temp_free_i32(t1);
>  }
>  
> @@ -2027,6 +2039,18 @@ void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, 
> TCGv_i64 arg2,
>  mask = (1ull << len) - 1;
>  t1 = tcg_temp_new_i64();
>  
> +if (TCG_TARGET_HAS_extract2_i64) {
> +if (ofs + len == 64) {
> +tcg_gen_shli_i64(t1, arg1, len);
> +tcg_gen_extract2_i64(ret, t1, arg2, len);
> +goto done;
> +}
> +if (ofs == 0) {
> +tcg_gen_extract2_i64(ret, arg1, arg2, len);
> +tcg_gen_rotli_i64(ret, ret, len);
> +goto done;
> +}
> +}

Ditto.

>  if (ofs + len < 64) {
>  tcg_gen_andi_i64(t1, arg2, mask);
>  tcg_gen_shli_i64(t1, t1, ofs);
> @@ -2035,7 +2059,7 @@ void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, 
> TCGv_i64 arg2,
>  }
>  tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
>  tcg_gen_or_i64(ret, ret, t1);
> -
> + done:
>  tcg_temp_free_i64(t1);
>  }
>  
> 



Re: [Qemu-devel] [PATCH 4/5] block/qcow2-bitmap: Allow resizes with persistent bitmaps

2019-03-08 Thread John Snow



On 3/6/19 10:52 AM, Vladimir Sementsov-Ogievskiy wrote:
> 06.03.2019 18:41, John Snow wrote:
>>
>>
>> On 3/6/19 10:33 AM, Vladimir Sementsov-Ogievskiy wrote:
>>> 06.03.2019 2:43, John Snow wrote:
 Since we now load all bitmaps into memory anyway, we can just truncate them
 in-memory and then flush them back to disk. Just in case, we will still 
 check
 and enforce that this shortcut is valid -- i.e. that any bitmap described
 on-disk is indeed in-memory and can be modified.

 If there are any inconsistent bitmaps, we refuse to allow the truncate as
 we do not actually load these bitmaps into memory, and it isn't safe or
 reasonable to attempt to truncate corrupted data.

 Signed-off-by: John Snow 
 ---
block/qcow2.h|  1 +
block/qcow2-bitmap.c | 42 ++
block/qcow2.c| 27 ---
3 files changed, 63 insertions(+), 7 deletions(-)

 diff --git a/block/qcow2.h b/block/qcow2.h
 index 4c1fdfcbec..b9227a72cc 100644
 --- a/block/qcow2.h
 +++ b/block/qcow2.h
 @@ -689,6 +689,7 @@ Qcow2BitmapInfoList 
 *qcow2_get_bitmap_info_list(BlockDriverState *bs,
int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool 
 *header_updated,
 Error **errp);
int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
 +int qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp);
void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error 
 **errp);
void qcow2_flush_persistent_dirty_bitmaps(BlockDriverState *bs, Error 
 **errp);
int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp);
 diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
 index 9373055d3b..24f280bccc 100644
 --- a/block/qcow2-bitmap.c
 +++ b/block/qcow2-bitmap.c
 @@ -1167,6 +1167,48 @@ int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, 
 Error **errp)
return qcow2_reopen_bitmaps_rw_hint(bs, NULL, errp);
}

 +/* Checks to see if it's safe to resize bitmaps */
 +int qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp)
 +{
 +BDRVQcow2State *s = bs->opaque;
 +Qcow2BitmapList *bm_list;
 +Qcow2Bitmap *bm;
 +int ret = 0;
 +
 +if (s->nb_bitmaps == 0) {
 +return 0;
 +}
 +
 +bm_list = bitmap_list_load(bs, s->bitmap_directory_offset,
 +   s->bitmap_directory_size, false, errp);
 +if (bm_list == NULL) {
 +return -EINVAL;
 +}
 +
 +QSIMPLEQ_FOREACH(bm, bm_list, entry) {
 +BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(bs, bm->name);
 +if (bitmap == NULL) {
 +/* We rely on all bitmaps being in-memory to be able to 
 resize them,
 + * Otherwise, we'd need to resize them on disk explicitly */
 +error_setg(errp, "Cannot resize qcow2 with persistent bitmaps 
 that "
 +   "were not loaded into memory");
 +ret = -ENOTSUP;
 +goto out;
 +}
 +
 +/* The checks against readonly and busy are redundant, but 
 certainly
 + * do no harm. checks against inconsistent are crucial: */
 +if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) {
 +ret = -ENOTSUP;
 +goto out;
 +}
 +}
 +
 +out:
 +bitmap_list_free(bm_list);
 +return ret;
 +}
 +
/* store_bitmap_data()
 * Store bitmap to image, filling bitmap table accordingly.
 */
 diff --git a/block/qcow2.c b/block/qcow2.c
 index 7fb2730f09..6fd9252494 100644
 --- a/block/qcow2.c
 +++ b/block/qcow2.c
 @@ -3472,7 +3472,7 @@ static int coroutine_fn 
 qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
{
BDRVQcow2State *s = bs->opaque;
uint64_t old_length;
 -int64_t new_l1_size;
 +int64_t new_l1_size, offset_be;
int ret;
QDict *options;

 @@ -3498,10 +3498,8 @@ static int coroutine_fn 
 qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
goto fail;
}

 -/* cannot proceed if image has bitmaps */
 -if (s->nb_bitmaps) {
 -/* TODO: resize bitmaps in the image */
 -error_setg(errp, "Can't resize an image which has bitmaps");
 +/* Only certain persistent bitmaps can be resized: */
 +if (qcow2_truncate_bitmaps_check(bs, errp)) {
ret = -ENOTSUP;
goto fail;
}
 @@ -3702,9 +3700,9 @@ static int coroutine_fn 
 qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
   

Re: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

2019-03-08 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20190307144126.31847-1-richard.hender...@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190307144126.31847-1-richard.hender...@linaro.org
Subject: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]
patchew/20190307144126.31847-1-richard.hender...@linaro.org -> 
patchew/20190307144126.31847-1-richard.hender...@linaro.org
Switched to a new branch 'test'
fd5c8534d8 target/arm: Simplify BFXIL expansion
ff97eff064 target/arm: Use extract2 for EXTR
14907a5cdf tcg/aarch64: Support INDEX_op_extract2_{i32, i64}
571ce62802 tcg/arm: Support INDEX_op_extract2_i32
47322e4359 tcg/i386: Support INDEX_op_extract2_{i32, i64}
71c243e0b1 tcg: Use extract2 in tcg_gen_deposit_{i32, i64}
7f01d6944a tcg: Use extract2 in tcg_gen_shifti_i64
6040cdd72c tcg: Add INDEX_op_extract2_{i32,i64}
fd5a59c277 tcg: Implement tcg_gen_extract2_{i32, i64}

=== OUTPUT BEGIN ===
1/9 Checking commit fd5a59c277d1 (tcg: Implement tcg_gen_extract2_{i32, i64})
2/9 Checking commit 6040cdd72c14 (tcg: Add INDEX_op_extract2_{i32,i64})
ERROR: spaces required around that ':' (ctx:VxE)
#109: FILE: tcg/optimize.c:1205:
+CASE_OP_32_64(extract2):
^

total: 1 errors, 0 warnings, 199 lines checked

Patch 2/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

3/9 Checking commit 7f01d6944a7a (tcg: Use extract2 in tcg_gen_shifti_i64)
4/9 Checking commit 71c243e0b1d7 (tcg: Use extract2 in tcg_gen_deposit_{i32, 
i64})
5/9 Checking commit 47322e435956 (tcg/i386: Support INDEX_op_extract2_{i32, 
i64})
ERROR: spaces required around that ':' (ctx:VxE)
#48: FILE: tcg/i386/tcg-target.inc.c:2591:
+OP_32_64(extract2):
   ^

total: 1 errors, 0 warnings, 51 lines checked

Patch 5/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

6/9 Checking commit 571ce62802b8 (tcg/arm: Support INDEX_op_extract2_i32)
7/9 Checking commit 14907a5cdf13 (tcg/aarch64: Support INDEX_op_extract2_{i32, 
i64})
8/9 Checking commit ff97eff06477 (target/arm: Use extract2 for EXTR)
9/9 Checking commit fd5c8534d847 (target/arm: Simplify BFXIL expansion)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190307144126.31847-1-richard.hender...@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH 6/9] tcg/arm: Support INDEX_op_extract2_i32

2019-03-08 Thread Philippe Mathieu-Daudé
On 3/7/19 3:41 PM, Richard Henderson wrote:
> Signed-off-by: Richard Henderson 
> ---
>  tcg/arm/tcg-target.h |  2 +-
>  tcg/arm/tcg-target.inc.c | 25 +
>  2 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
> index 4ee6c98958..17e771374d 100644
> --- a/tcg/arm/tcg-target.h
> +++ b/tcg/arm/tcg-target.h
> @@ -116,7 +116,7 @@ extern bool use_idiv_instructions;
>  #define TCG_TARGET_HAS_deposit_i32  use_armv7_instructions
>  #define TCG_TARGET_HAS_extract_i32  use_armv7_instructions
>  #define TCG_TARGET_HAS_sextract_i32 use_armv7_instructions
> -#define TCG_TARGET_HAS_extract2_i32 0
> +#define TCG_TARGET_HAS_extract2_i32 1
>  #define TCG_TARGET_HAS_movcond_i32  1
>  #define TCG_TARGET_HAS_mulu2_i321
>  #define TCG_TARGET_HAS_muls2_i321
> diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c
> index 2245a8aeb9..6873b0cf95 100644
> --- a/tcg/arm/tcg-target.inc.c
> +++ b/tcg/arm/tcg-target.inc.c
> @@ -2064,6 +2064,27 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode 
> opc,
>  case INDEX_op_sextract_i32:
>  tcg_out_sextract(s, COND_AL, args[0], args[1], args[2], args[3]);
>  break;
> +case INDEX_op_extract2_i32:
> +/* ??? These optimization vs zero should be generic.  */
> +/* ??? But we can't substitute 2 for 1 in the opcode stream yet.  */
> +if (const_args[1]) {
> +if (const_args[2]) {
> +tcg_out_movi(s, TCG_TYPE_REG, args[0], 0);
> +} else {
> +tcg_out_dat_reg(s, COND_AL, ARITH_MOV, args[0], 0,
> +args[2], SHIFT_IMM_LSL(32 - args[3]));
> +}
> +} else if (const_args[2]) {
> +tcg_out_dat_reg(s, COND_AL, ARITH_MOV, args[0], 0,
> +args[1], SHIFT_IMM_LSR(args[3]));
> +} else {
> +/* We can do extract2 in 2 insns, vs the 3 required otherwise.  
> */
> +tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP, 0,
> +args[2], SHIFT_IMM_LSL(32 - args[3]));
> +tcg_out_dat_reg(s, COND_AL, ARITH_ORR, args[0], TCG_REG_TMP,
> +args[1], SHIFT_IMM_LSR(args[3]));
> +}

Reviewed-by: Philippe Mathieu-Daudé 

> +break;
>  
>  case INDEX_op_div_i32:
>  tcg_out_sdiv(s, COND_AL, args[0], args[1], args[2]);
> @@ -2108,6 +2129,8 @@ static const TCGTargetOpDef 
> *tcg_target_op_def(TCGOpcode op)
>  = { .args_ct_str = { "s", "s", "s", "s" } };
>  static const TCGTargetOpDef br
>  = { .args_ct_str = { "r", "rIN" } };
> +static const TCGTargetOpDef ext2
> += { .args_ct_str = { "r", "rZ", "rZ" } };
>  static const TCGTargetOpDef dep
>  = { .args_ct_str = { "r", "0", "rZ" } };
>  static const TCGTargetOpDef movc
> @@ -2174,6 +2197,8 @@ static const TCGTargetOpDef 
> *tcg_target_op_def(TCGOpcode op)
>  return &br;
>  case INDEX_op_deposit_i32:
>  return &dep;
> +case INDEX_op_extract2_i32:
> +return &ext2;
>  case INDEX_op_movcond_i32:
>  return &movc;
>  case INDEX_op_add2_i32:
> 



Re: [Qemu-devel] [PATCH v5 1/2] Add generic Nios II board.

2019-03-08 Thread Sandra Loosemore

On 3/7/19 7:57 AM, Peter Maydell wrote:

diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c
index 5f0ab2f..c697047 100644
--- a/hw/nios2/boot.c
+++ b/hw/nios2/boot.c
@@ -140,6 +140,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
  uint64_t entry, low, high;
  uint32_t base32;
  int big_endian = 0;
+int kernel_space = 0;

  #ifdef TARGET_WORDS_BIGENDIAN
  big_endian = 1;
@@ -155,10 +156,12 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
 translate_kernel_address, NULL,
 &entry, NULL, NULL,
 big_endian, EM_ALTERA_NIOS2, 0, 0);
+kernel_space = 1;
  }

  /* Always boot into physical ram. */
-boot_info.bootstrap_pc = ddr_base + 0xc000 + (entry & 0x07ff);
+boot_info.bootstrap_pc = ddr_base + (kernel_space ? 0xc000 : 0)
+ + (entry & 0x07ff);


It's not clear to me what's going on here, or why an
entry address of 0xc000_ is special, but I don't
know anything about NiosII -- maybe it's clear if you do?


The processor reference guide documents that the kernel is placed at 
virtual memory address 0xc000.


https://www.intel.com/content/www/us/en/programmable/documentation/iga1409256728501.html#iga1409332620358

The problem the patch to boot.c is trying to solve is that we found 
things like unwind info were screwed up when using -kernel to load 
executables with an entry address other than 0xc000.



Why isn't the bootstrap_pc just always the entry address ?
Some comments on what is being done here and the use cases
being addressed might assist. I wasn't able to work out what
the remarks in the commit message meant, I'm afraid.

Looking at the code, I don't think that the second call to
load_elf() will return a different entry address to the first
one (ie translate_kernel_address() is not applied to &entry).
That means that kernel_space is only true if entry == 0xc000,
and
   (kernel_space ? 0xc000 : 0) + (entry & 0x07ff);
is almost the same thing as just 'entry'.


It seems like these remarks are directed more at the existing code than 
the patch  :-S  TBH, I don't know why it was done that way originally.





+static void nios2_generic_nommu_init(MachineState *machine)
+{
+Nios2CPU *cpu;
+DeviceState *dev;
+MemoryRegion *address_space_mem = get_system_memory();
+MemoryRegion *phys_tcm = g_new(MemoryRegion, 1);
+MemoryRegion *phys_tcm_alias = g_new(MemoryRegion, 1);
+MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
+MemoryRegion *phys_ram_alias = g_new(MemoryRegion, 1);
+ram_addr_t tcm_base = 0x0;
+ram_addr_t tcm_size = 0x1000;/* 1 kiB, but QEMU limit is 4 kiB */
+ram_addr_t ram_base = 0x1000;
+ram_addr_t ram_size = 0x0800;
+qemu_irq *cpu_irq, irq[32];
+int i;


The description says this is "generic", but it appears to
be almost identical to the existing 10M50 board model,
including having exactly the same devices at the same
apparently arbitrary addresses.

Could we instead add a machine parameter to the existing
board so you could say "-machine 10m50-ghrd,mmu=no"
(and drop the other changes -- it's not clear what they're
needed for) ?

If it really ought to be a separate board model, perhaps
it should be in the same source file and share the common
code.


I didn't write this code, but the intent was actually to allow 
executables linked for the 3c120 devboards we'd been using for hardware 
testing to run in this emulation; not to emulate a mmu-less 10m50 board. 
 The BSP that we contributed to libgloss locates the reset vector, etc 
appropriately for this emulation.


I can't comment on whether the peripherals copied from the 10m50 
emulation are actually necessary or useful for anything; we certainly 
don't intend to support manipulating them from the program being loaded, 
but maybe other parts of QEMU expect certain devices to be present (I've 
seen that on other targets like ARM).  Andrew, do you have any state on 
this left?


-Sandra



Re: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

2019-03-08 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20190307144126.31847-1-richard.hender...@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190307144126.31847-1-richard.hender...@linaro.org
Subject: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]
patchew/20190307144126.31847-1-richard.hender...@linaro.org -> 
patchew/20190307144126.31847-1-richard.hender...@linaro.org
Switched to a new branch 'test'
3898cccde9 target/arm: Simplify BFXIL expansion
2ada5d316c target/arm: Use extract2 for EXTR
49b4870227 tcg/aarch64: Support INDEX_op_extract2_{i32, i64}
92cd638e55 tcg/arm: Support INDEX_op_extract2_i32
9b93a7bdeb tcg/i386: Support INDEX_op_extract2_{i32, i64}
d5d7cc7750 tcg: Use extract2 in tcg_gen_deposit_{i32, i64}
67a6356446 tcg: Use extract2 in tcg_gen_shifti_i64
17714e10e2 tcg: Add INDEX_op_extract2_{i32,i64}
c7936c5b94 tcg: Implement tcg_gen_extract2_{i32, i64}

=== OUTPUT BEGIN ===
1/9 Checking commit c7936c5b9404 (tcg: Implement tcg_gen_extract2_{i32, i64})
2/9 Checking commit 17714e10e223 (tcg: Add INDEX_op_extract2_{i32,i64})
ERROR: spaces required around that ':' (ctx:VxE)
#109: FILE: tcg/optimize.c:1205:
+CASE_OP_32_64(extract2):
^

total: 1 errors, 0 warnings, 199 lines checked

Patch 2/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

3/9 Checking commit 67a63564468a (tcg: Use extract2 in tcg_gen_shifti_i64)
4/9 Checking commit d5d7cc7750e3 (tcg: Use extract2 in tcg_gen_deposit_{i32, 
i64})
5/9 Checking commit 9b93a7bdebcd (tcg/i386: Support INDEX_op_extract2_{i32, 
i64})
ERROR: spaces required around that ':' (ctx:VxE)
#48: FILE: tcg/i386/tcg-target.inc.c:2591:
+OP_32_64(extract2):
   ^

total: 1 errors, 0 warnings, 51 lines checked

Patch 5/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

6/9 Checking commit 92cd638e55c0 (tcg/arm: Support INDEX_op_extract2_i32)
7/9 Checking commit 49b4870227e8 (tcg/aarch64: Support INDEX_op_extract2_{i32, 
i64})
8/9 Checking commit 2ada5d316ccb (target/arm: Use extract2 for EXTR)
9/9 Checking commit 3898cccde939 (target/arm: Simplify BFXIL expansion)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190307144126.31847-1-richard.hender...@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH 7/9] tcg/aarch64: Support INDEX_op_extract2_{i32, i64}

2019-03-08 Thread Philippe Mathieu-Daudé
On 3/7/19 3:41 PM, Richard Henderson wrote:
> Signed-off-by: Richard Henderson 
> ---
>  tcg/aarch64/tcg-target.h |  4 ++--
>  tcg/aarch64/tcg-target.inc.c | 11 +++
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h
> index 6600a54a02..ce2bb1f90b 100644
> --- a/tcg/aarch64/tcg-target.h
> +++ b/tcg/aarch64/tcg-target.h
> @@ -77,7 +77,7 @@ typedef enum {
>  #define TCG_TARGET_HAS_deposit_i32  1
>  #define TCG_TARGET_HAS_extract_i32  1
>  #define TCG_TARGET_HAS_sextract_i32 1
> -#define TCG_TARGET_HAS_extract2_i32 0
> +#define TCG_TARGET_HAS_extract2_i32 1
>  #define TCG_TARGET_HAS_movcond_i32  1
>  #define TCG_TARGET_HAS_add2_i32 1
>  #define TCG_TARGET_HAS_sub2_i32 1
> @@ -114,7 +114,7 @@ typedef enum {
>  #define TCG_TARGET_HAS_deposit_i64  1
>  #define TCG_TARGET_HAS_extract_i64  1
>  #define TCG_TARGET_HAS_sextract_i64 1
> -#define TCG_TARGET_HAS_extract2_i64 0
> +#define TCG_TARGET_HAS_extract2_i64 1
>  #define TCG_TARGET_HAS_movcond_i64  1
>  #define TCG_TARGET_HAS_add2_i64 1
>  #define TCG_TARGET_HAS_sub2_i64 1
> diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c
> index d57f9e500f..8b93598bce 100644
> --- a/tcg/aarch64/tcg-target.inc.c
> +++ b/tcg/aarch64/tcg-target.inc.c
> @@ -2058,6 +2058,11 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
>  tcg_out_sbfm(s, ext, a0, a1, a2, a2 + args[3] - 1);
>  break;
>  
> +case INDEX_op_extract2_i64:
> +case INDEX_op_extract2_i32:
> +tcg_out_extr(s, ext, a0, a1, a2, args[3]);

EXTR a0, a1, a2, #args[3] ; OK

Reviewed-by: Philippe Mathieu-Daudé 

> +break;
> +
>  case INDEX_op_add2_i32:
>  tcg_out_addsub2(s, TCG_TYPE_I32, a0, a1, REG0(2), REG0(3),
>  (int32_t)args[4], args[5], const_args[4],
> @@ -2300,6 +2305,8 @@ static const TCGTargetOpDef 
> *tcg_target_op_def(TCGOpcode op)
>  = { .args_ct_str = { "r", "r", "rAL" } };
>  static const TCGTargetOpDef dep
>  = { .args_ct_str = { "r", "0", "rZ" } };
> +static const TCGTargetOpDef ext2
> += { .args_ct_str = { "r", "rZ", "rZ" } };
>  static const TCGTargetOpDef movc
>  = { .args_ct_str = { "r", "r", "rA", "rZ", "rZ" } };
>  static const TCGTargetOpDef add2
> @@ -2430,6 +2437,10 @@ static const TCGTargetOpDef 
> *tcg_target_op_def(TCGOpcode op)
>  case INDEX_op_deposit_i64:
>  return &dep;
>  
> +case INDEX_op_extract2_i32:
> +case INDEX_op_extract2_i64:
> +return &ext2;
> +
>  case INDEX_op_add2_i32:
>  case INDEX_op_add2_i64:
>  case INDEX_op_sub2_i32:
> 



Re: [Qemu-devel] [PATCH 2/9] tcg: Add INDEX_op_extract2_{i32,i64}

2019-03-08 Thread Philippe Mathieu-Daudé
Hi Richard,

On 3/7/19 3:41 PM, Richard Henderson wrote:
> This will let backends implement the double-word shift operation.
> 
> Signed-off-by: Richard Henderson 
> ---
>  tcg/aarch64/tcg-target.h |  2 ++
>  tcg/arm/tcg-target.h |  1 +
>  tcg/i386/tcg-target.h|  2 ++
>  tcg/mips/tcg-target.h|  2 ++
>  tcg/ppc/tcg-target.h |  2 ++
>  tcg/riscv/tcg-target.h   |  2 ++
>  tcg/s390/tcg-target.h|  2 ++
>  tcg/sparc/tcg-target.h   |  2 ++
>  tcg/tcg-opc.h|  2 ++
>  tcg/tcg.h|  1 +
>  tcg/tci/tcg-target.h |  2 ++
>  tcg/optimize.c   | 10 ++
>  tcg/tcg-op.c |  4 
>  tcg/tcg.c|  4 
>  tcg/README   |  5 +
>  15 files changed, 43 insertions(+)
> 
> diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h
> index 2d93cf404e..6600a54a02 100644
> --- a/tcg/aarch64/tcg-target.h
> +++ b/tcg/aarch64/tcg-target.h
> @@ -77,6 +77,7 @@ typedef enum {
>  #define TCG_TARGET_HAS_deposit_i32  1
>  #define TCG_TARGET_HAS_extract_i32  1
>  #define TCG_TARGET_HAS_sextract_i32 1
> +#define TCG_TARGET_HAS_extract2_i32 0
>  #define TCG_TARGET_HAS_movcond_i32  1
>  #define TCG_TARGET_HAS_add2_i32 1
>  #define TCG_TARGET_HAS_sub2_i32 1
> @@ -113,6 +114,7 @@ typedef enum {
>  #define TCG_TARGET_HAS_deposit_i64  1
>  #define TCG_TARGET_HAS_extract_i64  1
>  #define TCG_TARGET_HAS_sextract_i64 1
> +#define TCG_TARGET_HAS_extract2_i64 0
>  #define TCG_TARGET_HAS_movcond_i64  1
>  #define TCG_TARGET_HAS_add2_i64 1
>  #define TCG_TARGET_HAS_sub2_i64 1
> diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
> index 16172f73a3..4ee6c98958 100644
> --- a/tcg/arm/tcg-target.h
> +++ b/tcg/arm/tcg-target.h
> @@ -116,6 +116,7 @@ extern bool use_idiv_instructions;
>  #define TCG_TARGET_HAS_deposit_i32  use_armv7_instructions
>  #define TCG_TARGET_HAS_extract_i32  use_armv7_instructions
>  #define TCG_TARGET_HAS_sextract_i32 use_armv7_instructions
> +#define TCG_TARGET_HAS_extract2_i32 0
>  #define TCG_TARGET_HAS_movcond_i32  1
>  #define TCG_TARGET_HAS_mulu2_i321
>  #define TCG_TARGET_HAS_muls2_i321
> diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h
> index 7995fe3eab..2c58eaa9ed 100644
> --- a/tcg/i386/tcg-target.h
> +++ b/tcg/i386/tcg-target.h
> @@ -124,6 +124,7 @@ extern bool have_avx2;
>  #define TCG_TARGET_HAS_deposit_i32  1
>  #define TCG_TARGET_HAS_extract_i32  1
>  #define TCG_TARGET_HAS_sextract_i32 1
> +#define TCG_TARGET_HAS_extract2_i32 0
>  #define TCG_TARGET_HAS_movcond_i32  1
>  #define TCG_TARGET_HAS_add2_i32 1
>  #define TCG_TARGET_HAS_sub2_i32 1
> @@ -162,6 +163,7 @@ extern bool have_avx2;
>  #define TCG_TARGET_HAS_deposit_i64  1
>  #define TCG_TARGET_HAS_extract_i64  1
>  #define TCG_TARGET_HAS_sextract_i64 0
> +#define TCG_TARGET_HAS_extract2_i64 0
>  #define TCG_TARGET_HAS_movcond_i64  1
>  #define TCG_TARGET_HAS_add2_i64 1
>  #define TCG_TARGET_HAS_sub2_i64 1
> diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h
> index 5cb8672470..c6b091d849 100644
> --- a/tcg/mips/tcg-target.h
> +++ b/tcg/mips/tcg-target.h
> @@ -162,6 +162,7 @@ extern bool use_mips32r2_instructions;
>  #define TCG_TARGET_HAS_deposit_i32  use_mips32r2_instructions
>  #define TCG_TARGET_HAS_extract_i32  use_mips32r2_instructions
>  #define TCG_TARGET_HAS_sextract_i32 0
> +#define TCG_TARGET_HAS_extract2_i32 0
>  #define TCG_TARGET_HAS_ext8s_i32use_mips32r2_instructions
>  #define TCG_TARGET_HAS_ext16s_i32   use_mips32r2_instructions
>  #define TCG_TARGET_HAS_rot_i32  use_mips32r2_instructions
> @@ -177,6 +178,7 @@ extern bool use_mips32r2_instructions;
>  #define TCG_TARGET_HAS_deposit_i64  use_mips32r2_instructions
>  #define TCG_TARGET_HAS_extract_i64  use_mips32r2_instructions
>  #define TCG_TARGET_HAS_sextract_i64 0
> +#define TCG_TARGET_HAS_extract2_i64 0
>  #define TCG_TARGET_HAS_ext8s_i64use_mips32r2_instructions
>  #define TCG_TARGET_HAS_ext16s_i64   use_mips32r2_instructions
>  #define TCG_TARGET_HAS_rot_i64  use_mips32r2_instructions
> diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h
> index 52c1bb04b1..7627fb62d3 100644
> --- a/tcg/ppc/tcg-target.h
> +++ b/tcg/ppc/tcg-target.h
> @@ -77,6 +77,7 @@ extern bool have_isa_3_00;
>  #define TCG_TARGET_HAS_deposit_i32  1
>  #define TCG_TARGET_HAS_extract_i32  1
>  #define TCG_TARGET_HAS_sextract_i32 0
> +#define TCG_TARGET_HAS_extract2_i32 0
>  #define TCG_TARGET_HAS_movcond_i32  1
>  #define TCG_TARGET_HAS_mulu2_i320
>  #define TCG_TARGET_HAS_muls2_i320
> @@ -115,6 +116,7 @@ extern bool have_isa_3_00;
>  #define TCG_TARGET_HAS_deposit_i64  1
>  #define TCG_TARGET_HAS_extract_i64  1
>  #define TCG_TARGET_HAS_sextract_i64 0
> +#define TCG_TARGET_HAS_extract2_i64   

Re: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

2019-03-08 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20190307144126.31847-1-richard.hender...@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190307144126.31847-1-richard.hender...@linaro.org
Subject: [Qemu-devel] [PATCH 0/9] tcg: Add tcg_gen_extract2_{i32,i64}

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]
patchew/20190307144126.31847-1-richard.hender...@linaro.org -> 
patchew/20190307144126.31847-1-richard.hender...@linaro.org
Switched to a new branch 'test'
3292d7b43c target/arm: Simplify BFXIL expansion
ff6ac2e56f target/arm: Use extract2 for EXTR
cf32404712 tcg/aarch64: Support INDEX_op_extract2_{i32, i64}
7bb2bf5b2f tcg/arm: Support INDEX_op_extract2_i32
77cd89c565 tcg/i386: Support INDEX_op_extract2_{i32, i64}
c74535f601 tcg: Use extract2 in tcg_gen_deposit_{i32, i64}
bf3e4eb1b5 tcg: Use extract2 in tcg_gen_shifti_i64
7880a5be65 tcg: Add INDEX_op_extract2_{i32,i64}
6f428742fe tcg: Implement tcg_gen_extract2_{i32, i64}

=== OUTPUT BEGIN ===
1/9 Checking commit 6f428742fe41 (tcg: Implement tcg_gen_extract2_{i32, i64})
2/9 Checking commit 7880a5be6520 (tcg: Add INDEX_op_extract2_{i32,i64})
ERROR: spaces required around that ':' (ctx:VxE)
#109: FILE: tcg/optimize.c:1205:
+CASE_OP_32_64(extract2):
^

total: 1 errors, 0 warnings, 199 lines checked

Patch 2/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

3/9 Checking commit bf3e4eb1b5b0 (tcg: Use extract2 in tcg_gen_shifti_i64)
4/9 Checking commit c74535f601dc (tcg: Use extract2 in tcg_gen_deposit_{i32, 
i64})
5/9 Checking commit 77cd89c565b5 (tcg/i386: Support INDEX_op_extract2_{i32, 
i64})
ERROR: spaces required around that ':' (ctx:VxE)
#48: FILE: tcg/i386/tcg-target.inc.c:2591:
+OP_32_64(extract2):
   ^

total: 1 errors, 0 warnings, 51 lines checked

Patch 5/9 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

6/9 Checking commit 7bb2bf5b2fa4 (tcg/arm: Support INDEX_op_extract2_i32)
7/9 Checking commit cf324047128d (tcg/aarch64: Support INDEX_op_extract2_{i32, 
i64})
8/9 Checking commit ff6ac2e56f23 (target/arm: Use extract2 for EXTR)
9/9 Checking commit 3292d7b43c8b (target/arm: Simplify BFXIL expansion)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190307144126.31847-1-richard.hender...@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH 1/9] tcg: Implement tcg_gen_extract2_{i32, i64}

2019-03-08 Thread Philippe Mathieu-Daudé
On 3/7/19 3:41 PM, Richard Henderson wrote:
> From: David Hildenbrand 
> 
> Will be helpful for s390x. Input 128 bit and output 64 bit only,
> which is sufficient for now.
> 
> Reviewed-by: Richard Henderson 
> Signed-off-by: David Hildenbrand 
> Message-Id: <20190225154204.26751-1-da...@redhat.com>
> [rth: Add matching tcg_gen_extract2_i32.]
> Signed-off-by: Richard Henderson 
> ---
>  tcg/tcg-op.h |  6 ++
>  tcg/tcg-op.c | 44 
>  2 files changed, 50 insertions(+)
> 
> diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h
> index d3e51b15af..1f1824c30a 100644
> --- a/tcg/tcg-op.h
> +++ b/tcg/tcg-op.h
> @@ -308,6 +308,8 @@ void tcg_gen_extract_i32(TCGv_i32 ret, TCGv_i32 arg,
>   unsigned int ofs, unsigned int len);
>  void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
>unsigned int ofs, unsigned int len);
> +void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
> +  unsigned int ofs);
>  void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1, TCGv_i32 arg2, TCGLabel 
> *);
>  void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, TCGLabel 
> *);
>  void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
> @@ -501,6 +503,8 @@ void tcg_gen_extract_i64(TCGv_i64 ret, TCGv_i64 arg,
>   unsigned int ofs, unsigned int len);
>  void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
>unsigned int ofs, unsigned int len);
> +void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
> +  unsigned int ofs);
>  void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, TCGv_i64 arg2, TCGLabel 
> *);
>  void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1, int64_t arg2, TCGLabel 
> *);
>  void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
> @@ -1068,6 +1072,7 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg 
> offset, TCGType t);
>  #define tcg_gen_deposit_z_tl tcg_gen_deposit_z_i64
>  #define tcg_gen_extract_tl tcg_gen_extract_i64
>  #define tcg_gen_sextract_tl tcg_gen_sextract_i64
> +#define tcg_gen_extract2_tl tcg_gen_extract2_i64
>  #define tcg_const_tl tcg_const_i64
>  #define tcg_const_local_tl tcg_const_local_i64
>  #define tcg_gen_movcond_tl tcg_gen_movcond_i64
> @@ -1178,6 +1183,7 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg 
> offset, TCGType t);
>  #define tcg_gen_deposit_z_tl tcg_gen_deposit_z_i32
>  #define tcg_gen_extract_tl tcg_gen_extract_i32
>  #define tcg_gen_sextract_tl tcg_gen_sextract_i32
> +#define tcg_gen_extract2_tl tcg_gen_extract2_i32
>  #define tcg_const_tl tcg_const_i32
>  #define tcg_const_local_tl tcg_const_local_i32
>  #define tcg_gen_movcond_tl tcg_gen_movcond_i32
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 1bd7ef24af..7c56c92c8e 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -809,6 +809,28 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
>  tcg_gen_sari_i32(ret, ret, 32 - len);
>  }
>  
> +/*
> + * Extract 32-bits from a 64-bit input, ah:al, starting from ofs.
> + * Unlike tcg_gen_extract_i32 above, len is fixed at 32.
> + */
> +void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
> +  unsigned int ofs)
> +{
> +tcg_debug_assert(ofs <= 32);
> +if (ofs == 0) {
> +tcg_gen_mov_i32(ret, al);
> +} else if (ofs == 32) {
> +tcg_gen_mov_i32(ret, ah);
> +} else if (al == ah) {
> +tcg_gen_rotri_i32(ret, al, ofs);
> +} else {
> +TCGv_i32 t0 = tcg_temp_new_i32();
> +tcg_gen_shri_i32(t0, al, ofs);
> +tcg_gen_deposit_i32(ret, t0, ah, 32 - ofs, ofs);
> +tcg_temp_free_i32(t0);
> +}
> +}
> +
>  void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 c1,
>   TCGv_i32 c2, TCGv_i32 v1, TCGv_i32 v2)
>  {
> @@ -2297,6 +2319,28 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
>  tcg_gen_sari_i64(ret, ret, 64 - len);
>  }
>  
> +/*
> + * Extract 64 bits from a 128-bit input, ah:al, starting from ofs.
> + * Unlike tcg_gen_extract_i64 above, len is fixed at 64.
> + */
> +void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
> +  unsigned int ofs)
> +{
> +tcg_debug_assert(ofs <= 64);
> +if (ofs == 0) {
> +tcg_gen_mov_i64(ret, al);
> +} else if (ofs == 64) {
> +tcg_gen_mov_i64(ret, ah);
> +} else if (al == ah) {
> +tcg_gen_rotri_i64(ret, al, ofs);
> +} else {
> +TCGv_i64 t0 = tcg_temp_new_i64();
> +tcg_gen_shri_i64(t0, al, ofs);
> +tcg_gen_deposit_i64(ret, t0, ah, 64 - ofs, ofs);
> +tcg_temp_free_i64(t0);
> +}
> +}
> +
>  void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1,
>   TCGv_i64 c2, TCGv_i64 v1, TCGv_i64 v2)
>  {
> 

Reviewed-by: Philippe Mathieu-Daudé 



Re: [Qemu-devel] [PATCH] qmp-shell: fix nested json regression

2019-03-08 Thread John Snow



On 2/5/19 8:49 AM, Marc-André Lureau wrote:
> Commit fcfab7541 ("qmp-shell: learn to send commands with quoted
> arguments") introduces the usage of Python 'shlex' to handle quoted
> arguments, but it accidentally broke generation of nested JSON
> structs.
> 
> shlex drops quotes, which breaks parsing of the nested struct.
> 
> cmd='blockdev-create job-id="job0 foo" 
> options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}'
> 
> shlex.split(cmd)
> ['blockdev-create',
>  'job-id=job0 foo',
>  'options={driver:qcow2,size:16384,file:{driver:file,filename:foo.qcow2}}']
> 
> Replace with a regexp to split while respecting quoted strings and preserving 
> quotes:
> 
> re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmd)
> ['blockdev-create',
>  'job-id="job0 foo"',
>  
> 'options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}']
> 
> Fixes: fcfab7541 ("qmp-shell: learn to send commands with quoted arguments")
> Reported-by: Kashyap Chamarthy 
> Signed-off-by: Marc-André Lureau 

Hi, did this get misplaced? Would be nice to have back for 4.0 release.



Re: [Qemu-devel] [PATCH v6 00/14] Audio patches

2019-03-08 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/cover.1552083282.git.dirty.ice...@gmail.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: cover.1552083282.git.dirty.ice...@gmail.com
Subject: [Qemu-devel] [PATCH v6 00/14] Audio patches

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]   patchew/cover.1552083282.git.dirty.ice...@gmail.com 
-> patchew/cover.1552083282.git.dirty.ice...@gmail.com
Switched to a new branch 'test'
77a2fc41d3 audio: -audiodev command line option: cleanup
a08295d4a4 wavaudio: port to -audiodev config
2b8db3b1b8 spiceaudio: port to -audiodev config
b13a98214e sdlaudio: port to -audiodev config
f32d4ec566 paaudio: port to -audiodev config
60ef81ebee ossaudio: port to -audiodev config
9361aaae4c noaudio: port to -audiodev config
956b77bf8d dsoundaudio: port to -audiodev config
fd47b30266 coreaudio: port to -audiodev config
b2e94202ed alsaaudio: port to -audiodev config
92e91a2161 audio: -audiodev command line option basic implementation
7597a04f3e audio: -audiodev command line option: documentation
9df02ffc44 audio: use qapi AudioFormat instead of audfmt_e
454e5ebb1c qapi: qapi for audio backends

=== OUTPUT BEGIN ===
1/14 Checking commit 454e5ebb1c11 (qapi: qapi for audio backends)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#51: 
new file mode 100644

total: 0 errors, 1 warnings, 320 lines checked

Patch 1/14 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
2/14 Checking commit 9df02ffc443d (audio: use qapi AudioFormat instead of 
audfmt_e)
ERROR: space prohibited between function name and open parenthesis '('
#36: FILE: audio/alsaaudio.c:297:
+static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)

ERROR: space prohibited between function name and open parenthesis '('
#84: FILE: audio/alsaaudio.c:347:
+static int alsa_to_audfmt (snd_pcm_format_t alsafmt, AudioFormat *fmt,

ERROR: space prohibited between function name and open parenthesis '('
#205: FILE: audio/audio.c:260:
+static const char *audio_audfmt_to_string (AudioFormat fmt)

ERROR: space prohibited between function name and open parenthesis '('
#241: FILE: audio/audio.c:289:
+static AudioFormat audio_string_to_audfmt (const char *s, AudioFormat defval,

ERROR: space prohibited between function name and open parenthesis '('
#282: FILE: audio/audio.c:324:
+static AudioFormat audio_get_conf_fmt (const char *envname,

ERROR: space prohibited between function name and open parenthesis '('
#523: FILE: audio/ossaudio.c:151:
+static int aud_to_ossfmt (AudioFormat fmt, int endianness)

ERROR: space prohibited between function name and open parenthesis '('
#553: FILE: audio/ossaudio.c:185:
+static int oss_to_audfmt (int ossfmt, AudioFormat *fmt, int *endianness)

ERROR: space prohibited between function name and open parenthesis '('
#620: FILE: audio/paaudio.c:388:
+static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)

ERROR: space prohibited between function name and open parenthesis '('
#649: FILE: audio/paaudio.c:413:
+static AudioFormat pa_to_audfmt (pa_sample_format_t fmt, int *endianness)

ERROR: space prohibited between function name and open parenthesis '('
#687: FILE: audio/sdlaudio.c:71:
+static int aud_to_sdlfmt (AudioFormat fmt)

ERROR: trailing statements should be on next line
#954: FILE: hw/audio/hda-codec.c:102:
+case AC_FMT_BITS_8:  as->fmt = AUDIO_FORMAT_S8;  break;

ERROR: trailing statements should be on next line
#955: FILE: hw/audio/hda-codec.c:103:
+case AC_FMT_BITS_16: as->fmt = AUDIO_FORMAT_S16; break;

ERROR: trailing statements should be on next line
#956: FILE: hw/audio/hda-codec.c:104:
+case AC_FMT_BITS_32: as->fmt = AUDIO_FORMAT_S32; break;

ERROR: space prohibited after that open square bracket '['
#970: FILE: hw/audio/hda-codec.c:137:
+[ AUDIO_FORMAT_U8  ] = "PCM-U8",

ERROR: space prohibited before that close square bracket ']'
#970: FILE: hw/audio/hda-codec.c:137:
+[ AUDIO_FORMAT_U8  ] = "PCM-U8",

ERROR: space prohibited after that open square bracket '['
#971: FILE: hw/audio/hda-codec.c:138:
+[ AUDIO_FORMAT_S8  ] = "PCM-S8",

ERROR: space prohibited before that close square bracket ']'
#971: FILE: hw/audio/hda-codec.c:138:
+[ AUDIO_FORMAT_S8  ] = "PCM-S8",

ERROR: space prohibited after that open square bracket '['
#972: FILE: hw/audio/hda-codec.c:139:
+[ AUDIO_FORMAT_U16 ] = "PCM-U16",

ERROR: space prohibited before that close square bracket ']'
#972: FILE: hw/audio/hda-codec.c:139:
+[ AUDIO_FORMAT_U16

[Qemu-devel] [PATCH v6 14/14] audio: -audiodev command line option: cleanup

2019-03-08 Thread Kővágó, Zoltán
Remove no longer needed code.

Signed-off-by: Kővágó, Zoltán 
---
 audio/audio_int.h |  17 -
 audio/audio.c | 186 +-
 2 files changed, 4 insertions(+), 199 deletions(-)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index 7bf5dfc0b5..3f14842709 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -33,22 +33,6 @@
 
 struct audio_pcm_ops;
 
-typedef enum {
-AUD_OPT_INT,
-AUD_OPT_FMT,
-AUD_OPT_STR,
-AUD_OPT_BOOL
-} audio_option_tag_e;
-
-struct audio_option {
-const char *name;
-audio_option_tag_e tag;
-void *valp;
-const char *descr;
-int *overriddenp;
-int overridden;
-};
-
 struct audio_callback {
 void *opaque;
 audio_callback_fn fn;
@@ -145,7 +129,6 @@ typedef struct audio_driver audio_driver;
 struct audio_driver {
 const char *name;
 const char *descr;
-struct audio_option *options;
 void *(*init) (Audiodev *);
 void (*fini) (void *);
 struct audio_pcm_ops *pcm_ops;
diff --git a/audio/audio.c b/audio/audio.c
index 79ed360666..5fd9a58a80 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -172,113 +172,6 @@ void *audio_calloc (const char *funcname, int nmemb, 
size_t size)
 return g_malloc0 (len);
 }
 
-static const char *audio_audfmt_to_string (AudioFormat fmt)
-{
-switch (fmt) {
-case AUDIO_FORMAT_U8:
-return "U8";
-
-case AUDIO_FORMAT_U16:
-return "U16";
-
-case AUDIO_FORMAT_S8:
-return "S8";
-
-case AUDIO_FORMAT_S16:
-return "S16";
-
-case AUDIO_FORMAT_U32:
-return "U32";
-
-case AUDIO_FORMAT_S32:
-return "S32";
-
-default:
-abort();
-}
-
-dolog ("Bogus audfmt %d returning S16\n", fmt);
-return "S16";
-}
-
-static AudioFormat audio_string_to_audfmt (const char *s, AudioFormat defval,
-int *defaultp)
-{
-if (!strcasecmp (s, "u8")) {
-*defaultp = 0;
-return AUDIO_FORMAT_U8;
-}
-else if (!strcasecmp (s, "u16")) {
-*defaultp = 0;
-return AUDIO_FORMAT_U16;
-}
-else if (!strcasecmp (s, "u32")) {
-*defaultp = 0;
-return AUDIO_FORMAT_U32;
-}
-else if (!strcasecmp (s, "s8")) {
-*defaultp = 0;
-return AUDIO_FORMAT_S8;
-}
-else if (!strcasecmp (s, "s16")) {
-*defaultp = 0;
-return AUDIO_FORMAT_S16;
-}
-else if (!strcasecmp (s, "s32")) {
-*defaultp = 0;
-return AUDIO_FORMAT_S32;
-}
-else {
-dolog ("Bogus audio format `%s' using %s\n",
-   s, audio_audfmt_to_string (defval));
-*defaultp = 1;
-return defval;
-}
-}
-
-static AudioFormat audio_get_conf_fmt (const char *envname,
-AudioFormat defval,
-int *defaultp)
-{
-const char *var = getenv (envname);
-if (!var) {
-*defaultp = 1;
-return defval;
-}
-return audio_string_to_audfmt (var, defval, defaultp);
-}
-
-static int audio_get_conf_int (const char *key, int defval, int *defaultp)
-{
-int val;
-char *strval;
-
-strval = getenv (key);
-if (strval && !qemu_strtoi(strval, NULL, 10, &val)) {
-*defaultp = 0;
-return val;
-}
-else {
-*defaultp = 1;
-return defval;
-}
-}
-
-static const char *audio_get_conf_str (const char *key,
-   const char *defval,
-   int *defaultp)
-{
-const char *val = getenv (key);
-if (!val) {
-*defaultp = 1;
-return defval;
-}
-else {
-*defaultp = 0;
-return val;
-}
-}
-
 void AUD_vlog (const char *cap, const char *fmt, va_list ap)
 {
 if (cap) {
@@ -297,74 +190,6 @@ void AUD_log (const char *cap, const char *fmt, ...)
 va_end (ap);
 }
 
-static void audio_process_options (const char *prefix,
-   struct audio_option *opt)
-{
-gchar *prefix_upper;
-
-if (audio_bug(__func__, !prefix)) {
-dolog ("prefix = NULL\n");
-return;
-}
-
-if (audio_bug(__func__, !opt)) {
-dolog ("opt = NULL\n");
-return;
-}
-
-prefix_upper = g_utf8_strup(prefix, -1);
-
-for (; opt->name; opt++) {
-char *optname;
-int def;
-
-if (!opt->valp) {
-dolog ("Option value pointer for `%s' is not set\n",
-   opt->name);
-continue;
-}
-
-optname = g_strdup_printf("QEMU_%s_%s", prefix_upper, opt->name);
-
-def = 1;
-switch (opt->tag) {
-case AUD_OPT_BOOL:
-case AUD_OPT_INT:
-{
-int *intp = opt->valp;
-*intp = audio_get_conf_int (optname, *intp, &def);
-}
-break;
-
-case AUD_OPT_FMT:
-{
-AudioFormat *fmtp = opt->valp;
-   

[Qemu-devel] [PATCH v6 12/14] spiceaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/spiceaudio.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c
index affc3df17f..4f7873af5a 100644
--- a/audio/spiceaudio.c
+++ b/audio/spiceaudio.c
@@ -373,10 +373,6 @@ static int line_in_ctl (HWVoiceIn *hw, int cmd, ...)
 return 0;
 }
 
-static struct audio_option audio_options[] = {
-{ /* end of list */ },
-};
-
 static struct audio_pcm_ops audio_callbacks = {
 .init_out = line_out_init,
 .fini_out = line_out_fini,
@@ -394,7 +390,6 @@ static struct audio_pcm_ops audio_callbacks = {
 static struct audio_driver spice_audio_driver = {
 .name   = "spice",
 .descr  = "spice audio driver",
-.options= audio_options,
 .init   = spice_audio_init,
 .fini   = spice_audio_fini,
 .pcm_ops= &audio_callbacks,
-- 
2.20.1




[Qemu-devel] [PATCH v6 11/14] sdlaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/audio_legacy.c | 12 
 audio/sdlaudio.c | 22 --
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
index 8d7f1475b5..478cf76d5f 100644
--- a/audio/audio_legacy.c
+++ b/audio/audio_legacy.c
@@ -281,6 +281,14 @@ static void handle_pa(Audiodev *dev)
 get_str("QEMU_PA_SERVER", &dev->u.pa.server, &dev->u.pa.has_server);
 }
 
+/* SDL */
+static void handle_sdl(Audiodev *dev)
+{
+/* SDL is output only */
+get_samples_to_usecs("QEMU_SDL_SAMPLES", &dev->u.sdl.out->buffer_length,
+ &dev->u.sdl.out->has_buffer_length, dev->u.sdl.out);
+}
+
 /* general */
 static void handle_per_direction(
 AudiodevPerDirectionOptions *pdo, const char *prefix)
@@ -342,6 +350,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
 handle_pa(e->dev);
 break;
 
+case AUDIODEV_DRIVER_SDL:
+handle_sdl(e->dev);
+break;
+
 default:
 break;
 }
diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
index b9ae506a56..ff9248ba68 100644
--- a/audio/sdlaudio.c
+++ b/audio/sdlaudio.c
@@ -44,16 +44,11 @@ typedef struct SDLVoiceOut {
 int decr;
 } SDLVoiceOut;
 
-static struct {
-int nb_samples;
-} conf = {
-.nb_samples = 1024
-};
-
 static struct SDLAudioState {
 int exit;
 int initialized;
 bool driver_created;
+Audiodev *dev;
 } glob_sdl;
 typedef struct SDLAudioState SDLAudioState;
 
@@ -271,7 +266,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings 
*as,
 req.freq = as->freq;
 req.format = aud_to_sdlfmt (as->fmt);
 req.channels = as->nchannels;
-req.samples = conf.nb_samples;
+req.samples = audio_buffer_samples(s->dev->u.sdl.out, as, 11610);
 req.callback = sdl_callback;
 req.userdata = sdl;
 
@@ -329,6 +324,7 @@ static void *sdl_audio_init(Audiodev *dev)
 }
 
 s->driver_created = true;
+s->dev = dev;
 return s;
 }
 
@@ -338,18 +334,9 @@ static void sdl_audio_fini (void *opaque)
 sdl_close (s);
 SDL_QuitSubSystem (SDL_INIT_AUDIO);
 s->driver_created = false;
+s->dev = NULL;
 }
 
-static struct audio_option sdl_options[] = {
-{
-.name  = "SAMPLES",
-.tag   = AUD_OPT_INT,
-.valp  = &conf.nb_samples,
-.descr = "Size of SDL buffer in samples"
-},
-{ /* End of list */ }
-};
-
 static struct audio_pcm_ops sdl_pcm_ops = {
 .init_out = sdl_init_out,
 .fini_out = sdl_fini_out,
@@ -361,7 +348,6 @@ static struct audio_pcm_ops sdl_pcm_ops = {
 static struct audio_driver sdl_audio_driver = {
 .name   = "sdl",
 .descr  = "SDL http://www.libsdl.org";,
-.options= sdl_options,
 .init   = sdl_audio_init,
 .fini   = sdl_audio_fini,
 .pcm_ops= &sdl_pcm_ops,
-- 
2.20.1




[Qemu-devel] [PATCH v6 13/14] wavaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/audio_legacy.c | 16 
 audio/wavaudio.c | 58 +++-
 2 files changed, 25 insertions(+), 49 deletions(-)

diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
index 478cf76d5f..6d140119d9 100644
--- a/audio/audio_legacy.c
+++ b/audio/audio_legacy.c
@@ -289,6 +289,18 @@ static void handle_sdl(Audiodev *dev)
  &dev->u.sdl.out->has_buffer_length, dev->u.sdl.out);
 }
 
+/* wav */
+static void handle_wav(Audiodev *dev)
+{
+get_int("QEMU_WAV_FREQUENCY",
+&dev->u.wav.out->frequency, &dev->u.wav.out->has_frequency);
+get_fmt("QEMU_WAV_FORMAT", &dev->u.wav.out->format,
+&dev->u.wav.out->has_format);
+get_int("QEMU_WAV_DAC_FIXED_CHANNELS",
+&dev->u.wav.out->channels, &dev->u.wav.out->has_channels);
+get_str("QEMU_WAV_PATH", &dev->u.wav.path, &dev->u.wav.has_path);
+}
+
 /* general */
 static void handle_per_direction(
 AudiodevPerDirectionOptions *pdo, const char *prefix)
@@ -354,6 +366,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
 handle_sdl(e->dev);
 break;
 
+case AUDIODEV_DRIVER_WAV:
+handle_wav(e->dev);
+break;
+
 default:
 break;
 }
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index 9eff3555b3..8d30f57296 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -24,6 +24,7 @@
 #include "qemu/osdep.h"
 #include "qemu/host-utils.h"
 #include "qemu/timer.h"
+#include "qapi/opts-visitor.h"
 #include "audio.h"
 
 #define AUDIO_CAP "wav"
@@ -37,11 +38,6 @@ typedef struct WAVVoiceOut {
 int total_samples;
 } WAVVoiceOut;
 
-typedef struct {
-struct audsettings settings;
-const char *wav_path;
-} WAVConf;
-
 static int wav_run_out (HWVoiceOut *hw, int live)
 {
 WAVVoiceOut *wav = (WAVVoiceOut *) hw;
@@ -112,8 +108,10 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings 
*as,
 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04,
 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
 };
-WAVConf *conf = drv_opaque;
-struct audsettings wav_as = conf->settings;
+Audiodev *dev = drv_opaque;
+AudiodevWavOptions *wopts = &dev->u.wav;
+struct audsettings wav_as = audiodev_to_audsettings(dev->u.wav.out);
+const char *wav_path = wopts->has_path ? wopts->path : "qemu.wav";
 
 stereo = wav_as.nchannels == 2;
 switch (wav_as.fmt) {
@@ -154,10 +152,10 @@ static int wav_init_out(HWVoiceOut *hw, struct 
audsettings *as,
 le_store (hdr + 28, hw->info.freq << (bits16 + stereo), 4);
 le_store (hdr + 32, 1 << (bits16 + stereo), 2);
 
-wav->f = fopen (conf->wav_path, "wb");
+wav->f = fopen(wav_path, "wb");
 if (!wav->f) {
 dolog ("Failed to open wave file `%s'\nReason: %s\n",
-   conf->wav_path, strerror (errno));
+   wav_path, strerror(errno));
 g_free (wav->pcm_buf);
 wav->pcm_buf = NULL;
 return -1;
@@ -225,54 +223,17 @@ static int wav_ctl_out (HWVoiceOut *hw, int cmd, ...)
 return 0;
 }
 
-static WAVConf glob_conf = {
-.settings.freq  = 44100,
-.settings.nchannels = 2,
-.settings.fmt   = AUDIO_FORMAT_S16,
-.wav_path   = "qemu.wav"
-};
-
 static void *wav_audio_init(Audiodev *dev)
 {
-WAVConf *conf = g_malloc(sizeof(WAVConf));
-*conf = glob_conf;
-return conf;
+assert(dev->driver == AUDIODEV_DRIVER_WAV);
+return dev;
 }
 
 static void wav_audio_fini (void *opaque)
 {
 ldebug ("wav_fini");
-g_free(opaque);
 }
 
-static struct audio_option wav_options[] = {
-{
-.name  = "FREQUENCY",
-.tag   = AUD_OPT_INT,
-.valp  = &glob_conf.settings.freq,
-.descr = "Frequency"
-},
-{
-.name  = "FORMAT",
-.tag   = AUD_OPT_FMT,
-.valp  = &glob_conf.settings.fmt,
-.descr = "Format"
-},
-{
-.name  = "DAC_FIXED_CHANNELS",
-.tag   = AUD_OPT_INT,
-.valp  = &glob_conf.settings.nchannels,
-.descr = "Number of channels (1 - mono, 2 - stereo)"
-},
-{
-.name  = "PATH",
-.tag   = AUD_OPT_STR,
-.valp  = &glob_conf.wav_path,
-.descr = "Path to wave file"
-},
-{ /* End of list */ }
-};
-
 static struct audio_pcm_ops wav_pcm_ops = {
 .init_out = wav_init_out,
 .fini_out = wav_fini_out,
@@ -284,7 +245,6 @@ static struct audio_pcm_ops wav_pcm_ops = {
 static struct audio_driver wav_audio_driver = {
 .name   = "wav",
 .descr  = "WAV renderer http://wikipedia.org/wiki/WAV";,
-.options= wav_options,
 .init   = wav_audio_init,
 .fini   = wav_audio_fini,
 .pcm_ops= &wav_pcm_ops,
-- 
2.20.1




[Qemu-devel] [PATCH v6 10/14] paaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/audio_legacy.c | 38 +
 audio/paaudio.c  | 81 
 2 files changed, 67 insertions(+), 52 deletions(-)

diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
index 94f95bbc73..8d7f1475b5 100644
--- a/audio/audio_legacy.c
+++ b/audio/audio_legacy.c
@@ -127,6 +127,16 @@ static uint32_t samples_to_usecs(uint32_t samples,
 return frames_to_usecs(samples / channels, pdo);
 }
 
+static void get_samples_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
+ AudiodevPerDirectionOptions *pdo)
+{
+const char *val = getenv(env);
+if (val) {
+*dst = samples_to_usecs(toui32(val), pdo);
+*has_dst = true;
+}
+}
+
 static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions 
*pdo)
 {
 AudioFormat fmt = pdo->has_format ? pdo->format : AUDIO_FORMAT_S16;
@@ -247,6 +257,30 @@ static void handle_oss(Audiodev *dev)
 get_int("QEMU_OSS_POLICY", &oopt->dsp_policy, &oopt->has_dsp_policy);
 }
 
+/* pulseaudio */
+static void handle_pa_per_direction(
+AudiodevPaPerDirectionOptions *ppdo, const char *env)
+{
+get_str(env, &ppdo->name, &ppdo->has_name);
+}
+
+static void handle_pa(Audiodev *dev)
+{
+handle_pa_per_direction(dev->u.pa.in, "QEMU_PA_SOURCE");
+handle_pa_per_direction(dev->u.pa.out, "QEMU_PA_SINK");
+
+get_samples_to_usecs(
+"QEMU_PA_SAMPLES", &dev->u.pa.in->buffer_length,
+&dev->u.pa.in->has_buffer_length,
+qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.in));
+get_samples_to_usecs(
+"QEMU_PA_SAMPLES", &dev->u.pa.out->buffer_length,
+&dev->u.pa.out->has_buffer_length,
+qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.out));
+
+get_str("QEMU_PA_SERVER", &dev->u.pa.server, &dev->u.pa.has_server);
+}
+
 /* general */
 static void handle_per_direction(
 AudiodevPerDirectionOptions *pdo, const char *prefix)
@@ -304,6 +338,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
 handle_oss(e->dev);
 break;
 
+case AUDIODEV_DRIVER_PA:
+handle_pa(e->dev);
+break;
+
 default:
 break;
 }
diff --git a/audio/paaudio.c b/audio/paaudio.c
index d649c58e3d..5d410ed73f 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -2,6 +2,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "audio.h"
+#include "qapi/opts-visitor.h"
 
 #include 
 
@@ -10,14 +11,7 @@
 #include "audio_pt_int.h"
 
 typedef struct {
-int samples;
-char *server;
-char *sink;
-char *source;
-} PAConf;
-
-typedef struct {
-PAConf conf;
+Audiodev *dev;
 pa_threaded_mainloop *mainloop;
 pa_context *context;
 } paaudio;
@@ -32,6 +26,7 @@ typedef struct {
 void *pcm_buf;
 struct audio_pt pt;
 paaudio *g;
+int samples;
 } PAVoiceOut;
 
 typedef struct {
@@ -46,6 +41,7 @@ typedef struct {
 const void *read_data;
 size_t read_index, read_length;
 paaudio *g;
+int samples;
 } PAVoiceIn;
 
 static void qpa_audio_fini(void *opaque);
@@ -227,7 +223,7 @@ static void *qpa_thread_out (void *arg)
 }
 }
 
-decr = to_mix = audio_MIN(pa->live, pa->g->conf.samples >> 5);
+decr = to_mix = audio_MIN(pa->live, pa->samples >> 5);
 rpos = pa->rpos;
 
 if (audio_pt_unlock(&pa->pt, __func__)) {
@@ -319,7 +315,7 @@ static void *qpa_thread_in (void *arg)
 }
 }
 
-incr = to_grab = audio_MIN(pa->dead, pa->g->conf.samples >> 5);
+incr = to_grab = audio_MIN(pa->dead, pa->samples >> 5);
 wpos = pa->wpos;
 
 if (audio_pt_unlock(&pa->pt, __func__)) {
@@ -546,6 +542,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings 
*as,
 struct audsettings obt_as = *as;
 PAVoiceOut *pa = (PAVoiceOut *) hw;
 paaudio *g = pa->g = drv_opaque;
+AudiodevPaOptions *popts = &g->dev->u.pa;
+AudiodevPaPerDirectionOptions *ppdo = popts->out;
 
 ss.format = audfmt_to_pa (as->fmt, as->endianness);
 ss.channels = as->nchannels;
@@ -566,7 +564,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings 
*as,
 g,
 "qemu",
 PA_STREAM_PLAYBACK,
-g->conf.sink,
+ppdo->has_name ? ppdo->name : NULL,
 &ss,
 NULL,   /* channel map */
 &ba,/* buffering attributes */
@@ -578,7 +576,8 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings 
*as,
 }
 
 audio_pcm_init_info (&hw->info, &obt_as);
-hw->samples = g->conf.samples;
+hw->samples = pa->samples = audio_buffer_samples(
+qapi_AudiodevPaPerDirectionOptions_base(ppdo), &obt_as, 46440);
 pa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
 pa->rpos = hw->rpos;
 if (!pa->pcm_buf) {
@@ -612,6 +611,8 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings 
*as, void *drv_opaque)
  

[Qemu-devel] [PATCH v6 04/14] audio: -audiodev command line option basic implementation

2019-03-08 Thread Kővágó, Zoltán
Audio drivers now get an Audiodev * as config paramters, instead of the
global audio_option structs.  There is some code in audio/audio_legacy.c
that converts the old environment variables to audiodev options (this
way backends do not have to worry about legacy options).  It also
contains a replacement of -audio-help, which prints out the equivalent
-audiodev based config of the currently specified environment variables.

Note that backends are not updated and still rely on environment
variables.

Also note that (due to moving try-poll from global to backend specific
option) currently ALSA and OSS will always try poll mode, regardless of
environment variables or -audiodev options.

Signed-off-by: Kővágó, Zoltán 
---
 audio/audio.h  |  18 +-
 audio/audio_int.h  |  20 +-
 audio/audio_template.h |  42 ++-
 audio/alsaaudio.c  |   2 +-
 audio/audio.c  | 630 ++---
 audio/audio_legacy.c   | 293 +++
 audio/coreaudio.c  |   2 +-
 audio/dsoundaudio.c|   2 +-
 audio/noaudio.c|   2 +-
 audio/ossaudio.c   |   2 +-
 audio/paaudio.c|   2 +-
 audio/sdlaudio.c   |   2 +-
 audio/spiceaudio.c |   2 +-
 audio/wavaudio.c   |   2 +-
 vl.c   |   7 +-
 audio/Makefile.objs|   2 +-
 16 files changed, 650 insertions(+), 380 deletions(-)
 create mode 100644 audio/audio_legacy.c

diff --git a/audio/audio.h b/audio/audio.h
index 02f29a3b3e..64b0f761bc 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -36,12 +36,21 @@ typedef void (*audio_callback_fn) (void *opaque, int avail);
 #define AUDIO_HOST_ENDIANNESS 0
 #endif
 
-struct audsettings {
+typedef struct audsettings {
 int freq;
 int nchannels;
 AudioFormat fmt;
 int endianness;
-};
+} audsettings;
+
+audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
+int audioformat_bytes_per_sample(AudioFormat fmt);
+int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
+audsettings *as, int def_usecs);
+int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
+ audsettings *as, int def_usecs);
+int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
+   audsettings *as, int def_usecs);
 
 typedef enum {
 AUD_CNOTIFY_ENABLE,
@@ -81,7 +90,6 @@ typedef struct QEMUAudioTimeStamp {
 void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 
0);
 void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 
-void AUD_help (void);
 void AUD_register_card (const char *name, QEMUSoundCard *card);
 void AUD_remove_card (QEMUSoundCard *card);
 CaptureVoiceOut *AUD_add_capture (
@@ -163,4 +171,8 @@ void audio_sample_to_uint64(void *samples, int pos,
 void audio_sample_from_uint64(void *samples, int pos,
 uint64_t left, uint64_t right);
 
+void audio_parse_option(const char *opt);
+void audio_init_audiodevs(void);
+void audio_legacy_help(void);
+
 #endif /* QEMU_AUDIO_H */
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 6c451b995c..7bf5dfc0b5 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -146,7 +146,7 @@ struct audio_driver {
 const char *name;
 const char *descr;
 struct audio_option *options;
-void *(*init) (void);
+void *(*init) (Audiodev *);
 void (*fini) (void *);
 struct audio_pcm_ops *pcm_ops;
 int can_be_default;
@@ -193,6 +193,7 @@ struct SWVoiceCap {
 
 typedef struct AudioState {
 struct audio_driver *drv;
+Audiodev *dev;
 void *drv_opaque;
 
 QEMUTimer *ts;
@@ -203,10 +204,13 @@ typedef struct AudioState {
 int nb_hw_voices_out;
 int nb_hw_voices_in;
 int vm_running;
+int64_t period_ticks;
 } AudioState;
 
 extern const struct mixeng_volume nominal_volume;
 
+extern const char *audio_prio_list[];
+
 void audio_driver_register(audio_driver *drv);
 audio_driver *audio_driver_lookup(const char *name);
 
@@ -248,4 +252,18 @@ static inline int audio_ring_dist (int dst, int src, int 
len)
 #define AUDIO_STRINGIFY_(n) #n
 #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
 
+typedef struct AudiodevListEntry {
+Audiodev *dev;
+QSIMPLEQ_ENTRY(AudiodevListEntry) next;
+} AudiodevListEntry;
+
+typedef QSIMPLEQ_HEAD(, AudiodevListEntry) AudiodevListHead;
+AudiodevListHead audio_handle_legacy_opts(void);
+
+void audio_free_audiodev_list(AudiodevListHead *head);
+
+void audio_create_pdos(Audiodev *dev);
+AudiodevPerDirectionOptions *audio_get_pdo_in(Audiodev *dev);
+AudiodevPerDirectionOptions *audio_get_pdo_out(Audiodev *dev);
+
 #endif /* QEMU_AUDIO_INT_H */
diff --git a/audio/audio_template.h b/audio/audio_template.h
index 7de227d2d1..1232bb54db 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -299,11 +299,42 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct 
audsettings *as)
 return NULL;
 }
 
+AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
+{
+switch (dev->

[Qemu-devel] [PATCH v6 05/14] alsaaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/alsaaudio.c| 329 +--
 audio/audio_legacy.c |  84 ++-
 2 files changed, 181 insertions(+), 232 deletions(-)

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 8302f3e882..49e6884309 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -33,28 +33,9 @@
 #define AUDIO_CAP "alsa"
 #include "audio_int.h"
 
-typedef struct ALSAConf {
-int size_in_usec_in;
-int size_in_usec_out;
-const char *pcm_name_in;
-const char *pcm_name_out;
-unsigned int buffer_size_in;
-unsigned int period_size_in;
-unsigned int buffer_size_out;
-unsigned int period_size_out;
-unsigned int threshold;
-
-int buffer_size_in_overridden;
-int period_size_in_overridden;
-
-int buffer_size_out_overridden;
-int period_size_out_overridden;
-} ALSAConf;
-
 struct pollhlp {
 snd_pcm_t *handle;
 struct pollfd *pfds;
-ALSAConf *conf;
 int count;
 int mask;
 };
@@ -66,6 +47,7 @@ typedef struct ALSAVoiceOut {
 void *pcm_buf;
 snd_pcm_t *handle;
 struct pollhlp pollhlp;
+Audiodev *dev;
 } ALSAVoiceOut;
 
 typedef struct ALSAVoiceIn {
@@ -73,16 +55,13 @@ typedef struct ALSAVoiceIn {
 snd_pcm_t *handle;
 void *pcm_buf;
 struct pollhlp pollhlp;
+Audiodev *dev;
 } ALSAVoiceIn;
 
 struct alsa_params_req {
 int freq;
 snd_pcm_format_t fmt;
 int nchannels;
-int size_in_usec;
-int override_mask;
-unsigned int buffer_size;
-unsigned int period_size;
 };
 
 struct alsa_params_obt {
@@ -408,17 +387,18 @@ static int alsa_to_audfmt (snd_pcm_format_t alsafmt, 
AudioFormat *fmt,
 
 static void alsa_dump_info (struct alsa_params_req *req,
 struct alsa_params_obt *obt,
-snd_pcm_format_t obtfmt)
+snd_pcm_format_t obtfmt,
+AudiodevAlsaPerDirectionOptions *apdo)
 {
-dolog ("parameter | requested value | obtained value\n");
-dolog ("format|  %10d | %10d\n", req->fmt, obtfmt);
-dolog ("channels  |  %10d | %10d\n",
-   req->nchannels, obt->nchannels);
-dolog ("frequency |  %10d | %10d\n", req->freq, obt->freq);
-dolog ("\n");
-dolog ("requested: buffer size %d period size %d\n",
-   req->buffer_size, req->period_size);
-dolog ("obtained: samples %ld\n", obt->samples);
+dolog("parameter | requested value | obtained value\n");
+dolog("format|  %10d | %10d\n", req->fmt, obtfmt);
+dolog("channels  |  %10d | %10d\n",
+  req->nchannels, obt->nchannels);
+dolog("frequency |  %10d | %10d\n", req->freq, obt->freq);
+dolog("\n");
+dolog("requested: buffer len %" PRId32 " period len %" PRId32 "\n",
+  apdo->buffer_length, apdo->period_length);
+dolog("obtained: samples %ld\n", obt->samples);
 }
 
 static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold)
@@ -451,23 +431,23 @@ static void alsa_set_threshold (snd_pcm_t *handle, 
snd_pcm_uframes_t threshold)
 }
 }
 
-static int alsa_open (int in, struct alsa_params_req *req,
-  struct alsa_params_obt *obt, snd_pcm_t **handlep,
-  ALSAConf *conf)
+static int alsa_open(bool in, struct alsa_params_req *req,
+ struct alsa_params_obt *obt, snd_pcm_t **handlep,
+ Audiodev *dev)
 {
+AudiodevAlsaOptions *aopts = &dev->u.alsa;
+AudiodevAlsaPerDirectionOptions *apdo = in ? aopts->in : aopts->out;
 snd_pcm_t *handle;
 snd_pcm_hw_params_t *hw_params;
 int err;
-int size_in_usec;
 unsigned int freq, nchannels;
-const char *pcm_name = in ? conf->pcm_name_in : conf->pcm_name_out;
+const char *pcm_name = apdo->has_dev ? apdo->dev : "default";
 snd_pcm_uframes_t obt_buffer_size;
 const char *typ = in ? "ADC" : "DAC";
 snd_pcm_format_t obtfmt;
 
 freq = req->freq;
 nchannels = req->nchannels;
-size_in_usec = req->size_in_usec;
 
 snd_pcm_hw_params_alloca (&hw_params);
 
@@ -527,79 +507,42 @@ static int alsa_open (int in, struct alsa_params_req *req,
 goto err;
 }
 
-if (req->buffer_size) {
-unsigned long obt;
+if (apdo->buffer_length) {
+int dir = 0;
+unsigned int btime = apdo->buffer_length;
 
-if (size_in_usec) {
-int dir = 0;
-unsigned int btime = req->buffer_size;
+err = snd_pcm_hw_params_set_buffer_time_near(
+handle, hw_params, &btime, &dir);
 
-err = snd_pcm_hw_params_set_buffer_time_near (
-handle,
-hw_params,
-&btime,
-&dir
-);
-obt = btime;
-}
-else {
-snd_pcm_uframes_t bsize = req->buff

[Qemu-devel] [PATCH v6 08/14] noaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/noaudio.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/audio/noaudio.c b/audio/noaudio.c
index 79690af1ea..ccc611fc84 100644
--- a/audio/noaudio.c
+++ b/audio/noaudio.c
@@ -163,7 +163,6 @@ static struct audio_pcm_ops no_pcm_ops = {
 static struct audio_driver no_audio_driver = {
 .name   = "none",
 .descr  = "Timer based audio emulation",
-.options= NULL,
 .init   = no_audio_init,
 .fini   = no_audio_fini,
 .pcm_ops= &no_pcm_ops,
-- 
2.20.1




[Qemu-devel] [PATCH v6 09/14] ossaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/audio_legacy.c |  32 +
 audio/ossaudio.c | 161 ++-
 2 files changed, 83 insertions(+), 110 deletions(-)

diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
index bf326bd360..94f95bbc73 100644
--- a/audio/audio_legacy.c
+++ b/audio/audio_legacy.c
@@ -219,6 +219,34 @@ static void handle_dsound(Audiodev *dev)
dev->u.dsound.in);
 }
 
+/* OSS */
+static void handle_oss_per_direction(
+AudiodevOssPerDirectionOptions *opdo, const char *try_poll_env,
+const char *dev_env)
+{
+get_bool(try_poll_env, &opdo->try_poll, &opdo->has_try_poll);
+get_str(dev_env, &opdo->dev, &opdo->has_dev);
+
+get_bytes_to_usecs("QEMU_OSS_FRAGSIZE",
+   &opdo->buffer_length, &opdo->has_buffer_length,
+   qapi_AudiodevOssPerDirectionOptions_base(opdo));
+get_int("QEMU_OSS_NFRAGS", &opdo->buffer_count,
+&opdo->has_buffer_count);
+}
+
+static void handle_oss(Audiodev *dev)
+{
+AudiodevOssOptions *oopt = &dev->u.oss;
+handle_oss_per_direction(oopt->in, "QEMU_AUDIO_ADC_TRY_POLL",
+ "QEMU_OSS_ADC_DEV");
+handle_oss_per_direction(oopt->out, "QEMU_AUDIO_DAC_TRY_POLL",
+ "QEMU_OSS_DAC_DEV");
+
+get_bool("QEMU_OSS_MMAP", &oopt->try_mmap, &oopt->has_try_mmap);
+get_bool("QEMU_OSS_EXCLUSIVE", &oopt->exclusive, &oopt->has_exclusive);
+get_int("QEMU_OSS_POLICY", &oopt->dsp_policy, &oopt->has_dsp_policy);
+}
+
 /* general */
 static void handle_per_direction(
 AudiodevPerDirectionOptions *pdo, const char *prefix)
@@ -272,6 +300,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
 handle_dsound(e->dev);
 break;
 
+case AUDIODEV_DRIVER_OSS:
+handle_oss(e->dev);
+break;
+
 default:
 break;
 }
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index e0cadbef29..fc28981a39 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -37,16 +37,6 @@
 #define USE_DSP_POLICY
 #endif
 
-typedef struct OSSConf {
-int try_mmap;
-int nfrags;
-int fragsize;
-const char *devpath_out;
-const char *devpath_in;
-int exclusive;
-int policy;
-} OSSConf;
-
 typedef struct OSSVoiceOut {
 HWVoiceOut hw;
 void *pcm_buf;
@@ -56,7 +46,7 @@ typedef struct OSSVoiceOut {
 int fragsize;
 int mmapped;
 int pending;
-OSSConf *conf;
+Audiodev *dev;
 } OSSVoiceOut;
 
 typedef struct OSSVoiceIn {
@@ -65,12 +55,12 @@ typedef struct OSSVoiceIn {
 int fd;
 int nfrags;
 int fragsize;
-OSSConf *conf;
+Audiodev *dev;
 } OSSVoiceIn;
 
 struct oss_params {
 int freq;
-AudioFormat fmt;
+int fmt;
 int nchannels;
 int nfrags;
 int fragsize;
@@ -262,19 +252,25 @@ static int oss_get_version (int fd, int *version, const 
char *typ)
 }
 #endif
 
-static int oss_open (int in, struct oss_params *req,
- struct oss_params *obt, int *pfd, OSSConf* conf)
+static int oss_open(int in, struct oss_params *req, audsettings *as,
+struct oss_params *obt, int *pfd, Audiodev *dev)
 {
+AudiodevOssOptions *oopts = &dev->u.oss;
+AudiodevOssPerDirectionOptions *opdo = in ? oopts->in : oopts->out;
 int fd;
-int oflags = conf->exclusive ? O_EXCL : 0;
+int oflags = (oopts->has_exclusive && oopts->exclusive) ? O_EXCL : 0;
 audio_buf_info abinfo;
 int fmt, freq, nchannels;
 int setfragment = 1;
-const char *dspname = in ? conf->devpath_in : conf->devpath_out;
+const char *dspname = opdo->has_dev ? opdo->dev : "/dev/dsp";
 const char *typ = in ? "ADC" : "DAC";
+#ifdef USE_DSP_POLICY
+int policy = oopts->has_dsp_policy ? oopts->dsp_policy : 5;
+#endif
 
 /* Kludge needed to have working mmap on Linux */
-oflags |= conf->try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
+oflags |= (oopts->has_try_mmap && oopts->try_mmap) ?
+O_RDWR : (in ? O_RDONLY : O_WRONLY);
 
 fd = open (dspname, oflags | O_NONBLOCK);
 if (-1 == fd) {
@@ -285,6 +281,9 @@ static int oss_open (int in, struct oss_params *req,
 freq = req->freq;
 nchannels = req->nchannels;
 fmt = req->fmt;
+req->nfrags = opdo->has_buffer_count ? opdo->buffer_count : 4;
+req->fragsize = audio_buffer_bytes(
+qapi_AudiodevOssPerDirectionOptions_base(opdo), as, 23220);
 
 if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
 oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
@@ -308,18 +307,18 @@ static int oss_open (int in, struct oss_params *req,
 }
 
 #ifdef USE_DSP_POLICY
-if (conf->policy >= 0) {
+if (policy >= 0) {
 int version;
 
 if (!oss_get_version (fd, &version, typ)) {
 trace_oss_version(version);
 
 if (version >= 0x04) {
-int policy = conf->policy;
-if (ioctl (fd, SNDCTL_DSP_POLICY, &p

[Qemu-devel] [PATCH v6 02/14] audio: use qapi AudioFormat instead of audfmt_e

2019-03-08 Thread Kővágó, Zoltán
I had to include an enum for audio sampling formats into qapi, but that
meant duplicating the audfmt_e enum.  This patch replaces audfmt_e and
associated values with the qapi generated AudioFormat enum.

This patch is mostly a search-and-replace, except for switches where the
qapi generated AUDIO_FORMAT_MAX caused problems.

Signed-off-by: Kővágó, Zoltán 
Reviewed-by: Thomas Huth 
---
 audio/audio.h | 12 +
 audio/alsaaudio.c | 53 +++--
 audio/audio.c | 97 +--
 audio/audio_win_int.c | 18 
 audio/ossaudio.c  | 30 ++--
 audio/paaudio.c   | 28 +--
 audio/sdlaudio.c  | 26 +--
 audio/spiceaudio.c|  4 +-
 audio/wavaudio.c  | 17 ---
 audio/wavcapture.c|  2 +-
 hw/arm/omap2.c|  2 +-
 hw/audio/ac97.c   |  2 +-
 hw/audio/adlib.c  |  2 +-
 hw/audio/cs4231a.c|  6 +--
 hw/audio/es1370.c |  4 +-
 hw/audio/gus.c|  2 +-
 hw/audio/hda-codec.c  | 18 
 hw/audio/lm4549.c |  6 +--
 hw/audio/milkymist-ac97.c |  2 +-
 hw/audio/pcspk.c  |  2 +-
 hw/audio/sb16.c   | 14 +++---
 hw/audio/wm8750.c |  6 +--
 hw/display/xlnx_dp.c  |  2 +-
 hw/input/tsc210x.c|  2 +-
 hw/usb/dev-audio.c|  2 +-
 ui/vnc.c  | 26 +--
 26 files changed, 196 insertions(+), 189 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index f4339a185e..02f29a3b3e 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -26,18 +26,10 @@
 #define QEMU_AUDIO_H
 
 #include "qemu/queue.h"
+#include "qapi/qapi-types-audio.h"
 
 typedef void (*audio_callback_fn) (void *opaque, int avail);
 
-typedef enum {
-AUD_FMT_U8,
-AUD_FMT_S8,
-AUD_FMT_U16,
-AUD_FMT_S16,
-AUD_FMT_U32,
-AUD_FMT_S32
-} audfmt_e;
-
 #ifdef HOST_WORDS_BIGENDIAN
 #define AUDIO_HOST_ENDIANNESS 1
 #else
@@ -47,7 +39,7 @@ typedef enum {
 struct audsettings {
 int freq;
 int nchannels;
-audfmt_e fmt;
+AudioFormat fmt;
 int endianness;
 };
 
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 635be73bf4..5bd034267f 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -87,7 +87,7 @@ struct alsa_params_req {
 
 struct alsa_params_obt {
 int freq;
-audfmt_e fmt;
+AudioFormat fmt;
 int endianness;
 int nchannels;
 snd_pcm_uframes_t samples;
@@ -294,16 +294,16 @@ static int alsa_write (SWVoiceOut *sw, void *buf, int len)
 return audio_pcm_sw_write (sw, buf, len);
 }
 
-static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
+static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
 {
 switch (fmt) {
-case AUD_FMT_S8:
+case AUDIO_FORMAT_S8:
 return SND_PCM_FORMAT_S8;
 
-case AUD_FMT_U8:
+case AUDIO_FORMAT_U8:
 return SND_PCM_FORMAT_U8;
 
-case AUD_FMT_S16:
+case AUDIO_FORMAT_S16:
 if (endianness) {
 return SND_PCM_FORMAT_S16_BE;
 }
@@ -311,7 +311,7 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int 
endianness)
 return SND_PCM_FORMAT_S16_LE;
 }
 
-case AUD_FMT_U16:
+case AUDIO_FORMAT_U16:
 if (endianness) {
 return SND_PCM_FORMAT_U16_BE;
 }
@@ -319,7 +319,7 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int 
endianness)
 return SND_PCM_FORMAT_U16_LE;
 }
 
-case AUD_FMT_S32:
+case AUDIO_FORMAT_S32:
 if (endianness) {
 return SND_PCM_FORMAT_S32_BE;
 }
@@ -327,7 +327,7 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int 
endianness)
 return SND_PCM_FORMAT_S32_LE;
 }
 
-case AUD_FMT_U32:
+case AUDIO_FORMAT_U32:
 if (endianness) {
 return SND_PCM_FORMAT_U32_BE;
 }
@@ -344,58 +344,58 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int 
endianness)
 }
 }
 
-static int alsa_to_audfmt (snd_pcm_format_t alsafmt, audfmt_e *fmt,
+static int alsa_to_audfmt (snd_pcm_format_t alsafmt, AudioFormat *fmt,
int *endianness)
 {
 switch (alsafmt) {
 case SND_PCM_FORMAT_S8:
 *endianness = 0;
-*fmt = AUD_FMT_S8;
+*fmt = AUDIO_FORMAT_S8;
 break;
 
 case SND_PCM_FORMAT_U8:
 *endianness = 0;
-*fmt = AUD_FMT_U8;
+*fmt = AUDIO_FORMAT_U8;
 break;
 
 case SND_PCM_FORMAT_S16_LE:
 *endianness = 0;
-*fmt = AUD_FMT_S16;
+*fmt = AUDIO_FORMAT_S16;
 break;
 
 case SND_PCM_FORMAT_U16_LE:
 *endianness = 0;
-*fmt = AUD_FMT_U16;
+*fmt = AUDIO_FORMAT_U16;
 break;
 
 case SND_PCM_FORMAT_S16_BE:
 *endianness = 1;
-*fmt = AUD_FMT_S16;
+*fmt = AUDIO_FORMAT_S16;
 break;
 
 case SND_PCM_FORMAT_U16_BE:
 *endianness = 1;
-*fmt = AUD_FMT_U16;
+

[Qemu-devel] [PATCH v6 06/14] coreaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/audio_legacy.c | 28 +
 audio/coreaudio.c| 49 ++--
 2 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
index f58c8b6aee..5f557a2de9 100644
--- a/audio/audio_legacy.c
+++ b/audio/audio_legacy.c
@@ -109,6 +109,17 @@ static uint32_t frames_to_usecs(uint32_t frames,
 return (frames * 100 + freq / 2) / freq;
 }
 
+
+static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
+AudiodevPerDirectionOptions *pdo)
+{
+const char *val = getenv(env);
+if (val) {
+*dst = frames_to_usecs(toui32(val), pdo);
+*has_dst = true;
+}
+}
+
 /* backend specific functions */
 /* ALSA */
 static void handle_alsa_per_direction(
@@ -156,6 +167,19 @@ static void handle_alsa(Audiodev *dev)
 &aopt->threshold, &aopt->has_threshold);
 }
 
+/* coreaudio */
+static void handle_coreaudio(Audiodev *dev)
+{
+get_frames_to_usecs(
+"QEMU_COREAUDIO_BUFFER_SIZE",
+&dev->u.coreaudio.out->buffer_length,
+&dev->u.coreaudio.out->has_buffer_length,
+qapi_AudiodevCoreaudioPerDirectionOptions_base(dev->u.coreaudio.out));
+get_int("QEMU_COREAUDIO_BUFFER_COUNT",
+&dev->u.coreaudio.out->buffer_count,
+&dev->u.coreaudio.out->has_buffer_count);
+}
+
 /* general */
 static void handle_per_direction(
 AudiodevPerDirectionOptions *pdo, const char *prefix)
@@ -201,6 +225,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
 handle_alsa(e->dev);
 break;
 
+case AUDIODEV_DRIVER_COREAUDIO:
+handle_coreaudio(e->dev);
+break;
+
 default:
 break;
 }
diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 7d4225dbee..1ee43b7d5f 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -36,11 +36,6 @@
 #define MAC_OS_X_VERSION_10_6 1060
 #endif
 
-typedef struct {
-int buffer_frames;
-int nbuffers;
-} CoreaudioConf;
-
 typedef struct coreaudioVoiceOut {
 HWVoiceOut hw;
 pthread_mutex_t mutex;
@@ -507,7 +502,9 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct 
audsettings *as,
 int err;
 const char *typ = "playback";
 AudioValueRange frameRange;
-CoreaudioConf *conf = drv_opaque;
+Audiodev *dev = drv_opaque;
+AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
+int frames;
 
 /* create mutex */
 err = pthread_mutex_init(&core->mutex, NULL);
@@ -538,16 +535,17 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct 
audsettings *as,
 return -1;
 }
 
-if (frameRange.mMinimum > conf->buffer_frames) {
+frames = audio_buffer_frames(
+qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610);
+if (frameRange.mMinimum > frames) {
 core->audioDevicePropertyBufferFrameSize = (UInt32) 
frameRange.mMinimum;
 dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
-}
-else if (frameRange.mMaximum < conf->buffer_frames) {
+} else if (frameRange.mMaximum < frames) {
 core->audioDevicePropertyBufferFrameSize = (UInt32) 
frameRange.mMaximum;
 dolog ("warning: Downsizing Buffer Frames to %f\n", 
frameRange.mMaximum);
 }
 else {
-core->audioDevicePropertyBufferFrameSize = conf->buffer_frames;
+core->audioDevicePropertyBufferFrameSize = frames;
 }
 
 /* set Buffer Frame Size */
@@ -568,7 +566,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct 
audsettings *as,
"Could not get device buffer frame size\n");
 return -1;
 }
-hw->samples = conf->nbuffers * core->audioDevicePropertyBufferFrameSize;
+hw->samples = (cpdo->has_buffer_count ? cpdo->buffer_count : 4) *
+core->audioDevicePropertyBufferFrameSize;
 
 /* get StreamFormat */
 status = coreaudio_get_streamformat(core->outputDeviceID,
@@ -680,40 +679,15 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, 
...)
 return 0;
 }
 
-static CoreaudioConf glob_conf = {
-.buffer_frames = 512,
-.nbuffers = 4,
-};
-
 static void *coreaudio_audio_init(Audiodev *dev)
 {
-CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
-*conf = glob_conf;
-
-return conf;
+return dev;
 }
 
 static void coreaudio_audio_fini (void *opaque)
 {
-g_free(opaque);
 }
 
-static struct audio_option coreaudio_options[] = {
-{
-.name  = "BUFFER_SIZE",
-.tag   = AUD_OPT_INT,
-.valp  = &glob_conf.buffer_frames,
-.descr = "Size of the buffer in frames"
-},
-{
-.name  = "BUFFER_COUNT",
-.tag   = AUD_OPT_INT,
-.valp  = &glob_conf.nbuffers,
-.descr = "Number of buffers"
-},
-{ /* End of list */ }
-};
-
 static struct audio_pcm_ops coreaudio_pcm_ops = {
 .init_out = coreaudio_init_out,
  

[Qemu-devel] [PATCH v6 07/14] dsoundaudio: port to -audiodev config

2019-03-08 Thread Kővágó, Zoltán
Signed-off-by: Kővágó, Zoltán 
---
 audio/dsound_template.h |  6 ++---
 audio/audio_legacy.c| 43 ++
 audio/dsoundaudio.c | 59 -
 3 files changed, 63 insertions(+), 45 deletions(-)

diff --git a/audio/dsound_template.h b/audio/dsound_template.h
index b439f33f58..8ece870c9e 100644
--- a/audio/dsound_template.h
+++ b/audio/dsound_template.h
@@ -167,17 +167,18 @@ static int dsound_init_out(HWVoiceOut *hw, struct 
audsettings *as,
 dsound *s = drv_opaque;
 WAVEFORMATEX wfx;
 struct audsettings obt_as;
-DSoundConf *conf = &s->conf;
 #ifdef DSBTYPE_IN
 const char *typ = "ADC";
 DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
 DSCBUFFERDESC bd;
 DSCBCAPS bc;
+AudiodevPerDirectionOptions *pdo = s->dev->u.dsound.in;
 #else
 const char *typ = "DAC";
 DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
 DSBUFFERDESC bd;
 DSBCAPS bc;
+AudiodevPerDirectionOptions *pdo = s->dev->u.dsound.out;
 #endif
 
 if (!s->FIELD2) {
@@ -193,8 +194,8 @@ static int dsound_init_out(HWVoiceOut *hw, struct 
audsettings *as,
 memset (&bd, 0, sizeof (bd));
 bd.dwSize = sizeof (bd);
 bd.lpwfxFormat = &wfx;
+bd.dwBufferBytes = audio_buffer_bytes(pdo, as, 92880);
 #ifdef DSBTYPE_IN
-bd.dwBufferBytes = conf->bufsize_in;
 hr = IDirectSoundCapture_CreateCaptureBuffer (
 s->dsound_capture,
 &bd,
@@ -203,7 +204,6 @@ static int dsound_init_out(HWVoiceOut *hw, struct 
audsettings *as,
 );
 #else
 bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
-bd.dwBufferBytes = conf->bufsize_out;
 hr = IDirectSound_CreateSoundBuffer (
 s->dsound,
 &bd,
diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
index 5f557a2de9..bf326bd360 100644
--- a/audio/audio_legacy.c
+++ b/audio/audio_legacy.c
@@ -120,6 +120,30 @@ static void get_frames_to_usecs(const char *env, uint32_t 
*dst, bool *has_dst,
 }
 }
 
+static uint32_t samples_to_usecs(uint32_t samples,
+ AudiodevPerDirectionOptions *pdo)
+{
+uint32_t channels = pdo->has_channels ? pdo->channels : 2;
+return frames_to_usecs(samples / channels, pdo);
+}
+
+static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions 
*pdo)
+{
+AudioFormat fmt = pdo->has_format ? pdo->format : AUDIO_FORMAT_S16;
+uint32_t bytes_per_sample = audioformat_bytes_per_sample(fmt);
+return samples_to_usecs(bytes / bytes_per_sample, pdo);
+}
+
+static void get_bytes_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
+   AudiodevPerDirectionOptions *pdo)
+{
+const char *val = getenv(env);
+if (val) {
+*dst = bytes_to_usecs(toui32(val), pdo);
+*has_dst = true;
+}
+}
+
 /* backend specific functions */
 /* ALSA */
 static void handle_alsa_per_direction(
@@ -180,6 +204,21 @@ static void handle_coreaudio(Audiodev *dev)
 &dev->u.coreaudio.out->has_buffer_count);
 }
 
+/* dsound */
+static void handle_dsound(Audiodev *dev)
+{
+get_millis_to_usecs("QEMU_DSOUND_LATENCY_MILLIS",
+&dev->u.dsound.latency, &dev->u.dsound.has_latency);
+get_bytes_to_usecs("QEMU_DSOUND_BUFSIZE_OUT",
+   &dev->u.dsound.out->buffer_length,
+   &dev->u.dsound.out->has_buffer_length,
+   dev->u.dsound.out);
+get_bytes_to_usecs("QEMU_DSOUND_BUFSIZE_IN",
+   &dev->u.dsound.in->buffer_length,
+   &dev->u.dsound.in->has_buffer_length,
+   dev->u.dsound.in);
+}
+
 /* general */
 static void handle_per_direction(
 AudiodevPerDirectionOptions *pdo, const char *prefix)
@@ -229,6 +268,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
 handle_coreaudio(e->dev);
 break;
 
+case AUDIODEV_DRIVER_DSOUND:
+handle_dsound(e->dev);
+break;
+
 default:
 break;
 }
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index 02fe777cba..a7d04b5033 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -32,6 +32,7 @@
 
 #define AUDIO_CAP "dsound"
 #include "audio_int.h"
+#include "qemu/host-utils.h"
 
 #include 
 #include 
@@ -42,17 +43,11 @@
 
 /* #define DEBUG_DSOUND */
 
-typedef struct {
-int bufsize_in;
-int bufsize_out;
-int latency_millis;
-} DSoundConf;
-
 typedef struct {
 LPDIRECTSOUND dsound;
 LPDIRECTSOUNDCAPTURE dsound_capture;
 struct audsettings settings;
-DSoundConf conf;
+Audiodev *dev;
 } dsound;
 
 typedef struct {
@@ -248,9 +243,9 @@ static void GCC_FMT_ATTR (3, 4) dsound_logerr2 (
 dsound_log_hresult (hr);
 }
 
-static DWORD millis_to_bytes (struct audio_pcm_info *info, DWORD millis)
+static uint64_t usecs_to_bytes(struct audio_pcm_info *info, uint32_t usecs)
 {
-return (millis * info->bytes_per_second) / 1000;
+return muldiv64(usecs, info->bytes_per_seco

[Qemu-devel] [PATCH v6 03/14] audio: -audiodev command line option: documentation

2019-03-08 Thread Kővágó, Zoltán
This patch adds documentation of an -audiodev command line option, that
deprecates the old QEMU_* environment variables for audio backend
configuration.  It's syntax is similar to existing options (-netdev,
-device, etc):

  -audiodev driver_name,property=value,...

Although now it's possible to specify multiple -audiodev options on
command line, multiple audio backends are not supported yet.

Signed-off-by: Kővágó, Zoltán 
---

Notes:
Changes from v4:

* deprecated QEMU_AUDIO_ env vars
* updated to reflect qapi changes
* added info to qemu-deprecated.texi

 qemu-deprecated.texi |   7 ++
 qemu-options.hx  | 236 ++-
 2 files changed, 240 insertions(+), 3 deletions(-)

diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
index 45c57952da..5c07ad4acb 100644
--- a/qemu-deprecated.texi
+++ b/qemu-deprecated.texi
@@ -60,6 +60,13 @@ Support for invalid topologies will be removed, the user 
must ensure
 topologies described with -smp include all possible cpus, i.e.
   @math{@var{sockets} * @var{cores} * @var{threads} = @var{maxcpus}}.
 
+@subsection QEMU_AUDIO_ environment variables and -audio-help (since 4.0)
+
+The ``-audiodev'' argument is now the preferred way to specify audio
+backend settings instead of environment variables.  To ease migration to
+the new format, the ``-audiodev-help'' option can be used to convert
+the current values of the environment variables to ``-audiodev'' options.
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
diff --git a/qemu-options.hx b/qemu-options.hx
index 1cf9aac1fe..52ea13e6a2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -416,14 +416,244 @@ The default is @code{en-us}.
 ETEXI
 
 
+HXCOMM Deprecated by -audiodev
 DEF("audio-help", 0, QEMU_OPTION_audio_help,
-"-audio-help print list of audio drivers and their options\n",
+"-audio-help show -audiodev equivalent of the currently specified 
audio settings\n",
 QEMU_ARCH_ALL)
 STEXI
 @item -audio-help
 @findex -audio-help
-Will show the audio subsystem help: list of drivers, tunable
-parameters.
+Will show the -audiodev equivalent of the currently specified
+(deprecated) environment variables.
+ETEXI
+
+DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev,
+"-audiodev [driver=]driver,id=id[,prop[=value][,...]]\n"
+"specifies the audio backend to use\n"
+"id= identifier of the backend\n"
+"timer-period= timer period in microseconds\n"
+"in|out.fixed-settings= use fixed settings for host 
audio\n"
+"in|out.frequency= frequency to use with fixed settings\n"
+"in|out.channels= number of channels to use with fixed 
settings\n"
+"in|out.format= sample format to use with fixed settings\n"
+"valid values: s8, s16, s32, u8, u16, u32\n"
+"in|out.voices= number of voices to use\n"
+"in|out.buffer-len= length of buffer in microseconds\n"
+"-audiodev none,id=id,[,prop[=value][,...]]\n"
+"dummy driver that discards all output\n"
+#ifdef CONFIG_AUDIO_ALSA
+"-audiodev alsa,id=id[,prop[=value][,...]]\n"
+"in|out.dev= name of the audio device to use\n"
+"in|out.period-len= length of period in microseconds\n"
+"in|out.try-poll= attempt to use poll mode\n"
+"threshold= threshold (in microseconds) when playback 
starts\n"
+#endif
+#ifdef CONFIG_AUDIO_COREAUDIO
+"-audiodev coreaudio,id=id[,prop[=value][,...]]\n"
+"in|out.buffer-count= number of buffers\n"
+#endif
+#ifdef CONFIG_AUDIO_DSOUND
+"-audiodev dsound,id=id[,prop[=value][,...]]\n"
+"latency= add extra latency to playback in microseconds\n"
+#endif
+#ifdef CONFIG_AUDIO_OSS
+"-audiodev oss,id=id[,prop[=value][,...]]\n"
+"in|out.dev= path of the audio device to use\n"
+"in|out.buffer-count= number of buffers\n"
+"in|out.try-poll= attempt to use poll mode\n"
+"try-mmap= try using memory mapped access\n"
+"exclusive= open device in exclusive mode\n"
+"dsp-policy= set timing policy (0..10), -1 to use fragment 
mode\n"
+#endif
+#ifdef CONFIG_AUDIO_PA
+"-audiodev pa,id=id[,prop[=value][,...]]\n"
+"server= PulseAudio server address\n"
+"in|out.name= source/sink device name\n"
+#endif
+#ifdef CONFIG_AUDIO_SDL
+"-audiodev sdl,id=id[,prop[=value][,...]]\n"
+#endif
+#ifdef CONFIG_SPICE
+"-audiodev spice,id=id[,prop[=value][,...]]\n"
+#endif
+"-audiodev wav,id=id[,prop[=value][,...]]\n"
+"path= path of wav file to record\n",
+QEMU_ARCH_ALL)
+STEXI
+@item -audiodev 
[driver=]@var{driver},id=@v

[Qemu-devel] [PATCH v6 00/14] Audio patches

2019-03-08 Thread Kővágó, Zoltán
Hi,

Here's an updated version of my audio patches.  Changes from v5:

* small qapi fixes
* fixed a bug in audio_create_pdos [1]

Regards,
Zoltan

[1]: https://lists.nongnu.org/archive/html/qemu-devel/2019-02/msg06842.html

Kővágó, Zoltán (14):
  qapi: qapi for audio backends
  audio: use qapi AudioFormat instead of audfmt_e
  audio: -audiodev command line option: documentation
  audio: -audiodev command line option basic implementation
  alsaaudio: port to -audiodev config
  coreaudio: port to -audiodev config
  dsoundaudio: port to -audiodev config
  noaudio: port to -audiodev config
  ossaudio: port to -audiodev config
  paaudio: port to -audiodev config
  sdlaudio: port to -audiodev config
  spiceaudio: port to -audiodev config
  wavaudio: port to -audiodev config
  audio: -audiodev command line option: cleanup

 qemu-deprecated.texi  |   7 +
 qapi/audio.json   | 304 ++
 qapi/qapi-schema.json |   1 +
 audio/audio.h |  30 +-
 audio/audio_int.h |  37 +-
 audio/audio_template.h|  42 +-
 audio/dsound_template.h   |   6 +-
 audio/alsaaudio.c | 368 ++--
 audio/audio.c | 859 +-
 audio/audio_legacy.c  | 544 
 audio/audio_win_int.c |  18 +-
 audio/coreaudio.c |  51 +--
 audio/dsoundaudio.c   |  61 +--
 audio/noaudio.c   |   3 +-
 audio/ossaudio.c  | 191 +++--
 audio/paaudio.c   | 111 ++---
 audio/sdlaudio.c  |  50 +--
 audio/spiceaudio.c|  11 +-
 audio/wavaudio.c  |  75 +---
 audio/wavcapture.c|   2 +-
 hw/arm/omap2.c|   2 +-
 hw/audio/ac97.c   |   2 +-
 hw/audio/adlib.c  |   2 +-
 hw/audio/cs4231a.c|   6 +-
 hw/audio/es1370.c |   4 +-
 hw/audio/gus.c|   2 +-
 hw/audio/hda-codec.c  |  18 +-
 hw/audio/lm4549.c |   6 +-
 hw/audio/milkymist-ac97.c |   2 +-
 hw/audio/pcspk.c  |   2 +-
 hw/audio/sb16.c   |  14 +-
 hw/audio/wm8750.c |   6 +-
 hw/display/xlnx_dp.c  |   2 +-
 hw/input/tsc210x.c|   2 +-
 hw/usb/dev-audio.c|   2 +-
 ui/vnc.c  |  26 +-
 vl.c  |   7 +-
 audio/Makefile.objs   |   2 +-
 qapi/Makefile.objs|   6 +-
 qemu-options.hx   | 236 ++-
 40 files changed, 1834 insertions(+), 1286 deletions(-)
 create mode 100644 qapi/audio.json
 create mode 100644 audio/audio_legacy.c

-- 
2.20.1




[Qemu-devel] [PATCH v6 01/14] qapi: qapi for audio backends

2019-03-08 Thread Kővágó, Zoltán
This patch adds structures into qapi to replace the existing
configuration structures used by audio backends currently. This qapi
will be the base of the -audiodev command line parameter (that replaces
the old environment variables based config).

This is not a 1:1 translation of the old options, I've tried to make
them much more consistent (e.g. almost every backend had an option to
specify buffer size, but the name was different for every backend, and
some backends required usecs, while some other required frames, samples
or bytes). Also tried to reduce the number of abbreviations used by the
config keys.

Some of the more important changes:
* use `in` and `out` instead of `ADC` and `DAC`, as the former is more
  user friendly imho
* moved buffer settings into the global setting area (so it's the same
  for all backends that support it. Backends that can't change buffer
  size will simply ignore them). Also using usecs, as it's probably more
  user friendly than samples or bytes.
* try-poll is now an alsa backend specific option (as all other backends
  currently ignore it)

Signed-off-by: Kővágó, Zoltán 
Reviewed-by: Markus Armbruster 
---

Notes:
Changes from v5:

* documentation fixes
* renamed buffer-len to buffer-length and period-len to period-length

Changes from v4:

* documentation fixes
* renamed pa's source/sink to pa-in/pa-out
* per-direction options changed per Markus Armbruster's comments

Changes from v2:

* update copyright, version numbers
* remove #optional
* per-direction options are now optional (needed for 
qobject_object_visitor_new_str)
* removed unnecessary AudiodevNoOptions
* changed integers to unsigned

 qapi/audio.json   | 304 ++
 qapi/qapi-schema.json |   1 +
 qapi/Makefile.objs|   6 +-
 3 files changed, 308 insertions(+), 3 deletions(-)
 create mode 100644 qapi/audio.json

diff --git a/qapi/audio.json b/qapi/audio.json
new file mode 100644
index 00..97aee37288
--- /dev/null
+++ b/qapi/audio.json
@@ -0,0 +1,304 @@
+# -*- mode: python -*-
+#
+# Copyright (C) 2015-2019 Zoltán Kővágó 
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# @AudiodevPerDirectionOptions:
+#
+# General audio backend options that are used for both playback and
+# recording.
+#
+# @fixed-settings: use fixed settings for host input/output. When off,
+#  frequency, channels and format must not be
+#  specified (default true)
+#
+# @frequency: frequency to use when using fixed settings
+# (default 44100)
+#
+# @channels: number of channels when using fixed settings (default 2)
+#
+# @voices: number of voices to use (default 1)
+#
+# @format: sample format to use when using fixed settings
+#  (default s16)
+#
+# @buffer-length: the buffer length in microseconds
+#
+# Since: 4.0
+##
+{ 'struct': 'AudiodevPerDirectionOptions',
+  'data': {
+'*fixed-settings': 'bool',
+'*frequency':  'uint32',
+'*channels':   'uint32',
+'*voices': 'uint32',
+'*format': 'AudioFormat',
+'*buffer-length':  'uint32' } }
+
+##
+# @AudiodevGenericOptions:
+#
+# Generic driver-specific options.
+#
+# @in: options of the capture stream
+#
+# @out: options of the playback stream
+#
+# Since: 4.0
+##
+{ 'struct': 'AudiodevGenericOptions',
+  'data': {
+'*in':  'AudiodevPerDirectionOptions',
+'*out': 'AudiodevPerDirectionOptions' } }
+
+##
+# @AudiodevAlsaPerDirectionOptions:
+#
+# Options of the ALSA backend that are used for both playback and
+# recording.
+#
+# @dev: the name of the ALSA device to use (default 'default')
+#
+# @period-length: the period length in microseconds
+#
+# @try-poll: attempt to use poll mode, falling back to non-polling
+#access on failure (default true)
+#
+# Since: 4.0
+##
+{ 'struct': 'AudiodevAlsaPerDirectionOptions',
+  'base': 'AudiodevPerDirectionOptions',
+  'data': {
+'*dev':   'str',
+'*period-length': 'uint32',
+'*try-poll':  'bool' } }
+
+##
+# @AudiodevAlsaOptions:
+#
+# Options of the ALSA audio backend.
+#
+# @in: options of the capture stream
+#
+# @out: options of the playback stream
+#
+# @threshold: set the threshold (in microseconds) when playback starts
+#
+# Since: 4.0
+##
+{ 'struct': 'AudiodevAlsaOptions',
+  'data': {
+'*in':'AudiodevAlsaPerDirectionOptions',
+'*out':   'AudiodevAlsaPerDirectionOptions',
+'*threshold': 'uint32' } }
+
+##
+# @AudiodevCoreaudioPerDirectionOptions:
+#
+# Options of the Core Audio backend that are used for both playback and
+# recording.
+#
+# @buffer-count: number of buffers
+#
+# Since: 4.0
+##
+{ 'struct': 'AudiodevCoreaudioPerDirectionOptions',
+  'base': 'AudiodevPerDirectionOptions',
+  'data': {
+'*buffer-count': 'uint32' } }
+
+##
+# @AudiodevCoreaudioOptions:
+#
+# 

Re: [Qemu-devel] [PATCH v4 2/6] vfio-ccw: rework ssch state handling

2019-03-08 Thread Eric Farman




On 03/01/2019 04:38 AM, Cornelia Huck wrote:

The flow for processing ssch requests can be improved by splitting
the BUSY state:

- CP_PROCESSING: We reject any user space requests while we are in
   the process of translating a channel program and submitting it to
   the hardware. Use -EAGAIN to signal user space that it should
   retry the request.
- CP_PENDING: We have successfully submitted a request with ssch and
   are now expecting an interrupt. As we can't handle more than one
   channel program being processed, reject any further requests with
   -EBUSY. A final interrupt will move us out of this state; this also
   fixes a latent bug where a non-final interrupt might have freed up
   a channel program that still was in progress.
   By making this a separate state, we make it possible to issue a
   halt or a clear while we're still waiting for the final interrupt
   for the ssch (in a follow-on patch).

It also makes a lot of sense not to preemptively filter out writes to
the io_region if we're in an incorrect state: the state machine will
handle this correctly.

Reviewed-by: Eric Farman 
Signed-off-by: Cornelia Huck 
---
  drivers/s390/cio/vfio_ccw_drv.c |  8 ++--
  drivers/s390/cio/vfio_ccw_fsm.c | 19 ++-
  drivers/s390/cio/vfio_ccw_ops.c |  2 --
  drivers/s390/cio/vfio_ccw_private.h |  3 ++-
  4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
index a10cec0e86eb..0b3b9de45c60 100644
--- a/drivers/s390/cio/vfio_ccw_drv.c
+++ b/drivers/s390/cio/vfio_ccw_drv.c
@@ -72,20 +72,24 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work)
  {
struct vfio_ccw_private *private;
struct irb *irb;
+   bool is_final;
  
  	private = container_of(work, struct vfio_ccw_private, io_work);

irb = &private->irb;
  
+	is_final = !(scsw_actl(&irb->scsw) &

+(SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT));
if (scsw_is_solicited(&irb->scsw)) {
cp_update_scsw(&private->cp, &irb->scsw);
-   cp_free(&private->cp);
+   if (is_final)
+   cp_free(&private->cp);
}
memcpy(private->io_region->irb_area, irb, sizeof(*irb));
  
  	if (private->io_trigger)

eventfd_signal(private->io_trigger, 1);
  
-	if (private->mdev)

+   if (private->mdev && is_final)
private->state = VFIO_CCW_STATE_IDLE;
  }
  


Coincidentally, I did something AWESOME last night that the chunks 
listed above actually fix.  I have a large channel program, and when it 
runs my host crashes which isn't nice.  First, the callback:


[  547.821235] Call Trace:
[  547.821236] ([<>]   (null))
[  547.821244]  [<03ff808d8b4a>] cp_prefetch+0x422/0x750 [vfio_ccw]
[  547.821247]  [<03ff808d9a90>] fsm_io_request+0x1a0/0x2f0 [vfio_ccw]
[  547.821250]  [<03ff808d90c4>] vfio_ccw_mdev_write+0xc4/0x1d8 
[vfio_ccw]

[  547.821255]  [<00358d8c>] __vfs_write+0x34/0x1a8
[  547.821256]  [<003590d0>] vfs_write+0xa0/0x1d8
[  547.821259]  [<00359572>] ksys_pwrite64+0x8a/0xa8
[  547.821264]  [<00866cf0>] system_call+0x270/0x290
[  547.821264] Last Breaking-Event-Address:
[  547.821267]  [<003325b2>] __kmalloc+0x1c2/0x288

The channel program in question looks like this:

x01 cmd=0b flags=44 count=0006
x02 cmd=02 flags=64 count=07bf
x03 cmd=47 flags=44 count=0010
x04 cmd=49 flags=64 count=049b
x05 cmd=08 flags=00 count= TIC to x04
x06 cmd=0b flags=64 count=0007
x07 cmd=23 flags=44 count=0001
x08 cmd=e4 flags=44 count=0018
x09 cmd=07 flags=44 count=0006
x0a cmd=e4 flags=44 count=0018
x0b cmd=47 flags=64 count=001b
x0c cmd=8e flags=64 count=013a
x0d cmd=9a flags=64 count=0009
x0e cmd=31 flags=4c count=0005
x0f cmd=08 flags=00 count= TIC to x0e
x10 cmd=0d flags=64 count=061b
x11 cmd=07 flags=64 count=000b
x12 cmd=96 flags=64 count=0144
x13 cmd=a9 flags=64 count=0025
x14 cmd=08 flags=00 count= TIC to x13
x15 cmd=05 flags=64 count=0387
x16 cmd=a4 flags=64 count=003e
x17 cmd=e4 flags=44 count=0018
x18 cmd=0b flags=64 count=000a
x19 cmd=96 flags=64 count=0497
x1a cmd=8e flags=64 count=02c3
x1b cmd=29 flags=64 count=01bf
x1c cmd=08 flags=00 count= TIC to x1b
x1d cmd=1b flags=24 count=000a

Debugging it today, I found that we get an intermediate interrupt on CCW 
0x0e, and a final interrupt (well, unit check) on CCW 0x11.  But because 
of the intermediate interrupt, rewinding in cp_prefetch() at label 
out_err fails and we crash.  Whoops!


Recalling the above changes, I applied JUST the above pieces (not the 
remainder of this patch), and the above channel program works fine.  Now 
to figure out why I get a unit check.  :)


 - Eric




[Qemu-devel] [PATCH] usb-mtp: fix return status of delete

2019-03-08 Thread Bandan Das


Spotted by Coverity: CID 1399414

mtp delete allows the a return status of delete succeeded,
partial_delete or readonly - when none of the objects could be
deleted.

Some initiators recurse over the objects themselves. In that case,
only READ_ONLY can be returned.

Signed-off-by: Bandan Das 
---
 hw/usb/dev-mtp.c | 25 +
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 06e376bcd2..e3401aad75 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1137,9 +1137,9 @@ static MTPData *usb_mtp_get_object_prop_value(MTPState 
*s, MTPControl *c,
 
 /* Return correct return code for a delete event */
 enum {
-ALL_DELETE,
-PARTIAL_DELETE,
+ALL_DELETE = 1,
 READ_ONLY,
+PARTIAL_DELETE,
 };
 
 /* Assumes that children, if any, have been already freed */
@@ -1155,8 +1155,7 @@ static void usb_mtp_object_free_one(MTPState *s, 
MTPObject *o)
 static int usb_mtp_deletefn(MTPState *s, MTPObject *o, uint32_t trans)
 {
 MTPObject *iter, *iter2;
-bool partial_delete = false;
-bool success = false;
+int ret = 0;
 
 /*
  * TODO: Add support for Protection Status
@@ -1165,34 +1164,28 @@ static int usb_mtp_deletefn(MTPState *s, MTPObject *o, 
uint32_t trans)
 QLIST_FOREACH(iter, &o->children, list) {
 if (iter->format == FMT_ASSOCIATION) {
 QLIST_FOREACH(iter2, &iter->children, list) {
-usb_mtp_deletefn(s, iter2, trans);
+ret |= usb_mtp_deletefn(s, iter2, trans);
 }
 }
 }
 
 if (o->format == FMT_UNDEFINED_OBJECT) {
 if (remove(o->path)) {
-partial_delete = true;
+ret |= READ_ONLY;
 } else {
 usb_mtp_object_free_one(s, o);
-success = true;
+ret |= ALL_DELETE;
 }
 } else if (o->format == FMT_ASSOCIATION) {
 if (rmdir(o->path)) {
-partial_delete = true;
+ret |= READ_ONLY;
 } else {
 usb_mtp_object_free_one(s, o);
-success = true;
+ret |= ALL_DELETE;
 }
 }
 
-if (success && partial_delete) {
-return PARTIAL_DELETE;
-}
-if (!success && partial_delete) {
-return READ_ONLY;
-}
-return ALL_DELETE;
+return ret;
 }
 
 static void usb_mtp_object_delete(MTPState *s, uint32_t handle,
-- 
2.19.2




Re: [Qemu-devel] [PATCH 2/5] block/qcow2-bitmap: Allow bitmap flushing

2019-03-08 Thread John Snow



On 3/6/19 11:12 AM, Vladimir Sementsov-Ogievskiy wrote:
> 06.03.2019 18:59, John Snow wrote:
>>
>>
>> On 3/6/19 7:58 AM, Eric Blake wrote:
>>> On 3/5/19 5:43 PM, John Snow wrote:
 Usually, we only write out bitmaps when we're about to close out the file,
 so we always remove the bitmaps after to make it easier to determine the
 source of truth for migration purposes.

 However, there may be times we want to flush bitmap data more aggressively,
 like after a truncate event where we need to make the metadata consistent
 again.
>>>
>>> Or, as I've mentioned in other threads, after every
>>> bitmap-add/bitmap-delete operation, so that 'qemu-img info -U' can see
>>> which persistent bitmaps exist. But that's one step further than this
>>> series, so I won't insist on it today.
>>>
>>
>> Yes, I was keeping that in mind as I wrote this. I think it extends to
>> those cases trivially, so long as Vladimir is OK with what I'm trying to do.
>>
> 
> I still don't see the point of flushing bitmaps, the only thing is optimizing
> qemu-img info --force-share, which should never used except for debugging.
> 
> So, at least, if we'll have it, I'd prefer bitmap flushing to be optional,
> and other code should not rely on it.
> 

I don't have plans to add more uses of it personally, but I do think
that resize represents a genuine case of wanting the feature.



Re: [Qemu-devel] [PATCH 1/5] block/qcow2-bitmap: Skip length check in some cases

2019-03-08 Thread John Snow



On 3/6/19 11:07 AM, Vladimir Sementsov-Ogievskiy wrote:
> 06.03.2019 2:43, John Snow wrote:
>> If we were to allow resizes, the length check that happens when we load
>> bitmap headers from disk when we read or store bitmaps would begin to
>> fail:
>>
>> Imagine the circumstance where we've resized bitmaps in memory, but they 
>> still
>> have the old values on-disk. The lengths will no longer match bdrv_getlength,
>> so we must allow this check to be skipped when flushing bitmaps to disk.
>>
>> Limit this to when we are about to overwrite the headers: we will verify the
>> outgoing headers, but we will skip verifying the known stale headers.
>>
>> Signed-off-by: John Snow 
>> ---
>>   block/qcow2-bitmap.c | 34 +-
>>   1 file changed, 21 insertions(+), 13 deletions(-)
>>
>> diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
>> index c3b210ede1..d02730004a 100644
>> --- a/block/qcow2-bitmap.c
>> +++ b/block/qcow2-bitmap.c
>> @@ -435,7 +435,8 @@ static inline Qcow2BitmapDirEntry 
>> *next_dir_entry(Qcow2BitmapDirEntry *entry)
>>   return (Qcow2BitmapDirEntry *)((uint8_t *)entry + 
>> dir_entry_size(entry));
>>   }
>>   
>> -static int check_dir_entry(BlockDriverState *bs, Qcow2BitmapDirEntry *entry)
>> +static int check_dir_entry(BlockDriverState *bs, Qcow2BitmapDirEntry *entry,
>> +   bool allow_resize)
>>   {
>>   BDRVQcow2State *s = bs->opaque;
>>   uint64_t phys_bitmap_bytes;
>> @@ -462,8 +463,14 @@ static int check_dir_entry(BlockDriverState *bs, 
>> Qcow2BitmapDirEntry *entry)
>>   return len;
>>   }
>>   
>> -fail = (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) ||
>> -   (len > ((phys_bitmap_bytes * 8) << entry->granularity_bits));
>> +if (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) {
>> +return -EINVAL;
>> +}
>> +
>> +if (!allow_resize &&
>> +(len > ((phys_bitmap_bytes * 8) << entry->granularity_bits))) {
>> +return -EINVAL;
>> +}
> 
> now I think, that we don't need additional parameter, but instead do this 
> check only if
> ! entry->flags & BME_FLAG_IN_USE, which will correspond to:
> 
> 1. incoming: bitmap loaded from image
> 2. outgoing: bitmap stored to the image
> 

I can't tell if I like this or not, because we'd skip checking the image
on load if it was improperly stored. I guess that's... fine.

Though, it would mean we also skip the consistency check on subsequent
re-reads of the bitmap list, which I think we still want if only as a
sanity check on the code, right?

Further thoughts?

(Maybe this portion of the code is due for a refactor in 4.1 so we can
add better error messages to it, like Eric suggests.)



Re: [Qemu-devel] [PATCH 0/5] QEMU VFIO live migration

2019-03-08 Thread Alex Williamson
On Fri, 8 Mar 2019 16:21:46 +
"Dr. David Alan Gilbert"  wrote:

> * Alex Williamson (alex.william...@redhat.com) wrote:
> > On Thu, 7 Mar 2019 23:20:36 +
> > "Tian, Kevin"  wrote:
> >   
> > > > From: Alex Williamson [mailto:alex.william...@redhat.com]
> > > > Sent: Friday, March 8, 2019 1:44 AM
> > > > > >
> > > > > > > This kind of data needs to be saved / loaded in pre-copy 
> > > > > > > and
> > > > > > > stop-and-copy phase.
> > > > > > > The data of device memory is held in device memory region.
> > > > > > > Size of devie memory is usually larger than that of device
> > > > > > > memory region. qemu needs to save/load it in chunks of 
> > > > > > > size of
> > > > > > > device memory region.
> > > > > > > Not all device has device memory. Like IGD only uses 
> > > > > > > system
> > > > memory.
> > > > > >
> > > > > > It seems a little gratuitous to me that this is a separate region or
> > > > > > that this data is handled separately.  All of this data is opaque to
> > > > > > QEMU, so why do we need to separate it?
> > > > > hi Alex,
> > > > > as the device state interfaces are provided by kernel, it is expected 
> > > > > to
> > > > > meet as general needs as possible. So, do you think there are such use
> > > > > cases from user space that user space knows well of the device, and
> > > > > it wants kernel to return desired data back to it.
> > > > > E.g. It just wants to get whole device config data including all 
> > > > > mmios,
> > > > > page tables, pci config data...
> > > > > or, It just wants to get current device memory snapshot, not 
> > > > > including any
> > > > > dirty data.
> > > > > Or, It just needs the dirty pages in device memory or system memory.
> > > > > With all this accurate query, quite a lot of useful features can be
> > > > > developped in user space.
> > > > >
> > > > > If all of this data is opaque to user app, seems the only use case is
> > > > > for live migration.
> > > > 
> > > > I can certainly appreciate a more versatile interface, but I think
> > > > we're also trying to create the most simple interface we can, with the
> > > > primary target being live migration.  As soon as we start defining this
> > > > type of device memory and that type of device memory, we're going to
> > > > have another device come along that needs yet another because they have
> > > > a slightly different requirement.  Even without that, we're going to
> > > > have vendor drivers implement it differently, so what works for one
> > > > device for a more targeted approach may not work for all devices.  Can
> > > > you enumerate some specific examples of the use cases you imagine your
> > > > design to enable?
> > > > 
> > > 
> > > Do we want to consider an use case where user space would like to
> > > selectively introspect a portion of the device state (including implicit 
> > > state which are not available through PCI regions), and may ask for
> > > capability of direct mapping of selected portion for scanning (e.g.
> > > device memory) instead of always turning on dirty logging on all
> > > device state?  
> > 
> > I don't see that a migration interface necessarily lends itself to this
> > use case.  A migration data stream has no requirement to be user
> > consumable as anything other than opaque data, there's also no
> > requirement that it expose state in a form that directly represents the
> > internal state of the device.  In fact I'm not sure we want to encourage
> > introspection via this data stream.  If a user knows how to interpret
> > the data, what prevents them from modifying the data in-flight?  I've
> > raised the question previously regarding how the vendor driver can
> > validate the integrity of the migration data stream.  Using the
> > migration interface to introspect the device certainly suggests an
> > interface ripe for exploiting any potential weakness in the vendor
> > driver reassembling that migration stream.  If the user has an mmap to
> > the actual live working state of the vendor driver, protection in the
> > hardware seems like the only way you could protect against a malicious
> > user.  Please be defensive in what is directly exposed to the user and
> > what safeguards are in place within the vendor driver for validating
> > incoming data.  Thanks,  
> 
> Hmm; that sounds like a security-by-obscurity answer!

Yup, that's fair.  I won't deny that in-kernel vendor driver state
passing through userspace from source to target systems scares me quite
a bit, but defining device introspection as a use case for the
migration interface imposes requirements on the vendor drivers that
don't otherwise exist.  Mdev vendor specific utilities could always be
written to interpret the migration stream to deduce the internal state,
but I think that imposing segregated device memory vs device config
regions with the expectation that internal state can be directly
tracked is beyon

Re: [Qemu-devel] [PATCH] bitmaps: Fix typo in function name

2019-03-08 Thread John Snow



On 3/8/19 3:58 PM, Eric Blake wrote:
> Commit a88b179f introduced the ability to set and query bitmap
> persistence, but with an atypical spelling.
> 
> Signed-off-by: Eric Blake 
> ---
> 
> Based-on: <20190308202858.26636-1-js...@redhat.com>
> [PULL 00/17 Bitmaps patches]
> (Don't know if John wants to do a v2 pull request to silence some
> checkpatch warnings, in which case this could sneak in...)
> 

Yes, I'll take it. Staged.

--js

>  include/block/dirty-bitmap.h   | 4 ++--
>  block/dirty-bitmap.c   | 4 ++--
>  block/qcow2-bitmap.c   | 6 +++---
>  blockdev.c | 4 ++--
>  migration/block-dirty-bitmap.c | 4 ++--
>  5 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
> index 2a782439547..8044ace63e4 100644
> --- a/include/block/dirty-bitmap.h
> +++ b/include/block/dirty-bitmap.h
> @@ -78,7 +78,7 @@ void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap 
> *bitmap,
>  void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
> 
>  void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
> -void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
> +void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap,
> bool persistent);
>  void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
>  void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
> @@ -103,7 +103,7 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, 
> int64_t bytes);
>  bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
>  bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
>  bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
> -bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
> +bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap);
>  bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
>  bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
>  BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
> diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
> index 59c403c3fd5..b08d4ec69ee 100644
> --- a/block/dirty-bitmap.c
> +++ b/block/dirty-bitmap.c
> @@ -739,7 +739,7 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs)
>  }
> 
>  /* Called with BQL taken. */
> -void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, bool 
> persistent)
> +void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, bool 
> persistent)
>  {
>  qemu_mutex_lock(bitmap->mutex);
>  bitmap->persistent = persistent;
> @@ -764,7 +764,7 @@ void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap 
> *bitmap, bool migration)
>  qemu_mutex_unlock(bitmap->mutex);
>  }
> 
> -bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap)
> +bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap)
>  {
>  return bitmap->persistent && !bitmap->migration;
>  }
> diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
> index 80926966de2..6adbe06b4d2 100644
> --- a/block/qcow2-bitmap.c
> +++ b/block/qcow2-bitmap.c
> @@ -968,7 +968,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error 
> **errp)
>  goto fail;
>  }
> 
> -bdrv_dirty_bitmap_set_persistance(bitmap, true);
> +bdrv_dirty_bitmap_set_persistence(bitmap, true);
>  if (bm->flags & BME_FLAG_IN_USE) {
>  bdrv_dirty_bitmap_set_inconsistent(bitmap);
>  } else {
> @@ -1426,7 +1426,7 @@ void 
> qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
>  uint32_t granularity = bdrv_dirty_bitmap_granularity(bitmap);
>  Qcow2Bitmap *bm;
> 
> -if (!bdrv_dirty_bitmap_get_persistance(bitmap) ||
> +if (!bdrv_dirty_bitmap_get_persistence(bitmap) ||
>  bdrv_dirty_bitmap_readonly(bitmap) ||
>  bdrv_dirty_bitmap_inconsistent(bitmap)) {
>  continue;
> @@ -1544,7 +1544,7 @@ int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error 
> **errp)
>  for (bitmap = bdrv_dirty_bitmap_next(bs, NULL); bitmap != NULL;
>   bitmap = bdrv_dirty_bitmap_next(bs, bitmap))
>  {
> -if (bdrv_dirty_bitmap_get_persistance(bitmap)) {
> +if (bdrv_dirty_bitmap_get_persistence(bitmap)) {
>  bdrv_dirty_bitmap_set_readonly(bitmap, true);
>  }
>  }
> diff --git a/blockdev.c b/blockdev.c
> index 51fcfb7faf1..267debda336 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -2862,7 +2862,7 @@ void qmp_block_dirty_bitmap_add(const char *node, const 
> char *name,
>  bdrv_disable_dirty_bitmap(bitmap);
>  }
> 
> -bdrv_dirty_bitmap_set_persistance(bitmap, persistent);
> +bdrv_dirty_bitmap_set_persistence(bitmap, persistent);
>   out:
>  if (aio_context) {
>  aio_context_release(aio_context);
> @@ -2887,7 +2887,7 @@ void qmp_block_dirty_bitmap_remove(const char *node, 
> const char *name,
>  

Re: [Qemu-devel] [PULL 00/17] Bitmaps patches

2019-03-08 Thread Eric Blake
On 3/8/19 2:28 PM, John Snow wrote:
> The following changes since commit 234afe78281b10a798fb97c584e1b677844aaab8:
> 
>   Merge remote-tracking branch 
> 'remotes/huth-gitlab/tags/pull-request-2019-03-08' into staging (2019-03-08 
> 16:31:34 +)
> 
> are available in the Git repository at:
> 
>   https://github.com/jnsnow/qemu.git tags/bitmaps-pull-request
> 
> for you to fetch changes up to fc91aa3d937e56d512c702d9b966fcea0e499f0e:
> 
>   block/dirty-bitmaps: implement inconsistent bit (2019-03-08 14:07:29 -0500)
> 
> 
> Pull request

Replying to the cover letter in case Peter doesn't see the nested reply:
NACK, v2 coming up for minor checkpatch fixes

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v3 3/3] vfio/display: delay link up event

2019-03-08 Thread Alex Williamson
On Fri, 22 Feb 2019 11:19:11 +
Liam Merwick  wrote:

> On 22/02/2019 05:49, Gerd Hoffmann wrote:
> > Kick the display link up event with a 0.1 sec delay,
> > so the guest has a chance to notice the link down first.
> > 
> > Signed-off-by: Gerd Hoffmann   
> 
> Depending on your thoughts on the suggestion in patch 1 regarding a 
> comment at the 'err' label - another candidate in 
> vfio_display_edid_link_up().

This would also get the following fixup rolled in.  Thanks,

Alex

 hw/vfio/display.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/vfio/display.c b/hw/vfio/display.c
index e8f312dc3308..a3d9c8f5beac 100644
--- a/hw/vfio/display.c
+++ b/hw/vfio/display.c
@@ -44,7 +44,9 @@ static void vfio_display_edid_link_up(void *opaque)
 int fd = vdev->vbasedev.fd;
 
 dpy->edid_regs->link_state = VFIO_DEVICE_GFX_LINK_STATE_UP;
-pwrite_field(fd, dpy->edid_info, dpy->edid_regs, link_state);
+if (pwrite_field(fd, dpy->edid_info, dpy->edid_regs, link_state)) {
+goto err;
+}
 trace_vfio_display_edid_link_up();
 return;
 



[Qemu-devel] [RFC PATCH] docs/booting.rst: start documenting the boot process

2019-03-08 Thread Alex Bennée
While working on some test cases I realised there was quite a lot of
assumed knowledge about how things boot up. I thought it would be
worth gathering this together in a user facing document where we could
pour in the details and background to the boot process. As it's quite
wordy I thought it should be a separate document to the manual (which
can obviously reference this). So far I've managed almost a thousand
words and haven't actually related anything to QEMU's options yet.

So going forward:

  - is this a useful document to have in docs?
  - are there any other areas to mention?
- out auto-magic -bios selection seems like something worth covering
  - should we have some worked examples of command lines?
- I was thinking for example of read-only and pflash examples
  - we should also describe why direct kernel boots exits
- and also the fact they are not that direct (some code executes
  before a kernel - even if it's less than a full firmware)

Submitted for comment

Signed-off-by: Alex Bennée 
---
 docs/booting.rst | 127 +++
 1 file changed, 127 insertions(+)
 create mode 100644 docs/booting.rst

diff --git a/docs/booting.rst b/docs/booting.rst
new file mode 100644
index 00..a8a644ff9a
--- /dev/null
+++ b/docs/booting.rst
@@ -0,0 +1,127 @@
+=
+Anatomy of a Boot, a QEMU perspective
+=
+
+This document attempts to give an overview of how machines boot-up and
+how this matters to QEMU. We will discuss firmware and BIOSes and the
+things they do before the OS kernel is loaded and your usable system
+is finally ready.
+
+Firmware
+
+
+When a CPU is powered up it knows nothing about it's environment. It's
+internal state, including the program counter (PC), will be reset to a
+defined set of values and it will attempt to fetch it's first
+instruction and execute it. It is the job of the firmware to bring a
+CPU up from it's first few instructions to running in a relatively
+sane execution environment. Firmware tends to be specific to the
+hardware in question and is stored on non-volatile memory (memory that
+survives a power off) usually a ROM or flash device on the computers
+main board.
+
+Some examples of what firmware does include:
+
+Early Hardware Setup
+
+
+Modern hardware often requires configuring before it is usable. For
+example most modern systems won't have working RAM until the memory
+controller has been programmed with the correct timings for whatever
+memory is installed on the system. Processors may boot with a very
+restricted view of the memory map until RAM and other key peripherals
+have been configured to appear in it's address space. Some hardware
+may not even appear until some sort of blob has been loaded into it so
+it can start responding to the CPU.
+
+Fortunately for QEMU we don't have to worry too much about this very
+low level configuration. The device model we present to the CPU at
+start-up will generally respond to IO access from processor straight
+away.
+
+BIOS or Firmware Services
+-
+
+In the early days of the PC era the BIOS or Basic Input/Output System
+provided an abstraction interface to the operating system which
+allowed them to do basic IO operations without having to directly
+drive the hardware. Since then the scope of these firmware services
+have grown as systems become more and more complex.
+
+Modern firmware often follows the Unified Extensible Firmware
+Interface (UEFI) which provides services like secure boot, persistent
+variables and external time-keeping.
+
+There can often be multiple levels of firmware service functions. For
+example systems which support secure execution enclaves generally have
+a firmware component that executes in this secure mode which the
+operating system can call in a defined secure manner to undertake
+security sensitive tasks on it's behalf.
+
+Hardware Enumeration
+
+
+It's easy to assume that modern hardware is built to be discover-able
+and all the operating system needs to do is enumerate the various
+buses on the system to find out what hardware exists. While buses like
+PCI and USB do support discovery there is usually much more on a
+modern system than just these two things.
+
+In the embedded world it used to be acceptable to have a custom
+compiled kernel which knew where everything is meant to be. However
+this was a brittle approach and not very flexible - most obviously if
+you try and use a kernel compiled for one piece of hardware on another
+piece of hardware that might nominally have the same processor.
+
+The more modern approach is to have a "generic" kernel that has a
+number of different drivers compiled in which are then enabled based
+on a hardware description provided by the firmware. This allows
+flexibility on both sides. The software distribution is less concerned
+about managing lo

Re: [Qemu-devel] [PATCH v3 1/3] vfio/display: add edid support.

2019-03-08 Thread Alex Williamson
On Fri, 22 Feb 2019 11:09:06 +
Liam Merwick  wrote:

> On 22/02/2019 05:49, Gerd Hoffmann wrote:
> > This patch adds EDID support to the vfio display (aka vgpu) code.
> > When supported by the mdev driver qemu will generate a EDID blob
> > and pass it on using the new vfio edid region.  The EDID blob will
> > be updated on UI changes (i.e. window resize), so the guest can
> > adapt.
> > 
> > Signed-off-by: Gerd Hoffmann 
> > ---
> >   include/hw/vfio/vfio-common.h |   3 +
> >   hw/vfio/display.c | 127 
> > ++
> >   hw/vfio/trace-events  |   7 +++
> >   3 files changed, 137 insertions(+)
> > 
> > diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> > index 7624c9f511c4..5f7f709b95f1 100644
> > --- a/include/hw/vfio/vfio-common.h
> > +++ b/include/hw/vfio/vfio-common.h
> > @@ -148,6 +148,9 @@ typedef struct VFIODMABuf {
> >   typedef struct VFIODisplay {
> >   QemuConsole *con;
> >   RAMFBState *ramfb;
> > +struct vfio_region_info *edid_info;
> > +struct vfio_region_gfx_edid *edid_regs;
> > +uint8_t *edid_blob;
> >   struct {
> >   VFIORegion buffer;
> >   DisplaySurface *surface;
> > diff --git a/hw/vfio/display.c b/hw/vfio/display.c
> > index dead30e626cb..f59fcc487128 100644
> > --- a/hw/vfio/display.c
> > +++ b/hw/vfio/display.c
> > @@ -15,15 +15,139 @@
> >   #include 
> >   
> >   #include "sysemu/sysemu.h"
> > +#include "hw/display/edid.h"
> >   #include "ui/console.h"
> >   #include "qapi/error.h"
> >   #include "pci.h"
> > +#include "trace.h"
> >   
> >   #ifndef DRM_PLANE_TYPE_PRIMARY
> >   # define DRM_PLANE_TYPE_PRIMARY 1
> >   # define DRM_PLANE_TYPE_CURSOR  2
> >   #endif
> >   
> > +#define pread_field(_fd, _reg, _ptr, _fld)  \
> > +if (sizeof(_ptr->_fld) !=   \
> > +pread(_fd, &(_ptr->_fld), sizeof(_ptr->_fld),   \
> > +  _reg->offset + offsetof(typeof(*_ptr), _fld)))\
> > +goto err;
> > +#define pwrite_field(_fd, _reg, _ptr, _fld) \
> > +if (sizeof(_ptr->_fld) !=   \
> > +pwrite(_fd, &(_ptr->_fld), sizeof(_ptr->_fld),  \
> > +   _reg->offset + offsetof(typeof(*_ptr), _fld)))   \
> > +goto err;
> > +
> > +
> > +static void vfio_display_edid_update(VFIOPCIDevice *vdev, bool enabled,
> > + int prefx, int prefy)
> > +{
> > +VFIODisplay *dpy = vdev->dpy;
> > +int fd = vdev->vbasedev.fd;
> > +qemu_edid_info edid = {
> > +.maxx  = dpy->edid_regs->max_xres,
> > +.maxy  = dpy->edid_regs->max_yres,
> > +.prefx = prefx,
> > +.prefy = prefy,
> > +};
> > +
> > +dpy->edid_regs->link_state = VFIO_DEVICE_GFX_LINK_STATE_DOWN;
> > +pwrite_field(fd, dpy->edid_info, dpy->edid_regs, link_state);
> > +trace_vfio_display_edid_link_down();
> > +
> > +if (!enabled) {
> > +return;
> > +}
> > +
> > +if (edid.maxx && edid.prefx > edid.maxx) {
> > +edid.prefx = edid.maxx;
> > +}
> > +if (edid.maxy && edid.prefy > edid.maxy) {
> > +edid.prefy = edid.maxy;
> > +}
> > +qemu_edid_generate(dpy->edid_blob,
> > +   dpy->edid_regs->edid_max_size,
> > +   &edid);
> > +trace_vfio_display_edid_update(edid.prefx, edid.prefy);
> > +
> > +dpy->edid_regs->edid_size = qemu_edid_size(dpy->edid_blob);
> > +pwrite_field(fd, dpy->edid_info, dpy->edid_regs, edid_size);
> > +if (pwrite(fd, dpy->edid_blob, dpy->edid_regs->edid_size,
> > +   dpy->edid_info->offset + dpy->edid_regs->edid_offset)
> > +!= dpy->edid_regs->edid_size) {
> > +goto err;
> > +}
> > +
> > +dpy->edid_regs->link_state = VFIO_DEVICE_GFX_LINK_STATE_UP;
> > +pwrite_field(fd, dpy->edid_info, dpy->edid_regs, link_state);
> > +trace_vfio_display_edid_link_up();
> > +return;
> > +
> > +err:
> > +trace_vfio_display_edid_write_error();
> > +return;
> > +}
> > +
> > +static int vfio_display_edid_ui_info(void *opaque, uint32_t idx,
> > + QemuUIInfo *info)
> > +{
> > +VFIOPCIDevice *vdev = opaque;
> > +VFIODisplay *dpy = vdev->dpy;
> > +
> > +if (!dpy->edid_regs) {
> > +return 0;
> > +}
> > +
> > +if (info->width && info->height) {
> > +vfio_display_edid_update(vdev, true, info->width, info->height);
> > +} else {
> > +vfio_display_edid_update(vdev, false, 0, 0);
> > +}
> > +
> > +return 0;
> > +}
> > +
> > +static void vfio_display_edid_init(VFIOPCIDevice *vdev)
> > +{
> > +VFIODisplay *dpy = vdev->dpy;
> > +int fd = vdev->vbasedev.fd;
> > +int ret;
> > +
> > +ret = vfio_get_dev_region_info(&vdev->vbasedev,
> > +   VFI

Re: [Qemu-devel] [PULL 00/17] Bitmaps patches

2019-03-08 Thread John Snow
Guess I'll fix these first, sorry for the noise.

On 3/8/19 3:53 PM, no-re...@patchew.org wrote:
> Patchew URL: https://patchew.org/QEMU/20190308202858.26636-1-js...@redhat.com/
> 
> 
> 
> Hi,
> 
> This series seems to have some coding style problems. See output below for
> more information:
> 
> Type: series
> Message-id: 20190308202858.26636-1-js...@redhat.com
> Subject: [Qemu-devel] [PULL 00/17] Bitmaps patches
> 
> === TEST SCRIPT BEGIN ===
> #!/bin/bash
> git rev-parse base > /dev/null || exit 0
> git config --local diff.renamelimit 0
> git config --local diff.renames True
> git config --local diff.algorithm histogram
> ./scripts/checkpatch.pl --mailback base..
> === TEST SCRIPT END ===
> 
> Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
> From https://github.com/patchew-project/qemu
>  t [tag update]patchew/20190308202858.26636-1-js...@redhat.com -> 
> patchew/20190308202858.26636-1-js...@redhat.com
> Switched to a new branch 'test'
> d67d39e43b block/dirty-bitmaps: implement inconsistent bit
> cc50ffdaaa block/dirty-bitmaps: disallow busy bitmaps as merge source
> fe93ecd8b1 block/dirty-bitmaps: prohibit removing readonly bitmaps
> 1d82e65c16 block/dirty-bitmaps: prohibit readonly bitmaps for backups
> 61c55a9de7 block/dirty-bitmaps: add block_dirty_bitmap_check function
> 4f1ceecd95 block/dirty-bitmap: add inconsistent status
> 9d5d76cbd6 block/dirty-bitmaps: add inconsistent bit
> bdc998d9d5 iotests: add busy/recording bit test to 124
> 22c03a2fd5 blockdev: remove unused paio parameter documentation
> d74e8a7202 block/dirty-bitmaps: move comment block
> 8ea8b7a875 block/dirty-bitmaps: unify qmp_locked and user_locked calls
> ae989ad6ff block/dirty-bitmap: explicitly lock bitmaps with successors
> 6c71258b44 nbd: change error checking order for bitmaps
> cf861d0168 block/dirty-bitmap: change semantics of enabled predicate
> 5ba70dfbcf block/dirty-bitmap: remove set/reset assertions against enabled bit
> 83886ed7db block/dirty-bitmaps: rename frozen predicate helper
> 0e38e3ff4f block/dirty-bitmap: add recording and busy properties
> 
> === OUTPUT BEGIN ===
> 1/17 Checking commit 0e38e3ff4ff4 (block/dirty-bitmap: add recording and busy 
> properties)
> 2/17 Checking commit 83886ed7db44 (block/dirty-bitmaps: rename frozen 
> predicate helper)
> WARNING: line over 80 characters
> #87: FILE: block/dirty-bitmap.c:248:
> +error_setg(errp, "Cannot create a successor for a bitmap that is 
> in-use "
> 
> total: 0 errors, 1 warnings, 124 lines checked
> 
> Patch 2/17 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
> 3/17 Checking commit 5ba70dfbcf19 (block/dirty-bitmap: remove set/reset 
> assertions against enabled bit)
> 4/17 Checking commit cf861d01687f (block/dirty-bitmap: change semantics of 
> enabled predicate)
> 5/17 Checking commit 6c71258b445a (nbd: change error checking order for 
> bitmaps)
> 6/17 Checking commit ae989ad6ffc7 (block/dirty-bitmap: explicitly lock 
> bitmaps with successors)
> 7/17 Checking commit 8ea8b7a8757e (block/dirty-bitmaps: unify qmp_locked and 
> user_locked calls)
> ERROR: open brace '{' following function declarations go on the next line
> #39: FILE: block/dirty-bitmap.c:190:
> +bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) {
> 
> total: 1 errors, 0 warnings, 271 lines checked
> 
> Patch 7/17 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
> 
> 8/17 Checking commit d74e8a720254 (block/dirty-bitmaps: move comment block)
> 9/17 Checking commit 22c03a2fd589 (blockdev: remove unused paio parameter 
> documentation)
> 10/17 Checking commit bdc998d9d5ed (iotests: add busy/recording bit test to 
> 124)
> 11/17 Checking commit 9d5d76cbd6ca (block/dirty-bitmaps: add inconsistent bit)
> WARNING: Block comments use a leading /* on a separate line
> #26: FILE: block/dirty-bitmap.c:49:
> +bool inconsistent;  /* bitmap is persistent, but inconsistent.
> 
> WARNING: Block comments use a trailing */ on a separate line
> #28: FILE: block/dirty-bitmap.c:51:
> + * a QMP user can remove it. */
> 
> total: 0 errors, 2 warnings, 82 lines checked
> 
> Patch 11/17 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
> 12/17 Checking commit 4f1ceecd9528 (block/dirty-bitmap: add inconsistent 
> status)
> 13/17 Checking commit 61c55a9de7e4 (block/dirty-bitmaps: add 
> block_dirty_bitmap_check function)
> ERROR: open brace '{' following function declarations go on the next line
> #37: FILE: block/dirty-bitmap.c:177:
> +static bool bdrv_dirty_bitmap_busy(const BdrvDirtyBitmap *bitmap) {
> 
> WARNING: line over 80 characters
> #284: FILE: migration/block-dirty-bitmap.c:305:
> +if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, 

Re: [Qemu-devel] [PATCH v3 2/2] machine: Move nvdimms state into struct MachineState

2019-03-08 Thread Philippe Mathieu-Daudé
On Fri, Mar 8, 2019 at 7:16 PM Auger Eric  wrote:
> Hi Philippe,
> On 3/8/19 7:02 PM, Philippe Mathieu-Daudé wrote:
> > hi Eric,
> >
> > On 3/8/19 4:25 PM, Eric Auger wrote:
> >> As NVDIMM support is looming for ARM and SPAPR, let's
> >> move the acpi_nvdimm_state to the generic machine struct
> >> instead of duplicating the same code in several machines.
> >> It is also renamed into nvdimms_state and becomes a pointer.
> >>
> >> nvdimm and nvdimm-persistence become generic machine options.
> >> They become guarded by a nvdimm_supported machine class member.
> >> We also add a description for those options.
> >>
> >> Signed-off-by: Eric Auger 
> >> Suggested-by: Igor Mammedov 
> >>
> >> ---
> >> v2 -> v3
> >> - nvdimms_state becomes a pointer
> >> - add machine class nvdimm_supported
> >>
> >> v1 -> v2:
> >> - s/acpi_nvdimm_state/nvdimms_state
> >> - remove ms->nvdimms_state.is_enabled initialization to false.
> >> ---
> >>  hw/core/machine.c| 65 
> >>  hw/i386/acpi-build.c |  6 ++--
> >>  hw/i386/pc.c | 57 --
> >>  hw/i386/pc_piix.c|  4 +--
> >>  hw/i386/pc_q35.c |  4 +--
> >>  include/hw/boards.h  |  2 ++
> >>  include/hw/i386/pc.h |  4 ---
> >>  7 files changed, 79 insertions(+), 63 deletions(-)
> >>
> >> diff --git a/hw/core/machine.c b/hw/core/machine.c
> >> index 766ca5899d..29a33194a9 100644
> >> --- a/hw/core/machine.c
> >> +++ b/hw/core/machine.c
> >> @@ -22,6 +22,7 @@
> >>  #include "qemu/error-report.h"
> >>  #include "sysemu/qtest.h"
> >>  #include "hw/pci/pci.h"
> >> +#include "hw/mem/nvdimm.h"
> >>
> >>  GlobalProperty hw_compat_3_1[] = {
> >>  { "pcie-root-port", "x-speed", "2_5" },
> >> @@ -481,6 +482,47 @@ static void machine_set_memory_encryption(Object 
> >> *obj, const char *value,
> >>  ms->memory_encryption = g_strdup(value);
> >>  }
> >>
> >> +static bool machine_get_nvdimm(Object *obj, Error **errp)
> >> +{
> >> +MachineState *ms = MACHINE(obj);
> >> +
> >> +return ms->nvdimms_state->is_enabled;
> >> +}
> >> +
> >> +static void machine_set_nvdimm(Object *obj, bool value, Error **errp)
> >> +{
> >> +MachineState *ms = MACHINE(obj);
> >> +
> >> +ms->nvdimms_state->is_enabled = value;
> >> +}
> >> +
> >> +static char *machine_get_nvdimm_persistence(Object *obj, Error **errp)
> >> +{
> >> +MachineState *ms = MACHINE(obj);
> >> +
> >> +return g_strdup(ms->nvdimms_state->persistence_string);
> >> +}
> >> +
> >> +static void machine_set_nvdimm_persistence(Object *obj, const char *value,
> >> +   Error **errp)
> >> +{
> >> +MachineState *ms = MACHINE(obj);
> >> +NVDIMMState *nvdimms_state = ms->nvdimms_state;
> >> +
> >> +if (strcmp(value, "cpu") == 0) {
> >> +nvdimms_state->persistence = 3;
> >> +} else if (strcmp(value, "mem-ctrl") == 0) {
> >> +nvdimms_state->persistence = 2;
> >> +} else {
> >> +error_setg(errp, "-machine nvdimm-persistence=%s: unsupported 
> >> option",
> >> +   value);
> >> +return;
> >> +}
> >> +
> >> +g_free(nvdimms_state->persistence_string);
> >> +nvdimms_state->persistence_string = g_strdup(value);
> >> +}
> >> +
> >>  void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char 
> >> *type)
> >>  {
> >>  strList *item = g_new0(strList, 1);
> >> @@ -791,6 +833,28 @@ static void machine_initfn(Object *obj)
> >>  ms->mem_merge = true;
> >>  ms->enable_graphics = true;
> >>
> >> +if (mc->nvdimm_supported) {
> >> +ObjectClass *oc = OBJECT_CLASS(mc);
> >> +
> >> +ms->nvdimms_state = g_new0(NVDIMMState, 1);
> >> +object_class_property_add_bool(oc, "nvdimm",
> >> +   machine_get_nvdimm, 
> >> machine_set_nvdimm,
> >> +   &error_abort);
> >> +object_class_property_set_description(oc, "nvdimm",
> >> + "Set on/off to 
> >> enable/disable "
> >> + "NVDIMM instantiation", 
> >> NULL);
> >> +
> >> +object_class_property_add_str(oc, "nvdimm-persistence",
> >> +  machine_get_nvdimm_persistence,
> >> +  machine_set_nvdimm_persistence,
> >> +  &error_abort);
> >> +object_class_property_set_description(oc, "nvdimm-persistence",
> >> + "Set NVDIMM persistence"
> >> + "Valid values are cpu, 
> >> mem-ctrl",
> >> +  NULL);
> >> +}
> >> +
> >> +
> >>  /* Register notifier when init is done for sysbus sanity checks */
> >>  ms->sysbus_notifier.notify = machine_init_notify;
> >>  qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
> >> @@ -809,6 +873

[Qemu-devel] [PATCH] bitmaps: Fix typo in function name

2019-03-08 Thread Eric Blake
Commit a88b179f introduced the ability to set and query bitmap
persistence, but with an atypical spelling.

Signed-off-by: Eric Blake 
---

Based-on: <20190308202858.26636-1-js...@redhat.com>
[PULL 00/17 Bitmaps patches]
(Don't know if John wants to do a v2 pull request to silence some
checkpatch warnings, in which case this could sneak in...)

 include/block/dirty-bitmap.h   | 4 ++--
 block/dirty-bitmap.c   | 4 ++--
 block/qcow2-bitmap.c   | 6 +++---
 blockdev.c | 4 ++--
 migration/block-dirty-bitmap.c | 4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index 2a782439547..8044ace63e4 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -78,7 +78,7 @@ void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap 
*bitmap,
 void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);

 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
-void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
+void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap,
bool persistent);
 void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
 void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
@@ -103,7 +103,7 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, 
int64_t bytes);
 bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
-bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
+bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap);
 bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 59c403c3fd5..b08d4ec69ee 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -739,7 +739,7 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs)
 }

 /* Called with BQL taken. */
-void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, bool 
persistent)
+void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, bool 
persistent)
 {
 qemu_mutex_lock(bitmap->mutex);
 bitmap->persistent = persistent;
@@ -764,7 +764,7 @@ void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap 
*bitmap, bool migration)
 qemu_mutex_unlock(bitmap->mutex);
 }

-bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap)
+bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap)
 {
 return bitmap->persistent && !bitmap->migration;
 }
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 80926966de2..6adbe06b4d2 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -968,7 +968,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error 
**errp)
 goto fail;
 }

-bdrv_dirty_bitmap_set_persistance(bitmap, true);
+bdrv_dirty_bitmap_set_persistence(bitmap, true);
 if (bm->flags & BME_FLAG_IN_USE) {
 bdrv_dirty_bitmap_set_inconsistent(bitmap);
 } else {
@@ -1426,7 +1426,7 @@ void 
qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
 uint32_t granularity = bdrv_dirty_bitmap_granularity(bitmap);
 Qcow2Bitmap *bm;

-if (!bdrv_dirty_bitmap_get_persistance(bitmap) ||
+if (!bdrv_dirty_bitmap_get_persistence(bitmap) ||
 bdrv_dirty_bitmap_readonly(bitmap) ||
 bdrv_dirty_bitmap_inconsistent(bitmap)) {
 continue;
@@ -1544,7 +1544,7 @@ int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error 
**errp)
 for (bitmap = bdrv_dirty_bitmap_next(bs, NULL); bitmap != NULL;
  bitmap = bdrv_dirty_bitmap_next(bs, bitmap))
 {
-if (bdrv_dirty_bitmap_get_persistance(bitmap)) {
+if (bdrv_dirty_bitmap_get_persistence(bitmap)) {
 bdrv_dirty_bitmap_set_readonly(bitmap, true);
 }
 }
diff --git a/blockdev.c b/blockdev.c
index 51fcfb7faf1..267debda336 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2862,7 +2862,7 @@ void qmp_block_dirty_bitmap_add(const char *node, const 
char *name,
 bdrv_disable_dirty_bitmap(bitmap);
 }

-bdrv_dirty_bitmap_set_persistance(bitmap, persistent);
+bdrv_dirty_bitmap_set_persistence(bitmap, persistent);
  out:
 if (aio_context) {
 aio_context_release(aio_context);
@@ -2887,7 +2887,7 @@ void qmp_block_dirty_bitmap_remove(const char *node, 
const char *name,
 return;
 }

-if (bdrv_dirty_bitmap_get_persistance(bitmap)) {
+if (bdrv_dirty_bitmap_get_persistence(bitmap)) {
 aio_context = bdrv_get_aio_context(bs);
 aio_context_acquire(aio_context);
 bdrv_remove_persistent_dirty_bitmap(bs, name, &local_err);
diff --git a/migrat

Re: [Qemu-devel] [PULL 00/17] Bitmaps patches

2019-03-08 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20190308202858.26636-1-js...@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190308202858.26636-1-js...@redhat.com
Subject: [Qemu-devel] [PULL 00/17] Bitmaps patches

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190308202858.26636-1-js...@redhat.com -> 
patchew/20190308202858.26636-1-js...@redhat.com
Switched to a new branch 'test'
d67d39e43b block/dirty-bitmaps: implement inconsistent bit
cc50ffdaaa block/dirty-bitmaps: disallow busy bitmaps as merge source
fe93ecd8b1 block/dirty-bitmaps: prohibit removing readonly bitmaps
1d82e65c16 block/dirty-bitmaps: prohibit readonly bitmaps for backups
61c55a9de7 block/dirty-bitmaps: add block_dirty_bitmap_check function
4f1ceecd95 block/dirty-bitmap: add inconsistent status
9d5d76cbd6 block/dirty-bitmaps: add inconsistent bit
bdc998d9d5 iotests: add busy/recording bit test to 124
22c03a2fd5 blockdev: remove unused paio parameter documentation
d74e8a7202 block/dirty-bitmaps: move comment block
8ea8b7a875 block/dirty-bitmaps: unify qmp_locked and user_locked calls
ae989ad6ff block/dirty-bitmap: explicitly lock bitmaps with successors
6c71258b44 nbd: change error checking order for bitmaps
cf861d0168 block/dirty-bitmap: change semantics of enabled predicate
5ba70dfbcf block/dirty-bitmap: remove set/reset assertions against enabled bit
83886ed7db block/dirty-bitmaps: rename frozen predicate helper
0e38e3ff4f block/dirty-bitmap: add recording and busy properties

=== OUTPUT BEGIN ===
1/17 Checking commit 0e38e3ff4ff4 (block/dirty-bitmap: add recording and busy 
properties)
2/17 Checking commit 83886ed7db44 (block/dirty-bitmaps: rename frozen predicate 
helper)
WARNING: line over 80 characters
#87: FILE: block/dirty-bitmap.c:248:
+error_setg(errp, "Cannot create a successor for a bitmap that is 
in-use "

total: 0 errors, 1 warnings, 124 lines checked

Patch 2/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/17 Checking commit 5ba70dfbcf19 (block/dirty-bitmap: remove set/reset 
assertions against enabled bit)
4/17 Checking commit cf861d01687f (block/dirty-bitmap: change semantics of 
enabled predicate)
5/17 Checking commit 6c71258b445a (nbd: change error checking order for bitmaps)
6/17 Checking commit ae989ad6ffc7 (block/dirty-bitmap: explicitly lock bitmaps 
with successors)
7/17 Checking commit 8ea8b7a8757e (block/dirty-bitmaps: unify qmp_locked and 
user_locked calls)
ERROR: open brace '{' following function declarations go on the next line
#39: FILE: block/dirty-bitmap.c:190:
+bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) {

total: 1 errors, 0 warnings, 271 lines checked

Patch 7/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

8/17 Checking commit d74e8a720254 (block/dirty-bitmaps: move comment block)
9/17 Checking commit 22c03a2fd589 (blockdev: remove unused paio parameter 
documentation)
10/17 Checking commit bdc998d9d5ed (iotests: add busy/recording bit test to 124)
11/17 Checking commit 9d5d76cbd6ca (block/dirty-bitmaps: add inconsistent bit)
WARNING: Block comments use a leading /* on a separate line
#26: FILE: block/dirty-bitmap.c:49:
+bool inconsistent;  /* bitmap is persistent, but inconsistent.

WARNING: Block comments use a trailing */ on a separate line
#28: FILE: block/dirty-bitmap.c:51:
+ * a QMP user can remove it. */

total: 0 errors, 2 warnings, 82 lines checked

Patch 11/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
12/17 Checking commit 4f1ceecd9528 (block/dirty-bitmap: add inconsistent status)
13/17 Checking commit 61c55a9de7e4 (block/dirty-bitmaps: add 
block_dirty_bitmap_check function)
ERROR: open brace '{' following function declarations go on the next line
#37: FILE: block/dirty-bitmap.c:177:
+static bool bdrv_dirty_bitmap_busy(const BdrvDirtyBitmap *bitmap) {

WARNING: line over 80 characters
#284: FILE: migration/block-dirty-bitmap.c:305:
+if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, 
&local_err)) {

total: 1 errors, 1 warnings, 236 lines checked

Patch 13/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

14/17 Checking commit 1d82e65c16d6 (block/dirty-bitmaps: prohibit readonly 
bitmaps for backups)
15/17

Re: [Qemu-devel] [PULL 00/54] Kconfig conversion, excluding ARM and MIPS

2019-03-08 Thread Eric Blake
On 3/6/19 4:12 AM, Thomas Huth wrote:
> On 05/03/2019 21.08, Eric Blake wrote:
> [...]
>> 'make distclean' is a heavy hammer, is there anything smaller in scope
>> that will fix the problem without nuking everything, such as a strategic
>> touch or rm of one particular file?
> 
> Try this in the top-level folder of your build directory:
> 
>  rm *.mak.d

Worked here, thanks!

> 
> ... not sure whether we can somehow integrate that into the Makefile
> magic, though...

I'm not sure either, nor did I want to spend time today trying.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PULL 00/17] Bitmaps patches

2019-03-08 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20190308202858.26636-1-js...@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190308202858.26636-1-js...@redhat.com
Subject: [Qemu-devel] [PULL 00/17] Bitmaps patches

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190308202858.26636-1-js...@redhat.com -> 
patchew/20190308202858.26636-1-js...@redhat.com
Switched to a new branch 'test'
3d5e719ca4 block/dirty-bitmaps: implement inconsistent bit
465831cd59 block/dirty-bitmaps: disallow busy bitmaps as merge source
31780545dd block/dirty-bitmaps: prohibit removing readonly bitmaps
7559e374a2 block/dirty-bitmaps: prohibit readonly bitmaps for backups
aa7d65f2c7 block/dirty-bitmaps: add block_dirty_bitmap_check function
c680f34e1a block/dirty-bitmap: add inconsistent status
144ff09b4a block/dirty-bitmaps: add inconsistent bit
3404fb4d3c iotests: add busy/recording bit test to 124
c1abe84ba0 blockdev: remove unused paio parameter documentation
a9cea08dae block/dirty-bitmaps: move comment block
0c7cb0afda block/dirty-bitmaps: unify qmp_locked and user_locked calls
0978398f68 block/dirty-bitmap: explicitly lock bitmaps with successors
359bac67ac nbd: change error checking order for bitmaps
03ca272dcf block/dirty-bitmap: change semantics of enabled predicate
39788c7010 block/dirty-bitmap: remove set/reset assertions against enabled bit
953dca788e block/dirty-bitmaps: rename frozen predicate helper
ad226cd02f block/dirty-bitmap: add recording and busy properties

=== OUTPUT BEGIN ===
1/17 Checking commit ad226cd02f0d (block/dirty-bitmap: add recording and busy 
properties)
2/17 Checking commit 953dca788e01 (block/dirty-bitmaps: rename frozen predicate 
helper)
WARNING: line over 80 characters
#87: FILE: block/dirty-bitmap.c:248:
+error_setg(errp, "Cannot create a successor for a bitmap that is 
in-use "

total: 0 errors, 1 warnings, 124 lines checked

Patch 2/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/17 Checking commit 39788c7010d2 (block/dirty-bitmap: remove set/reset 
assertions against enabled bit)
4/17 Checking commit 03ca272dcfe2 (block/dirty-bitmap: change semantics of 
enabled predicate)
5/17 Checking commit 359bac67ac40 (nbd: change error checking order for bitmaps)
6/17 Checking commit 0978398f6879 (block/dirty-bitmap: explicitly lock bitmaps 
with successors)
7/17 Checking commit 0c7cb0afdaff (block/dirty-bitmaps: unify qmp_locked and 
user_locked calls)
ERROR: open brace '{' following function declarations go on the next line
#39: FILE: block/dirty-bitmap.c:190:
+bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) {

total: 1 errors, 0 warnings, 271 lines checked

Patch 7/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

8/17 Checking commit a9cea08daeed (block/dirty-bitmaps: move comment block)
9/17 Checking commit c1abe84ba004 (blockdev: remove unused paio parameter 
documentation)
10/17 Checking commit 3404fb4d3ca7 (iotests: add busy/recording bit test to 124)
11/17 Checking commit 144ff09b4a7c (block/dirty-bitmaps: add inconsistent bit)
WARNING: Block comments use a leading /* on a separate line
#26: FILE: block/dirty-bitmap.c:49:
+bool inconsistent;  /* bitmap is persistent, but inconsistent.

WARNING: Block comments use a trailing */ on a separate line
#28: FILE: block/dirty-bitmap.c:51:
+ * a QMP user can remove it. */

total: 0 errors, 2 warnings, 82 lines checked

Patch 11/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
12/17 Checking commit c680f34e1af5 (block/dirty-bitmap: add inconsistent status)
13/17 Checking commit aa7d65f2c71f (block/dirty-bitmaps: add 
block_dirty_bitmap_check function)
ERROR: open brace '{' following function declarations go on the next line
#37: FILE: block/dirty-bitmap.c:177:
+static bool bdrv_dirty_bitmap_busy(const BdrvDirtyBitmap *bitmap) {

WARNING: line over 80 characters
#284: FILE: migration/block-dirty-bitmap.c:305:
+if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, 
&local_err)) {

total: 1 errors, 1 warnings, 236 lines checked

Patch 13/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

14/17 Checking commit 7559e374a22f (block/dirty-bitmaps: prohibit readonly 
bitmaps for backups)
15/17

Re: [Qemu-devel] [PULL 00/17] Bitmaps patches

2019-03-08 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20190308202858.26636-1-js...@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20190308202858.26636-1-js...@redhat.com
Subject: [Qemu-devel] [PULL 00/17] Bitmaps patches

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]   patchew/20190308202858.26636-1-js...@redhat.com -> 
patchew/20190308202858.26636-1-js...@redhat.com
Switched to a new branch 'test'
6a083e7a44 block/dirty-bitmaps: implement inconsistent bit
f00e672dd7 block/dirty-bitmaps: disallow busy bitmaps as merge source
ca8fdb5e18 block/dirty-bitmaps: prohibit removing readonly bitmaps
4085064d76 block/dirty-bitmaps: prohibit readonly bitmaps for backups
46e4307e40 block/dirty-bitmaps: add block_dirty_bitmap_check function
e0e53b95d2 block/dirty-bitmap: add inconsistent status
061152794d block/dirty-bitmaps: add inconsistent bit
20eb6ea4b5 iotests: add busy/recording bit test to 124
f0dea169fe blockdev: remove unused paio parameter documentation
5b090a904b block/dirty-bitmaps: move comment block
235c618265 block/dirty-bitmaps: unify qmp_locked and user_locked calls
9cd31200c1 block/dirty-bitmap: explicitly lock bitmaps with successors
0260a9c1c5 nbd: change error checking order for bitmaps
80fbc5114e block/dirty-bitmap: change semantics of enabled predicate
62a0dda136 block/dirty-bitmap: remove set/reset assertions against enabled bit
4d10356687 block/dirty-bitmaps: rename frozen predicate helper
8e21a1f266 block/dirty-bitmap: add recording and busy properties

=== OUTPUT BEGIN ===
1/17 Checking commit 8e21a1f266ae (block/dirty-bitmap: add recording and busy 
properties)
2/17 Checking commit 4d10356687c2 (block/dirty-bitmaps: rename frozen predicate 
helper)
WARNING: line over 80 characters
#87: FILE: block/dirty-bitmap.c:248:
+error_setg(errp, "Cannot create a successor for a bitmap that is 
in-use "

total: 0 errors, 1 warnings, 124 lines checked

Patch 2/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/17 Checking commit 62a0dda1369b (block/dirty-bitmap: remove set/reset 
assertions against enabled bit)
4/17 Checking commit 80fbc5114eb1 (block/dirty-bitmap: change semantics of 
enabled predicate)
5/17 Checking commit 0260a9c1c566 (nbd: change error checking order for bitmaps)
6/17 Checking commit 9cd31200c142 (block/dirty-bitmap: explicitly lock bitmaps 
with successors)
7/17 Checking commit 235c61826568 (block/dirty-bitmaps: unify qmp_locked and 
user_locked calls)
ERROR: open brace '{' following function declarations go on the next line
#39: FILE: block/dirty-bitmap.c:190:
+bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) {

total: 1 errors, 0 warnings, 271 lines checked

Patch 7/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

8/17 Checking commit 5b090a904b91 (block/dirty-bitmaps: move comment block)
9/17 Checking commit f0dea169fe5e (blockdev: remove unused paio parameter 
documentation)
10/17 Checking commit 20eb6ea4b57a (iotests: add busy/recording bit test to 124)
11/17 Checking commit 061152794d63 (block/dirty-bitmaps: add inconsistent bit)
WARNING: Block comments use a leading /* on a separate line
#26: FILE: block/dirty-bitmap.c:49:
+bool inconsistent;  /* bitmap is persistent, but inconsistent.

WARNING: Block comments use a trailing */ on a separate line
#28: FILE: block/dirty-bitmap.c:51:
+ * a QMP user can remove it. */

total: 0 errors, 2 warnings, 82 lines checked

Patch 11/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
12/17 Checking commit e0e53b95d21c (block/dirty-bitmap: add inconsistent status)
13/17 Checking commit 46e4307e401e (block/dirty-bitmaps: add 
block_dirty_bitmap_check function)
ERROR: open brace '{' following function declarations go on the next line
#37: FILE: block/dirty-bitmap.c:177:
+static bool bdrv_dirty_bitmap_busy(const BdrvDirtyBitmap *bitmap) {

WARNING: line over 80 characters
#284: FILE: migration/block-dirty-bitmap.c:305:
+if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, 
&local_err)) {

total: 1 errors, 1 warnings, 236 lines checked

Patch 13/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

14/17 Checking commit 4085064d763d (block/dirty-bitmaps: prohibit readonly 
bitmaps for backups)
15/17

[Qemu-devel] [PULL 13/17] block/dirty-bitmaps: add block_dirty_bitmap_check function

2019-03-08 Thread John Snow
Instead of checking against busy, inconsistent, or read only directly,
use a check function with permissions bits that let us streamline the
checks without reproducing them in many places.

Included in this patch are permissions changes that simply add the
inconsistent check to existing permissions call spots, without
addressing existing bugs.

In general, this means that busy+readonly checks become BDRV_BITMAP_DEFAULT,
which checks against all three conditions. busy-only checks become
BDRV_BITMAP_ALLOW_RO.

Notably, remove allows inconsistent bitmaps, so it doesn't follow the pattern.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190301191545.8728-4-js...@redhat.com
Signed-off-by: John Snow 
---
 include/block/dirty-bitmap.h   | 13 -
 block/dirty-bitmap.c   | 42 -
 blockdev.c | 49 +++---
 migration/block-dirty-bitmap.c | 12 +++--
 nbd/server.c   |  3 +--
 5 files changed, 55 insertions(+), 64 deletions(-)

diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index bd1b6479df..2a78243954 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -5,6 +5,16 @@
 #include "qapi/qapi-types-block-core.h"
 #include "qemu/hbitmap.h"
 
+typedef enum BitmapCheckFlags {
+BDRV_BITMAP_BUSY = 1,
+BDRV_BITMAP_RO = 2,
+BDRV_BITMAP_INCONSISTENT = 4,
+} BitmapCheckFlags;
+
+#define BDRV_BITMAP_DEFAULT (BDRV_BITMAP_BUSY | BDRV_BITMAP_RO |\
+ BDRV_BITMAP_INCONSISTENT)
+#define BDRV_BITMAP_ALLOW_RO (BDRV_BITMAP_BUSY | BDRV_BITMAP_INCONSISTENT)
+
 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
   uint32_t granularity,
   const char *name,
@@ -24,6 +34,8 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState 
*bs,
 void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
 const char *name);
+int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
+Error **errp);
 void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
 void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs,
@@ -93,7 +105,6 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
 bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
 bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
-bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap);
 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
 BdrvDirtyBitmap *bitmap);
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 987ea7ca29..6b6fed1363 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -174,7 +174,7 @@ bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap 
*bitmap)
 return bitmap->successor;
 }
 
-bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) {
+static bool bdrv_dirty_bitmap_busy(const BdrvDirtyBitmap *bitmap) {
 return bitmap->busy;
 }
 
@@ -235,6 +235,33 @@ static bool bdrv_dirty_bitmap_recording(BdrvDirtyBitmap 
*bitmap)
  !bitmap->successor->disabled);
 }
 
+int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
+Error **errp)
+{
+if ((flags & BDRV_BITMAP_BUSY) && bdrv_dirty_bitmap_busy(bitmap)) {
+error_setg(errp, "Bitmap '%s' is currently in use by another"
+   " operation and cannot be used", bitmap->name);
+return -1;
+}
+
+if ((flags & BDRV_BITMAP_RO) && bdrv_dirty_bitmap_readonly(bitmap)) {
+error_setg(errp, "Bitmap '%s' is readonly and cannot be modified",
+   bitmap->name);
+return -1;
+}
+
+if ((flags & BDRV_BITMAP_INCONSISTENT) &&
+bdrv_dirty_bitmap_inconsistent(bitmap)) {
+error_setg(errp, "Bitmap '%s' is inconsistent and cannot be used",
+   bitmap->name);
+error_append_hint(errp, "Try block-dirty-bitmap-remove to delete"
+  " this bitmap from disk");
+return -1;
+}
+
+return 0;
+}
+
 /**
  * Create a successor bitmap destined to replace this bitmap after an 
operation.
  * Requires that the bitmap is not marked busy and has no successor.
@@ -247,9 +274,7 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
 uint64_t granularity;
 BdrvDirtyBitmap *child;
 
-if (bdrv_dirty_bitmap_busy(bitmap)) {
-error_setg(errp, "Cannot create a successor for a bitmap that is 
in-use "

[Qemu-devel] [PULL 12/17] block/dirty-bitmap: add inconsistent status

2019-03-08 Thread John Snow
Even though the status field is deprecated, we still have to support
it for a few more releases. Since this is a very new kind of bitmap
state, it makes sense for it to have its own status field.

Reviewed-by: Eric Blake 
Signed-off-by: John Snow 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190301191545.8728-3-js...@redhat.com
Signed-off-by: John Snow 
---
 qapi/block-core.json | 7 ++-
 block/dirty-bitmap.c | 7 ++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index e639ef6d1c..ae55cd0704 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -442,10 +442,15 @@
 #  recording new writes. If the bitmap was @disabled, it is not
 #  recording new writes. (Since 2.12)
 #
+# @inconsistent: This is a persistent dirty bitmap that was marked in-use on
+#disk, and is unusable by QEMU. It can only be deleted.
+#Please rely on the inconsistent field in @BlockDirtyInfo
+#instead, as the status field is deprecated. (Since 4.0)
+#
 # Since: 2.4
 ##
 { 'enum': 'DirtyBitmapStatus',
-  'data': ['active', 'disabled', 'frozen', 'locked'] }
+  'data': ['active', 'disabled', 'frozen', 'locked', 'inconsistent'] }
 
 ##
 # @BlockDirtyInfo:
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index c611bfb971..987ea7ca29 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -209,10 +209,15 @@ bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap)
  *   or it can be Disabled and not recording writes.
  * (4) Locked:   Whether Active or Disabled, the user cannot modify this bitmap
  *   in any way from the monitor.
+ * (5) Inconsistent: This is a persistent bitmap whose "in use" bit is set, and
+ *   is unusable by QEMU. It can be deleted to remove it from
+ *   the qcow2.
  */
 DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap)
 {
-if (bdrv_dirty_bitmap_has_successor(bitmap)) {
+if (bdrv_dirty_bitmap_inconsistent(bitmap)) {
+return DIRTY_BITMAP_STATUS_INCONSISTENT;
+} else if (bdrv_dirty_bitmap_has_successor(bitmap)) {
 return DIRTY_BITMAP_STATUS_FROZEN;
 } else if (bdrv_dirty_bitmap_busy(bitmap)) {
 return DIRTY_BITMAP_STATUS_LOCKED;
-- 
2.17.2




[Qemu-devel] [PULL 17/17] block/dirty-bitmaps: implement inconsistent bit

2019-03-08 Thread John Snow
Set the inconsistent bit on load instead of rejecting such bitmaps.
There is no way to un-set it; the only option is to delete the bitmap.

Obvervations:
- bitmap loading does not need to update the header for in_use bitmaps.
- inconsistent bitmaps don't need to have their data loaded; they're
  glorified corruption sentinels.
- bitmap saving does not need to save inconsistent bitmaps back to disk.
- bitmap reopening DOES need to drop the readonly flag from inconsistent
  bitmaps to allow reopening of qcow2 files with non-qemu-owned bitmaps
  being eventually flushed back to disk.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Message-id: 20190301191545.8728-8-js...@redhat.com
Signed-off-by: John Snow 
---
 block/qcow2-bitmap.c | 103 ++-
 1 file changed, 53 insertions(+), 50 deletions(-)

diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 3ee524da4b..80926966de 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -343,9 +343,15 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
 uint32_t granularity;
 BdrvDirtyBitmap *bitmap = NULL;
 
+granularity = 1U << bm->granularity_bits;
+bitmap = bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp);
+if (bitmap == NULL) {
+goto fail;
+}
+
 if (bm->flags & BME_FLAG_IN_USE) {
-error_setg(errp, "Bitmap '%s' is in use", bm->name);
-goto fail;
+/* Data is unusable, skip loading it */
+return bitmap;
 }
 
 ret = bitmap_table_load(bs, &bm->table, &bitmap_table);
@@ -356,12 +362,6 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
 goto fail;
 }
 
-granularity = 1U << bm->granularity_bits;
-bitmap = bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp);
-if (bitmap == NULL) {
-goto fail;
-}
-
 ret = load_bitmap_data(bs, bitmap_table, bm->table.size, bitmap);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not read bitmap '%s' from image",
@@ -949,6 +949,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error 
**errp)
 Qcow2Bitmap *bm;
 GSList *created_dirty_bitmaps = NULL;
 bool header_updated = false;
+bool needs_update = false;
 
 if (s->nb_bitmaps == 0) {
 /* No bitmaps - nothing to do */
@@ -962,35 +963,39 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error 
**errp)
 }
 
 QSIMPLEQ_FOREACH(bm, bm_list, entry) {
-if (!(bm->flags & BME_FLAG_IN_USE)) {
-BdrvDirtyBitmap *bitmap = load_bitmap(bs, bm, errp);
-if (bitmap == NULL) {
-goto fail;
-}
-
-if (!(bm->flags & BME_FLAG_AUTO)) {
-bdrv_disable_dirty_bitmap(bitmap);
-}
-bdrv_dirty_bitmap_set_persistance(bitmap, true);
-bm->flags |= BME_FLAG_IN_USE;
-created_dirty_bitmaps =
-g_slist_append(created_dirty_bitmaps, bitmap);
+BdrvDirtyBitmap *bitmap = load_bitmap(bs, bm, errp);
+if (bitmap == NULL) {
+goto fail;
 }
-}
 
-if (created_dirty_bitmaps != NULL) {
-if (can_write(bs)) {
-/* in_use flags must be updated */
-int ret = update_ext_header_and_dir_in_place(bs, bm_list);
-if (ret < 0) {
-error_setg_errno(errp, -ret, "Can't update bitmap directory");
-goto fail;
-}
-header_updated = true;
+bdrv_dirty_bitmap_set_persistance(bitmap, true);
+if (bm->flags & BME_FLAG_IN_USE) {
+bdrv_dirty_bitmap_set_inconsistent(bitmap);
 } else {
-g_slist_foreach(created_dirty_bitmaps, set_readonly_helper,
-(gpointer)true);
+/* NB: updated flags only get written if can_write(bs) is true. */
+bm->flags |= BME_FLAG_IN_USE;
+needs_update = true;
 }
+if (!(bm->flags & BME_FLAG_AUTO)) {
+bdrv_disable_dirty_bitmap(bitmap);
+}
+created_dirty_bitmaps =
+g_slist_append(created_dirty_bitmaps, bitmap);
+}
+
+if (needs_update && can_write(bs)) {
+/* in_use flags must be updated */
+int ret = update_ext_header_and_dir_in_place(bs, bm_list);
+if (ret < 0) {
+error_setg_errno(errp, -ret, "Can't update bitmap directory");
+goto fail;
+}
+header_updated = true;
+}
+
+if (!can_write(bs)) {
+g_slist_foreach(created_dirty_bitmaps, set_readonly_helper,
+(gpointer)true);
 }
 
 g_slist_free(created_dirty_bitmaps);
@@ -1112,23 +1117,21 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, 
bool *header_updated,
 }
 
 QSIMPLEQ_FOREACH(bm, bm_list, entry) {
-if (!(bm->flags & BME_FLAG_IN_USE)) {
-BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(bs, bm->name);
-if (bitmap == NU

Re: [Qemu-devel] [PATCH v4 2/2] machine: Move nvdimms state into struct MachineState

2019-03-08 Thread Eduardo Habkost
On Fri, Mar 08, 2019 at 07:20:53PM +0100, Eric Auger wrote:
> As NVDIMM support is looming for ARM and SPAPR, let's
> move the acpi_nvdimm_state to the generic machine struct
> instead of duplicating the same code in several machines.
> It is also renamed into nvdimms_state and becomes a pointer.
> 
> nvdimm and nvdimm-persistence become generic machine options.
> They become guarded by a nvdimm_supported machine class member.
> We also add a description for those options.
> 
> Signed-off-by: Eric Auger 
> Suggested-by: Igor Mammedov 
> 
> ---
> v3 -> v4:
> - s/object_class_property_*/object_property_*
> v2 -> v3
> - nvdimms_state becomes a pointer
> - add machine class nvdimm_supported
> 
> v1 -> v2:
> - s/acpi_nvdimm_state/nvdimms_state
> - remove ms->nvdimms_state.is_enabled initialization to false.
> ---
>  hw/core/machine.c| 65 
>  hw/i386/acpi-build.c |  6 ++--
>  hw/i386/pc.c | 57 --
>  hw/i386/pc_piix.c|  4 +--
>  hw/i386/pc_q35.c |  4 +--
>  include/hw/boards.h  |  2 ++
>  include/hw/i386/pc.h |  4 ---
>  7 files changed, 79 insertions(+), 63 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 766ca5899d..743fef2898 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -22,6 +22,7 @@
>  #include "qemu/error-report.h"
>  #include "sysemu/qtest.h"
>  #include "hw/pci/pci.h"
> +#include "hw/mem/nvdimm.h"
>  
>  GlobalProperty hw_compat_3_1[] = {
>  { "pcie-root-port", "x-speed", "2_5" },
> @@ -481,6 +482,47 @@ static void machine_set_memory_encryption(Object *obj, 
> const char *value,
>  ms->memory_encryption = g_strdup(value);
>  }
>  
> +static bool machine_get_nvdimm(Object *obj, Error **errp)
> +{
> +MachineState *ms = MACHINE(obj);
> +
> +return ms->nvdimms_state->is_enabled;
> +}
> +
> +static void machine_set_nvdimm(Object *obj, bool value, Error **errp)
> +{
> +MachineState *ms = MACHINE(obj);
> +
> +ms->nvdimms_state->is_enabled = value;
> +}
> +
> +static char *machine_get_nvdimm_persistence(Object *obj, Error **errp)
> +{
> +MachineState *ms = MACHINE(obj);
> +
> +return g_strdup(ms->nvdimms_state->persistence_string);
> +}
> +
> +static void machine_set_nvdimm_persistence(Object *obj, const char *value,
> +   Error **errp)
> +{
> +MachineState *ms = MACHINE(obj);
> +NVDIMMState *nvdimms_state = ms->nvdimms_state;
> +
> +if (strcmp(value, "cpu") == 0) {
> +nvdimms_state->persistence = 3;
> +} else if (strcmp(value, "mem-ctrl") == 0) {
> +nvdimms_state->persistence = 2;
> +} else {
> +error_setg(errp, "-machine nvdimm-persistence=%s: unsupported 
> option",
> +   value);
> +return;
> +}
> +
> +g_free(nvdimms_state->persistence_string);
> +nvdimms_state->persistence_string = g_strdup(value);
> +}
> +
>  void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char 
> *type)
>  {
>  strList *item = g_new0(strList, 1);
> @@ -791,6 +833,28 @@ static void machine_initfn(Object *obj)
>  ms->mem_merge = true;
>  ms->enable_graphics = true;
>  
> +if (mc->nvdimm_supported) {
> +Object *obj = OBJECT(ms);
> +
> +ms->nvdimms_state = g_new0(NVDIMMState, 1);
> +object_property_add_bool(obj, "nvdimm",
> + machine_get_nvdimm, machine_set_nvdimm,
> + &error_abort);
> +object_property_set_description(obj, "nvdimm",
> +"Set on/off to enable/disable "
> +"NVDIMM instantiation", NULL);
> +
> +object_property_add_str(obj, "nvdimm-persistence",
> +machine_get_nvdimm_persistence,
> +machine_set_nvdimm_persistence,
> +&error_abort);
> +object_property_set_description(obj, "nvdimm-persistence",
> +"Set NVDIMM persistence"
> +"Valid values are cpu, mem-ctrl",
> +NULL);
> +}

It's a pity that we are moving away from class properties back to
instance properties here, but we have no code today that rely on
class properties only.  For example, "-machine pc,help" still
shows the nvdimm properties with this patch.

Reviewed-by: Eduardo Habkost 

I will wait until Monday to queue it on machine-next.


> +
> +
>  /* Register notifier when init is done for sysbus sanity checks */
>  ms->sysbus_notifier.notify = machine_init_notify;
>  qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
> @@ -809,6 +873,7 @@ static void machine_finalize(Object *obj)
>  g_free(ms->dt_compatible);
>  g_free(ms->firmware);
>  g_free(ms->device_memory);
> +g_free(ms->nvdimms_state);
>  }
>  
>  bool

[Qemu-devel] [PULL 15/17] block/dirty-bitmaps: prohibit removing readonly bitmaps

2019-03-08 Thread John Snow
Remove is an inherently RW operation, so this will fail anyway, but
we can fail it very quickly instead of trying and failing, so do so.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190301191545.8728-6-js...@redhat.com
Signed-off-by: John Snow 
---
 blockdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index c6c7a64bfc..51fcfb7faf 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2882,7 +2882,8 @@ void qmp_block_dirty_bitmap_remove(const char *node, 
const char *name,
 return;
 }
 
-if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY, errp)) {
+if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY | BDRV_BITMAP_RO,
+errp)) {
 return;
 }
 
-- 
2.17.2




[Qemu-devel] [PULL 11/17] block/dirty-bitmaps: add inconsistent bit

2019-03-08 Thread John Snow
Add an inconsistent bit to dirty-bitmaps that allows us to report a bitmap as
persistent but potentially inconsistent, i.e. if we find bitmaps on a qcow2
that have been marked as "in use".

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190301191545.8728-2-js...@redhat.com
Signed-off-by: John Snow 
---
 qapi/block-core.json | 13 +
 include/block/dirty-bitmap.h |  2 ++
 block/dirty-bitmap.c | 20 
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 6e543594b3..e639ef6d1c 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -467,15 +467,20 @@
 #and cannot be modified via QMP or used by another operation.
 #Replaces `locked` and `frozen` statuses. (since 4.0)
 #
-# @persistent: true if the bitmap will eventually be flushed to persistent
-#  storage (since 4.0)
+# @persistent: true if the bitmap was stored on disk, is scheduled to be stored
+#  on disk, or both. (since 4.0)
+#
+# @inconsistent: true if this is a persistent bitmap that was improperly
+#stored. Implies @persistent to be true; @recording and
+#@busy to be false. This bitmap cannot be used. To remove
+#it, use @block-dirty-bitmap-remove. (Since 4.0)
 #
 # Since: 1.3
 ##
 { 'struct': 'BlockDirtyInfo',
   'data': {'*name': 'str', 'count': 'int', 'granularity': 'uint32',
-   'recording': 'bool', 'busy': 'bool',
-   'status': 'DirtyBitmapStatus', 'persistent': 'bool' } }
+   'recording': 'bool', 'busy': 'bool', 'status': 'DirtyBitmapStatus',
+   'persistent': 'bool', '*inconsistent': 'bool' } }
 
 ##
 # @Qcow2BitmapInfoFlags:
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index ba8477b73f..bd1b6479df 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -68,6 +68,7 @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap 
*bitmap);
 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
 void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
bool persistent);
+void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
 void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
  HBitmap **backup, Error **errp);
@@ -91,6 +92,7 @@ bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap 
*bitmap);
 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
 bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
+bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
 bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap);
 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 980cae4fa3..c611bfb971 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -46,6 +46,9 @@ struct BdrvDirtyBitmap {
and this bitmap must remain unchanged while
this flag is set. */
 bool persistent;/* bitmap must be saved to owner disk image */
+bool inconsistent;  /* bitmap is persistent, but inconsistent.
+ * It cannot be used at all in any way, except
+ * a QMP user can remove it. */
 bool migration; /* Bitmap is selected for migration, it should
not be stored on the next inactivation
(persistent flag doesn't matter until next
@@ -464,6 +467,8 @@ BlockDirtyInfoList 
*bdrv_query_dirty_bitmaps(BlockDriverState *bs)
 info->recording = bdrv_dirty_bitmap_recording(bm);
 info->busy = bdrv_dirty_bitmap_busy(bm);
 info->persistent = bm->persistent;
+info->has_inconsistent = bm->inconsistent;
+info->inconsistent = bm->inconsistent;
 entry->value = info;
 *plist = entry;
 plist = &entry->next;
@@ -711,6 +716,16 @@ void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap 
*bitmap, bool persistent)
 qemu_mutex_unlock(bitmap->mutex);
 }
 
+/* Called with BQL taken. */
+void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap)
+{
+qemu_mutex_lock(bitmap->mutex);
+assert(bitmap->persistent == true);
+bitmap->inconsistent = true;
+bitmap->disabled = true;
+qemu_mutex_unlock(bitmap->mutex);
+}
+
 /* Called with BQL taken. */
 void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migration)
 {
@@ -724,6 +739,11 @@ bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap 
*bitmap)
 

[Qemu-devel] [PULL 09/17] blockdev: remove unused paio parameter documentation

2019-03-08 Thread John Snow
This field isn't present anymore.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190223000614.13894-10-js...@redhat.com
Signed-off-by: John Snow 
---
 blockdev.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index b4d790131e..8e002cf681 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1255,7 +1255,6 @@ out_aio_context:
  * @node: The name of the BDS node to search for bitmaps
  * @name: The name of the bitmap to search for
  * @pbs: Output pointer for BDS lookup, if desired. Can be NULL.
- * @paio: Output pointer for aio_context acquisition, if desired. Can be NULL.
  * @errp: Output pointer for error information. Can be NULL.
  *
  * @return: A bitmap object on success, or NULL on failure.
-- 
2.17.2




[Qemu-devel] [PULL 10/17] iotests: add busy/recording bit test to 124

2019-03-08 Thread John Snow
This adds a simple test that ensures the busy bit works for push backups,
as well as doubling as bonus test for incremental backups that get interrupted
by EIO errors.

Recording bit tests are already handled sufficiently by 236.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Tested-by: Eric Blake 
Message-id: 20190223000614.13894-11-js...@redhat.com
Signed-off-by: John Snow 
---
 tests/qemu-iotests/124 | 113 +
 tests/qemu-iotests/124.out |   4 +-
 2 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/124 b/tests/qemu-iotests/124
index 5aa1bf1bd6..80b356f7bb 100755
--- a/tests/qemu-iotests/124
+++ b/tests/qemu-iotests/124
@@ -634,6 +634,119 @@ class 
TestIncrementalBackupBlkdebug(TestIncrementalBackupBase):
 self.vm.shutdown()
 self.check_backups()
 
+def test_incremental_pause(self):
+"""
+Test an incremental backup that errors into a pause and is resumed.
+"""
+
+drive0 = self.drives[0]
+# NB: The blkdebug script here looks for a "flush, read, read" pattern.
+# The flush occurs in hmp_io_writes, the first read in device_add, and
+# the last read during the block job.
+result = self.vm.qmp('blockdev-add',
+ node_name=drive0['id'],
+ driver=drive0['fmt'],
+ file={
+ 'driver': 'blkdebug',
+ 'image': {
+ 'driver': 'file',
+ 'filename': drive0['file']
+ },
+ 'set-state': [{
+ 'event': 'flush_to_disk',
+ 'state': 1,
+ 'new_state': 2
+ },{
+ 'event': 'read_aio',
+ 'state': 2,
+ 'new_state': 3
+ }],
+ 'inject-error': [{
+ 'event': 'read_aio',
+ 'errno': 5,
+ 'state': 3,
+ 'immediately': False,
+ 'once': True
+ }],
+ })
+self.assert_qmp(result, 'return', {})
+self.create_anchor_backup(drive0)
+bitmap = self.add_bitmap('bitmap0', drive0)
+
+# Emulate guest activity
+self.hmp_io_writes(drive0['id'], (('0xab', 0, 512),
+  ('0xfe', '16M', '256k'),
+  ('0x64', '32736k', '64k')))
+
+# For the purposes of query-block visibility of bitmaps, add a drive
+# frontend after we've written data; otherwise we can't use hmp-io
+result = self.vm.qmp("device_add",
+ id="device0",
+ drive=drive0['id'],
+ driver="virtio-blk")
+self.assert_qmp(result, 'return', {})
+
+# Bitmap Status Check
+query = self.vm.qmp('query-block')
+ret = [bmap for bmap in query['return'][0]['dirty-bitmaps']
+   if bmap.get('name') == bitmap.name][0]
+self.assert_qmp(ret, 'count', 458752)
+self.assert_qmp(ret, 'granularity', 65536)
+self.assert_qmp(ret, 'status', 'active')
+self.assert_qmp(ret, 'busy', False)
+self.assert_qmp(ret, 'recording', True)
+
+# Start backup
+parent, _ = bitmap.last_target()
+target = self.prepare_backup(bitmap, parent)
+res = self.vm.qmp('drive-backup',
+  job_id=bitmap.drive['id'],
+  device=bitmap.drive['id'],
+  sync='incremental',
+  bitmap=bitmap.name,
+  format=bitmap.drive['fmt'],
+  target=target,
+  mode='existing',
+  on_source_error='stop')
+self.assert_qmp(res, 'return', {})
+
+# Wait for the error
+event = self.vm.event_wait(name="BLOCK_JOB_ERROR",
+   
match={"data":{"device":bitmap.drive['id']}})
+self.assert_qmp(event, 'data', {'device': bitmap.drive['id'],
+'action': 'stop',
+'operation': 'read'})
+
+# Bitmap Status Check
+query = self.vm.qmp('query-block')
+ret = [bmap for bmap in query['return'][0]['dirty-bitmaps']
+   if bmap.get('name') == bitmap.name][0]
+self.assert_qmp(ret, 'count', 458752)
+self.assert_qmp(ret, '

[Qemu-devel] [PULL 07/17] block/dirty-bitmaps: unify qmp_locked and user_locked calls

2019-03-08 Thread John Snow
These mean the same thing now. Unify them and rename the merged call
bdrv_dirty_bitmap_busy to indicate semantically what we are describing,
as well as help disambiguate from the various _locked and _unlocked
versions of bitmap helpers that refer to mutex locks.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190223000614.13894-8-js...@redhat.com
Signed-off-by: John Snow 
---
 include/block/dirty-bitmap.h   |  5 ++--
 block/dirty-bitmap.c   | 42 +++---
 blockdev.c | 18 +++
 migration/block-dirty-bitmap.c |  6 ++---
 nbd/server.c   |  6 ++---
 5 files changed, 35 insertions(+), 42 deletions(-)

diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index cdbb4dfefd..ba8477b73f 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -68,7 +68,7 @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap 
*bitmap);
 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
 void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
bool persistent);
-void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool 
qmp_locked);
+void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
  HBitmap **backup, Error **errp);
 void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migration);
@@ -91,8 +91,7 @@ bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap 
*bitmap);
 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
 bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
-bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap);
-bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap);
+bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap);
 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
 BdrvDirtyBitmap *bitmap);
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index abc219814c..d50e74d337 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -48,8 +48,7 @@ struct BdrvDirtyBitmap {
 QemuMutex *mutex;
 HBitmap *bitmap;/* Dirty bitmap implementation */
 HBitmap *meta;  /* Meta dirty bitmap */
-bool qmp_locked;/* Bitmap is locked, it can't be modified
-   through QMP */
+bool busy;  /* Bitmap is busy, it can't be used via QMP */
 BdrvDirtyBitmap *successor; /* Anonymous child, if any. */
 char *name; /* Optional non-empty unique ID */
 int64_t size;   /* Size of the bitmap, in bytes */
@@ -188,22 +187,17 @@ bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap 
*bitmap)
 return bitmap->successor;
 }
 
-bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap) {
-return bdrv_dirty_bitmap_qmp_locked(bitmap);
+bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) {
+return bitmap->busy;
 }
 
-void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked)
+void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy)
 {
 qemu_mutex_lock(bitmap->mutex);
-bitmap->qmp_locked = qmp_locked;
+bitmap->busy = busy;
 qemu_mutex_unlock(bitmap->mutex);
 }
 
-bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap)
-{
-return bitmap->qmp_locked;
-}
-
 /* Called with BQL taken.  */
 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap)
 {
@@ -215,7 +209,7 @@ DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap 
*bitmap)
 {
 if (bdrv_dirty_bitmap_has_successor(bitmap)) {
 return DIRTY_BITMAP_STATUS_FROZEN;
-} else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
+} else if (bdrv_dirty_bitmap_busy(bitmap)) {
 return DIRTY_BITMAP_STATUS_LOCKED;
 } else if (!bdrv_dirty_bitmap_enabled(bitmap)) {
 return DIRTY_BITMAP_STATUS_DISABLED;
@@ -233,7 +227,7 @@ static bool bdrv_dirty_bitmap_recording(BdrvDirtyBitmap 
*bitmap)
 
 /**
  * Create a successor bitmap destined to replace this bitmap after an 
operation.
- * Requires that the bitmap is not user_locked and has no successor.
+ * Requires that the bitmap is not marked busy and has no successor.
  * The successor will be enabled if the parent bitmap was.
  * Called with BQL taken.
  */
@@ -243,7 +237,7 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
 uint64_t granularity;
 BdrvDirtyBitmap *child;
 
-if (bdrv_dirty_bitmap_user_locked(bitmap)) {
+if (bdrv_dirty_bitmap_busy(bitmap)) {
 error_setg(errp, "Cannot create a successor for a bitmap that is 
in-use "
"by an operation");
 re

[Qemu-devel] [PULL 06/17] block/dirty-bitmap: explicitly lock bitmaps with successors

2019-03-08 Thread John Snow
Instead of implying a user_locked/busy status, make it explicit.
Now, bitmaps in use by migration, NBD or backup operations
are all treated the same way with the same code paths.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190223000614.13894-7-js...@redhat.com
Signed-off-by: John Snow 
---
 block/dirty-bitmap.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 2e3192d86f..abc219814c 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -50,7 +50,7 @@ struct BdrvDirtyBitmap {
 HBitmap *meta;  /* Meta dirty bitmap */
 bool qmp_locked;/* Bitmap is locked, it can't be modified
through QMP */
-BdrvDirtyBitmap *successor; /* Anonymous child; implies user_locked state 
*/
+BdrvDirtyBitmap *successor; /* Anonymous child, if any. */
 char *name; /* Optional non-empty unique ID */
 int64_t size;   /* Size of the bitmap, in bytes */
 bool disabled;  /* Bitmap is disabled. It ignores all writes to
@@ -188,10 +188,8 @@ bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap 
*bitmap)
 return bitmap->successor;
 }
 
-/* Both conditions disallow user-modification via QMP. */
 bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap) {
-return bdrv_dirty_bitmap_has_successor(bitmap) ||
-   bdrv_dirty_bitmap_qmp_locked(bitmap);
+return bdrv_dirty_bitmap_qmp_locked(bitmap);
 }
 
 void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked)
@@ -267,8 +265,9 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
 child->disabled = bitmap->disabled;
 bitmap->disabled = true;
 
-/* Install the successor and freeze the parent */
+/* Install the successor and lock the parent */
 bitmap->successor = child;
+bitmap->qmp_locked = true;
 return 0;
 }
 
@@ -323,6 +322,7 @@ BdrvDirtyBitmap 
*bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
 bitmap->successor = NULL;
 successor->persistent = bitmap->persistent;
 bitmap->persistent = false;
+bitmap->qmp_locked = false;
 bdrv_release_dirty_bitmap(bs, bitmap);
 
 return successor;
@@ -352,6 +352,7 @@ BdrvDirtyBitmap 
*bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
 }
 
 parent->disabled = successor->disabled;
+parent->qmp_locked = false;
 bdrv_release_dirty_bitmap_locked(successor);
 parent->successor = NULL;
 
-- 
2.17.2




[Qemu-devel] [PULL 14/17] block/dirty-bitmaps: prohibit readonly bitmaps for backups

2019-03-08 Thread John Snow
drive and blockdev backup cannot use readonly bitmaps, because the
sync=incremental mechanism actually edits the bitmaps on success.

If you really want to do this operation, use a copied bitmap.

Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20190301191545.8728-5-js...@redhat.com
Signed-off-by: John Snow 
---
 blockdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 455ab806b2..c6c7a64bfc 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3533,7 +3533,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
JobTxn *txn,
 bdrv_unref(target_bs);
 goto out;
 }
-if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_ALLOW_RO, errp)) {
+if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_DEFAULT, errp)) {
 goto out;
 }
 }
@@ -3643,7 +3643,7 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup, 
JobTxn *txn,
 error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap);
 goto out;
 }
-if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_ALLOW_RO, errp)) {
+if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_DEFAULT, errp)) {
 goto out;
 }
 }
-- 
2.17.2




  1   2   3   4   5   >