[PATCH V2 09/10] net/colo-compare.c: Add secondary old packet detection

2020-10-15 Thread Zhang Chen
From: Zhang Chen 

Detect queued secondary packet to sync VM state in time.

Signed-off-by: Zhang Chen 
Reviewed-by: Li Zhijian 
---
 net/colo-compare.c | 25 -
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 1263203e7f..0c87fd9e33 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -636,19 +636,26 @@ void colo_compare_unregister_notifier(Notifier *notify)
 static int colo_old_packet_check_one_conn(Connection *conn,
   CompareState *s)
 {
-GList *result = NULL;
-
-result = g_queue_find_custom(>primary_list,
- >compare_timeout,
- (GCompareFunc)colo_old_packet_check_one);
+if (!g_queue_is_empty(>primary_list)) {
+if (g_queue_find_custom(>primary_list,
+>compare_timeout,
+(GCompareFunc)colo_old_packet_check_one))
+goto out;
+}
 
-if (result) {
-/* Do checkpoint will flush old packet */
-colo_compare_inconsistency_notify(s);
-return 0;
+if (!g_queue_is_empty(>secondary_list)) {
+if (g_queue_find_custom(>secondary_list,
+>compare_timeout,
+(GCompareFunc)colo_old_packet_check_one))
+goto out;
 }
 
 return 1;
+
+out:
+/* Do checkpoint will flush old packet */
+colo_compare_inconsistency_notify(s);
+return 0;
 }
 
 /*
-- 
2.17.1




[PATCH V2 05/10] colo-compare: fix missing compare_seq initialization

2020-10-15 Thread Zhang Chen
From: Li Zhijian 

Fixes: f449c9e549c ("colo: compare the packet based on the tcp sequence
number")

Signed-off-by: Li Zhijian 
Signed-off-by: Zhang Chen 
Reviewed-by: Zhang Chen 
Reviewed-by: Philippe Mathieu-Daudé 
---
 net/colo.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/colo.c b/net/colo.c
index a6c66d829a..ef00609848 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -133,14 +133,11 @@ void reverse_connection_key(ConnectionKey *key)
 
 Connection *connection_new(ConnectionKey *key)
 {
-Connection *conn = g_slice_new(Connection);
+Connection *conn = g_slice_new0(Connection);
 
 conn->ip_proto = key->ip_proto;
 conn->processing = false;
-conn->offset = 0;
 conn->tcp_state = TCPS_CLOSED;
-conn->pack = 0;
-conn->sack = 0;
 g_queue_init(>primary_list);
 g_queue_init(>secondary_list);
 
-- 
2.17.1




[PATCH V2 08/10] net/colo-compare.c: Change the timer clock type

2020-10-15 Thread Zhang Chen
From: Zhang Chen 

The virtual clock only runs during the emulation. It stops
when the virtual machine is stopped.
The host clock should be used for device models that emulate accurate
real time sources. It will continue to run when the virtual machine
is suspended. COLO need to know the host time here.

Fixes: dd321ecfc2e ("colo-compare: Use IOThread to Check old packet
regularly and Process packets of the primary")

Reported-by: Derek Su 
Signed-off-by: Zhang Chen 
Reviewed-by: Li Zhijian 
Reviewed-by: Philippe Mathieu-Daudé 
---
 net/colo-compare.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 76b83a9ca0..1263203e7f 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -900,7 +900,7 @@ static void check_old_packet_regular(void *opaque)
 
 /* if have old packet we will notify checkpoint */
 colo_old_packet_check(s);
-timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
   s->expired_scan_cycle);
 }
 
@@ -934,10 +934,10 @@ static void colo_compare_timer_init(CompareState *s)
 {
 AioContext *ctx = iothread_get_aio_context(s->iothread);
 
-s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL,
+s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_HOST,
 SCALE_MS, check_old_packet_regular,
 s);
-timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
   s->expired_scan_cycle);
 }
 
-- 
2.17.1




[PATCH V2 03/10] Reduce the time of checkpoint for COLO

2020-10-15 Thread Zhang Chen
From: "Rao, Lei" 

we should set ram_bulk_stage to false after ram_state_init,
otherwise the bitmap will be unused in migration_bitmap_find_dirty.
all pages in ram cache will be flushed to the ram of secondary guest
for each checkpoint.

Signed-off-by: Lei Rao 
Signed-off-by: Derek Su 
Signed-off-by: Zhang Chen 
Reviewed-by: Li Zhijian 
Reviewed-by: Zhang Chen 
---
 migration/ram.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/migration/ram.c b/migration/ram.c
index 433489d633..9cfac3d9ba 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3009,6 +3009,18 @@ static void decompress_data_with_multi_threads(QEMUFile 
*f,
 qemu_mutex_unlock(_done_lock);
 }
 
+ /*
+  * we must set ram_bulk_stage to false, otherwise in
+  * migation_bitmap_find_dirty the bitmap will be unused and
+  * all the pages in ram cache wil be flushed to the ram of
+  * secondary VM.
+  */
+static void colo_init_ram_state(void)
+{
+ram_state_init(_state);
+ram_state->ram_bulk_stage = false;
+}
+
 /*
  * colo cache: this is for secondary VM, we cache the whole
  * memory of the secondary VM, it is need to hold the global lock
@@ -3052,7 +3064,7 @@ int colo_init_ram_cache(void)
 }
 }
 
-ram_state_init(_state);
+colo_init_ram_state();
 return 0;
 }
 
-- 
2.17.1




[PATCH V2 06/10] colo-compare: check mark in mutual exclusion

2020-10-15 Thread Zhang Chen
From: Li Zhijian 

Signed-off-by: Li Zhijian 
Signed-off-by: Zhang Chen 
Reviewed-by: Zhang Chen 
---
 net/colo-compare.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index a35c10fb59..8d476bbd99 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -477,13 +477,11 @@ sec:
 colo_release_primary_pkt(s, ppkt);
 g_queue_push_head(>secondary_list, spkt);
 goto pri;
-}
-if (mark == COLO_COMPARE_FREE_SECONDARY) {
+} else if (mark == COLO_COMPARE_FREE_SECONDARY) {
 conn->compare_seq = spkt->seq_end;
 packet_destroy(spkt, NULL);
 goto sec;
-}
-if (mark == (COLO_COMPARE_FREE_PRIMARY | COLO_COMPARE_FREE_SECONDARY)) 
{
+} else if (mark == (COLO_COMPARE_FREE_PRIMARY | 
COLO_COMPARE_FREE_SECONDARY)) {
 conn->compare_seq = ppkt->seq_end;
 colo_release_primary_pkt(s, ppkt);
 packet_destroy(spkt, NULL);
-- 
2.17.1




[PATCH V2 04/10] Fix the qemu crash when guest shutdown in COLO mode

2020-10-15 Thread Zhang Chen
From: "Rao, Lei" 

In COLO mode, if the startup parameters of QEMU include "no-shutdown",
QEMU will crash when the guest shutdown. The root cause is when the
guest shutdown, the state of VM will switch COLO to SHUTDOWN. When do
checkpoint again, the state will be changed to COLO. But the state
switch is undefined in runstate_transitions_def, we should add it.
This patch fixes the following:
qemu-system-x86_64: invalid runstate transition: 'shutdown' -> 'colo'
Aborted

Signed-off-by: Lei Rao 
Signed-off-by: Zhang Chen 
Reviewed-by: Zhang Chen 
---
 softmmu/vl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 5a11a62f78..bafe7c5b70 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -632,6 +632,7 @@ static const RunStateTransition runstate_transitions_def[] 
= {
 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
 { RUN_STATE_SHUTDOWN, RUN_STATE_PRELAUNCH },
+{ RUN_STATE_SHUTDOWN, RUN_STATE_COLO },
 
 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
-- 
2.17.1




[PATCH V2 01/10] net/filter-rewriter: destroy g_hash_table in colo_rewriter_cleanup

2020-10-15 Thread Zhang Chen
From: Pan Nengyuan 

s->connection_track_table forgot to destroy in colo_rewriter_cleanup. Fix it.

Reported-by: Euler Robot 
Signed-off-by: Pan Nengyuan 
Signed-off-by: Zhang Chen 
Reviewed-by: Zhang Chen 
Reviewed-by: Li Qiang 
---
 net/filter-rewriter.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index dc3c27a489..e063a818b7 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -381,6 +381,8 @@ static void colo_rewriter_cleanup(NetFilterState *nf)
 filter_rewriter_flush(nf);
 g_free(s->incoming_queue);
 }
+
+g_hash_table_destroy(s->connection_track_table);
 }
 
 static void colo_rewriter_setup(NetFilterState *nf, Error **errp)
-- 
2.17.1




[PATCH V2 02/10] Optimize seq_sorter function for colo-compare

2020-10-15 Thread Zhang Chen
From: "Rao, Lei" 

The seq of tcp has been filled in fill_pkt_tcp_info, it
can be used directly here.

Signed-off-by: Lei Rao 
Signed-off-by: Zhang Chen 
Reviewed-by: Li Zhijian 
Reviewed-by: Zhang Chen 
---
 net/colo-compare.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 3a45d64175..a35c10fb59 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -194,13 +194,10 @@ static void 
colo_compare_inconsistency_notify(CompareState *s)
 }
 }
 
+/* Use restricted to colo_insert_packet() */
 static gint seq_sorter(Packet *a, Packet *b, gpointer data)
 {
-struct tcp_hdr *atcp, *btcp;
-
-atcp = (struct tcp_hdr *)(a->transport_header);
-btcp = (struct tcp_hdr *)(b->transport_header);
-return ntohl(atcp->th_seq) - ntohl(btcp->th_seq);
+return a->tcp_seq - b->tcp_seq;
 }
 
 static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
-- 
2.17.1




[PATCH V2 07/10] net/colo-compare.c: Fix compare_timeout format issue

2020-10-15 Thread Zhang Chen
From: Zhang Chen 

This parameter need compare with the return of qemu_clock_get_ms(),
it is uint64_t. So we need fix this issue here.

Fixes: 9cc43c94b31 ("net/colo-compare.c: Expose "compare_timeout" to users")

Reported-by: Derek Su 
Signed-off-by: Zhang Chen 
Reviewed-by: Li Zhijian 
Reviewed-by: Philippe Mathieu-Daudé 
---
 net/colo-compare.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 8d476bbd99..76b83a9ca0 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -120,7 +120,7 @@ struct CompareState {
 SendCo out_sendco;
 SendCo notify_sendco;
 bool vnet_hdr;
-uint32_t compare_timeout;
+uint64_t compare_timeout;
 uint32_t expired_scan_cycle;
 
 /*
@@ -1076,9 +1076,9 @@ static void compare_get_timeout(Object *obj, Visitor *v,
 Error **errp)
 {
 CompareState *s = COLO_COMPARE(obj);
-uint32_t value = s->compare_timeout;
+uint64_t value = s->compare_timeout;
 
-visit_type_uint32(v, name, , errp);
+visit_type_uint64(v, name, , errp);
 }
 
 static void compare_set_timeout(Object *obj, Visitor *v,
@@ -1141,9 +1141,9 @@ static void set_max_queue_size(Object *obj, Visitor *v,
Error **errp)
 {
 Error *local_err = NULL;
-uint32_t value;
+uint64_t value;
 
-visit_type_uint32(v, name, , _err);
+visit_type_uint64(v, name, , _err);
 if (local_err) {
 goto out;
 }
@@ -1391,7 +1391,7 @@ static void colo_compare_init(Object *obj)
 object_property_add_str(obj, "notify_dev",
 compare_get_notify_dev, compare_set_notify_dev);
 
-object_property_add(obj, "compare_timeout", "uint32",
+object_property_add(obj, "compare_timeout", "uint64",
 compare_get_timeout,
 compare_set_timeout, NULL, NULL);
 
-- 
2.17.1




[PATCH V2 00/10] COLO project queued patches 20-Oct

2020-10-15 Thread Zhang Chen
From: Zhang Chen 

Hi Jason, this series include latest COLO related patches.
please check and merge it.

Li Zhijian (2):
  colo-compare: fix missing compare_seq initialization
  colo-compare: check mark in mutual exclusion

Pan Nengyuan (1):
  net/filter-rewriter: destroy g_hash_table in colo_rewriter_cleanup

Rao, Lei (3):
  Optimize seq_sorter function for colo-compare
  Reduce the time of checkpoint for COLO
  Fix the qemu crash when guest shutdown in COLO mode

Zhang Chen (4):
  net/colo-compare.c: Fix compare_timeout format issue
  net/colo-compare.c: Change the timer clock type
  net/colo-compare.c: Add secondary old packet detection
  net/colo-compare.c: Increase default queued packet scan frequency

 migration/ram.c   | 14 ++-
 net/colo-compare.c| 58 ++-
 net/colo.c|  5 +---
 net/filter-rewriter.c |  2 ++
 softmmu/vl.c  |  1 +
 5 files changed, 47 insertions(+), 33 deletions(-)

-- 
2.17.1




[PULL 3/3] hw/usb/hcd-dwc2: fix divide-by-zero in dwc2_handle_packet()

2020-10-15 Thread Gerd Hoffmann
From: Mauro Matteo Cascella 

Check the value of mps to avoid potential divide-by-zero later in the function.
Since HCCHAR_MPS is guest controllable, this prevents a malicious/buggy guest
from crashing the QEMU process on the host.

Signed-off-by: Mauro Matteo Cascella 
Reviewed-by: Paul Zimmerman 
Reported-by: Gaoning Pan 
Reported-by: Xingwei Lin 
Message-id: 20201015075957.268823-1-mcasc...@redhat.com
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/hcd-dwc2.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c
index 64c23c1ed084..e1d96acf7ecf 100644
--- a/hw/usb/hcd-dwc2.c
+++ b/hw/usb/hcd-dwc2.c
@@ -250,6 +250,12 @@ static void dwc2_handle_packet(DWC2State *s, uint32_t 
devadr, USBDevice *dev,
 trace_usb_dwc2_handle_packet(chan, dev, >packet, epnum, types[eptype],
  dirs[epdir], mps, len, pcnt);
 
+if (mps == 0) {
+qemu_log_mask(LOG_GUEST_ERROR,
+"%s: Bad HCCHAR_MPS set to zero\n", __func__);
+return;
+}
+
 if (eptype == USB_ENDPOINT_XFER_CONTROL && pid == TSIZ_SC_MC_PID_SETUP) {
 pid = USB_TOKEN_SETUP;
 } else {
-- 
2.27.0




[PULL 0/3] Usb 20201016 patches

2020-10-15 Thread Gerd Hoffmann
The following changes since commit 57c98ea9acdcef5021f5671efa6475a5794a51c4:

  Merge remote-tracking branch 'remotes/kraxel/tags/ui-20201014-pull-request' 
into staging (2020-10-14 13:56:06 +0100)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/usb-20201016-pull-request

for you to fetch changes up to 9832f6783c4198658d101c6b8e8a14e1f2c57aa3:

  hw/usb/hcd-dwc2: fix divide-by-zero in dwc2_handle_packet() (2020-10-15 
12:16:42 +0200)


usb: fixes for dwc2 + ehci.



Anthony PERARD via (1):
  usb/hcd-ehci: Fix error handling on missing device for iTD

Mauro Matteo Cascella (1):
  hw/usb/hcd-dwc2: fix divide-by-zero in dwc2_handle_packet()

Paul Zimmerman (1):
  usb: hcd-dwc2: change assert()s to qemu_log_mask(LOG_GUEST_ERROR...)

 hw/usb/hcd-dwc2.c | 106 +-
 hw/usb/hcd-ehci.c |  35 +++
 2 files changed, 105 insertions(+), 36 deletions(-)

-- 
2.27.0





[PULL 1/3] usb: hcd-dwc2: change assert()s to qemu_log_mask(LOG_GUEST_ERROR...)

2020-10-15 Thread Gerd Hoffmann
From: Paul Zimmerman 

Change several assert()s to qemu_log_mask(LOG_GUEST_ERROR...),
to prevent the guest from causing Qemu to assert. Also fix up
several existing qemu_log_mask()s to include the function name in
the message.

Suggested-by: Peter Maydell 
Signed-off-by: Paul Zimmerman 
Message-id: 20200920021449.830-1-pauld...@gmail.com
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/hcd-dwc2.c | 100 +-
 1 file changed, 81 insertions(+), 19 deletions(-)

diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c
index 97688d21bf0f..64c23c1ed084 100644
--- a/hw/usb/hcd-dwc2.c
+++ b/hw/usb/hcd-dwc2.c
@@ -238,7 +238,12 @@ static void dwc2_handle_packet(DWC2State *s, uint32_t 
devadr, USBDevice *dev,
 pid = get_field(hctsiz, TSIZ_SC_MC_PID);
 pcnt = get_field(hctsiz, TSIZ_PKTCNT);
 len = get_field(hctsiz, TSIZ_XFERSIZE);
-assert(len <= DWC2_MAX_XFER_SIZE);
+if (len > DWC2_MAX_XFER_SIZE) {
+qemu_log_mask(LOG_GUEST_ERROR,
+  "%s: HCTSIZ transfer size too large\n", __func__);
+return;
+}
+
 chan = index >> 3;
 p = >packet[chan];
 
@@ -663,7 +668,12 @@ static uint64_t dwc2_glbreg_read(void *ptr, hwaddr addr, 
int index,
 DWC2State *s = ptr;
 uint32_t val;
 
-assert(addr <= GINTSTS2);
+if (addr > GINTSTS2) {
+qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
+  __func__, addr);
+return 0;
+}
+
 val = s->glbreg[index];
 
 switch (addr) {
@@ -690,7 +700,12 @@ static void dwc2_glbreg_write(void *ptr, hwaddr addr, int 
index, uint64_t val,
 uint32_t old;
 int iflg = 0;
 
-assert(addr <= GINTSTS2);
+if (addr > GINTSTS2) {
+qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
+  __func__, addr);
+return;
+}
+
 mmio = >glbreg[index];
 old = *mmio;
 
@@ -715,27 +730,34 @@ static void dwc2_glbreg_write(void *ptr, hwaddr addr, int 
index, uint64_t val,
 val &= ~GRSTCTL_DMAREQ;
 if (!(old & GRSTCTL_TXFFLSH) && (val & GRSTCTL_TXFFLSH)) {
 /* TODO - TX fifo flush */
-qemu_log_mask(LOG_UNIMP, "Tx FIFO flush not implemented\n");
+qemu_log_mask(LOG_UNIMP, "%s: Tx FIFO flush not implemented\n",
+  __func__);
 }
 if (!(old & GRSTCTL_RXFFLSH) && (val & GRSTCTL_RXFFLSH)) {
 /* TODO - RX fifo flush */
-qemu_log_mask(LOG_UNIMP, "Rx FIFO flush not implemented\n");
+qemu_log_mask(LOG_UNIMP, "%s: Rx FIFO flush not implemented\n",
+  __func__);
 }
 if (!(old & GRSTCTL_IN_TKNQ_FLSH) && (val & GRSTCTL_IN_TKNQ_FLSH)) {
 /* TODO - device IN token queue flush */
-qemu_log_mask(LOG_UNIMP, "Token queue flush not implemented\n");
+qemu_log_mask(LOG_UNIMP, "%s: Token queue flush not implemented\n",
+  __func__);
 }
 if (!(old & GRSTCTL_FRMCNTRRST) && (val & GRSTCTL_FRMCNTRRST)) {
 /* TODO - host frame counter reset */
-qemu_log_mask(LOG_UNIMP, "Frame counter reset not implemented\n");
+qemu_log_mask(LOG_UNIMP,
+  "%s: Frame counter reset not implemented\n",
+  __func__);
 }
 if (!(old & GRSTCTL_HSFTRST) && (val & GRSTCTL_HSFTRST)) {
 /* TODO - host soft reset */
-qemu_log_mask(LOG_UNIMP, "Host soft reset not implemented\n");
+qemu_log_mask(LOG_UNIMP, "%s: Host soft reset not implemented\n",
+  __func__);
 }
 if (!(old & GRSTCTL_CSFTRST) && (val & GRSTCTL_CSFTRST)) {
 /* TODO - core soft reset */
-qemu_log_mask(LOG_UNIMP, "Core soft reset not implemented\n");
+qemu_log_mask(LOG_UNIMP, "%s: Core soft reset not implemented\n",
+  __func__);
 }
 /* don't allow clearing of self-clearing bits */
 val |= old & (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH |
@@ -774,7 +796,12 @@ static uint64_t dwc2_fszreg_read(void *ptr, hwaddr addr, 
int index,
 DWC2State *s = ptr;
 uint32_t val;
 
-assert(addr == HPTXFSIZ);
+if (addr != HPTXFSIZ) {
+qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
+  __func__, addr);
+return 0;
+}
+
 val = s->fszreg[index];
 
 trace_usb_dwc2_fszreg_read(addr, val);
@@ -789,7 +816,12 @@ static void dwc2_fszreg_write(void *ptr, hwaddr addr, int 
index, uint64_t val,
 uint32_t *mmio;
 uint32_t old;
 
-assert(addr == HPTXFSIZ);
+if (addr != HPTXFSIZ) {
+qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
+  __func__, addr);
+return;
+}
+
 mmio = >fszreg[index];
 old = *mmio;
 
@@ -810,7 +842,12 @@ static uint64_t 

[PULL 2/3] usb/hcd-ehci: Fix error handling on missing device for iTD

2020-10-15 Thread Gerd Hoffmann
From: Anthony PERARD via 

The EHCI Host Controller emulation attempt to locate the device
associated with a periodic isochronous transfer description (iTD) and
when this fail the host controller is reset.

But according the EHCI spec 1.0 section 5.15.2.4 Host System
Error, the host controller is supposed to reset itself only when it
failed to communicate with the Host (Operating System), like when
there's an error on the PCI bus. If a transaction fails, there's
nothing in the spec that say to reset the host controller.

This patch rework the error path so that the host controller can keep
working when the OS setup a bogus transaction, it also revert to the
behavior of the EHCI emulation to before commits:
e94682f1fe ("ehci: check device is not NULL before calling usb_ep_get()")
7011baece2 ("usb: remove unnecessary NULL device check from usb_ep_get()")

The issue has been found while trying to passthrough a USB device to a
Windows Server 2012 Xen guest via "usb-ehci", which prevent the USB
device from working in Windows. ("usb-ehci" alone works, windows only
setup this weird periodic iTD to device 127 endpoint 15 when the USB
device is passthrough.)

Signed-off-by: Anthony PERARD 
Message-id: 20201014104106.2962640-1-anthony.per...@citrix.com
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/hcd-ehci.c | 35 ++-
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 2b995443fbfd..ae7f20c502ac 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -1447,24 +1447,25 @@ static int ehci_process_itd(EHCIState *ehci,
 dev = ehci_find_device(ehci, devaddr);
 if (dev == NULL) {
 ehci_trace_guest_bug(ehci, "no device found");
-qemu_sglist_destroy(>isgl);
-return -1;
-}
-pid = dir ? USB_TOKEN_IN : USB_TOKEN_OUT;
-ep = usb_ep_get(dev, pid, endp);
-if (ep && ep->type == USB_ENDPOINT_XFER_ISOC) {
-usb_packet_setup(>ipacket, pid, ep, 0, addr, false,
- (itd->transact[i] & ITD_XACT_IOC) != 0);
-if (usb_packet_map(>ipacket, >isgl)) {
-qemu_sglist_destroy(>isgl);
-return -1;
-}
-usb_handle_packet(dev, >ipacket);
-usb_packet_unmap(>ipacket, >isgl);
-} else {
-DPRINTF("ISOCH: attempt to addess non-iso endpoint\n");
-ehci->ipacket.status = USB_RET_NAK;
+ehci->ipacket.status = USB_RET_NODEV;
 ehci->ipacket.actual_length = 0;
+} else {
+pid = dir ? USB_TOKEN_IN : USB_TOKEN_OUT;
+ep = usb_ep_get(dev, pid, endp);
+if (ep && ep->type == USB_ENDPOINT_XFER_ISOC) {
+usb_packet_setup(>ipacket, pid, ep, 0, addr, false,
+ (itd->transact[i] & ITD_XACT_IOC) != 0);
+if (usb_packet_map(>ipacket, >isgl)) {
+qemu_sglist_destroy(>isgl);
+return -1;
+}
+usb_handle_packet(dev, >ipacket);
+usb_packet_unmap(>ipacket, >isgl);
+} else {
+DPRINTF("ISOCH: attempt to addess non-iso endpoint\n");
+ehci->ipacket.status = USB_RET_NAK;
+ehci->ipacket.actual_length = 0;
+}
 }
 qemu_sglist_destroy(>isgl);
 
-- 
2.27.0




RE: [PATCH 00/10] COLO project queued patches 20-Oct

2020-10-15 Thread Zhang, Chen


> -Original Message-
> From: Jason Wang 
> Sent: Friday, October 16, 2020 10:24 AM
> To: Zhang, Chen ; qemu-dev  de...@nongnu.org>
> Cc: Zhang Chen 
> Subject: Re: [PATCH 00/10] COLO project queued patches 20-Oct
> 
> 
> On 2020/10/15 下午3:58, Zhang, Chen wrote:
> >
> >> -Original Message-
> >> From: Jason Wang 
> >> Sent: Thursday, October 15, 2020 3:56 PM
> >> To: Zhang, Chen ; qemu-dev  >> de...@nongnu.org>
> >> Cc: Zhang Chen 
> >> Subject: Re: [PATCH 00/10] COLO project queued patches 20-Oct
> >>
> >>
> >> On 2020/10/14 下午3:25, Zhang Chen wrote:
> >>> From: Zhang Chen 
> >>>
> >>> Hi Jason, this series include latest COLO related patches.
> >>> please check and merge it.
> >>>
> >>> Thanks
> >>> Zhang Chen
> >>
> >> Hi:
> >>
> >> I want to merge but I don't get patch 10/10.
> >>
> >> Is that lost during posting?
> > Oh, Sorry I missed it.
> > Already resend it:
> > [PATCH 10/10] net/colo-compare.c: Increase default queued packet scan
> > frequency
> >
> > Thanks
> > Chen
> 
> 
> It looks to me Philippe has some minor comments on some patches, please
> address them and send a new version.

Sure. I will update to V2.

Thanks
Chen

> 
> Thanks
> 
> 
> >
> >> Thanks
> >>
> >>
> >>> Li Zhijian (2):
> >>> colo-compare: fix missing compare_seq initialization
> >>> colo-compare: check mark in mutual exclusion
> >>>
> >>> Pan Nengyuan (1):
> >>> net/filter-rewriter: destroy g_hash_table in
> >>> colo_rewriter_cleanup
> >>>
> >>> Rao, Lei (3):
> >>> Optimize seq_sorter function for colo-compare
> >>> Reduce the time of checkpoint for COLO
> >>> Fix the qemu crash when guest shutdown in COLO mode
> >>>
> >>> Zhang Chen (4):
> >>> net/colo-compare.c: Fix compare_timeout format issue
> >>> net/colo-compare.c: Change the timer clock type
> >>> net/colo-compare.c: Add secondary old packet detection
> >>> net/colo-compare.c: Increase default queued packet scan
> >>> frequency
> >>>
> >>>migration/ram.c   | 14 ++-
> >>>net/colo-compare.c| 57 ++---
> --
> >>>net/colo.c|  5 +---
> >>>net/filter-rewriter.c |  2 ++
> >>>softmmu/vl.c  |  1 +
> >>>5 files changed, 46 insertions(+), 33 deletions(-)
> >>>



Re: [RFC PATCH] contrib/gitdm: Add more individual contributors

2020-10-15 Thread Thomas Huth
Am Sun,  4 Oct 2020 20:25:06 +0200
schrieb Philippe Mathieu-Daudé :

> These individual contributors have a number of contributions,
> add them to the 'individual' group map.
> 
> Cc: Ahmed Karaman 
> Cc: Aleksandar Markovic 
> Cc: Alistair Francis 
> Cc: Artyom Tarasenko 
> Cc: David Carlier 
> Cc: Finn Thain 
> Cc: Guenter Roeck 
> Cc: Helge Deller 
> Cc: Hervé Poussineau 
> Cc: James Hogan 
> Cc: Jean-Christophe Dubois 
> Cc: Kővágó Zoltán 
> Cc: Laurent Vivier 
> Cc: Michael Rolnik 
> Cc: Niek Linnenbank 
> Cc: Paul Burton 
> Cc: Paul Zimmerman 
> Cc: Stefan Weil 
> Cc: Subbaraya Sundeep 
> Cc: Sven Schnelle 
> Cc: Thomas Huth 
> Cc: Volker Rümelin 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
> To the developers Cc'ed: If you agree with your entry, please
> reply with a Reviewed-by/Acked-by tag. If you disagree or doesn't
> care, please either reply with Nack-by or ignore this patch.
> I'll repost in 2 weeks as formal patch (not RFC) with only the
> entries acked by their author.

Acked-by: Thomas Huth 



[PATCH v2 1/2] vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup

2020-10-15 Thread Cindy Lu
fix the bug that fd will still open after the cleanup

Signed-off-by: Cindy Lu 
---
 net/vhost-vdpa.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index bc0e0d2d35..0480b92102 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -144,6 +144,10 @@ static void vhost_vdpa_cleanup(NetClientState *nc)
 g_free(s->vhost_net);
 s->vhost_net = NULL;
 }
+ if (s->vhost_vdpa.device_fd >= 0) {
+qemu_close(s->vhost_vdpa.device_fd);
+s->vhost_vdpa.device_fd = -1;
+}
 }
 
 static bool vhost_vdpa_has_vnet_hdr(NetClientState *nc)
