[PULL 8/9] linux-user: Return void from queue_signal()

2022-01-18 Thread Laurent Vivier
From: Peter Maydell 

The linux-user queue_signal() function always returns 1, and none of
its callers check the return value.  Give it a void return type
instead.

The return value is a leftover from the old pre-2016 linux-user
signal handling code, which really did have a queue of signals and so
might return a failure indication if too many signals were queued at
once.  The current design avoids having to ever have more than one
signal queued via queue_signal() at once, so it can never fail.

Signed-off-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20220114153732.3767229-4-peter.mayd...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/signal-common.h | 4 ++--
 linux-user/signal.c| 5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h
index 42aa479080b8..2113165a7583 100644
--- a/linux-user/signal-common.h
+++ b/linux-user/signal-common.h
@@ -59,8 +59,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 
 void process_pending_signals(CPUArchState *cpu_env);
 void signal_init(void);
-int queue_signal(CPUArchState *env, int sig, int si_type,
- target_siginfo_t *info);
+void queue_signal(CPUArchState *env, int sig, int si_type,
+  target_siginfo_t *info);
 void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
 void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
 int target_to_host_signal(int sig);
diff --git a/linux-user/signal.c b/linux-user/signal.c
index bfbbeab9ad2e..32854bb3752d 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -780,8 +780,8 @@ static void QEMU_NORETURN dump_core_and_abort(int 
target_sig)
 
 /* queue a signal so that it will be send to the virtual CPU as soon
as possible */
-int queue_signal(CPUArchState *env, int sig, int si_type,
- target_siginfo_t *info)
+void queue_signal(CPUArchState *env, int sig, int si_type,
+  target_siginfo_t *info)
 {
 CPUState *cpu = env_cpu(env);
 TaskState *ts = cpu->opaque;
@@ -794,7 +794,6 @@ int queue_signal(CPUArchState *env, int sig, int si_type,
 ts->sync_signal.pending = sig;
 /* signal that a new signal is pending */
 qatomic_set(>signal_pending, 1);
-return 1; /* indicates that the signal was queued */
 }
 
 
-- 
2.34.1




[PULL 9/9] linux-user: Remove MAX_SIGQUEUE_SIZE

2022-01-18 Thread Laurent Vivier
From: Warner Losh 

It's been unused for 7 years since 907f5fddaa67 when linux-user stopped
queueing any signals.

Signed-off-by: Warner Losh 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20220116204423.16133-2-...@bsdimp.com>
Signed-off-by: Laurent Vivier 
---
 linux-user/qemu.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 5c713fa8ab26..7910ce59cc8c 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -89,8 +89,6 @@ struct vm86_saved_state {
 #include "nwfpe/fpa11.h"
 #endif
 
-#define MAX_SIGQUEUE_SIZE 1024
-
 struct emulated_sigtable {
 int pending; /* true if signal is pending */
 target_siginfo_t info;
-- 
2.34.1




[PULL 4/9] tests: Fix typo in check-help output

2022-01-18 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

Fix typo in 'make check-help' output.

Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <2022075528.22294-1-f4...@amsat.org>
Signed-off-by: Laurent Vivier 
---
 tests/Makefile.include | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 4c564cf7899e..3aba62240099 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -23,7 +23,7 @@ endif
@echo " $(MAKE) check-clean  Clean the tests and related data"
@echo
@echo "The following are useful for CI builds"
-   @echo " $(MAKE) check-build  Build most test binaris"
+   @echo " $(MAKE) check-build  Build most test binaries"
@echo " $(MAKE) get-vm-imagesDownloads all images used by 
avocado tests, according to configured targets (~350 MB each, 1.5 GB max)"
@echo
@echo
-- 
2.34.1




[PULL 6/9] linux-user: Fix comment typo in arm cpu_loop code

2022-01-18 Thread Laurent Vivier
From: Peter Maydell 

Fix a typo in a comment in the arm cpu_loop code.

Signed-off-by: Peter Maydell 
Reviewed-by: Warner Losh 
Message-Id: <20220114182535.3804783-1-peter.mayd...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/arm/cpu_loop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index f153ab503a8a..032e1ffddfbd 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -434,8 +434,8 @@ void cpu_loop(CPUARMState *env)
 case 0x6: /* Access flag fault, level 2 */
 case 0x9: /* Domain fault, level 1 */
 case 0xb: /* Domain fault, level 2 */
-case 0xd: /* Permision fault, level 1 */
-case 0xf: /* Permision fault, level 2 */
+case 0xd: /* Permission fault, level 1 */
+case 0xf: /* Permission fault, level 2 */
 si_signo = TARGET_SIGSEGV;
 si_code = TARGET_SEGV_ACCERR;
 break;
-- 
2.34.1




[PULL 3/9] qdev-core.h: Fix wrongly named reference to TYPE_SPLIT_IRQ

2022-01-18 Thread Laurent Vivier
From: Peter Maydell 

Fix a comment in qdev-core.h where we incorrectly referred
to TYPE_IRQ_SPLIT when we meant TYPE_SPLIT_IRQ.

Signed-off-by: Peter Maydell 
Message-Id: <2022072655.3546766-1-peter.mayd...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 include/hw/qdev-core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index d19c94175203..92c3d6520866 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -493,7 +493,7 @@ qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const 
char *name, int n);
  * qemu_irqs at once, or to connect multiple outbound GPIOs to the
  * same qemu_irq. (Warning: there is no assertion or other guard to
  * catch this error: the model will just not do the right thing.)
- * Instead, for fan-out you can use the TYPE_IRQ_SPLIT device: connect
+ * Instead, for fan-out you can use the TYPE_SPLIT_IRQ device: connect
  * a device's outbound GPIO to the splitter's input, and connect each
  * of the splitter's outputs to a different device.  For fan-in you
  * can use the TYPE_OR_IRQ device, which is a model of a logical OR
-- 
2.34.1




[PULL 5/9] softmmu: Provide a clue as to why device tree loading failed

2022-01-18 Thread Laurent Vivier
From: Bernhard Beschow 

fdt_open_into() obligingly returns an error code in case the operation
failed. So be obliging as well and use it in the error message.

Signed-off-by: Bernhard Beschow 
Reviewed-by: David Gibson 
Reviewed-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20220116114649.40859-1-shen...@gmail.com>
Signed-off-by: Laurent Vivier 
---
 softmmu/device_tree.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index 3965c834ca62..31d106694048 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -60,7 +60,8 @@ void *create_device_tree(int *sizep)
 }
 ret = fdt_open_into(fdt, fdt, *sizep);
 if (ret) {
-error_report("Unable to copy device tree in memory");
+error_report("%s: Unable to copy device tree into memory: %s",
+ __func__, fdt_strerror(ret));
 exit(1);
 }
 
@@ -104,7 +105,8 @@ void *load_device_tree(const char *filename_path, int 
*sizep)
 
 ret = fdt_open_into(fdt, fdt, dt_size);
 if (ret) {
-error_report("Unable to copy device tree in memory");
+error_report("%s: Unable to copy device tree into memory: %s",
+ __func__, fdt_strerror(ret));
 goto fail;
 }
 
-- 
2.34.1




[PULL 0/9] Trivial branch for 7.0 patches

2022-01-18 Thread Laurent Vivier
The following changes since commit 6621441db50d5bae7e34dbd04bf3c57a27a71b32:

  Merge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-20220115' 
into staging (2022-01-16 20:12:23 +)

are available in the Git repository at:

  https://gitlab.com/laurent_vivier/qemu.git 
tags/trivial-branch-for-7.0-pull-request

for you to fetch changes up to bfadf13f63d63d099bf2be14c9b1863f25a091a2:

  linux-user: Remove MAX_SIGQUEUE_SIZE (2022-01-18 12:44:44 +0100)


trivial patches pull request 20220118

Fix comments and typos
Add vmstate for ETRAX timers
Use ldst in megasas



Bernhard Beschow (1):
  softmmu: Provide a clue as to why device tree loading failed

Peter Maydell (4):
  qdev-core.h: Fix wrongly named reference to TYPE_SPLIT_IRQ
  linux-user: Fix comment typo in arm cpu_loop code
  linux-user: Rename user_force_sig tracepoint to match function name
  linux-user: Return void from queue_signal()

Philippe Mathieu-Daudé (3):
  hw/timer/etraxfs_timer: Add vmstate for ETRAX timers
  hw/scsi/megasas: Simplify using the ldst API
  tests: Fix typo in check-help output

Warner Losh (1):
  linux-user: Remove MAX_SIGQUEUE_SIZE

 hw/scsi/megasas.c  | 17 +++--
 hw/timer/etraxfs_timer.c   | 34 +-
 include/hw/qdev-core.h |  2 +-
 linux-user/arm/cpu_loop.c  |  4 ++--
 linux-user/qemu.h  |  2 --
 linux-user/signal-common.h |  4 ++--
 linux-user/signal.c|  7 +++
 linux-user/trace-events|  2 +-
 softmmu/device_tree.c  |  6 --
 tests/Makefile.include |  2 +-
 10 files changed, 50 insertions(+), 30 deletions(-)

-- 
2.34.1




[PULL 7/9] linux-user: Rename user_force_sig tracepoint to match function name

2022-01-18 Thread Laurent Vivier
From: Peter Maydell 

In commit c599d4d6d6e9bfdb64 in 2016 we renamed the old force_sig()
function to dump_core_and_abort(), but we forgot to rename the
associated tracepoint.  Rename the tracepoint to to match the
function it's called from.

Signed-off-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20220114153732.3767229-3-peter.mayd...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/signal.c | 2 +-
 linux-user/trace-events | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index f813b4f18e44..bfbbeab9ad2e 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -734,7 +734,7 @@ static void QEMU_NORETURN dump_core_and_abort(int 
target_sig)
 struct sigaction act;
 
 host_sig = target_to_host_signal(target_sig);
-trace_user_force_sig(env, target_sig, host_sig);
+trace_user_dump_core_and_abort(env, target_sig, host_sig);
 gdb_signalled(env, target_sig);
 
 /* dump core if supported by target binary format */
diff --git a/linux-user/trace-events b/linux-user/trace-events
index e7d2f54e9401..f33717f248af 100644
--- a/linux-user/trace-events
+++ b/linux-user/trace-events
@@ -9,7 +9,7 @@ user_setup_frame(void *env, uint64_t frame_addr) "env=%p 
frame_addr=0x%"PRIx64
 user_setup_rt_frame(void *env, uint64_t frame_addr) "env=%p 
frame_addr=0x%"PRIx64
 user_do_rt_sigreturn(void *env, uint64_t frame_addr) "env=%p 
frame_addr=0x%"PRIx64
 user_do_sigreturn(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64
-user_force_sig(void *env, int target_sig, int host_sig) "env=%p signal %d 
(host %d)"
+user_dump_core_and_abort(void *env, int target_sig, int host_sig) "env=%p 
signal %d (host %d)"
 user_handle_signal(void *env, int target_sig) "env=%p signal %d"
 user_host_signal(void *env, int host_sig, int target_sig) "env=%p signal %d 
(target %d)"
 user_queue_signal(void *env, int target_sig) "env=%p signal %d"
-- 
2.34.1




[PULL 1/9] hw/timer/etraxfs_timer: Add vmstate for ETRAX timers

2022-01-18 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

Add the vmstate for the ETRAX timers.
This is in theory a migration compatibility break
for the 'AXIS devboard 88' CRIS machine.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Richard Henderson 
Message-Id: <20211106105623.510868-1-f4...@amsat.org>
Signed-off-by: Laurent Vivier 
---
 hw/timer/etraxfs_timer.c | 34 +-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
index 4ba662190de3..139e5b86a447 100644
--- a/hw/timer/etraxfs_timer.c
+++ b/hw/timer/etraxfs_timer.c
@@ -26,6 +26,7 @@
 #include "hw/sysbus.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
+#include "migration/vmstate.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
 #include "hw/irq.h"
@@ -64,7 +65,7 @@ struct ETRAXTimerState {
 ptimer_state *ptimer_t1;
 ptimer_state *ptimer_wd;
 
-int wd_hits;
+uint32_t wd_hits;
 
 /* Control registers.  */
 uint32_t rw_tmr0_div;
@@ -83,6 +84,36 @@ struct ETRAXTimerState {
 uint32_t r_masked_intr;
 };
 
+static const VMStateDescription vmstate_etraxfs = {
+.name = "etraxfs",
+.version_id = 0,
+.minimum_version_id = 0,
+.fields = (VMStateField[]) {
+VMSTATE_PTIMER(ptimer_t0, ETRAXTimerState),
+VMSTATE_PTIMER(ptimer_t1, ETRAXTimerState),
+VMSTATE_PTIMER(ptimer_wd, ETRAXTimerState),
+
+VMSTATE_UINT32(wd_hits, ETRAXTimerState),
+
+VMSTATE_UINT32(rw_tmr0_div, ETRAXTimerState),
+VMSTATE_UINT32(r_tmr0_data, ETRAXTimerState),
+VMSTATE_UINT32(rw_tmr0_ctrl, ETRAXTimerState),
+
+VMSTATE_UINT32(rw_tmr1_div, ETRAXTimerState),
+VMSTATE_UINT32(r_tmr1_data, ETRAXTimerState),
+VMSTATE_UINT32(rw_tmr1_ctrl, ETRAXTimerState),
+
+VMSTATE_UINT32(rw_wd_ctrl, ETRAXTimerState),
+
+VMSTATE_UINT32(rw_intr_mask, ETRAXTimerState),
+VMSTATE_UINT32(rw_ack_intr, ETRAXTimerState),
+VMSTATE_UINT32(r_intr, ETRAXTimerState),
+VMSTATE_UINT32(r_masked_intr, ETRAXTimerState),
+
+VMSTATE_END_OF_LIST()
+}
+};
+
 static uint64_t
 timer_read(void *opaque, hwaddr addr, unsigned int size)
 {
@@ -357,6 +388,7 @@ static void etraxfs_timer_class_init(ObjectClass *klass, 
void *data)
 ResettableClass *rc = RESETTABLE_CLASS(klass);
 
 dc->realize = etraxfs_timer_realize;
+dc->vmsd = _etraxfs;
 rc->phases.enter = etraxfs_timer_reset_enter;
 rc->phases.hold = etraxfs_timer_reset_hold;
 }
-- 
2.34.1




[PULL 2/9] hw/scsi/megasas: Simplify using the ldst API

2022-01-18 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

This code is easier to review using the load/store API.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <20211218111912.1499377-1-phi...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 hw/scsi/megasas.c | 17 +++--
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index dc9bbdb740e7..83c321ec208a 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -383,8 +383,7 @@ static int megasas_setup_inquiry(uint8_t *cdb, int pg, int 
len)
 cdb[1] = 0x1;
 cdb[2] = pg;
 }
-cdb[3] = (len >> 8) & 0xff;
-cdb[4] = (len & 0xff);
+stw_be_p([3], len);
 return len;
 }
 
@@ -400,18 +399,8 @@ static void megasas_encode_lba(uint8_t *cdb, uint64_t lba,
 } else {
 cdb[0] = READ_16;
 }
-cdb[2] = (lba >> 56) & 0xff;
-cdb[3] = (lba >> 48) & 0xff;
-cdb[4] = (lba >> 40) & 0xff;
-cdb[5] = (lba >> 32) & 0xff;
-cdb[6] = (lba >> 24) & 0xff;
-cdb[7] = (lba >> 16) & 0xff;
-cdb[8] = (lba >> 8) & 0xff;
-cdb[9] = (lba) & 0xff;
-cdb[10] = (len >> 24) & 0xff;
-cdb[11] = (len >> 16) & 0xff;
-cdb[12] = (len >> 8) & 0xff;
-cdb[13] = (len) & 0xff;
+stq_be_p([2], lba);
+stl_be_p([2 + 8], len);
 }
 
 /*
-- 
2.34.1




Re: [PATCH] linux-user: Fix comment typo in arm cpu_loop code

2022-01-18 Thread Laurent Vivier

Le 14/01/2022 à 19:25, Peter Maydell a écrit :

Fix a typo in a comment in the arm cpu_loop code.

Signed-off-by: Peter Maydell 
---
  linux-user/arm/cpu_loop.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index f153ab503a8..032e1ffddfb 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -434,8 +434,8 @@ void cpu_loop(CPUARMState *env)
  case 0x6: /* Access flag fault, level 2 */
  case 0x9: /* Domain fault, level 1 */
  case 0xb: /* Domain fault, level 2 */
-case 0xd: /* Permision fault, level 1 */
-case 0xf: /* Permision fault, level 2 */
+case 0xd: /* Permission fault, level 1 */
+case 0xf: /* Permission fault, level 2 */
  si_signo = TARGET_SIGSEGV;
  si_code = TARGET_SEGV_ACCERR;
  break;


Applied to my trivial-patches branch.

Thanks,
Laurent



Re: [PATCH 3/3] linux-user: Return void from queue_signal()

2022-01-18 Thread Laurent Vivier

Le 14/01/2022 à 16:37, Peter Maydell a écrit :

The linux-user queue_signal() function always returns 1, and none of
its callers check the return value.  Give it a void return type
instead.

The return value is a leftover from the old pre-2016 linux-user
signal handling code, which really did have a queue of signals and so
might return a failure indication if too many signals were queued at
once.  The current design avoids having to ever have more than one
signal queued via queue_signal() at once, so it can never fail.

Signed-off-by: Peter Maydell 
---
  linux-user/signal-common.h | 4 ++--
  linux-user/signal.c| 5 ++---
  2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h
index 42aa479080b..2113165a758 100644
--- a/linux-user/signal-common.h
+++ b/linux-user/signal-common.h
@@ -59,8 +59,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
  
  void process_pending_signals(CPUArchState *cpu_env);

  void signal_init(void);
-int queue_signal(CPUArchState *env, int sig, int si_type,
- target_siginfo_t *info);
+void queue_signal(CPUArchState *env, int sig, int si_type,
+  target_siginfo_t *info);
  void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
  void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
  int target_to_host_signal(int sig);
diff --git a/linux-user/signal.c b/linux-user/signal.c
index bfbbeab9ad2..32854bb3752 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -780,8 +780,8 @@ static void QEMU_NORETURN dump_core_and_abort(int 
target_sig)
  
  /* queue a signal so that it will be send to the virtual CPU as soon

 as possible */
-int queue_signal(CPUArchState *env, int sig, int si_type,
- target_siginfo_t *info)
+void queue_signal(CPUArchState *env, int sig, int si_type,
+  target_siginfo_t *info)
  {
  CPUState *cpu = env_cpu(env);
  TaskState *ts = cpu->opaque;
@@ -794,7 +794,6 @@ int queue_signal(CPUArchState *env, int sig, int si_type,
  ts->sync_signal.pending = sig;
  /* signal that a new signal is pending */
  qatomic_set(>signal_pending, 1);
-return 1; /* indicates that the signal was queued */
  }
  
  


Applied to my trivial-patches branch.

Thanks,
Laurent



Re: [PATCH 1/2] linx-user: Remove MAX_SIGQUEUE_SIZE

2022-01-18 Thread Laurent Vivier

Le 16/01/2022 à 21:44, Warner Losh a écrit :

It's been unused for 7 years since 907f5fddaa67 when linux-user stopped
queueing any signals.

Signed-off-by: Warner Losh 
---
  linux-user/qemu.h | 2 --
  1 file changed, 2 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 5c713fa8ab2..7910ce59cc8 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -89,8 +89,6 @@ struct vm86_saved_state {
  #include "nwfpe/fpa11.h"
  #endif
  
-#define MAX_SIGQUEUE_SIZE 1024

-
  struct emulated_sigtable {
  int pending; /* true if signal is pending */
  target_siginfo_t info;


Applied to my trivial-patches branch.
(typo fixed)

Thanks,
Laurent



Re: [PATCH 2/3] linux-user: Rename user_force_sig tracepoint to match function name

2022-01-18 Thread Laurent Vivier

Le 14/01/2022 à 16:37, Peter Maydell a écrit :

In commit c599d4d6d6e9bfdb64 in 2016 we renamed the old force_sig()
function to dump_core_and_abort(), but we forgot to rename the
associated tracepoint.  Rename the tracepoint to to match the
function it's called from.

Signed-off-by: Peter Maydell 
---
  linux-user/signal.c | 2 +-
  linux-user/trace-events | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index f813b4f18e4..bfbbeab9ad2 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -734,7 +734,7 @@ static void QEMU_NORETURN dump_core_and_abort(int 
target_sig)
  struct sigaction act;
  
  host_sig = target_to_host_signal(target_sig);

-trace_user_force_sig(env, target_sig, host_sig);
+trace_user_dump_core_and_abort(env, target_sig, host_sig);
  gdb_signalled(env, target_sig);
  
  /* dump core if supported by target binary format */

diff --git a/linux-user/trace-events b/linux-user/trace-events
index e7d2f54e940..f33717f248a 100644
--- a/linux-user/trace-events
+++ b/linux-user/trace-events
@@ -9,7 +9,7 @@ user_setup_frame(void *env, uint64_t frame_addr) "env=%p 
frame_addr=0x%"PRIx64
  user_setup_rt_frame(void *env, uint64_t frame_addr) "env=%p 
frame_addr=0x%"PRIx64
  user_do_rt_sigreturn(void *env, uint64_t frame_addr) "env=%p 
frame_addr=0x%"PRIx64
  user_do_sigreturn(void *env, uint64_t frame_addr) "env=%p 
frame_addr=0x%"PRIx64
-user_force_sig(void *env, int target_sig, int host_sig) "env=%p signal %d (host 
%d)"
+user_dump_core_and_abort(void *env, int target_sig, int host_sig) "env=%p signal %d 
(host %d)"
  user_handle_signal(void *env, int target_sig) "env=%p signal %d"
  user_host_signal(void *env, int host_sig, int target_sig) "env=%p signal %d 
(target %d)"
  user_queue_signal(void *env, int target_sig) "env=%p signal %d"


Applied to my trivial-patches branch.

Thanks,
Laurent



Re: [PATCH] softmmu: Provide a clue as to why device tree loading failed

2022-01-18 Thread Laurent Vivier

Le 16/01/2022 à 12:46, Bernhard Beschow a écrit :

fdt_open_into() obligingly returns an error code in case the operation
failed. So be obliging as well and use it in the error message.

Signed-off-by: Bernhard Beschow 
---
  softmmu/device_tree.c | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index 3965c834ca..31d1066940 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -60,7 +60,8 @@ void *create_device_tree(int *sizep)
  }
  ret = fdt_open_into(fdt, fdt, *sizep);
  if (ret) {
-error_report("Unable to copy device tree in memory");
+error_report("%s: Unable to copy device tree into memory: %s",
+ __func__, fdt_strerror(ret));
  exit(1);
  }
  
@@ -104,7 +105,8 @@ void *load_device_tree(const char *filename_path, int *sizep)
  
  ret = fdt_open_into(fdt, fdt, dt_size);

  if (ret) {
-error_report("Unable to copy device tree in memory");
+error_report("%s: Unable to copy device tree into memory: %s",
+ __func__, fdt_strerror(ret));
  goto fail;
  }
  



Applied to my trivial-patches branch.

Thanks,
Laurent



[PATCH 3/3] m68k: virt: correctly set the initial PC

2022-01-15 Thread Laurent Vivier
According to QEMU parameter, set initial PC to the entry of
the loaded kernel.

Signed-off-by: Laurent Vivier 
---
 hw/m68k/virt.c | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index 78e926a55457..bbaf630bbf20 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -85,14 +85,21 @@
 #define VIRT_VIRTIO_MMIO_BASE 0xff01 /* MMIO: 0xff01 - 0xff01 
*/
 #define VIRT_VIRTIO_IRQ_BASE  PIC_IRQ(2, 1)  /* PIC: 2, 3, 4, 5, IRQ: ALL */
 
+typedef struct {
+M68kCPU *cpu;
+hwaddr initial_pc;
+hwaddr initial_stack;
+} ResetInfo;
+
 static void main_cpu_reset(void *opaque)
 {
-M68kCPU *cpu = opaque;
+ResetInfo *reset_info = opaque;
+M68kCPU *cpu = reset_info->cpu;
 CPUState *cs = CPU(cpu);
 
 cpu_reset(cs);
-cpu->env.aregs[7] = ldl_phys(cs->as, 0);
-cpu->env.pc = ldl_phys(cs->as, 4);
+cpu->env.aregs[7] = reset_info->initial_stack;
+cpu->env.pc = reset_info->initial_pc;
 }
 
 static void virt_init(MachineState *machine)
@@ -113,6 +120,7 @@ static void virt_init(MachineState *machine)
 SysBusDevice *sysbus;
 hwaddr io_base;
 int i;
+ResetInfo *reset_info;
 
 if (ram_size > 3399672 * KiB) {
 /*
@@ -124,9 +132,13 @@ static void virt_init(MachineState *machine)
 exit(1);
 }
 
+reset_info = g_malloc0(sizeof(ResetInfo));
+
 /* init CPUs */
 cpu = M68K_CPU(cpu_create(machine->cpu_type));
-qemu_register_reset(main_cpu_reset, cpu);
+
+reset_info->cpu = cpu;
+qemu_register_reset(main_cpu_reset, reset_info);
 
 /* RAM */
 memory_region_add_subregion(get_system_memory(), 0, machine->ram);
@@ -206,7 +218,7 @@ static void virt_init(MachineState *machine)
 error_report("could not load kernel '%s'", kernel_filename);
 exit(1);
 }
-stl_phys(cs->as, 4, elf_entry); /* reset initial PC */
+reset_info->initial_pc = elf_entry;
 parameters_base = (high + 1) & ~1;
 
 BOOTINFO1(cs->as, parameters_base, BI_MACHTYPE, MACH_VIRT);
-- 
2.34.1




[PATCH 2/3] hw/elf_ops: clear uninitialized segment space

2022-01-15 Thread Laurent Vivier
When the mem_size of the segment is bigger than the file_size,
and if this space doesn't overlap another segment, it needs
to be cleared.

This bug is very similar to the one we had for linux-user,
22d113b52f41 ("linux-user: Fix loading of BSS segments"),
where .bss section is encoded as an extension of the the data
one by setting the segment p_memsz > p_filesz.

Signed-off-by: Laurent Vivier 
[PMD: Use recently added address_space_set()]
Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Stefano Garzarella 
Reviewed-by: Richard Henderson 
---
 include/hw/elf_ops.h | 13 +
 hw/core/loader.c |  4 
 2 files changed, 17 insertions(+)

diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 995de8495c27..7c3b1d0f6cc5 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -555,6 +555,19 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
 if (res != MEMTX_OK) {
 goto fail;
 }
+/*
+ * We need to zero'ify the space that is not copied
+ * from file
+ */
+if (file_size < mem_size) {
+res = address_space_set(as ? as : 
_space_memory,
+addr + file_size, 0,
+mem_size - file_size,
+MEMTXATTRS_UNSPECIFIED);
+if (res != MEMTX_OK) {
+goto fail;
+}
+}
 }
 }
 
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 052a0fd7198b..19edb928e999 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -1164,9 +1164,13 @@ static void rom_reset(void *unused)
 if (rom->mr) {
 void *host = memory_region_get_ram_ptr(rom->mr);
 memcpy(host, rom->data, rom->datasize);
+memset(host + rom->datasize, 0, rom->romsize - rom->datasize);
 } else {
 address_space_write_rom(rom->as, rom->addr, MEMTXATTRS_UNSPECIFIED,
 rom->data, rom->datasize);
+address_space_set(rom->as, rom->addr + rom->datasize, 0,
+  rom->romsize - rom->datasize,
+  MEMTXATTRS_UNSPECIFIED);
 }
 if (rom->isrom) {
 /* rom needs to be written only once */
-- 
2.34.1




[PATCH 0/3] m68k: virt: fix reboot

2022-01-15 Thread Laurent Vivier
This series fixes the reboot of the virt-m68k machine
by correctly initializing the start address and fixing
the ELF kernel image.

The two first patches were already sent last year and
never merged:

https://patchwork.kernel.org/project/qemu-devel/cover/20210429141326.69245-1-laur...@vivier.eu/

Thanks,
Laurent

Laurent Vivier (2):
  hw/elf_ops: clear uninitialized segment space
  m68k: virt: correctly set the initial PC

Philippe Mathieu-Daudé (1):
  exec/memory: Extract address_space_set() from dma_memory_set()

 include/exec/memory.h | 16 
 include/hw/elf_ops.h  | 13 +
 hw/core/loader.c  |  4 
 hw/m68k/virt.c| 22 +-
 softmmu/dma-helpers.c | 15 +--
 softmmu/physmem.c | 19 +++
 6 files changed, 70 insertions(+), 19 deletions(-)

-- 
2.34.1




[PATCH 1/3] exec/memory: Extract address_space_set() from dma_memory_set()

2022-01-15 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

dma_memory_set() does a DMA barrier, set the address space with
a constant value. The constant value filling code is not specific
to DMA and can be used for AddressSpace. Extract it as a new
helper: address_space_set().

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Laurent Vivier 
Reviewed-by: Stefano Garzarella 
Reviewed-by: Richard Henderson 
[lv: rebase]
Signed-off-by: Laurent Vivier 
---
 include/exec/memory.h | 16 
 softmmu/dma-helpers.c | 15 +--
 softmmu/physmem.c | 19 +++
 3 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 20f1b27377ea..c00c50943107 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2906,6 +2906,22 @@ address_space_write_cached(MemoryRegionCache *cache, 
hwaddr addr,
 }
 }
 