-- 
2.21.3




[PATCH v2 2/2] net: Add vhost-vdpa in show_netdevs()

2020-10-15 Thread Cindy Lu
Fix the bug that while Check qemu supported netdev,
there is no vhost-vdpa

Signed-off-by: Cindy Lu 
---
 net/net.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/net.c b/net/net.c
index 7a2a0fb5ac..794c652282 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1049,6 +1049,9 @@ static void show_netdevs(void)
 #endif
 #ifdef CONFIG_POSIX
 "vhost-user",
+#endif
+#ifdef CONFIG_VHOST_VDPA
+"vhost-vdpa",
 #endif
 };
 
-- 
2.21.3




Re: [PATCH v4 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Yonggang Luo
On Fri, Oct 16, 2020 at 6:19 AM Paolo Bonzini  wrote:
>
>
>
> Il ven 16 ott 2020, 00:06 Yonggang Luo  ha scritto:
>>
>> meson didn't support running ../scripts/kernel-do directly
>
>
> Can you explain why this matters? Meson does not look at docs/conf.py.
>
> Paolo
>
>>
>> Signed-off-by: Yonggang Luo 
>> ---
>>  docs/conf.py | 2 +-
>>  docs/sphinx/kerneldoc.py | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/docs/conf.py b/docs/conf.py
>> index 00e1b750e2..e584f68393 100644
>> --- a/docs/conf.py
>> +++ b/docs/conf.py
>> @@ -241,7 +241,7 @@ texinfo_documents = [
>>  # We use paths starting from qemu_docdir here so that you can run
>>  # sphinx-build from anywhere and the kerneldoc extension can still
>>  # find everything.
>> -kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc')
>> +kerneldoc_bin = ['perl', os.path.join(qemu_docdir,
'../scripts/kernel-doc')]
>>  kerneldoc_srctree = os.path.join(qemu_docdir, '..')
>>  hxtool_srctree = os.path.join(qemu_docdir, '..')
>>  qapidoc_srctree = os.path.join(qemu_docdir, '..')
>> diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py
>> index 3e87940206..3ac277d162 100644
>> --- a/docs/sphinx/kerneldoc.py
>> +++ b/docs/sphinx/kerneldoc.py
>> @@ -67,7 +67,7 @@ class KernelDocDirective(Directive):
>>
>>  def run(self):
>>  env = self.state.document.settings.env
>> -cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno']
>> +cmd = env.config.kerneldoc_bin + ['-rst', '-enable-lineno']
  meson use the conf directly
>>
>>  filename = env.config.kerneldoc_srctree + '/' +
self.arguments[0]

>>  export_file_patterns = []
>> --
>> 2.28.0.windows.1
>>


--
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH 00/10] COLO project queued patches 20-Oct

2020-10-15 Thread Jason Wang



On 2020/10/15 下午3:58, Zhang, Chen wrote:



-Original Message-
From: Jason Wang 
Sent: Thursday, October 15, 2020 3:56 PM
To: Zhang, Chen ; qemu-dev 
Cc: Zhang Chen 
Subject: Re: [PATCH 00/10] COLO project queued patches 20-Oct


On 2020/10/14 下午3:25, Zhang Chen wrote:

From: Zhang Chen 

Hi Jason, this series include latest COLO related patches.
please check and merge it.

Thanks
Zhang Chen


Hi:

I want to merge but I don't get patch 10/10.

Is that lost during posting?

Oh, Sorry I missed it.
Already resend it:
[PATCH 10/10] net/colo-compare.c: Increase default queued packet scan frequency

Thanks
Chen



It looks to me Philippe has some minor comments on some patches, please 
address them and send a new version.


Thanks





Thanks



Li Zhijian (2):
colo-compare: fix missing compare_seq initialization
colo-compare: check mark in mutual exclusion

Pan Nengyuan (1):
net/filter-rewriter: destroy g_hash_table in colo_rewriter_cleanup

Rao, Lei (3):
Optimize seq_sorter function for colo-compare
Reduce the time of checkpoint for COLO
Fix the qemu crash when guest shutdown in COLO mode

Zhang Chen (4):
net/colo-compare.c: Fix compare_timeout format issue
net/colo-compare.c: Change the timer clock type
net/colo-compare.c: Add secondary old packet detection
net/colo-compare.c: Increase default queued packet scan frequency

   migration/ram.c   | 14 ++-
   net/colo-compare.c| 57 ++-
   net/colo.c|  5 +---
   net/filter-rewriter.c |  2 ++
   softmmu/vl.c  |  1 +
   5 files changed, 46 insertions(+), 33 deletions(-)






Re: [PATCH v2] virtio-net: Set mac address to hardware if the peer is vdpa

2020-10-15 Thread Jason Wang



On 2020/9/25 下午11:13, Cindy Lu wrote:

If the peer's type is vdpa, we need to set the mac address to hardware
in virtio_net_device_realize,

Signed-off-by: Cindy Lu 
---
  hw/net/virtio-net.c | 6 ++
  1 file changed, 6 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index cb0d27084c..1f2c1643bf 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3399,6 +3399,12 @@ static void virtio_net_device_realize(DeviceState *dev, 
Error **errp)
  nc = qemu_get_queue(n->nic);
  nc->rxfilter_notify_enabled = 1;
  
+   if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {

+struct virtio_net_config netcfg = {};
+memcpy(, >nic_conf.macaddr, ETH_ALEN);
+vhost_net_set_config(get_vhost_net(nc->peer),
+(uint8_t *), 0, ETH_ALEN, VHOST_SET_CONFIG_TYPE_MASTER);
+}
  QTAILQ_INIT(>rsc_chains);
  n->qdev = dev;
  



Applied.

Thanks





Re: [PATCH v2 2/2] hw/rtc/m48t59: Simplify m48t59_init() passing MemoryRegion argument

2020-10-15 Thread David Gibson
On Thu, Oct 15, 2020 at 09:46:47PM +0200, Philippe Mathieu-Daudé wrote:
> Pass a MemoryRegion* to m48t59_init(), directly call
> memory_region_add_subregion() instead of sysbus_mmio_map().
> 
> Signed-off-by: Philippe Mathieu-Daudé 

ppc parts

Acked-by: David Gibson 

> ---
>  include/hw/rtc/m48t59.h |  2 +-
>  hw/ppc/ppc405_boards.c  |  2 +-
>  hw/rtc/m48t59.c | 10 +++---
>  hw/sparc/sun4m.c|  3 ++-
>  hw/sparc64/sun4u.c  |  7 ++-
>  5 files changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/include/hw/rtc/m48t59.h b/include/hw/rtc/m48t59.h
> index d99dda2b7de..3c337e8171c 100644
> --- a/include/hw/rtc/m48t59.h
> +++ b/include/hw/rtc/m48t59.h
> @@ -49,7 +49,7 @@ struct NvramClass {
>  
>  Nvram *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
> int base_year, int type);
> -Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
> +Nvram *m48t59_init(MemoryRegion *mr, hwaddr mem_base, qemu_irq IRQ,
> uint16_t size, int base_year, int model);
>  
>  #endif /* HW_M48T59_H */
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index 93ffee801a3..6ab1b860545 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
>  /* Register FPGA */
>  ref405ep_fpga_init(sysmem, 0xF030);
>  /* Register NVRAM */
> -m48t59_init(NULL, 0xF000, 8192, 1968, 8);
> +m48t59_init(get_system_memory(), 0xF000, NULL, 8192, 1968, 8);
>  /* Load kernel */
>  linux_boot = (kernel_filename != NULL);
>  if (linux_boot) {
> diff --git a/hw/rtc/m48t59.c b/hw/rtc/m48t59.c
> index 8b02c2ec558..7ec4b241218 100644
> --- a/hw/rtc/m48t59.c
> +++ b/hw/rtc/m48t59.c
> @@ -565,9 +565,8 @@ const MemoryRegionOps m48t59_io_ops = {
>  };
>  
>  /* Initialisation routine */
> -Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
> -   uint16_t size, int base_year,
> -   int model)
> +Nvram *m48t59_init(MemoryRegion *mr, hwaddr mem_base, qemu_irq IRQ,
> +   uint16_t size, int base_year, int model)
>  {
>  DeviceState *dev;
>  SysBusDevice *s;
> @@ -584,10 +583,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
>  s = SYS_BUS_DEVICE(dev);
>  sysbus_realize_and_unref(s, _fatal);
>  sysbus_connect_irq(s, 0, IRQ);
> -if (mem_base != 0) {
> -sysbus_mmio_map(s, 0, mem_base);
> -}
> -
> +memory_region_add_subregion(mr, mem_base, sysbus_mmio_get_region(s, 
> 0));
>  return NVRAM(s);
>  }
>  
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index 20c1fa41192..aebe9e0df3d 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -966,7 +966,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
>  create_unimplemented_device("SUNW,sx", hwdef->sx_base, 0x2000);
>  }
>  
> -nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
> +nvram = m48t59_init(get_system_memory(), hwdef->nvram_base, 
> slavio_irq[0],
> +0x2000, 1968, 8);
>  
>  slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], 
> slavio_cpu_irq, smp_cpus);
>  
> diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
> index 6854522bbfa..4c975c25274 100644
> --- a/hw/sparc64/sun4u.c
> +++ b/hw/sparc64/sun4u.c
> @@ -561,7 +561,6 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
>  SabreState *sabre;
>  PCIBus *pci_bus, *pci_busA, *pci_busB;
>  PCIDevice *ebus, *pci_dev;
> -SysBusDevice *s;
>  DeviceState *iommu, *dev;
>  FWCfgState *fw_cfg;
>  NICInfo *nd;
> @@ -671,10 +670,8 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
>  pci_ide_create_devs(pci_dev);
>  
>  /* Map NVRAM into I/O (ebus) space */
> -nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
> -s = SYS_BUS_DEVICE(nvram);
> -memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
> -sysbus_mmio_get_region(s, 0));
> +nvram = m48t59_init(pci_address_space_io(ebus), 0x2000, NULL,
> +NVRAM_SIZE, 1968, 59);
>   
>  initrd_size = 0;
>  initrd_addr = 0;

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


signature.asc
Description: PGP signature


Re: [RFC PATCH v2 0/8] block-backend: Introduce I/O hang

2020-10-15 Thread Ying Fang




On 10/10/2020 10:27 AM, cenjiahui wrote:

Hi Kevin,

Could you please spend some time reviewing and commenting on this patch series.

Thanks,
Jiahui Cen


This feature is confirmed effective in a cloud storage environment since
it can help to improve the availability without pausing the entire
guest. Hope it won't be lost on the thread. Any comments or reviews
are welcome.



On 2020/9/30 17:45, Jiahui Cen wrote:

A VM in the cloud environment may use a virutal disk as the backend storage,
and there are usually filesystems on the virtual block device. When backend
storage is temporarily down, any I/O issued to the virtual block device will
cause an error. For example, an error occurred in ext4 filesystem would make
the filesystem readonly. However a cloud backend storage can be soon recovered.
For example, an IP-SAN may be down due to network failure and will be online
soon after network is recovered. The error in the filesystem may not be
recovered unless a device reattach or system restart. So an I/O rehandle is
in need to implement a self-healing mechanism.

This patch series propose a feature called I/O hang. It can rehandle AIOs
with EIO error without sending error back to guest. From guest's perspective
of view it is just like an IO is hanging and not returned. Guest can get
back running smoothly when I/O is recovred with this feature enabled.

v1->v2:
* Rebase to fix compile problems.
* Fix incorrect remove of rehandle list.
* Provide rehandle pause interface.

Jiahui Cen (8):
   block-backend: introduce I/O rehandle info
   block-backend: rehandle block aios when EIO
   block-backend: add I/O hang timeout
   block-backend: add I/O rehandle pause/unpause
   block-backend: enable I/O hang when timeout is set
   virtio-blk: pause I/O hang when resetting
   qemu-option: add I/O hang timeout option
   qapi: add I/O hang and I/O hang timeout qapi event

  block/block-backend.c  | 300 +
  blockdev.c |  11 ++
  hw/block/virtio-blk.c  |   8 +
  include/sysemu/block-backend.h |   5 +
  qapi/block-core.json   |  26 +++
  5 files changed, 350 insertions(+)


.





Re: [PATCH] spapr: Move spapr_create_nvdimm_dr_connectors() to core machine code

2020-10-15 Thread David Gibson
On Tue, Oct 13, 2020 at 09:33:44AM +0200, Greg Kurz wrote:
> On Tue, 13 Oct 2020 11:40:14 +1100
> David Gibson  wrote:
> 
> > On Mon, Oct 12, 2020 at 12:15:21PM +0200, Greg Kurz wrote:
> > > The spapr_create_nvdimm_dr_connectors() function doesn't need to access
> > > any internal details of the sPAPR NVDIMM implementation. Also, pretty
> > > much like for the LMBs, only spapr_machine_init() is responsible for the
> > > creation of DR connectors for NVDIMMs.
> > > 
> > > Make this clear by making this function static in hw/ppc/spapr.c.
> > > 
> > > Signed-off-by: Greg Kurz 
> > 
> > Hrm, I'm not really seeing the advantage to moving this.  It doesn't
> > have to be in spapr_nvdimm for data hiding, but it is related, and
> > spapr.c is kind of huge.
> > 
> 
> The only advantage is to give an appropriate scope to this function,
> as many other functions that create internal devices, eg. other DRC
> types or the default PHB for which a similar change was accepted
> 2 years ago.
> 
> commit 999c9caf2eee66103195e1ec7580b379929db9d2
> Author: Greg Kurz 
> Date:   Fri Dec 21 01:35:09 2018 +0100
> 
> spapr: move spapr_create_phb() to core machine code
> 
> This function is only used when creating the default PHB. Let's rename
> it and move it to the core machine code for clarity.
> 
> Signed-off-by: Greg Kurz 
> Reviewed-by: Alexey Kardashevskiy 
> Reviewed-by: David Gibson 
> Signed-off-by: David Gibson 
> 
> I agree that spapr.c is huge indeed (4943 lines) but this increases its
> size by _just_ 0.2 %. And there are certainly good candidates that
> landed in spapr.c by _default_ over the years but should rather be
> moved to their own compilation unit (eg. a bunch of FDT building
> functions for various resources or some hotplug related functions
> that don't need to access machine internals).

Good points.  Applied to ppc-for-5.2.

> 
> > > ---
> > >  hw/ppc/spapr.c|   10 ++
> > >  hw/ppc/spapr_nvdimm.c |   11 ---
> > >  include/hw/ppc/spapr_nvdimm.h |1 -
> > >  3 files changed, 10 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > index 63315f2d0fa9..ee716a12af73 100644
> > > --- a/hw/ppc/spapr.c
> > > +++ b/hw/ppc/spapr.c
> > > @@ -2641,6 +2641,16 @@ static hwaddr spapr_rma_size(SpaprMachineState 
> > > *spapr, Error **errp)
> > >  return rma_size;
> > >  }
> > >  
> > > +static void spapr_create_nvdimm_dr_connectors(SpaprMachineState *spapr)
> > > +{
> > > +MachineState *machine = MACHINE(spapr);
> > > +int i;
> > > +
> > > +for (i = 0; i < machine->ram_slots; i++) {
> > > +spapr_dr_connector_new(OBJECT(spapr), TYPE_SPAPR_DRC_PMEM, i);
> > > +}
> > > +}
> > > +
> > >  /* pSeries LPAR / sPAPR hardware init */
> > >  static void spapr_machine_init(MachineState *machine)
> > >  {
> > > diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
> > > index b3a489e9fe18..9e3d94071fe1 100644
> > > --- a/hw/ppc/spapr_nvdimm.c
> > > +++ b/hw/ppc/spapr_nvdimm.c
> > > @@ -106,17 +106,6 @@ void spapr_add_nvdimm(DeviceState *dev, uint64_t 
> > > slot, Error **errp)
> > >  }
> > >  }
> > >  
> > > -void spapr_create_nvdimm_dr_connectors(SpaprMachineState *spapr)
> > > -{
> > > -MachineState *machine = MACHINE(spapr);
> > > -int i;
> > > -
> > > -for (i = 0; i < machine->ram_slots; i++) {
> > > -spapr_dr_connector_new(OBJECT(spapr), TYPE_SPAPR_DRC_PMEM, i);
> > > -}
> > > -}
> > > -
> > > -
> > >  static int spapr_dt_nvdimm(SpaprMachineState *spapr, void *fdt,
> > > int parent_offset, NVDIMMDevice *nvdimm)
> > >  {
> > > diff --git a/include/hw/ppc/spapr_nvdimm.h b/include/hw/ppc/spapr_nvdimm.h
> > > index b834d82f5545..490b19a009f4 100644
> > > --- a/include/hw/ppc/spapr_nvdimm.h
> > > +++ b/include/hw/ppc/spapr_nvdimm.h
> > > @@ -31,6 +31,5 @@ void spapr_dt_persistent_memory(SpaprMachineState 
> > > *spapr, void *fdt);
> > >  bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice 
> > > *nvdimm,
> > > uint64_t size, Error **errp);
> > >  void spapr_add_nvdimm(DeviceState *dev, uint64_t slot, Error **errp);
> > > -void spapr_create_nvdimm_dr_connectors(SpaprMachineState *spapr);
> > >  
> > >  #endif
> > > 
> > > 
> > 
> 



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


signature.asc
Description: PGP signature


Re: [PATCH] hw/net: move allocation to the heap due to very large stack frame

2020-10-15 Thread David Gibson
On Wed, Oct 14, 2020 at 07:15:47AM -0700, Elena Afanasova wrote:
> On Tue, 2020-10-13 at 16:32 +1100, David Gibson wrote:
> > On Mon, Oct 12, 2020 at 03:45:02PM +0200, Paolo Bonzini wrote:
> > > On 12/10/20 12:44, Thomas Huth wrote:
> > > > I think this is one of the tasks from:
> > > > 
> > > >  
> > > > https://wiki.qemu.org/Contribute/BiteSizedTasks#Compiler-driven_cleanups
> > > > 
> > > > It has been added by Paolo in 2016:
> > > > 
> > > >  
> > > > https://wiki.qemu.org/index.php?title=Contribute/BiteSizedTasks=5368=5367
> > > > 
> > > > ... so maybe Paolo can comment on the size that has been chosen
> > > > here...?
> > > 
> > > I used 16K, mostly because it is a nice round number.  8k is too
> > > small
> > > due to PATH_MAX-sized variables.  16k seemed to be plenty and
> > > triggered
> > > in few-enough places that the cleanup is viable.
> > 
> > Ok.  Why are large stack frames bad in qemu?
> > 
> 
> I think that the main issue here is alloca() because it can lead to UB.

That's a fair point.  I've applied the patch to ppc-for-5.2, with a
tweak to the commit message.

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


signature.asc
Description: PGP signature


Re: [PATCH v2 3/3] uninorth: use qdev gpios for PCI IRQs

2020-10-15 Thread David Gibson
On Tue, Oct 13, 2020 at 05:58:52PM +0100, Mark Cave-Ayland wrote:
> On 13/10/2020 14:38, BALATON Zoltan via wrote:
> 
> > On Tue, 13 Oct 2020, Mark Cave-Ayland wrote:
> > > Currently an object link property is used to pass a reference to the 
> > > OpenPIC
> > > into the PCI host bridge so that pci_unin_init_irqs() can connect the PCI
> > > IRQs to the PIC itself.
> > > 
> > > This can be simplified by defining the PCI IRQs as qdev gpios and then 
> > > wiring
> > > up the PCI IRQs to the PIC in the New World machine init function.
> > > 
> > > Signed-off-by: Mark Cave-Ayland 
> > > ---
> > > hw/pci-host/uninorth.c | 45 +++---
> > > hw/ppc/mac_newworld.c  | 24 --
> > > include/hw/pci-host/uninorth.h |  2 --
> > > 3 files changed, 25 insertions(+), 46 deletions(-)
> > > 
> > > diff --git a/hw/pci-host/uninorth.c b/hw/pci-host/uninorth.c
> > > index 1ed1072eeb..0c0a9ecee1 100644
> > > --- a/hw/pci-host/uninorth.c
> > > +++ b/hw/pci-host/uninorth.c
> > > @@ -32,8 +32,6 @@
> > > #include "hw/pci-host/uninorth.h"
> > > #include "trace.h"
> > > 
> > > -static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e };
> > > -
> > > static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
> > > {
> > >     return (irq_num + (pci_dev->devfn >> 3)) & 3;
> > > @@ -43,7 +41,7 @@ static void pci_unin_set_irq(void *opaque, int irq_num, 
> > > int level)
> > > {
> > >     UNINHostState *s = opaque;
> > > 
> > > -    trace_unin_set_irq(unin_irq_line[irq_num], level);
> > > +    trace_unin_set_irq(irq_num, level);
> > >     qemu_set_irq(s->irqs[irq_num], level);
> > > }
> > > 
> > > @@ -112,15 +110,6 @@ static const MemoryRegionOps unin_data_ops = {
> > >     .endianness = DEVICE_LITTLE_ENDIAN,
> > > };
> > > 
> > > -static void pci_unin_init_irqs(UNINHostState *s)
> > > -{
> > > -    int i;
> > > -
> > > -    for (i = 0; i < ARRAY_SIZE(s->irqs); i++) {
> > > -    s->irqs[i] = qdev_get_gpio_in(DEVICE(s->pic), unin_irq_line[i]);
> > > -    }
> > > -}
> > > -
> > > static char *pci_unin_main_ofw_unit_address(const SysBusDevice *dev)
> > > {
> > >     UNINHostState *s = UNI_NORTH_PCI_HOST_BRIDGE(dev);
> > > @@ -141,7 +130,6 @@ static void pci_unin_main_realize(DeviceState *dev, 
> > > Error **errp)
> > >    PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
> > > 
> > >     pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north-pci");
> > > -    pci_unin_init_irqs(s);
> > > 
> > >     /* DEC 21154 bridge */
> > > #if 0
> > > @@ -172,15 +160,12 @@ static void pci_unin_main_init(Object *obj)
> > >  "unin-pci-hole", >pci_mmio,
> > >  0x8000ULL, 0x1000ULL);
> > > 
> > > -    object_property_add_link(obj, "pic", TYPE_OPENPIC,
> > > - (Object **) >pic,
> > > - qdev_prop_allow_set_link_before_realize,
> > > - 0);
> > > -
> > >     sysbus_init_mmio(sbd, >conf_mem);
> > >     sysbus_init_mmio(sbd, >data_mem);
> > >     sysbus_init_mmio(sbd, >pci_hole);
> > >     sysbus_init_mmio(sbd, >pci_io);
> > > +
> > > +    qdev_init_gpio_out(DEVICE(obj), s->irqs, ARRAY_SIZE(s->irqs));
> > > }
> > > 
> > > static void pci_u3_agp_realize(DeviceState *dev, Error **errp)
> > > @@ -196,7 +181,6 @@ static void pci_u3_agp_realize(DeviceState *dev, 
> > > Error **errp)
> > >    PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
> > > 
> > >     pci_create_simple(h->bus, PCI_DEVFN(11, 0), "u3-agp");
> > > -    pci_unin_init_irqs(s);
> > > }
> > > 
> > > static void pci_u3_agp_init(Object *obj)
> > > @@ -220,15 +204,12 @@ static void pci_u3_agp_init(Object *obj)
> > >  "unin-pci-hole", >pci_mmio,
> > >  0x8000ULL, 0x7000ULL);
> > > 
> > > -    object_property_add_link(obj, "pic", TYPE_OPENPIC,
> > > - (Object **) >pic,
> > > - qdev_prop_allow_set_link_before_realize,
> > > - 0);
> > > -
> > >     sysbus_init_mmio(sbd, >conf_mem);
> > >     sysbus_init_mmio(sbd, >data_mem);
> > >     sysbus_init_mmio(sbd, >pci_hole);
> > >     sysbus_init_mmio(sbd, >pci_io);
> > > +
> > > +    qdev_init_gpio_out(DEVICE(obj), s->irqs, ARRAY_SIZE(s->irqs));
> > > }
> > > 
> > > static void pci_unin_agp_realize(DeviceState *dev, Error **errp)
> > > @@ -244,7 +225,6 @@ static void pci_unin_agp_realize(DeviceState *dev, 
> > > Error **errp)
> > >    PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
> > > 
> > >     pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north-agp");
> > > -    pci_unin_init_irqs(s);
> > > }
> > > 
> > > static void pci_unin_agp_init(Object *obj)
> > > @@ -259,13 +239,10 @@ static void pci_unin_agp_init(Object *obj)
> > >     memory_region_init_io(>data_mem, OBJECT(h), _host_data_le_ops,
> > >   obj, "unin-agp-conf-data", 

Re: [PATCH v2 1/3] macio: don't reference serial_hd() directly within the device

2020-10-15 Thread David Gibson
On Tue, Oct 13, 2020 at 12:49:20PM +0100, Mark Cave-Ayland wrote:
> Instead use qdev_prop_set_chr() to configure the ESCC serial chardevs at the
> Mac Old World and New World machine level.
> 
> Also remove the now obsolete comment referring to the use of serial_hd() and
> the setting of user_creatable to false accordingly.
> 
> Signed-off-by: Mark Cave-Ayland 

Applied to ppc-for-5.2, thanks.

> ---
>  hw/misc/macio/macio.c | 4 
>  hw/ppc/mac_newworld.c | 6 ++
>  hw/ppc/mac_oldworld.c | 6 ++
>  3 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/misc/macio/macio.c b/hw/misc/macio/macio.c
> index 679722628e..51368884d0 100644
> --- a/hw/misc/macio/macio.c
> +++ b/hw/misc/macio/macio.c
> @@ -109,8 +109,6 @@ static void macio_common_realize(PCIDevice *d, Error 
> **errp)
>  qdev_prop_set_uint32(DEVICE(>escc), "disabled", 0);
>  qdev_prop_set_uint32(DEVICE(>escc), "frequency", ESCC_CLOCK);
>  qdev_prop_set_uint32(DEVICE(>escc), "it_shift", 4);
> -qdev_prop_set_chr(DEVICE(>escc), "chrA", serial_hd(0));
> -qdev_prop_set_chr(DEVICE(>escc), "chrB", serial_hd(1));
>  qdev_prop_set_uint32(DEVICE(>escc), "chnBtype", escc_serial);
>  qdev_prop_set_uint32(DEVICE(>escc), "chnAtype", escc_serial);
>  if (!qdev_realize(DEVICE(>escc), BUS(>macio_bus), errp)) {
> @@ -458,8 +456,6 @@ static void macio_class_init(ObjectClass *klass, void 
> *data)
>  k->class_id = PCI_CLASS_OTHERS << 8;
>  device_class_set_props(dc, macio_properties);
>  set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
> -/* Reason: Uses serial_hds in macio_instance_init */
> -dc->user_creatable = false;
>  }
>  
>  static const TypeInfo macio_bus_info = {
> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
> index 4dfbeec0ca..6f5ef2e782 100644
> --- a/hw/ppc/mac_newworld.c
> +++ b/hw/ppc/mac_newworld.c
> @@ -123,6 +123,7 @@ static void ppc_core99_init(MachineState *machine)
>  UNINHostState *uninorth_pci;
>  PCIBus *pci_bus;
>  PCIDevice *macio;
> +ESCCState *escc;
>  bool has_pmu, has_adb;
>  MACIOIDEState *macio_ide;
>  BusState *adb_bus;
> @@ -380,6 +381,11 @@ static void ppc_core99_init(MachineState *machine)
>  qdev_prop_set_bit(dev, "has-adb", has_adb);
>  object_property_set_link(OBJECT(macio), "pic", OBJECT(pic_dev),
>   _abort);
> +
> +escc = ESCC(object_resolve_path_component(OBJECT(macio), "escc"));
> +qdev_prop_set_chr(DEVICE(escc), "chrA", serial_hd(0));
> +qdev_prop_set_chr(DEVICE(escc), "chrB", serial_hd(1));
> +
>  pci_realize_and_unref(macio, pci_bus, _fatal);
>  
>  /* We only emulate 2 out of 3 IDE controllers for now */
> diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
> index f8173934a2..d6a76d06dc 100644
> --- a/hw/ppc/mac_oldworld.c
> +++ b/hw/ppc/mac_oldworld.c
> @@ -96,6 +96,7 @@ static void ppc_heathrow_init(MachineState *machine)
>  PCIBus *pci_bus;
>  PCIDevice *macio;
>  MACIOIDEState *macio_ide;
> +ESCCState *escc;
>  SysBusDevice *s;
>  DeviceState *dev, *pic_dev;
>  BusState *adb_bus;
> @@ -281,6 +282,11 @@ static void ppc_heathrow_init(MachineState *machine)
>  qdev_prop_set_uint64(dev, "frequency", tbfreq);
>  object_property_set_link(OBJECT(macio), "pic", OBJECT(pic_dev),
>   _abort);
> +
> +escc = ESCC(object_resolve_path_component(OBJECT(macio), "escc"));
> +qdev_prop_set_chr(DEVICE(escc), "chrA", serial_hd(0));
> +qdev_prop_set_chr(DEVICE(escc), "chrB", serial_hd(1));
> +
>  pci_realize_and_unref(macio, pci_bus, _fatal);
>  
>  macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio),

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


signature.asc
Description: PGP signature


Re: [PATCH v2 2/3] grackle: use qdev gpios for PCI IRQs

2020-10-15 Thread David Gibson
On Tue, Oct 13, 2020 at 12:49:21PM +0100, Mark Cave-Ayland wrote:
> Currently an object link property is used to pass a reference to the Heathrow
> PIC into the PCI host bridge so that grackle_init_irqs() can connect the PCI
> IRQs to the PIC itself.
> 
> This can be simplified by defining the PCI IRQs as qdev gpios and then wiring
> up the PCI IRQs to the PIC in the Old World machine init function.
> 
> Signed-off-by: Mark Cave-Ayland 

Applied to ppc-for-5.2.

> ---
>  hw/pci-host/grackle.c | 19 ++-
>  hw/ppc/mac_oldworld.c |  7 +--
>  2 files changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/hw/pci-host/grackle.c b/hw/pci-host/grackle.c
> index 57c29b20af..b05facf463 100644
> --- a/hw/pci-host/grackle.c
> +++ b/hw/pci-host/grackle.c
> @@ -28,7 +28,6 @@
>  #include "hw/ppc/mac.h"
>  #include "hw/qdev-properties.h"
>  #include "hw/pci/pci.h"
> -#include "hw/intc/heathrow_pic.h"
>  #include "hw/irq.h"
>  #include "qapi/error.h"
>  #include "qemu/module.h"
> @@ -41,7 +40,6 @@ struct GrackleState {
>  PCIHostState parent_obj;
>  
>  uint32_t ofw_addr;
> -HeathrowState *pic;
>  qemu_irq irqs[4];
>  MemoryRegion pci_mmio;
>  MemoryRegion pci_hole;
> @@ -62,15 +60,6 @@ static void pci_grackle_set_irq(void *opaque, int irq_num, 
> int level)
>  qemu_set_irq(s->irqs[irq_num], level);
>  }
>  
> -static void grackle_init_irqs(GrackleState *s)
> -{
> -int i;
> -
> -for (i = 0; i < ARRAY_SIZE(s->irqs); i++) {
> -s->irqs[i] = qdev_get_gpio_in(DEVICE(s->pic), 0x15 + i);
> -}
> -}
> -
>  static void grackle_realize(DeviceState *dev, Error **errp)
>  {
>  GrackleState *s = GRACKLE_PCI_HOST_BRIDGE(dev);
> @@ -85,7 +74,6 @@ static void grackle_realize(DeviceState *dev, Error **errp)
>   0, 4, TYPE_PCI_BUS);
>  
>  pci_create_simple(phb->bus, 0, "grackle");
> -grackle_init_irqs(s);
>  }
>  
>  static void grackle_init(Object *obj)
> @@ -106,15 +94,12 @@ static void grackle_init(Object *obj)
>  memory_region_init_io(>data_mem, obj, _host_data_le_ops,
>DEVICE(obj), "pci-data-idx", 0x1000);
>  
> -object_property_add_link(obj, "pic", TYPE_HEATHROW,
> - (Object **) >pic,
> - qdev_prop_allow_set_link_before_realize,
> - 0);
> -
>  sysbus_init_mmio(sbd, >conf_mem);
>  sysbus_init_mmio(sbd, >data_mem);
>  sysbus_init_mmio(sbd, >pci_hole);
>  sysbus_init_mmio(sbd, >pci_io);
> +
> +qdev_init_gpio_out(DEVICE(obj), s->irqs, ARRAY_SIZE(s->irqs));
>  }
>  
>  static void grackle_pci_realize(PCIDevice *d, Error **errp)
> diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
> index d6a76d06dc..05e46ee6fe 100644
> --- a/hw/ppc/mac_oldworld.c
> +++ b/hw/ppc/mac_oldworld.c
> @@ -253,10 +253,9 @@ static void ppc_heathrow_init(MachineState *machine)
>  /* Grackle PCI host bridge */
>  dev = qdev_new(TYPE_GRACKLE_PCI_HOST_BRIDGE);
>  qdev_prop_set_uint32(dev, "ofw-addr", 0x8000);
> -object_property_set_link(OBJECT(dev), "pic", OBJECT(pic_dev),
> - _abort);
>  s = SYS_BUS_DEVICE(dev);
>  sysbus_realize_and_unref(s, _fatal);
> +
>  sysbus_mmio_map(s, 0, GRACKLE_BASE);
>  sysbus_mmio_map(s, 1, GRACKLE_BASE + 0x20);
>  /* PCI hole */
> @@ -266,6 +265,10 @@ static void ppc_heathrow_init(MachineState *machine)
>  memory_region_add_subregion(get_system_memory(), 0xfe00,
>  sysbus_mmio_get_region(s, 3));
>  
> +for (i = 0; i < 4; i++) {
> +qdev_connect_gpio_out(dev, i, qdev_get_gpio_in(pic_dev, 0x15 + i));
> +}
> +
>  pci_bus = PCI_HOST_BRIDGE(dev)->bus;
>  
>  pci_vga_init(pci_bus);

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


signature.asc
Description: PGP signature


Re: [PATCH v2 3/3] uninorth: use qdev gpios for PCI IRQs

2020-10-15 Thread David Gibson
On Tue, Oct 13, 2020 at 12:49:22PM +0100, Mark Cave-Ayland wrote:
> Currently an object link property is used to pass a reference to the OpenPIC
> into the PCI host bridge so that pci_unin_init_irqs() can connect the PCI
> IRQs to the PIC itself.
> 
> This can be simplified by defining the PCI IRQs as qdev gpios and then wiring
> up the PCI IRQs to the PIC in the New World machine init function.
> 
> Signed-off-by: Mark Cave-Ayland 

Applied to ppc-for-5.2, thanks.

> ---
>  hw/pci-host/uninorth.c | 45 +++---
>  hw/ppc/mac_newworld.c  | 24 --
>  include/hw/pci-host/uninorth.h |  2 --
>  3 files changed, 25 insertions(+), 46 deletions(-)
> 
> diff --git a/hw/pci-host/uninorth.c b/hw/pci-host/uninorth.c
> index 1ed1072eeb..0c0a9ecee1 100644
> --- a/hw/pci-host/uninorth.c
> +++ b/hw/pci-host/uninorth.c
> @@ -32,8 +32,6 @@
>  #include "hw/pci-host/uninorth.h"
>  #include "trace.h"
>  
> -static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e };
> -
>  static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
>  {
>  return (irq_num + (pci_dev->devfn >> 3)) & 3;
> @@ -43,7 +41,7 @@ static void pci_unin_set_irq(void *opaque, int irq_num, int 
> level)
>  {
>  UNINHostState *s = opaque;
>  
> -trace_unin_set_irq(unin_irq_line[irq_num], level);
> +trace_unin_set_irq(irq_num, level);
>  qemu_set_irq(s->irqs[irq_num], level);
>  }
>  
> @@ -112,15 +110,6 @@ static const MemoryRegionOps unin_data_ops = {
>  .endianness = DEVICE_LITTLE_ENDIAN,
>  };
>  
> -static void pci_unin_init_irqs(UNINHostState *s)
> -{
> -int i;
> -
> -for (i = 0; i < ARRAY_SIZE(s->irqs); i++) {
> -s->irqs[i] = qdev_get_gpio_in(DEVICE(s->pic), unin_irq_line[i]);
> -}
> -}
> -
>  static char *pci_unin_main_ofw_unit_address(const SysBusDevice *dev)
>  {
>  UNINHostState *s = UNI_NORTH_PCI_HOST_BRIDGE(dev);
> @@ -141,7 +130,6 @@ static void pci_unin_main_realize(DeviceState *dev, Error 
> **errp)
> PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
>  
>  pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north-pci");
> -pci_unin_init_irqs(s);
>  
>  /* DEC 21154 bridge */
>  #if 0
> @@ -172,15 +160,12 @@ static void pci_unin_main_init(Object *obj)
>   "unin-pci-hole", >pci_mmio,
>   0x8000ULL, 0x1000ULL);
>  
> -object_property_add_link(obj, "pic", TYPE_OPENPIC,
> - (Object **) >pic,
> - qdev_prop_allow_set_link_before_realize,
> - 0);
> -
>  sysbus_init_mmio(sbd, >conf_mem);
>  sysbus_init_mmio(sbd, >data_mem);
>  sysbus_init_mmio(sbd, >pci_hole);
>  sysbus_init_mmio(sbd, >pci_io);
> +
> +qdev_init_gpio_out(DEVICE(obj), s->irqs, ARRAY_SIZE(s->irqs));
>  }
>  
>  static void pci_u3_agp_realize(DeviceState *dev, Error **errp)
> @@ -196,7 +181,6 @@ static void pci_u3_agp_realize(DeviceState *dev, Error 
> **errp)
> PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
>  
>  pci_create_simple(h->bus, PCI_DEVFN(11, 0), "u3-agp");
> -pci_unin_init_irqs(s);
>  }
>  
>  static void pci_u3_agp_init(Object *obj)
> @@ -220,15 +204,12 @@ static void pci_u3_agp_init(Object *obj)
>   "unin-pci-hole", >pci_mmio,
>   0x8000ULL, 0x7000ULL);
>  
> -object_property_add_link(obj, "pic", TYPE_OPENPIC,
> - (Object **) >pic,
> - qdev_prop_allow_set_link_before_realize,
> - 0);
> -
>  sysbus_init_mmio(sbd, >conf_mem);
>  sysbus_init_mmio(sbd, >data_mem);
>  sysbus_init_mmio(sbd, >pci_hole);
>  sysbus_init_mmio(sbd, >pci_io);
> +
> +qdev_init_gpio_out(DEVICE(obj), s->irqs, ARRAY_SIZE(s->irqs));
>  }
>  
>  static void pci_unin_agp_realize(DeviceState *dev, Error **errp)
> @@ -244,7 +225,6 @@ static void pci_unin_agp_realize(DeviceState *dev, Error 
> **errp)
> PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);
>  
>  pci_create_simple(h->bus, PCI_DEVFN(11, 0), "uni-north-agp");
> -pci_unin_init_irqs(s);
>  }
>  
>  static void pci_unin_agp_init(Object *obj)
> @@ -259,13 +239,10 @@ static void pci_unin_agp_init(Object *obj)
>  memory_region_init_io(>data_mem, OBJECT(h), _host_data_le_ops,
>obj, "unin-agp-conf-data", 0x1000);
>  
> -object_property_add_link(obj, "pic", TYPE_OPENPIC,
> - (Object **) >pic,
> - qdev_prop_allow_set_link_before_realize,
> - 0);
> -
>  sysbus_init_mmio(sbd, >conf_mem);
>  sysbus_init_mmio(sbd, >data_mem);
> +
> +qdev_init_gpio_out(DEVICE(obj), s->irqs, ARRAY_SIZE(s->irqs));
>  }
>  
>  static void pci_unin_internal_realize(DeviceState *dev, Error **errp)
> @@ -281,7 +258,6 @@ 

Re: [PATCH] ppc/spapr: re-assert IRQs during event-scan if there are pending

2020-10-15 Thread David Gibson
On Thu, Oct 15, 2020 at 11:03:18PM +0200, Laurent Vivier wrote:
> If we hotplug a CPU during the first second of the kernel boot,
> the IRQ can be sent to the kernel while the RTAS event handler
> is not installed. The event is queued, but the kernel doesn't
> collect it and ignores the new CPU.
> 
> As the code relies on edge-triggered IRQ, we can re-assert it
> during the event-scan RTAS call if there are still pending
> events (as it is already done in check-exception).
> 
> Signed-off-by: Laurent Vivier 

Applied to ppc-for-5.2.

> ---
>  hw/ppc/spapr_events.c | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
> index 1069d0197b4f..1add53547ec3 100644
> --- a/hw/ppc/spapr_events.c
> +++ b/hw/ppc/spapr_events.c
> @@ -1000,10 +1000,22 @@ static void event_scan(PowerPCCPU *cpu, 
> SpaprMachineState *spapr,
> target_ulong args,
> uint32_t nret, target_ulong rets)
>  {
> +int i;
>  if (nargs != 4 || nret != 1) {
>  rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
>  return;
>  }
> +
> +for (i = 0; i < EVENT_CLASS_MAX; i++) {
> +if (rtas_event_log_contains(EVENT_CLASS_MASK(i))) {
> +const SpaprEventSource *source =
> +spapr_event_sources_get_source(spapr->event_sources, i);
> +
> +g_assert(source->enabled);
> +qemu_irq_pulse(spapr_qirq(spapr, source->irq));
> +}
> +}
> +
>  rtas_st(rets, 0, RTAS_OUT_NO_ERRORS_FOUND);
>  }
>  

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


signature.asc
Description: PGP signature


Re: [PATCH v2 2/3] grackle: use qdev gpios for PCI IRQs

2020-10-15 Thread BALATON Zoltan via

On Thu, 15 Oct 2020, Mark Cave-Ayland wrote:
I've queued the grackle/uninorth patches to my qemu-macppc branch, however 
when I try to apply patches from the above series git fails with the 
following message:


Applying: mac_oldworld: Drop a variable, use get_system_memory() directly
error: sha1 information is lacking or useless (hw/ppc/mac_oldworld.c).
error: could not build fake ancestor


Maybe because these were based on your screamer branch but I could 
cherry-pick them from there to your qemu-macppc branch without issue.



Any chance you can rebase and repost? I'm happy to take patches 3 and 4, and


I've just posted the rebased series.

if my suggestion of casting the return address via target_ulong works then I 
think 1 and 2 are also fine.


Your original comment was:

"Given that this needs to work with both qemu-system-ppc and 
qemu-system-ppc64 would casting bios_addr to target_ulong work?"


This cast only appears in mac_oldworld.c which is qemu-system-ppc only (or 
not different in qemu-system-ppc64 unlike mac_newworld.c) so target_ulong 
there is basically uint32_t. I've changed the cast accordingly but I think 
it does not really matter.


The I2C stuff I can't really review, and weren't 
there still issues with the SPD data in patch 8 reporting the wrong RAM size?


As said in previous message the i2c and SPD patches are not quite ready 
yet so I've omitted those from this series, I may rework them later once 
this part is merged and can rebase the rest on top of that. We would also 
need your screamer patches to get the Mac ROM working, what is still 
missing for those?


Regards,
BALATON Zoltan



[PATCH v8 1/5] mac_oldworld: Allow loading binary ROM image

2020-10-15 Thread BALATON Zoltan via
The beige G3 Power Macintosh has a 4MB firmware ROM. Fix the size of
the rom region and fall back to loading a binary image with -bios if
loading ELF image failed. This allows testing emulation with a ROM
image from real hardware as well as using an ELF OpenBIOS image.

Signed-off-by: BALATON Zoltan 
---
 hw/ppc/mac_oldworld.c | 29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 05e46ee6fe..0a40769b3e 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -59,6 +59,8 @@
 #define NDRV_VGA_FILENAME "qemu_vga.ndrv"
 
 #define GRACKLE_BASE 0xfec0
+#define PROM_BASE 0xffc0
+#define PROM_SIZE (4 * MiB)
 
 static void fw_cfg_boot_set(void *opaque, const char *boot_device,
 Error **errp)
@@ -100,6 +102,7 @@ static void ppc_heathrow_init(MachineState *machine)
 SysBusDevice *s;
 DeviceState *dev, *pic_dev;
 BusState *adb_bus;
+uint64_t bios_addr;
 int bios_size;
 unsigned int smp_cpus = machine->smp.cpus;
 uint16_t ppc_boot_device;
@@ -128,24 +131,32 @@ static void ppc_heathrow_init(MachineState *machine)
 
 memory_region_add_subregion(sysmem, 0, machine->ram);
 
-/* allocate and load BIOS */
-memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", BIOS_SIZE,
+/* allocate and load firmware ROM */
+memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", PROM_SIZE,
_fatal);
+memory_region_add_subregion(sysmem, PROM_BASE, bios);
 
-if (bios_name == NULL)
+if (!bios_name) {
 bios_name = PROM_FILENAME;
+}
 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-memory_region_add_subregion(sysmem, PROM_ADDR, bios);
-
-/* Load OpenBIOS (ELF) */
 if (filename) {
-bios_size = load_elf(filename, NULL, 0, NULL, NULL, NULL, NULL, NULL,
- 1, PPC_ELF_MACHINE, 0, 0);
+/* Load OpenBIOS (ELF) */
+bios_size = load_elf(filename, NULL, NULL, NULL, NULL, _addr,
+ NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
+/* Unfortunately, load_elf sign-extends reading elf32 */
+bios_addr = (target_ulong)bios_addr;
+
+if (bios_size <= 0) {
+/* or load binary ROM image */
+bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE);
+bios_addr = PROM_BASE;
+}
 g_free(filename);
 } else {
 bios_size = -1;
 }
-if (bios_size < 0 || bios_size > BIOS_SIZE) {
+if (bios_size < 0 || bios_addr - PROM_BASE + bios_size > PROM_SIZE) {
 error_report("could not load PowerPC bios '%s'", bios_name);
 exit(1);
 }
-- 
2.21.3




[PATCH v8 2/5] mac_newworld: Allow loading binary ROM image

2020-10-15 Thread BALATON Zoltan via
Fall back to load binary ROM image if loading ELF fails. This also
moves PROM_BASE and PROM_SIZE defines to board as these are matching
the ROM size and address on this board and removes the now unused
PROM_ADDR and BIOS_SIZE defines from common mac.h.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/ppc/mac.h  |  2 --
 hw/ppc/mac_newworld.c | 22 ++
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index f3976b9a45..22c8408078 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -39,10 +39,8 @@
 /* SMP is not enabled, for now */
 #define MAX_CPUS 1
 
-#define BIOS_SIZE(1 * MiB)
 #define NVRAM_SIZE0x2000
 #define PROM_FILENAME"openbios-ppc"
-#define PROM_ADDR 0xfff0
 
 #define KERNEL_LOAD_ADDR 0x0100
 #define KERNEL_GAP   0x0010
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index 7a8dc09c8d..f9a1cc8944 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -82,6 +82,8 @@
 
 #define NDRV_VGA_FILENAME "qemu_vga.ndrv"
 
+#define PROM_BASE 0xfff0
+#define PROM_SIZE (1 * MiB)
 
 static void fw_cfg_boot_set(void *opaque, const char *boot_device,
 Error **errp)
@@ -100,7 +102,7 @@ static void ppc_core99_reset(void *opaque)
 
 cpu_reset(CPU(cpu));
 /* 970 CPUs want to get their initial IP as part of their boot protocol */
-cpu->env.nip = PROM_ADDR + 0x100;
+cpu->env.nip = PROM_BASE + 0x100;
 }
 
 /* PowerPC Mac99 hardware initialisation */
@@ -154,25 +156,29 @@ static void ppc_core99_init(MachineState *machine)
 /* allocate RAM */
 memory_region_add_subregion(get_system_memory(), 0, machine->ram);
 