+/**
+ * address_space_set: Fill address space with a constant byte.
+ *
+ * Return a MemTxResult indicating whether the operation succeeded
+ * or failed (eg unassigned memory, device rejected the transaction,
+ * IOMMU fault).
+ *
+ * @as: #AddressSpace to be accessed
+ * @addr: address within that address space
+ * @c: constant byte to fill the memory
+ * @len: the number of bytes to fill with the constant byte
+ * @attrs: memory transaction attributes
+ */
+MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
+  uint8_t c, hwaddr len, MemTxAttrs attrs);
+
 #ifdef NEED_CPU_H
 /* enum device_endian to MemOp.  */
 static inline MemOp devend_memop(enum device_endian end)
diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c
index b0be1564797f..c2028b658582 100644
--- a/softmmu/dma-helpers.c
+++ b/softmmu/dma-helpers.c
@@ -23,20 +23,7 @@ MemTxResult dma_memory_set(AddressSpace *as, dma_addr_t addr,
 {
 dma_barrier(as, DMA_DIRECTION_FROM_DEVICE);
 
-#define FILLBUF_SIZE 512
-uint8_t fillbuf[FILLBUF_SIZE];
-int l;
-MemTxResult error = MEMTX_OK;
-
-memset(fillbuf, c, FILLBUF_SIZE);
-while (len > 0) {
-l = len < FILLBUF_SIZE ? len : FILLBUF_SIZE;
-error |= address_space_write(as, addr, attrs, fillbuf, l);
-len -= l;
-addr += l;
-}
-
-return error;
+return address_space_set(as, addr, c, len, attrs);
 }
 
 void qemu_sglist_init(QEMUSGList *qsg, DeviceState *dev, int alloc_hint,
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 3524c04c2a16..dddf70edf5d2 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -2927,6 +2927,25 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr 
addr, MemTxAttrs attrs,
 }
 }
 
+MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
+  uint8_t c, hwaddr len, MemTxAttrs attrs)
+{
+#define FILLBUF_SIZE 512
+uint8_t fillbuf[FILLBUF_SIZE];
+int l;
+MemTxResult error = MEMTX_OK;
+
+memset(fillbuf, c, FILLBUF_SIZE);
+while (len > 0) {
+l = len < FILLBUF_SIZE ? len : FILLBUF_SIZE;
+error |= address_space_write(as, addr, attrs, fillbuf, l);
+len -= l;
+addr += l;
+}
+
+return error;
+}
+
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
 hwaddr len, bool is_write)
 {
-- 
2.34.1




Re: [PATCH] qdev-core.h: Fix wrongly named reference to TYPE_SPLIT_IRQ

2022-01-12 Thread Laurent Vivier

Le 11/01/2022 à 18:26, Peter Maydell a écrit :

Fix a comment in qdev-core.h where we incorrectly referred
to TYPE_IRQ_SPLIT when we meant TYPE_SPLIT_IRQ.

Signed-off-by: Peter Maydell 
---
  include/hw/qdev-core.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index d19c9417520..92c3d652086 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -493,7 +493,7 @@ qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const 
char *name, int n);
   * qemu_irqs at once, or to connect multiple outbound GPIOs to the
   * same qemu_irq. (Warning: there is no assertion or other guard to
   * catch this error: the model will just not do the right thing.)
- * Instead, for fan-out you can use the TYPE_IRQ_SPLIT device: connect
+ * Instead, for fan-out you can use the TYPE_SPLIT_IRQ device: connect
   * a device's outbound GPIO to the splitter's input, and connect each
   * of the splitter's outputs to a different device.  For fan-in you
   * can use the TYPE_OR_IRQ device, which is a model of a logical OR


Applied to my trivial-patches branch.

Thanks,
Laurent



Re: [PATCH] tests: Fix typo in check-help output

2022-01-12 Thread Laurent Vivier

Le 11/01/2022 à 18:55, Philippe Mathieu-Daudé a écrit :

Fix typo in 'make check-help' output.

Signed-off-by: Philippe Mathieu-Daudé 
---
  tests/Makefile.include | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 4c564cf7899..3aba6224009 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -23,7 +23,7 @@ endif
@echo " $(MAKE) check-clean  Clean the tests and related data"
@echo
@echo "The following are useful for CI builds"
-   @echo " $(MAKE) check-build  Build most test binaris"
+   @echo " $(MAKE) check-build  Build most test binaries"
@echo " $(MAKE) get-vm-imagesDownloads all images used by avocado 
tests, according to configured targets (~350 MB each, 1.5 GB max)"
@echo
@echo



Applied to my trivial-patches branch.

Thanks,
Laurent



Re: [PATCH] hw/timer/etraxfs_timer: Add vmstate for ETRAX timers

2022-01-12 Thread Laurent Vivier

Le 18/12/2021 à 03:28, Richard Henderson a écrit :

On 12/17/21 3:37 PM, Philippe Mathieu-Daudé wrote:

ping?

On 11/6/21 11:56, Philippe Mathieu-Daudé wrote:

Add the vmstate for the ETRAX timers.
This is in theory a migration compatibility break
for the 'AXIS devboard 88' CRIS machine.

Signed-off-by: Philippe Mathieu-Daudé 
---
  hw/timer/etraxfs_timer.c | 34 +-
  1 file changed, 33 insertions(+), 1 deletion(-)



In that it matches another similar timer device:
Reviewed-by: Richard Henderson 



+static const VMStateDescription vmstate_etraxfs = {
+    .name = "etraxfs",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .fields = (VMStateField[]) {
+    VMSTATE_PTIMER(ptimer_t0, ETRAXTimerState),
+    VMSTATE_PTIMER(ptimer_t1, ETRAXTimerState),
+    VMSTATE_PTIMER(ptimer_wd, ETRAXTimerState),
+
+    VMSTATE_UINT32(wd_hits, ETRAXTimerState),
+
+    VMSTATE_UINT32(rw_tmr0_div, ETRAXTimerState),
+    VMSTATE_UINT32(r_tmr0_data, ETRAXTimerState),
+    VMSTATE_UINT32(rw_tmr0_ctrl, ETRAXTimerState),
+
+    VMSTATE_UINT32(rw_tmr1_div, ETRAXTimerState),
+    VMSTATE_UINT32(r_tmr1_data, ETRAXTimerState),
+    VMSTATE_UINT32(rw_tmr1_ctrl, ETRAXTimerState),
+
+    VMSTATE_UINT32(rw_wd_ctrl, ETRAXTimerState),
+
+    VMSTATE_UINT32(rw_intr_mask, ETRAXTimerState),
+    VMSTATE_UINT32(rw_ack_intr, ETRAXTimerState),
+    VMSTATE_UINT32(r_intr, ETRAXTimerState),
+    VMSTATE_UINT32(r_masked_intr, ETRAXTimerState),
+
+    VMSTATE_END_OF_LIST()
+    }
+};


What I don't understand is how these controls get applied to qemu_irq after vmload, here or in any 
other device.  It seems like we should have some post_load hook that calls timer_update_irq, etc.




FWIW, in VMSTATE_PTIMER(), we use a vmstate_ptimer struct that registers a vmstate_info_timer with 
VMSTATE_TIMER_PTR(). vmstate_info_timer uses timer_get() to update or delete the timer when it is 
loaded.


Applied to my trivial-patches branch.

Thanks,
Laurent





Re: [PATCH v2] hw/scsi/megasas: Simplify using the ldst API

2022-01-12 Thread Laurent Vivier

Le 18/12/2021 à 12:19, Philippe Mathieu-Daudé a écrit :

This code is easier to review using the load/store API.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
v2: Fixed offset in megasas_setup_inquiry (rth)
---
  hw/scsi/megasas.c | 17 +++--
  1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 619b66ef0f3..9a4e9ba87e6 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -375,8 +375,7 @@ static int megasas_setup_inquiry(uint8_t *cdb, int pg, int 
len)
  cdb[1] = 0x1;
  cdb[2] = pg;
  }
-cdb[3] = (len >> 8) & 0xff;
-cdb[4] = (len & 0xff);
+stw_be_p([3], len);
  return len;
  }
  
@@ -392,18 +391,8 @@ static void megasas_encode_lba(uint8_t *cdb, uint64_t lba,

  } else {
  cdb[0] = READ_16;
  }
-cdb[2] = (lba >> 56) & 0xff;
-cdb[3] = (lba >> 48) & 0xff;
-cdb[4] = (lba >> 40) & 0xff;
-cdb[5] = (lba >> 32) & 0xff;
-cdb[6] = (lba >> 24) & 0xff;
-cdb[7] = (lba >> 16) & 0xff;
-cdb[8] = (lba >> 8) & 0xff;
-cdb[9] = (lba) & 0xff;
-cdb[10] = (len >> 24) & 0xff;
-cdb[11] = (len >> 16) & 0xff;
-cdb[12] = (len >> 8) & 0xff;
-cdb[13] = (len) & 0xff;
+stq_be_p([2], lba);
+stl_be_p([2 + 8], len);
  }
  
  /*


Applied to my trivial-patches branch.

Thanks,
Laurent



Re: [PATCH] linux-user: rt_sigprocmask, check read perms first

2022-01-11 Thread Laurent Vivier

Hi Patrick,

Le 11/01/2022 à 21:14, Patrick Venture a écrit :



On Sat, Jan 8, 2022 at 10:16 AM Laurent Vivier mailto:laur...@vivier.eu>> wrote:

Le 06/01/2022 à 23:00, Patrick Venture a écrit :
 > From: Shu-Chun Weng mailto:s...@google.com>>
 >
 > Linux kernel does it this way (checks read permission before validating 
`how`)
 > and the latest version of ABSL's `AddressIsReadable()` depends on this
 > behavior.
 >
 > c.f.

https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb9f796dcdd7/kernel/signal.c#L3147

<https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb9f796dcdd7/kernel/signal.c#L3147>
 > Reviewed-by: Patrick Venture mailto:vent...@google.com>>
 > Signed-off-by: Shu-Chun Weng mailto:s...@google.com>>
 > ---
 >   linux-user/syscall.c | 10 +-
 >   1 file changed, 5 insertions(+), 5 deletions(-)
 >
 > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
 > index ce9d64896c..3070d31f34 100644
 > --- a/linux-user/syscall.c
 > +++ b/linux-user/syscall.c
 > @@ -9491,6 +9491,11 @@ static abi_long do_syscall1(void *cpu_env, int 
num, abi_long arg1,
 >               }
 >
 >               if (arg2) {
 > +                if (!(p = lock_user(VERIFY_READ, arg2, 
sizeof(target_sigset_t), 1)))
 > +                    return -TARGET_EFAULT;
 > +                target_to_host_sigset(, p);
 > +                unlock_user(p, arg2, 0);
 > +                set_ptr = 
 >                   switch(how) {
 >                   case TARGET_SIG_BLOCK:
 >                       how = SIG_BLOCK;
 > @@ -9504,11 +9509,6 @@ static abi_long do_syscall1(void *cpu_env, int 
num, abi_long arg1,
 >                   default:
 >                       return -TARGET_EINVAL;
 >                   }
 > -                if (!(p = lock_user(VERIFY_READ, arg2, 
sizeof(target_sigset_t), 1)))
 > -                    return -TARGET_EFAULT;
 > -                target_to_host_sigset(, p);
 > -                unlock_user(p, arg2, 0);
 > -                set_ptr = 
 >               } else {
 >                   how = 0;
 >                   set_ptr = NULL;

I know it's only code move but generally we also update the style to pass 
scripts/checkpatch.pl
<http://checkpatch.pl>
successfully.


That is a reasonable request, however, can I just send a follow-on patch?  I didn't write this one 
and I honestly don't know much about it, but I don't mind doing the cleanup



Could you also update TARGET_NR_sigprocmask in the same way as it seems the 
kernel behaves like
this
too in this case?


I can take a look.  I would prefer then to also prefetch the style fixup in a preceding patch. I 
don't recall seeing whether qemu supports clang-format.




There is no problem. You can keep this patch unmodified, and add patches to fix 
the problems.

I only ask to have all the patches in one series.

Thanks,
Laurent




[PULL 30/30] linux-user: Implement capability prctls

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

This is PR_CAPBSET_READ, PR_CAPBSET_DROP and the "legacy"
PR_CAP_AMBIENT PR_GET_SECUREBITS, PR_SET_SECUREBITS.

All of these arguments are integer values only, and do not
require mapping of values between host and guest.

Signed-off-by: Richard Henderson 
Reviewed-by: Laurent Vivier 
Message-Id: <20220106225738.103012-5-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f9ae6328b53b..5950222a77e0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6504,10 +6504,15 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
 case PR_SET_UNALIGN:
 return do_prctl_set_unalign(env, arg2);
 
+case PR_CAP_AMBIENT:
+case PR_CAPBSET_READ:
+case PR_CAPBSET_DROP:
 case PR_GET_DUMPABLE:
 case PR_SET_DUMPABLE:
 case PR_GET_KEEPCAPS:
 case PR_SET_KEEPCAPS:
+case PR_GET_SECUREBITS:
+case PR_SET_SECUREBITS:
 case PR_GET_TIMING:
 case PR_SET_TIMING:
 case PR_GET_TIMERSLACK:
-- 
2.33.1




[PULL 25/30] linux-user/arm: Move target_oabi_flock64 out of target_structs.h

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Place it next to copy_from/to_user_oabi_flock64, the only users,
inside the existing target-specific ifdef.  This leaves only
generic ipc structs in target_structs.h.

Signed-off-by: Richard Henderson 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Laurent Vivier 
Message-Id: <20220107042600.149852-2-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/arm/target_structs.h | 8 
 linux-user/syscall.c| 8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/linux-user/arm/target_structs.h b/linux-user/arm/target_structs.h
index 339b070bf1a5..25bf8dd3a5c9 100644
--- a/linux-user/arm/target_structs.h
+++ b/linux-user/arm/target_structs.h
@@ -48,12 +48,4 @@ struct target_shmid_ds {
 abi_ulong __unused4;
 abi_ulong __unused5;
 };
-
-struct target_oabi_flock64 {
-abi_short l_type;
-abi_short l_whence;
-abi_llong l_start;
-abi_llong l_len;
-abi_int   l_pid;
-} QEMU_PACKED;
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce9d64896cb8..ca6e0b8fb0a1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6927,6 +6927,14 @@ typedef abi_long from_flock64_fn(struct flock64 *fl, 
abi_ulong target_addr);
 typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock64 
*fl);
 
 #if defined(TARGET_ARM) && TARGET_ABI_BITS == 32
+struct target_oabi_flock64 {
+abi_short l_type;
+abi_short l_whence;
+abi_llong l_start;
+abi_llong l_len;
+abi_int   l_pid;
+} QEMU_PACKED;
+
 static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
abi_ulong target_flock_addr)
 {
-- 
2.33.1




[PULL 16/30] target/mips: Extract break code into env->error_code

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Simplify cpu_loop by doing all of the decode in translate.

This fixes a bug in that cpu_loop was not handling the
different layout of the R6 version of break16.  This fixes
a bug in that cpu_loop extracted the wrong bits for the
mips16e break16 instruction.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-17-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/mips/cpu_loop.c| 73 +++
 target/mips/tcg/micromips_translate.c.inc |  6 +-
 target/mips/tcg/mips16e_translate.c.inc   |  2 +-
 target/mips/tcg/translate.c   | 12 +++-
 target/mips/tcg/translate.h   |  1 +
 5 files changed, 25 insertions(+), 69 deletions(-)

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 1286fbc2e0d3..9a6ab2dd986a 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -65,6 +65,7 @@ void cpu_loop(CPUMIPSState *env)
 {
 CPUState *cs = env_cpu(env);
 int trapnr, si_code;
+unsigned int code;
 abi_long ret;
 # ifdef TARGET_ABI_MIPSO32
 unsigned int syscall_num;
@@ -185,71 +186,15 @@ done_syscall:
  * handling code in arch/mips/kernel/traps.c.
  */
 case EXCP_BREAK:
-{
-abi_ulong trap_instr;
-unsigned int code;
-
-/*
- * FIXME: It would be better to decode the trap number
- * during translate, and store it in error_code while
- * raising the exception.  We should not be re-reading
- * the opcode here.
- */
-
-if (env->hflags & MIPS_HFLAG_M16) {
-if (env->insn_flags & ASE_MICROMIPS) {
-/* microMIPS mode */
-ret = get_user_u16(trap_instr, env->active_tc.PC);
-if (ret != 0) {
-goto error;
-}
-
-if ((trap_instr >> 10) == 0x11) {
-/* 16-bit instruction */
-code = trap_instr & 0xf;
-} else {
-/* 32-bit instruction */
-abi_ulong instr_lo;
-
-ret = get_user_u16(instr_lo,
-   env->active_tc.PC + 2);
-if (ret != 0) {
-goto error;
-}
-trap_instr = (trap_instr << 16) | instr_lo;
-code = ((trap_instr >> 6) & ((1 << 20) - 1));
-/* Unfortunately, microMIPS also suffers from
-   the old assembler bug...  */
-if (code >= (1 << 10)) {
-code >>= 10;
-}
-}
-} else {
-/* MIPS16e mode */
-ret = get_user_u16(trap_instr, env->active_tc.PC);
-if (ret != 0) {
-goto error;
-}
-code = (trap_instr >> 6) & 0x3f;
-}
-} else {
-ret = get_user_u32(trap_instr, env->active_tc.PC);
-if (ret != 0) {
-goto error;
-}
-
-/* As described in the original Linux kernel code, the
- * below checks on 'code' are to work around an old
- * assembly bug.
- */
-code = ((trap_instr >> 6) & ((1 << 20) - 1));
-if (code >= (1 << 10)) {
-code >>= 10;
-}
-}
-
-do_tr_or_bp(env, code, false);
+/*
+ * As described in the original Linux kernel code, the below
+ * checks on 'code' are to work around an old assembly bug.
+ */
+code = env->error_code;
+if (code >= (1 << 10)) {
+code >>= 10;
 }
+do_tr_or_bp(env, code, false);
 break;
 case EXCP_TRAP:
 {
diff --git a/target/mips/tcg/micromips_translate.c.inc 
b/target/mips/tcg/micromips_translate.c.inc
index 0760941431e1..9013f8403739 100644
--- a/target/mips/tcg/micromips_translate.c.inc
+++ b/target/mips/tcg/micromips_translate.c.inc
@@ -822,7 +822,7 @@ static void gen_pool16c_insn(DisasContext *ctx)
 gen_HILO(ctx, OPC_MFLO, 0, uMIPS_RS5(ctx->opcode));
 break;
 case BREAK16:
-gen

[PULL 26/30] linux-user: Move target_struct.h generic definitions to generic/

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Most targets share the same generic ipc structure definitions.

Signed-off-by: Richard Henderson 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Laurent Vivier 
Message-Id: <20220107042600.149852-3-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/aarch64/target_structs.h| 59 +-
 linux-user/arm/target_structs.h| 52 +--
 linux-user/cris/target_structs.h   | 59 +-
 linux-user/generic/target_structs.h| 58 +
 linux-user/hexagon/target_structs.h| 55 +---
 linux-user/i386/target_structs.h   | 59 +-
 linux-user/m68k/target_structs.h   | 59 +-
 linux-user/microblaze/target_structs.h | 59 +-
 linux-user/nios2/target_structs.h  | 59 +-
 linux-user/openrisc/target_structs.h   | 59 +-
 linux-user/riscv/target_structs.h  | 47 +---
 linux-user/sh4/target_structs.h| 59 +-
 linux-user/x86_64/target_structs.h | 36 +---
 13 files changed, 70 insertions(+), 650 deletions(-)
 create mode 100644 linux-user/generic/target_structs.h

diff --git a/linux-user/aarch64/target_structs.h 
b/linux-user/aarch64/target_structs.h
index 7c748344cabc..3a06f373c35a 100644
--- a/linux-user/aarch64/target_structs.h
+++ b/linux-user/aarch64/target_structs.h
@@ -1,58 +1 @@
-/*
- * ARM AArch64 specific structures for linux-user
- *
- * Copyright (c) 2013 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef AARCH64_TARGET_STRUCTS_H
-#define AARCH64_TARGET_STRUCTS_H
-
-struct target_ipc_perm {
-abi_int __key;  /* Key.  */
-abi_uint uid;   /* Owner's user ID.  */
-abi_uint gid;   /* Owner's group ID.  */
-abi_uint cuid;  /* Creator's user ID.  */
-abi_uint cgid;  /* Creator's group ID.  */
-abi_ushort mode;/* Read/write permission.  */
-abi_ushort __pad1;
-abi_ushort __seq;   /* Sequence number.  */
-abi_ushort __pad2;
-abi_ulong __unused1;
-abi_ulong __unused2;
-};
-
-struct target_shmid_ds {
-struct target_ipc_perm shm_perm;/* operation permission struct */
-abi_long shm_segsz; /* size of segment in bytes */
-abi_ulong shm_atime;/* time of last shmat() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused1;
-#endif
-abi_ulong shm_dtime;/* time of last shmdt() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused2;
-#endif
-abi_ulong shm_ctime;/* time of last change by shmctl() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused3;
-#endif
-abi_int shm_cpid;   /* pid of creator */
-abi_int shm_lpid;   /* pid of last shmop */
-abi_ulong shm_nattch;   /* number of current attaches */
-abi_ulong __unused4;
-abi_ulong __unused5;
-};
-
-#endif
+#include "../generic/target_structs.h"
diff --git a/linux-user/arm/target_structs.h b/linux-user/arm/target_structs.h
index 25bf8dd3a5c9..3a06f373c35a 100644
--- a/linux-user/arm/target_structs.h
+++ b/linux-user/arm/target_structs.h
@@ -1,51 +1 @@
-/*
- * ARM specific structures for linux-user
- *
- * Copyright (c) 2013 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef ARM_TARGET_STRUCTS_H
-#define ARM_TARGET_STRUCTS_H
-
-struct target_ipc_perm {
-abi_int __key;

[PULL 29/30] linux-user: Implement PR_SET_PDEATHSIG

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Signed-off-by: Richard Henderson 
Reviewed-by: Laurent Vivier 
Message-Id: <20220106225738.103012-4-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b17cfe31c8b4..f9ae6328b53b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6450,6 +6450,9 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
 }
 return ret;
 }
+case PR_SET_PDEATHSIG:
+return get_errno(prctl(PR_SET_PDEATHSIG, target_to_host_signal(arg2),
+   arg3, arg4, arg5));
 case PR_GET_NAME:
 {
 void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);
-- 
2.33.1




[PULL 28/30] linux-user: Map signal number in PR_GET_PDEATHSIG

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Convert the host signal number to guest signal number
before returning the value to the guest.

Signed-off-by: Richard Henderson 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20220106225738.103012-3-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index eff107b8bcfd..b17cfe31c8b4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6444,7 +6444,8 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
 int deathsig;
 ret = get_errno(prctl(PR_GET_PDEATHSIG, ,
   arg3, arg4, arg5));
-if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
+if (!is_error(ret) &&
+put_user_s32(host_to_target_signal(deathsig), arg2)) {
 return -TARGET_EFAULT;
 }
 return ret;
-- 
2.33.1




[PULL 27/30] linux-user: Do not special-case NULL for PR_GET_PDEATHSIG

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

The kernel does not special-case arg2 != NULL, so
neither should we.

Signed-off-by: Richard Henderson 
Reviewed-by: Laurent Vivier 
Message-Id: <20220106225738.103012-2-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ca6e0b8fb0a1..eff107b8bcfd 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6444,7 +6444,7 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
 int deathsig;
 ret = get_errno(prctl(PR_GET_PDEATHSIG, ,
   arg3, arg4, arg5));
-if (!is_error(ret) && arg2 && put_user_s32(deathsig, arg2)) {
+if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
 return -TARGET_EFAULT;
 }
 return ret;
-- 
2.33.1




[PULL 14/30] linux-user/mips: Improve do_break

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Rename to do_tr_or_bp, as per the kernel function.
Add a 'trap' argument, akin to the kernel's si_code, but clearer.
The return value is always 0, so change the return value to void.
Use force_sig and force_sig_fault.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-15-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/mips/cpu_loop.c | 46 +-
 1 file changed, 26 insertions(+), 20 deletions(-)

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 32f9fc1c1c7c..4fa24cc07452 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -40,29 +40,25 @@ enum {
 BRK_DIVZERO = 7
 };
 
-static int do_break(CPUMIPSState *env, target_siginfo_t *info,
-unsigned int code)
+static void do_tr_or_bp(CPUMIPSState *env, unsigned int code, bool trap)
 {
-int ret = -1;
+target_ulong pc = env->active_tc.PC;
 
 switch (code) {
 case BRK_OVERFLOW:
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, pc);
+break;
 case BRK_DIVZERO:
-info->si_signo = TARGET_SIGFPE;
-info->si_errno = 0;
-info->si_code = (code == BRK_OVERFLOW) ? FPE_INTOVF : FPE_INTDIV;
-queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info);
-ret = 0;
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV, pc);
 break;
 default:
-info->si_signo = TARGET_SIGTRAP;
-info->si_errno = 0;
-queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info);
-ret = 0;
+if (trap) {
+force_sig(TARGET_SIGTRAP);
+} else {
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, pc);
+}
 break;
 }
-
-return ret;
 }
 
 void cpu_loop(CPUMIPSState *env)
@@ -205,6 +201,13 @@ done_syscall:
 abi_ulong trap_instr;
 unsigned int code;
 
+/*
+ * FIXME: It would be better to decode the trap number
+ * during translate, and store it in error_code while
+ * raising the exception.  We should not be re-reading
+ * the opcode here.
+ */
+
 if (env->hflags & MIPS_HFLAG_M16) {
 if (env->insn_flags & ASE_MICROMIPS) {
 /* microMIPS mode */
@@ -257,9 +260,7 @@ done_syscall:
 }
 }
 
-if (do_break(env, , code) != 0) {
-goto error;
-}
+do_tr_or_bp(env, code, false);
 }
 break;
 case EXCP_TRAP:
@@ -267,6 +268,13 @@ done_syscall:
 abi_ulong trap_instr;
 unsigned int code = 0;
 
+/*
+ * FIXME: It would be better to decode the trap number
+ * during translate, and store it in error_code while
+ * raising the exception.  We should not be re-reading
+ * the opcode here.
+ */
+
 if (env->hflags & MIPS_HFLAG_M16) {
 /* microMIPS mode */
 abi_ulong instr[2];
@@ -293,9 +301,7 @@ done_syscall:
 }
 }
 
-if (do_break(env, , code) != 0) {
-goto error;
-}
+do_tr_or_bp(env, code, true);
 }
 break;
 case EXCP_ATOMIC:
-- 
2.33.1




[PULL 22/30] linux-user/sh4: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal. Fill in the missing PC for SIGTRAP.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-23-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/sh4/cpu_loop.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/linux-user/sh4/cpu_loop.c b/linux-user/sh4/cpu_loop.c
index 3290f6445c5f..1bd313cb19a2 100644
--- a/linux-user/sh4/cpu_loop.c
+++ b/linux-user/sh4/cpu_loop.c
@@ -28,7 +28,6 @@ void cpu_loop(CPUSH4State *env)
 {
 CPUState *cs = env_cpu(env);
 int trapnr, ret;
-target_siginfo_t info;
 
 while (1) {
 bool arch_interrupt = true;
@@ -60,10 +59,7 @@ void cpu_loop(CPUSH4State *env)
 /* just indicate that signals should be handled asap */
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
-- 
2.33.1




[PULL 23/30] linux-user/sparc: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal. Fill in the missing PC for SIGTRAP.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-24-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/sparc/cpu_loop.c | 14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 8765ab60205c..baf3d9ae011f 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -155,7 +155,6 @@ void cpu_loop (CPUSPARCState *env)
 CPUState *cs = env_cpu(env);
 int trapnr;
 abi_long ret;
-target_siginfo_t info;
 
 while (1) {
 cpu_exec_start(cs);
@@ -241,19 +240,10 @@ void cpu_loop (CPUSPARCState *env)
 /* just indicate that signals should be handled asap */
 break;
 case TT_ILL_INSN:
-{
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = TARGET_ILL_ILLOPC;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-}
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
-- 
2.33.1




[PULL 19/30] linux-user/ppc: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal.  Fill in the missing PC for SIGTRAP.
The fault address for POWERPC_EXCP_ISI is nip exactly, not nip - 4.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-20-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/ppc/cpu_loop.c | 136 --
 1 file changed, 28 insertions(+), 108 deletions(-)

diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c
index 30c82f23540a..46e6ffd6d300 100644
--- a/linux-user/ppc/cpu_loop.c
+++ b/linux-user/ppc/cpu_loop.c
@@ -76,8 +76,7 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val)
 void cpu_loop(CPUPPCState *env)
 {
 CPUState *cs = env_cpu(env);
-target_siginfo_t info;
-int trapnr;
+int trapnr, si_signo, si_code;
 target_ulong ret;
 
 for(;;) {
@@ -102,61 +101,10 @@ void cpu_loop(CPUPPCState *env)
   "Aborting\n");
 break;
 case POWERPC_EXCP_DSI:  /* Data storage exception*/
-/* XXX: check this. Seems bugged */
-switch (env->error_code & 0xFF00) {
-case 0x4000:
-case 0x4200:
-info.si_signo = TARGET_SIGSEGV;
-info.si_errno = 0;
-info.si_code = TARGET_SEGV_MAPERR;
-break;
-case 0x0400:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = TARGET_ILL_ILLADR;
-break;
-case 0x0800:
-info.si_signo = TARGET_SIGSEGV;
-info.si_errno = 0;
-info.si_code = TARGET_SEGV_ACCERR;
-break;
-default:
-/* Let's send a regular segfault... */
-EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
-  env->error_code);
-info.si_signo = TARGET_SIGSEGV;
-info.si_errno = 0;
-info.si_code = TARGET_SEGV_MAPERR;
-break;
-}
-info._sifields._sigfault._addr = env->spr[SPR_DAR];
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-break;
 case POWERPC_EXCP_ISI:  /* Instruction storage exception */
-/* XXX: check this */
-switch (env->error_code & 0xFF00) {
-case 0x4000:
-info.si_signo = TARGET_SIGSEGV;
-info.si_errno = 0;
-info.si_code = TARGET_SEGV_MAPERR;
-break;
-case 0x1000:
-case 0x0800:
-info.si_signo = TARGET_SIGSEGV;
-info.si_errno = 0;
-info.si_code = TARGET_SEGV_ACCERR;
-break;
-default:
-/* Let's send a regular segfault... */
-EXCP_DUMP(env, "Invalid segfault errno (%02x)\n",
-  env->error_code);
-info.si_signo = TARGET_SIGSEGV;
-info.si_errno = 0;
-info.si_code = TARGET_SEGV_MAPERR;
-break;
-}
-info._sifields._sigfault._addr = env->nip - 4;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+/* FIXME: handle maperr in ppc_cpu_record_sigsegv. */
+force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR,
+env->spr[SPR_DAR]);
 break;
 case POWERPC_EXCP_EXTERNAL: /* External input*/
 cpu_abort(cs, "External interrupt while in user mode. "
@@ -167,24 +115,23 @@ void cpu_loop(CPUPPCState *env)
 /* XXX: check this */
 switch (env->error_code & ~0xF) {
 case POWERPC_EXCP_FP:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
+si_signo = TARGET_SIGFPE;
 switch (env->error_code & 0xF) {
 case POWERPC_EXCP_FP_OX:
-info.si_code = TARGET_FPE_FLTOVF;
+si_code = TARGET_FPE_FLTOVF;
 break;
 case POWERPC_EXCP_FP_UX:
-info.si_code = TARGET_FPE_FLTUND;
+si_code = TARGET_FPE_FLTUND;
 break;
 case POWERPC_EXCP_FP_ZX:
 case POWERPC_EXCP_FP_VXZDZ:
-info.si_code = TARGET_FPE_FLTDIV;
+si_code = TARGET_FPE_FLTDIV;
 break;
 case POWERPC_EXCP_FP_XX:
-info.si_code = TARGET_FPE_FLTRES;
+si_code = TARGET_FPE_FLTRES;
 break;
  

[PULL 08/30] linux-user/hppa: Set FPE_CONDTRAP for COND

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

This si_code was changed in 75abf64287cab, for linux 4.17.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-9-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/hppa/cpu_loop.c | 2 ++
 linux-user/syscall_defs.h  | 1 +
 2 files changed, 3 insertions(+)

diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
index a65e1571a0cf..a576d1a249fd 100644
--- a/linux-user/hppa/cpu_loop.c
+++ b/linux-user/hppa/cpu_loop.c
@@ -156,6 +156,8 @@ void cpu_loop(CPUHPPAState *env)
 force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->iaoq_f);
 break;
 case EXCP_COND:
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_CONDTRAP, env->iaoq_f);
+break;
 case EXCP_ASSIST:
 force_sig_fault(TARGET_SIGFPE, 0, env->iaoq_f);
 break;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 510a8c1ab585..f23f0a2178f8 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -688,6 +688,7 @@ typedef struct target_siginfo {
 #define TARGET_FPE_FLTINV  (7)  /* floating point invalid operation */
 #define TARGET_FPE_FLTSUB  (8)  /* subscript out of range */
 #define TARGET_FPE_FLTUNK  (14) /* undiagnosed fp exception */
+#define TARGET_FPE_CONDTRAP(15) /* trap on condition */
 
 /*
  * SIGSEGV si_codes
-- 
2.33.1




[PULL 15/30] linux-user/mips: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal. Fill in the missing PC for SIGTRAP
and SIGFPE; use force_sig (SI_KERNEL) for EXCP_DSPDIS.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-16-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/mips/cpu_loop.c | 38 +-
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 4fa24cc07452..1286fbc2e0d3 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -64,8 +64,7 @@ static void do_tr_or_bp(CPUMIPSState *env, unsigned int code, 
bool trap)
 void cpu_loop(CPUMIPSState *env)
 {
 CPUState *cs = env_cpu(env);
-target_siginfo_t info;
-int trapnr;
+int trapnr, si_code;
 abi_long ret;
 # ifdef TARGET_ABI_MIPSO32
 unsigned int syscall_num;
@@ -156,43 +155,32 @@ done_syscall:
 break;
 case EXCP_CpU:
 case EXCP_RI:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = 0;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+case EXCP_DSPDIS:
+force_sig(TARGET_SIGILL);
 break;
 case EXCP_INTERRUPT:
 /* just indicate that signals should be handled asap */
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-break;
-case EXCP_DSPDIS:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = TARGET_ILL_ILLOPC;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT,
+env->active_tc.PC);
 break;
 case EXCP_FPE:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-info.si_code = TARGET_FPE_FLTUNK;
+si_code = TARGET_FPE_FLTUNK;
 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) {
-info.si_code = TARGET_FPE_FLTINV;
+si_code = TARGET_FPE_FLTINV;
 } else if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_DIV0) {
-info.si_code = TARGET_FPE_FLTDIV;
+si_code = TARGET_FPE_FLTDIV;
 } else if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_OVERFLOW) {
-info.si_code = TARGET_FPE_FLTOVF;
+si_code = TARGET_FPE_FLTOVF;
 } else if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_UNDERFLOW) {
-info.si_code = TARGET_FPE_FLTUND;
+si_code = TARGET_FPE_FLTUND;
 } else if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INEXACT) {
-info.si_code = TARGET_FPE_FLTRES;
+si_code = TARGET_FPE_FLTRES;
 }
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGFPE, si_code, env->active_tc.PC);
 break;
+
 /* The code below was inspired by the MIPS Linux kernel trap
  * handling code in arch/mips/kernel/traps.c.
  */
-- 
2.33.1




[PULL 24/30] linux-user/xtensa: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal. Fill in the missing PC for SIGTRAP.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-25-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/xtensa/cpu_loop.c | 26 +-
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/linux-user/xtensa/cpu_loop.c b/linux-user/xtensa/cpu_loop.c
index 6bc6d6dee6c4..d51ce053926d 100644
--- a/linux-user/xtensa/cpu_loop.c
+++ b/linux-user/xtensa/cpu_loop.c
@@ -126,7 +126,6 @@ static void xtensa_underflow12(CPUXtensaState *env)
 void cpu_loop(CPUXtensaState *env)
 {
 CPUState *cs = env_cpu(env);
-target_siginfo_t info;
 abi_ulong ret;
 int trapnr;
 
@@ -163,14 +162,12 @@ void cpu_loop(CPUXtensaState *env)
 case EXC_USER:
 switch (env->sregs[EXCCAUSE]) {
 case ILLEGAL_INSTRUCTION_CAUSE:
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,
+env->sregs[EPC1]);
+break;
 case PRIVILEGED_CAUSE:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code =
-env->sregs[EXCCAUSE] == ILLEGAL_INSTRUCTION_CAUSE ?
-TARGET_ILL_ILLOPC : TARGET_ILL_PRVOPC;
-info._sifields._sigfault._addr = env->sregs[EPC1];
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC,
+env->sregs[EPC1]);
 break;
 
 case SYSCALL_CAUSE:
@@ -219,11 +216,8 @@ void cpu_loop(CPUXtensaState *env)
 break;
 
 case INTEGER_DIVIDE_BY_ZERO_CAUSE:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-info.si_code = TARGET_FPE_INTDIV;
-info._sifields._sigfault._addr = env->sregs[EPC1];
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV,
+env->sregs[EPC1]);
 break;
 
 default:
@@ -232,10 +226,8 @@ void cpu_loop(CPUXtensaState *env)
 }
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT,
+env->sregs[EPC1]);
 break;
 case EXC_DEBUG:
 default:
-- 
2.33.1




[PULL 18/30] linux-user/openrisc: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal. Fill in the missing PC for SIGTRAP.

Reviewed-by: Stafford Horne 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-19-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/openrisc/cpu_loop.c | 18 +++---
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/linux-user/openrisc/cpu_loop.c b/linux-user/openrisc/cpu_loop.c
index 592901a68b73..7683bea0649e 100644
--- a/linux-user/openrisc/cpu_loop.c
+++ b/linux-user/openrisc/cpu_loop.c
@@ -29,7 +29,6 @@ void cpu_loop(CPUOpenRISCState *env)
 CPUState *cs = env_cpu(env);
 int trapnr;
 abi_long ret;
-target_siginfo_t info;
 
 for (;;) {
 cpu_exec_start(cs);
@@ -55,27 +54,16 @@ void cpu_loop(CPUOpenRISCState *env)
 }
 break;
 case EXCP_ALIGN:
-info.si_signo = TARGET_SIGBUS;
-info.si_errno = 0;
-info.si_code = TARGET_BUS_ADRALN;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, env->eear);
 break;
 case EXCP_ILLEGAL:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = TARGET_ILL_ILLOPC;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
 break;
 case EXCP_INTERRUPT:
 /* We processed the pending cpu work above.  */
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
-- 
2.33.1




[PULL 20/30] linux-user/riscv: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal.  Fix missing PC from EXCP_DEBUG by
merging the case with EXCP_BREAKPOINT.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-21-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/riscv/cpu_loop.c | 31 +--
 1 file changed, 5 insertions(+), 26 deletions(-)

diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c
index 0cd8985cb854..26d446f32379 100644
--- a/linux-user/riscv/cpu_loop.c
+++ b/linux-user/riscv/cpu_loop.c
@@ -30,8 +30,7 @@
 void cpu_loop(CPURISCVState *env)
 {
 CPUState *cs = env_cpu(env);
-int trapnr, signum, sigcode;
-target_ulong sigaddr;
+int trapnr;
 target_ulong ret;
 
 for (;;) {
@@ -40,10 +39,6 @@ void cpu_loop(CPURISCVState *env)
 cpu_exec_end(cs);
 process_queued_cpu_work(cs);
 
-signum = 0;
-sigcode = 0;
-sigaddr = 0;
-
 switch (trapnr) {
 case EXCP_INTERRUPT:
 /* just indicate that signals should be handled asap */
@@ -79,39 +74,23 @@ void cpu_loop(CPURISCVState *env)
 }
 break;
 case RISCV_EXCP_ILLEGAL_INST:
-signum = TARGET_SIGILL;
-sigcode = TARGET_ILL_ILLOPC;
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
 break;
 case RISCV_EXCP_BREAKPOINT:
-signum = TARGET_SIGTRAP;
-sigcode = TARGET_TRAP_BRKPT;
-sigaddr = env->pc;
+case EXCP_DEBUG:
+gdbstep:
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
 break;
 case RISCV_EXCP_SEMIHOST:
 env->gpr[xA0] = do_common_semihosting(cs);
 env->pc += 4;
 break;
-case EXCP_DEBUG:
-gdbstep:
-signum = TARGET_SIGTRAP;
-sigcode = TARGET_TRAP_BRKPT;
-break;
 default:
 EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n",
  trapnr);
 exit(EXIT_FAILURE);
 }
 
-if (signum) {
-target_siginfo_t info = {
-.si_signo = signum,
-.si_errno = 0,
-.si_code = sigcode,
-._sifields._sigfault._addr = sigaddr
-};
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-}
-
 process_pending_signals(env);
 }
 }
-- 
2.33.1




[PULL 09/30] linux-user/i386: Split out maybe_handle_vm86_trap

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Reduce the number of ifdefs within cpu_loop().

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-10-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/i386/cpu_loop.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index 9aaae93e2f5c..ac0f4e32 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -198,6 +198,17 @@ static void emulate_vsyscall(CPUX86State *env)
 }
 #endif
 