-/* allocate and load BIOS */
-memory_region_init_rom(bios, NULL, "ppc_core99.bios", BIOS_SIZE,
+/* allocate and load firmware ROM */
+memory_region_init_rom(bios, NULL, "ppc_core99.bios", PROM_SIZE,
_fatal);
+memory_region_add_subregion(get_system_memory(), PROM_BASE, bios);
 
-if (bios_name == NULL)
+if (!bios_name) {
 bios_name = PROM_FILENAME;
+}
 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-memory_region_add_subregion(get_system_memory(), PROM_ADDR, bios);
-
-/* Load OpenBIOS (ELF) */
 if (filename) {
+/* Load OpenBIOS (ELF) */
 bios_size = load_elf(filename, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
 
+if (bios_size <= 0) {
+/* or load binary ROM image */
+bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE);
+}
 g_free(filename);
 } else {
 bios_size = -1;
 }
-if (bios_size < 0 || bios_size > BIOS_SIZE) {
+if (bios_size < 0 || bios_size > PROM_SIZE) {
 error_report("could not load PowerPC bios '%s'", bios_name);
 exit(1);
 }
-- 
2.21.3




[PATCH v8 0/5] Mac Old World ROM experiment (ppc/mac_* clean ups and loading binary ROM)

2020-10-15 Thread BALATON Zoltan via
This is the cut down version of the earlier series omitting unfinished
patches that I plan to rework later and rebased to Mark's qemu-macppc
branch. Compared to v7 the only change is the cast to (target_ulong)
from (uint32_t) as requested by Mark in patch 1.

Regards,
BALATON Zoltan

BALATON Zoltan (5):
  mac_oldworld: Allow loading binary ROM image
  mac_newworld: Allow loading binary ROM image
  mac_oldworld: Drop a variable, use get_system_memory() directly
  mac_oldworld: Drop some variables
  mac_oldworld: Change PCI address of macio to match real hardware

 hw/ppc/mac.h  |  2 --
 hw/ppc/mac_newworld.c | 22 --
 hw/ppc/mac_oldworld.c | 67 ---
 3 files changed, 52 insertions(+), 39 deletions(-)

-- 
2.21.3




[PATCH v8 4/5] mac_oldworld: Drop some variables

2020-10-15 Thread BALATON Zoltan via
Values not used frequently enough may not worth putting in a local
variable, especially with names almost as long as the original value
because that does not improve readability, to the contrary it makes it
harder to see what value is used. Drop a few such variables.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Mark Cave-Ayland 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/ppc/mac_oldworld.c | 35 +--
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 5b30fa0739..13eb9bafa1 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -83,14 +83,11 @@ static void ppc_heathrow_reset(void *opaque)
 static void ppc_heathrow_init(MachineState *machine)
 {
 ram_addr_t ram_size = machine->ram_size;
-const char *kernel_filename = machine->kernel_filename;
-const char *kernel_cmdline = machine->kernel_cmdline;
-const char *initrd_filename = machine->initrd_filename;
 const char *boot_device = machine->boot_order;
 PowerPCCPU *cpu = NULL;
 CPUPPCState *env = NULL;
 char *filename;
-int linux_boot, i;
+int i;
 MemoryRegion *bios = g_new(MemoryRegion, 1);
 uint32_t kernel_base, initrd_base, cmdline_base = 0;
 int32_t kernel_size, initrd_size;
@@ -109,8 +106,6 @@ static void ppc_heathrow_init(MachineState *machine)
 void *fw_cfg;
 uint64_t tbfreq;
 
-linux_boot = (kernel_filename != NULL);
-
 /* init CPUs */
 for (i = 0; i < smp_cpus; i++) {
 cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
@@ -147,7 +142,7 @@ static void ppc_heathrow_init(MachineState *machine)
 bios_addr = (target_ulong)bios_addr;
 
 if (bios_size <= 0) {
-/* or load binary ROM image */
+/* or if could not load ELF try loading a binary ROM image */
 bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE);
 bios_addr = PROM_BASE;
 }
@@ -160,7 +155,7 @@ static void ppc_heathrow_init(MachineState *machine)
 exit(1);
 }
 
-if (linux_boot) {
+if (machine->kernel_filename) {
 int bswap_needed;
 
 #ifdef BSWAP_NEEDED
@@ -169,29 +164,32 @@ static void ppc_heathrow_init(MachineState *machine)
 bswap_needed = 0;
 #endif
 kernel_base = KERNEL_LOAD_ADDR;
-kernel_size = load_elf(kernel_filename, NULL,
+kernel_size = load_elf(machine->kernel_filename, NULL,
translate_kernel_address, NULL, NULL, NULL,
NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
 if (kernel_size < 0)
-kernel_size = load_aout(kernel_filename, kernel_base,
+kernel_size = load_aout(machine->kernel_filename, kernel_base,
 ram_size - kernel_base, bswap_needed,
 TARGET_PAGE_SIZE);
 if (kernel_size < 0)
-kernel_size = load_image_targphys(kernel_filename,
+kernel_size = load_image_targphys(machine->kernel_filename,
   kernel_base,
   ram_size - kernel_base);
 if (kernel_size < 0) {
-error_report("could not load kernel '%s'", kernel_filename);
+error_report("could not load kernel '%s'",
+ machine->kernel_filename);
 exit(1);
 }
 /* load initrd */
-if (initrd_filename) {
-initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + 
KERNEL_GAP);
-initrd_size = load_image_targphys(initrd_filename, initrd_base,
+if (machine->initrd_filename) {
+initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size +
+KERNEL_GAP);
+initrd_size = load_image_targphys(machine->initrd_filename,
+  initrd_base,
   ram_size - initrd_base);
 if (initrd_size < 0) {
 error_report("could not load initial ram disk '%s'",
- initrd_filename);
+ machine->initrd_filename);
 exit(1);
 }
 cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
@@ -343,9 +341,10 @@ static void ppc_heathrow_init(MachineState *machine)
 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
-if (kernel_cmdline) {
+if (machine->kernel_cmdline) {
 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
-pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, 
kernel_cmdline);
+pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
+ machine->kernel_cmdline);
 } else 

[PATCH v8 3/5] mac_oldworld: Drop a variable, use get_system_memory() directly

2020-10-15 Thread BALATON Zoltan via
Half of the occurances already use get_system_memory() directly
instead of sysmem variable, convert the two other uses to
get_system_memory() too which seems to be more common and drop the
variable.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Mark Cave-Ayland 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/ppc/mac_oldworld.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 0a40769b3e..5b30fa0739 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -87,7 +87,6 @@ static void ppc_heathrow_init(MachineState *machine)
 const char *kernel_cmdline = machine->kernel_cmdline;
 const char *initrd_filename = machine->initrd_filename;
 const char *boot_device = machine->boot_order;
-MemoryRegion *sysmem = get_system_memory();
 PowerPCCPU *cpu = NULL;
 CPUPPCState *env = NULL;
 char *filename;
@@ -129,12 +128,12 @@ static void ppc_heathrow_init(MachineState *machine)
 exit(1);
 }
 
-memory_region_add_subregion(sysmem, 0, machine->ram);
+memory_region_add_subregion(get_system_memory(), 0, machine->ram);
 
 /* allocate and load firmware ROM */
 memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", PROM_SIZE,
_fatal);
-memory_region_add_subregion(sysmem, PROM_BASE, bios);
+memory_region_add_subregion(get_system_memory(), PROM_BASE, bios);
 
 if (!bios_name) {
 bios_name = PROM_FILENAME;
-- 
2.21.3




[PATCH v8 5/5] mac_oldworld: Change PCI address of macio to match real hardware

2020-10-15 Thread BALATON Zoltan via
The board firmware expect these to be at fixed addresses and programs
them without probing, this patch puts the macio device at the expected
PCI address.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Mark Cave-Ayland 
---
 hw/ppc/mac_oldworld.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 13eb9bafa1..bb563e8aab 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -288,7 +288,7 @@ static void ppc_heathrow_init(MachineState *machine)
 ide_drive_get(hd, ARRAY_SIZE(hd));
 
 /* MacIO */
-macio = pci_new(-1, TYPE_OLDWORLD_MACIO);
+macio = pci_new(PCI_DEVFN(16, 0), TYPE_OLDWORLD_MACIO);
 dev = DEVICE(macio);
 qdev_prop_set_uint64(dev, "frequency", tbfreq);
 object_property_set_link(OBJECT(macio), "pic", OBJECT(pic_dev),
-- 
2.21.3




Re: [PATCH 0/7] build: replace ninjatool with ninja

2020-10-15 Thread Howard Spoelstra
On Thu, Oct 15, 2020 at 7:39 PM Volker Rümelin  wrote:

>
> >
> > Thanks Paolo,
> >
> > Then only the issue regarding the pcbios/optionrom stuff remains ;-)
> >
> > make[1]: *** No rule to make target 'multiboot.bin', needed by 'all'.
> Stop.
> > make: *** [Makefile:171: pc-bios/optionrom/all] Error 2
> > make: *** Waiting for unfinished jobs
> >
> > Best,
> > Howard
> >
>
> Hi Howard,
>
> one solution for this issue is to uncomment the following line in
> msys2_shell.cmd.
>
> rem To activate windows native symlinks uncomment next line
> set MSYS=winsymlinks:nativestrict
>
> Then tell Windows 10 it's okay to create symlinks without elevated rights.
> Here is a link with a description how to do this.
> https://www.joshkel.com/2018/01/18/symlinks-in-windows/
>
> I think since commit bf708f3c4a "optionrom: simplify Makefile"
> pc-bios/optionrom/Makefile in your build directory has to be a symbolic
> link. Without 'set MSYS=winsymlinks:nativestrict' msys2 ln -s copies the
> Makefile instead of creating a symbolic link.
>
>
Thanks Volker!

I changed the Windows policy and setting in msys2_shell.cmd. However, I had
to edit ming64.ini to uncomment the MSYS=winsymlinks:nativestrict there as
well to get things going.

While it is great to have this fix, I can't say I'm really happy with the
need to change the Windows policy and to have to fix msys2.

The patches Mark referred to and to which I also pointed earlier did fix
this problem without changing Windows/Msys2/Mingw64 settings.

Best regards,
Howard


[RFC PATCH v2 4/4] target/mips: Allow using the 34Kf with 16/32/64 preset TLB entries

2020-10-15 Thread Philippe Mathieu-Daudé
Per "MIPS32 34K Processor Core Family Software User's Manual,
Revision 01.13" page 8 in "Joint TLB (JTLB)" section:

  "The JTLB is a fully associative TLB cache containing 16, 32,
   or 64-dual-entries mapping up to 128 virtual pages to their
   corresponding physical addresses."

Add these values to the CP0_Config1_MMU_preset array.

Example to use a 34Kf cpu with preset 64 TLB:

  $ qemu-system-mipsel -cpu 34Kf,tlb-entries=64 ...

This is helpful for developers of the Yocto Project [*]:

  Yocto Project uses qemu-system-mips 34Kf cpu model, to run 32bit
  MIPS CI loop. It was observed that in this case CI test execution
  time was almost twice longer than 64bit MIPS variant that runs
  under MIPS64R2-generic model. It was investigated and concluded
  that the difference in number of TLBs 16 in 34Kf case vs 64 in
  MIPS64R2-generic is responsible for most of CI real time execution
  difference. Because with 16 TLBs linux user-land trashes TLB more
  and it needs to execute more instructions in TLB refill handler
  calls, as result it runs much longer.

[*] https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg03428.html

Buglink: https://bugzilla.yoctoproject.org/show_bug.cgi?id=13992
Reported-by: Victor Kamensky 
Signed-off-by: Philippe Mathieu-Daudé 
---
 target/mips/translate_init.c.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/mips/translate_init.c.inc b/target/mips/translate_init.c.inc
index a426463c434..02500e696f4 100644
--- a/target/mips/translate_init.c.inc
+++ b/target/mips/translate_init.c.inc
@@ -258,6 +258,7 @@ const mips_def_t mips_defs[] =
(0 << CP0C1_IS) | (3 << CP0C1_IL) | (1 << CP0C1_IA) |
(0 << CP0C1_DS) | (3 << CP0C1_DL) | (1 << CP0C1_DA) |
(1 << CP0C1_CA),
+.CP0_Config1_MMU_preset = (const unsigned[]){16, 32, 64, 0},
 .CP0_Config2 = MIPS_CONFIG2,
 .CP0_Config3 = MIPS_CONFIG3 | (1 << CP0C3_VInt) | (1 << CP0C3_MT) |
(1 << CP0C3_DSPP),
-- 
2.26.2




[RFC PATCH v2 1/4] target/mips: Make cpu_mips_realize_env() propagate Error

2020-10-15 Thread Philippe Mathieu-Daudé
To be able to propagate error to our caller, make
cpu_mips_realize_env() take an Error argument and
return a boolean value indicating an error is set or
not, following the example documented since commit
e3fe3988d7 ("error: Document Error API usage rules").

Signed-off-by: Philippe Mathieu-Daudé 
---
 target/mips/internal.h  | 10 +-
 target/mips/cpu.c   |  4 +++-
 target/mips/translate.c |  4 +++-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/target/mips/internal.h b/target/mips/internal.h
index 7f159a9230c..c2b2e79c515 100644
--- a/target/mips/internal.h
+++ b/target/mips/internal.h
@@ -206,7 +206,15 @@ void mips_tcg_init(void);
 
 /* TODO QOM'ify CPU reset and remove */
 void cpu_state_reset(CPUMIPSState *s);
-void cpu_mips_realize_env(CPUMIPSState *env);
+
+/**
+ * cpu_mips_realize_env: Realize CPUMIPSState
+ * @env: CPUMIPSState object
+ * @errp: pointer to error object
+ * On success, return %true.
+ * On failure, store an error through @errp and return %false.
+ */
+bool cpu_mips_realize_env(CPUMIPSState *env, Error **errp);
 
 /* cp0_timer.c */
 uint32_t cpu_mips_get_random(CPUMIPSState *env);
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index e86cd065483..117c748345e 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -147,7 +147,9 @@ static void mips_cpu_realizefn(DeviceState *dev, Error 
**errp)
 return;
 }
 
-cpu_mips_realize_env(>env);
+if (!cpu_mips_realize_env(>env, errp)) {
+return;
+}
 
 cpu_reset(cs);
 qemu_init_vcpu(cs);
diff --git a/target/mips/translate.c b/target/mips/translate.c
index 398edf72898..4c9b6216321 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -31316,7 +31316,7 @@ void mips_tcg_init(void)
 
 #include "translate_init.c.inc"
 
-void cpu_mips_realize_env(CPUMIPSState *env)
+bool cpu_mips_realize_env(CPUMIPSState *env, Error **errp)
 {
 env->exception_base = (int32_t)0xBFC0;
 
@@ -31325,6 +31325,8 @@ void cpu_mips_realize_env(CPUMIPSState *env)
 #endif
 fpu_init(env, env->cpu_model);
 mvp_init(env, env->cpu_model);
+
+return true;
 }
 
 bool cpu_supports_cps_smp(const char *cpu_type)
-- 
2.26.2




[RFC PATCH v2 2/4] target/mips: Store number of TLB entries in CPUMIPSState

2020-10-15 Thread Philippe Mathieu-Daudé
As we want to make the number of TLB entries configurable,
store it in CPUMIPSState. Introduce the init_tlb_entries()
helper which initializes it from the CP0C1_MMU config content.

Signed-off-by: Philippe Mathieu-Daudé 
---
 target/mips/cpu.h|  1 +
 target/mips/translate.c  | 13 -
 target/mips/translate_init.c.inc |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/target/mips/cpu.h b/target/mips/cpu.h
index 7cf7f5239f7..b84e9a8fcae 100644
--- a/target/mips/cpu.h
+++ b/target/mips/cpu.h
@@ -1140,6 +1140,7 @@ struct CPUMIPSState {
 #endif
 
 const mips_def_t *cpu_model;
+uint8_t tlb_entries;
 void *irq[8];
 QEMUTimer *timer; /* Internal timer */
 struct MIPSITUState *itu;
diff --git a/target/mips/translate.c b/target/mips/translate.c
index 4c9b6216321..698bcee8915 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -31316,8 +31316,18 @@ void mips_tcg_init(void)
 
 #include "translate_init.c.inc"
 
+static bool init_tlb_entries(CPUMIPSState *env, Error **errp)
+{
+env->tlb_entries = 1 + extract32(env->cpu_model->CP0_Config1, CP0C1_MMU, 
6);
+
+return true;
+}
+
 bool cpu_mips_realize_env(CPUMIPSState *env, Error **errp)
 {
+if (!init_tlb_entries(env, errp)) {
+return false;
+}
 env->exception_base = (int32_t)0xBFC0;
 
 #ifndef CONFIG_USER_ONLY
@@ -31357,7 +31367,8 @@ void cpu_state_reset(CPUMIPSState *env)
 #ifdef TARGET_WORDS_BIGENDIAN
 env->CP0_Config0 |= (1 << CP0C0_BE);
 #endif
-env->CP0_Config1 = env->cpu_model->CP0_Config1;
+env->CP0_Config1 = deposit32(env->cpu_model->CP0_Config1, CP0C1_MMU, 6,
+ env->tlb_entries - 1);
 env->CP0_Config2 = env->cpu_model->CP0_Config2;
 env->CP0_Config3 = env->cpu_model->CP0_Config3;
 env->CP0_Config4 = env->cpu_model->CP0_Config4;
diff --git a/target/mips/translate_init.c.inc b/target/mips/translate_init.c.inc
index 637caccd890..a426463c434 100644
--- a/target/mips/translate_init.c.inc
+++ b/target/mips/translate_init.c.inc
@@ -946,7 +946,7 @@ static void fixed_mmu_init (CPUMIPSState *env, const 
mips_def_t *def)
 
 static void r4k_mmu_init (CPUMIPSState *env, const mips_def_t *def)
 {
-env->tlb->nb_tlb = 1 + ((def->CP0_Config1 >> CP0C1_MMU) & 63);
+env->tlb->nb_tlb = env->tlb_entries;
 env->tlb->map_address = _map_address;
 env->tlb->helper_tlbwi = r4k_helper_tlbwi;
 env->tlb->helper_tlbwr = r4k_helper_tlbwr;
-- 
2.26.2




[RFC PATCH v2 3/4] target/mips: Make the number of TLB entries a CPU property

2020-10-15 Thread Philippe Mathieu-Daudé
Allow selecting the number of TLB entries from a preset array.

Signed-off-by: Philippe Mathieu-Daudé 
---
 target/mips/internal.h  |  1 +
 target/mips/cpu.c   |  8 +++-
 target/mips/translate.c | 26 --
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/target/mips/internal.h b/target/mips/internal.h
index c2b2e79c515..34f82c6e842 100644
--- a/target/mips/internal.h
+++ b/target/mips/internal.h
@@ -29,6 +29,7 @@ struct mips_def_t {
 int32_t CP0_PRid;
 int32_t CP0_Config0;
 int32_t CP0_Config1;
+const unsigned *CP0_Config1_MMU_preset;
 int32_t CP0_Config2;
 int32_t CP0_Config3;
 int32_t CP0_Config4;
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index 117c748345e..da31831368b 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -26,7 +26,7 @@
 #include "qemu/module.h"
 #include "sysemu/kvm.h"
 #include "exec/exec-all.h"
-
+#include "hw/qdev-properties.h"
 
 static void mips_cpu_set_pc(CPUState *cs, vaddr value)
 {
@@ -183,6 +183,11 @@ static ObjectClass *mips_cpu_class_by_name(const char 
*cpu_model)
 return oc;
 }
 
+static Property mips_cpu_properties[] = {
+DEFINE_PROP_UINT8("tlb-entries", MIPSCPU, env.tlb_entries, 0),
+DEFINE_PROP_END_OF_LIST()
+};
+
 static void mips_cpu_class_init(ObjectClass *c, void *data)
 {
 MIPSCPUClass *mcc = MIPS_CPU_CLASS(c);
@@ -192,6 +197,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
 device_class_set_parent_realize(dc, mips_cpu_realizefn,
 >parent_realize);
 device_class_set_parent_reset(dc, mips_cpu_reset, >parent_reset);
+device_class_set_props(dc, mips_cpu_properties);
 
 cc->class_by_name = mips_cpu_class_by_name;
 cc->has_work = mips_cpu_has_work;
diff --git a/target/mips/translate.c b/target/mips/translate.c
index 698bcee8915..f5815160fb6 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -39,6 +39,7 @@
 #include "exec/translator.h"
 #include "exec/log.h"
 #include "qemu/qemu-print.h"
+#include "qapi/error.h"
 
 #define MIPS_DEBUG_DISAS 0
 
@@ -31318,9 +31319,30 @@ void mips_tcg_init(void)
 
 static bool init_tlb_entries(CPUMIPSState *env, Error **errp)
 {
-env->tlb_entries = 1 + extract32(env->cpu_model->CP0_Config1, CP0C1_MMU, 
6);
+const unsigned *preset = env->cpu_model->CP0_Config1_MMU_preset;
+bool valid = false;
 
-return true;
+if (!env->tlb_entries) {
+env->tlb_entries = 1 + extract32(env->cpu_model->CP0_Config1,
+ CP0C1_MMU, 6);
+return true;
+}
+if (!preset) {
+error_setg(errp, "Property 'tlb-entries' not modifiable for this CPU");
+return false;
+}
+while (!valid && *preset) {
+if (*preset == env->tlb_entries) {
+valid = true;
+break;
+}
+preset++;
+}
+if (!valid) {
+error_setg(errp, "Invalid value '%u' for property 'tlb-entries'",
+   env->tlb_entries);
+}
+return valid;
 }
 
 bool cpu_mips_realize_env(CPUMIPSState *env, Error **errp)
-- 
2.26.2




[RFC PATCH v2 0/4] target/mips: Make the number of TLB entries a CPU property

2020-10-15 Thread Philippe Mathieu-Daudé
Yocto developers have expressed interest in running MIPS32
CPU with preset number of TLB:
https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg03428.html

Help them by allowing to set the TLB entries from a preset array
of valid hardware values.

Please test/review,

Phil.

Philippe Mathieu-Daudé (4):
  target/mips: Make cpu_mips_realize_env() propagate Error
  target/mips: Store number of TLB entries in CPUMIPSState
  target/mips: Make the number of TLB entries a CPU property
  target/mips: Allow using the 34Kf with 16/32/64 preset TLB entries

 target/mips/cpu.h|  1 +
 target/mips/internal.h   | 11 -
 target/mips/cpu.c| 12 --
 target/mips/translate.c  | 39 ++--
 target/mips/translate_init.c.inc |  3 ++-
 5 files changed, 60 insertions(+), 6 deletions(-)

-- 
2.26.2




Re: [PATCH] ppc/spapr: re-assert IRQs during event-scan if there are pending

2020-10-15 Thread Greg Kurz
On Thu, 15 Oct 2020 23:03:18 +0200
Laurent Vivier  wrote:

> If we hotplug a CPU during the first second of the kernel boot,
> the IRQ can be sent to the kernel while the RTAS event handler
> is not installed. The event is queued, but the kernel doesn't
> collect it and ignores the new CPU.
> 
> As the code relies on edge-triggered IRQ, we can re-assert it
> during the event-scan RTAS call if there are still pending
> events (as it is already done in check-exception).
> 
> Signed-off-by: Laurent Vivier 
> ---

Any BugId to share ?

>  hw/ppc/spapr_events.c | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
> index 1069d0197b4f..1add53547ec3 100644
> --- a/hw/ppc/spapr_events.c
> +++ b/hw/ppc/spapr_events.c
> @@ -1000,10 +1000,22 @@ static void event_scan(PowerPCCPU *cpu, 
> SpaprMachineState *spapr,
> target_ulong args,
> uint32_t nret, target_ulong rets)
>  {
> +int i;
>  if (nargs != 4 || nret != 1) {
>  rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
>  return;
>  }
> +
> +for (i = 0; i < EVENT_CLASS_MAX; i++) {
> +if (rtas_event_log_contains(EVENT_CLASS_MASK(i))) {
> +const SpaprEventSource *source =
> +spapr_event_sources_get_source(spapr->event_sources, i);
> +
> +g_assert(source->enabled);
> +qemu_irq_pulse(spapr_qirq(spapr, source->irq));
> +}
> +}
> +

This looks good but any reason for not putting this in a function called by
both event_scan() and check_exception() ?

Anyway, this can be done as a follow-up:

Reviewed-by: Greg Kurz 

>  rtas_st(rets, 0, RTAS_OUT_NO_ERRORS_FOUND);
>  }
>  




Re: [PATCH v4 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Paolo Bonzini
Il ven 16 ott 2020, 00:06 Yonggang Luo  ha scritto:

> meson didn't support running ../scripts/kernel-do directly
>

Can you explain why this matters? Meson does not look at docs/conf.py.

Paolo


> Signed-off-by: Yonggang Luo 
> ---
>  docs/conf.py | 2 +-
>  docs/sphinx/kerneldoc.py | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/docs/conf.py b/docs/conf.py
> index 00e1b750e2..e584f68393 100644
> --- a/docs/conf.py
> +++ b/docs/conf.py
> @@ -241,7 +241,7 @@ texinfo_documents = [
>  # We use paths starting from qemu_docdir here so that you can run
>  # sphinx-build from anywhere and the kerneldoc extension can still
>  # find everything.
> -kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc')
> +kerneldoc_bin = ['perl', os.path.join(qemu_docdir,
> '../scripts/kernel-doc')]
>  kerneldoc_srctree = os.path.join(qemu_docdir, '..')
>  hxtool_srctree = os.path.join(qemu_docdir, '..')
>  qapidoc_srctree = os.path.join(qemu_docdir, '..')
> diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py
> index 3e87940206..3ac277d162 100644
> --- a/docs/sphinx/kerneldoc.py
> +++ b/docs/sphinx/kerneldoc.py
> @@ -67,7 +67,7 @@ class KernelDocDirective(Directive):
>
>  def run(self):
>  env = self.state.document.settings.env
> -cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno']
> +cmd = env.config.kerneldoc_bin + ['-rst', '-enable-lineno']
>
>  filename = env.config.kerneldoc_srctree + '/' + self.arguments[0]
>  export_file_patterns = []
> --
> 2.28.0.windows.1
>
>


[PATCH v4 3/4] meson: Move the detection logic for sphinx to meson

2020-10-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 configure | 59 +++---
 docs/meson.build  |  4 +--
 meson.build   | 60 +++
 meson_options.txt |  5 ++-
 tests/qapi-schema/meson.build |  2 +-
 5 files changed, 64 insertions(+), 66 deletions(-)

diff --git a/configure b/configure
index 1ce31f97b4..ff593a8542 100755
--- a/configure
+++ b/configure
@@ -297,7 +297,7 @@ brlapi=""
 curl=""
 iconv="auto"
 curses="auto"
-docs=""
+docs="auto"
 fdt="auto"
 netmap="no"
 sdl="auto"
@@ -822,15 +822,6 @@ do
 fi
 done
 
-sphinx_build=
-for binary in sphinx-build-3 sphinx-build
-do
-if has "$binary"
-then
-sphinx_build=$(command -v "$binary")
-break
-fi
-done
 
 # Check for ancillary tools used in testing
 genisoimage=
@@ -1226,9 +1217,9 @@ for opt do
   ;;
   --disable-crypto-afalg) crypto_afalg="no"
   ;;
-  --disable-docs) docs="no"
+  --disable-docs) docs="disabled"
   ;;
-  --enable-docs) docs="yes"
+  --enable-docs) docs="enabled"
   ;;
   --disable-vhost-net) vhost_net="no"
   ;;
@@ -4413,45 +4404,6 @@ if check_include linux/btrfs.h ; then
 btrfs=yes
 fi
 
-# If we're making warnings fatal, apply this to Sphinx runs as well
-sphinx_werror=""
-if test "$werror" = "yes"; then
-sphinx_werror="-W"
-fi
-
-# Check we have a new enough version of sphinx-build
-has_sphinx_build() {
-# This is a bit awkward but works: create a trivial document and
-# try to run it with our configuration file (which enforces a
-# version requirement). This will fail if either
-# sphinx-build doesn't exist at all or if it is too old.
-mkdir -p "$TMPDIR1/sphinx"
-touch "$TMPDIR1/sphinx/index.rst"
-"$sphinx_build" $sphinx_werror -c "$source_path/docs" \
--b html "$TMPDIR1/sphinx" \
-"$TMPDIR1/sphinx/out"  >> config.log 2>&1
-}
-
-# Check if tools are available to build documentation.
-if test "$docs" != "no" ; then
-  if has_sphinx_build; then
-sphinx_ok=yes
-  else
-sphinx_ok=no
-  fi
-  if test "$sphinx_ok" = "yes"; then
-docs=yes
-  else
-if test "$docs" = "yes" ; then
-  if has $sphinx_build && test "$sphinx_ok" != "yes"; then
-echo "Warning: $sphinx_build exists but it is either too old or uses 
too old a Python version" >&2
-  fi
-  feature_not_found "docs" "Install a Python 3 version of python-sphinx"
-fi
-docs=no
-  fi
-fi
-
 # Search for bswap_32 function
 byteswap_h=no
 cat > $TMPC << EOF
@@ -6087,9 +6039,6 @@ qemu_version=$(head $source_path/VERSION)
 echo "PKGVERSION=$pkgversion" >>$config_host_mak
 echo "SRC_PATH=$source_path" >> $config_host_mak
 echo "TARGET_DIRS=$target_list" >> $config_host_mak
-if [ "$docs" = "yes" ] ; then
-  echo "BUILD_DOCS=yes" >> $config_host_mak
-fi
 if test "$modules" = "yes"; then
   # $shacmd can generate a hash started with digit, which the compiler doesn't
   # like as an symbol. So prefix it with an underscore
@@ -6794,7 +6743,6 @@ fi
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "PYTHON=$python" >> $config_host_mak
-echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
 echo "MESON=$meson" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
@@ -7076,6 +7024,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
 -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
 -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
 -Diconv=$iconv -Dcurses=$curses \
+-Ddocs=$docs -Dsphinx_build=$sphinx_build \
 $cross_arg \
 "$PWD" "$source_path"
 
diff --git a/docs/meson.build b/docs/meson.build
index 0340d489ac..f566809a6a 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -37,7 +37,7 @@ if build_docs
 input: [files('conf.py'), files(manual / 'conf.py')],
 depfile: manual + '.d',
 depend_files: sphinx_extn_depends,
-command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@',
+command: SPHINX_ARGS + ['-Ddepfile=@DEPFILE@',
   '-Ddepfile_stamp=@OUTPUT0@',
   '-b', 'html', '-d', private_dir,
   input_dir, output_dir])
@@ -59,7 +59,7 @@ if build_docs
  input: this_manual,
  install: build_docs,
  install_dir: install_dirs,
- command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
+ command: SPHINX_ARGS + ['-b', 'man', '-d', 
private_dir,
input_dir, meson.current_build_dir()])
 endif
   endforeach
diff --git a/meson.build b/meson.build
index 8156df8b71..8940468208 100644
--- a/meson.build
+++ b/meson.build
@@ -17,7 +17,13 @@ cc = meson.get_compiler('c')
 config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
 

[PATCH v4 4/4] cirrus: Enable doc build on msys2/mingw

2020-10-15 Thread Yonggang Luo
Currently rST depends on old version sphinx-2.x.
Install it by downloading it.
Remove the need of university mirror, the main repo are recovered.

Signed-off-by: Yonggang Luo 
---
 .cirrus.yml | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 99d118239c..f42ccb956a 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -76,7 +76,6 @@ windows_msys2_task:
 ((Get-Content -path 
C:\tools\msys64\etc\\post-install\\07-pacman-key.post -Raw) -replace 
'--refresh-keys', '--version') | Set-Content -Path 
C:\tools\msys64\etc\\post-install\\07-pacman-key.post
 C:\tools\msys64\usr\bin\bash.exe -lc "sed -i 
's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
 C:\tools\msys64\usr\bin\bash.exe -lc "export"
-C:\tools\msys64\usr\bin\bash.exe -lc "grep -rl 'repo.msys2.org/' 
/etc/pacman.d/mirrorlist.* | xargs sed -i 
's/repo.msys2.org\//mirrors.tuna.tsinghua.edu.cn\/msys2\//g'"
 C:\tools\msys64\usr\bin\pacman.exe --noconfirm -Sy
 echo Y | C:\tools\msys64\usr\bin\pacman.exe --noconfirm -Suu 
--overwrite=*
 taskkill /F /FI "MODULES eq msys-2.0.dll"
@@ -111,6 +110,11 @@ windows_msys2_task:
   mingw-w64-x86_64-curl \
   mingw-w64-x86_64-gnutls \
   "
+bitsadmin /transfer msys_download /dynamic /download /priority 
FOREGROUND `
+  
https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
 `
+  C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
+C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -U 
/c/tools/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz"
+del C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
 C:\tools\msys64\usr\bin\bash.exe -lc "rm -rf /var/cache/pacman/pkg/*"
 cd C:\tools\msys64
 echo "Start archive"
-- 
2.28.0.windows.1




[PATCH v4 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Yonggang Luo
meson didn't support running ../scripts/kernel-do directly

Signed-off-by: Yonggang Luo 
---
 docs/conf.py | 2 +-
 docs/sphinx/kerneldoc.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index 00e1b750e2..e584f68393 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -241,7 +241,7 @@ texinfo_documents = [
 # We use paths starting from qemu_docdir here so that you can run
 # sphinx-build from anywhere and the kerneldoc extension can still
 # find everything.
-kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc')
+kerneldoc_bin = ['perl', os.path.join(qemu_docdir, '../scripts/kernel-doc')]
 kerneldoc_srctree = os.path.join(qemu_docdir, '..')
 hxtool_srctree = os.path.join(qemu_docdir, '..')
 qapidoc_srctree = os.path.join(qemu_docdir, '..')
diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py
index 3e87940206..3ac277d162 100644
--- a/docs/sphinx/kerneldoc.py
+++ b/docs/sphinx/kerneldoc.py
@@ -67,7 +67,7 @@ class KernelDocDirective(Directive):
 
 def run(self):
 env = self.state.document.settings.env
-cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno']
+cmd = env.config.kerneldoc_bin + ['-rst', '-enable-lineno']
 
 filename = env.config.kerneldoc_srctree + '/' + self.arguments[0]
 export_file_patterns = []
-- 
2.28.0.windows.1




[PATCH v4 0/4] Fixes docs building on msys2/mingw

2020-10-15 Thread Yonggang Luo
V3-V4
Quic fixes of
python style
if xxx:

tested locally

V2-V3
No need convert perl trick to python script anymore
after Paolo's removal of ninjatool.
Revise Meson: Move the detection logic for sphinx to meson
for pass other platform by letting SPHINX_ARGS to be empty
when build_docs are false

v1 - v2
Also move the docs configure part from
configure to meson, this also fixed the pending
ninjatool removal caused issue that docs  can
not be build under msys2/mingw

Yonggang Luo (4):
  docs: Fixes build docs on msys2/mingw
  configure: the docdir option should passed to meson as is.
  meson: Move the detection logic for sphinx to meson
  cirrus: Enable doc build on msys2/mingw

 .cirrus.yml   |  6 +++-
 configure | 62 +++
 docs/conf.py  |  2 +-
 docs/meson.build  |  4 +--
 docs/sphinx/kerneldoc.py  |  2 +-
 meson.build   | 60 +
 meson_options.txt |  5 ++-
 tests/qapi-schema/meson.build |  2 +-
 8 files changed, 72 insertions(+), 71 deletions(-)

-- 
2.28.0.windows.1




[PATCH v4 2/4] configure: the docdir option should passed to meson as is.

2020-10-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 configure | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/configure b/configure
index f839c2a557..1ce31f97b4 100755
--- a/configure
+++ b/configure
@@ -971,7 +971,7 @@ for opt do
   ;;
   --with-suffix=*) qemu_suffix="$optarg"
   ;;
-  --docdir=*) qemu_docdir="$optarg"
+  --docdir=*) docdir="$optarg"
   ;;
   --sysconfdir=*) sysconfdir="$optarg"
   ;;
@@ -5770,7 +5770,6 @@ fi
 qemu_confdir="$sysconfdir/$qemu_suffix"
 qemu_moddir="$libdir/$qemu_suffix"
 qemu_datadir="$datadir/$qemu_suffix"
-qemu_docdir="$docdir/$qemu_suffix"
 qemu_localedir="$datadir/locale"
 qemu_icondir="$datadir/icons"
 qemu_desktopdir="$datadir/applications"
-- 
2.28.0.windows.1




Re: [PATCH v2 0/4] Fixes docs building on msys2/mingw

2020-10-15 Thread Yonggang Luo
On Fri, Oct 16, 2020 at 5:53 AM Paolo Bonzini  wrote:
>
> Looks good, apart from the CR removal patch that can simply be dropped.
Resend with fixes, the CR removal patch composite two part.

>
> Paolo
>
> Il gio 15 ott 2020, 22:10 Yonggang Luo  ha scritto:
>>
>> v1 - v2
>> Also move the docs configure part from
>> configure to meson, this also fixed the pending
>> ninjatool removal caused issue that docs  can
>> not be build under msys2/mingw
>>
>> Yonggang Luo (4):
>>   docs: Fixes build docs on msys2/mingw
>>   configure: the docdir option should passed to meson as is.
>>   meson: Move the detection logic for sphinx to meson
>>   cirrus: Enable doc build on msys2/mingw
>>
>>  .cirrus.yml   |  6 +++-
>>  configure | 62 +++
>>  docs/conf.py  |  2 +-
>>  docs/meson.build  |  4 +--
>>  docs/sphinx/kerneldoc.py  |  2 +-
>>  meson.build   | 59 +
>>  meson_options.txt |  5 ++-
>>  scripts/rst-sanitize.py   | 21 
>>  tests/qapi-schema/meson.build |  7 ++--
>>  9 files changed, 95 insertions(+), 73 deletions(-)
>>  create mode 100644 scripts/rst-sanitize.py
>>
>> --
>> 2.28.0.windows.1
>>
>>


--
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


[PATCH v3 3/4] meson: Move the detection logic for sphinx to meson

2020-10-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 configure | 59 +++
 docs/meson.build  |  4 +--
 meson.build   | 59 ++-
 meson_options.txt |  5 ++-
 tests/qapi-schema/meson.build |  2 +-
 5 files changed, 63 insertions(+), 66 deletions(-)

diff --git a/configure b/configure
index 1ce31f97b4..ff593a8542 100755
--- a/configure
+++ b/configure
@@ -297,7 +297,7 @@ brlapi=""
 curl=""
 iconv="auto"
 curses="auto"
-docs=""
+docs="auto"
 fdt="auto"
 netmap="no"
 sdl="auto"
@@ -822,15 +822,6 @@ do
 fi
 done
 
-sphinx_build=
-for binary in sphinx-build-3 sphinx-build
-do
-if has "$binary"
-then
-sphinx_build=$(command -v "$binary")
-break
-fi
-done
 
 # Check for ancillary tools used in testing
 genisoimage=
@@ -1226,9 +1217,9 @@ for opt do
   ;;
   --disable-crypto-afalg) crypto_afalg="no"
   ;;
-  --disable-docs) docs="no"
+  --disable-docs) docs="disabled"
   ;;
-  --enable-docs) docs="yes"
+  --enable-docs) docs="enabled"
   ;;
   --disable-vhost-net) vhost_net="no"
   ;;
@@ -4413,45 +4404,6 @@ if check_include linux/btrfs.h ; then
 btrfs=yes
 fi
 
-# If we're making warnings fatal, apply this to Sphinx runs as well
-sphinx_werror=""
-if test "$werror" = "yes"; then
-sphinx_werror="-W"
-fi
-
-# Check we have a new enough version of sphinx-build
-has_sphinx_build() {
-# This is a bit awkward but works: create a trivial document and
-# try to run it with our configuration file (which enforces a
-# version requirement). This will fail if either
-# sphinx-build doesn't exist at all or if it is too old.
-mkdir -p "$TMPDIR1/sphinx"
-touch "$TMPDIR1/sphinx/index.rst"
-"$sphinx_build" $sphinx_werror -c "$source_path/docs" \
--b html "$TMPDIR1/sphinx" \
-"$TMPDIR1/sphinx/out"  >> config.log 2>&1
-}
-
-# Check if tools are available to build documentation.
-if test "$docs" != "no" ; then
-  if has_sphinx_build; then
-sphinx_ok=yes
-  else
-sphinx_ok=no
-  fi
-  if test "$sphinx_ok" = "yes"; then
-docs=yes
-  else
-if test "$docs" = "yes" ; then
-  if has $sphinx_build && test "$sphinx_ok" != "yes"; then
-echo "Warning: $sphinx_build exists but it is either too old or uses 
too old a Python version" >&2
-  fi
-  feature_not_found "docs" "Install a Python 3 version of python-sphinx"
-fi
-docs=no
-  fi
-fi
-
 # Search for bswap_32 function
 byteswap_h=no
 cat > $TMPC << EOF
@@ -6087,9 +6039,6 @@ qemu_version=$(head $source_path/VERSION)
 echo "PKGVERSION=$pkgversion" >>$config_host_mak
 echo "SRC_PATH=$source_path" >> $config_host_mak
 echo "TARGET_DIRS=$target_list" >> $config_host_mak
-if [ "$docs" = "yes" ] ; then
-  echo "BUILD_DOCS=yes" >> $config_host_mak
-fi
 if test "$modules" = "yes"; then
   # $shacmd can generate a hash started with digit, which the compiler doesn't
   # like as an symbol. So prefix it with an underscore
@@ -6794,7 +6743,6 @@ fi
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "PYTHON=$python" >> $config_host_mak
-echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
 echo "MESON=$meson" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
@@ -7076,6 +7024,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
 -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
 -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
 -Diconv=$iconv -Dcurses=$curses \
+-Ddocs=$docs -Dsphinx_build=$sphinx_build \
 $cross_arg \
 "$PWD" "$source_path"
 
diff --git a/docs/meson.build b/docs/meson.build
index 0340d489ac..f566809a6a 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -37,7 +37,7 @@ if build_docs
 input: [files('conf.py'), files(manual / 'conf.py')],
 depfile: manual + '.d',
 depend_files: sphinx_extn_depends,
-command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@',
+command: SPHINX_ARGS + ['-Ddepfile=@DEPFILE@',
   '-Ddepfile_stamp=@OUTPUT0@',
   '-b', 'html', '-d', private_dir,
   input_dir, output_dir])
@@ -59,7 +59,7 @@ if build_docs
  input: this_manual,
  install: build_docs,
  install_dir: install_dirs,
- command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
+ command: SPHINX_ARGS + ['-b', 'man', '-d', 
private_dir,
input_dir, meson.current_build_dir()])
 endif
   endforeach
diff --git a/meson.build b/meson.build
index 8156df8b71..ddd64d6df5 100644
--- a/meson.build
+++ b/meson.build
@@ -17,7 +17,13 @@ cc = meson.get_compiler('c')
 config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
 

[PATCH v3 4/4] cirrus: Enable doc build on msys2/mingw

2020-10-15 Thread Yonggang Luo
Currently rST depends on old version sphinx-2.x.
Install it by downloading it.
Remove the need of university mirror, the main repo are recovered.

Signed-off-by: Yonggang Luo 
---
 .cirrus.yml | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 99d118239c..f42ccb956a 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -76,7 +76,6 @@ windows_msys2_task:
 ((Get-Content -path 
C:\tools\msys64\etc\\post-install\\07-pacman-key.post -Raw) -replace 
'--refresh-keys', '--version') | Set-Content -Path 
C:\tools\msys64\etc\\post-install\\07-pacman-key.post
 C:\tools\msys64\usr\bin\bash.exe -lc "sed -i 
's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
 C:\tools\msys64\usr\bin\bash.exe -lc "export"
-C:\tools\msys64\usr\bin\bash.exe -lc "grep -rl 'repo.msys2.org/' 
/etc/pacman.d/mirrorlist.* | xargs sed -i 
's/repo.msys2.org\//mirrors.tuna.tsinghua.edu.cn\/msys2\//g'"
 C:\tools\msys64\usr\bin\pacman.exe --noconfirm -Sy
 echo Y | C:\tools\msys64\usr\bin\pacman.exe --noconfirm -Suu 
--overwrite=*
 taskkill /F /FI "MODULES eq msys-2.0.dll"
@@ -111,6 +110,11 @@ windows_msys2_task:
   mingw-w64-x86_64-curl \
   mingw-w64-x86_64-gnutls \
   "
+bitsadmin /transfer msys_download /dynamic /download /priority 
FOREGROUND `
+  
https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
 `
+  C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
+C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -U 
/c/tools/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz"
+del C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
 C:\tools\msys64\usr\bin\bash.exe -lc "rm -rf /var/cache/pacman/pkg/*"
 cd C:\tools\msys64
 echo "Start archive"
-- 
2.28.0.windows.1




[PATCH v3 0/4] Fixes docs building on msys2/mingw

2020-10-15 Thread Yonggang Luo
V2-V3
No need convert perl trick to python script anymore
after Paolo's removal of ninjatool.
Revise Meson: Move the detection logic for sphinx to meson
for pass other platform by letting SPHINX_ARGS to be empty
when build_docs are false

v1 - v2
Also move the docs configure part from
configure to meson, this also fixed the pending
ninjatool removal caused issue that docs  can
not be build under msys2/mingw

Yonggang Luo (4):
  docs: Fixes build docs on msys2/mingw
  configure: the docdir option should passed to meson as is.
  meson: Move the detection logic for sphinx to meson
  cirrus: Enable doc build on msys2/mingw

 .cirrus.yml   |  6 +++-
 configure | 62 +++
 docs/conf.py  |  2 +-
 docs/meson.build  |  4 +--
 docs/sphinx/kerneldoc.py  |  2 +-
 meson.build   | 59 +
 meson_options.txt |  5 ++-
 tests/qapi-schema/meson.build |  2 +-
 8 files changed, 71 insertions(+), 71 deletions(-)

-- 
2.28.0.windows.1




[PATCH v3 2/4] configure: the docdir option should passed to meson as is.

2020-10-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 configure | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/configure b/configure
index f839c2a557..1ce31f97b4 100755
--- a/configure
+++ b/configure
@@ -971,7 +971,7 @@ for opt do
   ;;
   --with-suffix=*) qemu_suffix="$optarg"
   ;;
-  --docdir=*) qemu_docdir="$optarg"
+  --docdir=*) docdir="$optarg"
   ;;
   --sysconfdir=*) sysconfdir="$optarg"
   ;;
@@ -5770,7 +5770,6 @@ fi
 qemu_confdir="$sysconfdir/$qemu_suffix"
 qemu_moddir="$libdir/$qemu_suffix"
 qemu_datadir="$datadir/$qemu_suffix"
-qemu_docdir="$docdir/$qemu_suffix"
 qemu_localedir="$datadir/locale"
 qemu_icondir="$datadir/icons"
 qemu_desktopdir="$datadir/applications"
-- 
2.28.0.windows.1




[PATCH v3 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Yonggang Luo
meson didn't support running ../scripts/kernel-do directly

Signed-off-by: Yonggang Luo 
---
 docs/conf.py | 2 +-
 docs/sphinx/kerneldoc.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index 00e1b750e2..e584f68393 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -241,7 +241,7 @@ texinfo_documents = [
 # We use paths starting from qemu_docdir here so that you can run
 # sphinx-build from anywhere and the kerneldoc extension can still
 # find everything.
-kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc')
+kerneldoc_bin = ['perl', os.path.join(qemu_docdir, '../scripts/kernel-doc')]
 kerneldoc_srctree = os.path.join(qemu_docdir, '..')
 hxtool_srctree = os.path.join(qemu_docdir, '..')
 qapidoc_srctree = os.path.join(qemu_docdir, '..')
diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py
index 3e87940206..3ac277d162 100644
--- a/docs/sphinx/kerneldoc.py
+++ b/docs/sphinx/kerneldoc.py
@@ -67,7 +67,7 @@ class KernelDocDirective(Directive):
 
 def run(self):
 env = self.state.document.settings.env
-cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno']
+cmd = env.config.kerneldoc_bin + ['-rst', '-enable-lineno']
 
 filename = env.config.kerneldoc_srctree + '/' + self.arguments[0]
 export_file_patterns = []
-- 
2.28.0.windows.1




Re: [PATCH v2 0/4] Fixes docs building on msys2/mingw

2020-10-15 Thread Paolo Bonzini
Looks good, apart from the CR removal patch that can simply be dropped.

Paolo

Il gio 15 ott 2020, 22:10 Yonggang Luo  ha scritto:

> v1 - v2
> Also move the docs configure part from
> configure to meson, this also fixed the pending
> ninjatool removal caused issue that docs  can
> not be build under msys2/mingw
>
> Yonggang Luo (4):
>   docs: Fixes build docs on msys2/mingw
>   configure: the docdir option should passed to meson as is.
>   meson: Move the detection logic for sphinx to meson
>   cirrus: Enable doc build on msys2/mingw
>
>  .cirrus.yml   |  6 +++-
>  configure | 62 +++
>  docs/conf.py  |  2 +-
>  docs/meson.build  |  4 +--
>  docs/sphinx/kerneldoc.py  |  2 +-
>  meson.build   | 59 +
>  meson_options.txt |  5 ++-
>  scripts/rst-sanitize.py   | 21 
>  tests/qapi-schema/meson.build |  7 ++--
>  9 files changed, 95 insertions(+), 73 deletions(-)
>  create mode 100644 scripts/rst-sanitize.py
>
> --
> 2.28.0.windows.1
>
>
>


Re: [PATCH 0/7] build: replace ninjatool with ninja

2020-10-15 Thread Paolo Bonzini
Il gio 15 ott 2020, 20:49 Mark Cave-Ayland 
ha scritto:

> Is there any reason why
> https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg06997.html still
> can't be
> merged?
>

Because it's not the right approach. There is no reason why building
firmware cannot be done with cross compilers, so moving those directories
to Meson (not because Meson can't handle them; more specifically, the issue
is tying the firmware build to the QEMU build system) is going in the wrong
direction.

The "Canadian cross" scenario, where you build on Linux a mingw GCC but the
compiler is s390, is not even enough to describe the complexity in the case
of QEMU, because there are multiple firmware for different machines.

However we already have all the infrastructure to do such builds, we just
don't use it for the firmware. So, instead of the patch you recalled above,
the tests/tcg machinery should be extended into something that can be
reused for firmware. As an aside, orchestrating this multi-compiler part of
the build is what the Makefiles will keep on handling for the foreseeable
future. As an aside to the aside, tests/tcg is more than underdocumented
and I forget everything about it 5 minutes after looking at it.

This is not something that I will be able to work on anytime soon. But
still I don't think that going in the wrong direction is a good idea, even
if temporarily.

Paolo


>
> ATB,
>
> Mark.
>
>


Re: [PATCH v2 2/4] configure: the docdir option should passed to meson as is.

2020-10-15 Thread Yonggang Luo
Grep  qemu_docdir and docdir  in configure, you will know why,  qemu_docdir
not used at all in configure,

On Fri, Oct 16, 2020 at 5:24 AM Paolo Bonzini  wrote:
>
> Why?
>
> Paolo
>
> Il gio 15 ott 2020, 22:11 Yonggang Luo  ha scritto:
>>
>> Signed-off-by: Yonggang Luo 
>> ---
>>  configure | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/configure b/configure
>> index f839c2a557..1ce31f97b4 100755
>> --- a/configure
>> +++ b/configure
>> @@ -971,7 +971,7 @@ for opt do
>>;;
>>--with-suffix=*) qemu_suffix="$optarg"
>>;;
>> -  --docdir=*) qemu_docdir="$optarg"
>> +  --docdir=*) docdir="$optarg"
>>;;
>>--sysconfdir=*) sysconfdir="$optarg"
>>;;
>> @@ -5770,7 +5770,6 @@ fi
>>  qemu_confdir="$sysconfdir/$qemu_suffix"
>>  qemu_moddir="$libdir/$qemu_suffix"
>>  qemu_datadir="$datadir/$qemu_suffix"
>> -qemu_docdir="$docdir/$qemu_suffix"
>>  qemu_localedir="$datadir/locale"
>>  qemu_icondir="$datadir/icons"
>>  qemu_desktopdir="$datadir/applications"
>> --
>> 2.28.0.windows.1
>>


--
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH v2 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Yonggang Luo
It's tests, running by make

On Fri, Oct 16, 2020 at 5:23 AM Paolo Bonzini  wrote:
>
>
>
> Il gio 15 ott 2020, 22:30 Peter Maydell  ha
scritto:
>>
>> On Thu, 15 Oct 2020 at 21:13, Yonggang Luo  wrote:
>> >
>> > Signed-off-by: Yonggang Luo 
>> > ---
>> >  docs/conf.py  |  2 +-
>> >  docs/sphinx/kerneldoc.py  |  2 +-
>> >  scripts/rst-sanitize.py   | 21 +
>> >  tests/qapi-schema/meson.build |  5 +++--
>> >  4 files changed, 26 insertions(+), 4 deletions(-)
>> >  create mode 100644 scripts/rst-sanitize.py
>> >
>> > diff --git a/scripts/rst-sanitize.py b/scripts/rst-sanitize.py
>> > new file mode 100644
>> > index 00..26060f1208
>> > --- /dev/null
>> > +++ b/scripts/rst-sanitize.py
>> > @@ -0,0 +1,21 @@
>> > +#!/usr/bin/env python3
>> > +
>> > +#
>> > +# Script for remove cr line ending in file
>> > +#
>> > +# Authors:
>> > +#  Yonggang Luo 
>> > +#
>> > +# This work is licensed under the terms of the GNU GPL, version 2
>> > +# or, at your option, any later version.  See the COPYING file in
>> > +# the top-level directory.
>> > +
>> > +import sys
>> > +
>> > +def main(_program, file, *unused):
>> > +with open(file, 'rb') as content_file:
>> > +content = content_file.read()
>> > +sys.stdout.buffer.write(content.replace(b'\r', b''))
>> > +
>> > +if __name__ == "__main__":
>> > +main(*sys.argv)
>>
>> Why doesn't the perl rune work? Your commit message doesn't say.
>
>
> Ninjatool gets confused by Windows escapes. So it's a QEMU-ism and
switching to ninja fixes it. There's no need to use a separate script for
this.
>
> Paolo
>
>>
>> > diff --git a/tests/qapi-schema/meson.build
b/tests/qapi-schema/meson.build
>> > index 1f222a7a13..20a7641af8 100644
>> > --- a/tests/qapi-schema/meson.build
>> > +++ b/tests/qapi-schema/meson.build
>> > @@ -251,18 +251,19 @@ qapi_doc_out = custom_target('QAPI rST doc',
>> >  # using an explicit '\' character in the command arguments to
>> >  # a custom_target(), as Meson will unhelpfully replace it with a '/'
>> >  # (https://github.com/mesonbuild/meson/issues/1564)
>> > +rst_sanitize_cmd = [find_program('../../scripts/rst-sanitize.py'),
'@INPUT@']
>> >  qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized',
>> >output: ['doc-good.txt.nocr'],
>> >input: qapi_doc_out[0],
>> >build_by_default: build_docs,
>> > -  command: ['perl', '-pe', '$x = chr
13; s/$x$//', '@INPUT@'],
>> > +  command: rst_sanitize_cmd,
>> >capture: true)
>> >
>> >  qapi_doc_ref_nocr = custom_target('QAPI rST doc reference
newline-sanitized',
>> >output: ['doc-good.ref.nocr'],
>> >input: files('doc-good.txt'),
>> >build_by_default: build_docs,
>> > -  command: ['perl', '-pe', '$x = chr
13; s/$x$//', '@INPUT@'],
>> > +  command: rst_sanitize_cmd,
>> >capture: true)
>>
>> thanks
>> -- PMM
>>


--
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH v2 2/4] configure: the docdir option should passed to meson as is.

2020-10-15 Thread Paolo Bonzini
Why?

Paolo

Il gio 15 ott 2020, 22:11 Yonggang Luo  ha scritto:

> Signed-off-by: Yonggang Luo 
> ---
>  configure | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index f839c2a557..1ce31f97b4 100755
> --- a/configure
> +++ b/configure
> @@ -971,7 +971,7 @@ for opt do
>;;
>--with-suffix=*) qemu_suffix="$optarg"
>;;
> -  --docdir=*) qemu_docdir="$optarg"
> +  --docdir=*) docdir="$optarg"
>;;
>--sysconfdir=*) sysconfdir="$optarg"
>;;
> @@ -5770,7 +5770,6 @@ fi
>  qemu_confdir="$sysconfdir/$qemu_suffix"
>  qemu_moddir="$libdir/$qemu_suffix"
>  qemu_datadir="$datadir/$qemu_suffix"
> -qemu_docdir="$docdir/$qemu_suffix"
>  qemu_localedir="$datadir/locale"
>  qemu_icondir="$datadir/icons"
>  qemu_desktopdir="$datadir/applications"
> --
> 2.28.0.windows.1
>
>


[PATCH v2 1/5] spapr: Fix leak of CPU machine specific data

2020-10-15 Thread Greg Kurz
When a CPU core is being removed, the machine specific data of each
CPU thread object is leaked.

Fix this by calling the dedicated helper we have for that instead of
simply unparenting the CPU object. Call it from a separate loop in
spapr_cpu_core_unrealize() for symmetry with spapr_cpu_core_realize().

Signed-off-by: Greg Kurz 
---
 hw/ppc/spapr_cpu_core.c |   22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index b03620823adb..c55211214524 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -188,7 +188,6 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, 
SpaprCpuCore *sc)
 }
 spapr_irq_cpu_intc_destroy(SPAPR_MACHINE(qdev_get_machine()), cpu);
 cpu_remove_sync(CPU(cpu));
-object_unparent(OBJECT(cpu));
 }
 
 /*
@@ -213,6 +212,15 @@ static void spapr_cpu_core_reset_handler(void *opaque)
 spapr_cpu_core_reset(opaque);
 }
 
+static void spapr_delete_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc)
+{
+SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
+
+cpu->machine_data = NULL;
+g_free(spapr_cpu);
+object_unparent(OBJECT(cpu));
+}
+
 static void spapr_cpu_core_unrealize(DeviceState *dev)
 {
 SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
@@ -224,6 +232,9 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
 for (i = 0; i < cc->nr_threads; i++) {
 spapr_unrealize_vcpu(sc->threads[i], sc);
 }
+for (i = 0; i < cc->nr_threads; i++) {
+spapr_delete_vcpu(sc->threads[i], sc);
+}
 g_free(sc->threads);
 }
 
@@ -294,15 +305,6 @@ err:
 return NULL;
 }
 
-static void spapr_delete_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc)
-{
-SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
-
-cpu->machine_data = NULL;
-g_free(spapr_cpu);
-object_unparent(OBJECT(cpu));
-}
-
 static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
 {
 /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user





Re: [PATCH v2 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Paolo Bonzini
Il gio 15 ott 2020, 22:30 Peter Maydell  ha
scritto:

> On Thu, 15 Oct 2020 at 21:13, Yonggang Luo  wrote:
> >
> > Signed-off-by: Yonggang Luo 
> > ---
> >  docs/conf.py  |  2 +-
> >  docs/sphinx/kerneldoc.py  |  2 +-
> >  scripts/rst-sanitize.py   | 21 +
> >  tests/qapi-schema/meson.build |  5 +++--
> >  4 files changed, 26 insertions(+), 4 deletions(-)
> >  create mode 100644 scripts/rst-sanitize.py
> >
> > diff --git a/scripts/rst-sanitize.py b/scripts/rst-sanitize.py
> > new file mode 100644
> > index 00..26060f1208
> > --- /dev/null
> > +++ b/scripts/rst-sanitize.py
> > @@ -0,0 +1,21 @@
> > +#!/usr/bin/env python3
> > +
> > +#
> > +# Script for remove cr line ending in file
> > +#
> > +# Authors:
> > +#  Yonggang Luo 
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2
> > +# or, at your option, any later version.  See the COPYING file in
> > +# the top-level directory.
> > +
> > +import sys
> > +
> > +def main(_program, file, *unused):
> > +with open(file, 'rb') as content_file:
> > +content = content_file.read()
> > +sys.stdout.buffer.write(content.replace(b'\r', b''))
> > +
> > +if __name__ == "__main__":
> > +main(*sys.argv)
>
> Why doesn't the perl rune work? Your commit message doesn't say.
>

Ninjatool gets confused by Windows escapes. So it's a QEMU-ism and
switching to ninja fixes it. There's no need to use a separate script for
this.

Paolo


> > diff --git a/tests/qapi-schema/meson.build
> b/tests/qapi-schema/meson.build
> > index 1f222a7a13..20a7641af8 100644
> > --- a/tests/qapi-schema/meson.build
> > +++ b/tests/qapi-schema/meson.build
> > @@ -251,18 +251,19 @@ qapi_doc_out = custom_target('QAPI rST doc',
> >  # using an explicit '\' character in the command arguments to
> >  # a custom_target(), as Meson will unhelpfully replace it with a '/'
> >  # (https://github.com/mesonbuild/meson/issues/1564)
> > +rst_sanitize_cmd = [find_program('../../scripts/rst-sanitize.py'),
> '@INPUT@']
> >  qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized',
> >output: ['doc-good.txt.nocr'],
> >input: qapi_doc_out[0],
> >build_by_default: build_docs,
> > -  command: ['perl', '-pe', '$x = chr
> 13; s/$x$//', '@INPUT@'],
> > +  command: rst_sanitize_cmd,
> >capture: true)
> >
> >  qapi_doc_ref_nocr = custom_target('QAPI rST doc reference
> newline-sanitized',
> >output: ['doc-good.ref.nocr'],
> >input: files('doc-good.txt'),
> >build_by_default: build_docs,
> > -  command: ['perl', '-pe', '$x = chr
> 13; s/$x$//', '@INPUT@'],
> > +  command: rst_sanitize_cmd,
> >capture: true)
>
> thanks
> -- PMM
>
>


[PATCH v2 0/5] spapr: Fix and cleanups for sPAPR CPU core

2020-10-15 Thread Greg Kurz
While reading the code _again_ I spotted a memory leak and I realized
that the realize/unrealize paths are uselessly complex and not really
symmetrical.

This series fixes the leak and re-shuffles the code to make it cleaner.

Tested with 'make check', travis-ci and manual hotplug/unplug of CPU
cores. Also tested error paths by simulating failures when creating
interrupt presenters or when setting the vCPU id.

v2: - enforce symmetry between realize and unrealize
- unrealize vCPUs with qdev_unrealize()
- one loop to create/realize and to unrealize/delete vCPUs

---

Greg Kurz (5):
  spapr: Fix leak of CPU machine specific data
  spapr: Unrealize vCPUs with qdev_unrealize()
  spapr: Drop spapr_delete_vcpu() unused argument
  spapr: Make spapr_cpu_core_unrealize() idempotent
  spapr: Simplify spapr_cpu_core_realize() and spapr_cpu_core_unrealize()


 accel/tcg/user-exec-stub.c  |4 ++
 hw/ppc/spapr_cpu_core.c |   69 ++-
 target/ppc/translate_init.c.inc |2 +
 3 files changed, 37 insertions(+), 38 deletions(-)

--
Greg




[PATCH v2 5/5] spapr: Simplify spapr_cpu_core_realize() and spapr_cpu_core_unrealize()

2020-10-15 Thread Greg Kurz
Now that the error path of spapr_cpu_core_realize() is just to call
idempotent spapr_cpu_core_unrealize() for rollback, no need to create
and realize the vCPUs in two separate loops.

Merge them and do them same in spapr_cpu_core_unrealize() for symmetry.

Signed-off-by: Greg Kurz 
---
 hw/ppc/spapr_cpu_core.c |   16 +++-
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 317fb9934f58..2f7dc3c23ded 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -238,10 +238,6 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
  _abort)) {
 spapr_unrealize_vcpu(sc->threads[i], sc);
 }
-}
-}
-for (i = 0; i < cc->nr_threads; i++) {
-if (sc->threads[i]) {
 spapr_delete_vcpu(sc->threads[i]);
 }
 }
@@ -326,7 +322,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error 
**errp)
   TYPE_SPAPR_MACHINE);
 SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
 CPUCore *cc = CPU_CORE(OBJECT(dev));
-int i, j;
+int i;
 
 if (!spapr) {
 error_setg(errp, TYPE_SPAPR_CPU_CORE " needs a pseries machine");
@@ -337,14 +333,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error 
**errp)
 sc->threads = g_new0(PowerPCCPU *, cc->nr_threads);
 for (i = 0; i < cc->nr_threads; i++) {
 sc->threads[i] = spapr_create_vcpu(sc, i, errp);
-if (!sc->threads[i]) {
-spapr_cpu_core_unrealize(dev);
-return;
-}
-}
-
-for (j = 0; j < cc->nr_threads; j++) {
-if (!spapr_realize_vcpu(sc->threads[j], spapr, sc, errp)) {
+if (!sc->threads[i] ||
+!spapr_realize_vcpu(sc->threads[i], spapr, sc, errp)) {
 spapr_cpu_core_unrealize(dev);
 return;
 }





Re: [PULL 0/3] microblaze patch queue

2020-10-15 Thread Peter Maydell
On Thu, 15 Oct 2020 at 05:52, Richard Henderson
 wrote:
>
> The following changes since commit 57c98ea9acdcef5021f5671efa6475a5794a51c4:
>
>   Merge remote-tracking branch 'remotes/kraxel/tags/ui-20201014-pull-request' 
> into staging (2020-10-14 13:56:06 +0100)
>
> are available in the Git repository at:
>
>   https://github.com/rth7680/qemu.git tags/pull-mb-20201014
>
> for you to fetch changes up to 49e258df83e2200847cd4b331f48d8d872fba51c:
>
>   linux-user/microblaze: Remove non-rt signal frames (2020-10-14 21:19:56 
> -0700)
>
> 
> Implement rt signal frames for microblaze-linux-user
> Adjust linux-user test for musl
>
> 


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.2
for any user-visible changes.

-- PMM



[PATCH v2 2/5] spapr: Unrealize vCPUs with qdev_unrealize()

2020-10-15 Thread Greg Kurz
Since we introduced CPU hot-unplug in sPAPR, we don't unrealize the
vCPU objects explicitly. Instead, we let QOM handle that for us under
object_property_del_all() when the CPU core object is finalized. The
only thing we do is calling cpu_remove_sync() to tear the vCPU thread
down.

This happens to work but it is ugly because:
- we call qdev_realize() but the corresponding qdev_unrealize() is
  buried deep in the QOM code
- we call cpu_remove_sync() to undo qemu_init_vcpu() called by
  ppc_cpu_realize() in target/ppc/translate_init.c.inc
- the CPU init and teardown paths aren't really symmetrical

The latter didn't bite us so far but a future patch that greatly
simplifies the CPU core realize path needs it to avoid a crash
in QOM.

For all these reasons, have ppc_cpu_unrealize() to undo the changes
of ppc_cpu_realize() by calling cpu_remove_sync() at the right place,
and have the sPAPR CPU core code to call qdev_unrealize().

This requires to add a missing stub because translate_init.c.inc is
also compiled for user mode.

Signed-off-by: Greg Kurz 
---
 accel/tcg/user-exec-stub.c  |4 
 hw/ppc/spapr_cpu_core.c |4 ++--
 target/ppc/translate_init.c.inc |2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/accel/tcg/user-exec-stub.c b/accel/tcg/user-exec-stub.c
index f6d8c8fb6f2d..b876f5c1e45d 100644
--- a/accel/tcg/user-exec-stub.c
+++ b/accel/tcg/user-exec-stub.c
@@ -9,6 +9,10 @@ void cpu_resume(CPUState *cpu)
 {
 }
 
+void cpu_remove_sync(CPUState *cpu)
+{
+}
+
 void qemu_init_vcpu(CPUState *cpu)
 {
 }
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index c55211214524..e4aeb93c0299 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -187,7 +187,7 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, 
SpaprCpuCore *sc)
 vmstate_unregister(NULL, _spapr_cpu_state, cpu->machine_data);
 }
 spapr_irq_cpu_intc_destroy(SPAPR_MACHINE(qdev_get_machine()), cpu);
-cpu_remove_sync(CPU(cpu));
+qdev_unrealize(DEVICE(cpu));
 }
 
 /*
@@ -255,7 +255,7 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, 
SpaprMachineState *spapr,
 kvmppc_set_papr(cpu);
 
 if (spapr_irq_cpu_intc_create(spapr, cpu, errp) < 0) {
-cpu_remove_sync(CPU(cpu));
+qdev_unrealize(DEVICE(cpu));
 return false;
 }
 
diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc
index bb66526280ef..d2a8204d6011 100644
--- a/target/ppc/translate_init.c.inc
+++ b/target/ppc/translate_init.c.inc
@@ -10328,6 +10328,8 @@ static void ppc_cpu_unrealize(DeviceState *dev)
 
 pcc->parent_unrealize(dev);
 
+cpu_remove_sync(CPU(cpu));
+
 for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
 if (cpu->opcodes[i] == _handler) {
 continue;





[PATCH v2 3/5] spapr: Drop spapr_delete_vcpu() unused argument

2020-10-15 Thread Greg Kurz
The 'sc' argument is unused. Drop it.

Signed-off-by: Greg Kurz 
---
 hw/ppc/spapr_cpu_core.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index e4aeb93c0299..45eb2121876e 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -212,7 +212,7 @@ static void spapr_cpu_core_reset_handler(void *opaque)
 spapr_cpu_core_reset(opaque);
 }
 
-static void spapr_delete_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc)
+static void spapr_delete_vcpu(PowerPCCPU *cpu)
 {
 SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
 
@@ -233,7 +233,7 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
 spapr_unrealize_vcpu(sc->threads[i], sc);
 }
 for (i = 0; i < cc->nr_threads; i++) {
-spapr_delete_vcpu(sc->threads[i], sc);
+spapr_delete_vcpu(sc->threads[i]);
 }
 g_free(sc->threads);
 }
@@ -345,7 +345,7 @@ err_unrealize:
 }
 err:
 while (--i >= 0) {
-spapr_delete_vcpu(sc->threads[i], sc);
+spapr_delete_vcpu(sc->threads[i]);
 }
 g_free(sc->threads);
 }





[PATCH v2 4/5] spapr: Make spapr_cpu_core_unrealize() idempotent

2020-10-15 Thread Greg Kurz
spapr_cpu_core_realize() has a rollback path which partially duplicates
the code of spapr_cpu_core_unrealize().

Let's make spapr_cpu_core_unrealize() idempotent and call it instead. This
requires to:
- move the registration and unregistration of the reset handler around
  but it is harmless,
- allocate the array of vCPUs with g_new0() to be able to filter out
  unused slots,
- make sure to only unrealize vCPUs that have been already realized.

Signed-off-by: Greg Kurz 
---
 hw/ppc/spapr_cpu_core.c |   41 +
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 45eb2121876e..317fb9934f58 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -227,15 +227,26 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
 CPUCore *cc = CPU_CORE(dev);
 int i;
 
-qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
-
 for (i = 0; i < cc->nr_threads; i++) {
-spapr_unrealize_vcpu(sc->threads[i], sc);
+if (sc->threads[i]) {
+/*
+ * Since this we can get here from the error path of
+ * spapr_cpu_core_realize(), make sure we only unrealize
+ * vCPUs that have already been realized.
+ */
+if (object_property_get_bool(OBJECT(sc->threads[i]), "realized",
+ _abort)) {
+spapr_unrealize_vcpu(sc->threads[i], sc);
+}
+}
 }
 for (i = 0; i < cc->nr_threads; i++) {
-spapr_delete_vcpu(sc->threads[i]);
+if (sc->threads[i]) {
+spapr_delete_vcpu(sc->threads[i]);
+}
 }
 g_free(sc->threads);
+qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
 }
 
 static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
@@ -322,32 +333,22 @@ static void spapr_cpu_core_realize(DeviceState *dev, 
Error **errp)
 return;
 }
 
-sc->threads = g_new(PowerPCCPU *, cc->nr_threads);
+qemu_register_reset(spapr_cpu_core_reset_handler, sc);
+sc->threads = g_new0(PowerPCCPU *, cc->nr_threads);
 for (i = 0; i < cc->nr_threads; i++) {
 sc->threads[i] = spapr_create_vcpu(sc, i, errp);
 if (!sc->threads[i]) {
-goto err;
+spapr_cpu_core_unrealize(dev);
+return;
 }
 }
 
 for (j = 0; j < cc->nr_threads; j++) {
 if (!spapr_realize_vcpu(sc->threads[j], spapr, sc, errp)) {
-goto err_unrealize;
+spapr_cpu_core_unrealize(dev);
+return;
 }
 }
-
-qemu_register_reset(spapr_cpu_core_reset_handler, sc);
-return;
-
-err_unrealize:
-while (--j >= 0) {
-spapr_unrealize_vcpu(sc->threads[j], sc);
-}
-err:
-while (--i >= 0) {
-spapr_delete_vcpu(sc->threads[i]);
-}
-g_free(sc->threads);
 }
 
 static Property spapr_cpu_core_properties[] = {





Re: ide: Linux reports drive diagnostic failures on boot

2020-10-15 Thread John Snow

On 10/15/20 4:17 PM, Mark Cave-Ayland wrote:

On 13/10/2020 19:39, John Snow wrote:


On 10/13/20 6:59 AM, Mark Cave-Ayland wrote:
During my latest OpenBIOS boot tests I've noticed the following IDE 
diagnostics failure message appearing in dmesg at Linux boot time 
when booting from CDROM on both SPARC64 and PPC:



Sorry for the inconvenience.


Well it wasn't too bad - in my case the kernel was able to recover so it 
wasn't a complete showstopper for my tests. It seemed worth mentioning 
in case this causes other failures elsewhere though.



[    9.347342] scsi host0: pata_cmd64x
[    9.369055] scsi host1: pata_cmd64x
[    9.371622] ata1: PATA max UDMA/33 cmd 0x1fe02008000 ctl 
0x1fe02008080 bmdma 0x1fe02008200 irq 8
[    9.372805] ata2: PATA max UDMA/33 cmd 0x1fe02008100 ctl 
0x1fe02008180 bmdma 0x1fe02008208 irq 8

[    9.711740] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100
[    9.712591] ata2.00: Drive reports diagnostics failure. This may 
indicate a drive
[    9.713256] ata2.00: fault or invalid emulation. Contact drive 
vendor for information.

[    9.737677] ata2.00: configured for UDMA/33
[    9.790179] scsi 1:0:0:0: CD-ROM    QEMU QEMU DVD-ROM 
2.5+ PQ: 0 ANSI: 5

[   10.381172] hme :01:01.1 enp1s1f1: renamed from eth0
[   10.508819] sr 1:0:0:0: [sr0] scsi3-mmc drive: 4x/4x cd/rw 
xa/form2 tray

[   10.509805] cdrom: Uniform CD-ROM driver Revision: 3.20


A session with git bisect points to the following commit:

55adb3c45620c31f29978f209e2a44a08d34e2da is the first bad commit
commit 55adb3c45620c31f29978f209e2a44a08d34e2da
Author: John Snow 
Date:   Fri Jul 24 01:23:00 2020 -0400

 ide: cancel pending callbacks on SRST

 The SRST implementation did not keep up with the rest of IDE; it is
 possible to perform a weak reset on an IDE device to remove the 
BSY/DRQ
 bits, and then issue writes to the control/device registers 
which can

 cause chaos with the state machine.

 Fix that by actually performing a real reset.

 Reported-by: Alexander Bulekov 
 Fixes: https://bugs.launchpad.net/qemu/+bug/1878253
 Fixes: https://bugs.launchpad.net/qemu/+bug/1887303
 Fixes: https://bugs.launchpad.net/qemu/+bug/1887309
 Signed-off-by: John Snow 

:04 04 70a7c1cfbafb22fa815d3ae4d7ed075ac3918188 
3f37762f20e9ca9d2874eaf819d7175a1dca1dd9 M  hw



John/Alexander: any chance you could take a look at this? The message 
above is really simple to reproduce under qemu-system-sparc64 using 
http://cdimage.debian.org/cdimage/ports/9.0/sparc64/iso-cd/debian-9.0-sparc64-NETINST-1.iso 
and the following command line:


./qemu-system-sparc64 \
 -cdrom debian-9.0-sparc64-NETINST-1.iso \
 -m 256 \
 -nographic \
 -boot d


ATB,

Mark.



Shucks.

This patch happened because the old SRST code reset the IDE state 
machine (cleared the status register) but then didn't cancel any of 
the pending callbacks, so it was possible to shuffle the state machine 
off the rails onto junk data. Obviously bad.


Now, SRST actually cancels the callbacks which I thought would have 
been safe, but it's possible that doing a "real" reset here is 
touching more registers than it ought to.


Let's take a look at the linux source code ...

/* Let the user know. We don't want to disallow opens for
    rescue purposes, or in case the vendor is just a blithering
    idiot. Do this after the dev_config call as some controllers
    with buggy firmware may want to avoid reporting false device
    bugs */

Ah, always a nice day to be called an idiot. Thank you for your 
service, Alan Cox.


This message gets printed when ATA_HORKAGE_DIAGNOSTIC is set. 
libata-sff.c suggests this happens when the error register* comes back 
0x00 after an SRST.


(*I think that tf.feature is only feature on writes, but error on 
reads. Same address.)


Now, ide_reset -- which we use for initialization and resets both 
always sets the error register to 0x00. libata thinks that 0x00 means 
a failed diagnostics test, though.


This ought to be covered by ATA8-APT. Section 9.2, Software reset 
protocol.


Cliff notes:

- Host writes to SRST and waits for 5 μs.
- Both devices obey the SRST write, regardless of drive selection.
- Each device clears their registers and sets BSY (within 400ns.)
- Host clears SRST and waits for at least 2ms.
- Host polls devices, waiting for BSY to be 0.


device0 can set bit7 in the error register to 0 or 1, depending on the 
presence or absence of device1 and how it behaves following a 
diagnostic test.



Device 1 is absent: bit7 is cleared.
Device 1 is present:
   - If PDIAG- is asserted, bit7 is cleared.
   - If PDIAG- is not asserted within 31 seconds, bit7 is set.

Then, ah:

The EXECUTE DEVICE DIAGNOSTICS diagnostic code shall be placed in bits 
(6:0) of the Error register (See Clause 0). The device shall set the 
signature values (See Clause 0). The content of the Features register 
is undefined.


I got this pretty wrong. I'm seeing a few 

[PULL 3/5] tests/9pfs: wipe local 9pfs test directory

2020-10-15 Thread Christian Schoenebeck
Before running the first 9pfs test case, make sure the test directory
for running the 9pfs 'local' tests on is entirely empty. For that
reason simply delete the test directory (if any) before (re)creating
it on test suite startup.

Note: The preferable precise behaviour would be the test directory
only being wiped once *before* a test suite run. Right now the test
directory is also wiped at the *end* of a test suite run because
libqos is calling the virtio_9p_register_nodes() callback for some
reason also when a test suite completed. This is suboptimal as
developers cannot immediately see what files and directories the
9pfs local tests created precisely after the test suite completed.
But fortunately the test directory is not wiped if some test failed.
So it is probably not worth it drilling another hole into libqos
for this issue.

Signed-off-by: Christian Schoenebeck 
Message-Id: 

Signed-off-by: Christian Schoenebeck 
---
 tests/qtest/libqos/virtio-9p.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index 9cb284cb3c..bd53498041 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -53,6 +53,18 @@ static void create_local_test_dir(void)
 g_assert((st.st_mode & S_IFMT) == S_IFDIR);
 }
 
+/* Deletes directory previously created by create_local_test_dir(). */
+static void remove_local_test_dir(void)
+{
+g_assert(local_test_path != NULL);
+char *cmd = g_strdup_printf("rm -r '%s'\n", local_test_path);
+int res = system(cmd);
+if (res < 0) {
+/* ignore error, dummy check to prevent compiler error */
+}
+g_free(cmd);
+}
+
 static void virtio_9p_cleanup(QVirtio9P *interface)
 {
 qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc);
@@ -230,6 +242,7 @@ static void virtio_9p_register_nodes(void)
 
 /* make sure test dir for the 'local' tests exists and is clean */
 init_local_test_path();