+static bool maybe_handle_vm86_trap(CPUX86State *env, int trapnr)
+{
+#ifndef TARGET_X86_64
+if (env->eflags & VM_MASK) {
+handle_vm86_trap(env, trapnr);
+return true;
+}
+#endif
+return false;
+}
+
 void cpu_loop(CPUX86State *env)
 {
 CPUState *cs = env_cpu(env);
@@ -259,12 +270,9 @@ void cpu_loop(CPUX86State *env)
 break;
 case EXCP0D_GPF:
 /* XXX: potential problem if ABI32 */
-#ifndef TARGET_X86_64
-if (env->eflags & VM_MASK) {
-handle_vm86_fault(env);
+if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-#endif
 gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
 break;
 case EXCP0E_PAGE:
@@ -274,22 +282,16 @@ void cpu_loop(CPUX86State *env)
env->cr[2]);
 break;
 case EXCP00_DIVZ:
-#ifndef TARGET_X86_64
-if (env->eflags & VM_MASK) {
-handle_vm86_trap(env, trapnr);
+if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-#endif
 gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip);
 break;
 case EXCP01_DB:
 case EXCP03_INT3:
-#ifndef TARGET_X86_64
-if (env->eflags & VM_MASK) {
-handle_vm86_trap(env, trapnr);
+if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-#endif
 if (trapnr == EXCP01_DB) {
 gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip);
 } else {
@@ -298,12 +300,9 @@ void cpu_loop(CPUX86State *env)
 break;
 case EXCP04_INTO:
 case EXCP05_BOUND:
-#ifndef TARGET_X86_64
-if (env->eflags & VM_MASK) {
-handle_vm86_trap(env, trapnr);
+if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-#endif
 gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
 break;
 case EXCP06_ILLOP:
-- 
2.33.1




[PULL 21/30] linux-user/s390x: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-22-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/s390x/cpu_loop.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c
index ad0c3cd2635d..7901dfe6f518 100644
--- a/linux-user/s390x/cpu_loop.c
+++ b/linux-user/s390x/cpu_loop.c
@@ -58,7 +58,6 @@ void cpu_loop(CPUS390XState *env)
 {
 CPUState *cs = env_cpu(env);
 int trapnr, n, sig;
-target_siginfo_t info;
 target_ulong addr;
 abi_long ret;
 
@@ -158,11 +157,7 @@ void cpu_loop(CPUS390XState *env)
  */
 env->psw.addr += env->int_pgm_ilen;
 do_signal:
-info.si_signo = sig;
-info.si_errno = 0;
-info.si_code = n;
-info._sifields._sigfault._addr = addr;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(sig, n, addr);
 break;
 
 case EXCP_ATOMIC:
-- 
2.33.1




[PULL 12/30] linux-user/microblaze: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal. Fill in the missing PC for SIGTRAP.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-13-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/microblaze/cpu_loop.c | 61 +---
 1 file changed, 25 insertions(+), 36 deletions(-)

diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_loop.c
index ff1fb26c8baf..08620d4e6899 100644
--- a/linux-user/microblaze/cpu_loop.c
+++ b/linux-user/microblaze/cpu_loop.c
@@ -27,9 +27,8 @@
 void cpu_loop(CPUMBState *env)
 {
 CPUState *cs = env_cpu(env);
-int trapnr, ret;
-target_siginfo_t info;
-
+int trapnr, ret, si_code;
+
 while (1) {
 cpu_exec_start(cs);
 trapnr = cpu_exec(cs);
@@ -38,8 +37,8 @@ void cpu_loop(CPUMBState *env)
 
 switch (trapnr) {
 case EXCP_INTERRUPT:
-  /* just indicate that signals should be handled asap */
-  break;
+/* just indicate that signals should be handled asap */
+break;
 case EXCP_SYSCALL:
 /* Return address is 4 bytes after the call.  */
 env->regs[14] += 4;
@@ -67,6 +66,7 @@ void cpu_loop(CPUMBState *env)
  */
 env->regs[14] = env->pc;
 break;
+
 case EXCP_HW_EXCP:
 env->regs[17] = env->pc + 4;
 if (env->iflags & D_FLAG) {
@@ -74,42 +74,31 @@ void cpu_loop(CPUMBState *env)
 env->pc -= 4;
 /* FIXME: if branch was immed, replay the imm as well.  */
 }
-
 env->iflags &= ~(IMM_FLAG | D_FLAG);
-
 switch (env->esr & 31) {
-case ESR_EC_DIVZERO:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-info.si_code = TARGET_FPE_FLTDIV;
-info._sifields._sigfault._addr = 0;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-break;
-case ESR_EC_FPU:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-if (env->fsr & FSR_IO) {
-info.si_code = TARGET_FPE_FLTINV;
-}
-if (env->fsr & FSR_DZ) {
-info.si_code = TARGET_FPE_FLTDIV;
-}
-info._sifields._sigfault._addr = 0;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-break;
-default:
-fprintf(stderr, "Unhandled hw-exception: 0x%x\n",
-env->esr & ESR_EC_MASK);
-cpu_dump_state(cs, stderr, 0);
-exit(EXIT_FAILURE);
-break;
+case ESR_EC_DIVZERO:
+si_code = TARGET_FPE_FLTDIV;
+break;
+case ESR_EC_FPU:
+si_code = 0;
+if (env->fsr & FSR_IO) {
+si_code = TARGET_FPE_FLTINV;
+}
+if (env->fsr & FSR_DZ) {
+si_code = TARGET_FPE_FLTDIV;
+}
+break;
+default:
+fprintf(stderr, "Unhandled hw-exception: 0x%x\n",
+env->esr & ESR_EC_MASK);
+cpu_dump_state(cs, stderr, 0);
+exit(EXIT_FAILURE);
 }
+force_sig_fault(TARGET_SIGFPE, si_code, env->pc);
 break;
+
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
-- 
2.33.1




[PULL 13/30] linux-user/microblaze: Fix SIGFPE si_codes

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Fix a typo for ESR_EC_DIVZERO, which is integral not floating-point.
Fix the if ladder for decoding floating-point exceptions.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-14-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/microblaze/cpu_loop.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_loop.c
index 08620d4e6899..1a2556be2c5f 100644
--- a/linux-user/microblaze/cpu_loop.c
+++ b/linux-user/microblaze/cpu_loop.c
@@ -77,15 +77,25 @@ void cpu_loop(CPUMBState *env)
 env->iflags &= ~(IMM_FLAG | D_FLAG);
 switch (env->esr & 31) {
 case ESR_EC_DIVZERO:
-si_code = TARGET_FPE_FLTDIV;
+si_code = TARGET_FPE_INTDIV;
 break;
 case ESR_EC_FPU:
-si_code = 0;
-if (env->fsr & FSR_IO) {
+/*
+ * Note that the kernel passes along fsr as si_code
+ * if there's no recognized bit set.  Possibly this
+ * implies that si_code is 0, but follow the structure.
+ */
+si_code = env->fsr;
+if (si_code & FSR_IO) {
 si_code = TARGET_FPE_FLTINV;
-}
-if (env->fsr & FSR_DZ) {
+} else if (si_code & FSR_OF) {
+si_code = TARGET_FPE_FLTOVF;
+} else if (si_code & FSR_UF) {
+si_code = TARGET_FPE_FLTUND;
+} else if (si_code & FSR_DZ) {
 si_code = TARGET_FPE_FLTDIV;
+} else if (si_code & FSR_DO) {
+si_code = TARGET_FPE_FLTRES;
 }
 break;
 default:
-- 
2.33.1




[PULL 04/30] linux-user/cris: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal.  Fill in the missing PC for SIGTRAP.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-5-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/cris/cpu_loop.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/linux-user/cris/cpu_loop.c b/linux-user/cris/cpu_loop.c
index 5213aebf5549..0f46b3c1a87a 100644
--- a/linux-user/cris/cpu_loop.c
+++ b/linux-user/cris/cpu_loop.c
@@ -28,8 +28,7 @@ void cpu_loop(CPUCRISState *env)
 {
 CPUState *cs = env_cpu(env);
 int trapnr, ret;
-target_siginfo_t info;
-
+
 while (1) {
 cpu_exec_start(cs);
 trapnr = cpu_exec(cs);
@@ -38,8 +37,8 @@ void cpu_loop(CPUCRISState *env)
 
 switch (trapnr) {
 case EXCP_INTERRUPT:
-  /* just indicate that signals should be handled asap */
-  break;
+/* just indicate that signals should be handled asap */
+break;
 case EXCP_BREAK:
 ret = do_syscall(env, 
  env->regs[9], 
@@ -57,10 +56,7 @@ void cpu_loop(CPUCRISState *env)
 }
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
-- 
2.33.1




[PULL 11/30] linux-user/m68k: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal. Fill in the missing PC for SIGTRAP.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-12-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/m68k/cpu_loop.c | 24 
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c
index 318159441440..928a18e3cf05 100644
--- a/linux-user/m68k/cpu_loop.c
+++ b/linux-user/m68k/cpu_loop.c
@@ -29,7 +29,6 @@ void cpu_loop(CPUM68KState *env)
 CPUState *cs = env_cpu(env);
 int trapnr;
 unsigned int n;
-target_siginfo_t info;
 
 for(;;) {
 cpu_exec_start(cs);
@@ -46,25 +45,13 @@ void cpu_loop(CPUM68KState *env)
 case EXCP_ILLEGAL:
 case EXCP_LINEA:
 case EXCP_LINEF:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = TARGET_ILL_ILLOPN;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc);
 break;
 case EXCP_CHK:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-info.si_code = TARGET_FPE_INTOVF;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->pc);
 break;
 case EXCP_DIV0:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-info.si_code = TARGET_FPE_INTDIV;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV, env->pc);
 break;
 case EXCP_TRAP0:
 {
@@ -91,10 +78,7 @@ void cpu_loop(CPUM68KState *env)
 /* just indicate that signals should be handled asap */
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
-- 
2.33.1




[PULL 17/30] target/mips: Extract trap code into env->error_code

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Simplify cpu_loop by doing all of the decode in translate.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-18-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/mips/cpu_loop.c| 41 +--
 target/mips/tcg/micromips_translate.c.inc |  4 +--
 target/mips/tcg/nanomips_translate.c.inc  |  4 +--
 target/mips/tcg/translate.c   | 24 ++---
 4 files changed, 25 insertions(+), 48 deletions(-)

diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 9a6ab2dd986a..9bb12a07ba08 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -197,51 +197,12 @@ done_syscall:
 do_tr_or_bp(env, code, false);
 break;
 case EXCP_TRAP:
-{
-abi_ulong trap_instr;
-unsigned int code = 0;
-
-/*
- * FIXME: It would be better to decode the trap number
- * during translate, and store it in error_code while
- * raising the exception.  We should not be re-reading
- * the opcode here.
- */
-
-if (env->hflags & MIPS_HFLAG_M16) {
-/* microMIPS mode */
-abi_ulong instr[2];
-
-ret = get_user_u16(instr[0], env->active_tc.PC) ||
-  get_user_u16(instr[1], env->active_tc.PC + 2);
-
-trap_instr = (instr[0] << 16) | instr[1];
-} else {
-ret = get_user_u32(trap_instr, env->active_tc.PC);
-}
-
-if (ret != 0) {
-goto error;
-}
-
-/* The immediate versions don't provide a code.  */
-if (!(trap_instr & 0xFC00)) {
-if (env->hflags & MIPS_HFLAG_M16) {
-/* microMIPS mode */
-code = ((trap_instr >> 12) & ((1 << 4) - 1));
-} else {
-code = ((trap_instr >> 6) & ((1 << 10) - 1));
-}
-}
-
-do_tr_or_bp(env, code, true);
-}
+do_tr_or_bp(env, env->error_code, true);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
 break;
 default:
-error:
 EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", 
trapnr);
 abort();
 }
diff --git a/target/mips/tcg/micromips_translate.c.inc 
b/target/mips/tcg/micromips_translate.c.inc
index 9013f8403739..fc6ede75b804 100644
--- a/target/mips/tcg/micromips_translate.c.inc
+++ b/target/mips/tcg/micromips_translate.c.inc
@@ -1047,7 +1047,7 @@ static void gen_pool32axf(CPUMIPSState *env, DisasContext 
*ctx, int rt, int rs)
 case TNE:
 mips32_op = OPC_TNE;
 do_trap:
-gen_trap(ctx, mips32_op, rs, rt, -1);
+gen_trap(ctx, mips32_op, rs, rt, -1, extract32(ctx->opcode, 12, 4));
 break;
 #ifndef CONFIG_USER_ONLY
 case MFC0:
@@ -2439,7 +2439,7 @@ static void decode_micromips32_opc(CPUMIPSState *env, 
DisasContext *ctx)
 check_insn_opc_removed(ctx, ISA_MIPS_R6);
 mips32_op = OPC_TEQI;
 do_trapi:
-gen_trap(ctx, mips32_op, rs, -1, imm);
+gen_trap(ctx, mips32_op, rs, -1, imm, 0);
 break;
 
 case BNEZC:
diff --git a/target/mips/tcg/nanomips_translate.c.inc 
b/target/mips/tcg/nanomips_translate.c.inc
index 2c022a49f244..916cece4d27e 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -1268,11 +1268,11 @@ static void gen_pool32a0_nanomips_insn(CPUMIPSState 
*env, DisasContext *ctx)
 switch (extract32(ctx->opcode, 10, 1)) {
 case NM_TEQ:
 check_nms(ctx);
-gen_trap(ctx, OPC_TEQ, rs, rt, -1);
+gen_trap(ctx, OPC_TEQ, rs, rt, -1, rd);
 break;
 case NM_TNE:
 check_nms(ctx);
-gen_trap(ctx, OPC_TNE, rs, rt, -1);
+gen_trap(ctx, OPC_TNE, rs, rt, -1, rd);
 break;
 }
 break;
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index 7f0cc81a9056..b82a7ec6ad50 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -4733,7 +4733,7 @@ static void gen_loongson_lsdc2(DisasContext *ctx, int rt,
 
 /* Traps */
 static void gen_trap(DisasContext *ctx, uint32_t opc,
- int rs, int rt, int16_t imm)
+ int rs, int rt, int16_t imm, int code)
 {
 int cond;
 TCGv t0 = tcg_temp_new();
@@ -4778,6 +4778,11 @@ static void gen_trap(DisasContext *ctx, uint32_t opc,
 case OPC_TGEU:  /* rs >

[PULL 10/30] linux-user/i386: Use force_sig, force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Replace the local gen_signal with the generic functions that match
how the kernel raises signals. Fill in the missing PC for SIGTRAP.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-11-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/i386/cpu_loop.c | 47 +++---
 1 file changed, 18 insertions(+), 29 deletions(-)

diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index ac0f4e32..29dfd7cd0c54 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -84,17 +84,6 @@ static void set_idt(int n, unsigned int dpl)
 }
 #endif
 
-static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr)
-{
-target_siginfo_t info = {
-.si_signo = sig,
-.si_code = code,
-._sifields._sigfault._addr = addr
-};
-
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-}
-
 #ifdef TARGET_X86_64
 static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len)
 {
@@ -107,7 +96,7 @@ static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, 
size_t len)
 }
 
 env->error_code = PG_ERROR_W_MASK | PG_ERROR_U_MASK;
-gen_signal(env, TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr);
+force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr);
 return false;
 }
 
@@ -193,8 +182,7 @@ static void emulate_vsyscall(CPUX86State *env)
 return;
 
  sigsegv:
-/* Like force_sig(SIGSEGV).  */
-gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
+force_sig(TARGET_SIGSEGV);
 }
 #endif
 
@@ -266,53 +254,54 @@ void cpu_loop(CPUX86State *env)
 #endif
 case EXCP0B_NOSEG:
 case EXCP0C_STACK:
-gen_signal(env, TARGET_SIGBUS, TARGET_SI_KERNEL, 0);
+force_sig(TARGET_SIGBUS);
 break;
 case EXCP0D_GPF:
 /* XXX: potential problem if ABI32 */
 if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
+force_sig(TARGET_SIGSEGV);
 break;
 case EXCP0E_PAGE:
-gen_signal(env, TARGET_SIGSEGV,
-   (env->error_code & 1 ?
-TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR),
-   env->cr[2]);
+force_sig_fault(TARGET_SIGSEGV,
+(env->error_code & PG_ERROR_P_MASK ?
+ TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR),
+env->cr[2]);
 break;
 case EXCP00_DIVZ:
 if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip);
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip);
 break;
 case EXCP01_DB:
-case EXCP03_INT3:
 if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-if (trapnr == EXCP01_DB) {
-gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip);
-} else {
-gen_signal(env, TARGET_SIGTRAP, TARGET_SI_KERNEL, 0);
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip);
+break;
+case EXCP03_INT3:
+if (maybe_handle_vm86_trap(env, trapnr)) {
+break;
 }
+force_sig(TARGET_SIGTRAP);
 break;
 case EXCP04_INTO:
 case EXCP05_BOUND:
 if (maybe_handle_vm86_trap(env, trapnr)) {
 break;
 }
-gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0);
+force_sig(TARGET_SIGSEGV);
 break;
 case EXCP06_ILLOP:
-gen_signal(env, TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip);
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip);
 break;
 case EXCP_INTERRUPT:
 /* just indicate that signals should be handled asap */
 break;
 case EXCP_DEBUG:
-gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0);
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip);
 break;
 case EXCP_ATOMIC:
 cpu_exec_step_atomic(cs);
-- 
2.33.1




[PULL 06/30] linux-user/hppa: Use the proper si_code for PRIV_OPR, PRIV_REG, OVERFLOW

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

These si_codes have been properly set by the kernel since the beginning.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-7-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/hppa/cpu_loop.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
index 4740da1b7a30..a65e1571a0cf 100644
--- a/linux-user/hppa/cpu_loop.c
+++ b/linux-user/hppa/cpu_loop.c
@@ -144,11 +144,17 @@ void cpu_loop(CPUHPPAState *env)
 env->iaoq_b = env->gr[31] + 4;
 break;
 case EXCP_ILL:
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
+break;
 case EXCP_PRIV_OPR:
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->iaoq_f);
+break;
 case EXCP_PRIV_REG:
-force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVREG, env->iaoq_f);
 break;
 case EXCP_OVERFLOW:
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->iaoq_f);
+break;
 case EXCP_COND:
 case EXCP_ASSIST:
 force_sig_fault(TARGET_SIGFPE, 0, env->iaoq_f);
-- 
2.33.1




[PULL 03/30] linux-user/alpha: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-4-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/alpha/cpu_loop.c | 61 -
 1 file changed, 19 insertions(+), 42 deletions(-)

diff --git a/linux-user/alpha/cpu_loop.c b/linux-user/alpha/cpu_loop.c
index caeea97b9d96..de6e0c901cdf 100644
--- a/linux-user/alpha/cpu_loop.c
+++ b/linux-user/alpha/cpu_loop.c
@@ -27,8 +27,7 @@
 void cpu_loop(CPUAlphaState *env)
 {
 CPUState *cs = env_cpu(env);
-int trapnr;
-target_siginfo_t info;
+int trapnr, si_code;
 abi_long sysret;
 
 while (1) {
@@ -56,18 +55,10 @@ void cpu_loop(CPUAlphaState *env)
 break;
 case EXCP_OPCDEC:
 do_sigill:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = TARGET_ILL_ILLOPC;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
 break;
 case EXCP_ARITH:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-info.si_code = TARGET_FPE_FLTINV;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGFPE, TARGET_FPE_FLTINV, env->pc);
 break;
 case EXCP_FEN:
 /* No-op.  Linux simply re-enables the FPU.  */
@@ -76,20 +67,10 @@ void cpu_loop(CPUAlphaState *env)
 switch (env->error_code) {
 case 0x80:
 /* BPT */
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-break;
+goto do_sigtrap_brkpt;
 case 0x81:
 /* BUGCHK */
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_UNK;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
-break;
+goto do_sigtrap_unk;
 case 0x83:
 /* CALLSYS */
 trapnr = env->ir[IR_V0];
@@ -130,47 +111,43 @@ void cpu_loop(CPUAlphaState *env)
 abort();
 case 0xAA:
 /* GENTRAP */
-info.si_signo = TARGET_SIGFPE;
 switch (env->ir[IR_A0]) {
 case TARGET_GEN_INTOVF:
-info.si_code = TARGET_FPE_INTOVF;
+si_code = TARGET_FPE_INTOVF;
 break;
 case TARGET_GEN_INTDIV:
-info.si_code = TARGET_FPE_INTDIV;
+si_code = TARGET_FPE_INTDIV;
 break;
 case TARGET_GEN_FLTOVF:
-info.si_code = TARGET_FPE_FLTOVF;
+si_code = TARGET_FPE_FLTOVF;
 break;
 case TARGET_GEN_FLTUND:
-info.si_code = TARGET_FPE_FLTUND;
+si_code = TARGET_FPE_FLTUND;
 break;
 case TARGET_GEN_FLTINV:
-info.si_code = TARGET_FPE_FLTINV;
+si_code = TARGET_FPE_FLTINV;
 break;
 case TARGET_GEN_FLTINE:
-info.si_code = TARGET_FPE_FLTRES;
+si_code = TARGET_FPE_FLTRES;
 break;
 case TARGET_GEN_ROPRAND:
-info.si_code = TARGET_FPE_FLTUNK;
+si_code = TARGET_FPE_FLTUNK;
 break;
 default:
-info.si_signo = TARGET_SIGTRAP;
-info.si_code = TARGET_TRAP_UNK;
-break;
+goto do_sigtrap_unk;
 }
-info.si_errno = 0;
-info._sifields._sigfault._addr = env->pc;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGFPE, si_code, env->pc);
 break;
 default:
 goto do_sigill;
 }
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+do_sigtrap_brkpt:
+force_sig_fault(TARGET_SIGTRAP, TARGET_T

[PULL 02/30] linux-user/alpha: Set FPE_FLTUNK for gentrap ROPRAND

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

This si_code was changed in 4cc13e4f6d441, for linux 4.17.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-3-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/alpha/cpu_loop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/alpha/cpu_loop.c b/linux-user/alpha/cpu_loop.c
index 96466b23f969..caeea97b9d96 100644
--- a/linux-user/alpha/cpu_loop.c
+++ b/linux-user/alpha/cpu_loop.c
@@ -151,7 +151,7 @@ void cpu_loop(CPUAlphaState *env)
 info.si_code = TARGET_FPE_FLTRES;
 break;
 case TARGET_GEN_ROPRAND:
-info.si_code = 0;
+info.si_code = TARGET_FPE_FLTUNK;
 break;
 default:
 info.si_signo = TARGET_SIGTRAP;
-- 
2.33.1




[PULL 07/30] linux-user: Remove TARGET_NSIGFPE

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

This define is unused, and we have no similar define for
the other signal sub-codes.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-8-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall_defs.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 18bed558fe6b..510a8c1ab585 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -688,7 +688,6 @@ typedef struct target_siginfo {
 #define TARGET_FPE_FLTINV  (7)  /* floating point invalid operation */
 #define TARGET_FPE_FLTSUB  (8)  /* subscript out of range */
 #define TARGET_FPE_FLTUNK  (14) /* undiagnosed fp exception */
-#define TARGET_NSIGFPE 15
 
 /*
  * SIGSEGV si_codes
-- 
2.33.1




[PULL 01/30] linux-user/alpha: Set TRAP_UNK for bugchk and unknown gentrap

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

These si_codes were changed in 535906c684fca, for linux 4.17.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-2-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/alpha/cpu_loop.c | 4 ++--
 linux-user/syscall_defs.h   | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/linux-user/alpha/cpu_loop.c b/linux-user/alpha/cpu_loop.c
index 37c33f0ccd07..96466b23f969 100644
--- a/linux-user/alpha/cpu_loop.c
+++ b/linux-user/alpha/cpu_loop.c
@@ -86,7 +86,7 @@ void cpu_loop(CPUAlphaState *env)
 /* BUGCHK */
 info.si_signo = TARGET_SIGTRAP;
 info.si_errno = 0;
-info.si_code = 0;
+info.si_code = TARGET_TRAP_UNK;
 info._sifields._sigfault._addr = env->pc;
 queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
 break;
@@ -155,7 +155,7 @@ void cpu_loop(CPUAlphaState *env)
 break;
 default:
 info.si_signo = TARGET_SIGTRAP;
-info.si_code = 0;
+info.si_code = TARGET_TRAP_UNK;
 break;
 }
 info.si_errno = 0;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index cca561f62268..18bed558fe6b 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -715,6 +715,7 @@ typedef struct target_siginfo {
 #define TARGET_TRAP_TRACE  (2) /* process trace trap */
 #define TARGET_TRAP_BRANCH  (3) /* process taken branch trap */
 #define TARGET_TRAP_HWBKPT  (4) /* hardware breakpoint/watchpoint */
+#define TARGET_TRAP_UNK (5) /* undiagnosed trap */
 
 struct target_rlimit {
 abi_ulong   rlim_cur;
-- 
2.33.1




[PULL 05/30] linux-user/hppa: Use force_sig_fault

2022-01-11 Thread Laurent Vivier
From: Richard Henderson 

Use the new function instead of setting up a target_siginfo_t
and calling queue_signal.  Fill in the missing PC for SIGTRAP
and missing si_code for SIGBUS.

Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20220107213243.212806-6-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/hppa/cpu_loop.c | 18 +++---
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
index a47a63176b26..4740da1b7a30 100644
--- a/linux-user/hppa/cpu_loop.c
+++ b/linux-user/hppa/cpu_loop.c
@@ -110,7 +110,6 @@ static abi_ulong hppa_lws(CPUHPPAState *env)
 void cpu_loop(CPUHPPAState *env)
 {
 CPUState *cs = env_cpu(env);
-target_siginfo_t info;
 abi_ulong ret;
 int trapnr;
 
@@ -147,26 +146,15 @@ void cpu_loop(CPUHPPAState *env)
 case EXCP_ILL:
 case EXCP_PRIV_OPR:
 case EXCP_PRIV_REG:
-info.si_signo = TARGET_SIGILL;
-info.si_errno = 0;
-info.si_code = TARGET_ILL_ILLOPN;
-info._sifields._sigfault._addr = env->iaoq_f;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
 break;
 case EXCP_OVERFLOW:
 case EXCP_COND:
 case EXCP_ASSIST:
-info.si_signo = TARGET_SIGFPE;
-info.si_errno = 0;
-info.si_code = 0;
-info._sifields._sigfault._addr = env->iaoq_f;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGFPE, 0, env->iaoq_f);
 break;
 case EXCP_DEBUG:
-info.si_signo = TARGET_SIGTRAP;
-info.si_errno = 0;
-info.si_code = TARGET_TRAP_BRKPT;
-queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
+force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->iaoq_f);
 break;
 case EXCP_INTERRUPT:
 /* just indicate that signals should be handled asap */
-- 
2.33.1




[PULL 00/30] Linux user for 7.0 patches

2022-01-11 Thread Laurent Vivier
The following changes since commit 64c01c7da449bcafc614b27ecf1325bb08031c84:

  Merge remote-tracking branch 'remotes/philmd/tags/sdmmc-20220108' into 
staging (2022-01-11 11:39:31 +)

are available in the Git repository at:

  https://gitlab.com/laurent_vivier/qemu.git 
tags/linux-user-for-7.0-pull-request

for you to fetch changes up to 4f4e5567f856d9b841494b3b5216a37d2952ee54:

  linux-user: Implement capability prctls (2022-01-11 18:40:44 +0100)


linux-user pull request 20220111
siginfo_t cleanup
more prtctl() update
target_struct.h cleanup



Richard Henderson (30):
  linux-user/alpha: Set TRAP_UNK for bugchk and unknown gentrap
  linux-user/alpha: Set FPE_FLTUNK for gentrap ROPRAND
  linux-user/alpha: Use force_sig_fault
  linux-user/cris: Use force_sig_fault
  linux-user/hppa: Use force_sig_fault
  linux-user/hppa: Use the proper si_code for PRIV_OPR, PRIV_REG,
OVERFLOW
  linux-user: Remove TARGET_NSIGFPE
  linux-user/hppa: Set FPE_CONDTRAP for COND
  linux-user/i386: Split out maybe_handle_vm86_trap
  linux-user/i386: Use force_sig, force_sig_fault
  linux-user/m68k: Use force_sig_fault
  linux-user/microblaze: Use force_sig_fault
  linux-user/microblaze: Fix SIGFPE si_codes
  linux-user/mips: Improve do_break
  linux-user/mips: Use force_sig_fault
  target/mips: Extract break code into env->error_code
  target/mips: Extract trap code into env->error_code
  linux-user/openrisc: Use force_sig_fault
  linux-user/ppc: Use force_sig_fault
  linux-user/riscv: Use force_sig_fault
  linux-user/s390x: Use force_sig_fault
  linux-user/sh4: Use force_sig_fault
  linux-user/sparc: Use force_sig_fault
  linux-user/xtensa: Use force_sig_fault
  linux-user/arm: Move target_oabi_flock64 out of target_structs.h
  linux-user: Move target_struct.h generic definitions to generic/
  linux-user: Do not special-case NULL for PR_GET_PDEATHSIG
  linux-user: Map signal number in PR_GET_PDEATHSIG
  linux-user: Implement PR_SET_PDEATHSIG
  linux-user: Implement capability prctls

 linux-user/aarch64/target_structs.h   |  59 +---
 linux-user/alpha/cpu_loop.c   |  61 +++-
 linux-user/arm/target_structs.h   |  60 +---
 linux-user/cris/cpu_loop.c|  12 +-
 linux-user/cris/target_structs.h  |  59 +---
 linux-user/generic/target_structs.h   |  58 
 linux-user/hexagon/target_structs.h   |  55 +--
 linux-user/hppa/cpu_loop.c|  26 ++--
 linux-user/i386/cpu_loop.c|  78 +-
 linux-user/i386/target_structs.h  |  59 +---
 linux-user/m68k/cpu_loop.c|  24 +---
 linux-user/m68k/target_structs.h  |  59 +---
 linux-user/microblaze/cpu_loop.c  |  71 +
 linux-user/microblaze/target_structs.h|  59 +---
 linux-user/mips/cpu_loop.c| 166 +-
 linux-user/nios2/target_structs.h |  59 +---
 linux-user/openrisc/cpu_loop.c|  18 +--
 linux-user/openrisc/target_structs.h  |  59 +---
 linux-user/ppc/cpu_loop.c | 136 --
 linux-user/riscv/cpu_loop.c   |  31 +---
 linux-user/riscv/target_structs.h |  47 +-
 linux-user/s390x/cpu_loop.c   |   7 +-
 linux-user/sh4/cpu_loop.c |   6 +-
 linux-user/sh4/target_structs.h   |  59 +---
 linux-user/sparc/cpu_loop.c   |  14 +-
 linux-user/syscall.c  |  19 ++-
 linux-user/syscall_defs.h |   3 +-
 linux-user/x86_64/target_structs.h|  36 +
 linux-user/xtensa/cpu_loop.c  |  26 ++--
 target/mips/tcg/micromips_translate.c.inc |  10 +-
 target/mips/tcg/mips16e_translate.c.inc   |   2 +-
 target/mips/tcg/nanomips_translate.c.inc  |   4 +-
 target/mips/tcg/translate.c   |  36 -
 target/mips/tcg/translate.h   |   1 +
 34 files changed, 318 insertions(+), 1161 deletions(-)
 create mode 100644 linux-user/generic/target_structs.h

-- 
2.33.1




Re: [PATCH v2] linux-user: Fix clang warning for nios2-linux-user code

2022-01-11 Thread Laurent Vivier

Le 11/01/2022 à 09:29, Peter Maydell a écrit :

The clang in Ubuntu 18.04 (10.0.0-4ubuntu1) produces a warning
on the code added in commit f5ef0e518d03 where we use a
shifted expression in a boolean context:

../../linux-user/elfload.c:2423:16: error: converting the result of '<<' to a 
boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
 } else if (LO_COMMPAGE) {
^
../../linux-user/elfload.c:1102:22: note: expanded from macro 'LO_COMMPAGE'
#define LO_COMMPAGE  TARGET_PAGE_SIZE
  ^
/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/exec/cpu-all.h:231:31: note: 
expanded from macro 'TARGET_PAGE_SIZE'
#define TARGET_PAGE_SIZE   (1 << TARGET_PAGE_BITS)
   ^
1 error generated.

The warning is bogus because whether LO_COMMPAGE is zero or not
depends on compile-time ifdefs; shut the compiler up by adding
an explicit comparison to zero.

Fixes: f5ef0e518d0331 ("linux-user/nios2: Map a real kuser page")
Signed-off-by: Peter Maydell 
---
v1->v2: fix sense of comparison (oops!)

  linux-user/elfload.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 329b2375ef1..d3274edfdb7 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2420,7 +2420,7 @@ static void pgb_static(const char *image_name, abi_ulong 
orig_loaddr,
  } else {
  offset = -(HI_COMMPAGE & -align);
  }
-} else if (LO_COMMPAGE) {
+} else if (LO_COMMPAGE != 0) {
  loaddr = MIN(loaddr, LO_COMMPAGE & -align);
  }
  


Reviewed-by: Laurent Vivier 



Re: [PATCH] linux-user: Fix clang warning for nios2-linux-user code

2022-01-10 Thread Laurent Vivier

Le 10/01/2022 à 20:17, Peter Maydell a écrit :

The clang in Ubuntu 18.04 (10.0.0-4ubuntu1) produces a warning
on the code added in commit f5ef0e518d03 where we use a
shifted expression in a boolean context:

../../linux-user/elfload.c:2423:16: error: converting the result of '<<' to a 
boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
 } else if (LO_COMMPAGE) {
^
../../linux-user/elfload.c:1102:22: note: expanded from macro 'LO_COMMPAGE'
#define LO_COMMPAGE  TARGET_PAGE_SIZE
  ^
/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/exec/cpu-all.h:231:31: note: 
expanded from macro 'TARGET_PAGE_SIZE'
#define TARGET_PAGE_SIZE   (1 << TARGET_PAGE_BITS)
   ^
1 error generated.

The warning is bogus because whether LO_COMMPAGE is zero or not
depends on compile-time ifdefs; shut the compiler up by adding
an explicit comparison to zero.

Fixes: f5ef0e518d0331 ("linux-user/nios2: Map a real kuser page")
Signed-off-by: Peter Maydell 
---
I'm probably going to apply this directly once it's reviewed, because
it fixes a build-break on one of my machines.

  linux-user/elfload.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 329b2375ef1..2993b01e60c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2420,7 +2420,7 @@ static void pgb_static(const char *image_name, abi_ulong 
orig_loaddr,
  } else {
  offset = -(HI_COMMPAGE & -align);
  }
-} else if (LO_COMMPAGE) {
+} else if (LO_COMMPAGE == 0) {


It seems to revert the logic should it be "(LO_COMMPAGE != 0)"?

Thanks,
Laurent

  loaddr = MIN(loaddr, LO_COMMPAGE & -align);
  }
  