+remove_local_test_dir();
 create_local_test_dir();
 
 QPCIAddress addr = {
-- 
2.20.1




[PULL 2/5] tests/9pfs: introduce local tests

2020-10-15 Thread Christian Schoenebeck
This patch introduces 9pfs test cases using the 9pfs 'local'
filesystem driver which reads/writes/creates/deletes real files
and directories.

In this initial version, there is only one local test which actually
only checks if the 9pfs 'local' device was created successfully.

Before the 9pfs 'local' tests are run, a test directory 'qtest-9p-local'
is created (with world rwx permissions) under the current working
directory. At this point that test directory is not auto deleted yet.

Signed-off-by: Christian Schoenebeck 
Message-Id: 
<81fc4b3b6b6c9bf7999e79f5e7cbc364a5f09ddb.1602182956.git.qemu_...@crudebyte.com>
Signed-off-by: Christian Schoenebeck 
---
 tests/qtest/libqos/virtio-9p.c | 81 ++
 tests/qtest/libqos/virtio-9p.h |  5 +++
 tests/qtest/virtio-9p-test.c   | 44 --
 3 files changed, 116 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index 2e300063e3..9cb284cb3c 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -24,6 +24,34 @@
 #include "qgraph.h"
 
 static QGuestAllocator *alloc;
+static char *local_test_path;
+
+/* Concatenates the passed 2 pathes. Returned result must be freed. */
+static char *concat_path(const char* a, const char* b)
+{
+return g_build_filename(a, b, NULL);
+}
+
+static void init_local_test_path(void)
+{
+char *pwd = get_current_dir_name();
+local_test_path = concat_path(pwd, "qtest-9p-local");
+free(pwd);
+}
+
+/* Creates the directory for the 9pfs 'local' filesystem driver to access. */
+static void create_local_test_dir(void)
+{
+struct stat st;
+
+g_assert(local_test_path != NULL);
+mkdir(local_test_path, 0777);
+
+/* ensure test directory exists now ... */
+g_assert(stat(local_test_path, ) == 0);
+/* ... and is actually a directory */
+g_assert((st.st_mode & S_IFMT) == S_IFDIR);
+}
 
 static void virtio_9p_cleanup(QVirtio9P *interface)
 {
@@ -146,11 +174,64 @@ static void *virtio_9p_pci_create(void *pci_bus, 
QGuestAllocator *t_alloc,
 return obj;
 }
 
+/**
+ * Performs regular expression based search and replace on @a haystack.
+ *
+ * @param haystack - input string to be parsed, result of replacement is
+ *   stored back to @a haystack
+ * @param pattern - the regular expression pattern for scanning @a haystack
+ * @param replace_fmt - matches of supplied @a pattern are replaced by this,
+ *  if necessary glib printf format can be used to add
+ *  variable arguments of this function to this
+ *  replacement string
+ */
+static void regex_replace(GString *haystack, const char *pattern,
+  const char *replace_fmt, ...)
+{
+GRegex *regex;
+char *replace, *s;
+va_list argp;
+
+va_start(argp, replace_fmt);
+replace = g_strdup_vprintf(replace_fmt, argp);
+va_end(argp);
+
+regex = g_regex_new(pattern, 0, 0, NULL);
+s = g_regex_replace(regex, haystack->str, -1, 0, replace, 0, NULL);
+g_string_assign(haystack, s);
+g_free(s);
+g_regex_unref(regex);
+g_free(replace);
+}
+
+void virtio_9p_assign_local_driver(GString *cmd_line, const char *args)
+{
+g_assert_nonnull(local_test_path);
+
+/* replace 'synth' driver by 'local' driver */
+regex_replace(cmd_line, "-fsdev synth,", "-fsdev local,");
+
+/* append 'path=...' to '-fsdev ...' group */
+regex_replace(cmd_line, "(-fsdev \\w[^ ]*)", "\\1,path='%s'",
+  local_test_path);
+
+if (!args) {
+return;
+}
+
+/* append passed args to '-fsdev ...' group */
+regex_replace(cmd_line, "(-fsdev \\w[^ ]*)", "\\1,%s", args);
+}
+
 static void virtio_9p_register_nodes(void)
 {
 const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG;
 const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG;
 
+/* make sure test dir for the 'local' tests exists and is clean */
+init_local_test_path();
+create_local_test_dir();
+
 QPCIAddress addr = {
 .devfn = QPCI_DEVFN(4, 0),
 };
diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h
index b1e6badc4a..326a603f72 100644
--- a/tests/qtest/libqos/virtio-9p.h
+++ b/tests/qtest/libqos/virtio-9p.h
@@ -44,4 +44,9 @@ struct QVirtio9PDevice {
 QVirtio9P v9p;
 };
 
+/**
+ * Prepares QEMU command line for 9pfs tests using the 'local' fs driver.
+ */
+void virtio_9p_assign_local_driver(GString *cmd_line, const char *args);
+
 #endif
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 3281153b9c..af7e169d3a 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -895,29 +895,45 @@ static void fs_readdir_split_512(void *obj, void *data,
 fs_readdir_split(obj, data, t_alloc, 512);
 }
 
+static void *assign_9p_local_driver(GString *cmd_line, void *arg)
+{
+virtio_9p_assign_local_driver(cmd_line, 

[PULL 5/5] tests/9pfs: add local Tmkdir test

2020-10-15 Thread Christian Schoenebeck
This test case uses the 9pfs 'local' driver to create a directory
and then checks if the expected directory was actually created
(as real directory) on host side.

This patch introduces a custom split() implementation, because
the test code requires non empty array elements as result. For
that reason g_strsplit() would not be a good alternative, as
it would require additional filter code for reshuffling the
array, and the resulting code would be even more complex than
this split() function.

Signed-off-by: Christian Schoenebeck 
Message-Id: 

Signed-off-by: Christian Schoenebeck 
---
 tests/qtest/virtio-9p-test.c | 139 +++
 1 file changed, 139 insertions(+)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index af7e169d3a..c15908f27b 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -18,6 +18,62 @@
 #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
 static QGuestAllocator *alloc;
 
+/*
+ * Used to auto generate new fids. Start with arbitrary high value to avoid
+ * collision with hard coded fids in basic test code.
+ */
+static uint32_t fid_generator = 1000;
+
+static uint32_t genfid(void)
+{
+return fid_generator++;
+}
+
+/**
+ * Splits the @a in string by @a delim into individual (non empty) strings
+ * and outputs them to @a out. The output array @a out is NULL terminated.
+ *
+ * Output array @a out must be freed by calling split_free().
+ *
+ * @returns number of individual elements in output array @a out (without the
+ *  final NULL terminating element)
+ */
+static int split(const char *in, const char *delim, char ***out)
+{
+int n = 0, i = 0;
+char *tmp, *p;
+
+tmp = g_strdup(in);
+for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) {
+if (strlen(p) > 0) {
+++n;
+}
+}
+g_free(tmp);
+
+*out = g_new0(char *, n + 1); /* last element NULL delimiter */
+
+tmp = g_strdup(in);
+for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) {
+if (strlen(p) > 0) {
+(*out)[i++] = g_strdup(p);
+}
+}
+g_free(tmp);
+
+return n;
+}
+
+static void split_free(char ***out)
+{
+int i;
+for (i = 0; (*out)[i]; ++i) {
+g_free((*out)[i]);
+}
+g_free(*out);
+*out = NULL;
+}
+
 static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
 {
 QVirtio9P *v9p = obj;
@@ -201,6 +257,7 @@ static const char *rmessage_name(uint8_t id)
 id == P9_RWALK ? "RWALK" :
 id == P9_RLOPEN ? "RLOPEN" :
 id == P9_RWRITE ? "RWRITE" :
+id == P9_RMKDIR ? "RMKDIR" :
 id == P9_RFLUSH ? "RFLUSH" :
 id == P9_RREADDIR ? "READDIR" :
 "";
@@ -578,6 +635,39 @@ static bool fs_dirents_contain_name(struct V9fsDirent *e, 
const char* name)
 return false;
 }
 
+/* size[4] Tmkdir tag[2] dfid[4] name[s] mode[4] gid[4] */
+static P9Req *v9fs_tmkdir(QVirtio9P *v9p, uint32_t dfid, const char *name,
+  uint32_t mode, uint32_t gid, uint16_t tag)
+{
+P9Req *req;
+
+uint32_t body_size = 4 + 4 + 4;
+uint16_t string_size = v9fs_string_size(name);
+
+g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
+body_size += string_size;
+
+req = v9fs_req_init(v9p, body_size, P9_TMKDIR, tag);
+v9fs_uint32_write(req, dfid);
+v9fs_string_write(req, name);
+v9fs_uint32_write(req, mode);
+v9fs_uint32_write(req, gid);
+v9fs_req_send(req);
+return req;
+}
+
+/* size[4] Rmkdir tag[2] qid[13] */
+static void v9fs_rmkdir(P9Req *req, v9fs_qid *qid)
+{
+v9fs_req_recv(req, P9_RMKDIR);
+if (qid) {
+v9fs_memread(req, qid, 13);
+} else {
+v9fs_memskip(req, 13);
+}
+v9fs_req_free(req);
+}
+
 /* basic readdir test where reply fits into a single response message */
 static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
 {
@@ -877,6 +967,30 @@ static void fs_flush_ignored(void *obj, void *data, 
QGuestAllocator *t_alloc)
 g_free(wnames[0]);
 }
 
+static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc,
+ const char *path, const char *cname)
+{
+QVirtio9P *v9p = obj;
+alloc = t_alloc;
+char **wnames;
+char *const name = g_strdup(cname);
+P9Req *req;
+const uint32_t fid = genfid();
+
+int nwnames = split(path, "/", );
+
+req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
+v9fs_req_wait_for_reply(req, NULL);
+v9fs_rwalk(req, NULL, NULL);
+
+req = v9fs_tmkdir(v9p, fid, name, 0750, 0, 0);
+v9fs_req_wait_for_reply(req, NULL);
+v9fs_rmkdir(req, NULL);
+
+g_free(name);
+split_free();
+}
+
 static void fs_readdir_split_128(void *obj, void *data,
  QGuestAllocator *t_alloc)
 {
@@ -895,6 +1009,30 @@ static void fs_readdir_split_512(void *obj, void *data,
 fs_readdir_split(obj, data, t_alloc, 512);
 }
 
+
+/* tests using the 9pfs 

[PULL 1/5] tests/9pfs: change qtest name prefix to synth

2020-10-15 Thread Christian Schoenebeck
All existing 9pfs test cases are using the 'synth' fs driver so far, which
means they are not accessing real files, but a purely simulated (in RAM
only) file system.

Let's make this clear by changing the prefix of the individual qtest case
names from 'fs/' to 'synth/'. That way they'll be easily distinguishable
from upcoming new 9pfs test cases supposed to be using a different fs
driver.

Signed-off-by: Christian Schoenebeck 
Message-Id: 

Signed-off-by: Christian Schoenebeck 
---
 tests/qtest/virtio-9p-test.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index de30b717b6..3281153b9c 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -897,26 +897,26 @@ static void fs_readdir_split_512(void *obj, void *data,
 
 static void register_virtio_9p_test(void)
 {
-qos_add_test("config", "virtio-9p", pci_config, NULL);
-qos_add_test("fs/version/basic", "virtio-9p", fs_version, NULL);
-qos_add_test("fs/attach/basic", "virtio-9p", fs_attach, NULL);
-qos_add_test("fs/walk/basic", "virtio-9p", fs_walk, NULL);
-qos_add_test("fs/walk/no_slash", "virtio-9p", fs_walk_no_slash,
+qos_add_test("synth/config", "virtio-9p", pci_config, NULL);
+qos_add_test("synth/version/basic", "virtio-9p", fs_version, NULL);
+qos_add_test("synth/attach/basic", "virtio-9p", fs_attach, NULL);
+qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, NULL);
+qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash,
  NULL);
-qos_add_test("fs/walk/dotdot_from_root", "virtio-9p",
+qos_add_test("synth/walk/dotdot_from_root", "virtio-9p",
  fs_walk_dotdot, NULL);
-qos_add_test("fs/lopen/basic", "virtio-9p", fs_lopen, NULL);
-qos_add_test("fs/write/basic", "virtio-9p", fs_write, NULL);
-qos_add_test("fs/flush/success", "virtio-9p", fs_flush_success,
+qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, NULL);
+qos_add_test("synth/write/basic", "virtio-9p", fs_write, NULL);
+qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,
  NULL);
-qos_add_test("fs/flush/ignored", "virtio-9p", fs_flush_ignored,
+qos_add_test("synth/flush/ignored", "virtio-9p", fs_flush_ignored,
  NULL);
-qos_add_test("fs/readdir/basic", "virtio-9p", fs_readdir, NULL);
-qos_add_test("fs/readdir/split_512", "virtio-9p",
+qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir, NULL);
+qos_add_test("synth/readdir/split_512", "virtio-9p",
  fs_readdir_split_512, NULL);
-qos_add_test("fs/readdir/split_256", "virtio-9p",
+qos_add_test("synth/readdir/split_256", "virtio-9p",
  fs_readdir_split_256, NULL);
-qos_add_test("fs/readdir/split_128", "virtio-9p",
+qos_add_test("synth/readdir/split_128", "virtio-9p",
  fs_readdir_split_128, NULL);
 }
 
-- 
2.20.1




[PULL 0/5] 9p queue 2020-10-15

2020-10-15 Thread Christian Schoenebeck
The following changes since commit 57c98ea9acdcef5021f5671efa6475a5794a51c4:

  Merge remote-tracking branch 'remotes/kraxel/tags/ui-20201014-pull-request' 
into staging (2020-10-14 13:56:06 +0100)

are available in the Git repository at:

  https://github.com/cschoenebeck/qemu.git tags/pull-9p-20201015

for you to fetch changes up to 97a64ec211d051439b654950ed3f7cffc47d489b:

  tests/9pfs: add local Tmkdir test (2020-10-15 16:11:17 +0200)


9pfs: add tests using local fs driver

The currently existing 9pfs test cases are all solely using the 9pfs 'synth'
fileystem driver, which is a very simple and purely simulated (in RAM only)
filesystem. There are issues though where the 'synth' fs driver is not
sufficient. For example the following two bugs need test cases running the
9pfs 'local' fs driver:

https://bugs.launchpad.net/qemu/+bug/1336794
https://bugs.launchpad.net/qemu/+bug/1877384

This patch set for that reason introduces 9pfs test cases using the 9pfs
'local' filesystem driver along to the already existing tests on 'synth'.


Christian Schoenebeck (5):
  tests/9pfs: change qtest name prefix to synth
  tests/9pfs: introduce local tests
  tests/9pfs: wipe local 9pfs test directory
  tests/9pfs: add virtio_9p_test_path()
  tests/9pfs: add local Tmkdir test

 tests/qtest/libqos/virtio-9p.c | 100 +
 tests/qtest/libqos/virtio-9p.h |  10 +++
 tests/qtest/virtio-9p-test.c   | 197 -
 3 files changed, 286 insertions(+), 21 deletions(-)



[PULL 4/5] tests/9pfs: add virtio_9p_test_path()

2020-10-15 Thread Christian Schoenebeck
This new public function virtio_9p_test_path() allows 9pfs
'local' tests to translate a path from guest scope to host
scope. For instance by passing an empty string it would
return the root path on host of the exported 9pfs tree.

Signed-off-by: Christian Schoenebeck 
Message-Id: 

Signed-off-by: Christian Schoenebeck 
---
 tests/qtest/libqos/virtio-9p.c | 6 ++
 tests/qtest/libqos/virtio-9p.h | 5 +
 2 files changed, 11 insertions(+)

diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index bd53498041..1524982634 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -65,6 +65,12 @@ static void remove_local_test_dir(void)
 g_free(cmd);
 }
 
+char *virtio_9p_test_path(const char *path)
+{
+g_assert(local_test_path);
+return concat_path(local_test_path, path);
+}
+
 static void virtio_9p_cleanup(QVirtio9P *interface)
 {
 qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc);
diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h
index 326a603f72..19a4d97454 100644
--- a/tests/qtest/libqos/virtio-9p.h
+++ b/tests/qtest/libqos/virtio-9p.h
@@ -49,4 +49,9 @@ struct QVirtio9PDevice {
  */
 void virtio_9p_assign_local_driver(GString *cmd_line, const char *args);
 
+/**
+ * Returns path on host to the passed guest path. Result must be freed.
+ */
+char *virtio_9p_test_path(const char *path);
+
 #endif
-- 
2.20.1




[PATCH] ppc/spapr: re-assert IRQs during event-scan if there are pending

2020-10-15 Thread Laurent Vivier
If we hotplug a CPU during the first second of the kernel boot,
the IRQ can be sent to the kernel while the RTAS event handler
is not installed. The event is queued, but the kernel doesn't
collect it and ignores the new CPU.

As the code relies on edge-triggered IRQ, we can re-assert it
during the event-scan RTAS call if there are still pending
events (as it is already done in check-exception).

Signed-off-by: Laurent Vivier 
---
 hw/ppc/spapr_events.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
index 1069d0197b4f..1add53547ec3 100644
--- a/hw/ppc/spapr_events.c
+++ b/hw/ppc/spapr_events.c
@@ -1000,10 +1000,22 @@ static void event_scan(PowerPCCPU *cpu, 
SpaprMachineState *spapr,
target_ulong args,
uint32_t nret, target_ulong rets)
 {
+int i;
 if (nargs != 4 || nret != 1) {
 rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
 return;
 }
+
+for (i = 0; i < EVENT_CLASS_MAX; i++) {
+if (rtas_event_log_contains(EVENT_CLASS_MASK(i))) {
+const SpaprEventSource *source =
+spapr_event_sources_get_source(spapr->event_sources, i);
+
+g_assert(source->enabled);
+qemu_irq_pulse(spapr_qirq(spapr, source->irq));
+}
+}
+
 rtas_st(rets, 0, RTAS_OUT_NO_ERRORS_FOUND);
 }
 
-- 
2.26.2




Re: [PATCH 0/3] hw/misc/mac_via: Factor generic via_irq_request() out

2020-10-15 Thread Mark Cave-Ayland

On 13/10/2020 21:49, Philippe Mathieu-Daudé wrote:


The same logic is used in 4 different places:
- via1_irq_request()
- via2_irq_request()
- via1_VBL()
- via1_one_second()

Extract the common function and reuse it.

Philippe Mathieu-Daudé (3):
   hw/misc/mac_via: Make generic via_irq_request() from
 via1_irq_request()
   hw/misc/mac_via: Replace via2_irq_request() with via_irq_request()
   hw/misc/mac_via: Use via_irq_request() in via1_VBL(),
 via1_one_second()

  hw/misc/mac_via.c | 59 +++
  1 file changed, 18 insertions(+), 41 deletions(-)


Whilst I can see the advantage of consolidating the logic in via_irq_request(), I'd 
still like to keep the above 4 functions as wrappers for now since they are a great 
aid with current work debugging Linux and MacOS. Perhaps for now the functions above 
could act as thin wrappers on your version of via_irq_request(), or alternatively 
this could be something to revisit once the m68k/q800 emulation has matured further?



ATB,

Mark.



Re: [PATCH v2 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Yonggang Luo
On Fri, Oct 16, 2020 at 4:30 AM Peter Maydell 
wrote:
>
> On Thu, 15 Oct 2020 at 21:13, Yonggang Luo  wrote:
> >
> > Signed-off-by: Yonggang Luo 
> > ---
> >  docs/conf.py  |  2 +-
> >  docs/sphinx/kerneldoc.py  |  2 +-
> >  scripts/rst-sanitize.py   | 21 +
> >  tests/qapi-schema/meson.build |  5 +++--
> >  4 files changed, 26 insertions(+), 4 deletions(-)
> >  create mode 100644 scripts/rst-sanitize.py
> >
> > diff --git a/scripts/rst-sanitize.py b/scripts/rst-sanitize.py
> > new file mode 100644
> > index 00..26060f1208
> > --- /dev/null
> > +++ b/scripts/rst-sanitize.py
> > @@ -0,0 +1,21 @@
> > +#!/usr/bin/env python3
> > +
> > +#
> > +# Script for remove cr line ending in file
> > +#
> > +# Authors:
> > +#  Yonggang Luo 
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2
> > +# or, at your option, any later version.  See the COPYING file in
> > +# the top-level directory.
> > +
> > +import sys
> > +
> > +def main(_program, file, *unused):
> > +with open(file, 'rb') as content_file:
> > +content = content_file.read()
> > +sys.stdout.buffer.write(content.replace(b'\r', b''))
> > +
> > +if __name__ == "__main__":
> > +main(*sys.argv)
>
> Why doesn't the perl rune work? Your commit message doesn't say.


PASS 3 test-qdev-global-props /qdev/properties/dynamic/global
PASS 4 test-qdev-global-props /qdev/properties/global/subclass
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}
 ../../../../../CI-Tools/msys64/usr/bin/sh.EXE
C:/work/xemu/qemu/build/../tests/decode/check.sh python3 -B
C:/work/xemu/qemu/build/../tests/../scripts/decodetree.py
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}
PYTHONPATH=C:/work/xemu/qemu/scripts PYTHONIOENCODING=utf-8
../../../../CI-Tools/msys64/mingw64/bin/python3.exe
C:/work/xemu/qemu/build/../tests/qapi-schema/test-qapi.py
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-any.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-array.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-base.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-branch-if-invalid.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-clash.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-conflict-dict.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-conflict-enum-bool.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-conflict-enum-int.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-conflict-string.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-conflict-bool-string.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-conflict-num-string.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-empty.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-invalid-dict.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-nested.json
C:/work/xemu/qemu/build/../tests/qapi-schema/alternate-unknown.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-alternate.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-any.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-array-empty.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-array-unknown.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-bad-boxed.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-boxed-anon.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-boxed-string.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-int.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-invalid.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-member-array-bad.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-member-case.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-member-unknown.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-name-clash.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-union.json
C:/work/xemu/qemu/build/../tests/qapi-schema/args-unknown.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-base.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-data.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-ident.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-if.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-if-empty.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-if-empty-list.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-if-list.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-type-bool.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-type-dict.json
C:/work/xemu/qemu/build/../tests/qapi-schema/bad-type-int.json
C:/work/xemu/qemu/build/../tests/qapi-schema/base-cycle-direct.json
C:/work/xemu/qemu/build/../tests/qapi-schema/base-cycle-indirect.json
C:/work/xemu/qemu/build/../tests/qapi-schema/command-int.json
C:/work/xemu/qemu/build/../tests/qapi-schema/comments.json
C:/work/xemu/qemu/build/../tests/qapi-schema/doc-bad-alternate-member.json

Re: [PATCH V1 18/32] osdep: import MADV_DOEXEC

2020-10-15 Thread Alex Williamson
On Thu, 8 Oct 2020 12:32:35 -0400
Steven Sistare  wrote:

> On 8/24/2020 6:30 PM, Alex Williamson wrote:
> > On Wed, 19 Aug 2020 17:52:26 -0400
> > Steven Sistare  wrote:  
> >> On 8/17/2020 10:42 PM, Alex Williamson wrote:  
> >>> On Mon, 17 Aug 2020 15:44:03 -0600
> >>> Alex Williamson  wrote:  
>  On Mon, 17 Aug 2020 17:20:57 -0400
>  Steven Sistare  wrote:  
> > On 8/17/2020 4:48 PM, Alex Williamson wrote:  
> >> On Mon, 17 Aug 2020 14:30:51 -0400
> >> Steven Sistare  wrote:
> >> 
> >>> On 7/30/2020 11:14 AM, Steve Sistare wrote:
>  Anonymous memory segments used by the guest are preserved across a 
>  re-exec
>  of qemu, mapped at the same VA, via a proposed madvise(MADV_DOEXEC) 
>  option
>  in the Linux kernel. For the madvise patches, see:
> 
>  https://lore.kernel.org/lkml/1595869887-23307-1-git-send-email-anthony.yzn...@oracle.com/
> 
>  Signed-off-by: Steve Sistare 
>  ---
>   include/qemu/osdep.h | 7 +++
>   1 file changed, 7 insertions(+)  
> >>>
> >>> Hi Alex,
> >>>   The MADV_DOEXEC functionality, which is a pre-requisite for the 
> >>> entire qemu 
> >>> live update series, is getting a chilly reception on lkml.  We could 
> >>> instead 
> >>> create guest memory using memfd_create and preserve the fd across 
> >>> exec.  However, 
> >>> the subsequent mmap(fd) will return a different VA than was used 
> >>> previously, 
> >>> which  is a problem for memory that was registered with vfio, as the 
> >>> original VA 
> >>> is remembered in the kernel struct vfio_dma and used in various 
> >>> kernel functions, 
> >>> such as vfio_iommu_replay.
> >>>
> >>> To fix, we could provide a VFIO_IOMMU_REMAP_DMA ioctl taking iova, 
> >>> size, and
> >>> new_vaddr.  The implementation finds an exact match for (iova, size) 
> >>> and replaces 
> >>> vaddr with new_vaddr.  Flags cannot be changed.
> >>>
> >>> memfd_create plus VFIO_IOMMU_REMAP_DMA would replace MADV_DOEXEC.
> >>> vfio on any form of shared memory (shm, dax, etc) could also be 
> >>> preserved across
> >>> exec with shmat/mmap plus VFIO_IOMMU_REMAP_DMA.
> >>>
> >>> What do you think
> >>
> >> Your new REMAP ioctl would have parameters identical to the MAP_DMA
> >> ioctl, so I think we should just use one of the flag bits on the
> >> existing MAP_DMA ioctl for this variant.
> >
> > Sounds good.
> >   
> >> Reading through the discussion on the kernel side there seems to be
> >> some confusion around why vfio needs the vaddr beyond the user call to
> >> MAP_DMA though.  Originally this was used to test for virtually
> >> contiguous mappings for merging and splitting purposes.  This is
> >> defunct in the v2 interface, however the vaddr is now used largely for
> >> mdev devices.  If an mdev device is not backed by an IOMMU device and
> >> does not share a container with an IOMMU device, then a user MAP_DMA
> >> ioctl essentially just registers the translation within the vfio
> >> container.  The mdev vendor driver can then later either request pages
> >> to be pinned for device DMA or can perform copy_to/from_user() to
> >> simulate DMA via the CPU.
> >>
> >> Therefore I don't see that there's a simple re-architecture of the vfio
> >> IOMMU backend that could drop vaddr use.  
> >
> > Yes.  I did not explain on lkml as you do here (thanks), but I reached 
> > the 
> > same conclusion.
> >   
> >> I'm a bit concerned this new
> >> remap proposal also raises the question of how do we prevent userspace
> >> remapping vaddrs racing with asynchronous kernel use of the previous
> >> vaddrs.  
> >
> > Agreed.  After a quick glance at the code, holding iommu->lock during 
> > remap might be sufficient, but it needs more study.  
> 
>  Unless you're suggesting an extended hold of the lock across the entire
>  re-exec of QEMU, that's only going to prevent a race between a remap
>  and a vendor driver pin or access, the time between the previous vaddr
>  becoming invalid and the remap is unprotected.
> >>
> >> OK.  What if we exclude mediated devices?  Its appears they are the only
> >> ones where the kernel may async'ly use the vaddr, via call chains ending 
> >> in 
> >> vfio_iommu_type1_pin_pages or vfio_iommu_type1_dma_rw_chunk.
> >>
> >> The other functions that use dma->vaddr are
> >> vfio_dma_do_map 
> >> vfio_pin_map_dma 
> >> vfio_iommu_replay 
> >> vfio_pin_pages_remote
> >> and they are all initiated via userland ioctl (if I have traced all the 
> >> code 
> >> paths correctly).  Thus iommu->lock would protect them.
> >>
> >> We would block live update in qemu if the 

Re: [PATCH v2 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Peter Maydell
On Thu, 15 Oct 2020 at 21:13, Yonggang Luo  wrote:
>
> Signed-off-by: Yonggang Luo 
> ---
>  docs/conf.py  |  2 +-
>  docs/sphinx/kerneldoc.py  |  2 +-
>  scripts/rst-sanitize.py   | 21 +
>  tests/qapi-schema/meson.build |  5 +++--
>  4 files changed, 26 insertions(+), 4 deletions(-)
>  create mode 100644 scripts/rst-sanitize.py
>
> diff --git a/scripts/rst-sanitize.py b/scripts/rst-sanitize.py
> new file mode 100644
> index 00..26060f1208
> --- /dev/null
> +++ b/scripts/rst-sanitize.py
> @@ -0,0 +1,21 @@
> +#!/usr/bin/env python3
> +
> +#
> +# Script for remove cr line ending in file
> +#
> +# Authors:
> +#  Yonggang Luo 
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or, at your option, any later version.  See the COPYING file in
> +# the top-level directory.
> +
> +import sys
> +
> +def main(_program, file, *unused):
> +with open(file, 'rb') as content_file:
> +content = content_file.read()
> +sys.stdout.buffer.write(content.replace(b'\r', b''))
> +
> +if __name__ == "__main__":
> +main(*sys.argv)

Why doesn't the perl rune work? Your commit message doesn't say.

> diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
> index 1f222a7a13..20a7641af8 100644
> --- a/tests/qapi-schema/meson.build
> +++ b/tests/qapi-schema/meson.build
> @@ -251,18 +251,19 @@ qapi_doc_out = custom_target('QAPI rST doc',
>  # using an explicit '\' character in the command arguments to
>  # a custom_target(), as Meson will unhelpfully replace it with a '/'
>  # (https://github.com/mesonbuild/meson/issues/1564)
> +rst_sanitize_cmd = [find_program('../../scripts/rst-sanitize.py'), '@INPUT@']
>  qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized',
>output: ['doc-good.txt.nocr'],
>input: qapi_doc_out[0],
>build_by_default: build_docs,
> -  command: ['perl', '-pe', '$x = chr 13; 
> s/$x$//', '@INPUT@'],
> +  command: rst_sanitize_cmd,
>capture: true)
>
>  qapi_doc_ref_nocr = custom_target('QAPI rST doc reference newline-sanitized',
>output: ['doc-good.ref.nocr'],
>input: files('doc-good.txt'),
>build_by_default: build_docs,
> -  command: ['perl', '-pe', '$x = chr 13; 
> s/$x$//', '@INPUT@'],
> +  command: rst_sanitize_cmd,
>capture: true)

thanks
-- PMM



[PATCH] meson: Only install icons and qemu.desktop if have_system

2020-10-15 Thread Bruce Rogers
These files are not needed for a linux-user only install.

Signed-off-by: Bruce Rogers 
---
 ui/meson.build | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/ui/meson.build b/ui/meson.build
index 78ad792ffb..fb36d305ca 100644
--- a/ui/meson.build
+++ b/ui/meson.build
@@ -113,8 +113,11 @@ if have_system or xkbcommon.found()
 endif
 
 subdir('shader')
-subdir('icons')
 
-install_data('qemu.desktop', install_dir: config_host['qemu_desktopdir'])
+if have_system
+  subdir('icons')
+
+  install_data('qemu.desktop', install_dir: config_host['qemu_desktopdir'])
+endif
 
 modules += {'ui': ui_modules}
-- 
2.28.0




Re: ide: Linux reports drive diagnostic failures on boot

2020-10-15 Thread Mark Cave-Ayland

On 13/10/2020 19:39, John Snow wrote:


On 10/13/20 6:59 AM, Mark Cave-Ayland wrote:
During my latest OpenBIOS boot tests I've noticed the following IDE diagnostics 
failure message appearing in dmesg at Linux boot time when booting from CDROM on 
both SPARC64 and PPC:



Sorry for the inconvenience.


Well it wasn't too bad - in my case the kernel was able to recover so it wasn't a 
complete showstopper for my tests. It seemed worth mentioning in case this causes 
other failures elsewhere though.



[    9.347342] scsi host0: pata_cmd64x
[    9.369055] scsi host1: pata_cmd64x
[    9.371622] ata1: PATA max UDMA/33 cmd 0x1fe02008000 ctl 0x1fe02008080 bmdma 
0x1fe02008200 irq 8
[    9.372805] ata2: PATA max UDMA/33 cmd 0x1fe02008100 ctl 0x1fe02008180 bmdma 
0x1fe02008208 irq 8

[    9.711740] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100
[    9.712591] ata2.00: Drive reports diagnostics failure. This may indicate a 
drive
[    9.713256] ata2.00: fault or invalid emulation. Contact drive vendor for 
information.

[    9.737677] ata2.00: configured for UDMA/33
[    9.790179] scsi 1:0:0:0: CD-ROM    QEMU QEMU DVD-ROM 2.5+ PQ: 0 
ANSI: 5

[   10.381172] hme :01:01.1 enp1s1f1: renamed from eth0
[   10.508819] sr 1:0:0:0: [sr0] scsi3-mmc drive: 4x/4x cd/rw xa/form2 tray
[   10.509805] cdrom: Uniform CD-ROM driver Revision: 3.20


A session with git bisect points to the following commit:

55adb3c45620c31f29978f209e2a44a08d34e2da is the first bad commit
commit 55adb3c45620c31f29978f209e2a44a08d34e2da
Author: John Snow 
Date:   Fri Jul 24 01:23:00 2020 -0400

 ide: cancel pending callbacks on SRST

 The SRST implementation did not keep up with the rest of IDE; it is
 possible to perform a weak reset on an IDE device to remove the BSY/DRQ
 bits, and then issue writes to the control/device registers which can
 cause chaos with the state machine.

 Fix that by actually performing a real reset.

 Reported-by: Alexander Bulekov 
 Fixes: https://bugs.launchpad.net/qemu/+bug/1878253
 Fixes: https://bugs.launchpad.net/qemu/+bug/1887303
 Fixes: https://bugs.launchpad.net/qemu/+bug/1887309
 Signed-off-by: John Snow 

:04 04 70a7c1cfbafb22fa815d3ae4d7ed075ac3918188 
3f37762f20e9ca9d2874eaf819d7175a1dca1dd9 M  hw



John/Alexander: any chance you could take a look at this? The message above is 
really simple to reproduce under qemu-system-sparc64 using 
http://cdimage.debian.org/cdimage/ports/9.0/sparc64/iso-cd/debian-9.0-sparc64-NETINST-1.iso 
and the following command line:


./qemu-system-sparc64 \
 -cdrom debian-9.0-sparc64-NETINST-1.iso \
 -m 256 \
 -nographic \
 -boot d


ATB,

Mark.



Shucks.

This patch happened because the old SRST code reset the IDE state machine (cleared 
the status register) but then didn't cancel any of the pending callbacks, so it was 
possible to shuffle the state machine off the rails onto junk data. Obviously bad.


Now, SRST actually cancels the callbacks which I thought would have been safe, but 
it's possible that doing a "real" reset here is touching more registers than it ought 
to.


Let's take a look at the linux source code ...

/* Let the user know. We don't want to disallow opens for
    rescue purposes, or in case the vendor is just a blithering
    idiot. Do this after the dev_config call as some controllers
    with buggy firmware may want to avoid reporting false device
    bugs */

Ah, always a nice day to be called an idiot. Thank you for your service, Alan 
Cox.

This message gets printed when ATA_HORKAGE_DIAGNOSTIC is set. libata-sff.c suggests 
this happens when the error register* comes back 0x00 after an SRST.


(*I think that tf.feature is only feature on writes, but error on reads. Same 
address.)

Now, ide_reset -- which we use for initialization and resets both always sets the 
error register to 0x00. libata thinks that 0x00 means a failed diagnostics test, though.


This ought to be covered by ATA8-APT. Section 9.2, Software reset protocol.

Cliff notes:

- Host writes to SRST and waits for 5 μs.
- Both devices obey the SRST write, regardless of drive selection.
- Each device clears their registers and sets BSY (within 400ns.)
- Host clears SRST and waits for at least 2ms.
- Host polls devices, waiting for BSY to be 0.


device0 can set bit7 in the error register to 0 or 1, depending on the presence or 
absence of device1 and how it behaves following a diagnostic test.



Device 1 is absent: bit7 is cleared.
Device 1 is present:
   - If PDIAG- is asserted, bit7 is cleared.
   - If PDIAG- is not asserted within 31 seconds, bit7 is set.

Then, ah:

The EXECUTE DEVICE DIAGNOSTICS diagnostic code shall be placed in bits (6:0) of the 
Error register (See Clause 0). The device shall set the signature values (See Clause 
0). The content of the Features register is undefined.


I got this pretty wrong. I'm seeing a few problems:

1. I thought SRST was triggered on the falling edge, but 

[PATCH v3 1/2] block: Fixes nfs compiling error on msys2/mingw

2020-10-15 Thread Yonggang Luo
These compiling errors are fixed:
../block/nfs.c:27:10: fatal error: poll.h: No such file or directory
   27 | #include 
  |  ^~~~
compilation terminated.

../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'
   63 | blkcnt_t st_blocks;
  | ^~~~
../block/nfs.c: In function 'nfs_client_open':
../block/nfs.c:550:27: error: 'struct _stat64' has no member named 'st_blocks'
  550 | client->st_blocks = st.st_blocks;
  |   ^
../block/nfs.c: In function 'nfs_get_allocated_file_size':
../block/nfs.c:751:41: error: 'struct _stat64' has no member named 'st_blocks'
  751 | return (task.ret < 0 ? task.ret : st.st_blocks * 512);
  | ^
../block/nfs.c: In function 'nfs_reopen_prepare':
../block/nfs.c:805:31: error: 'struct _stat64' has no member named 'st_blocks'
  805 | client->st_blocks = st.st_blocks;
  |   ^
../block/nfs.c: In function 'nfs_get_allocated_file_size':
../block/nfs.c:752:1: error: control reaches end of non-void function 
[-Werror=return-type]
  752 | }
  | ^

On msys2/mingw, there is no st_blocks in struct _stat64 yet, we disable the 
usage of it
on msys2/mingw, and create a typedef long long blkcnt_t; for further 
implementation

Signed-off-by: Yonggang Luo 
---
 block/nfs.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/block/nfs.c b/block/nfs.c
index f86e660374..cf8795fb49 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -24,7 +24,9 @@
 
 #include "qemu/osdep.h"
 
+#if !defined(_WIN32)
 #include 
+#endif
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
@@ -51,6 +53,10 @@
 #define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)
 #define QEMU_NFS_MAX_DEBUG_LEVEL 2
 
+#if defined(_WIN32)
+typedef long long blkcnt_t;
+#endif
+
 typedef struct NFSClient {
 struct nfs_context *context;
 struct nfsfh *fh;
@@ -545,7 +551,9 @@ static int64_t nfs_client_open(NFSClient *client, 
BlockdevOptionsNfs *opts,
 }
 
 ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE);
+#if !defined(_WIN32)
 client->st_blocks = st.st_blocks;
+#endif
 client->has_zero_init = S_ISREG(st.st_mode);
 *strp = '/';
 goto out;
@@ -706,6 +714,7 @@ static int nfs_has_zero_init(BlockDriverState *bs)
 return client->has_zero_init;
 }
 
+#if !defined(_WIN32)
 /* Called (via nfs_service) with QemuMutex held.  */
 static void
 nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
@@ -748,6 +757,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState 
*bs)
 
 return (task.ret < 0 ? task.ret : st.st_blocks * 512);
 }
+#endif
 
 static int coroutine_fn
 nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
@@ -800,7 +810,9 @@ static int nfs_reopen_prepare(BDRVReopenState *state,
nfs_get_error(client->context));
 return ret;
 }
+#if !defined(_WIN32)
 client->st_blocks = st.st_blocks;
+#endif
 }
 
 return 0;
@@ -869,7 +881,10 @@ static BlockDriver bdrv_nfs = {
 .create_opts= _create_opts,
 
 .bdrv_has_zero_init = nfs_has_zero_init,
+/* libnfs does not provide the allocated filesize of a file on win32. */
+#if !defined(_WIN32)
 .bdrv_get_allocated_file_size   = nfs_get_allocated_file_size,
+#endif
 .bdrv_co_truncate   = nfs_file_co_truncate,
 
 .bdrv_file_open = nfs_file_open,
-- 
2.28.0.windows.1




[PATCH v3 0/2] Fixes building nfs on msys2/mingw

2020-10-15 Thread Yonggang Luo
Revise the commit message of
* block: enable libnfs on msys2/mingw in cirrus.yml

V1-V2
Apply suggestion from  Peter Lieven

Yonggang Luo (2):
  block: Fixes nfs compiling error on msys2/mingw
  block: enable libnfs on msys2/mingw in cirrus.yml

 .cirrus.yml |  1 +
 block/nfs.c | 15 +++
 2 files changed, 16 insertions(+)

-- 
2.28.0.windows.1




[PATCH v3 2/2] block: enable libnfs on msys2/mingw in cirrus.yml

2020-10-15 Thread Yonggang Luo
Initially, libnfs has not been enabled, and now it's fixed, so enable it
on cirrus.

Signed-off-by: Yonggang Luo 
---
 .cirrus.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.cirrus.yml b/.cirrus.yml
index f42ccb956a..2c6bf45e6d 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -109,6 +109,7 @@ windows_msys2_task:
   mingw-w64-x86_64-cyrus-sasl \
   mingw-w64-x86_64-curl \
   mingw-w64-x86_64-gnutls \
+  mingw-w64-x86_64-libnfs \
   "
 bitsadmin /transfer msys_download /dynamic /download /priority 
FOREGROUND `
   
https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
 `
-- 
2.28.0.windows.1




[PATCH v2 3/4] meson: Move the detection logic for sphinx to meson

2020-10-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 configure | 59 +++
 docs/meson.build  |  4 +--
 meson.build   | 59 ++-
 meson_options.txt |  5 ++-
 tests/qapi-schema/meson.build |  2 +-
 5 files changed, 63 insertions(+), 66 deletions(-)

diff --git a/configure b/configure
index 1ce31f97b4..ff593a8542 100755
--- a/configure
+++ b/configure
@@ -297,7 +297,7 @@ brlapi=""
 curl=""
 iconv="auto"
 curses="auto"
-docs=""
+docs="auto"
 fdt="auto"
 netmap="no"
 sdl="auto"
@@ -822,15 +822,6 @@ do
 fi
 done
 
-sphinx_build=
-for binary in sphinx-build-3 sphinx-build
-do
-if has "$binary"
-then
-sphinx_build=$(command -v "$binary")
-break
-fi
-done
 
 # Check for ancillary tools used in testing
 genisoimage=
@@ -1226,9 +1217,9 @@ for opt do
   ;;
   --disable-crypto-afalg) crypto_afalg="no"
   ;;
-  --disable-docs) docs="no"
+  --disable-docs) docs="disabled"
   ;;
-  --enable-docs) docs="yes"
+  --enable-docs) docs="enabled"
   ;;
   --disable-vhost-net) vhost_net="no"
   ;;
@@ -4413,45 +4404,6 @@ if check_include linux/btrfs.h ; then
 btrfs=yes
 fi
 
-# If we're making warnings fatal, apply this to Sphinx runs as well
-sphinx_werror=""
-if test "$werror" = "yes"; then
-sphinx_werror="-W"
-fi
-
-# Check we have a new enough version of sphinx-build
-has_sphinx_build() {
-# This is a bit awkward but works: create a trivial document and
-# try to run it with our configuration file (which enforces a
-# version requirement). This will fail if either
-# sphinx-build doesn't exist at all or if it is too old.
-mkdir -p "$TMPDIR1/sphinx"
-touch "$TMPDIR1/sphinx/index.rst"
-"$sphinx_build" $sphinx_werror -c "$source_path/docs" \
--b html "$TMPDIR1/sphinx" \
-"$TMPDIR1/sphinx/out"  >> config.log 2>&1
-}
-
-# Check if tools are available to build documentation.
-if test "$docs" != "no" ; then
-  if has_sphinx_build; then
-sphinx_ok=yes
-  else
-sphinx_ok=no
-  fi
-  if test "$sphinx_ok" = "yes"; then
-docs=yes
-  else
-if test "$docs" = "yes" ; then
-  if has $sphinx_build && test "$sphinx_ok" != "yes"; then
-echo "Warning: $sphinx_build exists but it is either too old or uses 
too old a Python version" >&2
-  fi
-  feature_not_found "docs" "Install a Python 3 version of python-sphinx"
-fi
-docs=no
-  fi
-fi
-
 # Search for bswap_32 function
 byteswap_h=no
 cat > $TMPC << EOF
@@ -6087,9 +6039,6 @@ qemu_version=$(head $source_path/VERSION)
 echo "PKGVERSION=$pkgversion" >>$config_host_mak
 echo "SRC_PATH=$source_path" >> $config_host_mak
 echo "TARGET_DIRS=$target_list" >> $config_host_mak
-if [ "$docs" = "yes" ] ; then
-  echo "BUILD_DOCS=yes" >> $config_host_mak
-fi
 if test "$modules" = "yes"; then
   # $shacmd can generate a hash started with digit, which the compiler doesn't
   # like as an symbol. So prefix it with an underscore