[PULL 2/4] q800: fix segfault with invalid MacROM

2022-01-09 Thread Laurent Vivier
"qemu-system-m68k -M q800 -bios /dev/null" crashes with a segfault
in q800_init().
This happens because the code doesn't check that rom_ptr() returned
a non-NULL pointer .

To avoid NULL pointer, don't allow 0 sized file and use bios_size with
rom_ptr().

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
Reported-by: Peter Maydell 
Signed-off-by: Laurent Vivier 
Reviewed-by: Thomas Huth 
Reviewed-by: Mark Cave-Ayland 
Message-Id: <20220107105049.961489-1-laur...@vivier.eu>
Signed-off-by: Laurent Vivier 
---
 hw/m68k/q800.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index e4c7c9b88ad0..55dfe5036f40 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -672,12 +672,13 @@ static void q800_init(MachineState *machine)
 
 /* Remove qtest_enabled() check once firmware files are in the tree */
 if (!qtest_enabled()) {
-if (bios_size < 0 || bios_size > MACROM_SIZE) {
+if (bios_size <= 0 || bios_size > MACROM_SIZE) {
 error_report("could not load MacROM '%s'", bios_name);
 exit(1);
 }
 
-ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
+ptr = rom_ptr(MACROM_ADDR, bios_size);
+assert(ptr != NULL);
 stl_phys(cs->as, 0, ldl_p(ptr));/* reset initial SP */
 stl_phys(cs->as, 4,
  MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */
-- 
2.33.1




[PULL 4/4] target/m68k: don't word align SP in stack frame if M68K_FEATURE_UNALIGNED_DATA feature enabled

2022-01-09 Thread Laurent Vivier
From: Mark Cave-Ayland 

Commit a9431a03f7 ("target/m68k: add M68K_FEATURE_UNALIGNED_DATA feature") added
a new feature for processors from the 68020 onwards which do not require data
accesses to be word aligned.

Unfortunately the original commit missed an additional case whereby the SP is
still word aligned when setting up an additional format 1 stack frame so add the
necessary M68K_FEATURE_UNALIGNED_DATA feature guard.

Signed-off-by: Mark Cave-Ayland 
Fixes: a9431a03f7 ("target/m68k: add M68K_FEATURE_UNALIGNED_DATA feature")
Reviewed-by: Laurent Vivier 
Message-Id: <20220108180453.18680-1-mark.cave-ayl...@ilande.co.uk>
Signed-off-by: Laurent Vivier 
---
 target/m68k/op_helper.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c
index c0f4825034ae..acbd4735154e 100644
--- a/target/m68k/op_helper.c
+++ b/target/m68k/op_helper.c
@@ -415,7 +415,10 @@ static void m68k_interrupt_all(CPUM68KState *env, int 
is_hw)
 oldsr = sr;
 env->aregs[7] = sp;
 cpu_m68k_set_sr(env, sr &= ~SR_M);
-sp = env->aregs[7] & ~1;
+sp = env->aregs[7];
+if (!m68k_feature(env, M68K_FEATURE_UNALIGNED_DATA)) {
+sp &= ~1;
+}
 do_stack_frame(env, , 1, oldsr, 0, retaddr);
 } else {
 do_stack_frame(env, , 0, oldsr, 0, retaddr);
-- 
2.33.1




[PULL 3/4] macfb: fix VRAM dirty memory region logging

2022-01-09 Thread Laurent Vivier
From: Mark Cave-Ayland 

The macfb VRAM memory region was configured with coalescing rather than dirty
memory logging enabled, causing some areas of the screen not to redraw after
a full screen update.

Signed-off-by: Mark Cave-Ayland 
Fixes: 8ac919a065 ("hw/m68k: add Nubus macfb video card")
Reviewed-by: Laurent Vivier 
Message-Id: <20220108164147.30813-1-mark.cave-ayl...@ilande.co.uk>
Signed-off-by: Laurent Vivier 
---
 hw/display/macfb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/display/macfb.c b/hw/display/macfb.c
index 277d3e663331..4bd7c3ad6a5a 100644
--- a/hw/display/macfb.c
+++ b/hw/display/macfb.c
@@ -661,9 +661,9 @@ static bool macfb_common_realize(DeviceState *dev, 
MacfbState *s, Error **errp)
 
 memory_region_init_ram(>mem_vram, OBJECT(dev), "macfb-vram",
MACFB_VRAM_SIZE, _abort);
+memory_region_set_log(>mem_vram, true, DIRTY_MEMORY_VGA);
 s->vram = memory_region_get_ram_ptr(>mem_vram);
 s->vram_bit_mask = MACFB_VRAM_SIZE - 1;
-memory_region_set_coalescing(>mem_vram);
 
 s->vbl_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, macfb_vbl_timer, s);
 macfb_update_mode(s);
-- 
2.33.1




[PULL 1/4] hw: m68k: Add virt compat machine type for 7.0

2022-01-09 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
Reviewed-by: Thomas Huth 
Reviewed-by: Cornelia Huck 
Message-Id: <20211218114340.1856757-1-laur...@vivier.eu>
---
 hw/m68k/virt.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index 0efa4a45c7f4..78e926a55457 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -304,10 +304,17 @@ type_init(virt_machine_register_types)
 } \
 type_init(machvirt_machine_##major##_##minor##_init);
 
+static void virt_machine_7_0_options(MachineClass *mc)
+{
+}
+DEFINE_VIRT_MACHINE(7, 0, true)
+
 static void virt_machine_6_2_options(MachineClass *mc)
 {
+virt_machine_7_0_options(mc);
+compat_props_add(mc->compat_props, hw_compat_6_2, hw_compat_6_2_len);
 }
-DEFINE_VIRT_MACHINE(6, 2, true)
+DEFINE_VIRT_MACHINE(6, 2, false)
 
 static void virt_machine_6_1_options(MachineClass *mc)
 {
-- 
2.33.1




[PULL 0/4] M68k for 7.0 patches

2022-01-09 Thread Laurent Vivier
The following changes since commit df722e33d5da26ea8604500ca8f509245a0ea524:

  Merge tag 'bsd-user-arm-pull-request' of gitlab.com:bsdimp/qemu into staging 
(2022-01-08 09:37:59 -0800)

are available in the Git repository at:

  git://github.com/vivier/qemu-m68k.git tags/m68k-for-7.0-pull-request

for you to fetch changes up to 31144eb6393b66b06a13e8a6ad0e730f9e82d4c6:

  target/m68k: don't word align SP in stack frame if 
M68K_FEATURE_UNALIGNED_DATA feature enabled (2022-01-09 12:05:02 +0100)


M68k pull request 20220109

Add virt compat machine type for 7.0
fix q800 -bios parameter
fix VRAM refresh
fix M68K_FEATURE_UNALIGNED_DATA feature



Laurent Vivier (2):
  hw: m68k: Add virt compat machine type for 7.0
  q800: fix segfault with invalid MacROM

Mark Cave-Ayland (2):
  macfb: fix VRAM dirty memory region logging
  target/m68k: don't word align SP in stack frame if
M68K_FEATURE_UNALIGNED_DATA feature enabled

 hw/display/macfb.c  | 2 +-
 hw/m68k/q800.c  | 5 +++--
 hw/m68k/virt.c  | 9 -
 target/m68k/op_helper.c | 5 -
 4 files changed, 16 insertions(+), 5 deletions(-)

-- 
2.33.1




Re: [PATCH] target/m68k: don't word align SP in stack frame if M68K_FEATURE_UNALIGNED_DATA feature enabled

2022-01-08 Thread Laurent Vivier

Le 08/01/2022 à 19:04, Mark Cave-Ayland a écrit :

Commit a9431a03f7 ("target/m68k: add M68K_FEATURE_UNALIGNED_DATA feature") added
a new feature for processors from the 68020 onwards which do not require data
accesses to be word aligned.

Unfortunately the original commit missed an additional case whereby the SP is
still word aligned when setting up an additional format 1 stack frame so add the
necessary M68K_FEATURE_UNALIGNED_DATA feature guard.

Signed-off-by: Mark Cave-Ayland 
Fixes: a9431a03f7 ("target/m68k: add M68K_FEATURE_UNALIGNED_DATA feature")
---
  target/m68k/op_helper.c | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c
index ab6b559fd3..59d8d5a09e 100644
--- a/target/m68k/op_helper.c
+++ b/target/m68k/op_helper.c
@@ -429,7 +429,10 @@ static void m68k_interrupt_all(CPUM68KState *env, int 
is_hw)
  oldsr = sr;
  env->aregs[7] = sp;
  cpu_m68k_set_sr(env, sr &= ~SR_M);
-sp = env->aregs[7] & ~1;
+sp = env->aregs[7];
+if (!m68k_feature(env, M68K_FEATURE_UNALIGNED_DATA)) {
+sp &= ~1;
+}
  do_stack_frame(env, , 1, oldsr, 0, retaddr);
  } else {
  do_stack_frame(env, , 0, oldsr, 0, retaddr);


Reviewed-by: Laurent Vivier 



Re: [PATCH] linux-user: rt_sigprocmask, check read perms first

2022-01-08 Thread Laurent Vivier

Le 06/01/2022 à 23:00, Patrick Venture a écrit :

From: Shu-Chun Weng 

Linux kernel does it this way (checks read permission before validating `how`)
and the latest version of ABSL's `AddressIsReadable()` depends on this
behavior.

c.f.  
https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb9f796dcdd7/kernel/signal.c#L3147
Reviewed-by: Patrick Venture 
Signed-off-by: Shu-Chun Weng 
---
  linux-user/syscall.c | 10 +-
  1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce9d64896c..3070d31f34 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9491,6 +9491,11 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
  }
  
  if (arg2) {

+if (!(p = lock_user(VERIFY_READ, arg2, 
sizeof(target_sigset_t), 1)))
+return -TARGET_EFAULT;
+target_to_host_sigset(, p);
+unlock_user(p, arg2, 0);
+set_ptr = 
  switch(how) {
  case TARGET_SIG_BLOCK:
  how = SIG_BLOCK;
@@ -9504,11 +9509,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
  default:
  return -TARGET_EINVAL;
  }
-if (!(p = lock_user(VERIFY_READ, arg2, 
sizeof(target_sigset_t), 1)))
-return -TARGET_EFAULT;
-target_to_host_sigset(, p);
-unlock_user(p, arg2, 0);
-set_ptr = 
  } else {
  how = 0;
  set_ptr = NULL;


I know it's only code move but generally we also update the style to pass scripts/checkpatch.pl 
successfully.


Could you also update TARGET_NR_sigprocmask in the same way as it seems the kernel behaves like this 
too in this case?


Thanks,
Laurent



Re: [PATCH 0/4] linux-user: prctl follow-ups

2022-01-08 Thread Laurent Vivier

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

Hi Laurent, as requested.  I did all of the cap_task_prctl options,
and fixed a few existing bugs with PR_GET_DEATHSIG.

r~

Richard Henderson (4):
   linux-user: Do not special-case NULL for PR_GET_PDEATHSIG
   linux-user: Map signal number in PR_GET_PDEATHSIG
   linux-user: Implement PR_SET_PDEATHSIG
   linux-user: Implement capability prctls

  linux-user/syscall.c | 11 ++-
  1 file changed, 10 insertions(+), 1 deletion(-)



Series applied to my linux-user-for-7.0 branch.

Thanks,
Laurent



Re: [PATCH 2/2] linux-user: Move target_struct.h generic definitions to generic/

2022-01-08 Thread Laurent Vivier

Le 07/01/2022 à 05:26, Richard Henderson a écrit :

Most targets share the same generic ipc structure definitions.

Signed-off-by: Richard Henderson 
---
  linux-user/aarch64/target_structs.h| 59 +-
  linux-user/arm/target_structs.h| 52 +--
  linux-user/cris/target_structs.h   | 59 +-
  linux-user/generic/target_structs.h| 58 +
  linux-user/hexagon/target_structs.h| 55 +---
  linux-user/i386/target_structs.h   | 59 +-
  linux-user/m68k/target_structs.h   | 59 +-
  linux-user/microblaze/target_structs.h | 59 +-
  linux-user/nios2/target_structs.h  | 59 +-
  linux-user/openrisc/target_structs.h   | 59 +-
  linux-user/riscv/target_structs.h  | 47 +---
  linux-user/sh4/target_structs.h| 59 +-
  linux-user/x86_64/target_structs.h | 36 +---
  13 files changed, 70 insertions(+), 650 deletions(-)
  create mode 100644 linux-user/generic/target_structs.h

diff --git a/linux-user/aarch64/target_structs.h 
b/linux-user/aarch64/target_structs.h
index 7c748344ca..3a06f373c3 100644
--- a/linux-user/aarch64/target_structs.h
+++ b/linux-user/aarch64/target_structs.h
@@ -1,58 +1 @@
-/*
- * ARM AArch64 specific structures for linux-user
- *
- * Copyright (c) 2013 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-#ifndef AARCH64_TARGET_STRUCTS_H
-#define AARCH64_TARGET_STRUCTS_H
-
-struct target_ipc_perm {
-abi_int __key;  /* Key.  */
-abi_uint uid;   /* Owner's user ID.  */
-abi_uint gid;   /* Owner's group ID.  */
-abi_uint cuid;  /* Creator's user ID.  */
-abi_uint cgid;  /* Creator's group ID.  */
-abi_ushort mode;/* Read/write permission.  */
-abi_ushort __pad1;
-abi_ushort __seq;   /* Sequence number.  */
-abi_ushort __pad2;
-abi_ulong __unused1;
-abi_ulong __unused2;
-};
-
-struct target_shmid_ds {
-struct target_ipc_perm shm_perm;/* operation permission struct */
-abi_long shm_segsz; /* size of segment in bytes */
-abi_ulong shm_atime;/* time of last shmat() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused1;
-#endif
-abi_ulong shm_dtime;/* time of last shmdt() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused2;
-#endif
-abi_ulong shm_ctime;/* time of last change by shmctl() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused3;
-#endif
-abi_int shm_cpid;   /* pid of creator */
-abi_int shm_lpid;   /* pid of last shmop */
-abi_ulong shm_nattch;   /* number of current attaches */
-abi_ulong __unused4;
-abi_ulong __unused5;
-};
-
-#endif
+#include "../generic/target_structs.h"
diff --git a/linux-user/arm/target_structs.h b/linux-user/arm/target_structs.h
index 25bf8dd3a5..3a06f373c3 100644
--- a/linux-user/arm/target_structs.h
+++ b/linux-user/arm/target_structs.h
@@ -1,51 +1 @@
-/*
- * ARM specific structures for linux-user
- *
- * Copyright (c) 2013 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see .
- */
-#ifndef ARM_TARGET_STRUCTS_H
-#define ARM_TARGET_STRUCTS_H
-
-struct target_ipc_perm {
-abi_int __key;  /* Key.  */
-abi_uint uid;   /* Owner's user ID.  */
-abi_uint gid;   /* Owner's group ID.  */
- 

Re: [PATCH 1/2] linux-user/arm: Move target_oabi_flock64 out of target_structs.h

2022-01-08 Thread Laurent Vivier

Le 07/01/2022 à 05:25, Richard Henderson a écrit :

Place it next to copy_from/to_user_oabi_flock64, the only users,
inside the existing target-specific ifdef.  This leaves only
generic ipc structs in target_structs.h.

Signed-off-by: Richard Henderson 
---
  linux-user/arm/target_structs.h | 8 
  linux-user/syscall.c| 8 
  2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/linux-user/arm/target_structs.h b/linux-user/arm/target_structs.h
index 339b070bf1..25bf8dd3a5 100644
--- a/linux-user/arm/target_structs.h
+++ b/linux-user/arm/target_structs.h
@@ -48,12 +48,4 @@ struct target_shmid_ds {
  abi_ulong __unused4;
  abi_ulong __unused5;
  };
-
-struct target_oabi_flock64 {
-abi_short l_type;
-abi_short l_whence;
-abi_llong l_start;
-abi_llong l_len;
-abi_int   l_pid;
-} QEMU_PACKED;
  #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce9d64896c..ca6e0b8fb0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6927,6 +6927,14 @@ typedef abi_long from_flock64_fn(struct flock64 *fl, 
abi_ulong target_addr);
  typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock64 
*fl);
  
  #if defined(TARGET_ARM) && TARGET_ABI_BITS == 32

+struct target_oabi_flock64 {
+abi_short l_type;
+abi_short l_whence;
+abi_llong l_start;
+abi_llong l_len;
+abi_int   l_pid;
+} QEMU_PACKED;
+
  static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
 abi_ulong 
target_flock_addr)
  {


Reviewed-by: Laurent Vivier 



Re: [PATCH 2/2] linux-user: Move target_struct.h generic definitions to generic/

2022-01-08 Thread Laurent Vivier
struct target_ipc_perm shm_perm;/* operation permission struct */
-abi_long shm_segsz; /* size of segment in bytes */
-abi_ulong shm_atime;/* time of last shmat() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused1;
-#endif
-abi_ulong shm_dtime;/* time of last shmdt() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused2;
-#endif
-abi_ulong shm_ctime;/* time of last change by shmctl() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused3;
-#endif
-abi_int shm_cpid;   /* pid of creator */
-abi_int shm_lpid;   /* pid of last shmop */
-abi_ulong shm_nattch;   /* number of current attaches */
-abi_ulong __unused4;
-abi_ulong __unused5;
-};
-
-#endif
+#include "../generic/target_structs.h"
diff --git a/linux-user/x86_64/target_structs.h 
b/linux-user/x86_64/target_structs.h
index ce367b253b..f1181383c4 100644
--- a/linux-user/x86_64/target_structs.h
+++ b/linux-user/x86_64/target_structs.h
@@ -19,41 +19,7 @@
  #ifndef X86_64_TARGET_STRUCTS_H
  #define X86_64_TARGET_STRUCTS_H
  
-struct target_ipc_perm {

-abi_int __key;  /* Key.  */
-abi_uint uid;   /* Owner's user ID.  */
-abi_uint gid;   /* Owner's group ID.  */
-abi_uint cuid;  /* Creator's user ID.  */
-abi_uint cgid;  /* Creator's group ID.  */
-abi_ushort mode;/* Read/write permission.  */
-abi_ushort __pad1;
-abi_ushort __seq;   /* Sequence number.  */
-abi_ushort __pad2;
-abi_ulong __unused1;
-abi_ulong __unused2;
-};
-
-struct target_shmid_ds {
-struct target_ipc_perm shm_perm;/* operation permission struct */
-abi_long shm_segsz; /* size of segment in bytes */
-abi_ulong shm_atime;/* time of last shmat() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused1;
-#endif
-abi_ulong shm_dtime;/* time of last shmdt() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused2;
-#endif
-abi_ulong shm_ctime;/* time of last change by shmctl() */
-#if TARGET_ABI_BITS == 32
-abi_ulong __unused3;
-#endif
-abi_int shm_cpid;   /* pid of creator */
-abi_int shm_lpid;   /* pid of last shmop */
-abi_ulong shm_nattch;   /* number of current attaches */
-abi_ulong __unused4;
-abi_ulong __unused5;
-};
+#include "../generic/target_structs.h"
  
  /* The x86 definition differs from the generic one in that the

   * two padding fields exist whether the ABI is 32 bits or 64 bits.


Reviewed-by: Laurent Vivier 




Re: [PATCH 1/2] linux-user/arm: Move target_oabi_flock64 out of target_structs.h

2022-01-08 Thread Laurent Vivier

Le 07/01/2022 à 05:25, Richard Henderson a écrit :

Place it next to copy_from/to_user_oabi_flock64, the only users,
inside the existing target-specific ifdef.  This leaves only
generic ipc structs in target_structs.h.

Signed-off-by: Richard Henderson 
---
  linux-user/arm/target_structs.h | 8 
  linux-user/syscall.c| 8 
  2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/linux-user/arm/target_structs.h b/linux-user/arm/target_structs.h
index 339b070bf1..25bf8dd3a5 100644
--- a/linux-user/arm/target_structs.h
+++ b/linux-user/arm/target_structs.h
@@ -48,12 +48,4 @@ struct target_shmid_ds {
  abi_ulong __unused4;
  abi_ulong __unused5;
  };
-
-struct target_oabi_flock64 {
-abi_short l_type;
-abi_short l_whence;
-abi_llong l_start;
-abi_llong l_len;
-abi_int   l_pid;
-} QEMU_PACKED;
  #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce9d64896c..ca6e0b8fb0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6927,6 +6927,14 @@ typedef abi_long from_flock64_fn(struct flock64 *fl, 
abi_ulong target_addr);
  typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock64 
*fl);
  
  #if defined(TARGET_ARM) && TARGET_ABI_BITS == 32

+struct target_oabi_flock64 {
+abi_short l_type;
+abi_short l_whence;
+abi_llong l_start;
+abi_llong l_len;
+abi_int   l_pid;
+} QEMU_PACKED;
+
  static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
 abi_ulong 
target_flock_addr)
  {


Applied to my linux-user-for-7.0 branch.

Thanks,
Laurent




Re: [PATCH] macfb: fix VRAM dirty memory region logging

2022-01-08 Thread Laurent Vivier

Le 08/01/2022 à 18:15, Mark Cave-Ayland a écrit :

On 08/01/2022 16:53, Laurent Vivier wrote:


Le 08/01/2022 à 17:41, Mark Cave-Ayland a écrit :

The macfb VRAM memory region was configured with coalescing rather than dirty
memory logging enabled, causing some areas of the screen not to redraw after
a full screen update.

Signed-off-by: Mark Cave-Ayland 
Fixes: 8ac919a065 ("hw/m68k: add Nubus macfb video card")
---
  hw/display/macfb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/display/macfb.c b/hw/display/macfb.c
index 277d3e6633..4bd7c3ad6a 100644
--- a/hw/display/macfb.c
+++ b/hw/display/macfb.c
@@ -661,9 +661,9 @@ static bool macfb_common_realize(DeviceState *dev, 
MacfbState *s, Error **errp)
  memory_region_init_ram(>mem_vram, OBJECT(dev), "macfb-vram",
 MACFB_VRAM_SIZE, _abort);
+    memory_region_set_log(>mem_vram, true, DIRTY_MEMORY_VGA);
  s->vram = memory_region_get_ram_ptr(>mem_vram);
  s->vram_bit_mask = MACFB_VRAM_SIZE - 1;
-    memory_region_set_coalescing(>mem_vram);
  s->vbl_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, macfb_vbl_timer, s);
  macfb_update_mode(s);


I understant why you add memory_region_set_log() but I don't understand why you remove 
memory_region_set_coalescing().


Looking at the other display devices, only VGA and cirrus use memory_region_set_coalescing() and 
that's on the IO ports rather than the VRAM.

>
Based upon this my suspicion is that this is mainly a vmexit optimisation when using KVM which isn't 
relevant here for macfb.


You're right.

Reviewed-by: Laurent Vivier 

Thanks,
Laurent



Re: [PATCH v5 00/24] linux-user: Clean up siginfo_t handling

2022-01-08 Thread Laurent Vivier

Le 07/01/2022 à 22:32, Richard Henderson a écrit :

Changes from v4:
   * Rebase on master.

All patches are reviewed.


Series applied to my linux-user-for-7.0 branch.

Thanks,
Laurent



r~


Richard Henderson (24):
   linux-user/alpha: Set TRAP_UNK for bugchk and unknown gentrap
   linux-user/alpha: Set FPE_FLTUNK for gentrap ROPRAND
   linux-user/alpha: Use force_sig_fault
   linux-user/cris: Use force_sig_fault
   linux-user/hppa: Use force_sig_fault
   linux-user/hppa: Use the proper si_code for PRIV_OPR, PRIV_REG,
 OVERFLOW
   linux-user: Remove TARGET_NSIGFPE
   linux-user/hppa: Set FPE_CONDTRAP for COND
   linux-user/i386: Split out maybe_handle_vm86_trap
   linux-user/i386: Use force_sig, force_sig_fault
   linux-user/m68k: Use force_sig_fault
   linux-user/microblaze: Use force_sig_fault
   linux-user/microblaze: Fix SIGFPE si_codes
   linux-user/mips: Improve do_break
   linux-user/mips: Use force_sig_fault
   target/mips: Extract break code into env->error_code
   target/mips: Extract trap code into env->error_code
   linux-user/openrisc: Use force_sig_fault
   linux-user/ppc: Use force_sig_fault
   linux-user/riscv: Use force_sig_fault
   linux-user/s390x: Use force_sig_fault
   linux-user/sh4: Use force_sig_fault
   linux-user/sparc: Use force_sig_fault
   linux-user/xtensa: Use force_sig_fault

  linux-user/syscall_defs.h |   3 +-
  target/mips/tcg/translate.h   |   1 +
  linux-user/alpha/cpu_loop.c   |  61 +++-
  linux-user/cris/cpu_loop.c|  12 +-
  linux-user/hppa/cpu_loop.c|  26 ++--
  linux-user/i386/cpu_loop.c|  78 +-
  linux-user/m68k/cpu_loop.c|  24 +---
  linux-user/microblaze/cpu_loop.c  |  71 +
  linux-user/mips/cpu_loop.c| 166 +-
  linux-user/openrisc/cpu_loop.c|  18 +--
  linux-user/ppc/cpu_loop.c | 136 --
  linux-user/riscv/cpu_loop.c   |  31 +---
  linux-user/s390x/cpu_loop.c   |   7 +-
  linux-user/sh4/cpu_loop.c |   6 +-
  linux-user/sparc/cpu_loop.c   |  14 +-
  linux-user/xtensa/cpu_loop.c  |  26 ++--
  target/mips/tcg/translate.c   |  36 -
  target/mips/tcg/micromips_translate.c.inc |  10 +-
  target/mips/tcg/mips16e_translate.c.inc   |   2 +-
  target/mips/tcg/nanomips_translate.c.inc  |   4 +-
  20 files changed, 230 insertions(+), 502 deletions(-)






Re: [PATCH 4/4] linux-user: Implement capability prctls

2022-01-08 Thread Laurent Vivier

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

This is PR_CAPBSET_READ, PR_CAPBSET_DROP and the "legacy"
PR_CAP_AMBIENT PR_GET_SECUREBITS, PR_SET_SECUREBITS.

All of these arguments are integer values only, and do not
require mapping of values between host and guest.

Signed-off-by: Richard Henderson 
---
  linux-user/syscall.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8495f5e08e..4711afaf8c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6504,10 +6504,15 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
  case PR_SET_UNALIGN:
  return do_prctl_set_unalign(env, arg2);
  
+case PR_CAP_AMBIENT:

+case PR_CAPBSET_READ:
+case PR_CAPBSET_DROP:
  case PR_GET_DUMPABLE:
  case PR_SET_DUMPABLE:
  case PR_GET_KEEPCAPS:
  case PR_SET_KEEPCAPS:
+case PR_GET_SECUREBITS:
+case PR_SET_SECUREBITS:
  case PR_GET_TIMING:
  case PR_SET_TIMING:
  case PR_GET_TIMERSLACK:


Reviewed-by: Laurent Vivier 



Re: [PATCH 3/4] linux-user: Implement PR_SET_PDEATHSIG

2022-01-08 Thread Laurent Vivier

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

Signed-off-by: Richard Henderson 
---
  linux-user/syscall.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9eb2fb2bb2..8495f5e08e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6450,6 +6450,9 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
  }
  return ret;
  }
+case PR_SET_PDEATHSIG:
+return get_errno(prctl(PR_SET_PDEATHSIG, target_to_host_signal(arg2),
+   arg3, arg4, arg5));
  case PR_GET_NAME:
  {
  void *name = lock_user(VERIFY_WRITE, arg2, 16, 1);


Reviewed-by: Laurent Vivier 



Re: [PATCH 1/4] linux-user: Do not special-case NULL for PR_GET_PDEATHSIG

2022-01-08 Thread Laurent Vivier

Le 08/01/2022 à 18:10, Laurent Vivier a écrit :

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

The kernel does not special-case arg2 != NULL, so
neither should we.

Signed-off-by: Richard Henderson 
---
  linux-user/syscall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce9d64896c..e8f9e0643e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6444,7 +6444,7 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
  int deathsig;
  ret = get_errno(prctl(PR_GET_PDEATHSIG, ,
    arg3, arg4, arg5));
-    if (!is_error(ret) && arg2 && put_user_s32(deathsig, arg2)) {
+    if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
  return -TARGET_EFAULT;
  }
  return ret;


Reviewed-by: Laurent Vivier 



Reviewed-by: Laurent Vivier 



Re: [PATCH 1/4] linux-user: Do not special-case NULL for PR_GET_PDEATHSIG

2022-01-08 Thread Laurent Vivier

Le 06/01/2022 à 23:57, Richard Henderson a écrit :

The kernel does not special-case arg2 != NULL, so
neither should we.

Signed-off-by: Richard Henderson 
---
  linux-user/syscall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce9d64896c..e8f9e0643e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6444,7 +6444,7 @@ static abi_long do_prctl(CPUArchState *env, abi_long 
option, abi_long arg2,
  int deathsig;
  ret = get_errno(prctl(PR_GET_PDEATHSIG, ,
arg3, arg4, arg5));
-if (!is_error(ret) && arg2 && put_user_s32(deathsig, arg2)) {
+if (!is_error(ret) && put_user_s32(deathsig, arg2)) {
  return -TARGET_EFAULT;
  }
  return ret;


Reviewed-by: Laurent Vivier 



Re: [PATCH] macfb: fix VRAM dirty memory region logging

2022-01-08 Thread Laurent Vivier

Le 08/01/2022 à 17:41, Mark Cave-Ayland a écrit :

The macfb VRAM memory region was configured with coalescing rather than dirty
memory logging enabled, causing some areas of the screen not to redraw after
a full screen update.

Signed-off-by: Mark Cave-Ayland 
Fixes: 8ac919a065 ("hw/m68k: add Nubus macfb video card")
---
  hw/display/macfb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/display/macfb.c b/hw/display/macfb.c
index 277d3e6633..4bd7c3ad6a 100644
--- a/hw/display/macfb.c
+++ b/hw/display/macfb.c
@@ -661,9 +661,9 @@ static bool macfb_common_realize(DeviceState *dev, 
MacfbState *s, Error **errp)
  
  memory_region_init_ram(>mem_vram, OBJECT(dev), "macfb-vram",

 MACFB_VRAM_SIZE, _abort);
+memory_region_set_log(>mem_vram, true, DIRTY_MEMORY_VGA);
  s->vram = memory_region_get_ram_ptr(>mem_vram);
  s->vram_bit_mask = MACFB_VRAM_SIZE - 1;
-memory_region_set_coalescing(>mem_vram);
  
  s->vbl_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, macfb_vbl_timer, s);

  macfb_update_mode(s);


I understant why you add memory_region_set_log() but I don't understand why you remove 
memory_region_set_coalescing().


Thanks,
Laurent



[PATCH v2] q800: fix segfault with invalid MacROM

2022-01-07 Thread Laurent Vivier
"qemu-system-m68k -M q800 -bios /dev/null" crashes with a segfault
in q800_init().
This happens because the code doesn't check that rom_ptr() returned
a non-NULL pointer .

To avoid NULL pointer, don't allow 0 sized file and use bios_size with
rom_ptr().

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
Reported-by: Peter Maydell 
Signed-off-by: Laurent Vivier 
---
 hw/m68k/q800.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index e4c7c9b88ad0..55dfe5036f40 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -672,12 +672,13 @@ static void q800_init(MachineState *machine)
 
 /* Remove qtest_enabled() check once firmware files are in the tree */
 if (!qtest_enabled()) {
-if (bios_size < 0 || bios_size > MACROM_SIZE) {
+if (bios_size <= 0 || bios_size > MACROM_SIZE) {
 error_report("could not load MacROM '%s'", bios_name);
 exit(1);
 }
 
-ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
+ptr = rom_ptr(MACROM_ADDR, bios_size);
+assert(ptr != NULL);
 stl_phys(cs->as, 0, ldl_p(ptr));/* reset initial SP */
 stl_phys(cs->as, 4,
  MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */
-- 
2.33.1




Re: [PATCH] q800: fix segfault with invalid MacROM

2022-01-07 Thread Laurent Vivier

Le 07/01/2022 à 10:47, BALATON Zoltan a écrit :

On Fri, 7 Jan 2022, Laurent Vivier wrote:

Le 07/01/2022 à 09:15, Mark Cave-Ayland a écrit :

On 06/01/2022 12:22, Laurent Vivier wrote:


"qemu-system-m68k -M q800 -bios /dev/null" crahses with a segfault
in q800_init().
This happens because the code doesn't check that rom_ptr() returned
a non-NULL pointer .

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
Reported-by: Peter Maydell 
Signed-off-by: Laurent Vivier 
---
  hw/m68k/q800.c | 8 +++-
  1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index e4c7c9b88ad0..6261716c8f7e 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -672,10 +672,16 @@ static void q800_init(MachineState *machine)
  /* Remove qtest_enabled() check once firmware files are in the tree */
  if (!qtest_enabled()) {
-    if (bios_size < 0 || bios_size > MACROM_SIZE) {
+    if (bios_size == -1) {
  error_report("could not load MacROM '%s'", bios_name);
  exit(1);
  }
+    if (bios_size != MACROM_SIZE) {
+    error_report("Invalid size for MacROM '%s': %d bytes,"
+ " expected %d bytes", bios_name, bios_size,
+ MACROM_SIZE);
+    exit(1);
+    }
  ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
  stl_phys(cs->as, 0, ldl_p(ptr));    /* reset initial SP */


The patch does fix the issue, but it seems a little odd that you can't use -bios 
path/to/m68k-binary to boot with an arbitrary sized binary which could be useful for reproducers 
such as https://gitlab.com/qemu-project/qemu/-/issues/360.


How easy would it be to add the extra rom_ptr() NULL check instead?



I was thinking that a smaller binary can be padded to 1 MB for use because on a real hardware the 
size of the ROM cannot be arbitrary.


But it seems reasonable to check only for the NULL pointer rather than the size, I'm going to send 
a v2.


Instead of adding !rom_ptr as well, isn't it enough to change to
bios_size <= 0 in the existing check?



I agree. And to change rom_ptr(MACROM_ADDR, MACROM_SIZE) to 
rom_ptr(MACROM_ADDR, bios_size)

Thanks,
Laurent



Re: [PATCH 0/6] linux-user: prctl improvements

2022-01-07 Thread Laurent Vivier



Hi Gaosong,

Le 07/01/2022 à 09:46, gaosong a écrit :

Hi Laurent,

On 2022/1/6 下午6:46, Laurent Vivier wrote:
make the LTP testsuite (20200930) happy again (capset02, prctl01, prctl02, prctl03)? 


Do we have LTP test documents?   or What test methods do we have for linux-user?


I run the Linux Test Project test suite in a container (unshare command) using 
binfmt_misc:

https://linux-test-project.github.io/

I have some scripts to automatically create debian chroots and build/run the 
suite inside:

https://github.com/vivier/linux-user-test-scrips

My top script is "run_all.sh" that creates the chroots and run the ltp_test.

The list of the targets I test is in targets.conf:

etch="m68k"
stretch="s390x ppc64le mipsel mips64el mips arm aarch64"
jessie="ppc"
wheezy="sparc32plus"
lenny="hppa alpha"
sid="m68k ppc64 sh4 riscv64 alpha aarch64 s390x hppa sparc64"
trusty="aarch64 ppc ppc64le"
bionic="aarch64 arm ppc64le s390x"

Than I compare the results with the previous run using diff_ltp.sh

This means I don't test architectures that don't have debian support, and only 
test on x86_64 host.

Thanks,
Laurent



Re: [PATCH] q800: fix segfault with invalid MacROM

2022-01-07 Thread Laurent Vivier

Le 07/01/2022 à 09:15, Mark Cave-Ayland a écrit :

On 06/01/2022 12:22, Laurent Vivier wrote:


"qemu-system-m68k -M q800 -bios /dev/null" crahses with a segfault
in q800_init().
This happens because the code doesn't check that rom_ptr() returned
a non-NULL pointer .

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
Reported-by: Peter Maydell 
Signed-off-by: Laurent Vivier 
---
  hw/m68k/q800.c | 8 +++-
  1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index e4c7c9b88ad0..6261716c8f7e 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -672,10 +672,16 @@ static void q800_init(MachineState *machine)
  /* Remove qtest_enabled() check once firmware files are in the tree */
  if (!qtest_enabled()) {
-    if (bios_size < 0 || bios_size > MACROM_SIZE) {
+    if (bios_size == -1) {
  error_report("could not load MacROM '%s'", bios_name);
  exit(1);
  }
+    if (bios_size != MACROM_SIZE) {
+    error_report("Invalid size for MacROM '%s': %d bytes,"
+ " expected %d bytes", bios_name, bios_size,
+ MACROM_SIZE);
+    exit(1);
+    }
  ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
  stl_phys(cs->as, 0, ldl_p(ptr));    /* reset initial SP */


The patch does fix the issue, but it seems a little odd that you can't use -bios path/to/m68k-binary 
to boot with an arbitrary sized binary which could be useful for reproducers such as 
https://gitlab.com/qemu-project/qemu/-/issues/360.


How easy would it be to add the extra rom_ptr() NULL check instead?



I was thinking that a smaller binary can be padded to 1 MB for use because on a real hardware the 
size of the ROM cannot be arbitrary.


But it seems reasonable to check only for the NULL pointer rather than the 
size, I'm going to send a v2.

Thanks,
Laurent



Byte Sized task (was Re: [PATCH] linux-user/syscall.c: malloc to g_try_malloc)

2022-01-06 Thread Laurent Vivier

Hi Ahmed,

the email address you use for the trivial ML is broken. I've fixed it for my answer and added 
qemu-devel.


Le 05/01/2022 à 20:09, Ahmed Abouzied a écrit :

Hello,

Thanks for the review. I also found some occurrences of "cpu_physical_memor_*" calls that should be 
replaced with "address_space_*" around the codebase as mentioned 
[here](https://wiki.qemu.org/Contribute/BiteSizedTasks 
<https://wiki.qemu.org/Contribute/BiteSizedTasks>) in the API conversion section. The "/hw" 
directory for instance. Should I go about replacing those as well? Should I create a Gitlab issue 
first to track the changes?



According to the wiki, the gitlab issue are already created with the "Byte 
Sized" label.

https://gitlab.com/qemu-project/qemu/-/issues?scope=all=opened_name[]=Bite%20Sized

But this one is not, I think John can help you for that (added in cc:)

Thanks,
Laurent


Best regards,
Ahmed

On Wed, 5 Jan 2022 at 12:26, Laurent Vivier mailto:laur...@vivier.eu>> wrote:

Le 04/01/2022 à 15:38, Ahmed Abouzied a écrit :
 > Use g_try_malloc instead of malloc to alocate the target ifconfig.
 > Also replace the corresponding free with g_free.
 >
 > Signed-off-by: Ahmed Abouzied mailto:em...@aabouzied.com>>
 > ---
 >
 > Hello,
 >
 > I noticed that there was a `malloc` call in this file. It seems that it
 > was added by the commit 22e4a267 (3 years ago) which was after the commit
 > 0e173b24 (6 years ago) that replaced malloc calls with glib alternative 
calls.
 >
 > There is no issue for this on Gitlab. Should I have created an issue
 > first?
 >
 > Best regards,
 >
 >   linux-user/syscall.c | 4 ++--
 >   1 file changed, 2 insertions(+), 2 deletions(-)
 >
 > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
 > index 56a3e17183..715f9430e1 100644
 > --- a/linux-user/syscall.c
 > +++ b/linux-user/syscall.c
 > @@ -4867,7 +4867,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry 
*ie, uint8_t *buf_temp,
 >                * We can't fit all the extents into the fixed size buffer.
 >                * Allocate one that is large enough and use it instead.
 >                */
 > -            host_ifconf = malloc(outbufsz);
 > +            host_ifconf = g_try_malloc(outbufsz);
 >               if (!host_ifconf) {
 >                   return -TARGET_ENOMEM;
 >               }
 > @@ -4915,7 +4915,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry 
*ie, uint8_t *buf_temp,
 >       }
 >
 >       if (free_buf) {
 > -        free(host_ifconf);
 > +        g_free(host_ifconf);
 >       }
 >
 >       return ret;

Applied to my linux-user-for-7.0 branch.

Thanks,
Laurent






[PATCH] q800: fix segfault with invalid MacROM

2022-01-06 Thread Laurent Vivier
"qemu-system-m68k -M q800 -bios /dev/null" crahses with a segfault
in q800_init().
This happens because the code doesn't check that rom_ptr() returned
a non-NULL pointer .

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/756
Reported-by: Peter Maydell 
Signed-off-by: Laurent Vivier 
---
 hw/m68k/q800.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index e4c7c9b88ad0..6261716c8f7e 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -672,10 +672,16 @@ static void q800_init(MachineState *machine)
 
 /* Remove qtest_enabled() check once firmware files are in the tree */
 if (!qtest_enabled()) {
-if (bios_size < 0 || bios_size > MACROM_SIZE) {
+if (bios_size == -1) {
 error_report("could not load MacROM '%s'", bios_name);
 exit(1);
 }
+if (bios_size != MACROM_SIZE) {
+error_report("Invalid size for MacROM '%s': %d bytes,"
+ " expected %d bytes", bios_name, bios_size,
+ MACROM_SIZE);
+exit(1);
+}
 
 ptr = rom_ptr(MACROM_ADDR, MACROM_SIZE);
 stl_phys(cs->as, 0, ldl_p(ptr));/* reset initial SP */
-- 
2.33.1




Re: [PATCH 0/6] linux-user: prctl improvements

2022-01-06 Thread Laurent Vivier

Le 20/12/2021 à 22:41, Richard Henderson a écrit :

This is split out from a larger patch set for unaligned accesses.
The changes in target/ have no effect without the changes in tcg/,
but this allows the syscall to be handled separately.


r~


Hi Richard,

while I was testing the series for the pull request I found some regressions on commands that were 
passing on before and are not now.


Could you send a follow up patch to add at least PR_CAPBSET_DROP and PR_SET_PDEATHSIG to make the 
LTP testsuite (20200930) happy again (capset02, prctl01, prctl02, prctl03)?


Thanks,
Laurent



[PULL 07/27] linux-user: Split out do_prctl and subroutines

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

Since the prctl constants are supposed to be generic, supply
any that are not provided by the host.

Split out subroutines for PR_GET_FP_MODE, PR_SET_FP_MODE,
PR_GET_VL, PR_SET_VL, PR_RESET_KEYS, PR_SET_TAGGED_ADDR_CTRL,
PR_GET_TAGGED_ADDR_CTRL.  Return EINVAL for guests that do
not support these options rather than pass them on to the host.

Reviewed-by: Laurent Vivier 
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
Message-Id: <20211227150127.2659293-2-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/aarch64/target_prctl.h| 160 ++
 linux-user/aarch64/target_syscall.h  |  23 --
 linux-user/alpha/target_prctl.h  |   1 +
 linux-user/arm/target_prctl.h|   1 +
 linux-user/cris/target_prctl.h   |   1 +
 linux-user/hexagon/target_prctl.h|   1 +
 linux-user/hppa/target_prctl.h   |   1 +
 linux-user/i386/target_prctl.h   |   1 +
 linux-user/m68k/target_prctl.h   |   1 +
 linux-user/microblaze/target_prctl.h |   1 +
 linux-user/mips/target_prctl.h   |  88 ++
 linux-user/mips/target_syscall.h |   6 -
 linux-user/mips64/target_prctl.h |   1 +
 linux-user/mips64/target_syscall.h   |   6 -
 linux-user/nios2/target_prctl.h  |   1 +
 linux-user/openrisc/target_prctl.h   |   1 +
 linux-user/ppc/target_prctl.h|   1 +
 linux-user/riscv/target_prctl.h  |   1 +
 linux-user/s390x/target_prctl.h  |   1 +
 linux-user/sh4/target_prctl.h|   1 +
 linux-user/sparc/target_prctl.h  |   1 +
 linux-user/syscall.c | 433 +--
 linux-user/x86_64/target_prctl.h |   1 +
 linux-user/xtensa/target_prctl.h |   1 +
 24 files changed, 414 insertions(+), 320 deletions(-)
 create mode 100644 linux-user/aarch64/target_prctl.h
 create mode 100644 linux-user/alpha/target_prctl.h
 create mode 100644 linux-user/arm/target_prctl.h
 create mode 100644 linux-user/cris/target_prctl.h
 create mode 100644 linux-user/hexagon/target_prctl.h
 create mode 100644 linux-user/hppa/target_prctl.h
 create mode 100644 linux-user/i386/target_prctl.h
 create mode 100644 linux-user/m68k/target_prctl.h
 create mode 100644 linux-user/microblaze/target_prctl.h
 create mode 100644 linux-user/mips/target_prctl.h
 create mode 100644 linux-user/mips64/target_prctl.h
 create mode 100644 linux-user/nios2/target_prctl.h
 create mode 100644 linux-user/openrisc/target_prctl.h
 create mode 100644 linux-user/ppc/target_prctl.h
 create mode 100644 linux-user/riscv/target_prctl.h
 create mode 100644 linux-user/s390x/target_prctl.h
 create mode 100644 linux-user/sh4/target_prctl.h
 create mode 100644 linux-user/sparc/target_prctl.h
 create mode 100644 linux-user/x86_64/target_prctl.h
 create mode 100644 linux-user/xtensa/target_prctl.h

diff --git a/linux-user/aarch64/target_prctl.h 
b/linux-user/aarch64/target_prctl.h
new file mode 100644
index ..3f5a5d3933a0
--- /dev/null
+++ b/linux-user/aarch64/target_prctl.h
@@ -0,0 +1,160 @@
+/*
+ * AArch64 specific prctl functions for linux-user
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef AARCH64_TARGET_PRCTL_H
+#define AARCH64_TARGET_PRCTL_H
+
+static abi_long do_prctl_get_vl(CPUArchState *env)
+{
+ARMCPU *cpu = env_archcpu(env);
+if (cpu_isar_feature(aa64_sve, cpu)) {
+return ((cpu->env.vfp.zcr_el[1] & 0xf) + 1) * 16;
+}
+return -TARGET_EINVAL;
+}
+#define do_prctl_get_vl do_prctl_get_vl
+
+static abi_long do_prctl_set_vl(CPUArchState *env, abi_long arg2)
+{
+/*
+ * We cannot support either PR_SVE_SET_VL_ONEXEC or PR_SVE_VL_INHERIT.
+ * Note the kernel definition of sve_vl_valid allows for VQ=512,
+ * i.e. VL=8192, even though the current architectural maximum is VQ=16.
+ */
+if (cpu_isar_feature(aa64_sve, env_archcpu(env))
+&& arg2 >= 0 && arg2 <= 512 * 16 && !(arg2 & 15)) {
+ARMCPU *cpu = env_archcpu(env);
+uint32_t vq, old_vq;
+
+old_vq = (env->vfp.zcr_el[1] & 0xf) + 1;
+vq = MAX(arg2 / 16, 1);
+vq = MIN(vq, cpu->sve_max_vq);
+
+if (vq < old_vq) {
+aarch64_sve_narrow_vq(env, vq);
+}
+env->vfp.zcr_el[1] = vq - 1;
+arm_rebuild_hflags(env);
+return vq * 16;
+}
+return -TARGET_EINVAL;
+}
+#define do_prctl_set_vl do_prctl_set_vl
+
+static abi_long do_prctl_reset_keys(CPUArchState *env, abi_long arg2)
+{
+ARMCPU *cpu = env_archcpu(env);
+
+if (cpu_isar_feature(aa64_pauth, cpu)) {
+int all = (PR_PAC_APIAKEY | PR_PAC_APIBKEY |
+   PR_PAC_APDAKEY | PR_PAC_APDBKEY | PR_PAC_APGAKEY);
+int ret = 0;
+Error *err = NULL;
+
+if (arg2 == 0) {
+arg2 = all;
+} else if (arg2 & ~all) {
+return -TARGET_EINVAL;
+}
+if (arg2 & PR_PAC_APIAKEY) {
+ret |= qemu_guest_getrando

[PULL 26/27] linux-user: netlink: Add IFLA_VFINFO_LIST

2022-01-06 Thread Laurent Vivier
# QEMU_LOG=unimp ip a
  Unknown host QEMU_IFLA type: 22

Signed-off-by: Laurent Vivier 
Reviewed-by: Richard Henderson 
Message-Id: <20211219154514.2165728-2-laur...@vivier.eu>
Signed-off-by: Laurent Vivier 
---
 linux-user/fd-trans.c | 174 ++
 1 file changed, 174 insertions(+)

diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
index 14c19a90b2b0..36e4a4c2aae8 100644
--- a/linux-user/fd-trans.c
+++ b/linux-user/fd-trans.c
@@ -271,6 +271,37 @@ enum {
 QEMU___RTA_MAX
 };
 
+enum {
+QEMU_IFLA_VF_STATS_RX_PACKETS,
+QEMU_IFLA_VF_STATS_TX_PACKETS,
+QEMU_IFLA_VF_STATS_RX_BYTES,
+QEMU_IFLA_VF_STATS_TX_BYTES,
+QEMU_IFLA_VF_STATS_BROADCAST,
+QEMU_IFLA_VF_STATS_MULTICAST,
+QEMU_IFLA_VF_STATS_PAD,
+QEMU_IFLA_VF_STATS_RX_DROPPED,
+QEMU_IFLA_VF_STATS_TX_DROPPED,
+QEMU__IFLA_VF_STATS_MAX,
+};
+
+enum {
+QEMU_IFLA_VF_UNSPEC,
+QEMU_IFLA_VF_MAC,
+QEMU_IFLA_VF_VLAN,
+QEMU_IFLA_VF_TX_RATE,
+QEMU_IFLA_VF_SPOOFCHK,
+QEMU_IFLA_VF_LINK_STATE,
+QEMU_IFLA_VF_RATE,
+QEMU_IFLA_VF_RSS_QUERY_EN,
+QEMU_IFLA_VF_STATS,
+QEMU_IFLA_VF_TRUST,
+QEMU_IFLA_VF_IB_NODE_GUID,
+QEMU_IFLA_VF_IB_PORT_GUID,
+QEMU_IFLA_VF_VLAN_LIST,
+QEMU_IFLA_VF_BROADCAST,
+QEMU__IFLA_VF_MAX,
+};
+
 TargetFdTrans **target_fd_trans;
 QemuMutex target_fd_trans_lock;
 unsigned int target_fd_max;
@@ -808,6 +839,145 @@ static abi_long host_to_target_data_xdp_nlattr(struct 
nlattr *nlattr,
 return 0;
 }
 
+static abi_long host_to_target_data_vlan_list_nlattr(struct nlattr *nlattr,
+ void *context)
+{
+struct ifla_vf_vlan_info *vlan_info;
+
+switch (nlattr->nla_type) {
+/* struct ifla_vf_vlan_info */
+case IFLA_VF_VLAN_INFO:
+vlan_info = NLA_DATA(nlattr);
+vlan_info->vf = tswap32(vlan_info->vf);
+vlan_info->vlan = tswap32(vlan_info->vlan);
+vlan_info->qos = tswap32(vlan_info->qos);
+break;
+default:
+qemu_log_mask(LOG_UNIMP, "Unknown host VLAN LIST type: %d\n",
+  nlattr->nla_type);
+break;
+}
+return 0;
+}
+
+static abi_long host_to_target_data_vf_stats_nlattr(struct nlattr *nlattr,
+void *context)
+{
+uint64_t *u64;
+
+switch (nlattr->nla_type) {
+/* uint64_t */
+case QEMU_IFLA_VF_STATS_RX_PACKETS:
+case QEMU_IFLA_VF_STATS_TX_PACKETS:
+case QEMU_IFLA_VF_STATS_RX_BYTES:
+case QEMU_IFLA_VF_STATS_TX_BYTES:
+case QEMU_IFLA_VF_STATS_BROADCAST:
+case QEMU_IFLA_VF_STATS_MULTICAST:
+case QEMU_IFLA_VF_STATS_PAD:
+case QEMU_IFLA_VF_STATS_RX_DROPPED:
+case QEMU_IFLA_VF_STATS_TX_DROPPED:
+u64 = NLA_DATA(nlattr);
+*u64 = tswap64(*u64);
+break;
+default:
+qemu_log_mask(LOG_UNIMP, "Unknown host VF STATS type: %d\n",
+  nlattr->nla_type);
+break;
+}
+return 0;
+}
+
+static abi_long host_to_target_data_vfinfo_nlattr(struct nlattr *nlattr,
+  void *context)
+{
+struct ifla_vf_mac *mac;
+struct ifla_vf_vlan *vlan;
+struct ifla_vf_vlan_info *vlan_info;
+struct ifla_vf_spoofchk *spoofchk;
+struct ifla_vf_rate *rate;
+struct ifla_vf_link_state *link_state;
+struct ifla_vf_rss_query_en *rss_query_en;
+struct ifla_vf_trust *trust;
+struct ifla_vf_guid *guid;
+
+switch (nlattr->nla_type) {
+/* struct ifla_vf_mac */
+case QEMU_IFLA_VF_MAC:
+mac = NLA_DATA(nlattr);
+mac->vf = tswap32(mac->vf);
+break;
+/* struct ifla_vf_broadcast */
+case QEMU_IFLA_VF_BROADCAST:
+break;
+/* struct struct ifla_vf_vlan */
+case QEMU_IFLA_VF_VLAN:
+vlan = NLA_DATA(nlattr);
+vlan->vf = tswap32(vlan->vf);
+vlan->vlan = tswap32(vlan->vlan);
+vlan->qos = tswap32(vlan->qos);
+break;
+/* struct ifla_vf_vlan_info */
+case QEMU_IFLA_VF_TX_RATE:
+vlan_info = NLA_DATA(nlattr);
+vlan_info->vf = tswap32(vlan_info->vf);
+vlan_info->vlan = tswap32(vlan_info->vlan);
+vlan_info->qos = tswap32(vlan_info->qos);
+break;
+/* struct ifla_vf_spoofchk */
+case QEMU_IFLA_VF_SPOOFCHK:
+spoofchk = NLA_DATA(nlattr);
+spoofchk->vf = tswap32(spoofchk->vf);
+spoofchk->setting = tswap32(spoofchk->setting);
+break;
+/* struct ifla_vf_rate */
+case QEMU_IFLA_VF_RATE:
+rate = NLA_DATA(nlattr);
+rate->vf = tswap32(rate->vf);
+rate->min_tx_rate = tswap32(rate->min_tx_rate);
+rate->max_tx_rate = tswap32(rate->max_tx_rate);
+break;
+/* struct ifla_vf_link_state */
+case QEMU_IFLA_VF_LINK_STATE:
+link_state = NL

[PULL 19/27] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

Arm will no longer be the only target requiring a commpage,
but it will continue to be the only target placing the page
at the high end of the address space.

Reviewed-by: Laurent Vivier 
Signed-off-by: Richard Henderson 
Message-Id: <20211221025012.1057923-4-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/elfload.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 767f54c76dc5..d34cd4fe43fb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -390,11 +390,11 @@ enum {
 
 /* The commpage only exists for 32 bit kernels */
 
-#define ARM_COMMPAGE (intptr_t)0x0f00u
+#define HI_COMMPAGE (intptr_t)0x0f00u
 
 static bool init_guest_commpage(void)
 {
-void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size);
+void *want = g2h_untagged(HI_COMMPAGE & -qemu_host_page_size);
 void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE,
   MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
 
@@ -2160,8 +2160,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
 return sp;
 }
 
-#ifndef ARM_COMMPAGE
-#define ARM_COMMPAGE 0
+#ifndef HI_COMMPAGE
+#define HI_COMMPAGE 0
 #define init_guest_commpage() true
 #endif
 
@@ -2361,7 +2361,7 @@ static void pgb_static(const char *image_name, abi_ulong 
orig_loaddr,
 }
 
 loaddr &= -align;
-if (ARM_COMMPAGE) {
+if (HI_COMMPAGE) {
 /*
  * Extend the allocation to include the commpage.
  * For a 64-bit host, this is just 4GiB; for a 32-bit host we
@@ -2372,14 +2372,14 @@ static void pgb_static(const char *image_name, 
abi_ulong orig_loaddr,
 if (sizeof(uintptr_t) == 8 || loaddr >= 0x8000u) {
 hiaddr = (uintptr_t) 4 << 30;
 } else {
-offset = -(ARM_COMMPAGE & -align);
+offset = -(HI_COMMPAGE & -align);
 }
 }
 
 addr = pgb_find_hole(loaddr, hiaddr - loaddr, align, offset);
 if (addr == -1) {
 /*
- * If ARM_COMMPAGE, there *might* be a non-consecutive allocation
+ * If HI_COMMPAGE, there *might* be a non-consecutive allocation
  * that can satisfy both.  But as the normal arm32 link base address
  * is ~32k, and we extend down to include the commpage, making the
  * overhead only ~96k, this is unlikely.
@@ -2400,7 +2400,7 @@ static void pgb_dynamic(const char *image_name, long 
align)
  * All we need is a commpage that satisfies align.
  * If we do not need a commpage, leave guest_base == 0.
  */
-if (ARM_COMMPAGE) {
+if (HI_COMMPAGE) {
 uintptr_t addr, commpage;
 
 /* 64-bit hosts should have used reserved_va. */
@@ -2410,7 +2410,7 @@ static void pgb_dynamic(const char *image_name, long 
align)
  * By putting the commpage at the first hole, that puts guest_base
  * just above that, and maximises the positive guest addresses.
  */
-commpage = ARM_COMMPAGE & -align;
+commpage = HI_COMMPAGE & -align;
 addr = pgb_find_hole(commpage, -commpage, align, 0);
 assert(addr != -1);
 guest_base = addr;
-- 
2.33.1




[PULL 21/27] linux-user/nios2: Fix EA vs PC confusion

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

The real kernel will talk about the user PC as EA,
because that's where the hardware will have copied it,
and where it expects to put it to then use ERET.
But qemu does not emulate all of the exception stuff
while emulating user-only.  Manipulate PC directly.

This fixes signal entry and return, and eliminates
some slight confusion from target_cpu_copy_regs.

Signed-off-by: Richard Henderson 
Reviewed-by: Laurent Vivier 
Message-Id: <20211221025012.1057923-6-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/nios2/cpu_loop.c | 5 +
 linux-user/nios2/signal.c   | 6 +++---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
index de0fc63e2196..1e93ef34e649 100644
--- a/linux-user/nios2/cpu_loop.c
+++ b/linux-user/nios2/cpu_loop.c
@@ -155,9 +155,6 @@ void target_cpu_copy_regs(CPUArchState *env, struct 
target_pt_regs *regs)
 env->regs[R_SP] = regs->sp;
 env->regs[R_GP] = regs->gp;
 env->regs[CR_ESTATUS] = regs->estatus;
-env->regs[R_EA] = regs->ea;
-/* TODO: unsigned long  orig_r7; */
-
-/* Emulate eret when starting thread. */
 env->regs[R_PC] = regs->ea;
+/* TODO: unsigned long  orig_r7; */
 }
diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index adbffe32e3c8..20b65aa06e08 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -73,7 +73,7 @@ static void rt_setup_ucontext(struct target_ucontext *uc, 
CPUNios2State *env)
 __put_user(env->regs[R_RA], [23]);
 __put_user(env->regs[R_FP], [24]);
 __put_user(env->regs[R_GP], [25]);
-__put_user(env->regs[R_EA], [27]);
+__put_user(env->regs[R_PC], [27]);
 __put_user(env->regs[R_SP], [28]);
 }
 
@@ -122,7 +122,7 @@ static int rt_restore_ucontext(CPUNios2State *env, struct 
target_ucontext *uc,
 __get_user(env->regs[R_GP], [25]);
 /* Not really necessary no user settable bits */
 __get_user(temp, [26]);
-__get_user(env->regs[R_EA], [27]);
+__get_user(env->regs[R_PC], [27]);
 
 __get_user(env->regs[R_RA], [23]);
 __get_user(env->regs[R_SP], [28]);
@@ -181,7 +181,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 env->regs[4] = sig;
 env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info);
 env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc);
-env->regs[R_EA] = ka->_sa_handler;
+env->regs[R_PC] = ka->_sa_handler;
 
 unlock_user_struct(frame, frame_addr, 1);
 }
-- 
2.33.1




[PULL 20/27] linux-user/nios2: Map a real kuser page

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

The first word of page1 is data, so the whole thing
can't be implemented with emulation of addresses.
Use init_guest_commpage for the allocation.

Hijack trap number 16 to implement cmpxchg.

Signed-off-by: Richard Henderson 
Reviewed-by: Laurent Vivier 
Message-Id: <20211221025012.1057923-5-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/elfload.c| 50 -
 linux-user/nios2/cpu_loop.c | 50 -
 target/nios2/translate.c|  9 ---
 3 files changed, 76 insertions(+), 33 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index d34cd4fe43fb..329b2375ef15 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1099,6 +1099,47 @@ static void init_thread(struct target_pt_regs *regs, 
struct image_info *infop)
 regs->estatus = 0x3;
 }
 
+#define LO_COMMPAGE  TARGET_PAGE_SIZE
+
+static bool init_guest_commpage(void)
+{
+static const uint8_t kuser_page[4 + 2 * 64] = {
+/* __kuser_helper_version */
+[0x00] = 0x02, 0x00, 0x00, 0x00,
+
+/* __kuser_cmpxchg */
+[0x04] = 0x3a, 0x6c, 0x3b, 0x00,  /* trap 16 */
+ 0x3a, 0x28, 0x00, 0xf8,  /* ret */
+
+/* __kuser_sigtramp */
+[0x44] = 0xc4, 0x22, 0x80, 0x00,  /* movi r2, __NR_rt_sigreturn */
+ 0x3a, 0x68, 0x3b, 0x00,  /* trap 0 */
+};
+
+void *want = g2h_untagged(LO_COMMPAGE & -qemu_host_page_size);
+void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE,
+  MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
+
+if (addr == MAP_FAILED) {
+perror("Allocating guest commpage");
+exit(EXIT_FAILURE);
+}
+if (addr != want) {
+return false;
+}
+
+memcpy(addr, kuser_page, sizeof(kuser_page));
+
+if (mprotect(addr, qemu_host_page_size, PROT_READ)) {
+perror("Protecting guest commpage");
+exit(EXIT_FAILURE);
+}
+
+page_set_flags(LO_COMMPAGE, LO_COMMPAGE + TARGET_PAGE_SIZE,
+   PAGE_READ | PAGE_EXEC | PAGE_VALID);
+return true;
+}
+
 #define ELF_EXEC_PAGESIZE4096
 
 #define USE_ELF_CORE_DUMP
@@ -2160,8 +2201,13 @@ static abi_ulong create_elf_tables(abi_ulong p, int 
argc, int envc,
 return sp;
 }
 
-#ifndef HI_COMMPAGE
+#if defined(HI_COMMPAGE)
+#define LO_COMMPAGE 0
+#elif defined(LO_COMMPAGE)
+#define HI_COMMPAGE 0
+#else
 #define HI_COMMPAGE 0
+#define LO_COMMPAGE 0
 #define init_guest_commpage() true
 #endif
 
@@ -2374,6 +2420,8 @@ static void pgb_static(const char *image_name, abi_ulong 
orig_loaddr,
 } else {
 offset = -(HI_COMMPAGE & -align);
 }
+} else if (LO_COMMPAGE) {
+loaddr = MIN(loaddr, LO_COMMPAGE & -align);
 }
 
 addr = pgb_find_hole(loaddr, hiaddr - loaddr, align, offset);
diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
index 5c3d01d22dd7..de0fc63e2196 100644
--- a/linux-user/nios2/cpu_loop.c
+++ b/linux-user/nios2/cpu_loop.c
@@ -76,6 +76,32 @@ void cpu_loop(CPUNios2State *env)
 force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLTRP,
 env->regs[R_PC]);
 break;
+
+case 16: /* QEMU specific, for __kuser_cmpxchg */
+{
+abi_ptr g = env->regs[4];
+uint32_t *h, n, o;
+
+if (g & 0x3) {
+force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, g);
+break;
+}
+ret = page_get_flags(g);
+if (!(ret & PAGE_VALID)) {
+force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, g);
+break;
+}
+if (!(ret & PAGE_READ) || !(ret & PAGE_WRITE)) {
+force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_ACCERR, g);
+break;
+}
+h = g2h(cs, g);
+o = env->regs[5];
+n = env->regs[6];
+env->regs[2] = qatomic_cmpxchg(h, o, n) - o;
+env->regs[R_PC] += 4;
+}
+break;
 }
 break;
 
@@ -86,29 +112,7 @@ void cpu_loop(CPUNios2State *env)
 queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
 break;
 case 0xaa:
-switch (env->regs[R_PC]) {
-/*case 0x1000:*/  /* TODO:__kuser_helper_version */
-case 0x1004:  /* __kuser_cmpxchg */
-start_exclusive();
-if (env->regs[4] & 0x3) {
-goto kuser_fail;
-}
-ret = get_user_u32(env->regs[2], env->regs[4]);
-  

[PULL 24/27] linux-user/syscall.c: malloc to g_try_malloc

2022-01-06 Thread Laurent Vivier
From: Ahmed Abouzied 

Use g_try_malloc instead of malloc to alocate the target ifconfig.
Also replace the corresponding free with g_free.

Signed-off-by: Ahmed Abouzied 
Message-Id: <20220104143841.25116-1-em...@aabouzied.com>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3160d77154b5..ce9d64896cb8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4915,7 +4915,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, 
uint8_t *buf_temp,
  * We can't fit all the extents into the fixed size buffer.
  * Allocate one that is large enough and use it instead.
  */
-host_ifconf = malloc(outbufsz);
+host_ifconf = g_try_malloc(outbufsz);
 if (!host_ifconf) {
 return -TARGET_ENOMEM;
 }
@@ -4963,7 +4963,7 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, 
uint8_t *buf_temp,
 }
 
 if (free_buf) {
-free(host_ifconf);
+g_free(host_ifconf);
 }
 
 return ret;
-- 
2.33.1




Re: [PATCH] linux-user: Remove the deprecated ppc64abi32 target

2022-01-06 Thread Laurent Vivier

Le 20/12/2021 à 17:01, Laurent Vivier a écrit :

Le 15/12/2021 à 09:49, Thomas Huth a écrit :

It's likely broken, and nobody cared for picking it up again
during the deprecation phase, so let's remove this now.

Since this is the last entry in deprecated_targets_list, remove
the related code in the configure script, too.

Signed-off-by: Thomas Huth 
---
  .gitlab-ci.d/buildtest.yml    | 27 -
  configs/targets/ppc64abi32-linux-user.mak |  8 -
  configure | 29 +--
  docs/about/deprecated.rst |  7 -
  docs/about/removed-features.rst   |  8 +
  docs/user/main.rst    |  1 -
  linux-user/elfload.c  |  4 +--
  linux-user/ppc/signal.c   | 11 ++-
  linux-user/ppc/target_syscall.h   |  4 +--
  linux-user/syscall_defs.h |  6 ++--
  .../dockerfiles/debian-ppc64el-cross.docker   |  2 +-
  tests/tcg/configure.sh    |  2 +-
  12 files changed, 21 insertions(+), 88 deletions(-)
  delete mode 100644 configs/targets/ppc64abi32-linux-user.mak



Applied to my linux-user-for-7.0 branch.


I've removed the patch from my series as Alex has added it to his testing/next 
branch.
As it modifies the gitlab CI and the dockerfiles, I think it better fits in his 
branch.

Thanks,
Laurent



[PULL 27/27] linux-user: netlink: update IFLA_BRPORT entries

2022-01-06 Thread Laurent Vivier
add IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT and IFLA_BRPORT_MCAST_EHT_HOSTS_CNT

  # QEMU_LOG=unimp ip a
  Unknown QEMU_IFLA_BRPORT type 37
  Unknown QEMU_IFLA_BRPORT type 38

Signed-off-by: Laurent Vivier 
Reviewed-by: Richard Henderson 
Message-Id: <20211219154514.2165728-3-laur...@vivier.eu>
Signed-off-by: Laurent Vivier 
---
 linux-user/fd-trans.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
index 36e4a4c2aae8..a17d05c07923 100644
--- a/linux-user/fd-trans.c
+++ b/linux-user/fd-trans.c
@@ -182,6 +182,8 @@ enum {
 QEMU_IFLA_BRPORT_BACKUP_PORT,
 QEMU_IFLA_BRPORT_MRP_RING_OPEN,
 QEMU_IFLA_BRPORT_MRP_IN_OPEN,
+QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT,
+QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_CNT,
 QEMU___IFLA_BRPORT_MAX
 };
 
@@ -607,6 +609,8 @@ static abi_long 
host_to_target_slave_data_bridge_nlattr(struct nlattr *nlattr,
 /* uin32_t */
 case QEMU_IFLA_BRPORT_COST:
 case QEMU_IFLA_BRPORT_BACKUP_PORT:
+case QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT:
+case QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_CNT:
 u32 = NLA_DATA(nlattr);
 *u32 = tswap32(*u32);
 break;
-- 
2.33.1




[PULL 18/27] linux-user/nios2: Fixes for signal frame setup

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

Do not confuse host and guest addresses.  Lock and unlock
the target_rt_sigframe structure in setup_rt_sigframe.

Since rt_setup_ucontext always returns 0, drop the return
value entirely.  This eliminates the only write to the err
variable in setup_rt_sigframe.

Always copy the siginfo structure.

Reviewed-by: Alex Bennée 
Reviewed-by: Peter Maydell 
Signed-off-by: Richard Henderson 
Message-Id: <20211221025012.1057923-3-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/nios2/signal.c | 51 ---
 1 file changed, 21 insertions(+), 30 deletions(-)

diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index a77e8a40f468..adbffe32e3c8 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -42,7 +42,7 @@ struct target_rt_sigframe {
 struct target_ucontext uc;
 };
 
-static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
+static void rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
 {
 unsigned long *gregs = uc->tuc_mcontext.gregs;
 
@@ -75,8 +75,6 @@ static int rt_setup_ucontext(struct target_ucontext *uc, 
CPUNios2State *env)
 __put_user(env->regs[R_GP], [25]);
 __put_user(env->regs[R_EA], [27]);
 __put_user(env->regs[R_SP], [28]);
-
-return 0;
 }
 
 static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc,
@@ -135,8 +133,8 @@ static int rt_restore_ucontext(CPUNios2State *env, struct 
target_ucontext *uc,
 return 0;
 }
 
-static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
-  size_t frame_size)
+static abi_ptr get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
+size_t frame_size)
 {
 unsigned long usp;
 
@@ -144,7 +142,7 @@ static void *get_sigframe(struct target_sigaction *ka, 
CPUNios2State *env,
 usp = target_sigsp(get_sp_from_cpustate(env), ka);
 
 /* Verify, is it 32 or 64 bit aligned */
-return (void *)((usp - frame_size) & -8UL);
+return (usp - frame_size) & -8;
 }
 
 void setup_rt_frame(int sig, struct target_sigaction *ka,
@@ -153,26 +151,25 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 CPUNios2State *env)
 {
 struct target_rt_sigframe *frame;
-int i, err = 0;
+abi_ptr frame_addr;
+int i;
 
-frame = get_sigframe(ka, env, sizeof(*frame));
-
-if (ka->sa_flags & SA_SIGINFO) {
-tswap_siginfo(>info, info);
+frame_addr = get_sigframe(ka, env, sizeof(*frame));
+if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
+force_sigsegv(sig);
+return;
 }
 
+tswap_siginfo(>info, info);
+
 /* Create the ucontext.  */
 __put_user(0, >uc.tuc_flags);
 __put_user(0, >uc.tuc_link);
 target_save_altstack(>uc.tuc_stack, env);
-err |= rt_setup_ucontext(>uc, env);
+rt_setup_ucontext(>uc, env);
 for (i = 0; i < TARGET_NSIG_WORDS; i++) {
 __put_user((abi_ulong)set->sig[i],
-(abi_ulong *)>uc.tuc_sigmask.sig[i]);
-}
-
-if (err) {
-goto give_sigsegv;
+   (abi_ulong *)>uc.tuc_sigmask.sig[i]);
 }
 
 /* Set up to return from userspace; jump to fixed address sigreturn
@@ -180,19 +177,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 env->regs[R_RA] = (unsigned long) (0x1044);
 
 /* Set up registers for signal handler */
-env->regs[R_SP] = (unsigned long) frame;
-env->regs[4] = (unsigned long) sig;
-env->regs[5] = (unsigned long) >info;
-env->regs[6] = (unsigned long) >uc;
-env->regs[R_EA] = (unsigned long) ka->_sa_handler;
-return;
-
-give_sigsegv:
-if (sig == TARGET_SIGSEGV) {
-ka->_sa_handler = TARGET_SIG_DFL;
-}
-force_sigsegv(sig);
-return;
+env->regs[R_SP] = frame_addr;
+env->regs[4] = sig;
+env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info);
+env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc);
+env->regs[R_EA] = ka->_sa_handler;
+
+unlock_user_struct(frame, frame_addr, 1);
 }
 
 long do_sigreturn(CPUNios2State *env)
-- 
2.33.1




[PULL 05/27] linux-user: target_syscall.h remove definition TARGET_MINSIGSTKSZ

2022-01-06 Thread Laurent Vivier
From: Song Gao 

TARGET_MINSIGSTKSZ has been defined in generic/signal.h
or target_signal.h, We don't need to define it again.

Signed-off-by: Song Gao 
Reviewed-by: Laurent Vivier 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Richard Henderson 
Message-Id: <1637893388-10282-3-git-send-email-gaos...@loongson.cn>
Signed-off-by: Laurent Vivier 
---
 linux-user/aarch64/target_syscall.h| 1 -
 linux-user/alpha/target_syscall.h  | 1 -
 linux-user/arm/target_syscall.h| 1 -
 linux-user/cris/target_syscall.h   | 1 -
 linux-user/hppa/target_syscall.h   | 1 -
 linux-user/i386/target_syscall.h   | 1 -
 linux-user/m68k/target_syscall.h   | 1 -
 linux-user/microblaze/target_syscall.h | 1 -
 linux-user/mips/target_syscall.h   | 1 -
 linux-user/mips64/target_syscall.h | 1 -
 linux-user/nios2/target_syscall.h  | 1 -
 linux-user/openrisc/target_syscall.h   | 1 -
 linux-user/ppc/target_syscall.h| 1 -
 linux-user/riscv/target_syscall.h  | 1 -
 linux-user/s390x/target_syscall.h  | 1 -
 linux-user/sh4/target_syscall.h| 1 -
 linux-user/sparc/target_syscall.h  | 1 -
 linux-user/x86_64/target_syscall.h | 1 -
 18 files changed, 18 deletions(-)

diff --git a/linux-user/aarch64/target_syscall.h 
b/linux-user/aarch64/target_syscall.h
index 76f6c3391d33..508219d62aba 100644
--- a/linux-user/aarch64/target_syscall.h
+++ b/linux-user/aarch64/target_syscall.h
@@ -15,7 +15,6 @@ struct target_pt_regs {
 #endif
 #define UNAME_MINIMUM_RELEASE "3.8.0"
 #define TARGET_CLONE_BACKWARDS
-#define TARGET_MINSIGSTKSZ   2048
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
diff --git a/linux-user/alpha/target_syscall.h 
b/linux-user/alpha/target_syscall.h
index 03091bf0a826..fda3a49f29be 100644
--- a/linux-user/alpha/target_syscall.h
+++ b/linux-user/alpha/target_syscall.h
@@ -63,7 +63,6 @@ struct target_pt_regs {
 #define TARGET_UAC_NOPRINT 1
 #define TARGET_UAC_NOFIX   2
 #define TARGET_UAC_SIGBUS  4
-#define TARGET_MINSIGSTKSZ  4096
 #define TARGET_MCL_CURRENT 0x2000
 #define TARGET_MCL_FUTURE  0x4000
 #define TARGET_MCL_ONFAULT 0x8000
diff --git a/linux-user/arm/target_syscall.h b/linux-user/arm/target_syscall.h
index e870ed7a5468..f04f9c9e3d75 100644
--- a/linux-user/arm/target_syscall.h
+++ b/linux-user/arm/target_syscall.h
@@ -27,7 +27,6 @@ struct target_pt_regs {
 
 #define TARGET_CLONE_BACKWARDS
 
-#define TARGET_MINSIGSTKSZ 2048
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
diff --git a/linux-user/cris/target_syscall.h b/linux-user/cris/target_syscall.h
index 19e12814039c..0b5ebf1f0283 100644
--- a/linux-user/cris/target_syscall.h
+++ b/linux-user/cris/target_syscall.h
@@ -39,7 +39,6 @@ struct target_pt_regs {
 };
 
 #define TARGET_CLONE_BACKWARDS2
-#define TARGET_MINSIGSTKSZ 2048
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
diff --git a/linux-user/hppa/target_syscall.h b/linux-user/hppa/target_syscall.h
index 0018bcb5c4dc..4b382c1fcf4a 100644
--- a/linux-user/hppa/target_syscall.h
+++ b/linux-user/hppa/target_syscall.h
@@ -22,7 +22,6 @@ struct target_pt_regs {
 #define UNAME_MACHINE "parisc"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 #define TARGET_CLONE_BACKWARDS
-#define TARGET_MINSIGSTKSZ   2048
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
diff --git a/linux-user/i386/target_syscall.h b/linux-user/i386/target_syscall.h
index ed356b3908dc..aaade06b136a 100644
--- a/linux-user/i386/target_syscall.h
+++ b/linux-user/i386/target_syscall.h
@@ -150,7 +150,6 @@ struct target_vm86plus_struct {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS
-#define TARGET_MINSIGSTKSZ 2048
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
diff --git a/linux-user/m68k/target_syscall.h b/linux-user/m68k/target_syscall.h
index 23359a6299dd..8d4ddbd76c8f 100644
--- a/linux-user/m68k/target_syscall.h
+++ b/linux-user/m68k/target_syscall.h
@@ -20,7 +20,6 @@ struct target_pt_regs {
 #define UNAME_MACHINE "m68k"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
-#define TARGET_MINSIGSTKSZ 2048
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
diff --git a/linux-user/microblaze/target_syscall.h 
b/linux-user/microblaze/target_syscall.h
index 7f653db34f87..43362a1664ca 100644
--- a/linux-user/microblaze/target_syscall.h
+++ b/linux-user/microblaze/target_syscall.h
@@ -49,7 +49,6 @@ struct target_pt_regs {
 };
 
 #define TARGET_CLONE_BACKWARDS
-#define TARGET_MINSIGSTKSZ  2048
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
diff --git a/linux-user/mips/target_syscall.h b/linux-user/mips/target_syscall.h
index f59057493a35..7a82661fdb47 1

[PULL 22/27] linux-user/nios2: Fix sigmask in setup_rt_frame

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

Do not cast the signal mask elements; trust __put_user.

Reviewed-by: Laurent Vivier 
Signed-off-by: Richard Henderson 
Message-Id: <20211221025012.1057923-7-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/nios2/signal.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index 20b65aa06e08..80e3d42fc965 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -168,8 +168,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 target_save_altstack(>uc.tuc_stack, env);
 rt_setup_ucontext(>uc, env);
 for (i = 0; i < TARGET_NSIG_WORDS; i++) {
-__put_user((abi_ulong)set->sig[i],
-   (abi_ulong *)>uc.tuc_sigmask.sig[i]);
+__put_user(set->sig[i], >uc.tuc_sigmask.sig[i]);
 }
 
 /* Set up to return from userspace; jump to fixed address sigreturn
-- 
2.33.1




[PULL 25/27] linux-user: netlink: update IFLA entries

2022-01-06 Thread Laurent Vivier
Add IFLA_PHYS_PORT_ID, IFLA_PARENT_DEV_NAME, IFLA_PARENT_DEV_BUS_NAME

  # QEMU_LOG=unimp ip a
  Unknown host QEMU_IFLA type: 56
  Unknown host QEMU_IFLA type: 57
  Unknown host QEMU_IFLA type: 34

Signed-off-by: Laurent Vivier 
Reviewed-by: Richard Henderson 
Message-Id: <20211219154514.2165728-1-laur...@vivier.eu>
Signed-off-by: Laurent Vivier 
---
 linux-user/fd-trans.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
index 69410899590c..14c19a90b2b0 100644
--- a/linux-user/fd-trans.c
+++ b/linux-user/fd-trans.c
@@ -138,6 +138,9 @@ enum {
 QEMU_IFLA_PROP_LIST,
 QEMU_IFLA_ALT_IFNAME,
 QEMU_IFLA_PERM_ADDRESS,
+QEMU_IFLA_PROTO_DOWN_REASON,
+QEMU_IFLA_PARENT_DEV_NAME,
+QEMU_IFLA_PARENT_DEV_BUS_NAME,
 QEMU___IFLA_MAX
 };
 
@@ -818,9 +821,12 @@ static abi_long host_to_target_data_link_rtattr(struct 
rtattr *rtattr)
 case QEMU_IFLA_ADDRESS:
 case QEMU_IFLA_BROADCAST:
 case QEMU_IFLA_PERM_ADDRESS:
+case QEMU_IFLA_PHYS_PORT_ID:
 /* string */
 case QEMU_IFLA_IFNAME:
 case QEMU_IFLA_QDISC:
+case QEMU_IFLA_PARENT_DEV_NAME:
+case QEMU_IFLA_PARENT_DEV_BUS_NAME:
 break;
 /* uin8_t */
 case QEMU_IFLA_OPERSTATE:
-- 
2.33.1




[PULL 16/27] linux-user/syscall.c: fix missed flag for shared memory in open_self_maps

2022-01-06 Thread Laurent Vivier
From: Andrey Kazmin 

The possible variants for region type in /proc/self/maps are either
private "p" or shared "s". In the current implementation,
we mark shared regions as "-". It could break memory mapping parsers
such as included into ASan/HWASan sanitizers.

Fixes: 01ef6b9e4e4e ("linux-user: factor out reading of /proc/self/maps")
Signed-off-by: Andrey Kazmin 
Reviewed-by: Laurent Vivier 
Acked-by: Alex Bennée 
Message-Id: <20211227125048.22610-1-a.kaz...@partner.samsung.com>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 01cd59cdce53..3160d77154b5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8045,7 +8045,7 @@ static int open_self_maps(void *cpu_env, int fd)
 (flags & PAGE_READ) ? 'r' : '-',
 (flags & PAGE_WRITE_ORG) ? 'w' : '-',
 (flags & PAGE_EXEC) ? 'x' : '-',
-e->is_priv ? 'p' : '-',
+e->is_priv ? 'p' : 's',
 (uint64_t) e->offset, e->dev, e->inode);
 if (path) {
 dprintf(fd, "%*s%s\n", 73 - count, "", path);
-- 
2.33.1




[PULL 00/27] Linux user for 7.0 patches

2022-01-06 Thread Laurent Vivier
The following changes since commit fb084237a3b78b20fd9d888dffd673b6656ea3be:

  common-user: Really fix i386 calls to safe_syscall_set_errno_tail (2022-01-04 
21:14:23 -0800)

are available in the Git repository at:

  https://gitlab.com/laurent_vivier/qemu.git 
tags/linux-user-for-7.0-pull-request

for you to fetch changes up to f0effdbc2a5b43422bc4c9c22641ef9dafa0c7ae:

  linux-user: netlink: update IFLA_BRPORT entries (2022-01-06 11:40:53 +0100)


linux-user pull request 20220106

update netlink entries
nios2 fixes
/proc/self/maps fixes
set/getscheduler update
prctl cleanup and fixes
target_signal.h cleanup
and some trivial fixes



Ahmed Abouzied (1):
  linux-user/syscall.c: malloc to g_try_malloc

Andrey Kazmin (1):
  linux-user/syscall.c: fix missed flag for shared memory in
open_self_maps

Laurent Vivier (3):
  linux-user: netlink: update IFLA entries
  linux-user: netlink: Add IFLA_VFINFO_LIST
  linux-user: netlink: update IFLA_BRPORT entries

Martin Wilck (1):
  qemu-binfmt-conf.sh: fix -F option

Matthias Schiffer (1):
  linux-user/signal: Map exit signals in SIGCHLD siginfo_t

Philippe Mathieu-Daudé (2):
  linux-user/hexagon: Use generic target_stat64 structure
  linux-user: Mark cpu_loop() with noreturn attribute

Richard Henderson (13):
  linux-user: Split out do_prctl and subroutines
  linux-user: Disable more prctl subcodes
  linux-user: Add code for PR_GET/SET_UNALIGN
  target/alpha: Implement prctl_unalign_sigbus
  target/hppa: Implement prctl_unalign_sigbus
  target/sh4: Implement prctl_unalign_sigbus
  linux-user/nios2: Properly emulate EXCP_TRAP
  linux-user/nios2: Fixes for signal frame setup
  linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE
  linux-user/nios2: Map a real kuser page
  linux-user/nios2: Fix EA vs PC confusion
  linux-user/nios2: Fix sigmask in setup_rt_frame
  linux-user/nios2: Use set_sigmask in do_rt_sigreturn

Song Gao (3):
  linux-user: Move target_signal.h generic definitions to
generic/signal.h
  linux-user: target_syscall.h remove definition TARGET_MINSIGSTKSZ
  linux-user: Remove TARGET_SIGSTKSZ

Tonis Tiigi (2):
  linux-user: add sched_getattr support
  linux-user: call set/getscheduler set/getparam directly

 cpu.c |  20 +-
 include/hw/core/cpu.h |   3 +
 linux-user/aarch64/target_prctl.h | 160 ++
 linux-user/aarch64/target_signal.h|  18 -
 linux-user/aarch64/target_syscall.h   |  24 -
 linux-user/alpha/target_prctl.h   |   1 +
 linux-user/alpha/target_signal.h  |   1 -
 linux-user/alpha/target_syscall.h |   1 -
 linux-user/arm/target_prctl.h |   1 +
 linux-user/arm/target_signal.h|  18 -
 linux-user/arm/target_syscall.h   |   1 -
 linux-user/cris/target_prctl.h|   1 +
 linux-user/cris/target_signal.h   |  18 -
 linux-user/cris/target_syscall.h  |   1 -
 linux-user/elfload.c  |  66 ++-
 linux-user/fd-trans.c | 184 ++
 linux-user/generic/signal.h   |  15 +
 linux-user/generic/target_prctl_unalign.h |  27 +
 linux-user/hexagon/target_prctl.h |   1 +
 linux-user/hexagon/target_signal.h|  11 -
 linux-user/hppa/target_prctl.h|   1 +
 linux-user/hppa/target_signal.h   |   1 -
 linux-user/hppa/target_syscall.h  |   1 -
 linux-user/i386/target_prctl.h|   1 +
 linux-user/i386/target_signal.h   |  18 -
 linux-user/i386/target_syscall.h  |   1 -
 linux-user/m68k/target_prctl.h|   1 +
 linux-user/m68k/target_signal.h   |  18 -
 linux-user/m68k/target_syscall.h  |   1 -
 linux-user/microblaze/target_prctl.h  |   1 +
 linux-user/microblaze/target_signal.h |  18 -
 linux-user/microblaze/target_syscall.h|   1 -
 linux-user/mips/target_prctl.h|  88 +++
 linux-user/mips/target_signal.h   |   1 -
 linux-user/mips/target_syscall.h  |   7 -
 linux-user/mips64/target_prctl.h  |   1 +
 linux-user/mips64/target_signal.h |   1 -
 linux-user/mips64/target_syscall.h|   7 -
 linux-user/nios2/cpu_loop.c   |  93 +--
 linux-user/nios2/signal.c |  58 +-
 linux-user/nios2/target_prctl.h   |   1 +
 linux-user/nios2/target_signal.h  |  16 -
 linux-user/nios2/target_syscall.h |   1 -
 linux-user/openrisc/target_prctl.h|   1 +
 linux-user/openrisc/target_signal.h   |  23 -
 linux-user/openrisc/target_syscall.h  |   1 -
 linux-user/ppc/target_prctl.h |   1 +
 linux-user/ppc/target_signal.h|  18 -
 linux-user/ppc/target_syscall.h   |   1 -
 linux-user/riscv/target_prctl.h   |   1 +
 linux-user/riscv/target_signal.h  |  12 -
 linux-user/riscv/target_syscall.h

[PULL 23/27] linux-user/nios2: Use set_sigmask in do_rt_sigreturn

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

Using do_sigprocmask directly was incorrect, as it will
leave the signal blocked by the outer layers of linux-user.

Reviewed-by: Laurent Vivier 
Signed-off-by: Richard Henderson 
Message-Id: <20211221025012.1057923-8-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/nios2/signal.c | 2 +-
 linux-user/signal.c   | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index 80e3d42fc965..517cd392701c 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -205,7 +205,7 @@ long do_rt_sigreturn(CPUNios2State *env)
 }
 
 target_to_host_sigset(, >uc.tuc_sigmask);
-do_sigprocmask(SIG_SETMASK, , NULL);
+set_sigmask();
 
 if (rt_restore_ucontext(env, >uc, )) {
 goto badframe;
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 1229fecf5cd4..f813b4f18e44 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -258,7 +258,6 @@ int do_sigprocmask(int how, const sigset_t *set, sigset_t 
*oldset)
 return 0;
 }
 
-#if !defined(TARGET_NIOS2)
 /* Just set the guest's signal mask to the specified value; the
  * caller is assumed to have called block_signals() already.
  */
@@ -268,7 +267,6 @@ void set_sigmask(const sigset_t *set)
 
 ts->signal_mask = *set;
 }
-#endif
 
 /* sigaltstack management */
 
-- 
2.33.1




[PULL 02/27] linux-user/hexagon: Use generic target_stat64 structure

2022-01-06 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

Linux Hexagon port doesn't define a specific 'struct stat'
but uses the generic one (see Linux commit 6103ec56c65c [*]
"asm-generic: add generic ABI headers" which predates the
introduction of the Hexagon port).

Remove the target specific target_stat (which in fact is the
target_stat64 structure but uses incorrect target_long and
ABI unsafe long long types) and use the generic target_stat64
instead.

[*] 
https://github.com/torvalds/linux/commit/6103ec56c65c3#diff-5f59b07b38273b7d6a74193bc81a8cd18928c688276eae20cb10c569de3253ee

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Richard Henderson 
Reviewed-by: Taylor Simpson 
Tested-by: Taylor Simpson 
Message-Id: <2026210919.2823206-1-f4...@amsat.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall_defs.h | 28 ++--
 1 file changed, 2 insertions(+), 26 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 0b139759377b..585e933140ac 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2133,7 +2133,8 @@ struct target_stat64  {
 abi_ulong __unused5;
 };
 
-#elif defined(TARGET_OPENRISC) || defined(TARGET_NIOS2) || 
defined(TARGET_RISCV)
+#elif defined(TARGET_OPENRISC) || defined(TARGET_NIOS2) \
+|| defined(TARGET_RISCV) || defined(TARGET_HEXAGON)
 
 /* These are the asm-generic versions of the stat and stat64 structures */
 
@@ -2244,31 +2245,6 @@ struct target_stat64 {
 uint64_t   st_ino;
 };
 
-#elif defined(TARGET_HEXAGON)
-
-struct target_stat {
-unsigned long long st_dev;
-unsigned long long st_ino;
-unsigned int st_mode;
-unsigned int st_nlink;
-unsigned int st_uid;
-unsigned int st_gid;
-unsigned long long st_rdev;
-target_ulong __pad1;
-long long st_size;
-target_long st_blksize;
-int __pad2;
-long long st_blocks;
-
-target_long target_st_atime;
-target_long target_st_atime_nsec;
-target_long target_st_mtime;
-target_long target_st_mtime_nsec;
-target_long target_st_ctime;
-target_long target_st_ctime_nsec;
-int __unused[2];
-};
-
 #else
 #error unsupported CPU
 #endif
-- 
2.33.1




[PULL 11/27] target/hppa: Implement prctl_unalign_sigbus

2022-01-06 Thread Laurent Vivier
From: Richard Henderson 

Leave TARGET_ALIGNED_ONLY set, but use the new CPUState
flag to set MO_UNALN for the instructions that the kernel
handles in the unaligned trap.

Signed-off-by: Richard Henderson 
Reviewed-by: Laurent Vivier 
Message-Id: <20211227150127.2659293-6-richard.hender...@linaro.org>
Signed-off-by: Laurent Vivier 
---
 linux-user/hppa/target_prctl.h |  2 +-
 target/hppa/cpu.h  |  5 -
 target/hppa/translate.c| 19 +++
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/linux-user/hppa/target_prctl.h b/linux-user/hppa/target_prctl.h
index eb53b31ad554..5629ddbf39cd 100644
--- a/linux-user/hppa/target_prctl.h
+++ b/linux-user/hppa/target_prctl.h
@@ -1 +1 @@
-/* No special prctl support required. */
+#include "../generic/target_prctl_unalign.h"
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 294fd7297f91..45fd338b02f8 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -259,12 +259,14 @@ static inline target_ulong hppa_form_gva(CPUHPPAState 
*env, uint64_t spc,
 return hppa_form_gva_psw(env->psw, spc, off);
 }
 
-/* Since PSW_{I,CB} will never need to be in tb->flags, reuse them.
+/*
+ * Since PSW_{I,CB} will never need to be in tb->flags, reuse them.
  * TB_FLAG_SR_SAME indicates that SR4 through SR7 all contain the
  * same value.
  */
 #define TB_FLAG_SR_SAME PSW_I
 #define TB_FLAG_PRIV_SHIFT  8
+#define TB_FLAG_UNALIGN 0x400
 
 static inline void cpu_get_tb_cpu_state(CPUHPPAState *env, target_ulong *pc,
 target_ulong *cs_base,
@@ -279,6 +281,7 @@ static inline void cpu_get_tb_cpu_state(CPUHPPAState *env, 
target_ulong *pc,
 #ifdef CONFIG_USER_ONLY
 *pc = env->iaoq_f & -4;
 *cs_base = env->iaoq_b & -4;
+flags |= TB_FLAG_UNALIGN * !env_cpu(env)->prctl_unalign_sigbus;
 #else
 /* ??? E, T, H, L, B, P bits need to be here, when implemented.  */
 flags |= env->psw & (PSW_W | PSW_C | PSW_D);
diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index 952027a28e12..a2392a1b64a4 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -274,8 +274,18 @@ typedef struct DisasContext {
 int mmu_idx;
 int privilege;
 bool psw_n_nonzero;
+
+#ifdef CONFIG_USER_ONLY
+MemOp unalign;
+#endif
 } DisasContext;
 
+#ifdef CONFIG_USER_ONLY
+#define UNALIGN(C)  (C)->unalign
+#else
+#define UNALIGN(C)  0
+#endif
+
 /* Note that ssm/rsm instructions number PSW_W and PSW_E differently.  */
 static int expand_sm_imm(DisasContext *ctx, int val)
 {
@@ -1475,7 +1485,7 @@ static void do_load_32(DisasContext *ctx, TCGv_i32 dest, 
unsigned rb,
 
 form_gva(ctx, , , rb, rx, scale, disp, sp, modify,
  ctx->mmu_idx == MMU_PHYS_IDX);
-tcg_gen_qemu_ld_reg(dest, addr, ctx->mmu_idx, mop);
+tcg_gen_qemu_ld_reg(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
 if (modify) {
 save_gpr(ctx, rb, ofs);
 }
@@ -1493,7 +1503,7 @@ static void do_load_64(DisasContext *ctx, TCGv_i64 dest, 
unsigned rb,
 
 form_gva(ctx, , , rb, rx, scale, disp, sp, modify,
  ctx->mmu_idx == MMU_PHYS_IDX);
-tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop);
+tcg_gen_qemu_ld_i64(dest, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
 if (modify) {
 save_gpr(ctx, rb, ofs);
 }
@@ -1511,7 +1521,7 @@ static void do_store_32(DisasContext *ctx, TCGv_i32 src, 
unsigned rb,
 
 form_gva(ctx, , , rb, rx, scale, disp, sp, modify,
  ctx->mmu_idx == MMU_PHYS_IDX);
-tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop);
+tcg_gen_qemu_st_i32(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
 if (modify) {
 save_gpr(ctx, rb, ofs);
 }
@@ -1529,7 +1539,7 @@ static void do_store_64(DisasContext *ctx, TCGv_i64 src, 
unsigned rb,
 
 form_gva(ctx, , , rb, rx, scale, disp, sp, modify,
  ctx->mmu_idx == MMU_PHYS_IDX);
-tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop);
+tcg_gen_qemu_st_i64(src, addr, ctx->mmu_idx, mop | UNALIGN(ctx));
 if (modify) {
 save_gpr(ctx, rb, ofs);
 }
@@ -4107,6 +4117,7 @@ static void hppa_tr_init_disas_context(DisasContextBase 
*dcbase, CPUState *cs)
 ctx->mmu_idx = MMU_USER_IDX;
 ctx->iaoq_f = ctx->base.pc_first | MMU_USER_IDX;
 ctx->iaoq_b = ctx->base.tb->cs_base | MMU_USER_IDX;
+ctx->unalign = (ctx->tb_flags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN);
 #else
 ctx->privilege = (ctx->tb_flags >> TB_FLAG_PRIV_SHIFT) & 3;
 ctx->mmu_idx = (ctx->tb_flags & PSW_D ? ctx->privilege : MMU_PHYS_IDX);
-- 
2.33.1




  1   2   3   4   5   6   7   8   9   10   >