@@ -6794,7 +6743,6 @@ fi
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "PYTHON=$python" >> $config_host_mak
-echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
 echo "MESON=$meson" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
@@ -7076,6 +7024,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
 -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
 -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
 -Diconv=$iconv -Dcurses=$curses \
+-Ddocs=$docs -Dsphinx_build=$sphinx_build \
 $cross_arg \
 "$PWD" "$source_path"
 
diff --git a/docs/meson.build b/docs/meson.build
index 0340d489ac..f566809a6a 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -37,7 +37,7 @@ if build_docs
 input: [files('conf.py'), files(manual / 'conf.py')],
 depfile: manual + '.d',
 depend_files: sphinx_extn_depends,
-command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@',
+command: SPHINX_ARGS + ['-Ddepfile=@DEPFILE@',
   '-Ddepfile_stamp=@OUTPUT0@',
   '-b', 'html', '-d', private_dir,
   input_dir, output_dir])
@@ -59,7 +59,7 @@ if build_docs
  input: this_manual,
  install: build_docs,
  install_dir: install_dirs,
- command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
+ command: SPHINX_ARGS + ['-b', 'man', '-d', 
private_dir,
input_dir, meson.current_build_dir()])
 endif
   endforeach
diff --git a/meson.build b/meson.build
index 8156df8b71..3cf54d82f6 100644
--- a/meson.build
+++ b/meson.build
@@ -17,7 +17,13 @@ cc = meson.get_compiler('c')
 config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
 

[PATCH v2 0/4] Fixes docs building on msys2/mingw

2020-10-15 Thread Yonggang Luo
v1 - v2
Also move the docs configure part from
configure to meson, this also fixed the pending
ninjatool removal caused issue that docs  can
not be build under msys2/mingw

Yonggang Luo (4):
  docs: Fixes build docs on msys2/mingw
  configure: the docdir option should passed to meson as is.
  meson: Move the detection logic for sphinx to meson
  cirrus: Enable doc build on msys2/mingw

 .cirrus.yml   |  6 +++-
 configure | 62 +++
 docs/conf.py  |  2 +-
 docs/meson.build  |  4 +--
 docs/sphinx/kerneldoc.py  |  2 +-
 meson.build   | 59 +
 meson_options.txt |  5 ++-
 scripts/rst-sanitize.py   | 21 
 tests/qapi-schema/meson.build |  7 ++--
 9 files changed, 95 insertions(+), 73 deletions(-)
 create mode 100644 scripts/rst-sanitize.py

-- 
2.28.0.windows.1




[PATCH v2 2/4] configure: the docdir option should passed to meson as is.

2020-10-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 configure | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/configure b/configure
index f839c2a557..1ce31f97b4 100755
--- a/configure
+++ b/configure
@@ -971,7 +971,7 @@ for opt do
   ;;
   --with-suffix=*) qemu_suffix="$optarg"
   ;;
-  --docdir=*) qemu_docdir="$optarg"
+  --docdir=*) docdir="$optarg"
   ;;
   --sysconfdir=*) sysconfdir="$optarg"
   ;;
@@ -5770,7 +5770,6 @@ fi
 qemu_confdir="$sysconfdir/$qemu_suffix"
 qemu_moddir="$libdir/$qemu_suffix"
 qemu_datadir="$datadir/$qemu_suffix"
-qemu_docdir="$docdir/$qemu_suffix"
 qemu_localedir="$datadir/locale"
 qemu_icondir="$datadir/icons"
 qemu_desktopdir="$datadir/applications"
-- 
2.28.0.windows.1




[PATCH v2 4/4] cirrus: Enable doc build on msys2/mingw

2020-10-15 Thread Yonggang Luo
Currently rST depends on old version sphinx-2.x.
Install it by downloading it.
Remove the need of university mirror, the main repo are recovered.

Signed-off-by: Yonggang Luo 
---
 .cirrus.yml | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 99d118239c..f42ccb956a 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -76,7 +76,6 @@ windows_msys2_task:
 ((Get-Content -path 
C:\tools\msys64\etc\\post-install\\07-pacman-key.post -Raw) -replace 
'--refresh-keys', '--version') | Set-Content -Path 
C:\tools\msys64\etc\\post-install\\07-pacman-key.post
 C:\tools\msys64\usr\bin\bash.exe -lc "sed -i 
's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
 C:\tools\msys64\usr\bin\bash.exe -lc "export"
-C:\tools\msys64\usr\bin\bash.exe -lc "grep -rl 'repo.msys2.org/' 
/etc/pacman.d/mirrorlist.* | xargs sed -i 
's/repo.msys2.org\//mirrors.tuna.tsinghua.edu.cn\/msys2\//g'"
 C:\tools\msys64\usr\bin\pacman.exe --noconfirm -Sy
 echo Y | C:\tools\msys64\usr\bin\pacman.exe --noconfirm -Suu 
--overwrite=*
 taskkill /F /FI "MODULES eq msys-2.0.dll"
@@ -111,6 +110,11 @@ windows_msys2_task:
   mingw-w64-x86_64-curl \
   mingw-w64-x86_64-gnutls \
   "
+bitsadmin /transfer msys_download /dynamic /download /priority 
FOREGROUND `
+  
https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
 `
+  C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
+C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -U 
/c/tools/mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz"
+del C:\tools\mingw-w64-x86_64-python-sphinx-2.3.1-1-any.pkg.tar.xz
 C:\tools\msys64\usr\bin\bash.exe -lc "rm -rf /var/cache/pacman/pkg/*"
 cd C:\tools\msys64
 echo "Start archive"
-- 
2.28.0.windows.1




[PATCH v2 1/4] docs: Fixes build docs on msys2/mingw

2020-10-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 docs/conf.py  |  2 +-
 docs/sphinx/kerneldoc.py  |  2 +-
 scripts/rst-sanitize.py   | 21 +
 tests/qapi-schema/meson.build |  5 +++--
 4 files changed, 26 insertions(+), 4 deletions(-)
 create mode 100644 scripts/rst-sanitize.py

diff --git a/docs/conf.py b/docs/conf.py
index 00e1b750e2..e584f68393 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -241,7 +241,7 @@ texinfo_documents = [
 # We use paths starting from qemu_docdir here so that you can run
 # sphinx-build from anywhere and the kerneldoc extension can still
 # find everything.
-kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc')
+kerneldoc_bin = ['perl', os.path.join(qemu_docdir, '../scripts/kernel-doc')]
 kerneldoc_srctree = os.path.join(qemu_docdir, '..')
 hxtool_srctree = os.path.join(qemu_docdir, '..')
 qapidoc_srctree = os.path.join(qemu_docdir, '..')
diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py
index 3e87940206..3ac277d162 100644
--- a/docs/sphinx/kerneldoc.py
+++ b/docs/sphinx/kerneldoc.py
@@ -67,7 +67,7 @@ class KernelDocDirective(Directive):
 
 def run(self):
 env = self.state.document.settings.env
-cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno']
+cmd = env.config.kerneldoc_bin + ['-rst', '-enable-lineno']
 
 filename = env.config.kerneldoc_srctree + '/' + self.arguments[0]
 export_file_patterns = []
diff --git a/scripts/rst-sanitize.py b/scripts/rst-sanitize.py
new file mode 100644
index 00..26060f1208
--- /dev/null
+++ b/scripts/rst-sanitize.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+#
+# Script for remove cr line ending in file
+#
+# Authors:
+#  Yonggang Luo 
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or, at your option, any later version.  See the COPYING file in
+# the top-level directory.
+
+import sys
+
+def main(_program, file, *unused):
+with open(file, 'rb') as content_file:
+content = content_file.read()
+sys.stdout.buffer.write(content.replace(b'\r', b''))
+
+if __name__ == "__main__":
+main(*sys.argv)
diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
index 1f222a7a13..20a7641af8 100644
--- a/tests/qapi-schema/meson.build
+++ b/tests/qapi-schema/meson.build
@@ -251,18 +251,19 @@ qapi_doc_out = custom_target('QAPI rST doc',
 # using an explicit '\' character in the command arguments to
 # a custom_target(), as Meson will unhelpfully replace it with a '/'
 # (https://github.com/mesonbuild/meson/issues/1564)
+rst_sanitize_cmd = [find_program('../../scripts/rst-sanitize.py'), '@INPUT@']
 qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized',
   output: ['doc-good.txt.nocr'],
   input: qapi_doc_out[0],
   build_by_default: build_docs,
-  command: ['perl', '-pe', '$x = chr 13; 
s/$x$//', '@INPUT@'],
+  command: rst_sanitize_cmd,
   capture: true)
 
 qapi_doc_ref_nocr = custom_target('QAPI rST doc reference newline-sanitized',
   output: ['doc-good.ref.nocr'],
   input: files('doc-good.txt'),
   build_by_default: build_docs,
-  command: ['perl', '-pe', '$x = chr 13; 
s/$x$//', '@INPUT@'],
+  command: rst_sanitize_cmd,
   capture: true)
 
 if build_docs
-- 
2.28.0.windows.1




Re: [PATCH v5] hw/avr: Add limited support for avr gpio registers

2020-10-15 Thread Michael Rolnik
Reviewed-by: Michael Rolnik 


On Sat, Oct 10, 2020 at 5:34 PM Heecheol Yang 
wrote:

> Add some of these features for AVR GPIO:
>
>   - GPIO I/O : PORTx registers
>   - Data Direction : DDRx registers
>   - DDRx toggling : PINx registers
>
> Following things are not supported yet:
>   - MCUR registers
>
> Signed-off-by: Heecheol Yang 
> ---
>  hw/avr/Kconfig |   1 +
>  hw/avr/atmega.c|   7 +-
>  hw/avr/atmega.h|   2 +
>  hw/gpio/Kconfig|   3 +
>  hw/gpio/avr_gpio.c | 136 +
>  hw/gpio/meson.build|   2 +
>  include/hw/gpio/avr_gpio.h |  53 +++
>  7 files changed, 202 insertions(+), 2 deletions(-)
>  create mode 100644 hw/gpio/avr_gpio.c
>  create mode 100644 include/hw/gpio/avr_gpio.h
>
> diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig
> index d31298c3cc..16a57ced11 100644
> --- a/hw/avr/Kconfig
> +++ b/hw/avr/Kconfig
> @@ -3,6 +3,7 @@ config AVR_ATMEGA_MCU
>  select AVR_TIMER16
>  select AVR_USART
>  select AVR_POWER
> +select AVR_GPIO
>
>  config ARDUINO
>  select AVR_ATMEGA_MCU
> diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
> index 44c6afebbb..ad942028fd 100644
> --- a/hw/avr/atmega.c
> +++ b/hw/avr/atmega.c
> @@ -283,8 +283,11 @@ static void atmega_realize(DeviceState *dev, Error
> **errp)
>  continue;
>  }
>  devname = g_strdup_printf("atmega-gpio-%c", 'a' + (char)i);
> -create_unimplemented_device(devname,
> -OFFSET_DATA + mc->dev[idx].addr, 3);
> +object_initialize_child(OBJECT(dev), devname, >gpio[i],
> +TYPE_AVR_GPIO);
> +sysbus_realize(SYS_BUS_DEVICE(>gpio[i]), _abort);
> +sysbus_mmio_map(SYS_BUS_DEVICE(>gpio[i]), 0,
> +OFFSET_DATA + mc->dev[idx].addr);
>  g_free(devname);
>  }
>
> diff --git a/hw/avr/atmega.h b/hw/avr/atmega.h
> index a99ee15c7e..e2289d5744 100644
> --- a/hw/avr/atmega.h
> +++ b/hw/avr/atmega.h
> @@ -13,6 +13,7 @@
>
>  #include "hw/char/avr_usart.h"
>  #include "hw/timer/avr_timer16.h"
> +#include "hw/gpio/avr_gpio.h"
>  #include "hw/misc/avr_power.h"
>  #include "target/avr/cpu.h"
>  #include "qom/object.h"
> @@ -44,6 +45,7 @@ struct AtmegaMcuState {
>  DeviceState *io;
>  AVRMaskState pwr[POWER_MAX];
>  AVRUsartState usart[USART_MAX];
> +AVRGPIOState gpio[GPIO_MAX];
>  AVRTimer16State timer[TIMER_MAX];
>  uint64_t xtal_freq_hz;
>  };
> diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig
> index b6fdaa2586..1752d0ce56 100644
> --- a/hw/gpio/Kconfig
> +++ b/hw/gpio/Kconfig
> @@ -10,3 +10,6 @@ config GPIO_KEY
>
>  config SIFIVE_GPIO
>  bool
> +
> +config AVR_GPIO
> +bool
> diff --git a/hw/gpio/avr_gpio.c b/hw/gpio/avr_gpio.c
> new file mode 100644
> index 00..29e799670d
> --- /dev/null
> +++ b/hw/gpio/avr_gpio.c
> @@ -0,0 +1,136 @@
> +/*
> + * AVR processors GPIO registers emulation.
> + *
> + * Copyright (C) 2020 Heecheol Yang 
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 or
> + * (at your option) version 3 of the License.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see .
> + */
> +#include "qemu/osdep.h"
> +#include "qemu/log.h"
> +#include "qemu/module.h"
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "hw/sysbus.h"
> +#include "hw/irq.h"
> +#include "hw/gpio/avr_gpio.h"
> +#include "hw/qdev-properties.h"
> +
> +static void avr_gpio_reset(DeviceState *dev)
> +{
> +AVRGPIOState *gpio = AVR_GPIO(dev);
> +gpio->reg.pin = 0u;
> +gpio->reg.ddr = 0u;
> +gpio->reg.port = 0u;
> +}
> +
> +static void avr_gpio_write_port(AVRGPIOState *s, uint64_t value)
> +{
> +uint8_t pin;
> +uint8_t cur_port_val = s->reg.port;
> +uint8_t cur_ddr_val = s->reg.ddr;
> +
> +for (pin = 0u; pin < 8u ; pin++) {
> +uint8_t cur_port_pin_val = cur_port_val & 0x01u;
> +uint8_t cur_ddr_pin_val = cur_ddr_val & 0x01u;
> +uint8_t new_port_pin_val = value & 0x01u;
> +
> +if (cur_ddr_pin_val && (cur_port_pin_val != new_port_pin_val)) {
> +qemu_set_irq(s->out[pin], new_port_pin_val);
> +}
> +cur_port_val >>= 1u;
> +cur_ddr_val >>= 1u;
> +value >>= 1u;
> +}
> +s->reg.port = value & s->reg.ddr;
> +}
> +static uint64_t avr_gpio_read(void *opaque, hwaddr offset, unsigned int
> size)
> +{
> +AVRGPIOState *s = (AVRGPIOState *)opaque;
> +switch (offset) 

Re: [PATCH 1/2] pci: Change error_report to assert(3)

2020-10-15 Thread Philippe Mathieu-Daudé

On 10/15/20 9:55 PM, Philippe Mathieu-Daudé wrote:

On 10/15/20 8:14 PM, Ben Widawsky wrote:

Asserts are used for developer bugs. As registering a bar of the wrong
size is not something that should be possible for a user to achieve,
this is a developer bug.

While here, use the more obvious helper function.

Signed-off-by: Ben Widawsky 
---
  hw/pci/pci.c | 6 +-
  1 file changed, 1 insertion(+), 5 deletions(-)


Reviewed-by: Philippe Mathieu-Daudé 


Maybe 'assert(3)' -> 'assert()' in subject.




Re: [RFC PATCH] contrib/gitdm: Add more individual contributors

2020-10-15 Thread Michael Rolnik
Acked-by: Michael Rolnik >

On Mon, Oct 12, 2020 at 8:56 AM sundeep subbaraya 
wrote:

> Acked-by: Subbaraya Sundeep 
>
> Thanks,
> Sundeep
>
> On Sun, Oct 4, 2020 at 11:55 PM Philippe Mathieu-Daudé 
> wrote:
> >
> > These individual contributors have a number of contributions,
> > add them to the 'individual' group map.
> >
> > Cc: Ahmed Karaman 
> > Cc: Aleksandar Markovic 
> > Cc: Alistair Francis 
> > Cc: Artyom Tarasenko 
> > Cc: David Carlier 
> > Cc: Finn Thain 
> > Cc: Guenter Roeck 
> > Cc: Helge Deller 
> > Cc: Hervé Poussineau 
> > Cc: James Hogan 
> > Cc: Jean-Christophe Dubois 
> > Cc: Kővágó Zoltán 
> > Cc: Laurent Vivier 
> > Cc: Michael Rolnik 
> > Cc: Niek Linnenbank 
> > Cc: Paul Burton 
> > Cc: Paul Zimmerman 
> > Cc: Stefan Weil 
> > Cc: Subbaraya Sundeep 
> > Cc: Sven Schnelle 
> > Cc: Thomas Huth 
> > Cc: Volker Rümelin 
> > Signed-off-by: Philippe Mathieu-Daudé 
> > ---
> > To the developers Cc'ed: If you agree with your entry, please
> > reply with a Reviewed-by/Acked-by tag. If you disagree or doesn't
> > care, please either reply with Nack-by or ignore this patch.
> > I'll repost in 2 weeks as formal patch (not RFC) with only the
> > entries acked by their author.
> > ---
> >  contrib/gitdm/group-map-individuals | 22 ++
> >  contrib/gitdm/group-map-redhat  |  1 -
> >  2 files changed, 22 insertions(+), 1 deletion(-)
> >
> > diff --git a/contrib/gitdm/group-map-individuals
> b/contrib/gitdm/group-map-individuals
> > index cf8a2ce367..b478fd4576 100644
> > --- a/contrib/gitdm/group-map-individuals
> > +++ b/contrib/gitdm/group-map-individuals
> > @@ -16,3 +16,25 @@ aurel...@aurel32.net
> >  bala...@eik.bme.hu
> >  e.emanuelegiuse...@gmail.com
> >  andrew.smir...@gmail.com
> > +s...@weilnetz.de
> > +h...@tuxfamily.org
> > +laur...@vivier.eu
> > +atar4q...@gmail.com
> > +hpous...@reactos.org
> > +del...@gmx.de
> > +alist...@alistair23.me
> > +fth...@telegraphics.com.au
> > +sv...@stackframe.org
> > +aleksandar.qemu.de...@gmail.com
> > +jho...@kernel.org
> > +paulbur...@kernel.org
> > +vr_q...@t-online.de
> > +nieklinnenb...@gmail.com
> > +devne...@gmail.com
> > +j...@tribudubois.net
> > +dirty.ice...@gmail.com
> > +mrol...@gmail.com
> > +pauld...@gmail.com
> > +li...@roeck-us.net
> > +sundeep.l...@gmail.com
> > +ahmedkhaledkara...@gmail.com
> > diff --git a/contrib/gitdm/group-map-redhat
> b/contrib/gitdm/group-map-redhat
> > index d15db2d35e..4a8ca84b36 100644
> > --- a/contrib/gitdm/group-map-redhat
> > +++ b/contrib/gitdm/group-map-redhat
> > @@ -3,6 +3,5 @@
> >  #
> >
> >  da...@gibson.dropbear.id.au
> > -laur...@vivier.eu
> >  p...@fedoraproject.org
> >  arm...@pond.sub.org
> > --
> > 2.26.2
> >
>


-- 
Best Regards,
Michael Rolnik


Re: [PATCH 1/2] pci: Change error_report to assert(3)

2020-10-15 Thread Philippe Mathieu-Daudé

On 10/15/20 8:14 PM, Ben Widawsky wrote:

Asserts are used for developer bugs. As registering a bar of the wrong
size is not something that should be possible for a user to achieve,
this is a developer bug.

While here, use the more obvious helper function.

Signed-off-by: Ben Widawsky 
---
  hw/pci/pci.c | 6 +-
  1 file changed, 1 insertion(+), 5 deletions(-)


Reviewed-by: Philippe Mathieu-Daudé 




Re: [PATCH] configure: fix handling of --docdir parameter

2020-10-15 Thread Philippe Mathieu-Daudé

On 10/15/20 9:07 PM, Bruce Rogers wrote:

Commit ca8c0909f01 changed qemu_docdir to be docdir, then later uses the
qemu_docdir name in the final assignment. Unfortunately, one instance of
qemu_docdir was missed: the one which comes from the --docdir parameter.
This patch restores the proper handling of the --docdir parameter.

Fixes: ca8c0909f01 ("configure: build docdir like other suffixed
directories")

Signed-off-by: Bruce Rogers 
---
  configure | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)


Reviewed-by: Philippe Mathieu-Daudé 




[PATCH v2 2/2] hw/rtc/m48t59: Simplify m48t59_init() passing MemoryRegion argument

2020-10-15 Thread Philippe Mathieu-Daudé
Pass a MemoryRegion* to m48t59_init(), directly call
memory_region_add_subregion() instead of sysbus_mmio_map().

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c | 10 +++---
 hw/sparc/sun4m.c|  3 ++-
 hw/sparc64/sun4u.c  |  7 ++-
 5 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/include/hw/rtc/m48t59.h b/include/hw/rtc/m48t59.h
index d99dda2b7de..3c337e8171c 100644
--- a/include/hw/rtc/m48t59.h
+++ b/include/hw/rtc/m48t59.h
@@ -49,7 +49,7 @@ struct NvramClass {
 
 Nvram *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
int base_year, int type);
-Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
+Nvram *m48t59_init(MemoryRegion *mr, hwaddr mem_base, qemu_irq IRQ,
uint16_t size, int base_year, int model);
 
 #endif /* HW_M48T59_H */
diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index 93ffee801a3..6ab1b860545 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
 /* Register FPGA */
 ref405ep_fpga_init(sysmem, 0xF030);
 /* Register NVRAM */
-m48t59_init(NULL, 0xF000, 8192, 1968, 8);
+m48t59_init(get_system_memory(), 0xF000, NULL, 8192, 1968, 8);
 /* Load kernel */
 linux_boot = (kernel_filename != NULL);
 if (linux_boot) {
diff --git a/hw/rtc/m48t59.c b/hw/rtc/m48t59.c
index 8b02c2ec558..7ec4b241218 100644
--- a/hw/rtc/m48t59.c
+++ b/hw/rtc/m48t59.c
@@ -565,9 +565,8 @@ const MemoryRegionOps m48t59_io_ops = {
 };
 
 /* Initialisation routine */
-Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-   uint16_t size, int base_year,
-   int model)
+Nvram *m48t59_init(MemoryRegion *mr, hwaddr mem_base, qemu_irq IRQ,
+   uint16_t size, int base_year, int model)
 {
 DeviceState *dev;
 SysBusDevice *s;
@@ -584,10 +583,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
 s = SYS_BUS_DEVICE(dev);
 sysbus_realize_and_unref(s, _fatal);
 sysbus_connect_irq(s, 0, IRQ);
-if (mem_base != 0) {
-sysbus_mmio_map(s, 0, mem_base);
-}
-
+memory_region_add_subregion(mr, mem_base, sysbus_mmio_get_region(s, 
0));
 return NVRAM(s);
 }
 
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 20c1fa41192..aebe9e0df3d 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -966,7 +966,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
 create_unimplemented_device("SUNW,sx", hwdef->sx_base, 0x2000);
 }
 
-nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
+nvram = m48t59_init(get_system_memory(), hwdef->nvram_base, slavio_irq[0],
+0x2000, 1968, 8);
 
 slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, 
smp_cpus);
 
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 6854522bbfa..4c975c25274 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -561,7 +561,6 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
 SabreState *sabre;
 PCIBus *pci_bus, *pci_busA, *pci_busB;
 PCIDevice *ebus, *pci_dev;
-SysBusDevice *s;
 DeviceState *iommu, *dev;
 FWCfgState *fw_cfg;
 NICInfo *nd;
@@ -671,10 +670,8 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
 pci_ide_create_devs(pci_dev);
 
 /* Map NVRAM into I/O (ebus) space */
-nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
-s = SYS_BUS_DEVICE(nvram);
-memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
-sysbus_mmio_get_region(s, 0));
+nvram = m48t59_init(pci_address_space_io(ebus), 0x2000, NULL,
+NVRAM_SIZE, 1968, 59);
  
 initrd_size = 0;
 initrd_addr = 0;
-- 
2.26.2




[PATCH v2 1/2] hw/rtc/m48t59: Simplify m48t59_init() removing 'io_base' argument

2020-10-15 Thread Philippe Mathieu-Daudé
As the 'io_base' argument of m48t59_init() is unused (set to 0),
remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the
preferred function to use.

Acked-by: David Gibson 
Reviewed-by: Mark Cave-Ayland 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/rtc/m48t59.h | 3 +--
 hw/ppc/ppc405_boards.c  | 2 +-
 hw/rtc/m48t59.c | 6 +-
 hw/sparc/sun4m.c| 2 +-
 hw/sparc64/sun4u.c  | 2 +-
 5 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/include/hw/rtc/m48t59.h b/include/hw/rtc/m48t59.h
index 04abedf3b2b..d99dda2b7de 100644
--- a/include/hw/rtc/m48t59.h
+++ b/include/hw/rtc/m48t59.h
@@ -50,7 +50,6 @@ struct NvramClass {
 Nvram *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
int base_year, int type);
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-   uint32_t io_base, uint16_t size, int base_year,
-   int type);
+   uint16_t size, int base_year, int model);
 
 #endif /* HW_M48T59_H */
diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index 6198ec1035b..93ffee801a3 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
 /* Register FPGA */
 ref405ep_fpga_init(sysmem, 0xF030);
 /* Register NVRAM */
-m48t59_init(NULL, 0xF000, 0, 8192, 1968, 8);
+m48t59_init(NULL, 0xF000, 8192, 1968, 8);
 /* Load kernel */
 linux_boot = (kernel_filename != NULL);
 if (linux_boot) {
diff --git a/hw/rtc/m48t59.c b/hw/rtc/m48t59.c
index 6525206976b..8b02c2ec558 100644
--- a/hw/rtc/m48t59.c
+++ b/hw/rtc/m48t59.c
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-   uint32_t io_base, uint16_t size, int base_year,
+   uint16_t size, int base_year,
int model)
 {
 DeviceState *dev;
@@ -584,10 +584,6 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
 s = SYS_BUS_DEVICE(dev);
 sysbus_realize_and_unref(s, _fatal);
 sysbus_connect_irq(s, 0, IRQ);
-if (io_base != 0) {
-memory_region_add_subregion(get_system_io(), io_base,
-sysbus_mmio_get_region(s, 1));
-}
 if (mem_base != 0) {
 sysbus_mmio_map(s, 0, mem_base);
 }
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 54a2b2f9ef3..20c1fa41192 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -966,7 +966,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
 create_unimplemented_device("SUNW,sx", hwdef->sx_base, 0x2000);
 }
 
-nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 1968, 8);
+nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
 slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, 
smp_cpus);
 
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index ad5ca2472a4..6854522bbfa 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -671,7 +671,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
 pci_ide_create_devs(pci_dev);
 
 /* Map NVRAM into I/O (ebus) space */
-nvram = m48t59_init(NULL, 0, 0, NVRAM_SIZE, 1968, 59);
+nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
 s = SYS_BUS_DEVICE(nvram);
 memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
 sysbus_mmio_get_region(s, 0));
-- 
2.26.2




[PATCH v2 0/2] hw/rtc/m48t59: Simplify m48t59_init()

2020-10-15 Thread Philippe Mathieu-Daudé
Since v1:
- Do not remove mem_base in patch 1 (Laurent)
- Pass MemoryRegion* (new patch)
- Run check-qtest

Philippe Mathieu-Daudé (2):
  hw/rtc/m48t59: Simplify m48t59_init() removing 'io_base' argument
  hw/rtc/m48t59: Simplify m48t59_init() passing MemoryRegion argument

 include/hw/rtc/m48t59.h |  5 ++---
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c | 14 +++---
 hw/sparc/sun4m.c|  3 ++-
 hw/sparc64/sun4u.c  |  7 ++-
 5 files changed, 10 insertions(+), 21 deletions(-)

-- 
2.26.2




Re: [PATCH v2 2/3] grackle: use qdev gpios for PCI IRQs

2020-10-15 Thread Mark Cave-Ayland

On 13/10/2020 18:05, BALATON Zoltan via wrote:


Hello,

Not related to this patch but while you're at it could you please take those patches 
that are already reviewed by you from this series as well?


http://patchwork.ozlabs.org/project/qemu-devel/list/?series=186439

That would help cleaning up my tree and see which patches still need changes. Let me 
know if these need any rebasing and point me to the tree on which I should rebase 
them. Currently they apply to your screamer branch I think.


I've queued the grackle/uninorth patches to my qemu-macppc branch, however when I try 
to apply patches from the above series git fails with the following message:


Applying: mac_oldworld: Drop a variable, use get_system_memory() directly
error: sha1 information is lacking or useless (hw/ppc/mac_oldworld.c).
error: could not build fake ancestor

Any chance you can rebase and repost? I'm happy to take patches 3 and 4, and if my 
suggestion of casting the return address via target_ulong works then I think 1 and 2 
are also fine. The I2C stuff I can't really review, and weren't there still issues 
with the SPD data in patch 8 reporting the wrong RAM size?



ATB,

Mark.



  1   2   3   4   >