Re: [RFC PATCH v5 1/4] target/riscv: Add smstateen support

2022-06-15 Thread Alistair Francis
On Sat, Jun 4, 2022 at 2:13 AM Mayuresh Chitale
 wrote:
>
> Smstateen extension specifies a mechanism to close
> the potential covert channels that could cause security issues.
>
> This patch adds the CSRs defined in the specification and
> the corresponding predicates and read/write functions.
>
> Signed-off-by: Mayuresh Chitale 
> ---
>  target/riscv/cpu.c  |   2 +
>  target/riscv/cpu.h  |   4 +
>  target/riscv/cpu_bits.h |  36 +++
>  target/riscv/csr.c  | 210 
>  target/riscv/machine.c  |  21 
>  5 files changed, 273 insertions(+)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index e6e878ceb3..2d65ccd90f 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -913,6 +913,7 @@ static Property riscv_cpu_properties[] = {
>  DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
>  DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
>  DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
> +DEFINE_PROP_BOOL("smstateen", RISCVCPU, cfg.ext_smstateen, false),

This allows a user to enable this extension. It should be a seperate
patch at the end of the series. The idea is that we add support, then
once it's fully supported we allow a user to enable the extension.

>
>  DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
>  DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
> @@ -1104,6 +1105,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char 
> **isa_str, int max_str_len)
>  ISA_EDATA_ENTRY(zve64f, ext_zve64f),
>  ISA_EDATA_ENTRY(zhinx, ext_zhinx),
>  ISA_EDATA_ENTRY(zhinxmin, ext_zhinxmin),
> +ISA_EDATA_ENTRY(smstateen, ext_smstateen),
>  ISA_EDATA_ENTRY(svinval, ext_svinval),
>  ISA_EDATA_ENTRY(svnapot, ext_svnapot),
>  ISA_EDATA_ENTRY(svpbmt, ext_svpbmt),
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index f08c3e8813..1c269b77bd 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -327,6 +327,9 @@ struct CPUArchState {
>
>  /* CSRs for execution enviornment configuration */
>  uint64_t menvcfg;
> +uint64_t mstateen[SMSTATEEN_MAX_COUNT];
> +uint64_t hstateen[SMSTATEEN_MAX_COUNT];
> +uint64_t sstateen[SMSTATEEN_MAX_COUNT];
>  target_ulong senvcfg;
>  uint64_t henvcfg;
>  #endif
> @@ -411,6 +414,7 @@ struct RISCVCPUConfig {
>  bool ext_zhinxmin;
>  bool ext_zve32f;
>  bool ext_zve64f;
> +bool ext_smstateen;
>
>  uint32_t mvendorid;
>  uint64_t marchid;
> diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> index 4a55c6a709..2a3ef26d21 100644
> --- a/target/riscv/cpu_bits.h
> +++ b/target/riscv/cpu_bits.h
> @@ -208,6 +208,12 @@
>  /* Supervisor Configuration CSRs */
>  #define CSR_SENVCFG 0x10A
>
> +/* Supervisor state CSRs */
> +#define CSR_SSTATEEN0   0x10C
> +#define CSR_SSTATEEN1   0x10D
> +#define CSR_SSTATEEN2   0x10E
> +#define CSR_SSTATEEN3   0x10F
> +
>  /* Supervisor Trap Handling */
>  #define CSR_SSCRATCH0x140
>  #define CSR_SEPC0x141
> @@ -257,6 +263,16 @@
>  #define CSR_HENVCFG 0x60A
>  #define CSR_HENVCFGH0x61A
>
> +/* Hypervisor state CSRs */
> +#define CSR_HSTATEEN0   0x60C
> +#define CSR_HSTATEEN0H  0x61C
> +#define CSR_HSTATEEN1   0x60D
> +#define CSR_HSTATEEN1H  0x61D
> +#define CSR_HSTATEEN2   0x60E
> +#define CSR_HSTATEEN2H  0x61E
> +#define CSR_HSTATEEN3   0x60F
> +#define CSR_HSTATEEN3H  0x61F
> +
>  /* Virtual CSRs */
>  #define CSR_VSSTATUS0x200
>  #define CSR_VSIE0x204
> @@ -304,6 +320,26 @@
>  #define CSR_MENVCFG 0x30A
>  #define CSR_MENVCFGH0x31A
>
> +/* Machine state CSRs */
> +#define CSR_MSTATEEN0   0x30C
> +#define CSR_MSTATEEN0H  0x31C
> +#define CSR_MSTATEEN1   0x30D
> +#define CSR_MSTATEEN1H  0x31D
> +#define CSR_MSTATEEN2   0x30E
> +#define CSR_MSTATEEN2H  0x31E
> +#define CSR_MSTATEEN3   0x30F
> +#define CSR_MSTATEEN3H  0x31F
> +
> +/* Common defines for all smstateen */
> +#define SMSTATEEN_MAX_COUNT 4
> +#define SMSTATEEN0_CS   0
> +#define SMSTATEEN0_FCSR 0
> +#define SMSTATEEN0_IMSIC58
> +#define SMSTATEEN0_AIA  59
> +#define SMSTATEEN0_SVSLCT   60
> +#define SMSTATEEN0_HSENVCFG 62
> +#define SMSTATEEN_STATEN63
> +
>  /* Enhanced Physical Memory Protection (ePMP) */
>  #define CSR_MSECCFG 0x747
>  #define CSR_MSECCFGH0x757
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index 409a209f14..324fefce59 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -247,6 +247,42 @@ static RISCVException hmode32(CPURISCVState *env, int 
> csrno)
>
>  }
>
> +static RISCVException mstateen(CPURISCVState *env, int csrno)
> +{
> +CPUState *cs = env_cpu(env);
> +RISCVCPU *cpu = RISCV_CPU(cs);
> +
> +if (!cpu->cfg.ext_smstateen) {
> +return RISCV_EXCP_ILLEGAL_INST;
> +}
> +
> +return 

Re: New "IndustryStandard" fw_cfg?

2022-06-15 Thread Xiaoyao Li

On 6/16/2022 1:37 PM, Gerd Hoffmann wrote:

   Hi,


Per my understanding, Unaccepted Memory in UEFI is introduced for
confidential VMs, i.e., for Intel TDX and AMD SEV-SNP. The only reason
UEFI/OVMF reports "Unaccepted Memory" to OS, is a confidential VM is
desired.


No.  Reporting "Unaccepted Memory" to the OS is not a hard requirement
for confidential VMs, it only optimizes boot times.  Instead of doing
that time-consuming process in the firmware for all memory we tell the
guest OS which memory is accepted already and which is not.  So the
guest OS can go accept the remaining memory in a background process.


But for non-confidential VMs, even a range of memory is reported as 
unaccepted nothing prevents it from being accessed without accepting it, 
and it's not time-consuming. Did I miss anything?



take care,
   Gerd






Re: New "IndustryStandard" fw_cfg?

2022-06-15 Thread Gerd Hoffmann
  Hi,

> Per my understanding, Unaccepted Memory in UEFI is introduced for
> confidential VMs, i.e., for Intel TDX and AMD SEV-SNP. The only reason
> UEFI/OVMF reports "Unaccepted Memory" to OS, is a confidential VM is
> desired.

No.  Reporting "Unaccepted Memory" to the OS is not a hard requirement
for confidential VMs, it only optimizes boot times.  Instead of doing
that time-consuming process in the firmware for all memory we tell the
guest OS which memory is accepted already and which is not.  So the
guest OS can go accept the remaining memory in a background process.

take care,
  Gerd




Re: [PATCH] target/riscv/pmp: guard against PMP ranges with a negative size

2022-06-15 Thread Alistair Francis
On Thu, Jun 16, 2022 at 7:12 AM Nicolas Pitre  wrote:
>
> For a TOR entry to match, the stard address must be lower than the end
> address. Normally this is always the case, but correct code might still
> run into the following scenario:
>
> Initial state:
>
> pmpaddr3 = 0x2000   pmp3cfg = OFF
> pmpaddr4 = 0x3000   pmp4cfg = TOR
>
> Execution:
>
> 1. write 0x40ff to pmpaddr3
> 2. write 0x32ff to pmpaddr4

Hey, thanks for that patch!

So, at this point we have a PMP region enforcing

0x40ff <= addr < 0x32ff

which is going to be wrong as that isn't valid. But this is also
partially a guest bug. If a guest sets invalid PMP regions we should
be throwing exceptions (if the PMP region is enabled and enforced in
the current mode)

> 3. set pmp3cfg to NAPOT with a read-modify-write on pmpcfg0
> 4. set pmp4cfg to NAPOT with a read-modify-write on pmpcfg1
>
> When (2) is emulated, a call to pmp_update_rule() creates a negative
> range for pmp4 as pmp4cfg is still set to TOR. And when (3) is emulated,

I don't see where the negative comes from. From what I can tell we
should just set `sa` and `ea` to the values specified by the guest.

> a call to tlb_flush() is performed, causing pmp_get_tlb_size() to return
> a very creatively large TLB size for pmp4. This, in turn, may result in

Hmm.. pmp_get_tlb_size() assumes pmp_ea > pmp_sa. Maybe we should add
a check in there?

> accesses to non-existent/unitialized memory regions and a fault, so that
> (4) ends up never being executed.
>
> This is in m-mode with MPRV unset, meaning that unlocked PMP entries
> should have no effect. Therefore such a behavior based on PMP content
> is very unexpected.

Ok, this part is a QEMU bug. If we aren't enforcing PMP regions we
should not be throwing PMP errors.

get_physical_address_pmp() should give us full permissions though in
this case, so I don't see where the failure is. Can you include some
more details?

>
> Make sure no negative PMP range can be created, whether explicitly by
> the emulated code or implicitly like the above.
>
> Signed-off-by: Nicolas Pitre 
>
> diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
> index 151da3fa08..ea2b67d947 100644
> --- a/target/riscv/pmp.c
> +++ b/target/riscv/pmp.c
> @@ -167,6 +167,9 @@ void pmp_update_rule_addr(CPURISCVState *env, uint32_t 
> pmp_index)
>  case PMP_AMATCH_TOR:
>  sa = prev_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
>  ea = (this_addr << 2) - 1u;
> +if (sa > ea) {
> +sa = ea = 0u;
> +}

This doesn't seem right though.

Image if a guest sets the values you have above, then jumps to user
mode. The spec doesn't seem to say what should happen with invalid PMP
ranges, but I feel like we should throw exceptions instead of just
ignoring the config.

Alistair

>  break;
>
>  case PMP_AMATCH_NA4:
>



Re: [PATCH v5 2/3] target/riscv: Add stimecmp support

2022-06-15 Thread Anup Patel
On Thu, Jun 16, 2022 at 8:08 AM Alistair Francis  wrote:
>
> On Thu, Jun 16, 2022 at 4:21 AM Atish Kumar Patra  wrote:
> >
> > On Wed, Jun 8, 2022 at 12:19 AM Alistair Francis  
> > wrote:
> > >
> > > On Mon, Jun 6, 2022 at 2:23 AM Atish Patra  wrote:
> > > >
> > > > On Thu, Jun 2, 2022 at 12:02 AM Alistair Francis  
> > > > wrote:
> > > > >
> > > > > On Wed, Jun 1, 2022 at 4:16 AM Atish Patra  
> > > > > wrote:
> > > > > >
> > > > > > stimecmp allows the supervisor mode to update stimecmp CSR directly
> > > > > > to program the next timer interrupt. This CSR is part of the Sstc
> > > > > > extension which was ratified recently.
> > > > > >
> > > > > > Signed-off-by: Atish Patra 
> > > > > > ---
> > > > > >  target/riscv/cpu.c |  8 
> > > > > >  target/riscv/cpu.h |  5 ++
> > > > > >  target/riscv/cpu_bits.h|  4 ++
> > > > > >  target/riscv/csr.c | 81 +++
> > > > > >  target/riscv/machine.c |  1 +
> > > > > >  target/riscv/meson.build   |  3 +-
> > > > > >  target/riscv/time_helper.c | 98 
> > > > > > ++
> > > > > >  target/riscv/time_helper.h | 30 
> > > > > >  8 files changed, 229 insertions(+), 1 deletion(-)
> > > > > >  create mode 100644 target/riscv/time_helper.c
> > > > > >  create mode 100644 target/riscv/time_helper.h
> > > > > >
> > > > > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > > > > > index 19f4e8294042..d58dd2f857a7 100644
> > > > > > --- a/target/riscv/cpu.c
> > > > > > +++ b/target/riscv/cpu.c
> > > > > > @@ -23,6 +23,7 @@
> > > > > >  #include "qemu/log.h"
> > > > > >  #include "cpu.h"
> > > > > >  #include "internals.h"
> > > > > > +#include "time_helper.h"
> > > > > >  #include "exec/exec-all.h"
> > > > > >  #include "qapi/error.h"
> > > > > >  #include "qemu/error-report.h"
> > > > > > @@ -779,7 +780,12 @@ static void riscv_cpu_init(Object *obj)
> > > > > >  #ifndef CONFIG_USER_ONLY
> > > > > >  qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq,
> > > > > >IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
> > > > > > +
> > > > > > +if (cpu->cfg.ext_sstc) {
> > > > > > +riscv_timer_init(cpu);
> > > > > > +}
> > > > > >  #endif /* CONFIG_USER_ONLY */
> > > > > > +
> > > > > >  }
> > > > > >
> > > > > >  static Property riscv_cpu_properties[] = {
> > > > > > @@ -806,6 +812,7 @@ static Property riscv_cpu_properties[] = {
> > > > > >  DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
> > > > > >  DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
> > > > > >  DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
> > > > > > +DEFINE_PROP_BOOL("sstc", RISCVCPU, cfg.ext_sstc, true),
> > > > >
> > > > > Do we want this enabled by default?
> > > > >
> > > >
> > > > sstc extension will result in performance improvements as it avoids
> > > > the SBI calls & interrupt forwarding
> > > > path. That's why I think it should be enabled by default.
> > > >
> > > > > >
> > > > > >  DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
> > > > > >  DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
> > > > > > @@ -965,6 +972,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, 
> > > > > > char **isa_str, int max_str_len)
> > > > > >  ISA_EDATA_ENTRY(zbs, ext_zbs),
> > > > > >  ISA_EDATA_ENTRY(zve32f, ext_zve32f),
> > > > > >  ISA_EDATA_ENTRY(zve64f, ext_zve64f),
> > > > > > +ISA_EDATA_ENTRY(sstc, ext_sstc),
> > > > > >  ISA_EDATA_ENTRY(svinval, ext_svinval),
> > > > > >  ISA_EDATA_ENTRY(svnapot, ext_svnapot),
> > > > > >  ISA_EDATA_ENTRY(svpbmt, ext_svpbmt),
> > > > > > diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> > > > > > index 1119d5201066..9a5e02f217ba 100644
> > > > > > --- a/target/riscv/cpu.h
> > > > > > +++ b/target/riscv/cpu.h
> > > > > > @@ -276,6 +276,9 @@ struct CPUArchState {
> > > > > >  uint64_t mfromhost;
> > > > > >  uint64_t mtohost;
> > > > > >
> > > > > > +/* Sstc CSRs */
> > > > > > +uint64_t stimecmp;
> > > > > > +
> > > > > >  /* physical memory protection */
> > > > > >  pmp_table_t pmp_state;
> > > > > >  target_ulong mseccfg;
> > > > > > @@ -329,6 +332,7 @@ struct CPUArchState {
> > > > > >  float_status fp_status;
> > > > > >
> > > > > >  /* Fields from here on are preserved across CPU reset. */
> > > > > > +QEMUTimer *stimer; /* Internal timer for S-mode interrupt */
> > > > > >
> > > > > >  hwaddr kernel_addr;
> > > > > >  hwaddr fdt_addr;
> > > > > > @@ -379,6 +383,7 @@ struct RISCVCPUConfig {
> > > > > >  bool ext_counters;
> > > > > >  bool ext_ifencei;
> > > > > >  bool ext_icsr;
> > > > > > +bool ext_sstc;
> > > > > >  bool ext_svinval;
> > > > > >  bool ext_svnapot;
> > > > > >  bool ext_svpbmt;
> > > > > > diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> > > > > > index 4e5b630f5965..29d0e4a1be01 100644
> > > > > > --- 

[PATCH 1/2] target/riscv: Remove CSRs that set/clear an IMSIC interrupt file bits

2022-06-15 Thread Anup Patel
Based on architecture review committee feedback, the [m|s|vs]seteienum,
[m|s|vs]clreienum, [m|s|vs]seteipnum, and [m|s|vs]clreipnum CSRs are
removed in the latest AIA draft v0.3.0 specification.
(Refer, https://github.com/riscv/riscv-aia/releases/tag/0.3.0-draft.31)

These CSRs were mostly for software convenience and software can always
use [m|s|vs]iselect and [m|s|vs]ireg CSRs to update the IMSIC interrupt
file bits.

We update the IMSIC CSR emulation as-per above to match the latest AIA
draft specification.

Signed-off-by: Anup Patel 
---
 target/riscv/cpu_bits.h |  24 +--
 target/riscv/csr.c  | 150 +---
 2 files changed, 6 insertions(+), 168 deletions(-)

diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 4a55c6a709..01608f86e5 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -177,14 +177,8 @@
 #define CSR_MIREG   0x351
 
 /* Machine-Level Interrupts (AIA) */
-#define CSR_MTOPI   0xfb0
-
-/* Machine-Level IMSIC Interface (AIA) */
-#define CSR_MSETEIPNUM  0x358
-#define CSR_MCLREIPNUM  0x359
-#define CSR_MSETEIENUM  0x35a
-#define CSR_MCLREIENUM  0x35b
 #define CSR_MTOPEI  0x35c
+#define CSR_MTOPI   0xfb0
 
 /* Virtual Interrupts for Supervisor Level (AIA) */
 #define CSR_MVIEN   0x308
@@ -224,14 +218,8 @@
 #define CSR_SIREG   0x151
 
 /* Supervisor-Level Interrupts (AIA) */
-#define CSR_STOPI   0xdb0
-
-/* Supervisor-Level IMSIC Interface (AIA) */
-#define CSR_SSETEIPNUM  0x158
-#define CSR_SCLREIPNUM  0x159
-#define CSR_SSETEIENUM  0x15a
-#define CSR_SCLREIENUM  0x15b
 #define CSR_STOPEI  0x15c
+#define CSR_STOPI   0xdb0
 
 /* Supervisor-Level High-Half CSRs (AIA) */
 #define CSR_SIEH0x114
@@ -282,14 +270,8 @@
 #define CSR_VSIREG  0x251
 
 /* VS-Level Interrupts (H-extension with AIA) */
-#define CSR_VSTOPI  0xeb0
-
-/* VS-Level IMSIC Interface (H-extension with AIA) */
-#define CSR_VSSETEIPNUM 0x258
-#define CSR_VSCLREIPNUM 0x259
-#define CSR_VSSETEIENUM 0x25a
-#define CSR_VSCLREIENUM 0x25b
 #define CSR_VSTOPEI 0x25c
+#define CSR_VSTOPI  0xeb0
 
 /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */
 #define CSR_HIDELEGH0x613
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 409a209f14..a4890ebc70 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -1040,14 +1040,6 @@ static int aia_xlate_vs_csrno(CPURISCVState *env, int 
csrno)
 return CSR_VSISELECT;
 case CSR_SIREG:
 return CSR_VSIREG;
-case CSR_SSETEIPNUM:
-return CSR_VSSETEIPNUM;
-case CSR_SCLREIPNUM:
-return CSR_VSCLREIPNUM;
-case CSR_SSETEIENUM:
-return CSR_VSSETEIENUM;
-case CSR_SCLREIENUM:
-return CSR_VSCLREIENUM;
 case CSR_STOPEI:
 return CSR_VSTOPEI;
 default:
@@ -1202,124 +1194,6 @@ done:
 return RISCV_EXCP_NONE;
 }
 
-static int rmw_xsetclreinum(CPURISCVState *env, int csrno, target_ulong *val,
-target_ulong new_val, target_ulong wr_mask)
-{
-int ret = -EINVAL;
-bool set, pend, virt;
-target_ulong priv, isel, vgein, xlen, nval, wmask;
-
-/* Translate CSR number for VS-mode */
-csrno = aia_xlate_vs_csrno(env, csrno);
-
-/* Decode register details from CSR number */
-virt = set = pend = false;
-switch (csrno) {
-case CSR_MSETEIPNUM:
-priv = PRV_M;
-set = true;
-pend = true;
-break;
-case CSR_MCLREIPNUM:
-priv = PRV_M;
-pend = true;
-break;
-case CSR_MSETEIENUM:
-priv = PRV_M;
-set = true;
-break;
-case CSR_MCLREIENUM:
-priv = PRV_M;
-break;
-case CSR_SSETEIPNUM:
-priv = PRV_S;
-set = true;
-pend = true;
-break;
-case CSR_SCLREIPNUM:
-priv = PRV_S;
-pend = true;
-break;
-case CSR_SSETEIENUM:
-priv = PRV_S;
-set = true;
-break;
-case CSR_SCLREIENUM:
-priv = PRV_S;
-break;
-case CSR_VSSETEIPNUM:
-priv = PRV_S;
-virt = true;
-set = true;
-pend = true;
-break;
-case CSR_VSCLREIPNUM:
-priv = PRV_S;
-virt = true;
-pend = true;
-break;
-case CSR_VSSETEIENUM:
-priv = PRV_S;
-virt = true;
-set = true;
-break;
-case CSR_VSCLREIENUM:
-priv = PRV_S;
-virt = true;
-break;
-default:
- goto done;
-};
-
-/* IMSIC CSRs only available when machine implements IMSIC. */
-if (!env->aia_ireg_rmw_fn[priv]) {
-goto done;
-}
-
-/* Find the selected guest interrupt file */
-vgein = (virt) ? get_field(env->hstatus, HSTATUS_VGEIN) : 0;
-
-/* Selected guest interrupt file should be valid */
-if (virt && (!vgein || env->geilen < 

[PATCH 2/2] target/riscv: Update default priority table for local interrupts

2022-06-15 Thread Anup Patel
The latest AIA draft v0.3.0 defines a relatively simpler scheme for
default priority assignments where:
1) local interrupts 24 to 31 and 48 to 63 are reserved for custom use
   and have implementation specific default priority.
2) remaining local interrupts 0 to 23 and 32 to 47 have a recommended
   (not mandatory) priority assignments.

We update the default priority table and hviprio mapping as-per above.

Signed-off-by: Anup Patel 
---
 target/riscv/cpu_bits.h   |   2 +-
 target/riscv/cpu_helper.c | 134 ++
 2 files changed, 66 insertions(+), 70 deletions(-)

diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 01608f86e5..63ba867379 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -773,7 +773,7 @@ typedef enum RISCVException {
 #define IPRIO_IRQ_BITS 8
 #define IPRIO_MMAXIPRIO255
 #define IPRIO_DEFAULT_UPPER4
-#define IPRIO_DEFAULT_MIDDLE   (IPRIO_DEFAULT_UPPER + 24)
+#define IPRIO_DEFAULT_MIDDLE   (IPRIO_DEFAULT_UPPER + 12)
 #define IPRIO_DEFAULT_MIPRIO_DEFAULT_MIDDLE
 #define IPRIO_DEFAULT_S(IPRIO_DEFAULT_M + 3)
 #define IPRIO_DEFAULT_SGEXT(IPRIO_DEFAULT_S + 3)
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index 3c8ebecf84..063a1403db 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -169,17 +169,17 @@ void riscv_cpu_update_mask(CPURISCVState *env)
  * 14 "
  * 15 "
  * 16 "
- * 18 Debug/trace interrupt
- * 20 (Reserved interrupt)
+ * 17 "
+ * 18 "
+ * 19 "
+ * 20 "
+ * 21 "
  * 22 "
- * 24 "
- * 26 "
- * 28 "
- * 30 (Reserved for standard reporting of bus or system errors)
+ * 23 "
  */
 
 static const int hviprio_index2irq[] = {
-0, 1, 4, 5, 8, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30 };
+0, 1, 4, 5, 8, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
 static const int hviprio_index2rdzero[] = {
 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
@@ -208,50 +208,60 @@ int riscv_cpu_hviprio_index2irq(int index, int *out_irq, 
int *out_rdzero)
  *  Default  |
  *  Priority | Major Interrupt Numbers
  * 
- *  Highest  | 63 (3f), 62 (3e), 31 (1f), 30 (1e), 61 (3d), 60 (3c),
- *   | 59 (3b), 58 (3a), 29 (1d), 28 (1c), 57 (39), 56 (38),
- *   | 55 (37), 54 (36), 27 (1b), 26 (1a), 53 (35), 52 (34),
- *   | 51 (33), 50 (32), 25 (19), 24 (18), 49 (31), 48 (30)
+ *  Highest  | 47, 23, 46, 45, 22, 44,
+ *   | 43, 21, 42, 41, 20, 40
  *   |
  *   | 11 (0b),  3 (03),  7 (07)
  *   |  9 (09),  1 (01),  5 (05)
  *   | 12 (0c)
  *   | 10 (0a),  2 (02),  6 (06)
  *   |
- *   | 47 (2f), 46 (2e), 23 (17), 22 (16), 45 (2d), 44 (2c),
- *   | 43 (2b), 42 (2a), 21 (15), 20 (14), 41 (29), 40 (28),
- *   | 39 (27), 38 (26), 19 (13), 18 (12), 37 (25), 36 (24),
- *  Lowest   | 35 (23), 34 (22), 17 (11), 16 (10), 33 (21), 32 (20)
+ *   | 39, 19, 38, 37, 18, 36,
+ *  Lowest   | 35, 17, 34, 33, 16, 32
  * 
  */
 static const uint8_t default_iprio[64] = {
- [63] = IPRIO_DEFAULT_UPPER,
- [62] = IPRIO_DEFAULT_UPPER + 1,
- [31] = IPRIO_DEFAULT_UPPER + 2,
- [30] = IPRIO_DEFAULT_UPPER + 3,
- [61] = IPRIO_DEFAULT_UPPER + 4,
- [60] = IPRIO_DEFAULT_UPPER + 5,
-
- [59] = IPRIO_DEFAULT_UPPER + 6,
- [58] = IPRIO_DEFAULT_UPPER + 7,
- [29] = IPRIO_DEFAULT_UPPER + 8,
- [28] = IPRIO_DEFAULT_UPPER + 9,
- [57] = IPRIO_DEFAULT_UPPER + 10,
- [56] = IPRIO_DEFAULT_UPPER + 11,
-
- [55] = IPRIO_DEFAULT_UPPER + 12,
- [54] = IPRIO_DEFAULT_UPPER + 13,
- [27] = IPRIO_DEFAULT_UPPER + 14,
- [26] = IPRIO_DEFAULT_UPPER + 15,
- [53] = IPRIO_DEFAULT_UPPER + 16,
- [52] = IPRIO_DEFAULT_UPPER + 17,
-
- [51] = IPRIO_DEFAULT_UPPER + 18,
- [50] = IPRIO_DEFAULT_UPPER + 19,
- [25] = IPRIO_DEFAULT_UPPER + 20,
- [24] = IPRIO_DEFAULT_UPPER + 21,
- [49] = IPRIO_DEFAULT_UPPER + 22,
- [48] = IPRIO_DEFAULT_UPPER + 23,
+ /* Custom interrupts 48 to 63 */
+ [63] = IPRIO_MMAXIPRIO,
+ [62] = IPRIO_MMAXIPRIO,
+ [61] = IPRIO_MMAXIPRIO,
+ [60] = IPRIO_MMAXIPRIO,
+ [59] = IPRIO_MMAXIPRIO,
+ [58] = IPRIO_MMAXIPRIO,
+ [57] = IPRIO_MMAXIPRIO,
+ [56] = IPRIO_MMAXIPRIO,
+ [55] = IPRIO_MMAXIPRIO,
+ [54] = IPRIO_MMAXIPRIO,
+ [53] = IPRIO_MMAXIPRIO,
+ [52] = IPRIO_MMAXIPRIO,
+ [51] = IPRIO_MMAXIPRIO,
+ [50] = IPRIO_MMAXIPRIO,
+ [49] = IPRIO_MMAXIPRIO,
+ [48] = IPRIO_MMAXIPRIO,
+
+ /* Custom interrupts 24 to 31 */
+ [31] = IPRIO_MMAXIPRIO,
+ [30] = IPRIO_MMAXIPRIO,
+ [29] = IPRIO_MMAXIPRIO,
+ [28] = IPRIO_MMAXIPRIO,
+ [27] = IPRIO_MMAXIPRIO,
+ [26] = IPRIO_MMAXIPRIO,
+ [25] = IPRIO_MMAXIPRIO,
+ [24] = IPRIO_MMAXIPRIO,
+
+ [47] = IPRIO_DEFAULT_UPPER,
+ [23] = IPRIO_DEFAULT_UPPER + 1,
+ [46] = IPRIO_DEFAULT_UPPER + 2,
+ [45] = IPRIO_DEFAULT_UPPER + 3,
+ [22] = IPRIO_DEFAULT_UPPER + 4,
+ [44] = 

[PATCH 0/2] AIA draft v0.3.0 support for QEMU RISC-V

2022-06-15 Thread Anup Patel
The latest AIA draft v0.3.0 addresses comments from the architecture
review committee.
(Refer, https://github.com/riscv/riscv-aia/releases/tag/0.3.0-draft.31)

There are primarily two changes:
1) Removing various [m|s|vs]seteienum, [m|s|vs]clreienum, [m|s|vs]seteipnum,
   and [m|s|vs]clrei;num CSRs because these CSRs were mostly for software
   convienence.
2) Simplifying the default priority assignment for local interrupts

These patches can also be found in riscv_aia_update_v1 branch at:
https://github.com/avpatel/qemu.git

Corresponding changes in OpenSBI and Linux were small and these can be
found at:
 riscv_aia_update_v1 branch of https://github.com/avpatel/opensbi.git
 riscv_aia_v1 branch of https://github.com/avpatel/linux.git

Anup Patel (2):
  target/riscv: Remove CSRs that set/clear an IMSIC interrupt file bits
  target/riscv: Update default priority table for local interrupts

 target/riscv/cpu_bits.h   |  26 +--
 target/riscv/cpu_helper.c | 134 +-
 target/riscv/csr.c| 150 +-
 3 files changed, 72 insertions(+), 238 deletions(-)

-- 
2.34.1




Re: [PATCH 1/3] target/riscv: Remove the redundant initialization of env->misa_mxl

2022-06-15 Thread Bin Meng
On Thu, Jun 16, 2022 at 10:34 AM Alistair Francis  wrote:
>
> On Mon, Jun 13, 2022 at 10:30 PM Bin Meng  wrote:
> >
> > On Mon, Jun 13, 2022 at 8:33 AM Alistair Francis  
> > wrote:
> > >
> > > On Thu, Jun 9, 2022 at 11:08 AM Bin Meng  wrote:
> > > >
> > > > env->misa_mxl was already set in the RISC-V cpu init routine, and
> > > > validated at the beginning of riscv_cpu_realize(). There is no need
> > > > to do a redundant initialization later.
> > > >
> > > > Signed-off-by: Bin Meng 
> > > > ---
> > > >
> > > >  target/riscv/cpu.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > > > index a91253d4bd..61d1737741 100644
> > > > --- a/target/riscv/cpu.c
> > > > +++ b/target/riscv/cpu.c
> > > > @@ -752,7 +752,7 @@ static void riscv_cpu_realize(DeviceState *dev, 
> > > > Error **errp)
> > > >  ext |= RVJ;
> > > >  }
> > > >
> > > > -set_misa(env, env->misa_mxl, ext);
> > > > +env->misa_ext_mask = env->misa_ext = ext;
> > >
> > > You're right that we don't need to set `misa_mxl`, but isn't it
> > > cleaner calling the helper function here instead of manually assigning
> > > it?
> > >
> >
> > There is no helper for assigning misa_ext only. Do you want a new
> > helper for that?
>
> No, I don't think we need a new helper. I mean, is there any harm in
> just calling `set_misa()` even if that means we are performing a
> redundant operation?
>

No there is no harm to perform a redundant initialization.

Feel free to drop this patch then.

Regards,
Bin



Re: [PATCH v5 2/3] target/riscv: Add stimecmp support

2022-06-15 Thread Alistair Francis
On Thu, Jun 16, 2022 at 4:21 AM Atish Kumar Patra  wrote:
>
> On Wed, Jun 8, 2022 at 12:19 AM Alistair Francis  wrote:
> >
> > On Mon, Jun 6, 2022 at 2:23 AM Atish Patra  wrote:
> > >
> > > On Thu, Jun 2, 2022 at 12:02 AM Alistair Francis  
> > > wrote:
> > > >
> > > > On Wed, Jun 1, 2022 at 4:16 AM Atish Patra  wrote:
> > > > >
> > > > > stimecmp allows the supervisor mode to update stimecmp CSR directly
> > > > > to program the next timer interrupt. This CSR is part of the Sstc
> > > > > extension which was ratified recently.
> > > > >
> > > > > Signed-off-by: Atish Patra 
> > > > > ---
> > > > >  target/riscv/cpu.c |  8 
> > > > >  target/riscv/cpu.h |  5 ++
> > > > >  target/riscv/cpu_bits.h|  4 ++
> > > > >  target/riscv/csr.c | 81 +++
> > > > >  target/riscv/machine.c |  1 +
> > > > >  target/riscv/meson.build   |  3 +-
> > > > >  target/riscv/time_helper.c | 98 
> > > > > ++
> > > > >  target/riscv/time_helper.h | 30 
> > > > >  8 files changed, 229 insertions(+), 1 deletion(-)
> > > > >  create mode 100644 target/riscv/time_helper.c
> > > > >  create mode 100644 target/riscv/time_helper.h
> > > > >
> > > > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > > > > index 19f4e8294042..d58dd2f857a7 100644
> > > > > --- a/target/riscv/cpu.c
> > > > > +++ b/target/riscv/cpu.c
> > > > > @@ -23,6 +23,7 @@
> > > > >  #include "qemu/log.h"
> > > > >  #include "cpu.h"
> > > > >  #include "internals.h"
> > > > > +#include "time_helper.h"
> > > > >  #include "exec/exec-all.h"
> > > > >  #include "qapi/error.h"
> > > > >  #include "qemu/error-report.h"
> > > > > @@ -779,7 +780,12 @@ static void riscv_cpu_init(Object *obj)
> > > > >  #ifndef CONFIG_USER_ONLY
> > > > >  qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq,
> > > > >IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
> > > > > +
> > > > > +if (cpu->cfg.ext_sstc) {
> > > > > +riscv_timer_init(cpu);
> > > > > +}
> > > > >  #endif /* CONFIG_USER_ONLY */
> > > > > +
> > > > >  }
> > > > >
> > > > >  static Property riscv_cpu_properties[] = {
> > > > > @@ -806,6 +812,7 @@ static Property riscv_cpu_properties[] = {
> > > > >  DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
> > > > >  DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
> > > > >  DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
> > > > > +DEFINE_PROP_BOOL("sstc", RISCVCPU, cfg.ext_sstc, true),
> > > >
> > > > Do we want this enabled by default?
> > > >
> > >
> > > sstc extension will result in performance improvements as it avoids
> > > the SBI calls & interrupt forwarding
> > > path. That's why I think it should be enabled by default.
> > >
> > > > >
> > > > >  DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
> > > > >  DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
> > > > > @@ -965,6 +972,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, 
> > > > > char **isa_str, int max_str_len)
> > > > >  ISA_EDATA_ENTRY(zbs, ext_zbs),
> > > > >  ISA_EDATA_ENTRY(zve32f, ext_zve32f),
> > > > >  ISA_EDATA_ENTRY(zve64f, ext_zve64f),
> > > > > +ISA_EDATA_ENTRY(sstc, ext_sstc),
> > > > >  ISA_EDATA_ENTRY(svinval, ext_svinval),
> > > > >  ISA_EDATA_ENTRY(svnapot, ext_svnapot),
> > > > >  ISA_EDATA_ENTRY(svpbmt, ext_svpbmt),
> > > > > diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> > > > > index 1119d5201066..9a5e02f217ba 100644
> > > > > --- a/target/riscv/cpu.h
> > > > > +++ b/target/riscv/cpu.h
> > > > > @@ -276,6 +276,9 @@ struct CPUArchState {
> > > > >  uint64_t mfromhost;
> > > > >  uint64_t mtohost;
> > > > >
> > > > > +/* Sstc CSRs */
> > > > > +uint64_t stimecmp;
> > > > > +
> > > > >  /* physical memory protection */
> > > > >  pmp_table_t pmp_state;
> > > > >  target_ulong mseccfg;
> > > > > @@ -329,6 +332,7 @@ struct CPUArchState {
> > > > >  float_status fp_status;
> > > > >
> > > > >  /* Fields from here on are preserved across CPU reset. */
> > > > > +QEMUTimer *stimer; /* Internal timer for S-mode interrupt */
> > > > >
> > > > >  hwaddr kernel_addr;
> > > > >  hwaddr fdt_addr;
> > > > > @@ -379,6 +383,7 @@ struct RISCVCPUConfig {
> > > > >  bool ext_counters;
> > > > >  bool ext_ifencei;
> > > > >  bool ext_icsr;
> > > > > +bool ext_sstc;
> > > > >  bool ext_svinval;
> > > > >  bool ext_svnapot;
> > > > >  bool ext_svpbmt;
> > > > > diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> > > > > index 4e5b630f5965..29d0e4a1be01 100644
> > > > > --- a/target/riscv/cpu_bits.h
> > > > > +++ b/target/riscv/cpu_bits.h
> > > > > @@ -215,6 +215,10 @@
> > > > >  #define CSR_STVAL   0x143
> > > > >  #define CSR_SIP 0x144
> > > > >
> > > > > +/* Sstc supervisor CSRs */
> > > > > +#define CSR_STIMECMP0x14D
> > > > > +#define 

Re: [PATCH 1/3] target/riscv: Remove the redundant initialization of env->misa_mxl

2022-06-15 Thread Alistair Francis
On Mon, Jun 13, 2022 at 10:30 PM Bin Meng  wrote:
>
> On Mon, Jun 13, 2022 at 8:33 AM Alistair Francis  wrote:
> >
> > On Thu, Jun 9, 2022 at 11:08 AM Bin Meng  wrote:
> > >
> > > env->misa_mxl was already set in the RISC-V cpu init routine, and
> > > validated at the beginning of riscv_cpu_realize(). There is no need
> > > to do a redundant initialization later.
> > >
> > > Signed-off-by: Bin Meng 
> > > ---
> > >
> > >  target/riscv/cpu.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > > index a91253d4bd..61d1737741 100644
> > > --- a/target/riscv/cpu.c
> > > +++ b/target/riscv/cpu.c
> > > @@ -752,7 +752,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error 
> > > **errp)
> > >  ext |= RVJ;
> > >  }
> > >
> > > -set_misa(env, env->misa_mxl, ext);
> > > +env->misa_ext_mask = env->misa_ext = ext;
> >
> > You're right that we don't need to set `misa_mxl`, but isn't it
> > cleaner calling the helper function here instead of manually assigning
> > it?
> >
>
> There is no helper for assigning misa_ext only. Do you want a new
> helper for that?

No, I don't think we need a new helper. I mean, is there any harm in
just calling `set_misa()` even if that means we are performing a
redundant operation?

Alistair

>
> Regards,
> Bin



Re: [PATCH] hw/riscv: virt: pass random seed to fdt

2022-06-15 Thread Alistair Francis
On Wed, Jun 15, 2022 at 2:07 PM Bin Meng  wrote:
>
> On Mon, Jun 13, 2022 at 8:08 PM Jason A. Donenfeld  wrote:
> >
> > If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to
> > initialize early. Set this using the usual guest random number
> > generation function. This is confirmed to successfully initialize the
> > RNG on Linux 5.19-rc2.
> >
> > Cc: Alistair Francis 
> > Signed-off-by: Jason A. Donenfeld 

Thanks!

Applied to riscv-to-apply.next with the full stop removed

Alistair

> > ---
> >  hw/riscv/virt.c | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> > index bc424dd2f5..368a723bf6 100644
> > --- a/hw/riscv/virt.c
> > +++ b/hw/riscv/virt.c
> > @@ -21,6 +21,7 @@
> >  #include "qemu/osdep.h"
> >  #include "qemu/units.h"
> >  #include "qemu/error-report.h"
> > +#include "qemu/guest-random.h"
> >  #include "qapi/error.h"
> >  #include "hw/boards.h"
> >  #include "hw/loader.h"
> > @@ -998,6 +999,7 @@ static void create_fdt(RISCVVirtState *s, const 
> > MemMapEntry *memmap,
> >  MachineState *mc = MACHINE(s);
> >  uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1;
> >  uint32_t irq_pcie_phandle = 1, irq_virtio_phandle = 1;
> > +uint8_t rng_seed[32];
> >
> >  if (mc->dtb) {
> >  mc->fdt = load_device_tree(mc->dtb, >fdt_size);
> > @@ -1046,6 +1048,10 @@ update_bootargs:
> >  if (cmdline && *cmdline) {
> >  qemu_fdt_setprop_string(mc->fdt, "/chosen", "bootargs", cmdline);
> >  }
> > +
> > +/* Pass seed to RNG. */
>
> nits: please remove the ending period
>
> > +qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
> > +qemu_fdt_setprop(mc->fdt, "/chosen", "rng-seed", rng_seed, 
> > sizeof(rng_seed));
> >  }
> >
> >  static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
> > --
>
> Otherwise,
> Reviewed-by: Bin Meng 
>



Re: [PATCH V8 02/39] migration: qemu file wrappers

2022-06-15 Thread Guoyi Tu

On 2022/6/15 22:51, Steve Sistare wrote:

Add qemu_file_open and qemu_fd_open to create QEMUFile objects for unix
files and file descriptors.


the function names should be updated.

--
Guoyi

Signed-off-by: Steve Sistare 
---
  migration/qemu-file-channel.c | 36 
  migration/qemu-file-channel.h |  6 ++
  2 files changed, 42 insertions(+)

diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c
index bb5a575..cc5aebc 100644
--- a/migration/qemu-file-channel.c
+++ b/migration/qemu-file-channel.c
@@ -27,8 +27,10 @@
  #include "qemu-file.h"
  #include "io/channel-socket.h"
  #include "io/channel-tls.h"
+#include "io/channel-file.h"
  #include "qemu/iov.h"
  #include "qemu/yank.h"
+#include "qapi/error.h"
  #include "yank_functions.h"
  
  
@@ -192,3 +194,37 @@ QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc)

  object_ref(OBJECT(ioc));
  return qemu_fopen_ops(ioc, _output_ops, true);
  }
+
+QEMUFile *qemu_fopen_file(const char *path, int flags, int mode,
+  const char *name, Error **errp)
+{
+g_autoptr(QIOChannelFile) fioc = NULL;
+QIOChannel *ioc;
+QEMUFile *f;
+
+if (flags & O_RDWR) {
+error_setg(errp, "qemu_fopen_file %s: O_RDWR not supported", path);
+return NULL;
+}
+
+fioc = qio_channel_file_new_path(path, flags, mode, errp);
+if (!fioc) {
+return NULL;
+}
+
+ioc = QIO_CHANNEL(fioc);
+qio_channel_set_name(ioc, name);
+f = (flags & O_WRONLY) ? qemu_fopen_channel_output(ioc) :
+ qemu_fopen_channel_input(ioc);
+return f;
+}
+
+QEMUFile *qemu_fopen_fd(int fd, bool writable, const char *name)
+{
+g_autoptr(QIOChannelFile) fioc = qio_channel_file_new_fd(fd);
+QIOChannel *ioc = QIO_CHANNEL(fioc);
+QEMUFile *f = writable ? qemu_fopen_channel_output(ioc) :
+ qemu_fopen_channel_input(ioc);
+qio_channel_set_name(ioc, name);
+return f;
+}
diff --git a/migration/qemu-file-channel.h b/migration/qemu-file-channel.h
index 0028a09..75fd0ad 100644
--- a/migration/qemu-file-channel.h
+++ b/migration/qemu-file-channel.h
@@ -29,4 +29,10 @@
  
  QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc);

  QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc);
+
+QEMUFile *qemu_fopen_file(const char *path, int flags, int mode,
+ const char *name, Error **errp);
+
+QEMUFile *qemu_fopen_fd(int fd, bool writable, const char *name);
+
  #endif




Re: [PATCH 0/3] target/riscv: Fix issue 1060

2022-06-15 Thread Alistair Francis
On Sun, Jun 5, 2022 at 9:12 AM Richard Henderson
 wrote:
>
> This issue concerns the value of mtval for illegal
> instruction exceptions, and came with a great test case.
> The fix is just two lines, in the first patch, but
> I noticed some cleanups on the way.
>
>
> r~
>
>
> Richard Henderson (3):
>   target/riscv: Set env->bins in gen_exception_illegal
>   target/riscv: Remove generate_exception_mtval
>   target/riscv: Minimize the calls to decode_save_opc

Thanks!

Applied to riscv-to-apply.next

Alistair

>
>  target/riscv/translate.c  | 31 +--
>  .../riscv/insn_trans/trans_privileged.c.inc   |  4 ++
>  target/riscv/insn_trans/trans_rvh.c.inc   |  2 +
>  target/riscv/insn_trans/trans_rvi.c.inc   |  2 +
>  tests/tcg/riscv64/Makefile.softmmu-target | 21 
>  tests/tcg/riscv64/issue1060.S | 53 +++
>  tests/tcg/riscv64/semihost.ld | 21 
>  7 files changed, 116 insertions(+), 18 deletions(-)
>  create mode 100644 tests/tcg/riscv64/Makefile.softmmu-target
>  create mode 100644 tests/tcg/riscv64/issue1060.S
>  create mode 100644 tests/tcg/riscv64/semihost.ld
>
> --
> 2.34.1
>
>



Re: [PULL 20/33] configure: handle host compiler in probe_target_compiler

2022-06-15 Thread Alex Bennée


Matheus Kowalczuk Ferst  writes:

> On 01/06/2022 15:05, Alex Bennée wrote:
>> From: Paolo Bonzini 
>> 
>> In preparation for handling more binaries than just cc, handle
>> the case of "probe_target_compiler $cpu" directly in the function,
>> setting the target_* variables based on the ones that are used to
>> build QEMU.  The clang check also needs to be moved after this
>> fallback.
>> 
>> Signed-off-by: Paolo Bonzini 
>> Reviewed-by: Richard Henderson 
>> Message-Id: <20220517092616.1272238-10-pbonz...@redhat.com>
>> Signed-off-by: Alex Bennée 
>> Message-Id: <20220527153603.887929-21-alex.ben...@linaro.org>
>
> Hi,
>
> After this patch, a clean build in ppc64le hosts will not build 
> ppc64{,le}-linux-user tests with "make check-tcg"
>
>> 
>> diff --git a/configure b/configure
>> index fbf6d39f96..217c8b3cac 100755
>> --- a/configure
>> +++ b/configure
>> @@ -954,10 +954,6 @@ case $git_submodules_action in
>>   ;;
>>   esac
>> 
>> -if eval test -z "\${cross_cc_$cpu}"; then
>> -eval "cross_cc_${cpu}=\$cc"
>> -fi
>> -
>>   default_target_list=""
>>   mak_wilds=""
>> 
>> @@ -2008,13 +2004,6 @@ probe_target_compiler() {
>> if eval test -n "\"\${cross_cc_$1}\""; then
>>   if eval has "\"\${cross_cc_$1}\""; then
>> eval "target_cc=\"\${cross_cc_$1}\""
>> -  case $1 in
>> -i386|x86_64)
>> -  if $target_cc --version | grep -qi "clang"; then
>> -unset target_cc
>> -  fi
>> -  ;;
>> -  esac
>>   fi
>> fi
>> if eval test -n "\"\${cross_as_$1}\""; then
>> @@ -2027,6 +2016,20 @@ probe_target_compiler() {
>> eval "target_ld=\"\${cross_ld_$1}\""
>>   fi
>> fi
>> +  if test "$1" = $cpu; then > +: ${target_cc:=$cc}
>> +: ${target_as:=$as}
>> +: ${target_ld:=$ld}
>> +  fi
>
> $cpu is normalized[1] to ppc64 on little-endian hosts, so 
> ppc64le-linux-user will not have $target_{cc,as,ld} set, and 
> ppc64-linux-user will have them set to a toolchain that may not support 
> -mbig-endian. I suppose we have a similar problem with MIPS targets on 
> MIPS hosts.

For now you can always explicitly tell configure about the host compiler
with:

 --cross-cc-ppc64le=gcc

but we should fix the broken detection. It seems the var cpu has an
overloaded meaning so I wonder if we just need an explicit host_cpu
setting when we normalize cpu?

>
> [1] 
> https://gitlab.com/qemu-project/qemu/-/blob/2ad60f6f8c12ca0acd8834fdd70e088361b8791f/configure#L611


-- 
Alex Bennée



[PATCH 3/4] slirp: Add mfr-id to -netdev options

2022-06-15 Thread Peter Delevoryas
This lets you set the manufacturer's ID for a slirp netdev, which can be
queried from the guest through the Get Version ID NC-SI command. For
example, by setting the manufacturer's ID to 0x8119:

wget 
https://github.com/facebook/openbmc/releases/download/openbmc-e2294ff5d31d/fby35.mtd
qemu-system-arm -machine fby35-bmc \
-drive file=fby35.mtd,format=raw,if=mtd -nographic \
-netdev user,id=nic,mfr-id=0x8119,hostfwd=::-:22 \
-net nic,model=ftgmac100,netdev=nic
...
username: root
password: 0penBmc
...
root@bmc-oob:~# ncsi-util 0x15
NC-SI Command Response:
cmd: GET_VERSION_ID(0x15)
Response: COMMAND_COMPLETED(0x)  Reason: NO_ERROR(0x)
Payload length = 40

20: 0xf1 0xf0 0xf0 0x00
24: 0x00 0x00 0x00 0x00
28: 0x00 0x00 0x00 0x00
32: 0x00 0x00 0x00 0x00
36: 0x00 0x00 0x00 0x00
40: 0x00 0x00 0x00 0x00
44: 0x00 0x00 0x00 0x00
48: 0x00 0x00 0x00 0x00
52: 0x00 0x00 0x81 0x19

Signed-off-by: Peter Delevoryas 
---
 net/slirp.c   | 5 +++--
 qapi/net.json | 5 -
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index 75e5ccafd9..231068c1e2 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -413,7 +413,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
   const char *vnameserver, const char *vnameserver6,
   const char *smb_export, const char *vsmbserver,
   const char **dnssearch, const char *vdomainname,
-  const char *tftp_server_name,
+  const char *tftp_server_name, uint32_t mfr_id,
   Error **errp)
 {
 /* default settings according to historic slirp */
@@ -636,6 +636,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 cfg.vnameserver6 = ip6_dns;
 cfg.vdnssearch = dnssearch;
 cfg.vdomainname = vdomainname;
+cfg.mfr_id = mfr_id;
 s->slirp = slirp_new(, _cb, s);
 QTAILQ_INSERT_TAIL(_stacks, s, entry);
 
@@ -1172,7 +1173,7 @@ int net_init_slirp(const Netdev *netdev, const char *name,
  user->bootfile, user->dhcpstart,
  user->dns, user->ipv6_dns, user->smb,
  user->smbserver, dnssearch, user->domainname,
- user->tftp_server_name, errp);
+ user->tftp_server_name, user->mfr_id, errp);
 
 while (slirp_configs) {
 config = slirp_configs;
diff --git a/qapi/net.json b/qapi/net.json
index d6f7cfd4d6..efc5cb3fb6 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -167,6 +167,8 @@
 #
 # @tftp-server-name: RFC2132 "TFTP server name" string (Since 3.1)
 #
+# @mfr-id: Manufacturer ID (Private Enterprise Number: IANA)
+#
 # Since: 1.2
 ##
 { 'struct': 'NetdevUserOptions',
@@ -192,7 +194,8 @@
 '*smbserver': 'str',
 '*hostfwd':   ['String'],
 '*guestfwd':  ['String'],
-'*tftp-server-name': 'str' } }
+'*tftp-server-name': 'str',
+'*mfr-id': 'uint32' } }
 
 ##
 # @NetdevTapOptions:
-- 
2.30.2




[PATCH 4/4] slirp: Add oob-eth-addr to -netdev options

2022-06-15 Thread Peter Delevoryas
With this change, you can now request the out-of-band MAC address from
slirp in fby35-bmc:

wget 
https://github.com/facebook/openbmc/releases/download/openbmc-e2294ff5d31d/fby35.mtd
qemu-system-arm -machine fby35-bmc \
-drive file=fby35.mtd,format=raw,if=mtd \
-nographic \
-netdev 
user,id=nic,mfr-id=0x8119,oob-eth-addr=de:ad:be:ef:ca:fe,hostfwd=::-:22 \
-net nic,model=ftgmac100,netdev=nic

...
username: root
password: 0penBmc
...

root@bmc-oob:~# ncsi-util -n eth0 -c 0 0x50 0 0 0x81 0x19 0 0 0x1b 0
NC-SI Command Response:
cmd: NCSI_OEM_CMD(0x50)
Response: COMMAND_COMPLETED(0x)  Reason: NO_ERROR(0x)
Payload length = 24

20: 0x00 0x00 0x81 0x19
24: 0x01 0x00 0x1b 0x00
28: 0x00 0x00 0x00 0x00
32: 0xde 0xad 0xbe 0xef
36: 0xca 0xfe 0x00 0x00

root@bmc-oob:~# ifconfig
eth0  Link encap:Ethernet  HWaddr DE:AD:BE:EF:CA:FE
  inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
  inet6 addr: fec0::dcad:beff:feef:cafe/64 Scope:Site
  inet6 addr: fe80::dcad:beff:feef:cafe/64 Scope:Link
  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  RX packets:253 errors:0 dropped:0 overruns:0 frame:0
  TX packets:271 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:1000
  RX bytes:24638 (24.0 KiB)  TX bytes:18876 (18.4 KiB)
  Interrupt:32

loLink encap:Local Loopback
  inet addr:127.0.0.1  Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNING  MTU:65536  Metric:1
  RX packets:2 errors:0 dropped:0 overruns:0 frame:0
  TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:1000
  RX bytes:120 (120.0 B)  TX bytes:120 (120.0 B)

Signed-off-by: Peter Delevoryas 
---
 net/slirp.c   | 13 +++--
 qapi/net.json |  5 -
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index 231068c1e2..858d3da859 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -414,7 +414,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
   const char *smb_export, const char *vsmbserver,
   const char **dnssearch, const char *vdomainname,
   const char *tftp_server_name, uint32_t mfr_id,
-  Error **errp)
+  uint8_t oob_eth_addr[ETH_ALEN], Error **errp)
 {
 /* default settings according to historic slirp */
 struct in_addr net  = { .s_addr = htonl(0x0a000200) }; /* 10.0.2.0 */
@@ -637,6 +637,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 cfg.vdnssearch = dnssearch;
 cfg.vdomainname = vdomainname;
 cfg.mfr_id = mfr_id;
+memcpy(cfg.oob_eth_addr, oob_eth_addr, ETH_ALEN);
 s->slirp = slirp_new(, _cb, s);
 QTAILQ_INSERT_TAIL(_stacks, s, entry);
 
@@ -1142,6 +1143,7 @@ int net_init_slirp(const Netdev *netdev, const char *name,
 const NetdevUserOptions *user;
 const char **dnssearch;
 bool ipv4 = true, ipv6 = true;
+MACAddr oob_eth_addr = {};
 
 assert(netdev->type == NET_CLIENT_DRIVER_USER);
 user = >u.user;
@@ -1166,6 +1168,12 @@ int net_init_slirp(const Netdev *netdev, const char 
*name,
 net_init_slirp_configs(user->hostfwd, SLIRP_CFG_HOSTFWD);
 net_init_slirp_configs(user->guestfwd, 0);
 
+if (user->has_oob_eth_addr &&
+net_parse_macaddr(oob_eth_addr.a, user->oob_eth_addr) < 0) {
+error_setg(errp, "invalid syntax for OOB ethernet address");
+return -1;
+}
+
 ret = net_slirp_init(peer, "user", name, user->q_restrict,
  ipv4, vnet, user->host,
  ipv6, user->ipv6_prefix, user->ipv6_prefixlen,
@@ -1173,7 +1181,8 @@ int net_init_slirp(const Netdev *netdev, const char *name,
  user->bootfile, user->dhcpstart,
  user->dns, user->ipv6_dns, user->smb,
  user->smbserver, dnssearch, user->domainname,
- user->tftp_server_name, user->mfr_id, errp);
+ user->tftp_server_name, user->mfr_id, oob_eth_addr.a,
+ errp);
 
 while (slirp_configs) {
 config = slirp_configs;
diff --git a/qapi/net.json b/qapi/net.json
index efc5cb3fb6..7b2c3c205c 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -169,6 +169,8 @@
 #
 # @mfr-id: Manufacturer ID (Private Enterprise Number: IANA)
 #
+# @oob-eth-addr: Out-of-band ethernet address for BMC
+#
 # Since: 1.2
 ##
 { 'struct': 'NetdevUserOptions',
@@ -195,7 +197,8 @@
 '*hostfwd':   ['String'],
 '*guestfwd':  ['String'],
 '*tftp-server-name': 'str',
-'*mfr-id': 'uint32' } }
+'*mfr-id': 'uint32',
+'*oob-eth-addr': 'str' } }
 
 ##
 # 

[PATCH 1/4] slirp: Update submodule to include NC-SI updates

2022-06-15 Thread Peter Delevoryas
There hasn't been a new libslirp release yet, but I don't see any reason
in particular why we couldn't update to this commit to support the new
NC-SI functionality added in !122 and !125, as long as it doesn't break
backwards compatibility with anything.

[1] https://gitlab.freedesktop.org/slirp/libslirp/-/merge_requests/122
[2] https://gitlab.freedesktop.org/slirp/libslirp/-/merge_requests/125

Signed-off-by: Peter Delevoryas 
---
 slirp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/slirp b/slirp
index 9d59bb775d..baf336047c 16
--- a/slirp
+++ b/slirp
@@ -1 +1 @@
-Subproject commit 9d59bb775d6294c8b447a88512f7bb43f12a25a8
+Subproject commit baf336047c3bb869b3103a6b1b3d8b15e5f1c58d
-- 
2.30.2




[PATCH 2/4] slirp: Update SlirpConfig version to 5

2022-06-15 Thread Peter Delevoryas
I think we probably need a new Slirp release
(4.8.0) and a switch statement here instead, right?

So that we can preserve the behavior for 4.7.0?

Signed-off-by: Peter Delevoryas 
---
 net/slirp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/slirp.c b/net/slirp.c
index 8679be6444..75e5ccafd9 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -617,7 +617,7 @@ static int net_slirp_init(NetClientState *peer, const char 
*model,
 
 s = DO_UPCAST(SlirpState, nc, nc);
 
-cfg.version = SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
+cfg.version = SLIRP_CHECK_VERSION(4, 7, 0) ? 5 : 1;
 cfg.restricted = restricted;
 cfg.in_enabled = ipv4;
 cfg.vnetwork = net;
-- 
2.30.2




[PATCH 0/4] slirp: Update submodule to include NC-SI features

2022-06-15 Thread Peter Delevoryas
I recently submitted some NC-SI changes ([1], [2]) to libslirp, and I'd like
to include them as netdev options in QEMU now.

I'm guessing that before we can do that though, there probably needs
to be a new libslirp release, right? Right now we're on 4.7.0, with
SlirpConfig version 4. I guess I'd like to create (or wait, either
is fine) 4.8.0, and update QEMU to use SlirpConfig version 5 if
that version is available.

By the way: do I need to add #if SLIRP_CHECK_VERSION(4,7,0) around any code
I'm adding? I'm hoping that's not the case, but I see that was necessary
with the recent timer changes.

Let me know what I should do, I am fully expecting that I'll need to either
wait for the next slirp release, submit a v2, etc. Just wanted to get the
ball rolling.

Thanks,
Peter

[1] https://gitlab.freedesktop.org/slirp/libslirp/-/merge_requests/122
[2] https://gitlab.freedesktop.org/slirp/libslirp/-/merge_requests/125



Peter Delevoryas (4):
  slirp: Update submodule to include NC-SI updates
  slirp: Update SlirpConfig version to 5
  slirp: Add mfr-id to -netdev options
  slirp: Add oob-eth-addr to -netdev options

 net/slirp.c   | 18 ++
 qapi/net.json |  8 +++-
 slirp |  2 +-
 3 files changed, 22 insertions(+), 6 deletions(-)

-- 
2.30.2




[PATCH v2 1/2] ui/gtk: detach VCS for additional guest displays

2022-06-15 Thread Dongwon Kim
Detaching any addtional guest displays in case there are multiple
displays assigned to the guest OS (e.g. max_outputs=n) so that
all of them are visible upon lauching.

v2: - check if the type of VC is GD_VC_GFX before qemu_console_is_graphic
  (Gerd Hoffman)
- vc[0] is always primary guest display so we won't need n_gfx_vcs
  (Gerd Hoffmann)
- making sure detached window's size same as original surface size
  (Daniel P. Berrangé)

Cc: Daniel P. Berrangé 
Cc: Markus Armbruster 
Cc: Philippe Mathieu-Daudé 
Cc: Paolo Bonzini 
Cc: Gerd Hoffmann 
Cc: Vivek Kasireddy 
Signed-off-by: Dongwon Kim 
---
 ui/gtk.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 2a791dd2aa..e6878c3209 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1361,6 +1361,11 @@ static void gd_menu_untabify(GtkMenuItem *item, void 
*opaque)
 
 g_signal_connect(vc->window, "delete-event",
  G_CALLBACK(gd_tab_window_close), vc);
+
+gtk_window_set_default_size(GTK_WINDOW(vc->window),
+surface_width(vc->gfx.ds),
+surface_height(vc->gfx.ds));
+
 gtk_widget_show_all(vc->window);
 
 if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
@@ -2311,6 +2316,7 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
 GtkDisplayState *s = g_malloc0(sizeof(*s));
 GdkDisplay *window_display;
 GtkIconTheme *theme;
+int i;
 char *dir;
 
 if (!gtkinit) {
@@ -2381,7 +2387,12 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
 gtk_widget_set_sensitive(s->copy_item,
  vc && vc->type == GD_VC_VTE);
 #endif
-
+for (i = 1; i < s->nb_vcs; i++) {
+if (vc->type == GD_VC_GFX &&
+qemu_console_is_graphic(s->vc[i].gfx.dcl.con)) {
+gtk_menu_item_activate(GTK_MENU_ITEM(s->untabify_item));
+}
+}
 if (opts->has_full_screen &&
 opts->full_screen) {
 gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
-- 
2.30.2




[PATCH v2 2/2] ui/gtk: a new array param monitor to specify the target displays

2022-06-15 Thread Dongwon Kim
New integer array parameter, 'monitor' is for specifying the target
displays where individual QEMU windows are placed upon launching.

The array contains a series of numbers representing the monitor where
QEMU windows are placed.

Numbers in the array are mapped to QEMU windows like,

[1st detached window, 2nd detached window, Main window]

Usage example: -display gtk,monitor.0=0,monitor.1=1.

Cc: Daniel P. Berrangé 
Cc: Markus Armbruster 
Cc: Philippe Mathieu-Daudé 
Cc: Paolo Bonzini 
Cc: Gerd Hoffmann 
Cc: Vivek Kasireddy 
Signed-off-by: Dongwon Kim 
---
 qapi/ui.json|  7 ++-
 qemu-options.hx |  2 +-
 ui/gtk.c| 32 +++-
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/qapi/ui.json b/qapi/ui.json
index 413371d5e8..5980f30c7f 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1195,12 +1195,17 @@
 #   assuming the guest will resize the display to match
 #   the window size then.  Otherwise it defaults to "off".
 #   Since 3.1
+# @monitor: Array of numbers, each of which represents physical
+#   monitor where individual QEMU window is placed in case
+#   there are multiple of them
+#   since 7.1
 #
 # Since: 2.12
 ##
 { 'struct'  : 'DisplayGTK',
   'data': { '*grab-on-hover' : 'bool',
-'*zoom-to-fit'   : 'bool'  } }
+'*zoom-to-fit'   : 'bool',
+'*monitor'   : ['uint16']  } }
 
 ##
 # @DisplayEGLHeadless:
diff --git a/qemu-options.hx b/qemu-options.hx
index 377d22fbd8..f79f533e9d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1938,7 +1938,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #endif
 #if defined(CONFIG_GTK)
 "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
-"[,show-cursor=on|off][,window-close=on|off]\n"
+"
[,monitor.=][,show-cursor=on|off][,window-close=on|off]\n"
 #endif
 #if defined(CONFIG_VNC)
 "-display vnc=[,]\n"
diff --git a/ui/gtk.c b/ui/gtk.c
index e6878c3209..fc9bf04680 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2316,6 +2316,10 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
 GtkDisplayState *s = g_malloc0(sizeof(*s));
 GdkDisplay *window_display;
 GtkIconTheme *theme;
+GtkWidget *win;
+GdkRectangle dest;
+uint16List *mon;
+int n_mon;
 int i;
 char *dir;
 
@@ -2393,7 +2397,33 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
 gtk_menu_item_activate(GTK_MENU_ITEM(s->untabify_item));
 }
 }
-if (opts->has_full_screen &&
+if (opts->u.gtk.has_monitor) {
+i = 0;
+n_mon = gdk_display_get_n_monitors(window_display);
+for (mon = opts->u.gtk.monitor; mon; mon = mon->next) {
+if (mon->value < n_mon) {
+for (; i < s->nb_vcs; i++) {
+win = s->vc[i].window ? s->vc[i].window : s->window;
+if (opts->has_full_screen && opts->full_screen) {
+gtk_window_fullscreen_on_monitor(
+GTK_WINDOW(win),
+gdk_display_get_default_screen(window_display),
+mon->value);
+} else {
+gdk_monitor_get_geometry(
+gdk_display_get_monitor(window_display, 
mon->value),
+);
+gtk_window_move(GTK_WINDOW(win),
+dest.x, dest.y);
+}
+i++;
+break;
+}
+}
+}
+}
+if (!opts->u.gtk.has_monitor &&
+opts->has_full_screen &&
 opts->full_screen) {
 gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item));
 }
-- 
2.30.2




[PATCH v2 0/2] handling guest multiple displays

2022-06-15 Thread Dongwon Kim
This patch seires is for adding some useful features for the guest os with
multi-displays. First patch is to make all of guest displays visible
when guest os is launched using "detach". Second patch is for providing
a method to assign each guest display to specific physical monitor,
which would be useful if someone wants to directly full-screen individual
guest scanouts to host's physical displays.

Changes in v2:

* ui/gtk: detach VCS for additional guest displays

  - check if the type of VC is GD_VC_GFX before qemu_console_is_graphic
(Gerd Hoffman)
  - vc[0] is always primary guest display so we won't need n_gfx_vcs
(Gerd Hoffmann)
  - making sure detached window's size same as original surface size
(Daniel P. Berrangé)

Dongwon Kim (2):
  ui/gtk: detach VCS for additional guest displays (v2)
  ui/gtk: a new array param monitor to specify the target displays (v2)

 qapi/ui.json|  7 ++-
 qemu-options.hx |  2 +-
 ui/gtk.c| 43 +--
 3 files changed, 48 insertions(+), 4 deletions(-)

-- 
2.30.2




Re: [PULL 00/18] Block patches

2022-06-15 Thread Richard Henderson

On 6/15/22 08:51, Stefan Hajnoczi wrote:

The following changes since commit 8e6c70b9d4a1b1f3011805947925cfdb31642f7f:

   Merge tag 'kraxel-20220614-pull-request' of git://git.kraxel.org/qemu into 
staging (2022-06-14 06:21:46 -0700)

are available in the Git repository at:

   https://gitlab.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 99b969fbe105117f5af6060d3afef40ca39cc9c1:

   linux-aio: explain why max batch is checked in laio_io_unplug() (2022-06-15 
16:43:42 +0100)


Pull request

This pull request includes an important aio=native I/O stall fix, the
experimental vifo-user server, the io_uring_register_ring_fd() optimization for
aio=io_uring, and an update to Vladimir Sementsov-Ogievskiy's maintainership
details.


Applied, thanks.  Please update https://wiki.qemu.org/ChangeLog/7.1 as 
appropriate.


r~






Jagannathan Raman (14):
   qdev: unplug blocker for devices
   remote/machine: add HotplugHandler for remote machine
   remote/machine: add vfio-user property
   vfio-user: build library
   vfio-user: define vfio-user-server object
   vfio-user: instantiate vfio-user context
   vfio-user: find and init PCI device
   vfio-user: run vfio-user context
   vfio-user: handle PCI config space accesses
   vfio-user: IOMMU support for remote device
   vfio-user: handle DMA mappings
   vfio-user: handle PCI BAR accesses
   vfio-user: handle device interrupts
   vfio-user: handle reset of remote device

Sam Li (1):
   Use io_uring_register_ring_fd() to skip fd operations

Stefan Hajnoczi (2):
   linux-aio: fix unbalanced plugged counter in laio_io_unplug()
   linux-aio: explain why max batch is checked in laio_io_unplug()

Vladimir Sementsov-Ogievskiy (1):
   MAINTAINERS: update Vladimir's address and repositories

  MAINTAINERS |  27 +-
  meson_options.txt   |   2 +
  qapi/misc.json  |  31 +
  qapi/qom.json   |  20 +-
  configure   |  17 +
  meson.build |  24 +-
  include/exec/memory.h   |   3 +
  include/hw/pci/msi.h|   1 +
  include/hw/pci/msix.h   |   1 +
  include/hw/pci/pci.h|  13 +
  include/hw/qdev-core.h  |  29 +
  include/hw/remote/iommu.h   |  40 +
  include/hw/remote/machine.h |   4 +
  include/hw/remote/vfio-user-obj.h   |   6 +
  block/io_uring.c|  12 +-
  block/linux-aio.c   |  10 +-
  hw/core/qdev.c  |  24 +
  hw/pci/msi.c|  49 +-
  hw/pci/msix.c   |  35 +-
  hw/pci/pci.c|  13 +
  hw/remote/iommu.c   | 131 
  hw/remote/machine.c |  88 ++-
  hw/remote/vfio-user-obj.c   | 958 
  softmmu/physmem.c   |   4 +-
  softmmu/qdev-monitor.c  |   4 +
  stubs/vfio-user-obj.c   |   6 +
  tests/qtest/fuzz/generic_fuzz.c |   9 +-
  .gitlab-ci.d/buildtest.yml  |   1 +
  .gitmodules |   3 +
  Kconfig.host|   4 +
  hw/remote/Kconfig   |   4 +
  hw/remote/meson.build   |   4 +
  hw/remote/trace-events  |  11 +
  scripts/meson-buildoptions.sh   |   4 +
  stubs/meson.build   |   1 +
  subprojects/libvfio-user|   1 +
  tests/docker/dockerfiles/centos8.docker |   2 +
  37 files changed, 1565 insertions(+), 31 deletions(-)
  create mode 100644 include/hw/remote/iommu.h
  create mode 100644 include/hw/remote/vfio-user-obj.h
  create mode 100644 hw/remote/iommu.c
  create mode 100644 hw/remote/vfio-user-obj.c
  create mode 100644 stubs/vfio-user-obj.c
  create mode 16 subprojects/libvfio-user






[PATCH] target/riscv/pmp: guard against PMP ranges with a negative size

2022-06-15 Thread Nicolas Pitre
For a TOR entry to match, the stard address must be lower than the end
address. Normally this is always the case, but correct code might still
run into the following scenario:

Initial state:

pmpaddr3 = 0x2000   pmp3cfg = OFF
pmpaddr4 = 0x3000   pmp4cfg = TOR

Execution:

1. write 0x40ff to pmpaddr3
2. write 0x32ff to pmpaddr4
3. set pmp3cfg to NAPOT with a read-modify-write on pmpcfg0
4. set pmp4cfg to NAPOT with a read-modify-write on pmpcfg1

When (2) is emulated, a call to pmp_update_rule() creates a negative
range for pmp4 as pmp4cfg is still set to TOR. And when (3) is emulated,
a call to tlb_flush() is performed, causing pmp_get_tlb_size() to return
a very creatively large TLB size for pmp4. This, in turn, may result in
accesses to non-existent/unitialized memory regions and a fault, so that
(4) ends up never being executed.

This is in m-mode with MPRV unset, meaning that unlocked PMP entries
should have no effect. Therefore such a behavior based on PMP content
is very unexpected.

Make sure no negative PMP range can be created, whether explicitly by
the emulated code or implicitly like the above.

Signed-off-by: Nicolas Pitre 

diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
index 151da3fa08..ea2b67d947 100644
--- a/target/riscv/pmp.c
+++ b/target/riscv/pmp.c
@@ -167,6 +167,9 @@ void pmp_update_rule_addr(CPURISCVState *env, uint32_t 
pmp_index)
 case PMP_AMATCH_TOR:
 sa = prev_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
 ea = (this_addr << 2) - 1u;
+if (sa > ea) {
+sa = ea = 0u;
+}
 break;
 
 case PMP_AMATCH_NA4:



Re: [PATCH V8 04/39] memory: RAM_ANON flag

2022-06-15 Thread David Hildenbrand
On 15.06.22 16:51, Steve Sistare wrote:
> A memory-backend-ram or a memory-backend-memfd block with the RAM_SHARED
> flag set is not migrated when migrate_ignore_shared() is true, but this
> is wrong, because it has no named backing store, and its contents will be
> lost.  Define a new flag RAM_ANON to distinguish this case.  Cpr will also
> test this flag, for similar reasons.
> 
> Signed-off-by: Steve Sistare 
> ---
>  backends/hostmem-epc.c   |  2 +-
>  backends/hostmem-memfd.c |  1 +
>  backends/hostmem-ram.c   |  1 +
>  include/exec/memory.h|  3 +++
>  include/exec/ram_addr.h  |  1 +
>  migration/ram.c  |  3 ++-
>  softmmu/physmem.c| 12 +---
>  7 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c
> index 037292d..cb06255 100644
> --- a/backends/hostmem-epc.c
> +++ b/backends/hostmem-epc.c
> @@ -37,7 +37,7 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, 
> Error **errp)
>  }
>  
>  name = object_get_canonical_path(OBJECT(backend));
> -ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED;
> +ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED | MAP_ANON;

I'm pretty sure that doesn't compile. -> RAM_ANON

>  memory_region_init_ram_from_fd(>mr, OBJECT(backend),
> name, backend->size, ram_flags,
> fd, 0, errp);
> diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
> index 3fc85c3..c9d8001 100644
> --- a/backends/hostmem-memfd.c
> +++ b/backends/hostmem-memfd.c
> @@ -55,6 +55,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, 
> Error **errp)
>  name = host_memory_backend_get_name(backend);
>  ram_flags = backend->share ? RAM_SHARED : 0;
>  ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
> +ram_flags |= RAM_ANON;
>  memory_region_init_ram_from_fd(>mr, OBJECT(backend), name,
> backend->size, ram_flags, fd, 0, errp);
>  g_free(name);
> diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
> index b8e55cd..5e80149 100644
> --- a/backends/hostmem-ram.c
> +++ b/backends/hostmem-ram.c
> @@ -30,6 +30,7 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error 
> **errp)
>  name = host_memory_backend_get_name(backend);
>  ram_flags = backend->share ? RAM_SHARED : 0;
>  ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
> +ram_flags |= RAM_ANON;
>  memory_region_init_ram_flags_nomigrate(>mr, OBJECT(backend), 
> name,
> backend->size, ram_flags, errp);
>  g_free(name);
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index f1c1945..0daddd7 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -203,6 +203,9 @@ typedef struct IOMMUTLBEvent {
>  /* RAM that isn't accessible through normal means. */
>  #define RAM_PROTECTED (1 << 8)
>  
> +/* RAM has no name outside the qemu process. */
> +#define RAM_ANON (1 << 9)

That name is a bit misleading because it mangles anonymous memory with
an anonymous file, which doesn't provide anonymous memory in "kernel
speak". Please find a better name, some idea below ...

I think what you actual want to know is: is this from a real file,
instead of from an anonymous file or anonymous memory. A real file can
be re-opened and remapped after closing QEMU. Further, you need
MAP_SHARED semantics.


/* RAM maps a real file instead of an anonymous file or no file/fd. */
#define RAM_REAL_FILE (1 << 9)

bool ramblock_maps_real_file(RAMBlock *rb)
{
return rb->flags & RAM_REAL_FILE;
}


Maybe we can come up with a better name for "real file".


Set the flag from applicable callsites. When setting the flag
internally, assert that we don't have a fd -- that cannot possibly make
sense.

At applicable callsites check for ramblock_maps_real_file() and that
it's actually a shared mapping. If not, it cannot be preserved by
restarting QEMU (easily, there might be ways for memfd involving other
processes).


Make sense?

-- 
Thanks,

David / dhildenb




[PATCH 10/11] target/ppc: Move slbsync to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/insn32.decode |  2 ++
 target/ppc/translate.c   | 17 -
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index 34f0e3cbeb..f7ebca578b 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -807,6 +807,8 @@ SLBMFEE 01 . - . 1110010011 -   
@X_tb
 
 SLBFEE  01 . - . 010011 1   @X_tb
 
+SLBSYNC 01 - - - 0101010010 -
+
 ## TLB Management Instructions
 
 _tlbierb rs ric prs:bool r:bool
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 62f3c19e6a..b005c15f98 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5388,20 +5388,6 @@ static void gen_tlbsync(DisasContext *ctx)
 #endif /* defined(CONFIG_USER_ONLY) */
 }
 
-#if defined(TARGET_PPC64)
-/* slbsync */
-static void gen_slbsync(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-GEN_PRIV(ctx);
-#else
-CHK_SV(ctx);
-gen_check_tlb_flush(ctx, true);
-#endif /* defined(CONFIG_USER_ONLY) */
-}
-
-#endif  /* defined(TARGET_PPC64) */
-
 /***  External control ***/
 /* Optional: */
 
@@ -6803,9 +6789,6 @@ GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, 
PPC_MEM_TLBIA),
  * different ISA versions
  */
 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
-#if defined(TARGET_PPC64)
-GEN_HANDLER_E(slbsync, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
-#endif
 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x0001, PPC_EXTERN),
 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x0001, PPC_EXTERN),
 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index 260bce35ac..c90cad10b4 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -139,6 +139,20 @@ static bool trans_SLBFEE(DisasContext *ctx, arg_SLBFEE *a)
 return true;
 }
 
+static bool trans_SLBSYNC(DisasContext *ctx, arg_SLBSYNC *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS2(ctx, ISA300);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_check_tlb_flush(ctx, true);
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




Re: [PATCH v2] docs: add PCIe root bus for VGA compat guideline

2022-06-15 Thread Alex Williamson
On Tue, 14 Jun 2022 10:52:52 +0200
Gerd Hoffmann  wrote:

> On Mon, Jun 13, 2022 at 03:47:04PM +0200, Laszlo Ersek wrote:
> > On 06/12/22 19:32, Kevin Locke wrote:  
> > > PCI Express devices which use legacy VGA compatibility should be placed
> > > on the Root Complex.  This simplifies ioport access to VGA registers,
> > > which requires use of a special exception bit to work across PCI(e)
> > > bridges.  It is also necessary for ioport access to VESA BIOS Extension
> > > (VBE) registers, which is not forwarded over PCI(e) bridges, even with
> > > the special exception bit for VGA register access.[1]
> > > 
> > > Update the PCI Express Guidelines to add these to the list of devices
> > > which can be placed directly on the Root Complex.
> > > 
> > > Note that the only PCI Express display devices currently supported
> > > (bochs-display and virtio-gpu-pci) do not offer VGA compatibility.
> > > Legacy PCI devices (e.g. vga, qxl-vga, virtio-vga) are already
> > > documented as allowed on the Root Complex by the first item in the list.
> > > However, this item documents an additional consideration for placing
> > > devices which was not previously mentioned, and may be relevant for PCIe
> > > devices offering VGA compatibility in the future.  
> 
> Well, the *key* problem is emulated VGA devices with VBE registers in
> io address space, because those are not forwarded over bridges.
> 
> For normal VGA registers this isn't much of a problem (in theory, not
> fully sure whenever that holds in practice, Alex?).  The linux kernel
> knows how to use the bridge control register to manage access to VGA
> registers.

Yes, AUIU the issue is entirely with the extended VBE requirements, the
VGA ranges are fully routable through the VGA control registers on the
bridge.  The only bare metal issue I'm aware of with VGA routing is
that we cannot route around Intel IGD.  IIRC, this latter quirk is the
only reason that enabling VGA routing for a vfio-pci device is
considered experimental, but it very much does work when there's no
host device silently consuming those ranges.

We've also historically had issues with AMD graphics drivers assuming
an express link which can lead to driver segfaults if those devices are
placed on the root complex.  OTOH, I'm not aware of any specific issues
with placing assigned VGA class GPUs in configurations with a root port.

I'd therefore expect any configuration guidelines we're proposing to be
very specific to devices that make use of VBE, not just VGA devices in
general.  Thanks,

Alex




[PATCH 08/11] target/ppc: Move slbmfee to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  2 +-
 target/ppc/insn32.decode |  1 +
 target/ppc/mmu-hash64.c  |  2 +-
 target/ppc/translate.c   | 13 -
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index dee6dfe6f4..271dd585e0 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -683,7 +683,7 @@ DEF_HELPER_FLAGS_2(tlbiva, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_FLAGS_4(tlbie_isa300, TCG_CALL_NO_WG, void, \
 env, tl, tl, i32)
 DEF_HELPER_FLAGS_3(SLBMTE, TCG_CALL_NO_RWG, void, env, tl, tl)
-DEF_HELPER_2(load_slb_esid, tl, env, tl)
+DEF_HELPER_2(SLBMFEE, tl, env, tl)
 DEF_HELPER_2(SLBMFEV, tl, env, tl)
 DEF_HELPER_2(find_slb_vsid, tl, env, tl)
 DEF_HELPER_FLAGS_2(SLBIA, TCG_CALL_NO_RWG, void, env, i32)
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index c0239335a1..22614ee915 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -803,6 +803,7 @@ SLBIA   01 --... - - 010010 -   
@X_ih
 SLBMTE  01 . - . 0110010010 -   @X_tb
 
 SLBMFEV 01 . - . 1101010011 -   @X_tb
+SLBMFEE 01 . - . 1110010011 -   @X_tb
 
 ## TLB Management Instructions
 
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 7854b91043..5d73d64436 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -319,7 +319,7 @@ void helper_SLBMTE(CPUPPCState *env, target_ulong rb, 
target_ulong rs)
 }
 }
 
-target_ulong helper_load_slb_esid(CPUPPCState *env, target_ulong rb)
+target_ulong helper_SLBMFEE(CPUPPCState *env, target_ulong rb)
 {
 PowerPCCPU *cpu = env_archcpu(env);
 target_ulong rt = 0;
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index f0fc375b0c..dc87316ce7 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5351,18 +5351,6 @@ static void gen_mtsrin_64b(DisasContext *ctx)
 #endif /* defined(CONFIG_USER_ONLY) */
 }
 
-static void gen_slbmfee(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-GEN_PRIV(ctx);
-#else
-CHK_SV(ctx);
-
-gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
- cpu_gpr[rB(ctx->opcode)]);
-#endif /* defined(CONFIG_USER_ONLY) */
-}
-
 
 static void gen_slbfee_(DisasContext *ctx)
 {
@@ -6833,7 +6821,6 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 
0x001F0001,
 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
  PPC_SEGMENT_64B),
-GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, 
PPC_SEGMENT_64B),
 GEN_HANDLER2(slbfee_, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F, 
PPC_SEGMENT_64B),
 #endif
 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index a037fc2b95..b169bd6317 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -91,6 +91,20 @@ static bool trans_SLBMFEV(DisasContext *ctx, arg_SLBMFEV *a)
 return true;
 }
 
+static bool trans_SLBMFEE(DisasContext *ctx, arg_SLBMFEE *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS(ctx, SEGMENT_64B);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_helper_SLBMFEE(cpu_gpr[a->rt], cpu_env, cpu_gpr[a->rb]);
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




[PATCH 05/11] target/ppc: Move slbia to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  2 +-
 target/ppc/insn32.decode |  5 +
 target/ppc/mmu-hash64.c  |  2 +-
 target/ppc/translate.c   | 17 -
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 5 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 86cd12f399..4fbabda2f6 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -686,7 +686,7 @@ DEF_HELPER_FLAGS_3(store_slb, TCG_CALL_NO_RWG, void, env, 
tl, tl)
 DEF_HELPER_2(load_slb_esid, tl, env, tl)
 DEF_HELPER_2(load_slb_vsid, tl, env, tl)
 DEF_HELPER_2(find_slb_vsid, tl, env, tl)
-DEF_HELPER_FLAGS_2(slbia, TCG_CALL_NO_RWG, void, env, i32)
+DEF_HELPER_FLAGS_2(SLBIA, TCG_CALL_NO_RWG, void, env, i32)
 DEF_HELPER_FLAGS_2(SLBIE, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_FLAGS_2(SLBIEG, TCG_CALL_NO_RWG, void, env, tl)
 #endif
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index b900fd8f17..c378b34b58 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -131,6 +131,9 @@
 _imm8 xt imm:uint8_t
 @X_imm8 .. . .. imm:8 .. .  _imm8 
xt=%x_xt
 
+_ih   ih:uint8_t
+@X_ih   .. .. ih:3 . . .. . _ih
+
 _rb   rb
 @X_rb   .. . . rb:5 .. ._rb
 
@@ -795,6 +798,8 @@ XVF64GERNN  111011 ... --  0 . 1010 ..-  
@XX3_at xa=%xx_xa_pair
 SLBIE   01 - - . 0110110010 -   @X_rb
 SLBIEG  01 . - . 0111010010 -   @X_tb
 
+SLBIA   01 --... - - 010010 -   @X_ih
+
 ## TLB Management Instructions
 
 _tlbierb rs ric prs:bool r:bool
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index a842fbd6f6..dd2c7e588f 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -101,7 +101,7 @@ void dump_slb(PowerPCCPU *cpu)
 }
 
 #ifdef CONFIG_TCG
-void helper_slbia(CPUPPCState *env, uint32_t ih)
+void helper_SLBIA(CPUPPCState *env, uint32_t ih)
 {
 PowerPCCPU *cpu = env_archcpu(env);
 int starting_entry;
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 6e47b81bf7..cf83890f82 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5450,22 +5450,6 @@ static void gen_tlbsync(DisasContext *ctx)
 }
 
 #if defined(TARGET_PPC64)
-/* slbia */
-static void gen_slbia(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-GEN_PRIV(ctx);
-#else
-uint32_t ih = (ctx->opcode >> 21) & 0x7;
-TCGv_i32 t0 = tcg_const_i32(ih);
-
-CHK_SV(ctx);
-
-gen_helper_slbia(cpu_env, t0);
-tcg_temp_free_i32(t0);
-#endif /* defined(CONFIG_USER_ONLY) */
-}
-
 /* slbsync */
 static void gen_slbsync(DisasContext *ctx)
 {
@@ -6885,7 +6869,6 @@ GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, 
PPC_MEM_TLBIA),
  */
 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
 #if defined(TARGET_PPC64)
-GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI),
 GEN_HANDLER_E(slbsync, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
 #endif
 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x0001, PPC_EXTERN),
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index b9bb950f7d..cbb8b81f13 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -49,6 +49,20 @@ static bool trans_SLBIEG(DisasContext *ctx, arg_SLBIEG *a)
 return true;
 }
 
+static bool trans_SLBIA(DisasContext *ctx, arg_SLBIA *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS(ctx, SLBI);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_helper_SLBIA(cpu_env, tcg_constant_i32(a->ih));
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




[PATCH 04/11] target/ppc: Move slbieg to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  2 +-
 target/ppc/insn32.decode |  1 +
 target/ppc/mmu-hash64.c  |  2 +-
 target/ppc/translate.c   | 13 -
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 793f307ab0..86cd12f399 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -688,7 +688,7 @@ DEF_HELPER_2(load_slb_vsid, tl, env, tl)
 DEF_HELPER_2(find_slb_vsid, tl, env, tl)
 DEF_HELPER_FLAGS_2(slbia, TCG_CALL_NO_RWG, void, env, i32)
 DEF_HELPER_FLAGS_2(SLBIE, TCG_CALL_NO_RWG, void, env, tl)
-DEF_HELPER_FLAGS_2(slbieg, TCG_CALL_NO_RWG, void, env, tl)
+DEF_HELPER_FLAGS_2(SLBIEG, TCG_CALL_NO_RWG, void, env, tl)
 #endif
 DEF_HELPER_FLAGS_2(load_sr, TCG_CALL_NO_RWG, tl, env, tl)
 DEF_HELPER_FLAGS_3(store_sr, TCG_CALL_NO_RWG, void, env, tl, tl)
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index af13625832..b900fd8f17 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -793,6 +793,7 @@ XVF64GERNN  111011 ... --  0 . 1010 ..-  
@XX3_at xa=%xx_xa_pair
 ## SLB Management Instructions
 
 SLBIE   01 - - . 0110110010 -   @X_rb
+SLBIEG  01 . - . 0111010010 -   @X_tb
 
 ## TLB Management Instructions
 
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 03f71a82ec..a842fbd6f6 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -202,7 +202,7 @@ void helper_SLBIE(CPUPPCState *env, target_ulong addr)
 __helper_slbie(env, addr, false);
 }
 
-void helper_slbieg(CPUPPCState *env, target_ulong addr)
+void helper_SLBIEG(CPUPPCState *env, target_ulong addr)
 {
 __helper_slbie(env, addr, true);
 }
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index b0bb67b676..6e47b81bf7 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5466,18 +5466,6 @@ static void gen_slbia(DisasContext *ctx)
 #endif /* defined(CONFIG_USER_ONLY) */
 }
 
-/* slbieg */
-static void gen_slbieg(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-GEN_PRIV(ctx);
-#else
-CHK_SV(ctx);
-
-gen_helper_slbieg(cpu_env, cpu_gpr[rB(ctx->opcode)]);
-#endif /* defined(CONFIG_USER_ONLY) */
-}
-
 /* slbsync */
 static void gen_slbsync(DisasContext *ctx)
 {
@@ -6898,7 +6886,6 @@ GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, 
PPC_MEM_TLBIA),
 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
 #if defined(TARGET_PPC64)
 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI),
-GEN_HANDLER_E(slbieg, 0x1F, 0x12, 0x0E, 0x001F0001, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(slbsync, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
 #endif
 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x0001, PPC_EXTERN),
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index 41fc5ade8b..b9bb950f7d 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -35,6 +35,20 @@ static bool trans_SLBIE(DisasContext *ctx, arg_SLBIE *a)
 return true;
 }
 
+static bool trans_SLBIEG(DisasContext *ctx, arg_SLBIEG *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS2(ctx, ISA300);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_helper_SLBIEG(cpu_env, cpu_gpr[a->rb]);
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




[PATCH 03/11] target/ppc: Move slbie to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  2 +-
 target/ppc/insn32.decode |  7 +++
 target/ppc/mmu-hash64.c  |  2 +-
 target/ppc/translate.c   | 13 -
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 5 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 0b2bc8020b..793f307ab0 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -687,7 +687,7 @@ DEF_HELPER_2(load_slb_esid, tl, env, tl)
 DEF_HELPER_2(load_slb_vsid, tl, env, tl)
 DEF_HELPER_2(find_slb_vsid, tl, env, tl)
 DEF_HELPER_FLAGS_2(slbia, TCG_CALL_NO_RWG, void, env, i32)
-DEF_HELPER_FLAGS_2(slbie, TCG_CALL_NO_RWG, void, env, tl)
+DEF_HELPER_FLAGS_2(SLBIE, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_FLAGS_2(slbieg, TCG_CALL_NO_RWG, void, env, tl)
 #endif
 DEF_HELPER_FLAGS_2(load_sr, TCG_CALL_NO_RWG, tl, env, tl)
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index 44ac5f0785..af13625832 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -131,6 +131,9 @@
 _imm8 xt imm:uint8_t
 @X_imm8 .. . .. imm:8 .. .  _imm8 
xt=%x_xt
 
+_rb   rb
+@X_rb   .. . . rb:5 .. ._rb
+
 _uim5 xt uim:uint8_t
 @X_uim5 .. . . uim:5 .. .   _uim5 
xt=%x_xt
 
@@ -787,6 +790,10 @@ XVF64GERPN  111011 ... --  0 . 10111010 ..-  
@XX3_at xa=%xx_xa_pair
 XVF64GERNP  111011 ... --  0 . 0010 ..-  @XX3_at xa=%xx_xa_pair
 XVF64GERNN  111011 ... --  0 . 1010 ..-  @XX3_at xa=%xx_xa_pair
 
+## SLB Management Instructions
+
+SLBIE   01 - - . 0110110010 -   @X_rb
+
 ## TLB Management Instructions
 
 _tlbierb rs ric prs:bool r:bool
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index da9fe99ff8..03f71a82ec 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -197,7 +197,7 @@ static void __helper_slbie(CPUPPCState *env, target_ulong 
addr,
 }
 }
 
-void helper_slbie(CPUPPCState *env, target_ulong addr)
+void helper_SLBIE(CPUPPCState *env, target_ulong addr)
 {
 __helper_slbie(env, addr, false);
 }
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 508ef6660d..b0bb67b676 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5466,18 +5466,6 @@ static void gen_slbia(DisasContext *ctx)
 #endif /* defined(CONFIG_USER_ONLY) */
 }
 
-/* slbie */
-static void gen_slbie(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-GEN_PRIV(ctx);
-#else
-CHK_SV(ctx);
-
-gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
-#endif /* defined(CONFIG_USER_ONLY) */
-}
-
 /* slbieg */
 static void gen_slbieg(DisasContext *ctx)
 {
@@ -6910,7 +6898,6 @@ GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, 
PPC_MEM_TLBIA),
 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
 #if defined(TARGET_PPC64)
 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI),
-GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
 GEN_HANDLER_E(slbieg, 0x1F, 0x12, 0x0E, 0x001F0001, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(slbsync, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
 #endif
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index f9e4a807f2..41fc5ade8b 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -21,6 +21,20 @@
  * Store Control Instructions
  */
 
+static bool trans_SLBIE(DisasContext *ctx, arg_SLBIE *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS(ctx, SLBI);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_helper_SLBIE(cpu_env, cpu_gpr[a->rb]);
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




[PATCH 00/11] target/ppc: Implement slbiag move slb* to decodetree

2022-06-15 Thread Lucas Coutinho
Implement the following PowerISA v3.0 instuction:
slbiag: SLB Invalidate All Global X-form

Move the following PowerISA v3.0 instuction to decodetree:
slbie: SLB Invalidate Entry X-form
slbieg: SLB Invalidate Entry Global X-form
slbia: SLB Invalidate All X-form
slbmte: SLB Move To Entry X-form
slbmfev: SLB Move From Entry VSID X-form
slbmfee: SLB Move From Entry ESID X-form
slbfee: SLB Find Entry ESID
slbsync: SLB Synchronize

Based-on: <20220614163018.39819-1-leandro.lup...@eldorado.org.br>

Lucas Coutinho (9):
  target/ppc: Move slbie to decodetree
  target/ppc: Move slbieg to decodetree
  target/ppc: Move slbia to decodetree
  target/ppc: Move slbmte to decodetree
  target/ppc: Move slbmfev to decodetree
  target/ppc: Move slbmfee to decodetree
  target/ppc: Move slbfee to decodetree
  target/ppc: Move slbsync to decodetree
  target/ppc: Implement slbiag

Matheus Ferst (2):
  target/ppc: receive DisasContext explicitly in GEN_PRIV
  target/ppc: add macros to check privilege level

 target/ppc/helper.h  |  15 +-
 target/ppc/insn32.decode |  26 ++
 target/ppc/mmu-hash64.c  |  41 +-
 target/ppc/translate.c   | 417 +++
 target/ppc/translate/fixedpoint-impl.c.inc   |   7 +-
 target/ppc/translate/fp-impl.c.inc   |   4 +-
 target/ppc/translate/storage-ctrl-impl.c.inc | 146 +++
 7 files changed, 377 insertions(+), 279 deletions(-)

-- 
2.25.1




[PATCH 07/11] target/ppc: Move slbmfev to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  2 +-
 target/ppc/insn32.decode |  2 ++
 target/ppc/mmu-hash64.c  |  2 +-
 target/ppc/translate.c   | 12 
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index acfb360e59..dee6dfe6f4 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -684,7 +684,7 @@ DEF_HELPER_FLAGS_4(tlbie_isa300, TCG_CALL_NO_WG, void, \
 env, tl, tl, i32)
 DEF_HELPER_FLAGS_3(SLBMTE, TCG_CALL_NO_RWG, void, env, tl, tl)
 DEF_HELPER_2(load_slb_esid, tl, env, tl)
-DEF_HELPER_2(load_slb_vsid, tl, env, tl)
+DEF_HELPER_2(SLBMFEV, tl, env, tl)
 DEF_HELPER_2(find_slb_vsid, tl, env, tl)
 DEF_HELPER_FLAGS_2(SLBIA, TCG_CALL_NO_RWG, void, env, i32)
 DEF_HELPER_FLAGS_2(SLBIE, TCG_CALL_NO_RWG, void, env, tl)
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index 00d033559f..c0239335a1 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -802,6 +802,8 @@ SLBIA   01 --... - - 010010 -   
@X_ih
 
 SLBMTE  01 . - . 0110010010 -   @X_tb
 
+SLBMFEV 01 . - . 1101010011 -   @X_tb
+
 ## TLB Management Instructions
 
 _tlbierb rs ric prs:bool r:bool
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 1922960608..7854b91043 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -343,7 +343,7 @@ target_ulong helper_find_slb_vsid(CPUPPCState *env, 
target_ulong rb)
 return rt;
 }
 
-target_ulong helper_load_slb_vsid(CPUPPCState *env, target_ulong rb)
+target_ulong helper_SLBMFEV(CPUPPCState *env, target_ulong rb)
 {
 PowerPCCPU *cpu = env_archcpu(env);
 target_ulong rt = 0;
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index efd00c7f77..f0fc375b0c 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5363,17 +5363,6 @@ static void gen_slbmfee(DisasContext *ctx)
 #endif /* defined(CONFIG_USER_ONLY) */
 }
 
-static void gen_slbmfev(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-GEN_PRIV(ctx);
-#else
-CHK_SV(ctx);
-
-gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
- cpu_gpr[rB(ctx->opcode)]);
-#endif /* defined(CONFIG_USER_ONLY) */
-}
 
 static void gen_slbfee_(DisasContext *ctx)
 {
@@ -6845,7 +6834,6 @@ GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 
0x0010F801, PPC_SEGMENT_64B),
 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
  PPC_SEGMENT_64B),
 GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, 
PPC_SEGMENT_64B),
-GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, 
PPC_SEGMENT_64B),
 GEN_HANDLER2(slbfee_, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F, 
PPC_SEGMENT_64B),
 #endif
 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index 4c2dd758b5..a037fc2b95 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -77,6 +77,20 @@ static bool trans_SLBMTE(DisasContext *ctx, arg_SLBMTE *a)
 return true;
 }
 
+static bool trans_SLBMFEV(DisasContext *ctx, arg_SLBMFEV *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS(ctx, SEGMENT_64B);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_helper_SLBMFEV(cpu_gpr[a->rt], cpu_env, cpu_gpr[a->rb]);
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




[PATCH 02/11] target/ppc: add macros to check privilege level

2022-06-15 Thread Lucas Coutinho
From: Matheus Ferst 

Equivalent to CHK_SV and CHK_HV, but can be used in decodetree methods.

Signed-off-by: Matheus Ferst 
Signed-off-by: Lucas Coutinho 
---
 target/ppc/translate.c | 21 +
 target/ppc/translate/fixedpoint-impl.c.inc |  7 ++-
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 920bb543cf..508ef6660d 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -6575,6 +6575,27 @@ static int times_16(DisasContext *ctx, int x)
 }   \
 } while (0)
 
+#if !defined(CONFIG_USER_ONLY)
+#define REQUIRE_SV(CTX) \
+do {\
+if (unlikely((CTX)->pr)) {  \
+gen_priv_opc(CTX);  \
+return true;\
+}   \
+} while (0)
+
+#define REQUIRE_HV(CTX) \
+do {\
+if (unlikely((CTX)->pr || !(CTX)->hv))  \
+gen_priv_opc(CTX);  \
+return true;\
+}   \
+} while (0)
+#else
+#define REQUIRE_SV(CTX) do { gen_priv_opc(CTX); return true; } while (0)
+#define REQUIRE_HV(CTX) do { gen_priv_opc(CTX); return true; } while (0)
+#endif
+
 /*
  * Helpers for implementing sets of trans_* functions.
  * Defer the implementation of NAME to FUNC, with optional extra arguments.
diff --git a/target/ppc/translate/fixedpoint-impl.c.inc 
b/target/ppc/translate/fixedpoint-impl.c.inc
index 1aab32be03..77d449c3cd 100644
--- a/target/ppc/translate/fixedpoint-impl.c.inc
+++ b/target/ppc/translate/fixedpoint-impl.c.inc
@@ -79,11 +79,8 @@ static bool do_ldst_quad(DisasContext *ctx, arg_D *a, bool 
store, bool prefixed)
 REQUIRE_INSNS_FLAGS(ctx, 64BX);
 
 if (!prefixed && !(ctx->insns_flags2 & PPC2_LSQ_ISA207)) {
-if (ctx->pr) {
-/* lq and stq were privileged prior to V. 2.07 */
-gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC);
-return true;
-}
+/* lq and stq were privileged prior to V. 2.07 */
+REQUIRE_SV(ctx);
 
 if (ctx->le_mode) {
 gen_align_no_le(ctx);
-- 
2.25.1




[PATCH 11/11] target/ppc: Implement slbiag

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  1 +
 target/ppc/insn32.decode |  4 +++
 target/ppc/mmu-hash64.c  | 27 
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 4 files changed, 46 insertions(+)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index de7bf9f175..4287f41880 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -687,6 +687,7 @@ DEF_HELPER_2(SLBMFEE, tl, env, tl)
 DEF_HELPER_2(SLBMFEV, tl, env, tl)
 DEF_HELPER_2(SLBFEE, tl, env, tl)
 DEF_HELPER_FLAGS_2(SLBIA, TCG_CALL_NO_RWG, void, env, i32)
+DEF_HELPER_FLAGS_3(SLBIAG, TCG_CALL_NO_RWG, void, env, tl, i32)
 DEF_HELPER_FLAGS_2(SLBIE, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_FLAGS_2(SLBIEG, TCG_CALL_NO_RWG, void, env, tl)
 #endif
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index f7ebca578b..b36a093828 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -137,6 +137,9 @@
 _rb   rb
 @X_rb   .. . . rb:5 .. ._rb
 
+_rs_l rs l:bool
+@X_rs_l .. rs:5  l:1 . .. . _rs_l
+
 _uim5 xt uim:uint8_t
 @X_uim5 .. . . uim:5 .. .   _uim5 
xt=%x_xt
 
@@ -799,6 +802,7 @@ SLBIE   01 - - . 0110110010 -   
@X_rb
 SLBIEG  01 . - . 0111010010 -   @X_tb
 
 SLBIA   01 --... - - 010010 -   @X_ih
+SLBIAG  01 . . - 1101010010 -   @X_rs_l
 
 SLBMTE  01 . - . 0110010010 -   @X_tb
 
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 7ec7a67a78..b9b31fd276 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -173,6 +173,33 @@ void helper_SLBIA(CPUPPCState *env, uint32_t ih)
 }
 }
 
+#if defined(TARGET_PPC64)
+void helper_SLBIAG(CPUPPCState *env, target_ulong rs, uint32_t l)
+{
+PowerPCCPU *cpu = env_archcpu(env);
+int n;
+
+/*
+ * slbiag must always flush all TLB (which is equivalent to ERAT in ppc
+ * architecture). Matching on SLB_ESID_V is not good enough, because slbmte
+ * can overwrite a valid SLB without flushing its lookaside information.
+ *
+ * It would be possible to keep the TLB in synch with the SLB by flushing
+ * when a valid entry is overwritten by slbmte, and therefore slbiag would
+ * not have to flush unless it evicts a valid SLB entry. However it is
+ * expected that slbmte is more common than slbiag, and slbiag is usually
+ * going to evict valid SLB entries, so that tradeoff is unlikely to be a
+ * good one.
+ */
+env->tlb_need_flush |= TLB_NEED_LOCAL_FLUSH;
+
+for (n = 0; n < cpu->hash64_opts->slb_size; n++) {
+ppc_slb_t *slb = >slb[n];
+slb->esid &= ~SLB_ESID_V;
+}
+}
+#endif
+
 static void __helper_slbie(CPUPPCState *env, target_ulong addr,
target_ulong global)
 {
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index c90cad10b4..6a4ba4089e 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -63,6 +63,20 @@ static bool trans_SLBIA(DisasContext *ctx, arg_SLBIA *a)
 return true;
 }
 
+static bool trans_SLBIAG(DisasContext *ctx, arg_SLBIAG *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS2(ctx, ISA300);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_helper_SLBIAG(cpu_env, cpu_gpr[a->rs], tcg_constant_i32(a->l));
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool trans_SLBMTE(DisasContext *ctx, arg_SLBMTE *a)
 {
 REQUIRE_64BIT(ctx);
-- 
2.25.1




[PATCH 06/11] target/ppc: Move slbmte to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  2 +-
 target/ppc/insn32.decode |  2 ++
 target/ppc/mmu-hash64.c  |  2 +-
 target/ppc/translate.c   | 14 --
 target/ppc/translate/storage-ctrl-impl.c.inc | 14 ++
 5 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 4fbabda2f6..acfb360e59 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -682,7 +682,7 @@ DEF_HELPER_FLAGS_2(tlbiva, TCG_CALL_NO_RWG, void, env, tl)
 
 DEF_HELPER_FLAGS_4(tlbie_isa300, TCG_CALL_NO_WG, void, \
 env, tl, tl, i32)
-DEF_HELPER_FLAGS_3(store_slb, TCG_CALL_NO_RWG, void, env, tl, tl)
+DEF_HELPER_FLAGS_3(SLBMTE, TCG_CALL_NO_RWG, void, env, tl, tl)
 DEF_HELPER_2(load_slb_esid, tl, env, tl)
 DEF_HELPER_2(load_slb_vsid, tl, env, tl)
 DEF_HELPER_2(find_slb_vsid, tl, env, tl)
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index c378b34b58..00d033559f 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -800,6 +800,8 @@ SLBIEG  01 . - . 0111010010 -   
@X_tb
 
 SLBIA   01 --... - - 010010 -   @X_ih
 
+SLBMTE  01 . - . 0110010010 -   @X_tb
+
 ## TLB Management Instructions
 
 _tlbierb rs ric prs:bool r:bool
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index dd2c7e588f..1922960608 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -309,7 +309,7 @@ static int ppc_find_slb_vsid(PowerPCCPU *cpu, target_ulong 
rb,
 return 0;
 }
 
-void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs)
+void helper_SLBMTE(CPUPPCState *env, target_ulong rb, target_ulong rs)
 {
 PowerPCCPU *cpu = env_archcpu(env);
 
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index cf83890f82..efd00c7f77 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5351,19 +5351,6 @@ static void gen_mtsrin_64b(DisasContext *ctx)
 #endif /* defined(CONFIG_USER_ONLY) */
 }
 
-/* slbmte */
-static void gen_slbmte(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-GEN_PRIV(ctx);
-#else
-CHK_SV(ctx);
-
-gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
- cpu_gpr[rS(ctx->opcode)]);
-#endif /* defined(CONFIG_USER_ONLY) */
-}
-
 static void gen_slbmfee(DisasContext *ctx)
 {
 #if defined(CONFIG_USER_ONLY)
@@ -6857,7 +6844,6 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 
0x001F0001,
 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
  PPC_SEGMENT_64B),
-GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
 GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, 
PPC_SEGMENT_64B),
 GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, 
PPC_SEGMENT_64B),
 GEN_HANDLER2(slbfee_, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F, 
PPC_SEGMENT_64B),
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index cbb8b81f13..4c2dd758b5 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -63,6 +63,20 @@ static bool trans_SLBIA(DisasContext *ctx, arg_SLBIA *a)
 return true;
 }
 
+static bool trans_SLBMTE(DisasContext *ctx, arg_SLBMTE *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS(ctx, SEGMENT_64B);
+REQUIRE_SV(ctx);
+
+#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
+gen_helper_SLBMTE(cpu_env, cpu_gpr[a->rb], cpu_gpr[a->rt]);
+#else
+qemu_build_not_reached();
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




[PATCH 01/11] target/ppc: receive DisasContext explicitly in GEN_PRIV

2022-06-15 Thread Lucas Coutinho
From: Matheus Ferst 

GEN_PRIV and related CHK_* macros just assumed that variable named
"ctx" would be in scope when they are used, and that it would be a
pointer to DisasContext. Change these macros to receive the pointer
explicitly.

Signed-off-by: Matheus Ferst 
Signed-off-by: Lucas Coutinho 
---
 target/ppc/translate.c | 299 +++--
 target/ppc/translate/fp-impl.c.inc |   4 +-
 2 files changed, 154 insertions(+), 149 deletions(-)

diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 4fcb311c2d..920bb543cf 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -1267,38 +1267,43 @@ typedef struct opcode_t {
 const char *oname;
 } opcode_t;
 
+static void gen_priv_opc(DisasContext *ctx)
+{
+gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC);
+}
+
 /* Helpers for priv. check */
-#define GEN_PRIV\
-do {\
-gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
+#define GEN_PRIV(CTX)  \
+do {   \
+gen_priv_opc(CTX); return; \
 } while (0)
 
 #if defined(CONFIG_USER_ONLY)
-#define CHK_HV GEN_PRIV
-#define CHK_SV GEN_PRIV
-#define CHK_HVRM GEN_PRIV
+#define CHK_HV(CTX) GEN_PRIV(CTX)
+#define CHK_SV(CTX) GEN_PRIV(CTX)
+#define CHK_HVRM(CTX) GEN_PRIV(CTX)
 #else
-#define CHK_HV  \
-do {\
-if (unlikely(ctx->pr || !ctx->hv)) {\
-GEN_PRIV;   \
-}   \
+#define CHK_HV(CTX) \
+do {\
+if (unlikely(ctx->pr || !ctx->hv)) {\
+GEN_PRIV(CTX);  \
+}   \
 } while (0)
-#define CHK_SV   \
+#define CHK_SV(CTX)  \
 do { \
 if (unlikely(ctx->pr)) { \
-GEN_PRIV;\
+GEN_PRIV(CTX);   \
 }\
 } while (0)
-#define CHK_HVRM\
-do {\
-if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
-GEN_PRIV;   \
-}   \
+#define CHK_HVRM(CTX)   \
+do {\
+if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
+GEN_PRIV(CTX);  \
+}   \
 } while (0)
 #endif
 
-#define CHK_NONE
+#define CHK_NONE(CTX)
 
 /*/
 /* PowerPC instructions table*/
@@ -3252,7 +3257,7 @@ GEN_QEMU_STORE_64(st64r, BSWAP_MEMOP(MO_UQ))
 static void glue(gen_, name##x)(DisasContext *ctx)\
 { \
 TCGv EA;  \
-chk;  \
+chk(ctx); \
 gen_set_access_type(ctx, ACCESS_INT); \
 EA = tcg_temp_new();  \
 gen_addr_reg_index(ctx, EA);  \
@@ -3270,7 +3275,7 @@ static void glue(gen_, name##x)(DisasContext *ctx)
\
 static void glue(gen_, name##epx)(DisasContext *ctx)  \
 { \
 TCGv EA;  \
-CHK_SV;   \
+CHK_SV(ctx);  \
 gen_set_access_type(ctx, ACCESS_INT); \
 EA = tcg_temp_new();  \
 gen_addr_reg_index(ctx, EA);  \
@@ -3298,7 +3303,7 @@ GEN_LDX_HVRM(lbzcix, ld8u, 0x15, 0x1a, PPC_CILDST)
 static void glue(gen_, name##x)(DisasContext *ctx)\
 { \
 TCGv EA;  \
-chk;   

[PATCH 09/11] target/ppc: Move slbfee to decodetree

2022-06-15 Thread Lucas Coutinho
Signed-off-by: Lucas Coutinho 
---
 target/ppc/helper.h  |  2 +-
 target/ppc/insn32.decode |  2 ++
 target/ppc/mmu-hash64.c  |  2 +-
 target/ppc/translate.c   | 26 ---
 target/ppc/translate/storage-ctrl-impl.c.inc | 34 
 5 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 271dd585e0..de7bf9f175 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -685,7 +685,7 @@ DEF_HELPER_FLAGS_4(tlbie_isa300, TCG_CALL_NO_WG, void, \
 DEF_HELPER_FLAGS_3(SLBMTE, TCG_CALL_NO_RWG, void, env, tl, tl)
 DEF_HELPER_2(SLBMFEE, tl, env, tl)
 DEF_HELPER_2(SLBMFEV, tl, env, tl)
-DEF_HELPER_2(find_slb_vsid, tl, env, tl)
+DEF_HELPER_2(SLBFEE, tl, env, tl)
 DEF_HELPER_FLAGS_2(SLBIA, TCG_CALL_NO_RWG, void, env, i32)
 DEF_HELPER_FLAGS_2(SLBIE, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_FLAGS_2(SLBIEG, TCG_CALL_NO_RWG, void, env, tl)
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index 22614ee915..34f0e3cbeb 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -805,6 +805,8 @@ SLBMTE  01 . - . 0110010010 -   
@X_tb
 SLBMFEV 01 . - . 1101010011 -   @X_tb
 SLBMFEE 01 . - . 1110010011 -   @X_tb
 
+SLBFEE  01 . - . 010011 1   @X_tb
+
 ## TLB Management Instructions
 
 _tlbierb rs ric prs:bool r:bool
diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 5d73d64436..7ec7a67a78 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -331,7 +331,7 @@ target_ulong helper_SLBMFEE(CPUPPCState *env, target_ulong 
rb)
 return rt;
 }
 
-target_ulong helper_find_slb_vsid(CPUPPCState *env, target_ulong rb)
+target_ulong helper_SLBFEE(CPUPPCState *env, target_ulong rb)
 {
 PowerPCCPU *cpu = env_archcpu(env);
 target_ulong rt = 0;
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index dc87316ce7..62f3c19e6a 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -5351,31 +5351,6 @@ static void gen_mtsrin_64b(DisasContext *ctx)
 #endif /* defined(CONFIG_USER_ONLY) */
 }
 
-
-static void gen_slbfee_(DisasContext *ctx)
-{
-#if defined(CONFIG_USER_ONLY)
-gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
-#else
-TCGLabel *l1, *l2;
-
-if (unlikely(ctx->pr)) {
-gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
-return;
-}
-gen_helper_find_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
- cpu_gpr[rB(ctx->opcode)]);
-l1 = gen_new_label();
-l2 = gen_new_label();
-tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
-tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rS(ctx->opcode)], -1, l1);
-tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], CRF_EQ);
-tcg_gen_br(l2);
-gen_set_label(l1);
-tcg_gen_movi_tl(cpu_gpr[rS(ctx->opcode)], 0);
-gen_set_label(l2);
-#endif
-}
 #endif /* defined(TARGET_PPC64) */
 
 /***  Lookaside buffer management  ***/
@@ -6821,7 +6796,6 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 
0x001F0001,
 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
  PPC_SEGMENT_64B),
-GEN_HANDLER2(slbfee_, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F, 
PPC_SEGMENT_64B),
 #endif
 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
 /*
diff --git a/target/ppc/translate/storage-ctrl-impl.c.inc 
b/target/ppc/translate/storage-ctrl-impl.c.inc
index b169bd6317..260bce35ac 100644
--- a/target/ppc/translate/storage-ctrl-impl.c.inc
+++ b/target/ppc/translate/storage-ctrl-impl.c.inc
@@ -105,6 +105,40 @@ static bool trans_SLBMFEE(DisasContext *ctx, arg_SLBMFEE 
*a)
 return true;
 }
 
+static bool trans_SLBFEE(DisasContext *ctx, arg_SLBFEE *a)
+{
+REQUIRE_64BIT(ctx);
+REQUIRE_INSNS_FLAGS(ctx, SEGMENT_64B);
+
+#if defined(CONFIG_USER_ONLY)
+gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
+#else
+
+#if defined(TARGET_PPC64)
+TCGLabel *l1, *l2;
+
+if (unlikely(ctx->pr)) {
+gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
+return true;
+}
+gen_helper_SLBFEE(cpu_gpr[a->rt], cpu_env,
+ cpu_gpr[a->rb]);
+l1 = gen_new_label();
+l2 = gen_new_label();
+tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
+tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[a->rt], -1, l1);
+tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], CRF_EQ);
+tcg_gen_br(l2);
+gen_set_label(l1);
+tcg_gen_movi_tl(cpu_gpr[a->rt], 0);
+gen_set_label(l2);
+#else
+qemu_build_not_reached();
+#endif
+#endif
+return true;
+}
+
 static bool do_tlbie(DisasContext *ctx, arg_X_tlbie *a, bool local)
 {
 #if defined(CONFIG_USER_ONLY)
-- 
2.25.1




Re: [PATCH v7 0/6] cutils: Introduce bundle mechanism

2022-06-15 Thread Paolo Bonzini

On 6/15/22 19:33, Akihiko Odaki wrote:

Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files located relative
to the installation tree. The build tree must have a new directory,
qemu-bundle, to represent what files the installation tree would
have for reference by the executables.

v7: Properly fix --firmwarepath (Daniel P. Berrangé)


Please give people a little time to review.  I left more comments on v6.

Paolo



Re: [PATCH v6 0/7] cutils: Introduce bundle mechanism

2022-06-15 Thread Paolo Bonzini

On 6/15/22 17:56, Akihiko Odaki wrote:

Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files located relative
to the installation tree. The build tree must have a new directory,
qemu-bundle, to represent what files the installation tree would
have for reference by the executables.


Thanks for prototyping this, I think this is appealing.  I'll take a 
look later at using meson introspection info to build the preinstall layout.


Paolo



Re: [PATCH v6 4/7] cutils: Introduce bundle mechanism

2022-06-15 Thread Paolo Bonzini

On 6/15/22 17:56, Akihiko Odaki wrote:

+void list_bundle_candidates(const char *path)
+{
+const char *dir = qemu_get_exec_dir();
+int i;
+
+for (i = 0; i < ARRAY_SIZE(bundle_formats); i++) {
+printf(bundle_formats[i], dir, path);
+putc('\n', stdout);
+}


This is not bisectable, bundle_formats[] doesn't exist here.

Paolo



Re: [PATCH v6 3/7] Remove prefixes from path configuration macros

2022-06-15 Thread Paolo Bonzini

On 6/15/22 17:56, Akihiko Odaki wrote:

The path configuration macros are often supplied to
get_relocated_path(), and the function had some logics to remove the
prefixes.

With this change, the prefixes are removed from those macros and
get_relocated_path() is also simplified.

Signed-off-by: Akihiko Odaki 


This doesn't work if somebody configures with --prefix=/usr 
--libexecdir=/usr/libexec.  Adding the prefixes in meson.build was done 
as a canonicalization step so that the C code has less cases to care about.


Paolo


---
  include/qemu/cutils.h |  2 +-
  meson.build   | 21 ++---
  qemu-options.hx   | 11 +--
  util/cutils.c | 34 +++---
  4 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 40e10e19a7e..57de1da5c95 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -207,7 +207,7 @@ const char *qemu_get_exec_dir(void);
   *
   * Returns a path for @dir that uses the directory of the running executable
   * as the prefix.  For example, if `bindir` is `/usr/bin` and @dir is
- * `/usr/share/qemu`, the function will append `../share/qemu` to the
+ * `share/qemu`, the function will append `../share/qemu` to the
   * directory that contains the running executable and return the result.
   * The returned string should be freed by the caller.
   */
diff --git a/meson.build b/meson.build
index 0c2e11ff071..01d5e32615e 100644
--- a/meson.build
+++ b/meson.build
@@ -1679,18 +1679,17 @@ config_host_data.set_quoted('CONFIG_TLS_PRIORITY', 
get_option('tls_priority'))
  if iasl.found()
config_host_data.set_quoted('CONFIG_IASL', iasl.full_path())
  endif
-config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / 
get_option('bindir'))
+config_host_data.set_quoted('CONFIG_BINDIR', get_option('bindir'))
  config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix'))
-config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / 
qemu_confdir)
-config_host_data.set_quoted('CONFIG_QEMU_DATADIR', get_option('prefix') / 
qemu_datadir)
-config_host_data.set_quoted('CONFIG_QEMU_DESKTOPDIR', get_option('prefix') / 
qemu_desktopdir)
-config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', get_option('prefix') / 
get_option('qemu_firmwarepath'))
-config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('prefix') / 
get_option('libexecdir'))
-config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', get_option('prefix') / 
qemu_icondir)
-config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('prefix') / 
get_option('localedir'))
-config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', get_option('prefix') 
/ get_option('localstatedir'))
-config_host_data.set_quoted('CONFIG_QEMU_MODDIR', get_option('prefix') / 
qemu_moddir)
-config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('prefix') / 
get_option('sysconfdir'))
+config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', qemu_confdir)
+config_host_data.set_quoted('CONFIG_QEMU_DATADIR', qemu_datadir)
+config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', 
get_option('qemu_firmwarepath'))
+config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('libexecdir'))
+config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', qemu_icondir)
+config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('localedir'))
+config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', 
get_option('localstatedir'))
+config_host_data.set_quoted('CONFIG_QEMU_MODDIR', qemu_moddir)
+config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('sysconfdir'))
  
  if config_host.has_key('CONFIG_MODULES')

config_host_data.set('CONFIG_STAMP', run_command(
diff --git a/qemu-options.hx b/qemu-options.hx
index 377d22fbd82..f0ae8f44ff2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2661,12 +2661,11 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
  " [,poll-us=n]\n"
  "configure a host TAP network backend with ID 'str'\n"
  "connected to a bridge (default=" DEFAULT_BRIDGE_INTERFACE 
")\n"
-"use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT 
")\n"
-"to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT 
")\n"
-"to deconfigure it\n"
+"use custom network script 'file' to configure it 
(optional)\n"
+"use custom network script 'dfile' to deconfigure it 
(optional)\n"
  "use '[down]script=no' to disable script execution\n"
-"use network helper 'helper' (default=" DEFAULT_BRIDGE_HELPER 
") to\n"
-"configure it\n"
+"use custom network helper 'helper' to\n"
+"configure it (optional)\n"
  "use 'fd=h' to connect to an already opened TAP 
interface\n"
  "use 'fds=x:y:...:z' to connect to already opened 

Re: New "IndustryStandard" fw_cfg?

2022-06-15 Thread Dionna Amalie Glaze
> > > For Qemu, the main code I see for adding config is here, but I'm not sure
> > > what y'all's preferred external configuration method is to get a value 
> > > from an
>
> Ideally no external configuration, although I suspect we need something
> at least temporarily.

Yes, whereas TDX can assume unaccepted memory is supported as part of
its "TDX support" set of capabilities an OS has, SEV-SNP has already
been released and is supported. We therefore need to not break
existing images that "support SEV-SNP".

>
> IMHO the long-term goal should be to make this fully automatic, by
> having efi apps (which includes the linux kernel's efi stub) and
> firmware negotiate this.  Problem is this most likely requires changing
> the uefi specs, which will take a while.
>
> One possible way I see is extending efi boot services with a
> GetMemoryMapEx() call, with an additional flags parameter where the
> caller can specify that it can handle unaccepted memory with a flag
> bit.  When the guest does not set the flag (or uses the old GetMemoryMap
> call) the firmware must accept all memory and return a memory map
> without unaccepted memory.

To allow for future weird memory extensions, I'd recommend this being
a struct with initial size field, but yes.
Sounds like a new UEFI spec would be needed for this negotiation.

>
> > > 2. A "well-known" file path to be included in the file slots starting at 
> > > 0x0020,
> > > such as "etc/min_accepted_mem_size", still plumbed through like in 1.
>
> New options should use a file path.
>
> See also docs/specs/fw_cfg.txt in qemu source tree.
>

Thanks for this.

> take care,
>   Gerd
>


-- 
-Dionna Glaze, PhD (she/her)



Re: [PATCH v6 5/7] datadir: Use bundle mechanism

2022-06-15 Thread Paolo Bonzini

On 6/15/22 17:56, Akihiko Odaki wrote:

diff --git a/tests/vm/fedora b/tests/vm/fedora
index 92b78d6e2c9..4ccd31bba61 100755
--- a/tests/vm/fedora
+++ b/tests/vm/fedora
@@ -79,7 +79,7 @@ class FedoraVM(basevm.BaseVM):
  self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
  self.print_step("Booting installer")
  self.boot(img_tmp, extra_args = [
-"-bios", "pc-bios/bios-256k.bin",
+"-bios", "qemu-bundle/share/qemu/bios-256k.bin",
  "-machine", "graphics=off",
  "-device", "VGA",
  "-cdrom", iso
diff --git a/tests/vm/freebsd b/tests/vm/freebsd
index 805db759d67..2095d8c5204 100755
--- a/tests/vm/freebsd
+++ b/tests/vm/freebsd
@@ -95,7 +95,7 @@ class FreeBSDVM(basevm.BaseVM):
  
  self.print_step("Booting installer")

  self.boot(img_tmp, extra_args = [
-"-bios", "pc-bios/bios-256k.bin",
+"-bios", "qemu-bundle/share/qemu/bios-256k.bin",
  "-machine", "graphics=off",
  "-device", "VGA",
  "-cdrom", iso


I think -bios can be removed completely here.

Paolo



Re: [PATCH 0/4] Multiple interface support on top of Multi-FD

2022-06-15 Thread Dr. David Alan Gilbert
* Daniel P. Berrangé (berra...@redhat.com) wrote:
> On Fri, Jun 10, 2022 at 05:58:31PM +0530, manish.mishra wrote:
> > 
> > On 09/06/22 9:17 pm, Daniel P. Berrangé wrote:
> > > On Thu, Jun 09, 2022 at 07:33:01AM +, Het Gala wrote:
> > > > As of now, the multi-FD feature supports connection over the default 
> > > > network
> > > > only. This Patchset series is a Qemu side implementation of providing 
> > > > multiple
> > > > interfaces support for multi-FD. This enables us to fully utilize 
> > > > dedicated or
> > > > multiple NICs in case bonding of NICs is not possible.
> > > > 
> > > > 
> > > > Introduction
> > > > -
> > > > Multi-FD Qemu implementation currently supports connection only on the 
> > > > default
> > > > network. This forbids us from advantages like:
> > > > - Separating VM live migration traffic from the default network.
> > 
> > Hi Daniel,
> > 
> > I totally understand your concern around this approach increasing compexity 
> > inside qemu,
> > 
> > when similar things can be done with NIC teaming. But we thought this 
> > approach provides
> > 
> > much more flexibility to user in few cases like.
> > 
> > 1. We checked our customer data, almost all of the host had multiple NIC, 
> > but LACP support
> > 
> >     in their setups was very rare. So for those cases this approach can 
> > help in utilise multiple
> > 
> >     NICs as teaming is not possible there.
> 
> AFAIK,  LACP is not required in order to do link aggregation with Linux.
> Traditional Linux bonding has no special NIC hardware or switch requirements,
> so LACP is merely a "nice to have" in order to simplify some aspects.
> 
> IOW, migration with traffic spread across multiple NICs is already
> possible AFAICT.

Are we sure that works with multifd?  I've seen a lot of bonding NIC
setups which spread based on a hash of source/destination IP and port
numbers; given that we use the same dest port and IP at the moment what
happens in reality?  That hashing can be quite delicate for high
bandwidth single streams.

> I can understand that some people may not have actually configured
> bonding on their hosts, but it is not unreasonable to request that
> they do so, if they want to take advantage fo aggrated bandwidth.
> 
> It has the further benefit that it will be fault tolerant. With
> this proposal if any single NIC has a problem, the whole migration
> will get stuck. With kernel level bonding, if any single NIC haus
> a problem, it'll get offlined by the kernel and migration will
> continue to  work across remaining active NICs.
> 
> > 2. We have seen requests recently to separate out traffic of storage, VM 
> > netwrok, migration
> > 
> >     over different vswitch which can be backed by 1 or more NICs as this 
> > give better
> > 
> >     predictability and assurance. So host with multiple ips/vswitches can 
> > be very common
> > 
> >     environment. In this kind of enviroment this approach gives per vm or 
> > migration level
> > 
> >     flexibilty, like for critical VM we can still use bandwidth from all 
> > available vswitch/interface
> > 
> >     but for normal VM they can keep live migration only on dedicated NICs 
> > without changing
> > 
> >     complete host network topology.
> > 
> >     At final we want it to be something like this [, 
> > , ]
> > 
> >     to provide bandwidth_control per interface.
> 
> Again, it is already possible to separate migration traffic from storage
> traffic, from other network traffic. The target IP given will influence
> which NIC is used based on routing table and I know this is already
> done widely with OpenStack deployments.
> 
> > 3. Dedicated NIC we mentioned as a use case, agree with you it can be done 
> > without this
> > 
> >     approach too.
> 
> 
> > > > Multi-interface with Multi-FD
> > > > -
> > > > Multiple-interface support over basic multi-FD has been implemented in 
> > > > the
> > > > patches. Advantages of this implementation are:
> > > > - Able to separate live migration traffic from default network 
> > > > interface by
> > > >creating multiFD channels on ip addresses of multiple non-default 
> > > > interfaces.
> > > > - Can optimize the number of multi-FD channels on a particular interface
> > > >depending upon the network bandwidth limit on a particular interface.
> > > Manually assigning individual channels to different NICs is a pretty
> > > inefficient way to optimizing traffic. Feels like you could easily get
> > > into a situation where one NIC ends up idle while the other is busy,
> > > especially if the traffic patterns are different. For example with
> > > post-copy there's an extra channel for OOB async page requests, and
> > > its far from clear that manually picking NICs per chanel upfront is
> > > going work for that.  The kernel can continually dynamically balance
> > > load on the fly and so do much better than any static mapping QEMU
> > > tries to apply, especially if there are 

Re: [PATCH v5 2/3] target/riscv: Add stimecmp support

2022-06-15 Thread Atish Kumar Patra
On Wed, Jun 8, 2022 at 12:19 AM Alistair Francis  wrote:
>
> On Mon, Jun 6, 2022 at 2:23 AM Atish Patra  wrote:
> >
> > On Thu, Jun 2, 2022 at 12:02 AM Alistair Francis  
> > wrote:
> > >
> > > On Wed, Jun 1, 2022 at 4:16 AM Atish Patra  wrote:
> > > >
> > > > stimecmp allows the supervisor mode to update stimecmp CSR directly
> > > > to program the next timer interrupt. This CSR is part of the Sstc
> > > > extension which was ratified recently.
> > > >
> > > > Signed-off-by: Atish Patra 
> > > > ---
> > > >  target/riscv/cpu.c |  8 
> > > >  target/riscv/cpu.h |  5 ++
> > > >  target/riscv/cpu_bits.h|  4 ++
> > > >  target/riscv/csr.c | 81 +++
> > > >  target/riscv/machine.c |  1 +
> > > >  target/riscv/meson.build   |  3 +-
> > > >  target/riscv/time_helper.c | 98 ++
> > > >  target/riscv/time_helper.h | 30 
> > > >  8 files changed, 229 insertions(+), 1 deletion(-)
> > > >  create mode 100644 target/riscv/time_helper.c
> > > >  create mode 100644 target/riscv/time_helper.h
> > > >
> > > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > > > index 19f4e8294042..d58dd2f857a7 100644
> > > > --- a/target/riscv/cpu.c
> > > > +++ b/target/riscv/cpu.c
> > > > @@ -23,6 +23,7 @@
> > > >  #include "qemu/log.h"
> > > >  #include "cpu.h"
> > > >  #include "internals.h"
> > > > +#include "time_helper.h"
> > > >  #include "exec/exec-all.h"
> > > >  #include "qapi/error.h"
> > > >  #include "qemu/error-report.h"
> > > > @@ -779,7 +780,12 @@ static void riscv_cpu_init(Object *obj)
> > > >  #ifndef CONFIG_USER_ONLY
> > > >  qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq,
> > > >IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
> > > > +
> > > > +if (cpu->cfg.ext_sstc) {
> > > > +riscv_timer_init(cpu);
> > > > +}
> > > >  #endif /* CONFIG_USER_ONLY */
> > > > +
> > > >  }
> > > >
> > > >  static Property riscv_cpu_properties[] = {
> > > > @@ -806,6 +812,7 @@ static Property riscv_cpu_properties[] = {
> > > >  DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
> > > >  DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
> > > >  DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
> > > > +DEFINE_PROP_BOOL("sstc", RISCVCPU, cfg.ext_sstc, true),
> > >
> > > Do we want this enabled by default?
> > >
> >
> > sstc extension will result in performance improvements as it avoids
> > the SBI calls & interrupt forwarding
> > path. That's why I think it should be enabled by default.
> >
> > > >
> > > >  DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
> > > >  DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
> > > > @@ -965,6 +972,7 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, 
> > > > char **isa_str, int max_str_len)
> > > >  ISA_EDATA_ENTRY(zbs, ext_zbs),
> > > >  ISA_EDATA_ENTRY(zve32f, ext_zve32f),
> > > >  ISA_EDATA_ENTRY(zve64f, ext_zve64f),
> > > > +ISA_EDATA_ENTRY(sstc, ext_sstc),
> > > >  ISA_EDATA_ENTRY(svinval, ext_svinval),
> > > >  ISA_EDATA_ENTRY(svnapot, ext_svnapot),
> > > >  ISA_EDATA_ENTRY(svpbmt, ext_svpbmt),
> > > > diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> > > > index 1119d5201066..9a5e02f217ba 100644
> > > > --- a/target/riscv/cpu.h
> > > > +++ b/target/riscv/cpu.h
> > > > @@ -276,6 +276,9 @@ struct CPUArchState {
> > > >  uint64_t mfromhost;
> > > >  uint64_t mtohost;
> > > >
> > > > +/* Sstc CSRs */
> > > > +uint64_t stimecmp;
> > > > +
> > > >  /* physical memory protection */
> > > >  pmp_table_t pmp_state;
> > > >  target_ulong mseccfg;
> > > > @@ -329,6 +332,7 @@ struct CPUArchState {
> > > >  float_status fp_status;
> > > >
> > > >  /* Fields from here on are preserved across CPU reset. */
> > > > +QEMUTimer *stimer; /* Internal timer for S-mode interrupt */
> > > >
> > > >  hwaddr kernel_addr;
> > > >  hwaddr fdt_addr;
> > > > @@ -379,6 +383,7 @@ struct RISCVCPUConfig {
> > > >  bool ext_counters;
> > > >  bool ext_ifencei;
> > > >  bool ext_icsr;
> > > > +bool ext_sstc;
> > > >  bool ext_svinval;
> > > >  bool ext_svnapot;
> > > >  bool ext_svpbmt;
> > > > diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
> > > > index 4e5b630f5965..29d0e4a1be01 100644
> > > > --- a/target/riscv/cpu_bits.h
> > > > +++ b/target/riscv/cpu_bits.h
> > > > @@ -215,6 +215,10 @@
> > > >  #define CSR_STVAL   0x143
> > > >  #define CSR_SIP 0x144
> > > >
> > > > +/* Sstc supervisor CSRs */
> > > > +#define CSR_STIMECMP0x14D
> > > > +#define CSR_STIMECMPH   0x15D
> > > > +
> > > >  /* Supervisor Protection and Translation */
> > > >  #define CSR_SPTBR   0x180
> > > >  #define CSR_SATP0x180
> > > > diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> > > > index 245f007e66e1..48d07911ae14 100644
> > > > --- 

[PATCH v7 6/6] net: Use bundle mechanism

2022-06-15 Thread Akihiko Odaki
Signed-off-by: Akihiko Odaki 
---
 meson.build | 2 ++
 net/tap.c   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 8961df266d1..5e0e08801c9 100644
--- a/meson.build
+++ b/meson.build
@@ -3574,6 +3574,8 @@ if have_tools
dependencies: [authz, crypto, io, qom, qemuutil,
   libcap_ng, mpathpersist],
install: true)
+
+bundles += { get_option('libexecdir') / 'qemu-bridge-helper': 
'../../qemu-bridge-helper' }
   endif
 
   if have_ivshmem
diff --git a/net/tap.c b/net/tap.c
index b3ddfd4a74b..5beba85fb22 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -507,7 +507,7 @@ static int net_bridge_run_helper(const char *helper, const 
char *bridge,
 sigprocmask(SIG_BLOCK, , );
 
 if (!helper) {
-helper = default_helper = get_relocated_path(DEFAULT_BRIDGE_HELPER);
+helper = default_helper = find_bundle(DEFAULT_BRIDGE_HELPER);
 }
 
 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
-- 
2.32.1 (Apple Git-133)




[PATCH v7 1/6] qga: Relocate a path emitted in the help text

2022-06-15 Thread Akihiko Odaki
Signed-off-by: Akihiko Odaki 
---
 qga/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/main.c b/qga/main.c
index c373fec3ee6..06e507b9979 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -270,7 +270,7 @@ QEMU_HELP_BOTTOM "\n"
 , cmd, QGA_VIRTIO_PATH_DEFAULT, QGA_SERIAL_PATH_DEFAULT,
 dfl_pathnames.pidfile,
 #ifdef CONFIG_FSFREEZE
-QGA_FSFREEZE_HOOK_DEFAULT,
+get_relocated_path(QGA_FSFREEZE_HOOK_DEFAULT),
 #endif
 dfl_pathnames.state_dir);
 }
-- 
2.32.1 (Apple Git-133)




[PATCH v7 5/6] ui/icons: Use bundle mechanism

2022-06-15 Thread Akihiko Odaki
Signed-off-by: Akihiko Odaki 
---
 ui/cocoa.m   |  2 +-
 ui/gtk.c |  2 +-
 ui/icons/meson.build | 32 
 ui/sdl2.c|  4 ++--
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 84c84e98fc5..25584cc78ce 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1562,7 +1562,7 @@ - (BOOL)verifyQuit
 - (IBAction) do_about_menu_item: (id) sender
 {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-char *icon_path_c = get_relocated_path(CONFIG_QEMU_ICONDIR 
"/hicolor/512x512/apps/qemu.png");
+char *icon_path_c = find_bundle(CONFIG_QEMU_ICONDIR 
"/hicolor/512x512/apps/qemu.png");
 NSString *icon_path = [NSString stringWithUTF8String:icon_path_c];
 g_free(icon_path_c);
 NSImage *icon = [[NSImage alloc] initWithContentsOfFile:icon_path];
diff --git a/ui/gtk.c b/ui/gtk.c
index 2a791dd2aa0..27d5a3407cf 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2321,7 +2321,7 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
 s->opts = opts;
 
 theme = gtk_icon_theme_get_default();
-dir = get_relocated_path(CONFIG_QEMU_ICONDIR);
+dir = find_bundle(CONFIG_QEMU_ICONDIR);
 gtk_icon_theme_prepend_search_path(theme, dir);
 g_free(dir);
 g_set_prgname("qemu");
diff --git a/ui/icons/meson.build b/ui/icons/meson.build
index 12c52080ebd..1d99aff10ed 100644
--- a/ui/icons/meson.build
+++ b/ui/icons/meson.build
@@ -1,13 +1,29 @@
+icons = [
+  {
+'source': 'qemu_32x32.bmp',
+'install': 'hicolor' / '32x32' / 'apps' / 'qemu.bmp',
+  },
+  {
+'source': 'qemu.svg',
+'install': 'hicolor' / 'scalable' / 'apps' / 'qemu.svg',
+  },
+]
+
 foreach s: [16, 24, 32, 48, 64, 128, 256, 512]
   s = '@0@x@0@'.format(s.to_string())
-  install_data('qemu_@0@.png'.format(s),
-   rename: 'qemu.png',
-   install_dir: qemu_icondir / 'hicolor' / s / 'apps')
+  icons += {
+'source': 'qemu_@0@.png'.format(s),
+'install': 'hicolor' / s / 'apps' / 'qemu.png',
+  }
 endforeach
 
-install_data('qemu_32x32.bmp',
- rename: 'qemu.bmp',
- install_dir: qemu_icondir / 'hicolor' / '32x32' / 'apps')
+foreach icon: icons
+  source = icon.get('source')
+  install = icon.get('install')
+
+  install_data(source,
+   rename: fs.name(install),
+   install_dir: qemu_icondir / fs.parent(install))
 
-install_data('qemu.svg',
- install_dir: qemu_icondir / 'hicolor' / 'scalable' / 'apps')
+  bundles += { qemu_bundledir / qemu_icondir / install: 
meson.current_source_dir() / source }
+endforeach
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 8cb77416af2..916815cc8a2 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -910,11 +910,11 @@ static void sdl2_display_init(DisplayState *ds, 
DisplayOptions *o)
 }
 
 #ifdef CONFIG_SDL_IMAGE
-dir = get_relocated_path(CONFIG_QEMU_ICONDIR 
"/hicolor/128x128/apps/qemu.png");
+dir = find_bundle(CONFIG_QEMU_ICONDIR "/hicolor/128x128/apps/qemu.png");
 icon = IMG_Load(dir);
 #else
 /* Load a 32x32x4 image. White pixels are transparent. */
-dir = get_relocated_path(CONFIG_QEMU_ICONDIR 
"/hicolor/32x32/apps/qemu.bmp");
+dir = find_bundle(CONFIG_QEMU_ICONDIR "/hicolor/32x32/apps/qemu.bmp");
 icon = SDL_LoadBMP(dir);
 if (icon) {
 uint32_t colorkey = SDL_MapRGB(icon->format, 255, 255, 255);
-- 
2.32.1 (Apple Git-133)




[PATCH v7 3/6] cutils: Introduce bundle mechanism

2022-06-15 Thread Akihiko Odaki
Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files located relative
to the installation tree. The build tree must have a new directory,
qemu-bundle, to represent what files the installation tree would
have for reference by the executables.

Signed-off-by: Akihiko Odaki 
---
 include/qemu/cutils.h | 19 +++
 meson.build   | 12 
 util/cutils.c | 23 +++
 3 files changed, 54 insertions(+)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 57de1da5c95..ca5bddb9e1c 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -213,6 +213,25 @@ const char *qemu_get_exec_dir(void);
  */
 char *get_relocated_path(const char *dir);
 
+/**
+ * find_bundle:
+ * @path: Relative path
+ *
+ * Returns a path for the specified directory or file bundled in QEMU. It uses
+ * the directory of the running executable as the prefix first. See
+ * get_relocated_path() for the details. The next candidate is "qemu-bundle"
+ * directory in the directory of the running executable. "qemu-bundle"
+ * directory is typically present in the build tree.
+ *
+ * The returned string should be freed by the caller.
+ *
+ * Returns: a path that can access the bundle, or NULL if no matching bundle
+ * exists.
+ */
+char *find_bundle(const char *path);
+
+void list_bundle_candidates(const char *path);
+
 static inline const char *yes_no(bool b)
 {
  return b ? "yes" : "no";
diff --git a/meson.build b/meson.build
index b982bfd5d07..8961df266d1 100644
--- a/meson.build
+++ b/meson.build
@@ -32,6 +32,7 @@ if get_option('qemu_suffix').startswith('/')
   error('qemu_suffix cannot start with a /')
 endif
 
+qemu_bundledir = meson.project_build_root() / 'qemu-bundle'
 qemu_confdir = get_option('sysconfdir') / get_option('qemu_suffix')
 qemu_datadir = get_option('datadir') / get_option('qemu_suffix')
 qemu_docdir = get_option('docdir') / get_option('qemu_suffix')
@@ -2843,6 +2844,8 @@ target_arch = {}
 target_softmmu_arch = {}
 target_user_arch = {}
 
+bundles = {}
+
 ###
 # Trace files #
 ###
@@ -3613,6 +3616,15 @@ if host_machine.system() == 'windows'
   alias_target('installer', nsis)
 endif
 
+###
+# Bundles #
+###
+
+foreach dst, src: bundles
+  run_command('mkdir', '-p', qemu_bundledir / fs.parent(dst), check: true)
+  run_command('ln', '-sf', src, qemu_bundledir / dst, check: true)
+endforeach
+
 #
 # Configuration summary #
 #
diff --git a/util/cutils.c b/util/cutils.c
index 983db97b4df..64cb1616b9c 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1066,3 +1066,26 @@ char *get_relocated_path(const char *dir)
 
 return g_string_free(result, false);
 }
+
+char *find_bundle(const char *path)
+{
+char *bundle = g_strdup_printf("%s/qemu-bundle/%s", qemu_get_exec_dir(), 
path);
+if (access(bundle, R_OK) == 0) {
+return bundle;
+}
+
+g_free(bundle);
+
+return get_relocated_path(path);
+}
+
+void list_bundle_candidates(const char *path)
+{
+const char *dir = qemu_get_exec_dir();
+int i;
+
+for (i = 0; i < ARRAY_SIZE(bundle_formats); i++) {
+printf(bundle_formats[i], dir, path);
+putc('\n', stdout);
+}
+}
-- 
2.32.1 (Apple Git-133)




[PATCH v7 4/6] datadir: Use bundle mechanism

2022-06-15 Thread Akihiko Odaki
softmmu/datadir.c had its own implementation to find files in the
build tree, but now bundle mechanism provides the unified
implementation which works for datadir and the other files.

Signed-off-by: Akihiko Odaki 
---
 .travis.yml |  2 +-
 pc-bios/keymaps/meson.build |  2 ++
 pc-bios/meson.build | 19 +--
 scripts/oss-fuzz/build.sh   |  2 +-
 softmmu/datadir.c   | 32 
 tests/qtest/fuzz/fuzz.c | 15 ---
 tests/vm/fedora |  2 +-
 tests/vm/freebsd|  2 +-
 tests/vm/netbsd |  2 +-
 tests/vm/openbsd|  2 +-
 util/cutils.c   | 10 +++---
 11 files changed, 28 insertions(+), 62 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9afc4a54b8f..9fee2167b95 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ jobs:
 - BUILD_RC=0 && make -j${JOBS} || BUILD_RC=$?
 - |
   if [ "$BUILD_RC" -eq 0 ] ; then
-  mv pc-bios/s390-ccw/*.img pc-bios/ ;
+  mv pc-bios/s390-ccw/*.img qemu-bundle/share/qemu ;
   ${TEST_CMD} ;
   else
   $(exit $BUILD_RC);
diff --git a/pc-bios/keymaps/meson.build b/pc-bios/keymaps/meson.build
index 44247a12b54..dd103092290 100644
--- a/pc-bios/keymaps/meson.build
+++ b/pc-bios/keymaps/meson.build
@@ -67,3 +67,5 @@ if native_qemu_keymap.found()
 endif
 
 install_data(['sl', 'sv'], install_dir: qemu_datadir / 'keymaps')
+
+bundles += { qemu_datadir / 'keymaps': '../../../pc-bios/keymaps' }
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index 41ba1c0ec7b..0d2119836bd 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -20,6 +20,8 @@ if unpack_edk2_blobs
   install: get_option('install_blobs'),
   install_dir: qemu_datadir,
   command: [ bzip2, '-dc', '@INPUT0@' ])
+
+bundles += { qemu_datadir / f: '../../../pc-bios' / f  }
   endforeach
 endif
 
@@ -85,16 +87,13 @@ blobs = [
   'vof-nvram.bin',
 ]
 
-ln_s = [find_program('ln', required: true), '-sf']
-foreach f : blobs
-  roms += custom_target(f,
-build_by_default: have_system,
-output: f,
-input: files('meson.build'),# dummy input
-install: get_option('install_blobs'),
-install_dir: qemu_datadir,
-command: [ ln_s, meson.project_source_root() / 'pc-bios' / f, 
'@OUTPUT@' ])
-endforeach
+if get_option('install_blobs')
+  install_data(blobs, install_dir: qemu_datadir)
+
+  foreach f : blobs
+bundles += { qemu_datadir / f: meson.current_source_dir() / f }
+  endforeach
+endif
 
 subdir('descriptors')
 subdir('keymaps')
diff --git a/scripts/oss-fuzz/build.sh b/scripts/oss-fuzz/build.sh
index 98b56e05210..cbf8b3080e9 100755
--- a/scripts/oss-fuzz/build.sh
+++ b/scripts/oss-fuzz/build.sh
@@ -88,7 +88,7 @@ if [ "$GITLAB_CI" != "true" ]; then
 fi
 
 # Copy over the datadir
-cp  -r ../pc-bios/ "$DEST_DIR/pc-bios"
+cp  -r ../pc-bios/ "$DEST_DIR/qemu-bundle/share/qemu"
 
 targets=$(./qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}')
 base_copy="$DEST_DIR/qemu-fuzz-i386-target-$(echo "$targets" | head -n 1)"
diff --git a/softmmu/datadir.c b/softmmu/datadir.c
index 3da42cb8ed7..b52c8dacd64 100644
--- a/softmmu/datadir.c
+++ b/softmmu/datadir.c
@@ -35,6 +35,7 @@ char *qemu_find_file(int type, const char *name)
 int i;
 const char *subdir;
 char *buf;
+char *bundle;
 
 /* Try the name as a straight path first */
 if (access(name, R_OK) == 0) {
@@ -61,7 +62,12 @@ char *qemu_find_file(int type, const char *name)
 }
 g_free(buf);
 }
-return NULL;
+
+bundle = g_strdup_printf("%s/%s%s", CONFIG_QEMU_DATADIR, subdir, name);
+buf = find_bundle(bundle);
+g_free(bundle);
+trace_load_file(name, buf);
+return buf;
 }
 
 void qemu_add_data_dir(char *path)
@@ -83,26 +89,6 @@ void qemu_add_data_dir(char *path)
 data_dir[data_dir_idx++] = path;
 }
 
-/*
- * Find a likely location for support files using the location of the binary.
- * When running from the build tree this will be "$bindir/pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated).
- *
- * The caller must use g_free() to free the returned data when it is
- * no longer required.
- */
-static char *find_datadir(void)
-{
-g_autofree char *dir = NULL;
-
-dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL);
-if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
-return g_steal_pointer();
-}
-
-return get_relocated_path(CONFIG_QEMU_DATADIR);
-}
-
 void qemu_add_default_firmwarepath(void)
 {
 char **dirs;
@@ -119,9 +105,6 @@ void qemu_add_default_firmwarepath(void)
 }
 }
 g_free(dirs);
-
-/* try to find datadir relative to the executable path */
-qemu_add_data_dir(find_datadir());
 }
 
 void qemu_list_data_dirs(void)
@@ -130,4 +113,5 @@ void 

[PATCH v7 2/6] Remove prefixes from path configuration macros

2022-06-15 Thread Akihiko Odaki
The path configuration macros are often supplied to
get_relocated_path(), and the function had some logics to remove the
prefixes.

With this change, the prefixes are removed from those macros and
get_relocated_path() is also simplified.

This also fixes --firmwarepath configuration option. The old
implementation naively added the prefix to the given option although
it is a list of paths. Now an absolute path in --firmwarepath will
be used as-is. A relative path in --firmwarepath will be relocated
with get_relocated_path().

Signed-off-by: Akihiko Odaki 
---
 include/qemu/cutils.h |  2 +-
 meson.build   | 23 +++
 qemu-options.hx   | 11 +--
 softmmu/datadir.c |  9 +++--
 util/cutils.c | 34 +++---
 5 files changed, 31 insertions(+), 48 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 40e10e19a7e..57de1da5c95 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -207,7 +207,7 @@ const char *qemu_get_exec_dir(void);
  *
  * Returns a path for @dir that uses the directory of the running executable
  * as the prefix.  For example, if `bindir` is `/usr/bin` and @dir is
- * `/usr/share/qemu`, the function will append `../share/qemu` to the
+ * `share/qemu`, the function will append `../share/qemu` to the
  * directory that contains the running executable and return the result.
  * The returned string should be freed by the caller.
  */
diff --git a/meson.build b/meson.build
index 0c2e11ff071..b982bfd5d07 100644
--- a/meson.build
+++ b/meson.build
@@ -1679,18 +1679,17 @@ config_host_data.set_quoted('CONFIG_TLS_PRIORITY', 
get_option('tls_priority'))
 if iasl.found()
   config_host_data.set_quoted('CONFIG_IASL', iasl.full_path())
 endif
-config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / 
get_option('bindir'))
+config_host_data.set_quoted('CONFIG_BINDIR', get_option('bindir'))
 config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix'))
-config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / 
qemu_confdir)
-config_host_data.set_quoted('CONFIG_QEMU_DATADIR', get_option('prefix') / 
qemu_datadir)
-config_host_data.set_quoted('CONFIG_QEMU_DESKTOPDIR', get_option('prefix') / 
qemu_desktopdir)
-config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', get_option('prefix') / 
get_option('qemu_firmwarepath'))
-config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('prefix') / 
get_option('libexecdir'))
-config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', get_option('prefix') / 
qemu_icondir)
-config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('prefix') / 
get_option('localedir'))
-config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', get_option('prefix') 
/ get_option('localstatedir'))
-config_host_data.set_quoted('CONFIG_QEMU_MODDIR', get_option('prefix') / 
qemu_moddir)
-config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('prefix') / 
get_option('sysconfdir'))
+config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', qemu_confdir)
+config_host_data.set_quoted('CONFIG_QEMU_DATADIR', qemu_datadir)
+config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', 
get_option('qemu_firmwarepath'))
+config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('libexecdir'))
+config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', qemu_icondir)
+config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('localedir'))
+config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', 
get_option('localstatedir'))
+config_host_data.set_quoted('CONFIG_QEMU_MODDIR', qemu_moddir)
+config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('sysconfdir'))
 
 if config_host.has_key('CONFIG_MODULES')
   config_host_data.set('CONFIG_STAMP', run_command(
@@ -3622,7 +3621,7 @@ endif
 summary_info = {}
 summary_info += {'Install prefix':get_option('prefix')}
 summary_info += {'BIOS directory':qemu_datadir}
-summary_info += {'firmware path': get_option('prefix') / 
get_option('qemu_firmwarepath')}
+summary_info += {'firmware path': get_option('qemu_firmwarepath')}
 summary_info += {'binary directory':  get_option('prefix') / 
get_option('bindir')}
 summary_info += {'library directory': get_option('prefix') / 
get_option('libdir')}
 summary_info += {'module directory':  qemu_moddir}
diff --git a/qemu-options.hx b/qemu-options.hx
index 377d22fbd82..f0ae8f44ff2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2661,12 +2661,11 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
 " [,poll-us=n]\n"
 "configure a host TAP network backend with ID 'str'\n"
 "connected to a bridge (default=" DEFAULT_BRIDGE_INTERFACE 
")\n"
-"use network scripts 'file' (default=" 
DEFAULT_NETWORK_SCRIPT ")\n"
-"to configure it and 'dfile' (default=" 
DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
-"to deconfigure it\n"
+"use custom network script 'file' to 

[PATCH v7 0/6] cutils: Introduce bundle mechanism

2022-06-15 Thread Akihiko Odaki
Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files located relative
to the installation tree. The build tree must have a new directory,
qemu-bundle, to represent what files the installation tree would
have for reference by the executables.

v7: Properly fix --firmwarepath (Daniel P. Berrangé)

v6: Reuse get_relocated_path() in find_bundle() (Paolo Bonzini)

v5:
* Prefer qemu-bundle if it exists. (Daniel P. Berrangé)
* Check install_blobs option before installing BIOSes (Paolo Bonzini)
* Add common code to set up qemu-bundle to the top level meson.build
  (Paolo Bonzini)

v4:
* Add Daniel P. Berrangé to CC. Hopefully this helps merging his patch:
  https://mail.gnu.org/archive/html/qemu-devel/2022-06/msg02276.html
* Rebased to the latest QEMU.

v3:
* Note that the bundle mechanism is for any files located relative to the
  installation tree including but not limited to datadir. (Peter Maydell)
* Fix "bridge" typo (Philippe Mathieu-Daudé)

v2: Rebased to the latest QEMU.

Akihiko Odaki (6):
  qga: Relocate a path emitted in the help text
  Remove prefixes from path configuration macros
  cutils: Introduce bundle mechanism
  datadir: Use bundle mechanism
  ui/icons: Use bundle mechanism
  net: Use bundle mechanism

 .travis.yml |  2 +-
 include/qemu/cutils.h   | 21 ++-
 meson.build | 37 +-
 net/tap.c   |  2 +-
 pc-bios/keymaps/meson.build |  2 ++
 pc-bios/meson.build | 19 +++--
 qemu-options.hx | 11 
 qga/main.c  |  2 +-
 scripts/oss-fuzz/build.sh   |  2 +-
 softmmu/datadir.c   | 41 +++-
 tests/qtest/fuzz/fuzz.c | 15 ---
 tests/vm/fedora |  2 +-
 tests/vm/freebsd|  2 +-
 tests/vm/netbsd |  2 +-
 tests/vm/openbsd|  2 +-
 ui/cocoa.m  |  2 +-
 ui/gtk.c|  2 +-
 ui/icons/meson.build| 32 --
 ui/sdl2.c   |  4 +--
 util/cutils.c   | 53 ++---
 20 files changed, 138 insertions(+), 117 deletions(-)

-- 
2.32.1 (Apple Git-133)




RE: [PATCH] virtio/vhost-user: Fix wrong vhost notifier GPtrArray size

2022-06-15 Thread Dong, Eddie
Reviewed-by: Eddie Dong 

> -Original Message-
> From: Qemu-devel  bounces+eddie.dong=intel@nongnu.org> On Behalf Of Yajun Wu
> Sent: Wednesday, May 25, 2022 8:49 PM
> To: qemu-devel@nongnu.org; m...@redhat.com; alex.ben...@linaro.org;
> yaj...@nvidia.com
> Cc: Parav Pandit 
> Subject: [PATCH] virtio/vhost-user: Fix wrong vhost notifier GPtrArray size
> 
> In fetch_or_create_notifier, idx begins with 0. So the GPtrArray size should
> be idx + 1 and g_ptr_array_set_size should be called with idx + 1.
> 
> This wrong GPtrArray size causes fetch_or_create_notifier return an invalid
> address. Passing this invalid pointer to vhost_user_host_notifier_remove
> causes assert fail:
> 
> qemu/include/qemu/int128.h:27: int128_get64: Assertion `r == a' failed.
>   shutting down, reason=crashed
> 
> Backends like dpdk-vdpa which sends out vhost notifier requests almost
> always hit qemu crash.
> 
> Fixes: 503e355465 ("virtio/vhost-user: dynamically assign
> VhostUserHostNotifiers")
> Signed-off-by: Yajun Wu 
> Acked-by: Parav Pandit 
> Change-Id: I87e0f7591ca9a59d210879b260704a2d9e9d6bcd
> ---
>  hw/virtio/vhost-user.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index
> b040c1ad2b..dbc690d16c 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -1525,7 +1525,7 @@ static VhostUserHostNotifier
> *fetch_or_create_notifier(VhostUserState *u,  {
>  VhostUserHostNotifier *n = NULL;
>  if (idx >= u->notifiers->len) {
> -g_ptr_array_set_size(u->notifiers, idx);
> +g_ptr_array_set_size(u->notifiers, idx + 1);
>  }
> 
>  n = g_ptr_array_index(u->notifiers, idx);
> --
> 2.36.0
> 



[python-qemu-qmp MR #7] readme: small fixes commands

2022-06-15 Thread GitLab Bot
Author: Beraldo Leal - https://gitlab.com/beraldoleal
Merge Request: 
https://gitlab.com/qemu-project/python-qemu-qmp/-/merge_requests/7
... from: beraldoleal/python-qemu-qmp:docs/readme
... into: qemu-project/python-qemu-qmp:main

Just some small fixes that will make easier to copy and paste from the
Gitlab/Pypi web interface.

Signed-off-by: Beraldo Leal 

---

This is an automated message. This bot will only relay the creation of new merge
requests and will not relay review comments, new revisions, or concluded merges.
Please follow the GitLab link to participate in review.



Re: [PATCH v6 1/7] datadir: Simplify firmware directory search

2022-06-15 Thread Daniel P . Berrangé
On Thu, Jun 16, 2022 at 12:56:28AM +0900, Akihiko Odaki wrote:
> The old implementation had some code to accept multiple firmware
> directories, but it is not used.

It is used by distros. In Fedora builds for example:

https://kojipkgs.fedoraproject.org/packages/qemu/7.0.0/1.fc37/data/logs/x86_64/build.log

Passes this to configure:

   
--firmwarepath=/usr/share/qemu-firmware:/usr/share/ipxe/qemu:/usr/share/seavgabios:/usr/share/seabios:/usr/share/sgabios
 
> Signed-off-by: Akihiko Odaki 
> ---
>  softmmu/datadir.c | 11 ++-
>  1 file changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/softmmu/datadir.c b/softmmu/datadir.c
> index 160cac999a6..2a206f2740a 100644
> --- a/softmmu/datadir.c
> +++ b/softmmu/datadir.c
> @@ -105,15 +105,8 @@ static char *find_datadir(void)
>  
>  void qemu_add_default_firmwarepath(void)
>  {
> -char **dirs;
> -size_t i;
> -
> -/* add configured firmware directories */
> -dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0);
> -for (i = 0; dirs[i] != NULL; i++) {
> -qemu_add_data_dir(get_relocated_path(dirs[i]));
> -}
> -g_strfreev(dirs);
> +/* add the configured firmware directory */
> +qemu_add_data_dir(get_relocated_path(CONFIG_QEMU_FIRMWAREPATH));
>  
>  /* try to find datadir relative to the executable path */
>  qemu_add_data_dir(find_datadir());
> -- 
> 2.32.1 (Apple Git-133)
> 

With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




Re: [PATCH v3 4/4] net: convert to use qemu_find_file to locate bridge helper

2022-06-15 Thread Akihiko Odaki

On 2022/06/15 21:04, Daniel P. Berrangé wrote:

On Wed, Jun 15, 2022 at 01:42:58PM +0200, Paolo Bonzini wrote:

On 6/15/22 12:52, Daniel P. Berrangé wrote:

+case QEMU_FILE_TYPE_HELPER:
+rel_install_dir = "";
+rel_build_dir = "";
+default_install_dir = default_helper_dir;
+break;
+


You're replacing ad hoc rules in Akihiko's meson.build with an ad hoc enum +
the corresponding "case"s here in qemu_find_file().  There is duplication
anyway, in this case between Meson and QEMU (plus QEMU needs to know about
two filesystem layouts).


IMHO this is simpler to deal with than the meson additions, and also
avoids the confusion of having files appearing in two places in the
build dir.


Thanks to Paolo's suggestion to unify the common code to build the 
bundle tree, the required code for each bundled file is just a statement 
now (something like: bundles += { destination: source }) in the v6. 
Doing everything in Meson also allows to reuse the knowledge of the 
build tree Meson already has. I do no longer think my patch series are 
complicated more than yours. It even has less lines now.


There is still a room for improvements though. Particularly, the 
installing code and bundle-tree code are still duplicate. For example, 
pc-bios/meson.build now has the following code:

install_data(blobs, install_dir: qemu_datadir)

foreach f : blobs
  bundles += { qemu_datadir / f: meson.current_source_dir() / f }
endforeach

It would be nice if it can be written like:
foreach f : blobs
  bundle_data(qemu_datadir / f, f)
endforeach

Unfortunately Meson does not allow this.

Another problem is that the top-level meson.build is somewhat clutter. 
In my opinion, it is a persistent problem of the build system but I 
don't have a solution.


Anyway, I think my patch series is as close to the ideal as Meson 
currently allows.


The confusion caused by the files appearing in two places in the
build tree should be minimal. qemu-bundle is implemented entirely with 
symbolic links. If you know what is a symbolic link, you also know it is 
an alias and the files appear in different places, and I expect everyone 
hacking QEMU knows symbolic link.




If we really want to have the build dir look just like the install
dir though, why write custom meson commands per file type at all,
instead add a rule that always invokes

DESTDIR=$(BUILDDIR)/vroot ninja install

to populate a dir that's guaranteed identical to the install layout


Unfortunately Meson cannot define a rule which will be always invoked as 
far as I know.


Regards,
Akihiko Odaki



Regards,
Daniel




Re: New "IndustryStandard" fw_cfg?

2022-06-15 Thread Tom Lendacky

On 6/15/22 10:19, Xiaoyao Li wrote:

On 6/15/2022 8:46 AM, Xu, Min M wrote:
I would like to add more engineers (Confidential Computing Reviewers in 
EDK2 community and Intel's QEMU engineers) in this mail thread.



-Original Message-
From: Dionna Amalie Glaze 
Sent: Wednesday, June 15, 2022 2:09 AM
To: qemu-devel@nongnu.org
Cc: Xu, Min M ; Lendacky, Thomas

Subject: New "IndustryStandard" fw_cfg?

Hi y'all, I'm Dionna. I work on Confidential VMs at Google Cloud. I've 
been

keeping up with the TDX and SEV-SNP developments in OVMF and Linux,
and some in Qemu.

There's a new UEFI feature in v2.9 of the specification (March 2021) that
allows for memory ranges to be classified as "unaccepted", since both TDX
and SEV-SNP require that the guest VM accept any host-made changes to
page state. We should expect newer technologies on non-x86 architectures
to require memory acceptance as well. Operating systems are not
necessarily going to support this memory type, however.

This leads to a problem: how does the UEFI know that the OS it's going to
boot will support unaccepted memory? 


Why does UEFI need to know it?

Per my understanding, Unaccepted Memory in UEFI is introduced for 
confidential VMs, i.e., for Intel TDX and AMD SEV-SNP. The only reason 
UEFI/OVMF reports "Unaccepted Memory" to OS, is a confidential VM is 
desired. Thus, the (guset) OS has to be enlightened to know how to handle 
unaccepted memory. And of course, the non-confidential enlightened OS, 
e.g., old linux kernel, fails boot/hits issue if it doesn't support 
unaccepted memory.


As of today, SNP guest support is part of current OVMF and Linux 5.19-rcX, 
but support for unaccepted memory is not. The current OVMF SNP guest 
support will accept all the guest memory and the Linux SNP guest support 
will terminate the SNP guest if a page is accessed that has not been accepted.


Thanks,
Tom







Re: [PATCH 0/4] Multiple interface support on top of Multi-FD

2022-06-15 Thread Daniel P . Berrangé
On Fri, Jun 10, 2022 at 05:58:31PM +0530, manish.mishra wrote:
> 
> On 09/06/22 9:17 pm, Daniel P. Berrangé wrote:
> > On Thu, Jun 09, 2022 at 07:33:01AM +, Het Gala wrote:
> > > As of now, the multi-FD feature supports connection over the default 
> > > network
> > > only. This Patchset series is a Qemu side implementation of providing 
> > > multiple
> > > interfaces support for multi-FD. This enables us to fully utilize 
> > > dedicated or
> > > multiple NICs in case bonding of NICs is not possible.
> > > 
> > > 
> > > Introduction
> > > -
> > > Multi-FD Qemu implementation currently supports connection only on the 
> > > default
> > > network. This forbids us from advantages like:
> > > - Separating VM live migration traffic from the default network.
> 
> Hi Daniel,
> 
> I totally understand your concern around this approach increasing compexity 
> inside qemu,
> 
> when similar things can be done with NIC teaming. But we thought this 
> approach provides
> 
> much more flexibility to user in few cases like.
> 
> 1. We checked our customer data, almost all of the host had multiple NIC, but 
> LACP support
> 
>     in their setups was very rare. So for those cases this approach can help 
> in utilise multiple
> 
>     NICs as teaming is not possible there.

AFAIK,  LACP is not required in order to do link aggregation with Linux.
Traditional Linux bonding has no special NIC hardware or switch requirements,
so LACP is merely a "nice to have" in order to simplify some aspects.

IOW, migration with traffic spread across multiple NICs is already
possible AFAICT.

I can understand that some people may not have actually configured
bonding on their hosts, but it is not unreasonable to request that
they do so, if they want to take advantage fo aggrated bandwidth.

It has the further benefit that it will be fault tolerant. With
this proposal if any single NIC has a problem, the whole migration
will get stuck. With kernel level bonding, if any single NIC haus
a problem, it'll get offlined by the kernel and migration will
continue to  work across remaining active NICs.

> 2. We have seen requests recently to separate out traffic of storage, VM 
> netwrok, migration
> 
>     over different vswitch which can be backed by 1 or more NICs as this give 
> better
> 
>     predictability and assurance. So host with multiple ips/vswitches can be 
> very common
> 
>     environment. In this kind of enviroment this approach gives per vm or 
> migration level
> 
>     flexibilty, like for critical VM we can still use bandwidth from all 
> available vswitch/interface
> 
>     but for normal VM they can keep live migration only on dedicated NICs 
> without changing
> 
>     complete host network topology.
> 
>     At final we want it to be something like this [, 
> , ]
> 
>     to provide bandwidth_control per interface.

Again, it is already possible to separate migration traffic from storage
traffic, from other network traffic. The target IP given will influence
which NIC is used based on routing table and I know this is already
done widely with OpenStack deployments.

> 3. Dedicated NIC we mentioned as a use case, agree with you it can be done 
> without this
> 
>     approach too.


> > > Multi-interface with Multi-FD
> > > -
> > > Multiple-interface support over basic multi-FD has been implemented in the
> > > patches. Advantages of this implementation are:
> > > - Able to separate live migration traffic from default network interface 
> > > by
> > >creating multiFD channels on ip addresses of multiple non-default 
> > > interfaces.
> > > - Can optimize the number of multi-FD channels on a particular interface
> > >depending upon the network bandwidth limit on a particular interface.
> > Manually assigning individual channels to different NICs is a pretty
> > inefficient way to optimizing traffic. Feels like you could easily get
> > into a situation where one NIC ends up idle while the other is busy,
> > especially if the traffic patterns are different. For example with
> > post-copy there's an extra channel for OOB async page requests, and
> > its far from clear that manually picking NICs per chanel upfront is
> > going work for that.  The kernel can continually dynamically balance
> > load on the fly and so do much better than any static mapping QEMU
> > tries to apply, especially if there are multiple distinct QEMU's
> > competing for bandwidth.
> > 
> Yes, Daniel current solution is only for pre-copy. As with postcopy
> multiFD is not yet supported but in future we can extend it for postcopy
> 
> channels too.
> 
> > > Implementation
> > > --
> > > 
> > > Earlier the 'migrate' qmp command:
> > > { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } }
> > > 
> > > Modified qmp command:
> > > { "execute": "migrate",
> > >   "arguments": { "uri": "tcp:0:4446", "multi-fd-uri-list": [ {
> > >   "source-uri": "tcp::6900", 

[PATCH V8 04/39] memory: RAM_ANON flag

2022-06-15 Thread Steve Sistare
A memory-backend-ram or a memory-backend-memfd block with the RAM_SHARED
flag set is not migrated when migrate_ignore_shared() is true, but this
is wrong, because it has no named backing store, and its contents will be
lost.  Define a new flag RAM_ANON to distinguish this case.  Cpr will also
test this flag, for similar reasons.

Signed-off-by: Steve Sistare 
---
 backends/hostmem-epc.c   |  2 +-
 backends/hostmem-memfd.c |  1 +
 backends/hostmem-ram.c   |  1 +
 include/exec/memory.h|  3 +++
 include/exec/ram_addr.h  |  1 +
 migration/ram.c  |  3 ++-
 softmmu/physmem.c| 12 +---
 7 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/backends/hostmem-epc.c b/backends/hostmem-epc.c
index 037292d..cb06255 100644
--- a/backends/hostmem-epc.c
+++ b/backends/hostmem-epc.c
@@ -37,7 +37,7 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, 
Error **errp)
 }
 
 name = object_get_canonical_path(OBJECT(backend));
-ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED;
+ram_flags = (backend->share ? RAM_SHARED : 0) | RAM_PROTECTED | MAP_ANON;
 memory_region_init_ram_from_fd(>mr, OBJECT(backend),
name, backend->size, ram_flags,
fd, 0, errp);
diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
index 3fc85c3..c9d8001 100644
--- a/backends/hostmem-memfd.c
+++ b/backends/hostmem-memfd.c
@@ -55,6 +55,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error 
**errp)
 name = host_memory_backend_get_name(backend);
 ram_flags = backend->share ? RAM_SHARED : 0;
 ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
+ram_flags |= RAM_ANON;
 memory_region_init_ram_from_fd(>mr, OBJECT(backend), name,
backend->size, ram_flags, fd, 0, errp);
 g_free(name);
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index b8e55cd..5e80149 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -30,6 +30,7 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error 
**errp)
 name = host_memory_backend_get_name(backend);
 ram_flags = backend->share ? RAM_SHARED : 0;
 ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
+ram_flags |= RAM_ANON;
 memory_region_init_ram_flags_nomigrate(>mr, OBJECT(backend), name,
backend->size, ram_flags, errp);
 g_free(name);
diff --git a/include/exec/memory.h b/include/exec/memory.h
index f1c1945..0daddd7 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -203,6 +203,9 @@ typedef struct IOMMUTLBEvent {
 /* RAM that isn't accessible through normal means. */
 #define RAM_PROTECTED (1 << 8)
 
+/* RAM has no name outside the qemu process. */
+#define RAM_ANON (1 << 9)
+
 static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn,
IOMMUNotifierFlag flags,
hwaddr start, hwaddr end,
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index f3e0c78..56188b8 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -94,6 +94,7 @@ static inline unsigned long int 
ramblock_recv_bitmap_offset(void *host_addr,
 }
 
 bool ramblock_is_pmem(RAMBlock *rb);
+bool ramblock_is_anon(RAMBlock *rb);
 
 long qemu_minrampagesize(void);
 long qemu_maxrampagesize(void);
diff --git a/migration/ram.c b/migration/ram.c
index 5f5e37f..5cdb93d 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -164,7 +164,8 @@ out:
 bool ramblock_is_ignored(RAMBlock *block)
 {
 return !qemu_ram_is_migratable(block) ||
-   (migrate_ignore_shared() && qemu_ram_is_shared(block));
+   (migrate_ignore_shared() && qemu_ram_is_shared(block) &&
+!ramblock_is_anon(block));
 }
 
 #undef RAMBLOCK_FOREACH
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 657841e..0f1ce28 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -1975,6 +1975,7 @@ static void ram_block_add(RAMBlock *new_block, Error 
**errp)
 new_block->offset = find_ram_offset(new_block->max_length);
 
 if (!new_block->host) {
+new_block->flags |= RAM_ANON;
 if (xen_enabled()) {
 xen_ram_alloc(new_block->offset, new_block->max_length,
   new_block->mr, );
@@ -2059,7 +2060,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, 
MemoryRegion *mr,
 
 /* Just support these ram flags by now. */
 assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE |
-  RAM_PROTECTED)) == 0);
+  RAM_PROTECTED | RAM_ANON)) == 0);
 
 if (xen_enabled()) {
 error_setg(errp, "-mem-path not supported with Xen");
@@ -2151,7 +2152,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, 
ram_addr_t max_size,
 Error *local_err = NULL;
 
 assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
- 

misaligned-pointer-use libslirp/src/tcp_input.c

2022-06-15 Thread Patrick Venture
Hey - I wanted to ask if someone else has seen this or has suggestions on
how to fix it in libslirp / qemu.

libslirp version: 3ad1710a96678fe79066b1469cead4058713a1d9

The blow is line:
https://gitlab.freedesktop.org/slirp/libslirp/-/blob/master/src/tcp_input.c#L310

I0614 13:44:44.3040872040 bytestream.cc:22] QEMU:
third_party/libslirp/src/tcp_input.c:310:56: runtime error: member access
within misaligned address 0x9a4000f4 for type 'struct qlink', which
requires 8 byte alignment
I0614 13:44:44.3041562040 bytestream.cc:22] QEMU: 0x9a4000f4: note:
pointer points here
I0614 13:44:44.3041842040 bytestream.cc:22] QEMU:   00 00 00 00 00 00
00 02  20 02 0a 00 00 01 42 01  0a 00 02 02 42 01 0a 00  00 01 86 dd 60 02
dd 79
I0614 13:44:44.3042042040 bytestream.cc:22] QEMU:   ^
I0614 13:44:44.6411732040 bytestream.cc:22] QEMU: #0 0xcbe34bd8
in tcp_input third_party/libslirp/src/tcp_input.c:310:56
I0614 13:44:44.6412392040 bytestream.cc:22] QEMU: #1 0xcbe22a94
in ip6_input third_party/libslirp/src/ip6_input.c:74:9
I0614 13:44:44.6412622040 bytestream.cc:22] QEMU: #2 0xcbe0bbbc
in slirp_input third_party/libslirp/src/slirp.c:1169:13
I0614 13:44:44.6412802040 bytestream.cc:22] QEMU: #3 0xcbd55f6c
in net_slirp_receive third_party/qemu/net/slirp.c:136:5
I0614 13:44:44.6412962040 bytestream.cc:22] QEMU: #4 0xcbd4e77c
in nc_sendv_compat third_party/qemu/net/net.c
I0614 13:44:44.6413232040 bytestream.cc:22] QEMU: #5 0xcbd4e77c
in qemu_deliver_packet_iov third_party/qemu/net/net.c:850:15
I0614 13:44:44.6413422040 bytestream.cc:22] QEMU: #6 0xcbd50bfc
in qemu_net_queue_deliver_iov third_party/qemu/net/queue.c:179:11
I0614 13:44:44.6413592040 bytestream.cc:22] QEMU: #7 0xcbd50bfc
in qemu_net_queue_send_iov third_party/qemu/net/queue.c:246:11
I0614 13:44:44.6413822040 bytestream.cc:22] QEMU: #8 0xcbd4a88c
in qemu_sendv_packet_async third_party/qemu/net/net.c:891:12
I0614 13:44:44.6413962040 bytestream.cc:22] QEMU: #9 0xcacb1de0
in virtio_net_flush_tx third_party/qemu/hw/net/virtio-net.c:2586:15
I0614 13:44:44.6414162040 bytestream.cc:22] QEMU: #10
0xcacb1580 in virtio_net_tx_bh
third_party/qemu/hw/net/virtio-net.c:2703:11
I0614 13:44:44.6414382040 bytestream.cc:22] QEMU: #11
0xcc2bcf64 in aio_bh_call third_party/qemu/util/async.c:142:5
I0614 13:44:44.6414632040 bytestream.cc:22] QEMU: #12
0xcc2bcf64 in aio_bh_poll third_party/qemu/util/async.c:170:13
I0614 13:44:44.6414772040 bytestream.cc:22] QEMU: #13
0xcc2b8f70 in aio_dispatch third_party/qemu/util/aio-posix.c:420:5
I0614 13:44:44.6414952040 bytestream.cc:22] QEMU: #14
0xcc2bf120 in aio_ctx_dispatch third_party/qemu/util/async.c:312:5
I0614 13:44:44.6415102040 bytestream.cc:22] QEMU: #15
0xcc3a7690 in g_main_dispatch third_party/glib/glib/gmain.c:3417:27
I0614 13:44:44.6415252040 bytestream.cc:22] QEMU: #16
0xcc3a7690 in g_main_context_dispatch
third_party/glib/glib/gmain.c:4135:7
I0614 13:44:44.6415462040 bytestream.cc:22] QEMU: #17
0xcc2de3ec in glib_pollfds_poll third_party/qemu/util/main-loop.c:232:9
I0614 13:44:44.6415622040 bytestream.cc:22] QEMU: #18
0xcc2de3ec in os_host_main_loop_wait
third_party/qemu/util/main-loop.c:255:5
I0614 13:44:44.6415802040 bytestream.cc:22] QEMU: #19
0xcc2de3ec in main_loop_wait third_party/qemu/util/main-loop.c:531:11
I0614 13:44:44.6415982040 bytestream.cc:22] QEMU: #20
0xcbd82798 in qemu_main_loop third_party/qemu/softmmu/runstate.c:727:9
I0614 13:44:44.6416122040 bytestream.cc:22] QEMU: #21
0xcadacb5c in main

Patrick


[PATCH] softmmu: Always initialize xlat in address_space_translate_for_iotlb

2022-06-15 Thread Richard Henderson
The bug is an uninitialized memory read, along the translate_fail
path, which results in garbage being read from iotlb_to_section,
which can lead to a crash in io_readx/io_writex.

The bug may be fixed by writing any value with zero
in ~TARGET_PAGE_MASK, so that the call to iotlb_to_section using
the xlat'ed address returns io_mem_unassigned, as desired by the
translate_fail path.

It is most useful to record the original physical page address,
which will eventually be logged by memory_region_access_valid
when the access is rejected by unassigned_mem_accepts.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1065
Signed-off-by: Richard Henderson 
---
 softmmu/physmem.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 657841eed0..fb0f0709b5 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -681,6 +681,9 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, 
hwaddr addr,
 AddressSpaceDispatch *d =
 qatomic_rcu_read(>cpu_ases[asidx].memory_dispatch);
 
+/* Record the original phys page for use by the translate_fail path. */
+*xlat = addr;
+
 for (;;) {
 section = address_space_translate_internal(d, addr, , plen, 
false);
 
-- 
2.34.1




Re: [PATCH 2/5] tests/qemu-iotests: skip 108 when FUSE is not loaded

2022-06-15 Thread Daniel P . Berrangé
On Wed, Jun 15, 2022 at 11:48:02AM -0400, John Snow wrote:
> On Wed, Jun 15, 2022 at 11:33 AM Daniel P. Berrangé  
> wrote:
> >
> > On Wed, Jun 15, 2022 at 09:41:32AM -0400, John Snow wrote:
> > > On Tue, Jun 14, 2022 at 10:30 AM John Snow  wrote:
> > > >
> > > > On Tue, Jun 14, 2022 at 4:59 AM Daniel P. Berrangé 
> > > >  wrote:
> > > > >
> > > > > On Tue, Jun 14, 2022 at 06:46:35AM +0200, Thomas Huth wrote:
> > > > > > On 14/06/2022 03.50, John Snow wrote:
> > > > > > > In certain container environments we may not have FUSE at all, so 
> > > > > > > skip
> > > > > > > the test in this circumstance too.
> > > > > > >
> > > > > > > Signed-off-by: John Snow 
> > > > > > > ---
> > > > > > >   tests/qemu-iotests/108 | 6 ++
> > > > > > >   1 file changed, 6 insertions(+)
> > > > > > >
> > > > > > > diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108
> > > > > > > index 9e923d6a59f..e401c5e9933 100755
> > > > > > > --- a/tests/qemu-iotests/108
> > > > > > > +++ b/tests/qemu-iotests/108
> > > > > > > @@ -60,6 +60,12 @@ if sudo -n losetup &>/dev/null; then
> > > > > > >   else
> > > > > > >   loopdev=false
> > > > > > > +# Check for fuse support in the host environment:
> > > > > > > +lsmod | grep fuse &>/dev/null;
> > > > > >
> > > > > > That doesn't work if fuse has been linked statically into the 
> > > > > > kernel. Would
> > > > > > it make sense to test for /sys/fs/fuse instead?
> > > > > >
> > > > > > (OTOH, we likely hardly won't run this on statically linked kernels 
> > > > > > anyway,
> > > > > > so it might not matter too much)
> > > > >
> > > > > But more importantly 'lsmod' may not be installed in our container
> > > > > images. So checking /sys/fs/fuse avoids introducing a dep on the
> > > > > 'kmod' package.
> > > > >
> > > > > >
> > > > > > > +if [[ $? -ne 0 ]]; then
> > > > > >
> > > > > > I'd prefer single "[" instead of "[[" ... but since we're requiring 
> > > > > > bash
> > > > > > anyway, it likely doesn't matter.
> > > > >
> > > > > Or
> > > > >
> > > > > if  test $? != 0 ; then
> > > > >
> > > > > >
> > > > > > > +_notrun 'No Passwordless sudo nor FUSE kernel module'
> > > > > > > +fi
> > > > > > > +
> > > > > > >   # QSD --export fuse will either yield "Parameter 'id' is 
> > > > > > > missing"
> > > > > > >   # or "Invalid parameter 'fuse'", depending on whether there 
> > > > > > > is
> > > > > > >   # FUSE support or not.
> > > > > >
> > > >
> > > > Good suggestions, thanks!
> > > >
> > >
> > > I think I need to test against /dev/fuse instead, because /sys/fs/fuse
> > > actually exists, but because of docker permissions (etc), FUSE isn't
> > > actually usable from the child container.
> > >
> > > I wound up with this:
> > >
> > > # Check for usable FUSE in the host environment:
> > > if test ! -c "/dev/fuse"; then
> > > _notrun 'No passwordless sudo nor usable /dev/fuse'
> > > fi
> > >
> > > Seems to work for my case here, at least, but I don't have a good
> > > sense for how broadly flexible it might be. It might be nicer to
> > > concoct some kind of NOP fuse mount instead, but I wasn't able to
> > > figure out such a command quickly.
> > >
> > > The next problem I have is actually related; test-qga (for the
> > > Centos.x86_64 run) is failing because the guest agent is reading
> > > /proc/self/mountinfo -- which contains entries for block devices that
> > > are not visible in the current container scope. I think when QGA goes
> > > to read info about these devices to populate a response, it chokes.
> > > This might be a genuine bug in QGA if we want it to tolerate existing
> > > inside of a container.
> >
> > Yes, we should fix this. Even if you don't run QGA in a container,
> > someone might configure the systemd service to harden it, by
> > restricting what /dev it is able to see and thus trigger the
> > same issue.
> 
> Naive solution: if we try to look in /sys/dev/block/%u:%u and find
> that we are unable to do so for whatever reason (ENOENT et al), just
> skip that entry for the fsinfo returned to the caller.
> 
> Does it need to be fancier than that?

/sys stuff maybe unfiltered, while /dev is restricted.

I've not looked at the QGA code for this, but conceptually I think
I would just identify where in the code errors hit, and ignore the
appropriate error conditions. The goal is to return as much info
as we reasonably can offer, given our execution environment
constraints.


With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




Re: [PATCH v4 5/7] 9pfs: fix 'Twalk' to only send error if no component walked

2022-06-15 Thread Christian Schoenebeck
On Mittwoch, 15. Juni 2022 17:52:49 CEST Greg Kurz wrote:
> On Tue, 15 Mar 2022 11:08:39 +0100
> 
> Christian Schoenebeck  wrote:
> > Current implementation of 'Twalk' request handling always sends an
> > 'Rerror'
> > 
> > response if any error occured. The 9p2000 protocol spec says though:
> >   "
> >   If the first element cannot be walked for any reason, Rerror is
> >   returned.
> >   Otherwise, the walk will return an Rwalk message containing nwqid qids
> >   corresponding, in order, to the files that are visited by the nwqid
> >   successful elementwise walks; nwqid is therefore either nwname or the
> >   index
> >   of the first elementwise walk that failed.
> >   "
> >   
> >   http://ericvh.github.io/9p-rfc/rfc9p2000.html#anchor33
> > 
> > For that reason we are no longer leaving from an error path in function
> > v9fs_walk(), unless really no path component could be walked successfully
> > or if the request has been interrupted.
> > 
> > Local variable 'nwalked' counts and reflects the number of path components
> > successfully processed by background I/O thread, whereas local variable
> > 'name_idx' subsequently counts and reflects the number of path components
> > eventually accepted successfully by 9p server controller portion.
> > 
> > New local variable 'any_err' is an aggregate variable reflecting whether
> > any error occurred at all, while already existing variable 'err' only
> > reflects the last error.
> > 
> > Despite QIDs being delivered to client in a more relaxed way now, it is
> > important to note though that fid still must remain unaffected if any
> > error
> > occurred.
> > 
> > Signed-off-by: Christian Schoenebeck 
> > ---
> > 
> >  hw/9pfs/9p.c | 43 +++
> >  1 file changed, 27 insertions(+), 16 deletions(-)
> > 
> > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > index 298f4e6548..e770972a71 100644
> > --- a/hw/9pfs/9p.c
> > +++ b/hw/9pfs/9p.c
> > @@ -1766,7 +1766,7 @@ static void coroutine_fn v9fs_walk(void *opaque)
> > 
> >  {
> >  
> >  int name_idx, nwalked;
> >  g_autofree V9fsQID *qids = NULL;
> > 
> > -int i, err = 0;
> > +int i, err = 0, any_err = 0;
> > 
> >  V9fsPath dpath, path;
> >  P9ARRAY_REF(V9fsPath) pathes = NULL;
> >  uint16_t nwnames;
> > 
> > @@ -1832,19 +1832,20 @@ static void coroutine_fn v9fs_walk(void *opaque)
> > 
> >   * driver code altogether inside the following block.
> >   */
> >  
> >  v9fs_co_run_in_worker({
> > 
> > +nwalked = 0;
> > 
> >  if (v9fs_request_cancelled(pdu)) {
> > 
> > -err = -EINTR;
> > +any_err |= err = -EINTR;
> 
> Not super fan of such constructs but I cannot think of anything
> better.. so be it ! :-)

Mwa, :( and I thought this was a slick (though probably yet again unorthodox) 
way to handle aggregate errors.

[...]
> > @@ -1874,12 +1875,12 @@ static void coroutine_fn v9fs_walk(void *opaque)
> > 
> >  /*
> >  
> >   * Handle all the rest of this Twalk request on main thread ...
> >   */
> > 
> > -if (err < 0) {
> > +if ((err < 0 && !nwalked) || err == -EINTR) {
> 
> So this is making an exception to the spec excerpt you're mentioning
> in the changelog.
> 
> EINTR can only come from the v9fs_request_cancelled(pdu) == true case,
> since QEMU doesn't have signal handlers AFAIK. This would be the result
> of a TFLUSH , likely to handle ^C from the client side. I guess that in
> that peculiar case, it quite makes sense to return RERROR/RLERROR instead
> of the "degraded" RWALK that the end user isn't waiting for. To sum up,
> TFLUSH behavior prevails on TWALK. Please add a comment though since
> this isn't super obvious in the spec.

Yes, everything you said is depicting this exception here precisely, and I 
agree that it deserves a comment for further clarification, which I'll simply 
add on my end to avoid the noise.

Does the following sound good to you?

"NOTE: -EINTR is an exception where we deviate from the protocol spec and 
simply send an (R)Lerror response instead of bothering to assemble a 
(deducted) Rwalk response; because -EINTR is always the result of a Tflush 
request, so client would no longer wait for a response in this case anyway."

> Apart from that, LGTM.
> 
> Reviewed-by: Greg Kurz 

Thanks for your reviews, much appreciated!

Best regards,
Christian Schoenebeck





Re: [PATCH v4 7/7] tests/9pfs: check fid being unaffected in fs_walk_2nd_nonexistent

2022-06-15 Thread Greg Kurz
On Tue, 15 Mar 2022 11:08:47 +0100
Christian Schoenebeck  wrote:

> Extend previously added test case by checking that fid was unaffected
> by 'Twalk' request (i.e. when 2nd path component of request being
> invalid). Do that by subsequently sending a 'Tgetattr' request with
> the fid previously used for 'Twalk'; that 'Tgetattr' request should
> return an 'Rlerror' response by 9p server with error code ENOENT as
> that fid is basically invalid.
> 
> And as we are at it, also check that the QID returned by 'Twalk' is
> not identical to the root node's QID.
> 
> Signed-off-by: Christian Schoenebeck 
> ---

Reviewed-by: Greg Kurz 

>  tests/qtest/virtio-9p-test.c | 26 ++
>  1 file changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index f6e78d388e..2784ee4b2d 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -721,14 +721,19 @@ static void fs_version(void *obj, void *data, 
> QGuestAllocator *t_alloc)
>  do_version(obj);
>  }
>  
> -static void do_attach(QVirtio9P *v9p)
> +static void do_attach_rqid(QVirtio9P *v9p, v9fs_qid *qid)
>  {
>  P9Req *req;
>  
>  do_version(v9p);
>  req = v9fs_tattach(v9p, 0, getuid(), 0);
>  v9fs_req_wait_for_reply(req, NULL);
> -v9fs_rattach(req, NULL);
> +v9fs_rattach(req, qid);
> +}
> +
> +static void do_attach(QVirtio9P *v9p)
> +{
> +do_attach_rqid(v9p, NULL);
>  }
>  
>  static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
> @@ -1101,19 +1106,32 @@ static void fs_walk_2nd_nonexistent(void *obj, void 
> *data,
>  {
>  QVirtio9P *v9p = obj;
>  alloc = t_alloc;
> +v9fs_qid root_qid;
>  uint16_t nwqid;
> +uint32_t fid, err;
> +P9Req *req;
>  g_autofree v9fs_qid *wqid = NULL;
>  g_autofree char *path = g_strdup_printf(
>  QTEST_V9FS_SYNTH_WALK_FILE "/non-existent", 0
>  );
>  
> -do_attach(v9p);
> -do_walk_rqids(v9p, path, , );
> +do_attach_rqid(v9p, _qid);
> +fid = do_walk_rqids(v9p, path, , );
>  /*
>   * The 9p2000 protocol spec says: "nwqid is therefore either nwname or 
> the
>   * index of the first elementwise walk that failed."
>   */
>  assert(nwqid == 1);
> +
> +/* returned QID wqid[0] is file ID of 1st subdir */
> +g_assert(wqid && wqid[0] && !is_same_qid(root_qid, wqid[0]));
> +
> +/* expect fid being unaffected by walk above */
> +req = v9fs_tgetattr(v9p, fid, P9_GETATTR_BASIC, 0);
> +v9fs_req_wait_for_reply(req, NULL);
> +v9fs_rlerror(req, );
> +
> +g_assert_cmpint(err, ==, ENOENT);
>  }
>  
>  static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)




[PATCH v6 6/7] ui/icons: Use bundle mechanism

2022-06-15 Thread Akihiko Odaki
Signed-off-by: Akihiko Odaki 
---
 ui/cocoa.m   |  2 +-
 ui/gtk.c |  2 +-
 ui/icons/meson.build | 32 
 ui/sdl2.c|  4 ++--
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 84c84e98fc5..25584cc78ce 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1562,7 +1562,7 @@ - (BOOL)verifyQuit
 - (IBAction) do_about_menu_item: (id) sender
 {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-char *icon_path_c = get_relocated_path(CONFIG_QEMU_ICONDIR 
"/hicolor/512x512/apps/qemu.png");
+char *icon_path_c = find_bundle(CONFIG_QEMU_ICONDIR 
"/hicolor/512x512/apps/qemu.png");
 NSString *icon_path = [NSString stringWithUTF8String:icon_path_c];
 g_free(icon_path_c);
 NSImage *icon = [[NSImage alloc] initWithContentsOfFile:icon_path];
diff --git a/ui/gtk.c b/ui/gtk.c
index 2a791dd2aa0..27d5a3407cf 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2321,7 +2321,7 @@ static void gtk_display_init(DisplayState *ds, 
DisplayOptions *opts)
 s->opts = opts;
 
 theme = gtk_icon_theme_get_default();
-dir = get_relocated_path(CONFIG_QEMU_ICONDIR);
+dir = find_bundle(CONFIG_QEMU_ICONDIR);
 gtk_icon_theme_prepend_search_path(theme, dir);
 g_free(dir);
 g_set_prgname("qemu");
diff --git a/ui/icons/meson.build b/ui/icons/meson.build
index 12c52080ebd..1d99aff10ed 100644
--- a/ui/icons/meson.build
+++ b/ui/icons/meson.build
@@ -1,13 +1,29 @@
+icons = [
+  {
+'source': 'qemu_32x32.bmp',
+'install': 'hicolor' / '32x32' / 'apps' / 'qemu.bmp',
+  },
+  {
+'source': 'qemu.svg',
+'install': 'hicolor' / 'scalable' / 'apps' / 'qemu.svg',
+  },
+]
+
 foreach s: [16, 24, 32, 48, 64, 128, 256, 512]
   s = '@0@x@0@'.format(s.to_string())
-  install_data('qemu_@0@.png'.format(s),
-   rename: 'qemu.png',
-   install_dir: qemu_icondir / 'hicolor' / s / 'apps')
+  icons += {
+'source': 'qemu_@0@.png'.format(s),
+'install': 'hicolor' / s / 'apps' / 'qemu.png',
+  }
 endforeach
 
-install_data('qemu_32x32.bmp',
- rename: 'qemu.bmp',
- install_dir: qemu_icondir / 'hicolor' / '32x32' / 'apps')
+foreach icon: icons
+  source = icon.get('source')
+  install = icon.get('install')
+
+  install_data(source,
+   rename: fs.name(install),
+   install_dir: qemu_icondir / fs.parent(install))
 
-install_data('qemu.svg',
- install_dir: qemu_icondir / 'hicolor' / 'scalable' / 'apps')
+  bundles += { qemu_bundledir / qemu_icondir / install: 
meson.current_source_dir() / source }
+endforeach
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 8cb77416af2..916815cc8a2 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -910,11 +910,11 @@ static void sdl2_display_init(DisplayState *ds, 
DisplayOptions *o)
 }
 
 #ifdef CONFIG_SDL_IMAGE
-dir = get_relocated_path(CONFIG_QEMU_ICONDIR 
"/hicolor/128x128/apps/qemu.png");
+dir = find_bundle(CONFIG_QEMU_ICONDIR "/hicolor/128x128/apps/qemu.png");
 icon = IMG_Load(dir);
 #else
 /* Load a 32x32x4 image. White pixels are transparent. */
-dir = get_relocated_path(CONFIG_QEMU_ICONDIR 
"/hicolor/32x32/apps/qemu.bmp");
+dir = find_bundle(CONFIG_QEMU_ICONDIR "/hicolor/32x32/apps/qemu.bmp");
 icon = SDL_LoadBMP(dir);
 if (icon) {
 uint32_t colorkey = SDL_MapRGB(icon->format, 255, 255, 255);
-- 
2.32.1 (Apple Git-133)




Re: [PATCH v7 04/13] migration: Export ram_transferred_ram()

2022-06-15 Thread Dr. David Alan Gilbert
* Juan Quintela (quint...@redhat.com) wrote:
> Signed-off-by: Juan Quintela 

Reviewed-by: Dr. David Alan Gilbert 

> ---
>  migration/ram.h | 2 ++
>  migration/ram.c | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/migration/ram.h b/migration/ram.h
> index ded0a3a086..7b641adc55 100644
> --- a/migration/ram.h
> +++ b/migration/ram.h
> @@ -65,6 +65,8 @@ int ram_load_postcopy(QEMUFile *f);
>  
>  void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
>  
> +void ram_transferred_add(uint64_t bytes);
> +
>  int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr);
>  bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t 
> byte_offset);
>  void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);
> diff --git a/migration/ram.c b/migration/ram.c
> index 5f5e37f64d..30b0680942 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -394,7 +394,7 @@ uint64_t ram_bytes_remaining(void)
>  
>  MigrationStats ram_counters;
>  
> -static void ram_transferred_add(uint64_t bytes)
> +void ram_transferred_add(uint64_t bytes)
>  {
>  if (runstate_is_running()) {
>  ram_counters.precopy_bytes += bytes;
> -- 
> 2.35.3
> 
-- 
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




[PATCH v6 7/7] net: Use bundle mechanism

2022-06-15 Thread Akihiko Odaki
Signed-off-by: Akihiko Odaki 
---
 meson.build | 2 ++
 net/tap.c   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index ab5ab85bf4e..72e42048cbe 100644
--- a/meson.build
+++ b/meson.build
@@ -3574,6 +3574,8 @@ if have_tools
dependencies: [authz, crypto, io, qom, qemuutil,
   libcap_ng, mpathpersist],
install: true)
+
+bundles += { get_option('libexecdir') / 'qemu-bridge-helper': 
'../../qemu-bridge-helper' }
   endif
 
   if have_ivshmem
diff --git a/net/tap.c b/net/tap.c
index b3ddfd4a74b..5beba85fb22 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -507,7 +507,7 @@ static int net_bridge_run_helper(const char *helper, const 
char *bridge,
 sigprocmask(SIG_BLOCK, , );
 
 if (!helper) {
-helper = default_helper = get_relocated_path(DEFAULT_BRIDGE_HELPER);
+helper = default_helper = find_bundle(DEFAULT_BRIDGE_HELPER);
 }
 
 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
-- 
2.32.1 (Apple Git-133)




[PATCH v6 2/7] qga: Relocate a path emitted in the help text

2022-06-15 Thread Akihiko Odaki
Signed-off-by: Akihiko Odaki 
---
 qga/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/main.c b/qga/main.c
index c373fec3ee6..06e507b9979 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -270,7 +270,7 @@ QEMU_HELP_BOTTOM "\n"
 , cmd, QGA_VIRTIO_PATH_DEFAULT, QGA_SERIAL_PATH_DEFAULT,
 dfl_pathnames.pidfile,
 #ifdef CONFIG_FSFREEZE
-QGA_FSFREEZE_HOOK_DEFAULT,
+get_relocated_path(QGA_FSFREEZE_HOOK_DEFAULT),
 #endif
 dfl_pathnames.state_dir);
 }
-- 
2.32.1 (Apple Git-133)




[PULL 18/18] linux-aio: explain why max batch is checked in laio_io_unplug()

2022-06-15 Thread Stefan Hajnoczi
It may not be obvious why laio_io_unplug() checks max batch. I discussed
this with Stefano and have added a comment summarizing the reason.

Cc: Stefano Garzarella 
Cc: Kevin Wolf 
Signed-off-by: Stefan Hajnoczi 
Reviewed-by: Stefano Garzarella 
Message-id: 20220609164712.1539045-3-stefa...@redhat.com
Signed-off-by: Stefan Hajnoczi 
---
 block/linux-aio.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/block/linux-aio.c b/block/linux-aio.c
index 6078da7e42..9c2393a2f7 100644
--- a/block/linux-aio.c
+++ b/block/linux-aio.c
@@ -365,6 +365,12 @@ void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s,
 assert(s->io_q.plugged);
 s->io_q.plugged--;
 
+/*
+ * Why max batch checking is performed here:
+ * Another BDS may have queued requests with a higher dev_max_batch and
+ * therefore in_queue could now exceed our dev_max_batch. Re-check the max
+ * batch so we can honor our device's dev_max_batch.
+ */
 if (s->io_q.in_queue >= laio_max_batch(s, dev_max_batch) ||
 (!s->io_q.plugged &&
  !s->io_q.blocked && !QSIMPLEQ_EMPTY(>io_q.pending))) {
-- 
2.36.1




[PULL 15/18] vfio-user: handle device interrupts

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Forward remote device's interrupts to the guest

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Message-id: 
9523479eaafe050677f4de2af5dd0df18c27cfd9.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 MAINTAINERS   |   1 +
 include/hw/pci/msi.h  |   1 +
 include/hw/pci/msix.h |   1 +
 include/hw/pci/pci.h  |  13 +++
 include/hw/remote/vfio-user-obj.h |   6 ++
 hw/pci/msi.c  |  49 +++--
 hw/pci/msix.c |  35 ++-
 hw/pci/pci.c  |  13 +++
 hw/remote/machine.c   |  16 ++-
 hw/remote/vfio-user-obj.c | 167 ++
 stubs/vfio-user-obj.c |   6 ++
 hw/remote/trace-events|   1 +
 stubs/meson.build |   1 +
 13 files changed, 298 insertions(+), 12 deletions(-)
 create mode 100644 include/hw/remote/vfio-user-obj.h
 create mode 100644 stubs/vfio-user-obj.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 563259101b..aaa649a50d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3644,6 +3644,7 @@ F: hw/remote/iohub.c
 F: include/hw/remote/iohub.h
 F: subprojects/libvfio-user
 F: hw/remote/vfio-user-obj.c
+F: include/hw/remote/vfio-user-obj.h
 F: hw/remote/iommu.c
 F: include/hw/remote/iommu.h
 
diff --git a/include/hw/pci/msi.h b/include/hw/pci/msi.h
index 4087688486..58aa576215 100644
--- a/include/hw/pci/msi.h
+++ b/include/hw/pci/msi.h
@@ -43,6 +43,7 @@ void msi_notify(PCIDevice *dev, unsigned int vector);
 void msi_send_message(PCIDevice *dev, MSIMessage msg);
 void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len);
 unsigned int msi_nr_vectors_allocated(const PCIDevice *dev);
+void msi_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp);
 
 static inline bool msi_present(const PCIDevice *dev)
 {
diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h
index 4c4a60c739..4f1cda0ebe 100644
--- a/include/hw/pci/msix.h
+++ b/include/hw/pci/msix.h
@@ -36,6 +36,7 @@ void msix_clr_pending(PCIDevice *dev, int vector);
 int msix_vector_use(PCIDevice *dev, unsigned vector);
 void msix_vector_unuse(PCIDevice *dev, unsigned vector);
 void msix_unuse_all_vectors(PCIDevice *dev);
+void msix_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp);
 
 void msix_notify(PCIDevice *dev, unsigned vector);
 
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 44dacfa224..b54b6ef88f 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -16,6 +16,7 @@ extern bool pci_available;
 #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f)
 #define PCI_FUNC(devfn) ((devfn) & 0x07)
 #define PCI_BUILD_BDF(bus, devfn) ((bus << 8) | (devfn))
+#define PCI_BDF_TO_DEVFN(x) ((x) & 0xff)
 #define PCI_BUS_MAX 256
 #define PCI_DEVFN_MAX   256
 #define PCI_SLOT_MAX32
@@ -127,6 +128,10 @@ typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int 
region_num,
 pcibus_t addr, pcibus_t size, int type);
 typedef void PCIUnregisterFunc(PCIDevice *pci_dev);
 
+typedef void MSITriggerFunc(PCIDevice *dev, MSIMessage msg);
+typedef MSIMessage MSIPrepareMessageFunc(PCIDevice *dev, unsigned vector);
+typedef MSIMessage MSIxPrepareMessageFunc(PCIDevice *dev, unsigned vector);
+
 typedef struct PCIIORegion {
 pcibus_t addr; /* current PCI mapping address. -1 means not mapped */
 #define PCI_BAR_UNMAPPED (~(pcibus_t)0)
@@ -329,6 +334,14 @@ struct PCIDevice {
 /* Space to store MSIX table & pending bit array */
 uint8_t *msix_table;
 uint8_t *msix_pba;
+
+/* May be used by INTx or MSI during interrupt notification */
+void *irq_opaque;
+
+MSITriggerFunc *msi_trigger;
+MSIPrepareMessageFunc *msi_prepare_message;
+MSIxPrepareMessageFunc *msix_prepare_message;
+
 /* MemoryRegion container for msix exclusive BAR setup */
 MemoryRegion msix_exclusive_bar;
 /* Memory Regions for MSIX table and pending bit entries. */
diff --git a/include/hw/remote/vfio-user-obj.h 
b/include/hw/remote/vfio-user-obj.h
new file mode 100644
index 00..87ab78b875
--- /dev/null
+++ b/include/hw/remote/vfio-user-obj.h
@@ -0,0 +1,6 @@
+#ifndef VFIO_USER_OBJ_H
+#define VFIO_USER_OBJ_H
+
+void vfu_object_set_bus_irq(PCIBus *pci_bus);
+
+#endif
diff --git a/hw/pci/msi.c b/hw/pci/msi.c
index 47d2b0f33c..5c471b9616 100644
--- a/hw/pci/msi.c
+++ b/hw/pci/msi.c
@@ -134,7 +134,7 @@ void msi_set_message(PCIDevice *dev, MSIMessage msg)
 pci_set_word(dev->config + msi_data_off(dev, msi64bit), msg.data);
 }
 
-MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector)
+static MSIMessage msi_prepare_message(PCIDevice *dev, unsigned int vector)
 {
 uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
 bool msi64bit = flags & PCI_MSI_FLAGS_64BIT;
@@ -159,6 +159,11 @@ MSIMessage msi_get_message(PCIDevice 

[PATCH v6 5/7] datadir: Use bundle mechanism

2022-06-15 Thread Akihiko Odaki
softmmu/datadir.c had its own implementation to find files in the
build tree, but now bundle mechanism provides the unified
implementation which works for datadir and the other files.

Signed-off-by: Akihiko Odaki 
---
 .travis.yml |  2 +-
 pc-bios/keymaps/meson.build |  2 ++
 pc-bios/meson.build | 19 +--
 scripts/oss-fuzz/build.sh   |  2 +-
 softmmu/datadir.c   | 32 
 tests/qtest/fuzz/fuzz.c | 15 ---
 tests/vm/fedora |  2 +-
 tests/vm/freebsd|  2 +-
 tests/vm/netbsd |  2 +-
 tests/vm/openbsd|  2 +-
 util/cutils.c   | 10 +++---
 11 files changed, 28 insertions(+), 62 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9afc4a54b8f..9fee2167b95 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ jobs:
 - BUILD_RC=0 && make -j${JOBS} || BUILD_RC=$?
 - |
   if [ "$BUILD_RC" -eq 0 ] ; then
-  mv pc-bios/s390-ccw/*.img pc-bios/ ;
+  mv pc-bios/s390-ccw/*.img qemu-bundle/share/qemu ;
   ${TEST_CMD} ;
   else
   $(exit $BUILD_RC);
diff --git a/pc-bios/keymaps/meson.build b/pc-bios/keymaps/meson.build
index 44247a12b54..dd103092290 100644
--- a/pc-bios/keymaps/meson.build
+++ b/pc-bios/keymaps/meson.build
@@ -67,3 +67,5 @@ if native_qemu_keymap.found()
 endif
 
 install_data(['sl', 'sv'], install_dir: qemu_datadir / 'keymaps')
+
+bundles += { qemu_datadir / 'keymaps': '../../../pc-bios/keymaps' }
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index 41ba1c0ec7b..0d2119836bd 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -20,6 +20,8 @@ if unpack_edk2_blobs
   install: get_option('install_blobs'),
   install_dir: qemu_datadir,
   command: [ bzip2, '-dc', '@INPUT0@' ])
+
+bundles += { qemu_datadir / f: '../../../pc-bios' / f  }
   endforeach
 endif
 
@@ -85,16 +87,13 @@ blobs = [
   'vof-nvram.bin',
 ]
 
-ln_s = [find_program('ln', required: true), '-sf']
-foreach f : blobs
-  roms += custom_target(f,
-build_by_default: have_system,
-output: f,
-input: files('meson.build'),# dummy input
-install: get_option('install_blobs'),
-install_dir: qemu_datadir,
-command: [ ln_s, meson.project_source_root() / 'pc-bios' / f, 
'@OUTPUT@' ])
-endforeach
+if get_option('install_blobs')
+  install_data(blobs, install_dir: qemu_datadir)
+
+  foreach f : blobs
+bundles += { qemu_datadir / f: meson.current_source_dir() / f }
+  endforeach
+endif
 
 subdir('descriptors')
 subdir('keymaps')
diff --git a/scripts/oss-fuzz/build.sh b/scripts/oss-fuzz/build.sh
index 98b56e05210..cbf8b3080e9 100755
--- a/scripts/oss-fuzz/build.sh
+++ b/scripts/oss-fuzz/build.sh
@@ -88,7 +88,7 @@ if [ "$GITLAB_CI" != "true" ]; then
 fi
 
 # Copy over the datadir
-cp  -r ../pc-bios/ "$DEST_DIR/pc-bios"
+cp  -r ../pc-bios/ "$DEST_DIR/qemu-bundle/share/qemu"
 
 targets=$(./qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}')
 base_copy="$DEST_DIR/qemu-fuzz-i386-target-$(echo "$targets" | head -n 1)"
diff --git a/softmmu/datadir.c b/softmmu/datadir.c
index 2a206f2740a..338479baddd 100644
--- a/softmmu/datadir.c
+++ b/softmmu/datadir.c
@@ -35,6 +35,7 @@ char *qemu_find_file(int type, const char *name)
 int i;
 const char *subdir;
 char *buf;
+char *bundle;
 
 /* Try the name as a straight path first */
 if (access(name, R_OK) == 0) {
@@ -61,7 +62,12 @@ char *qemu_find_file(int type, const char *name)
 }
 g_free(buf);
 }
-return NULL;
+
+bundle = g_strdup_printf("%s/%s%s", CONFIG_QEMU_DATADIR, subdir, name);
+buf = find_bundle(bundle);
+g_free(bundle);
+trace_load_file(name, buf);
+return buf;
 }
 
 void qemu_add_data_dir(char *path)
@@ -83,33 +89,10 @@ void qemu_add_data_dir(char *path)
 data_dir[data_dir_idx++] = path;
 }
 
-/*
- * Find a likely location for support files using the location of the binary.
- * When running from the build tree this will be "$bindir/pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated).
- *
- * The caller must use g_free() to free the returned data when it is
- * no longer required.
- */
-static char *find_datadir(void)
-{
-g_autofree char *dir = NULL;
-
-dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL);
-if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
-return g_steal_pointer();
-}
-
-return get_relocated_path(CONFIG_QEMU_DATADIR);
-}
-
 void qemu_add_default_firmwarepath(void)
 {
 /* add the configured firmware directory */
 qemu_add_data_dir(get_relocated_path(CONFIG_QEMU_FIRMWAREPATH));
-
-/* try to find datadir relative to the executable path */
-qemu_add_data_dir(find_datadir());
 }
 
 void qemu_list_data_dirs(void)
@@ -118,4 +101,5 @@ void 

[PATCH v6 0/7] cutils: Introduce bundle mechanism

2022-06-15 Thread Akihiko Odaki
Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files located relative
to the installation tree. The build tree must have a new directory,
qemu-bundle, to represent what files the installation tree would
have for reference by the executables.

v6: Reuse get_relocated_path() in find_bundle() (Paolo Bonzini)

v5:
* Prefer qemu-bundle if it exists. (Daniel P. Berrangé)
* Check install_blobs option before installing BIOSes (Paolo Bonzini)
* Add common code to set up qemu-bundle to the top level meson.build
  (Paolo Bonzini)

v4:
* Add Daniel P. Berrangé to CC. Hopefully this helps merging his patch:
  https://mail.gnu.org/archive/html/qemu-devel/2022-06/msg02276.html
* Rebased to the latest QEMU.

v3:
* Note that the bundle mechanism is for any files located relative to the
  installation tree including but not limited to datadir. (Peter Maydell)
* Fix "bridge" typo (Philippe Mathieu-Daudé)

v2: Rebased to the latest QEMU.

Akihiko Odaki (7):
  datadir: Simplify firmware directory search
  qga: Relocate a path emitted in the help text
  Remove prefixes from path configuration macros
  cutils: Introduce bundle mechanism
  datadir: Use bundle mechanism
  ui/icons: Use bundle mechanism
  net: Use bundle mechanism

 .travis.yml |  2 +-
 include/qemu/cutils.h   | 21 ++-
 meson.build | 35 
 net/tap.c   |  2 +-
 pc-bios/keymaps/meson.build |  2 ++
 pc-bios/meson.build | 19 +++--
 qemu-options.hx | 11 
 qga/main.c  |  2 +-
 scripts/oss-fuzz/build.sh   |  2 +-
 softmmu/datadir.c   | 43 +++---
 tests/qtest/fuzz/fuzz.c | 15 ---
 tests/vm/fedora |  2 +-
 tests/vm/freebsd|  2 +-
 tests/vm/netbsd |  2 +-
 tests/vm/openbsd|  2 +-
 ui/cocoa.m  |  2 +-
 ui/gtk.c|  2 +-
 ui/icons/meson.build| 32 --
 ui/sdl2.c   |  4 +--
 util/cutils.c   | 53 ++---
 20 files changed, 132 insertions(+), 123 deletions(-)

-- 
2.32.1 (Apple Git-133)




[PATCH v6 3/7] Remove prefixes from path configuration macros

2022-06-15 Thread Akihiko Odaki
The path configuration macros are often supplied to
get_relocated_path(), and the function had some logics to remove the
prefixes.

With this change, the prefixes are removed from those macros and
get_relocated_path() is also simplified.

Signed-off-by: Akihiko Odaki 
---
 include/qemu/cutils.h |  2 +-
 meson.build   | 21 ++---
 qemu-options.hx   | 11 +--
 util/cutils.c | 34 +++---
 4 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 40e10e19a7e..57de1da5c95 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -207,7 +207,7 @@ const char *qemu_get_exec_dir(void);
  *
  * Returns a path for @dir that uses the directory of the running executable
  * as the prefix.  For example, if `bindir` is `/usr/bin` and @dir is
- * `/usr/share/qemu`, the function will append `../share/qemu` to the
+ * `share/qemu`, the function will append `../share/qemu` to the
  * directory that contains the running executable and return the result.
  * The returned string should be freed by the caller.
  */
diff --git a/meson.build b/meson.build
index 0c2e11ff071..01d5e32615e 100644
--- a/meson.build
+++ b/meson.build
@@ -1679,18 +1679,17 @@ config_host_data.set_quoted('CONFIG_TLS_PRIORITY', 
get_option('tls_priority'))
 if iasl.found()
   config_host_data.set_quoted('CONFIG_IASL', iasl.full_path())
 endif
-config_host_data.set_quoted('CONFIG_BINDIR', get_option('prefix') / 
get_option('bindir'))
+config_host_data.set_quoted('CONFIG_BINDIR', get_option('bindir'))
 config_host_data.set_quoted('CONFIG_PREFIX', get_option('prefix'))
-config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', get_option('prefix') / 
qemu_confdir)
-config_host_data.set_quoted('CONFIG_QEMU_DATADIR', get_option('prefix') / 
qemu_datadir)
-config_host_data.set_quoted('CONFIG_QEMU_DESKTOPDIR', get_option('prefix') / 
qemu_desktopdir)
-config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', get_option('prefix') / 
get_option('qemu_firmwarepath'))
-config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('prefix') / 
get_option('libexecdir'))
-config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', get_option('prefix') / 
qemu_icondir)
-config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('prefix') / 
get_option('localedir'))
-config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', get_option('prefix') 
/ get_option('localstatedir'))
-config_host_data.set_quoted('CONFIG_QEMU_MODDIR', get_option('prefix') / 
qemu_moddir)
-config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('prefix') / 
get_option('sysconfdir'))
+config_host_data.set_quoted('CONFIG_QEMU_CONFDIR', qemu_confdir)
+config_host_data.set_quoted('CONFIG_QEMU_DATADIR', qemu_datadir)
+config_host_data.set_quoted('CONFIG_QEMU_FIRMWAREPATH', 
get_option('qemu_firmwarepath'))
+config_host_data.set_quoted('CONFIG_QEMU_HELPERDIR', get_option('libexecdir'))
+config_host_data.set_quoted('CONFIG_QEMU_ICONDIR', qemu_icondir)
+config_host_data.set_quoted('CONFIG_QEMU_LOCALEDIR', get_option('localedir'))
+config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', 
get_option('localstatedir'))
+config_host_data.set_quoted('CONFIG_QEMU_MODDIR', qemu_moddir)
+config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('sysconfdir'))
 
 if config_host.has_key('CONFIG_MODULES')
   config_host_data.set('CONFIG_STAMP', run_command(
diff --git a/qemu-options.hx b/qemu-options.hx
index 377d22fbd82..f0ae8f44ff2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2661,12 +2661,11 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
 " [,poll-us=n]\n"
 "configure a host TAP network backend with ID 'str'\n"
 "connected to a bridge (default=" DEFAULT_BRIDGE_INTERFACE 
")\n"
-"use network scripts 'file' (default=" 
DEFAULT_NETWORK_SCRIPT ")\n"
-"to configure it and 'dfile' (default=" 
DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
-"to deconfigure it\n"
+"use custom network script 'file' to configure it 
(optional)\n"
+"use custom network script 'dfile' to deconfigure it 
(optional)\n"
 "use '[down]script=no' to disable script execution\n"
-"use network helper 'helper' (default=" 
DEFAULT_BRIDGE_HELPER ") to\n"
-"configure it\n"
+"use custom network helper 'helper' to\n"
+"configure it (optional)\n"
 "use 'fd=h' to connect to an already opened TAP 
interface\n"
 "use 'fds=x:y:...:z' to connect to already opened 
multiqueue capable TAP interfaces\n"
 "use 'sndbuf=nbytes' to limit the size of the send buffer 
(the\n"
@@ -2684,7 +2683,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
 "-netdev bridge,id=str[,br=bridge][,helper=helper]\n"
 "configure a host TAP 

[PATCH v6 4/7] cutils: Introduce bundle mechanism

2022-06-15 Thread Akihiko Odaki
Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files located relative
to the installation tree. The build tree must have a new directory,
qemu-bundle, to represent what files the installation tree would
have for reference by the executables.

Signed-off-by: Akihiko Odaki 
---
 include/qemu/cutils.h | 19 +++
 meson.build   | 12 
 util/cutils.c | 23 +++
 3 files changed, 54 insertions(+)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 57de1da5c95..ca5bddb9e1c 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -213,6 +213,25 @@ const char *qemu_get_exec_dir(void);
  */
 char *get_relocated_path(const char *dir);
 
+/**
+ * find_bundle:
+ * @path: Relative path
+ *
+ * Returns a path for the specified directory or file bundled in QEMU. It uses
+ * the directory of the running executable as the prefix first. See
+ * get_relocated_path() for the details. The next candidate is "qemu-bundle"
+ * directory in the directory of the running executable. "qemu-bundle"
+ * directory is typically present in the build tree.
+ *
+ * The returned string should be freed by the caller.
+ *
+ * Returns: a path that can access the bundle, or NULL if no matching bundle
+ * exists.
+ */
+char *find_bundle(const char *path);
+
+void list_bundle_candidates(const char *path);
+
 static inline const char *yes_no(bool b)
 {
  return b ? "yes" : "no";
diff --git a/meson.build b/meson.build
index 01d5e32615e..ab5ab85bf4e 100644
--- a/meson.build
+++ b/meson.build
@@ -32,6 +32,7 @@ if get_option('qemu_suffix').startswith('/')
   error('qemu_suffix cannot start with a /')
 endif
 
+qemu_bundledir = meson.project_build_root() / 'qemu-bundle'
 qemu_confdir = get_option('sysconfdir') / get_option('qemu_suffix')
 qemu_datadir = get_option('datadir') / get_option('qemu_suffix')
 qemu_docdir = get_option('docdir') / get_option('qemu_suffix')
@@ -2843,6 +2844,8 @@ target_arch = {}
 target_softmmu_arch = {}
 target_user_arch = {}
 
+bundles = {}
+
 ###
 # Trace files #
 ###
@@ -3613,6 +3616,15 @@ if host_machine.system() == 'windows'
   alias_target('installer', nsis)
 endif
 
+###
+# Bundles #
+###
+
+foreach dst, src: bundles
+  run_command('mkdir', '-p', qemu_bundledir / fs.parent(dst), check: true)
+  run_command('ln', '-sf', src, qemu_bundledir / dst, check: true)
+endforeach
+
 #
 # Configuration summary #
 #
diff --git a/util/cutils.c b/util/cutils.c
index 983db97b4df..64cb1616b9c 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1066,3 +1066,26 @@ char *get_relocated_path(const char *dir)
 
 return g_string_free(result, false);
 }
+
+char *find_bundle(const char *path)
+{
+char *bundle = g_strdup_printf("%s/qemu-bundle/%s", qemu_get_exec_dir(), 
path);
+if (access(bundle, R_OK) == 0) {
+return bundle;
+}
+
+g_free(bundle);
+
+return get_relocated_path(path);
+}
+
+void list_bundle_candidates(const char *path)
+{
+const char *dir = qemu_get_exec_dir();
+int i;
+
+for (i = 0; i < ARRAY_SIZE(bundle_formats); i++) {
+printf(bundle_formats[i], dir, path);
+putc('\n', stdout);
+}
+}
-- 
2.32.1 (Apple Git-133)




[PULL 13/18] vfio-user: handle DMA mappings

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Define and register callbacks to manage the RAM regions used for
device DMA

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
faacbcd45c4d02c591f0dbfdc19041fbb3eae7eb.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 hw/remote/machine.c   |  5 
 hw/remote/vfio-user-obj.c | 55 +++
 hw/remote/trace-events|  2 ++
 3 files changed, 62 insertions(+)

diff --git a/hw/remote/machine.c b/hw/remote/machine.c
index cbb2add291..645b54343d 100644
--- a/hw/remote/machine.c
+++ b/hw/remote/machine.c
@@ -22,6 +22,7 @@
 #include "hw/remote/iohub.h"
 #include "hw/remote/iommu.h"
 #include "hw/qdev-core.h"
+#include "hw/remote/iommu.h"
 
 static void remote_machine_init(MachineState *machine)
 {
@@ -51,6 +52,10 @@ static void remote_machine_init(MachineState *machine)
 
 pci_host = PCI_HOST_BRIDGE(rem_host);
 
+if (s->vfio_user) {
+remote_iommu_setup(pci_host->bus);
+}
+
 remote_iohub_init(>iohub);
 
 pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index cef473cb98..7b21f77052 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -284,6 +284,54 @@ static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, 
char * const buf,
 return count;
 }
 
+static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
+{
+VfuObject *o = vfu_get_private(vfu_ctx);
+AddressSpace *dma_as = NULL;
+MemoryRegion *subregion = NULL;
+g_autofree char *name = NULL;
+struct iovec *iov = >iova;
+
+if (!info->vaddr) {
+return;
+}
+
+name = g_strdup_printf("mem-%s-%"PRIx64"", o->device,
+   (uint64_t)info->vaddr);
+
+subregion = g_new0(MemoryRegion, 1);
+
+memory_region_init_ram_ptr(subregion, NULL, name,
+   iov->iov_len, info->vaddr);
+
+dma_as = pci_device_iommu_address_space(o->pci_dev);
+
+memory_region_add_subregion(dma_as->root, (hwaddr)iov->iov_base, 
subregion);
+
+trace_vfu_dma_register((uint64_t)iov->iov_base, iov->iov_len);
+}
+
+static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
+{
+VfuObject *o = vfu_get_private(vfu_ctx);
+AddressSpace *dma_as = NULL;
+MemoryRegion *mr = NULL;
+ram_addr_t offset;
+
+mr = memory_region_from_host(info->vaddr, );
+if (!mr) {
+return;
+}
+
+dma_as = pci_device_iommu_address_space(o->pci_dev);
+
+memory_region_del_subregion(dma_as->root, mr);
+
+object_unparent((OBJECT(mr)));
+
+trace_vfu_dma_unregister((uint64_t)info->iova.iov_base);
+}
+
 /*
  * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
  * properties. It also depends on devices instantiated in QEMU. These
@@ -387,6 +435,13 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
 goto fail;
 }
 
+ret = vfu_setup_device_dma(o->vfu_ctx, _register, _unregister);
+if (ret < 0) {
+error_setg(errp, "vfu: Failed to setup DMA handlers for %s",
+   o->device);
+goto fail;
+}
+
 ret = vfu_realize_ctx(o->vfu_ctx);
 if (ret < 0) {
 error_setg(errp, "vfu: Failed to realize device %s- %s",
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
index 2ef7884346..f945c7e33b 100644
--- a/hw/remote/trace-events
+++ b/hw/remote/trace-events
@@ -7,3 +7,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to 
receive %d size %d,
 vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"
 vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x"
 vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x"
+vfu_dma_register(uint64_t gpa, size_t len) "vfu: registering GPA 0x%"PRIx64", 
%zu bytes"
+vfu_dma_unregister(uint64_t gpa) "vfu: unregistering GPA 0x%"PRIx64""
-- 
2.36.1




[PULL 16/18] vfio-user: handle reset of remote device

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Adds handler to reset a remote device

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
112eeadf3bc4c6cdb100bc3f9a6fcfc20b467c1b.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 hw/remote/vfio-user-obj.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 5ecdec06f6..c6cc53acf2 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -676,6 +676,20 @@ void vfu_object_set_bus_irq(PCIBus *pci_bus)
  max_bdf);
 }
 
+static int vfu_object_device_reset(vfu_ctx_t *vfu_ctx, vfu_reset_type_t type)
+{
+VfuObject *o = vfu_get_private(vfu_ctx);
+
+/* vfu_object_ctx_run() handles lost connection */
+if (type == VFU_RESET_LOST_CONN) {
+return 0;
+}
+
+qdev_reset_all(DEVICE(o->pci_dev));
+
+return 0;
+}
+
 /*
  * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
  * properties. It also depends on devices instantiated in QEMU. These
@@ -795,6 +809,12 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
 goto fail;
 }
 
+ret = vfu_setup_device_reset_cb(o->vfu_ctx, _object_device_reset);
+if (ret < 0) {
+error_setg(errp, "vfu: Failed to setup reset callback");
+goto fail;
+}
+
 ret = vfu_realize_ctx(o->vfu_ctx);
 if (ret < 0) {
 error_setg(errp, "vfu: Failed to realize device %s- %s",
-- 
2.36.1




[PATCH v6 1/7] datadir: Simplify firmware directory search

2022-06-15 Thread Akihiko Odaki
The old implementation had some code to accept multiple firmware
directories, but it is not used.

Signed-off-by: Akihiko Odaki 
---
 softmmu/datadir.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/softmmu/datadir.c b/softmmu/datadir.c
index 160cac999a6..2a206f2740a 100644
--- a/softmmu/datadir.c
+++ b/softmmu/datadir.c
@@ -105,15 +105,8 @@ static char *find_datadir(void)
 
 void qemu_add_default_firmwarepath(void)
 {
-char **dirs;
-size_t i;
-
-/* add configured firmware directories */
-dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0);
-for (i = 0; dirs[i] != NULL; i++) {
-qemu_add_data_dir(get_relocated_path(dirs[i]));
-}
-g_strfreev(dirs);
+/* add the configured firmware directory */
+qemu_add_data_dir(get_relocated_path(CONFIG_QEMU_FIRMWAREPATH));
 
 /* try to find datadir relative to the executable path */
 qemu_add_data_dir(find_datadir());
-- 
2.32.1 (Apple Git-133)




[PULL 17/18] linux-aio: fix unbalanced plugged counter in laio_io_unplug()

2022-06-15 Thread Stefan Hajnoczi
Every laio_io_plug() call has a matching laio_io_unplug() call. There is
a plugged counter that tracks the number of levels of plugging and
allows for nesting.

The plugged counter must reflect the balance between laio_io_plug() and
laio_io_unplug() calls accurately. Otherwise I/O stalls occur since
io_submit(2) calls are skipped while plugged.

Reported-by: Nikolay Tenev 
Signed-off-by: Stefan Hajnoczi 
Reviewed-by: Stefano Garzarella 
Message-id: 20220609164712.1539045-2-stefa...@redhat.com
Cc: Stefano Garzarella 
Fixes: 68d7946648 ("linux-aio: add `dev_max_batch` parameter to 
laio_io_unplug()")
[Stefano Garzarella suggested adding a Fixes tag.
--Stefan]
Signed-off-by: Stefan Hajnoczi 
---
 block/linux-aio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/linux-aio.c b/block/linux-aio.c
index 4c423fcccf..6078da7e42 100644
--- a/block/linux-aio.c
+++ b/block/linux-aio.c
@@ -363,8 +363,10 @@ void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s,
 uint64_t dev_max_batch)
 {
 assert(s->io_q.plugged);
+s->io_q.plugged--;
+
 if (s->io_q.in_queue >= laio_max_batch(s, dev_max_batch) ||
-(--s->io_q.plugged == 0 &&
+(!s->io_q.plugged &&
  !s->io_q.blocked && !QSIMPLEQ_EMPTY(>io_q.pending))) {
 ioq_submit(s);
 }
-- 
2.36.1




[PULL 11/18] vfio-user: handle PCI config space accesses

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Define and register handlers for PCI config space accesses

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
be9d2ccf9b1d24e50dcd9c23404dbf284142cec7.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 hw/remote/vfio-user-obj.c | 51 +++
 hw/remote/trace-events|  2 ++
 2 files changed, 53 insertions(+)

diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 178bd6f8ed..cef473cb98 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -46,6 +46,7 @@
 #include "qapi/qapi-events-misc.h"
 #include "qemu/notify.h"
 #include "qemu/thread.h"
+#include "qemu/main-loop.h"
 #include "sysemu/sysemu.h"
 #include "libvfio-user.h"
 #include "hw/qdev-core.h"
@@ -244,6 +245,45 @@ retry_attach:
 qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o);
 }
 
+static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf,
+ size_t count, loff_t offset,
+ const bool is_write)
+{
+VfuObject *o = vfu_get_private(vfu_ctx);
+uint32_t pci_access_width = sizeof(uint32_t);
+size_t bytes = count;
+uint32_t val = 0;
+char *ptr = buf;
+int len;
+
+/*
+ * Writes to the BAR registers would trigger an update to the
+ * global Memory and IO AddressSpaces. But the remote device
+ * never uses the global AddressSpaces, therefore overlapping
+ * memory regions are not a problem
+ */
+while (bytes > 0) {
+len = (bytes > pci_access_width) ? pci_access_width : bytes;
+if (is_write) {
+memcpy(, ptr, len);
+pci_host_config_write_common(o->pci_dev, offset,
+ pci_config_size(o->pci_dev),
+ val, len);
+trace_vfu_cfg_write(offset, val);
+} else {
+val = pci_host_config_read_common(o->pci_dev, offset,
+  pci_config_size(o->pci_dev), 
len);
+memcpy(ptr, , len);
+trace_vfu_cfg_read(offset, val);
+}
+offset += len;
+ptr += len;
+bytes -= len;
+}
+
+return count;
+}
+
 /*
  * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
  * properties. It also depends on devices instantiated in QEMU. These
@@ -336,6 +376,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
TYPE_VFU_OBJECT, o->device);
 qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
 
+ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX,
+   pci_config_size(o->pci_dev), _object_cfg_access,
+   VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB,
+   NULL, 0, -1, 0);
+if (ret < 0) {
+error_setg(errp,
+   "vfu: Failed to setup config space handlers for %s- %s",
+   o->device, strerror(errno));
+goto fail;
+}
+
 ret = vfu_realize_ctx(o->vfu_ctx);
 if (ret < 0) {
 error_setg(errp, "vfu: Failed to realize device %s- %s",
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
index 7da12f0d96..2ef7884346 100644
--- a/hw/remote/trace-events
+++ b/hw/remote/trace-events
@@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to 
receive %d size %d,
 
 # vfio-user-obj.c
 vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"
+vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x"
+vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x"
-- 
2.36.1




[PULL 14/18] vfio-user: handle PCI BAR accesses

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Determine the BARs used by the PCI device and register handlers to
manage the access to the same.

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
3373e10b5be5f42846f0632d4382466e1698c505.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 include/exec/memory.h   |   3 +
 hw/remote/vfio-user-obj.c   | 190 
 softmmu/physmem.c   |   4 +-
 tests/qtest/fuzz/generic_fuzz.c |   9 +-
 hw/remote/trace-events  |   3 +
 5 files changed, 203 insertions(+), 6 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index f1c19451bc..a6a0f4d8ad 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2810,6 +2810,9 @@ MemTxResult 
address_space_write_cached_slow(MemoryRegionCache *cache,
 hwaddr addr, const void *buf,
 hwaddr len);
 
+int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr);
+bool prepare_mmio_access(MemoryRegion *mr);
+
 static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
 {
 if (is_write) {
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 7b21f77052..dd760a99e2 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -52,6 +52,7 @@
 #include "hw/qdev-core.h"
 #include "hw/pci/pci.h"
 #include "qemu/timer.h"
+#include "exec/memory.h"
 
 #define TYPE_VFU_OBJECT "x-vfio-user-server"
 OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
@@ -332,6 +333,193 @@ static void dma_unregister(vfu_ctx_t *vfu_ctx, 
vfu_dma_info_t *info)
 trace_vfu_dma_unregister((uint64_t)info->iova.iov_base);
 }
 
+static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset,
+hwaddr size, const bool is_write)
+{
+uint8_t *ptr = buf;
+bool release_lock = false;
+uint8_t *ram_ptr = NULL;
+MemTxResult result;
+int access_size;
+uint64_t val;
+
+if (memory_access_is_direct(mr, is_write)) {
+/**
+ * Some devices expose a PCI expansion ROM, which could be buffer
+ * based as compared to other regions which are primarily based on
+ * MemoryRegionOps. memory_region_find() would already check
+ * for buffer overflow, we don't need to repeat it here.
+ */
+ram_ptr = memory_region_get_ram_ptr(mr);
+
+if (is_write) {
+memcpy((ram_ptr + offset), buf, size);
+} else {
+memcpy(buf, (ram_ptr + offset), size);
+}
+
+return 0;
+}
+
+while (size) {
+/**
+ * The read/write logic used below is similar to the ones in
+ * flatview_read/write_continue()
+ */
+release_lock = prepare_mmio_access(mr);
+
+access_size = memory_access_size(mr, size, offset);
+
+if (is_write) {
+val = ldn_he_p(ptr, access_size);
+
+result = memory_region_dispatch_write(mr, offset, val,
+  size_memop(access_size),
+  MEMTXATTRS_UNSPECIFIED);
+} else {
+result = memory_region_dispatch_read(mr, offset, ,
+ size_memop(access_size),
+ MEMTXATTRS_UNSPECIFIED);
+
+stn_he_p(ptr, access_size, val);
+}
+
+if (release_lock) {
+qemu_mutex_unlock_iothread();
+release_lock = false;
+}
+
+if (result != MEMTX_OK) {
+return -1;
+}
+
+size -= access_size;
+ptr += access_size;
+offset += access_size;
+}
+
+return 0;
+}
+
+static size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar,
+hwaddr bar_offset, char * const buf,
+hwaddr len, const bool is_write)
+{
+MemoryRegionSection section = { 0 };
+uint8_t *ptr = (uint8_t *)buf;
+MemoryRegion *section_mr = NULL;
+uint64_t section_size;
+hwaddr section_offset;
+hwaddr size = 0;
+
+while (len) {
+section = memory_region_find(pci_dev->io_regions[pci_bar].memory,
+ bar_offset, len);
+
+if (!section.mr) {
+warn_report("vfu: invalid address 0x%"PRIx64"", bar_offset);
+return size;
+}
+
+section_mr = section.mr;
+section_offset = section.offset_within_region;
+section_size = int128_get64(section.size);
+
+if (is_write && section_mr->readonly) {
+warn_report("vfu: attempting to write to readonly region in "
+"bar %d - [0x%"PRIx64" - 0x%"PRIx64"]",
+pci_bar, bar_offset,
+

[PULL 12/18] vfio-user: IOMMU support for remote device

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Assign separate address space for each device in the remote processes.

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
afe0b0a97582cdad42b5b25636a29c523265a10a.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 MAINTAINERS   |   2 +
 include/hw/remote/iommu.h |  40 
 hw/remote/iommu.c | 131 ++
 hw/remote/machine.c   |  13 +++-
 hw/remote/meson.build |   1 +
 5 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/remote/iommu.h
 create mode 100644 hw/remote/iommu.c

diff --git a/MAINTAINERS b/MAINTAINERS
index cbac72e239..563259101b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3644,6 +3644,8 @@ F: hw/remote/iohub.c
 F: include/hw/remote/iohub.h
 F: subprojects/libvfio-user
 F: hw/remote/vfio-user-obj.c
+F: hw/remote/iommu.c
+F: include/hw/remote/iommu.h
 
 EBPF:
 M: Jason Wang 
diff --git a/include/hw/remote/iommu.h b/include/hw/remote/iommu.h
new file mode 100644
index 00..33b68a8f4b
--- /dev/null
+++ b/include/hw/remote/iommu.h
@@ -0,0 +1,40 @@
+/**
+ * Copyright © 2022 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef REMOTE_IOMMU_H
+#define REMOTE_IOMMU_H
+
+#include "hw/pci/pci_bus.h"
+#include "hw/pci/pci.h"
+
+#ifndef INT2VOIDP
+#define INT2VOIDP(i) (void *)(uintptr_t)(i)
+#endif
+
+typedef struct RemoteIommuElem {
+MemoryRegion *mr;
+
+AddressSpace as;
+} RemoteIommuElem;
+
+#define TYPE_REMOTE_IOMMU "x-remote-iommu"
+OBJECT_DECLARE_SIMPLE_TYPE(RemoteIommu, REMOTE_IOMMU)
+
+struct RemoteIommu {
+Object parent;
+
+GHashTable *elem_by_devfn;
+
+QemuMutex lock;
+};
+
+void remote_iommu_setup(PCIBus *pci_bus);
+
+void remote_iommu_unplug_dev(PCIDevice *pci_dev);
+
+#endif
diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c
new file mode 100644
index 00..fd723d91f3
--- /dev/null
+++ b/hw/remote/iommu.c
@@ -0,0 +1,131 @@
+/**
+ * IOMMU for remote device
+ *
+ * Copyright © 2022 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "hw/remote/iommu.h"
+#include "hw/pci/pci_bus.h"
+#include "hw/pci/pci.h"
+#include "exec/memory.h"
+#include "exec/address-spaces.h"
+#include "trace.h"
+
+/**
+ * IOMMU for TYPE_REMOTE_MACHINE - manages DMA address space isolation
+ * for remote machine. It is used by TYPE_VFIO_USER_SERVER.
+ *
+ * - Each TYPE_VFIO_USER_SERVER instance handles one PCIDevice on a PCIBus.
+ *   There is one RemoteIommu per PCIBus, so the RemoteIommu tracks multiple
+ *   PCIDevices by maintaining a ->elem_by_devfn mapping.
+ *
+ * - memory_region_init_iommu() is not used because vfio-user MemoryRegions
+ *   will be added to the elem->mr container instead. This is more natural
+ *   than implementing the IOMMUMemoryRegionClass APIs since vfio-user
+ *   provides something that is close to a full-fledged MemoryRegion and
+ *   not like an IOMMU mapping.
+ *
+ * - When a device is hot unplugged, the elem->mr reference is dropped so
+ *   all vfio-user MemoryRegions associated with this vfio-user server are
+ *   destroyed.
+ */
+
+static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus,
+  void *opaque, int devfn)
+{
+RemoteIommu *iommu = opaque;
+RemoteIommuElem *elem = NULL;
+
+qemu_mutex_lock(>lock);
+
+elem = g_hash_table_lookup(iommu->elem_by_devfn, INT2VOIDP(devfn));
+
+if (!elem) {
+elem = g_malloc0(sizeof(RemoteIommuElem));
+g_hash_table_insert(iommu->elem_by_devfn, INT2VOIDP(devfn), elem);
+}
+
+if (!elem->mr) {
+elem->mr = MEMORY_REGION(object_new(TYPE_MEMORY_REGION));
+memory_region_set_size(elem->mr, UINT64_MAX);
+address_space_init(>as, elem->mr, NULL);
+}
+
+qemu_mutex_unlock(>lock);
+
+return >as;
+}
+
+void remote_iommu_unplug_dev(PCIDevice *pci_dev)
+{
+AddressSpace *as = pci_device_iommu_address_space(pci_dev);
+RemoteIommuElem *elem = NULL;
+
+if (as == _space_memory) {
+return;
+}
+
+elem = container_of(as, RemoteIommuElem, as);
+
+address_space_destroy(>as);
+
+object_unref(elem->mr);
+
+elem->mr = NULL;
+}
+
+static void remote_iommu_init(Object *obj)
+{
+RemoteIommu *iommu = REMOTE_IOMMU(obj);
+
+iommu->elem_by_devfn = g_hash_table_new_full(NULL, NULL, NULL, g_free);
+
+qemu_mutex_init(>lock);
+}
+
+static void remote_iommu_finalize(Object *obj)
+{
+RemoteIommu *iommu = REMOTE_IOMMU(obj);
+
+qemu_mutex_destroy(>lock);
+
+g_hash_table_destroy(iommu->elem_by_devfn);
+
+iommu->elem_by_devfn = NULL;
+}
+
+void 

[PULL 07/18] vfio-user: define vfio-user-server object

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Define vfio-user object which is remote process server for QEMU. Setup
object initialization functions and properties necessary to instantiate
the object

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
e45a17001e9b38f451543a664ababdf860e5f2f2.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 MAINTAINERS |   1 +
 qapi/qom.json   |  20 +++-
 include/hw/remote/machine.h |   2 +
 hw/remote/machine.c |  27 +
 hw/remote/vfio-user-obj.c   | 210 
 hw/remote/meson.build   |   1 +
 hw/remote/trace-events  |   3 +
 7 files changed, 262 insertions(+), 2 deletions(-)
 create mode 100644 hw/remote/vfio-user-obj.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d0fcaf0edb..cbac72e239 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3643,6 +3643,7 @@ F: include/hw/remote/proxy-memory-listener.h
 F: hw/remote/iohub.c
 F: include/hw/remote/iohub.h
 F: subprojects/libvfio-user
+F: hw/remote/vfio-user-obj.c
 
 EBPF:
 M: Jason Wang 
diff --git a/qapi/qom.json b/qapi/qom.json
index 6a653c6636..80dd419b39 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -734,6 +734,20 @@
 { 'struct': 'RemoteObjectProperties',
   'data': { 'fd': 'str', 'devid': 'str' } }
 
+##
+# @VfioUserServerProperties:
+#
+# Properties for x-vfio-user-server objects.
+#
+# @socket: socket to be used by the libvfio-user library
+#
+# @device: the ID of the device to be emulated at the server
+#
+# Since: 7.1
+##
+{ 'struct': 'VfioUserServerProperties',
+  'data': { 'socket': 'SocketAddress', 'device': 'str' } }
+
 ##
 # @RngProperties:
 #
@@ -874,7 +888,8 @@
 'tls-creds-psk',
 'tls-creds-x509',
 'tls-cipher-suites',
-{ 'name': 'x-remote-object', 'features': [ 'unstable' ] }
+{ 'name': 'x-remote-object', 'features': [ 'unstable' ] },
+{ 'name': 'x-vfio-user-server', 'features': [ 'unstable' ] }
   ] }
 
 ##
@@ -938,7 +953,8 @@
   'tls-creds-psk':  'TlsCredsPskProperties',
   'tls-creds-x509': 'TlsCredsX509Properties',
   'tls-cipher-suites':  'TlsCredsProperties',
-  'x-remote-object':'RemoteObjectProperties'
+  'x-remote-object':'RemoteObjectProperties',
+  'x-vfio-user-server': 'VfioUserServerProperties'
   } }
 
 ##
diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h
index 8d0fa98d33..ac32fda387 100644
--- a/include/hw/remote/machine.h
+++ b/include/hw/remote/machine.h
@@ -24,6 +24,8 @@ struct RemoteMachineState {
 RemoteIOHubState iohub;
 
 bool vfio_user;
+
+bool auto_shutdown;
 };
 
 /* Used to pass to co-routine device and ioc. */
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
index 9f3cdc55c3..4d008ed721 100644
--- a/hw/remote/machine.c
+++ b/hw/remote/machine.c
@@ -77,6 +77,28 @@ static void remote_machine_set_vfio_user(Object *obj, bool 
value, Error **errp)
 s->vfio_user = value;
 }
 
+static bool remote_machine_get_auto_shutdown(Object *obj, Error **errp)
+{
+RemoteMachineState *s = REMOTE_MACHINE(obj);
+
+return s->auto_shutdown;
+}
+
+static void remote_machine_set_auto_shutdown(Object *obj, bool value,
+ Error **errp)
+{
+RemoteMachineState *s = REMOTE_MACHINE(obj);
+
+s->auto_shutdown = value;
+}
+
+static void remote_machine_instance_init(Object *obj)
+{
+RemoteMachineState *s = REMOTE_MACHINE(obj);
+
+s->auto_shutdown = true;
+}
+
 static void remote_machine_class_init(ObjectClass *oc, void *data)
 {
 MachineClass *mc = MACHINE_CLASS(oc);
@@ -90,12 +112,17 @@ static void remote_machine_class_init(ObjectClass *oc, 
void *data)
 object_class_property_add_bool(oc, "vfio-user",
remote_machine_get_vfio_user,
remote_machine_set_vfio_user);
+
+object_class_property_add_bool(oc, "auto-shutdown",
+   remote_machine_get_auto_shutdown,
+   remote_machine_set_auto_shutdown);
 }
 
 static const TypeInfo remote_machine = {
 .name = TYPE_REMOTE_MACHINE,
 .parent = TYPE_MACHINE,
 .instance_size = sizeof(RemoteMachineState),
+.instance_init = remote_machine_instance_init,
 .class_init = remote_machine_class_init,
 .interfaces = (InterfaceInfo[]) {
 { TYPE_HOTPLUG_HANDLER },
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
new file mode 100644
index 00..bc49adcc27
--- /dev/null
+++ b/hw/remote/vfio-user-obj.c
@@ -0,0 +1,210 @@
+/**
+ * QEMU vfio-user-server server object
+ *
+ * Copyright © 2022 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL-v2, version 2 or later.
+ *
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+/**
+ * Usage: add options:
+ * -machine 

[PULL 02/18] Use io_uring_register_ring_fd() to skip fd operations

2022-06-15 Thread Stefan Hajnoczi
From: Sam Li 

Linux recently added a new io_uring(7) optimization API that QEMU
doesn't take advantage of yet. The liburing library that QEMU uses
has added a corresponding new API calling io_uring_register_ring_fd().
When this API is called after creating the ring, the io_uring_submit()
library function passes a flag to the io_uring_enter(2) syscall
allowing it to skip the ring file descriptor fdget()/fdput()
operations. This saves some CPU cycles.

Signed-off-by: Sam Li 
Message-id: 20220531105011.111082-1-faithilike...@gmail.com
Signed-off-by: Stefan Hajnoczi 
---
 meson.build  |  1 +
 block/io_uring.c | 12 +++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 0c2e11ff07..9e65cc5367 100644
--- a/meson.build
+++ b/meson.build
@@ -1752,6 +1752,7 @@ config_host_data.set('CONFIG_LIBNFS', libnfs.found())
 config_host_data.set('CONFIG_LIBSSH', libssh.found())
 config_host_data.set('CONFIG_LINUX_AIO', libaio.found())
 config_host_data.set('CONFIG_LINUX_IO_URING', linux_io_uring.found())
+config_host_data.set('CONFIG_LIBURING_REGISTER_RING_FD', 
cc.has_function('io_uring_register_ring_fd', prefix: '#include ', 
dependencies:linux_io_uring))
 config_host_data.set('CONFIG_LIBPMEM', libpmem.found())
 config_host_data.set('CONFIG_NUMA', numa.found())
 config_host_data.set('CONFIG_OPENGL', opengl.found())
diff --git a/block/io_uring.c b/block/io_uring.c
index 0b401512b9..d48e472e74 100644
--- a/block/io_uring.c
+++ b/block/io_uring.c
@@ -18,6 +18,7 @@
 #include "qapi/error.h"
 #include "trace.h"
 
+
 /* io_uring ring size */
 #define MAX_ENTRIES 128
 
@@ -434,8 +435,17 @@ LuringState *luring_init(Error **errp)
 }
 
 ioq_init(>io_q);
+#ifdef CONFIG_LIBURING_REGISTER_RING_FD
+if (io_uring_register_ring_fd(>ring) < 0) {
+/*
+ * Only warn about this error: we will fallback to the non-optimized
+ * io_uring operations.
+ */
+warn_report("failed to register linux io_uring ring file descriptor");
+}
+#endif
+
 return s;
-
 }
 
 void luring_cleanup(LuringState *s)
-- 
2.36.1




[PULL 10/18] vfio-user: run vfio-user context

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Setup a handler to run vfio-user context. The context is driven by
messages to the file descriptor associated with it - get the fd for
the context and hook up the handler with it

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
e934b0090529d448b6a7972b21dfc3d7421ce494.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 qapi/misc.json|  31 ++
 hw/remote/vfio-user-obj.c | 118 +-
 2 files changed, 148 insertions(+), 1 deletion(-)

diff --git a/qapi/misc.json b/qapi/misc.json
index 45344483cd..27ef5a2b20 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -553,3 +553,34 @@
 ##
 { 'event': 'RTC_CHANGE',
   'data': { 'offset': 'int', 'qom-path': 'str' } }
+
+##
+# @VFU_CLIENT_HANGUP:
+#
+# Emitted when the client of a TYPE_VFIO_USER_SERVER closes the
+# communication channel
+#
+# @vfu-id: ID of the TYPE_VFIO_USER_SERVER object. It is the last component
+#  of @vfu-qom-path referenced below
+#
+# @vfu-qom-path: path to the TYPE_VFIO_USER_SERVER object in the QOM tree
+#
+# @dev-id: ID of attached PCI device
+#
+# @dev-qom-path: path to attached PCI device in the QOM tree
+#
+# Since: 7.1
+#
+# Example:
+#
+# <- { "event": "VFU_CLIENT_HANGUP",
+#  "data": { "vfu-id": "vfu1",
+#"vfu-qom-path": "/objects/vfu1",
+#"dev-id": "sas1",
+#"dev-qom-path": "/machine/peripheral/sas1" },
+#  "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
+#
+##
+{ 'event': 'VFU_CLIENT_HANGUP',
+  'data': { 'vfu-id': 'str', 'vfu-qom-path': 'str',
+'dev-id': 'str', 'dev-qom-path': 'str' } }
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 3ca6aa2b45..178bd6f8ed 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -27,6 +27,9 @@
  *
  * device - id of a device on the server, a required option. PCI devices
  *  alone are supported presently.
+ *
+ * notes - x-vfio-user-server could block IO and monitor during the
+ * initialization phase.
  */
 
 #include "qemu/osdep.h"
@@ -40,11 +43,14 @@
 #include "hw/remote/machine.h"
 #include "qapi/error.h"
 #include "qapi/qapi-visit-sockets.h"
+#include "qapi/qapi-events-misc.h"
 #include "qemu/notify.h"
+#include "qemu/thread.h"
 #include "sysemu/sysemu.h"
 #include "libvfio-user.h"
 #include "hw/qdev-core.h"
 #include "hw/pci/pci.h"
+#include "qemu/timer.h"
 
 #define TYPE_VFU_OBJECT "x-vfio-user-server"
 OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
@@ -86,6 +92,8 @@ struct VfuObject {
 PCIDevice *pci_dev;
 
 Error *unplug_blocker;
+
+int vfu_poll_fd;
 };
 
 static void vfu_object_init_ctx(VfuObject *o, Error **errp);
@@ -164,6 +172,78 @@ static void vfu_object_set_device(Object *obj, const char 
*str, Error **errp)
 vfu_object_init_ctx(o, errp);
 }
 
+static void vfu_object_ctx_run(void *opaque)
+{
+VfuObject *o = opaque;
+const char *vfu_id;
+char *vfu_path, *pci_dev_path;
+int ret = -1;
+
+while (ret != 0) {
+ret = vfu_run_ctx(o->vfu_ctx);
+if (ret < 0) {
+if (errno == EINTR) {
+continue;
+} else if (errno == ENOTCONN) {
+vfu_id = object_get_canonical_path_component(OBJECT(o));
+vfu_path = object_get_canonical_path(OBJECT(o));
+g_assert(o->pci_dev);
+pci_dev_path = object_get_canonical_path(OBJECT(o->pci_dev));
+ /* o->device is a required property and is non-NULL here */
+g_assert(o->device);
+qapi_event_send_vfu_client_hangup(vfu_id, vfu_path,
+  o->device, pci_dev_path);
+qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL);
+o->vfu_poll_fd = -1;
+object_unparent(OBJECT(o));
+g_free(vfu_path);
+g_free(pci_dev_path);
+break;
+} else {
+VFU_OBJECT_ERROR(o, "vfu: Failed to run device %s - %s",
+ o->device, strerror(errno));
+break;
+}
+}
+}
+}
+
+static void vfu_object_attach_ctx(void *opaque)
+{
+VfuObject *o = opaque;
+GPollFD pfds[1];
+int ret;
+
+qemu_set_fd_handler(o->vfu_poll_fd, NULL, NULL, NULL);
+
+pfds[0].fd = o->vfu_poll_fd;
+pfds[0].events = G_IO_IN | G_IO_HUP | G_IO_ERR;
+
+retry_attach:
+ret = vfu_attach_ctx(o->vfu_ctx);
+if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
+/**
+ * vfu_object_attach_ctx can block QEMU's main loop
+ * during attach - the monitor and other IO
+ * could be unresponsive during this time.
+ */
+(void)qemu_poll_ns(pfds, 1, 500 * (int64_t)SCALE_MS);
+goto retry_attach;

[PULL 05/18] remote/machine: add vfio-user property

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Add vfio-user to x-remote machine. It is a boolean, which indicates if
the machine supports vfio-user protocol. The machine configures the bus
differently vfio-user and multiprocess protocols, so this property
informs it on how to configure the bus.

This property should be short lived. Once vfio-user fully replaces
multiprocess, this property could be removed.

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
5d51a152a419cbda35d070b8e49b772b60a7230a.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 include/hw/remote/machine.h |  2 ++
 hw/remote/machine.c | 23 +++
 2 files changed, 25 insertions(+)

diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h
index 2a2a33c4b2..8d0fa98d33 100644
--- a/include/hw/remote/machine.h
+++ b/include/hw/remote/machine.h
@@ -22,6 +22,8 @@ struct RemoteMachineState {
 
 RemotePCIHost *host;
 RemoteIOHubState iohub;
+
+bool vfio_user;
 };
 
 /* Used to pass to co-routine device and ioc. */
diff --git a/hw/remote/machine.c b/hw/remote/machine.c
index a97e53e250..9f3cdc55c3 100644
--- a/hw/remote/machine.c
+++ b/hw/remote/machine.c
@@ -58,6 +58,25 @@ static void remote_machine_init(MachineState *machine)
 qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s));
 }
 
+static bool remote_machine_get_vfio_user(Object *obj, Error **errp)
+{
+RemoteMachineState *s = REMOTE_MACHINE(obj);
+
+return s->vfio_user;
+}
+
+static void remote_machine_set_vfio_user(Object *obj, bool value, Error **errp)
+{
+RemoteMachineState *s = REMOTE_MACHINE(obj);
+
+if (phase_check(PHASE_MACHINE_CREATED)) {
+error_setg(errp, "Error enabling vfio-user - machine already created");
+return;
+}
+
+s->vfio_user = value;
+}
+
 static void remote_machine_class_init(ObjectClass *oc, void *data)
 {
 MachineClass *mc = MACHINE_CLASS(oc);
@@ -67,6 +86,10 @@ static void remote_machine_class_init(ObjectClass *oc, void 
*data)
 mc->desc = "Experimental remote machine";
 
 hc->unplug = qdev_simple_device_unplug_cb;
+
+object_class_property_add_bool(oc, "vfio-user",
+   remote_machine_get_vfio_user,
+   remote_machine_set_vfio_user);
 }
 
 static const TypeInfo remote_machine = {
-- 
2.36.1




[PULL 09/18] vfio-user: find and init PCI device

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Find the PCI device with specified id. Initialize the device context
with the QEMU PCI device

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
7798dbd730099b33fdd00c4c202cfe79e5c5c151.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 hw/remote/vfio-user-obj.c | 67 +++
 1 file changed, 67 insertions(+)

diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 68f8a9dfa9..3ca6aa2b45 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -43,6 +43,8 @@
 #include "qemu/notify.h"
 #include "sysemu/sysemu.h"
 #include "libvfio-user.h"
+#include "hw/qdev-core.h"
+#include "hw/pci/pci.h"
 
 #define TYPE_VFU_OBJECT "x-vfio-user-server"
 OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
@@ -80,6 +82,10 @@ struct VfuObject {
 Notifier machine_done;
 
 vfu_ctx_t *vfu_ctx;
+
+PCIDevice *pci_dev;
+
+Error *unplug_blocker;
 };
 
 static void vfu_object_init_ctx(VfuObject *o, Error **errp);
@@ -181,6 +187,9 @@ static void vfu_object_machine_done(Notifier *notifier, 
void *data)
 static void vfu_object_init_ctx(VfuObject *o, Error **errp)
 {
 ERRP_GUARD();
+DeviceState *dev = NULL;
+vfu_pci_type_t pci_type = VFU_PCI_TYPE_CONVENTIONAL;
+int ret;
 
 if (o->vfu_ctx || !o->socket || !o->device ||
 !phase_check(PHASE_MACHINE_READY)) {
@@ -199,6 +208,53 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
 error_setg(errp, "vfu: Failed to create context - %s", 
strerror(errno));
 return;
 }
+
+dev = qdev_find_recursive(sysbus_get_default(), o->device);
+if (dev == NULL) {
+error_setg(errp, "vfu: Device %s not found", o->device);
+goto fail;
+}
+
+if (!object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+error_setg(errp, "vfu: %s not a PCI device", o->device);
+goto fail;
+}
+
+o->pci_dev = PCI_DEVICE(dev);
+
+object_ref(OBJECT(o->pci_dev));
+
+if (pci_is_express(o->pci_dev)) {
+pci_type = VFU_PCI_TYPE_EXPRESS;
+}
+
+ret = vfu_pci_init(o->vfu_ctx, pci_type, PCI_HEADER_TYPE_NORMAL, 0);
+if (ret < 0) {
+error_setg(errp,
+   "vfu: Failed to attach PCI device %s to context - %s",
+   o->device, strerror(errno));
+goto fail;
+}
+
+error_setg(>unplug_blocker,
+   "vfu: %s for %s must be deleted before unplugging",
+   TYPE_VFU_OBJECT, o->device);
+qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
+
+return;
+
+fail:
+vfu_destroy_ctx(o->vfu_ctx);
+if (o->unplug_blocker && o->pci_dev) {
+qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
+error_free(o->unplug_blocker);
+o->unplug_blocker = NULL;
+}
+if (o->pci_dev) {
+object_unref(OBJECT(o->pci_dev));
+o->pci_dev = NULL;
+}
+o->vfu_ctx = NULL;
 }
 
 static void vfu_object_init(Object *obj)
@@ -241,6 +297,17 @@ static void vfu_object_finalize(Object *obj)
 
 o->device = NULL;
 
+if (o->unplug_blocker && o->pci_dev) {
+qdev_del_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
+error_free(o->unplug_blocker);
+o->unplug_blocker = NULL;
+}
+
+if (o->pci_dev) {
+object_unref(OBJECT(o->pci_dev));
+o->pci_dev = NULL;
+}
+
 if (!k->nr_devs && vfu_object_auto_shutdown()) {
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
 }
-- 
2.36.1




[PULL 04/18] remote/machine: add HotplugHandler for remote machine

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Allow hotplugging of PCI(e) devices to remote machine

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
d1e6cfa0afb528ad343758f9b1d918be0175c5e5.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 hw/remote/machine.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/hw/remote/machine.c b/hw/remote/machine.c
index 92d71d47bb..a97e53e250 100644
--- a/hw/remote/machine.c
+++ b/hw/remote/machine.c
@@ -20,6 +20,7 @@
 #include "qapi/error.h"
 #include "hw/pci/pci_host.h"
 #include "hw/remote/iohub.h"
+#include "hw/qdev-core.h"
 
 static void remote_machine_init(MachineState *machine)
 {
@@ -53,14 +54,19 @@ static void remote_machine_init(MachineState *machine)
 
 pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
  >iohub, REMOTE_IOHUB_NB_PIRQS);
+
+qbus_set_hotplug_handler(BUS(pci_host->bus), OBJECT(s));
 }
 
 static void remote_machine_class_init(ObjectClass *oc, void *data)
 {
 MachineClass *mc = MACHINE_CLASS(oc);
+HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
 
 mc->init = remote_machine_init;
 mc->desc = "Experimental remote machine";
+
+hc->unplug = qdev_simple_device_unplug_cb;
 }
 
 static const TypeInfo remote_machine = {
@@ -68,6 +74,10 @@ static const TypeInfo remote_machine = {
 .parent = TYPE_MACHINE,
 .instance_size = sizeof(RemoteMachineState),
 .class_init = remote_machine_class_init,
+.interfaces = (InterfaceInfo[]) {
+{ TYPE_HOTPLUG_HANDLER },
+{ }
+}
 };
 
 static void remote_machine_register_types(void)
-- 
2.36.1




[PULL 08/18] vfio-user: instantiate vfio-user context

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

create a context with the vfio-user library to run a PCI device

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
a452871ac8c812ff96fc4f0ce6037f4769953fab.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 hw/remote/vfio-user-obj.c | 82 +++
 1 file changed, 82 insertions(+)

diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index bc49adcc27..68f8a9dfa9 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -40,6 +40,9 @@
 #include "hw/remote/machine.h"
 #include "qapi/error.h"
 #include "qapi/qapi-visit-sockets.h"
+#include "qemu/notify.h"
+#include "sysemu/sysemu.h"
+#include "libvfio-user.h"
 
 #define TYPE_VFU_OBJECT "x-vfio-user-server"
 OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
@@ -73,8 +76,14 @@ struct VfuObject {
 char *device;
 
 Error *err;
+
+Notifier machine_done;
+
+vfu_ctx_t *vfu_ctx;
 };
 
+static void vfu_object_init_ctx(VfuObject *o, Error **errp);
+
 static bool vfu_object_auto_shutdown(void)
 {
 bool auto_shutdown = true;
@@ -107,6 +116,11 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, 
const char *name,
 {
 VfuObject *o = VFU_OBJECT(obj);
 
+if (o->vfu_ctx) {
+error_setg(errp, "vfu: Unable to set socket property - server busy");
+return;
+}
+
 qapi_free_SocketAddress(o->socket);
 
 o->socket = NULL;
@@ -122,17 +136,69 @@ static void vfu_object_set_socket(Object *obj, Visitor 
*v, const char *name,
 }
 
 trace_vfu_prop("socket", o->socket->u.q_unix.path);
+
+vfu_object_init_ctx(o, errp);
 }
 
 static void vfu_object_set_device(Object *obj, const char *str, Error **errp)
 {
 VfuObject *o = VFU_OBJECT(obj);
 
+if (o->vfu_ctx) {
+error_setg(errp, "vfu: Unable to set device property - server busy");
+return;
+}
+
 g_free(o->device);
 
 o->device = g_strdup(str);
 
 trace_vfu_prop("device", str);
+
+vfu_object_init_ctx(o, errp);
+}
+
+/*
+ * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
+ * properties. It also depends on devices instantiated in QEMU. These
+ * dependencies are not available during the instance_init phase of this
+ * object's life-cycle. As such, the server is initialized after the
+ * machine is setup. machine_init_done_notifier notifies TYPE_VFU_OBJECT
+ * when the machine is setup, and the dependencies are available.
+ */
+static void vfu_object_machine_done(Notifier *notifier, void *data)
+{
+VfuObject *o = container_of(notifier, VfuObject, machine_done);
+Error *err = NULL;
+
+vfu_object_init_ctx(o, );
+
+if (err) {
+error_propagate(_abort, err);
+}
+}
+
+static void vfu_object_init_ctx(VfuObject *o, Error **errp)
+{
+ERRP_GUARD();
+
+if (o->vfu_ctx || !o->socket || !o->device ||
+!phase_check(PHASE_MACHINE_READY)) {
+return;
+}
+
+if (o->err) {
+error_propagate(errp, o->err);
+o->err = NULL;
+return;
+}
+
+o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0,
+o, VFU_DEV_TYPE_PCI);
+if (o->vfu_ctx == NULL) {
+error_setg(errp, "vfu: Failed to create context - %s", 
strerror(errno));
+return;
+}
 }
 
 static void vfu_object_init(Object *obj)
@@ -147,6 +213,12 @@ static void vfu_object_init(Object *obj)
TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE);
 return;
 }
+
+if (!phase_check(PHASE_MACHINE_READY)) {
+o->machine_done.notify = vfu_object_machine_done;
+qemu_add_machine_init_done_notifier(>machine_done);
+}
+
 }
 
 static void vfu_object_finalize(Object *obj)
@@ -160,6 +232,11 @@ static void vfu_object_finalize(Object *obj)
 
 o->socket = NULL;
 
+if (o->vfu_ctx) {
+vfu_destroy_ctx(o->vfu_ctx);
+o->vfu_ctx = NULL;
+}
+
 g_free(o->device);
 
 o->device = NULL;
@@ -167,6 +244,11 @@ static void vfu_object_finalize(Object *obj)
 if (!k->nr_devs && vfu_object_auto_shutdown()) {
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
 }
+
+if (o->machine_done.notify) {
+qemu_remove_machine_init_done_notifier(>machine_done);
+o->machine_done.notify = NULL;
+}
 }
 
 static void vfu_object_class_init(ObjectClass *klass, void *data)
-- 
2.36.1




[PULL 03/18] qdev: unplug blocker for devices

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

Add blocker to prevent hot-unplug of devices

TYPE_VFIO_USER_SERVER, which is introduced shortly, attaches itself to a
PCIDevice on which it depends. If the attached PCIDevice gets removed
while the server in use, it could cause it crash. To prevent this,
TYPE_VFIO_USER_SERVER adds an unplug blocker for the PCIDevice.

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
c41ef80b7cc063314d629737bed2159e5713f2e0.1655151679.git.jag.ra...@oracle.com
Signed-off-by: Stefan Hajnoczi 
---
 include/hw/qdev-core.h | 29 +
 hw/core/qdev.c | 24 
 softmmu/qdev-monitor.c |  4 
 3 files changed, 57 insertions(+)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 92c3d65208..98774e2835 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -193,6 +193,7 @@ struct DeviceState {
 int instance_id_alias;
 int alias_required_for_version;
 ResettableState reset;
+GSList *unplug_blockers;
 };
 
 struct DeviceListener {
@@ -419,6 +420,34 @@ void qdev_simple_device_unplug_cb(HotplugHandler 
*hotplug_dev,
 void qdev_machine_creation_done(void);
 bool qdev_machine_modified(void);
 
+/**
+ * qdev_add_unplug_blocker: Add an unplug blocker to a device
+ *
+ * @dev: Device to be blocked from unplug
+ * @reason: Reason for blocking
+ */
+void qdev_add_unplug_blocker(DeviceState *dev, Error *reason);
+
+/**
+ * qdev_del_unplug_blocker: Remove an unplug blocker from a device
+ *
+ * @dev: Device to be unblocked
+ * @reason: Pointer to the Error used with qdev_add_unplug_blocker.
+ *  Used as a handle to lookup the blocker for deletion.
+ */
+void qdev_del_unplug_blocker(DeviceState *dev, Error *reason);
+
+/**
+ * qdev_unplug_blocked: Confirm if a device is blocked from unplug
+ *
+ * @dev: Device to be tested
+ * @reason: Returns one of the reasons why the device is blocked,
+ *  if any
+ *
+ * Returns: true if device is blocked from unplug, false otherwise
+ */
+bool qdev_unplug_blocked(DeviceState *dev, Error **errp);
+
 /**
  * GpioPolarity: Polarity of a GPIO line
  *
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 84f3019440..0806d8fcaa 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -468,6 +468,28 @@ char *qdev_get_dev_path(DeviceState *dev)
 return NULL;
 }
 
+void qdev_add_unplug_blocker(DeviceState *dev, Error *reason)
+{
+dev->unplug_blockers = g_slist_prepend(dev->unplug_blockers, reason);
+}
+
+void qdev_del_unplug_blocker(DeviceState *dev, Error *reason)
+{
+dev->unplug_blockers = g_slist_remove(dev->unplug_blockers, reason);
+}
+
+bool qdev_unplug_blocked(DeviceState *dev, Error **errp)
+{
+ERRP_GUARD();
+
+if (dev->unplug_blockers) {
+error_propagate(errp, error_copy(dev->unplug_blockers->data));
+return true;
+}
+
+return false;
+}
+
 static bool device_get_realized(Object *obj, Error **errp)
 {
 DeviceState *dev = DEVICE(obj);
@@ -704,6 +726,8 @@ static void device_finalize(Object *obj)
 
 DeviceState *dev = DEVICE(obj);
 
+g_assert(!dev->unplug_blockers);
+
 QLIST_FOREACH_SAFE(ngl, >gpios, node, next) {
 QLIST_REMOVE(ngl, node);
 qemu_free_irqs(ngl->in, ngl->num_in);
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index bb5897fc76..4b0ef65780 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -899,6 +899,10 @@ void qdev_unplug(DeviceState *dev, Error **errp)
 HotplugHandlerClass *hdc;
 Error *local_err = NULL;
 
+if (qdev_unplug_blocked(dev, errp)) {
+return;
+}
+
 if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) {
 error_setg(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
 return;
-- 
2.36.1




[PULL 06/18] vfio-user: build library

2022-06-15 Thread Stefan Hajnoczi
From: Jagannathan Raman 

add the libvfio-user library as a submodule. build it as a meson
subproject.

libvfio-user is distributed with BSD 3-Clause license and
json-c with MIT (Expat) license

Signed-off-by: Elena Ufimtseva 
Signed-off-by: John G Johnson 
Signed-off-by: Jagannathan Raman 
Reviewed-by: Stefan Hajnoczi 
Message-id: 
c2adec87958b081d1dc8775d4aa05c897912f025.1655151679.git.jag.ra...@oracle.com

[Changed submodule URL to QEMU's libvfio-user mirror on GitLab. The QEMU
project mirrors its dependencies so that it can provide full source code
even in the event that its dependencies become unavailable. Note that
the mirror repo is manually updated, so please contact me to make newer
libvfio-user commits available. If I become a bottleneck we can set up a
cronjob.

Updated scripts/meson-buildoptions.sh to match the meson_options.txt
change. Failure to do so can result in scripts/meson-buildoptions.sh
being modified by the build system later on and you end up with a dirty
working tree.
--Stefan]

Signed-off-by: Stefan Hajnoczi 
---
 MAINTAINERS |  1 +
 meson_options.txt   |  2 ++
 configure   | 17 +
 meson.build | 23 ++-
 .gitlab-ci.d/buildtest.yml  |  1 +
 .gitmodules |  3 +++
 Kconfig.host|  4 
 hw/remote/Kconfig   |  4 
 hw/remote/meson.build   |  2 ++
 scripts/meson-buildoptions.sh   |  4 
 subprojects/libvfio-user|  1 +
 tests/docker/dockerfiles/centos8.docker |  2 ++
 12 files changed, 63 insertions(+), 1 deletion(-)
 create mode 16 subprojects/libvfio-user

diff --git a/MAINTAINERS b/MAINTAINERS
index 5ba93348aa..d0fcaf0edb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3642,6 +3642,7 @@ F: hw/remote/proxy-memory-listener.c
 F: include/hw/remote/proxy-memory-listener.h
 F: hw/remote/iohub.c
 F: include/hw/remote/iohub.h
+F: subprojects/libvfio-user
 
 EBPF:
 M: Jason Wang 
diff --git a/meson_options.txt b/meson_options.txt
index 0e8197386b..f3e2f22c1e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -88,6 +88,8 @@ option('cfi_debug', type: 'boolean', value: 'false',
description: 'Verbose errors in case of CFI violation')
 option('multiprocess', type: 'feature', value: 'auto',
description: 'Out of process device emulation support')
+option('vfio_user_server', type: 'feature', value: 'disabled',
+   description: 'vfio-user server support')
 option('dbus_display', type: 'feature', value: 'auto',
description: '-display dbus support')
 option('tpm', type : 'feature', value : 'auto',
diff --git a/configure b/configure
index 4b12a8094c..c14e7f590a 100755
--- a/configure
+++ b/configure
@@ -315,6 +315,7 @@ meson_args=""
 ninja=""
 bindir="bin"
 skip_meson=no
+vfio_user_server="disabled"
 
 # The following Meson options are handled manually (still they
 # are included in the automatically generated help message)
@@ -909,6 +910,10 @@ for opt do
   ;;
   --disable-blobs) meson_option_parse --disable-install-blobs ""
   ;;
+  --enable-vfio-user-server) vfio_user_server="enabled"
+  ;;
+  --disable-vfio-user-server) vfio_user_server="disabled"
+  ;;
   --enable-tcmalloc) meson_option_parse --enable-malloc=tcmalloc tcmalloc
   ;;
   --enable-jemalloc) meson_option_parse --enable-malloc=jemalloc jemalloc
@@ -2132,6 +2137,17 @@ write_container_target_makefile() {
 
 
 
+##
+# check for vfio_user_server
+
+case "$vfio_user_server" in
+  enabled )
+if test "$git_submodules_action" != "ignore"; then
+  git_submodules="${git_submodules} subprojects/libvfio-user"
+fi
+;;
+esac
+
 ##
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -2672,6 +2688,7 @@ if test "$skip_meson" = no; then
   test "$slirp" != auto && meson_option_add "-Dslirp=$slirp"
   test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
   test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
+  test "$vfio_user_server" != auto && meson_option_add 
"-Dvfio_user_server=$vfio_user_server"
   run_meson() {
 NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" 
"$source_path"
   }
diff --git a/meson.build b/meson.build
index 9e65cc5367..ca19ddc30c 100644
--- a/meson.build
+++ b/meson.build
@@ -308,6 +308,10 @@ multiprocess_allowed = get_option('multiprocess') \
   .require(targetos == 'linux', error_message: 'Multiprocess QEMU is supported 
only on Linux') \
   .allowed()
 
+vfio_user_server_allowed = get_option('vfio_user_server') \
+  .require(targetos == 'linux', error_message: 'vfio-user server is supported 
only on Linux') \
+  .allowed()
+
 have_tpm = get_option('tpm') \
   .require(targetos != 'windows', error_message: 'TPM emulation only available 
on POSIX systems') \
   .allowed()
@@ -2380,7 +2384,8 @@ 

[PULL 01/18] MAINTAINERS: update Vladimir's address and repositories

2022-06-15 Thread Stefan Hajnoczi
From: Vladimir Sementsov-Ogievskiy 

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Message-id: 20220526115432.138384-1-vsement...@yandex-team.ru
Signed-off-by: Stefan Hajnoczi 
---
 MAINTAINERS | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4cf6174f9f..5ba93348aa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2546,7 +2546,7 @@ F: scsi/*
 
 Block Jobs
 M: John Snow 
-M: Vladimir Sementsov-Ogievskiy 
+M: Vladimir Sementsov-Ogievskiy 
 L: qemu-bl...@nongnu.org
 S: Supported
 F: blockjob.c
@@ -2571,7 +2571,7 @@ F: block/aio_task.c
 F: util/qemu-co-shared-resource.c
 F: include/qemu/co-shared-resource.h
 T: git https://gitlab.com/jsnow/qemu.git jobs
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git jobs
+T: git https://gitlab.com/vsementsov/qemu.git block
 
 Block QAPI, monitor, command line
 M: Markus Armbruster 
@@ -2592,7 +2592,7 @@ F: include/hw/cxl/
 
 Dirty Bitmaps
 M: Eric Blake 
-M: Vladimir Sementsov-Ogievskiy 
+M: Vladimir Sementsov-Ogievskiy 
 R: John Snow 
 L: qemu-bl...@nongnu.org
 S: Supported
@@ -2606,6 +2606,7 @@ F: util/hbitmap.c
 F: tests/unit/test-hbitmap.c
 F: docs/interop/bitmaps.rst
 T: git https://repo.or.cz/qemu/ericb.git bitmaps
+T: git https://gitlab.com/vsementsov/qemu.git block
 
 Character device backends
 M: Marc-André Lureau 
@@ -2816,16 +2817,17 @@ F: scripts/*.py
 F: tests/*.py
 
 Benchmark util
-M: Vladimir Sementsov-Ogievskiy 
+M: Vladimir Sementsov-Ogievskiy 
 S: Maintained
 F: scripts/simplebench/
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git simplebench
+T: git https://gitlab.com/vsementsov/qemu.git simplebench
 
 Transactions helper
-M: Vladimir Sementsov-Ogievskiy 
+M: Vladimir Sementsov-Ogievskiy 
 S: Maintained
 F: include/qemu/transactions.h
 F: util/transactions.c
+T: git https://gitlab.com/vsementsov/qemu.git block
 
 QAPI
 M: Markus Armbruster 
@@ -3402,7 +3404,7 @@ F: block/iscsi-opts.c
 
 Network Block Device (NBD)
 M: Eric Blake 
-M: Vladimir Sementsov-Ogievskiy 
+M: Vladimir Sementsov-Ogievskiy 
 L: qemu-bl...@nongnu.org
 S: Maintained
 F: block/nbd*
@@ -3414,7 +3416,7 @@ F: docs/interop/nbd.txt
 F: docs/tools/qemu-nbd.rst
 F: tests/qemu-iotests/tests/*nbd*
 T: git https://repo.or.cz/qemu/ericb.git nbd
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git nbd
+T: git https://gitlab.com/vsementsov/qemu.git block
 
 NFS
 M: Peter Lieven 
@@ -3499,13 +3501,13 @@ F: block/dmg.c
 parallels
 M: Stefan Hajnoczi 
 M: Denis V. Lunev 
-M: Vladimir Sementsov-Ogievskiy 
+M: Vladimir Sementsov-Ogievskiy 
 L: qemu-bl...@nongnu.org
 S: Supported
 F: block/parallels.c
 F: block/parallels-ext.c
 F: docs/interop/parallels.txt
-T: git https://src.openvz.org/scm/~vsementsov/qemu.git parallels
+T: git https://gitlab.com/vsementsov/qemu.git block
 
 qed
 M: Stefan Hajnoczi 
-- 
2.36.1




[PULL 00/18] Block patches

2022-06-15 Thread Stefan Hajnoczi
The following changes since commit 8e6c70b9d4a1b1f3011805947925cfdb31642f7f:

  Merge tag 'kraxel-20220614-pull-request' of git://git.kraxel.org/qemu into 
staging (2022-06-14 06:21:46 -0700)

are available in the Git repository at:

  https://gitlab.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 99b969fbe105117f5af6060d3afef40ca39cc9c1:

  linux-aio: explain why max batch is checked in laio_io_unplug() (2022-06-15 
16:43:42 +0100)


Pull request

This pull request includes an important aio=native I/O stall fix, the
experimental vifo-user server, the io_uring_register_ring_fd() optimization for
aio=io_uring, and an update to Vladimir Sementsov-Ogievskiy's maintainership
details.



Jagannathan Raman (14):
  qdev: unplug blocker for devices
  remote/machine: add HotplugHandler for remote machine
  remote/machine: add vfio-user property
  vfio-user: build library
  vfio-user: define vfio-user-server object
  vfio-user: instantiate vfio-user context
  vfio-user: find and init PCI device
  vfio-user: run vfio-user context
  vfio-user: handle PCI config space accesses
  vfio-user: IOMMU support for remote device
  vfio-user: handle DMA mappings
  vfio-user: handle PCI BAR accesses
  vfio-user: handle device interrupts
  vfio-user: handle reset of remote device

Sam Li (1):
  Use io_uring_register_ring_fd() to skip fd operations

Stefan Hajnoczi (2):
  linux-aio: fix unbalanced plugged counter in laio_io_unplug()
  linux-aio: explain why max batch is checked in laio_io_unplug()

Vladimir Sementsov-Ogievskiy (1):
  MAINTAINERS: update Vladimir's address and repositories

 MAINTAINERS |  27 +-
 meson_options.txt   |   2 +
 qapi/misc.json  |  31 +
 qapi/qom.json   |  20 +-
 configure   |  17 +
 meson.build |  24 +-
 include/exec/memory.h   |   3 +
 include/hw/pci/msi.h|   1 +
 include/hw/pci/msix.h   |   1 +
 include/hw/pci/pci.h|  13 +
 include/hw/qdev-core.h  |  29 +
 include/hw/remote/iommu.h   |  40 +
 include/hw/remote/machine.h |   4 +
 include/hw/remote/vfio-user-obj.h   |   6 +
 block/io_uring.c|  12 +-
 block/linux-aio.c   |  10 +-
 hw/core/qdev.c  |  24 +
 hw/pci/msi.c|  49 +-
 hw/pci/msix.c   |  35 +-
 hw/pci/pci.c|  13 +
 hw/remote/iommu.c   | 131 
 hw/remote/machine.c |  88 ++-
 hw/remote/vfio-user-obj.c   | 958 
 softmmu/physmem.c   |   4 +-
 softmmu/qdev-monitor.c  |   4 +
 stubs/vfio-user-obj.c   |   6 +
 tests/qtest/fuzz/generic_fuzz.c |   9 +-
 .gitlab-ci.d/buildtest.yml  |   1 +
 .gitmodules |   3 +
 Kconfig.host|   4 +
 hw/remote/Kconfig   |   4 +
 hw/remote/meson.build   |   4 +
 hw/remote/trace-events  |  11 +
 scripts/meson-buildoptions.sh   |   4 +
 stubs/meson.build   |   1 +
 subprojects/libvfio-user|   1 +
 tests/docker/dockerfiles/centos8.docker |   2 +
 37 files changed, 1565 insertions(+), 31 deletions(-)
 create mode 100644 include/hw/remote/iommu.h
 create mode 100644 include/hw/remote/vfio-user-obj.h
 create mode 100644 hw/remote/iommu.c
 create mode 100644 hw/remote/vfio-user-obj.c
 create mode 100644 stubs/vfio-user-obj.c
 create mode 16 subprojects/libvfio-user

-- 
2.36.1




Re: [PATCH v4 5/7] 9pfs: fix 'Twalk' to only send error if no component walked

2022-06-15 Thread Greg Kurz
On Tue, 15 Mar 2022 11:08:39 +0100
Christian Schoenebeck  wrote:

> Current implementation of 'Twalk' request handling always sends an 'Rerror'
> response if any error occured. The 9p2000 protocol spec says though:
> 
>   "
>   If the first element cannot be walked for any reason, Rerror is returned.
>   Otherwise, the walk will return an Rwalk message containing nwqid qids
>   corresponding, in order, to the files that are visited by the nwqid
>   successful elementwise walks; nwqid is therefore either nwname or the index
>   of the first elementwise walk that failed.
>   "
> 
>   http://ericvh.github.io/9p-rfc/rfc9p2000.html#anchor33
> 
> For that reason we are no longer leaving from an error path in function
> v9fs_walk(), unless really no path component could be walked successfully or
> if the request has been interrupted.
> 
> Local variable 'nwalked' counts and reflects the number of path components
> successfully processed by background I/O thread, whereas local variable
> 'name_idx' subsequently counts and reflects the number of path components
> eventually accepted successfully by 9p server controller portion.
> 
> New local variable 'any_err' is an aggregate variable reflecting whether any
> error occurred at all, while already existing variable 'err' only reflects
> the last error.
> 
> Despite QIDs being delivered to client in a more relaxed way now, it is
> important to note though that fid still must remain unaffected if any error
> occurred.
> 
> Signed-off-by: Christian Schoenebeck 
> ---
>  hw/9pfs/9p.c | 43 +++
>  1 file changed, 27 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 298f4e6548..e770972a71 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -1766,7 +1766,7 @@ static void coroutine_fn v9fs_walk(void *opaque)
>  {
>  int name_idx, nwalked;
>  g_autofree V9fsQID *qids = NULL;
> -int i, err = 0;
> +int i, err = 0, any_err = 0;
>  V9fsPath dpath, path;
>  P9ARRAY_REF(V9fsPath) pathes = NULL;
>  uint16_t nwnames;
> @@ -1832,19 +1832,20 @@ static void coroutine_fn v9fs_walk(void *opaque)
>   * driver code altogether inside the following block.
>   */
>  v9fs_co_run_in_worker({
> +nwalked = 0;
>  if (v9fs_request_cancelled(pdu)) {
> -err = -EINTR;
> +any_err |= err = -EINTR;

Not super fan of such constructs but I cannot think of anything
better.. so be it ! :-)

>  break;
>  }
>  err = s->ops->lstat(>ctx, , );
>  if (err < 0) {
> -err = -errno;
> +any_err |= err = -errno;
>  break;
>  }
>  stbuf = fidst;
> -for (nwalked = 0; nwalked < nwnames; nwalked++) {
> +for (; nwalked < nwnames; nwalked++) {
>  if (v9fs_request_cancelled(pdu)) {
> -err = -EINTR;
> +any_err |= err = -EINTR;
>  break;
>  }
>  if (!same_stat_id(>s->root_st, ) ||
> @@ -1854,16 +1855,16 @@ static void coroutine_fn v9fs_walk(void *opaque)
> wnames[nwalked].data,
> [nwalked]);
>  if (err < 0) {
> -err = -errno;
> +any_err |= err = -errno;
>  break;
>  }
>  if (v9fs_request_cancelled(pdu)) {
> -err = -EINTR;
> +any_err |= err = -EINTR;
>  break;
>  }
>  err = s->ops->lstat(>ctx, [nwalked], );
>  if (err < 0) {
> -err = -errno;
> +any_err |= err = -errno;
>  break;
>  }
>  stbufs[nwalked] = stbuf;
> @@ -1874,12 +1875,12 @@ static void coroutine_fn v9fs_walk(void *opaque)
>  /*
>   * Handle all the rest of this Twalk request on main thread ...
>   */
> -if (err < 0) {
> +if ((err < 0 && !nwalked) || err == -EINTR) {

So this is making an exception to the spec excerpt you're mentioning
in the changelog.

EINTR can only come from the v9fs_request_cancelled(pdu) == true case,
since QEMU doesn't have signal handlers AFAIK. This would be the result
of a TFLUSH , likely to handle ^C from the client side. I guess that in
that peculiar case, it quite makes sense to return RERROR/RLERROR instead
of the "degraded" RWALK that the end user isn't waiting for. To sum up,
TFLUSH behavior prevails on TWALK. Please add a comment though since
this isn't super obvious in the spec.

Apart from that, LGTM.

Reviewed-by: Greg Kurz 

>  goto out;
>  }
>  
> -err = stat_to_qid(pdu, , );
> -if (err < 0) {
> +any_err |= err = stat_to_qid(pdu, , );
> +if (err < 0 && !nwalked) {
>  goto out;
>  }
>  stbuf = fidst;
> @@ -1888,20 +1889,29 @@ static void 

Re: [PATCH 2/5] tests/qemu-iotests: skip 108 when FUSE is not loaded

2022-06-15 Thread John Snow
On Wed, Jun 15, 2022 at 11:33 AM Daniel P. Berrangé  wrote:
>
> On Wed, Jun 15, 2022 at 09:41:32AM -0400, John Snow wrote:
> > On Tue, Jun 14, 2022 at 10:30 AM John Snow  wrote:
> > >
> > > On Tue, Jun 14, 2022 at 4:59 AM Daniel P. Berrangé  
> > > wrote:
> > > >
> > > > On Tue, Jun 14, 2022 at 06:46:35AM +0200, Thomas Huth wrote:
> > > > > On 14/06/2022 03.50, John Snow wrote:
> > > > > > In certain container environments we may not have FUSE at all, so 
> > > > > > skip
> > > > > > the test in this circumstance too.
> > > > > >
> > > > > > Signed-off-by: John Snow 
> > > > > > ---
> > > > > >   tests/qemu-iotests/108 | 6 ++
> > > > > >   1 file changed, 6 insertions(+)
> > > > > >
> > > > > > diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108
> > > > > > index 9e923d6a59f..e401c5e9933 100755
> > > > > > --- a/tests/qemu-iotests/108
> > > > > > +++ b/tests/qemu-iotests/108
> > > > > > @@ -60,6 +60,12 @@ if sudo -n losetup &>/dev/null; then
> > > > > >   else
> > > > > >   loopdev=false
> > > > > > +# Check for fuse support in the host environment:
> > > > > > +lsmod | grep fuse &>/dev/null;
> > > > >
> > > > > That doesn't work if fuse has been linked statically into the kernel. 
> > > > > Would
> > > > > it make sense to test for /sys/fs/fuse instead?
> > > > >
> > > > > (OTOH, we likely hardly won't run this on statically linked kernels 
> > > > > anyway,
> > > > > so it might not matter too much)
> > > >
> > > > But more importantly 'lsmod' may not be installed in our container
> > > > images. So checking /sys/fs/fuse avoids introducing a dep on the
> > > > 'kmod' package.
> > > >
> > > > >
> > > > > > +if [[ $? -ne 0 ]]; then
> > > > >
> > > > > I'd prefer single "[" instead of "[[" ... but since we're requiring 
> > > > > bash
> > > > > anyway, it likely doesn't matter.
> > > >
> > > > Or
> > > >
> > > > if  test $? != 0 ; then
> > > >
> > > > >
> > > > > > +_notrun 'No Passwordless sudo nor FUSE kernel module'
> > > > > > +fi
> > > > > > +
> > > > > >   # QSD --export fuse will either yield "Parameter 'id' is 
> > > > > > missing"
> > > > > >   # or "Invalid parameter 'fuse'", depending on whether there is
> > > > > >   # FUSE support or not.
> > > > >
> > >
> > > Good suggestions, thanks!
> > >
> >
> > I think I need to test against /dev/fuse instead, because /sys/fs/fuse
> > actually exists, but because of docker permissions (etc), FUSE isn't
> > actually usable from the child container.
> >
> > I wound up with this:
> >
> > # Check for usable FUSE in the host environment:
> > if test ! -c "/dev/fuse"; then
> > _notrun 'No passwordless sudo nor usable /dev/fuse'
> > fi
> >
> > Seems to work for my case here, at least, but I don't have a good
> > sense for how broadly flexible it might be. It might be nicer to
> > concoct some kind of NOP fuse mount instead, but I wasn't able to
> > figure out such a command quickly.
> >
> > The next problem I have is actually related; test-qga (for the
> > Centos.x86_64 run) is failing because the guest agent is reading
> > /proc/self/mountinfo -- which contains entries for block devices that
> > are not visible in the current container scope. I think when QGA goes
> > to read info about these devices to populate a response, it chokes.
> > This might be a genuine bug in QGA if we want it to tolerate existing
> > inside of a container.
>
> Yes, we should fix this. Even if you don't run QGA in a container,
> someone might configure the systemd service to harden it, by
> restricting what /dev it is able to see and thus trigger the
> same issue.

Naive solution: if we try to look in /sys/dev/block/%u:%u and find
that we are unable to do so for whatever reason (ENOENT et al), just
skip that entry for the fsinfo returned to the caller.

Does it need to be fancier than that?

--js




Re: [PATCH] target/riscv: Update tval for hardware watchpoint

2022-06-15 Thread Richard Henderson

On 6/14/22 21:08, Bin Meng wrote:

From: Bin Meng 

When watchpoint is hit, the breakpoint exception should update tval
to point to the faulting virtual address.

Signed-off-by: Bin Meng 
---

  target/riscv/cpu.h| 1 +
  target/riscv/cpu_helper.c | 6 ++
  target/riscv/debug.c  | 2 ++
  3 files changed, 9 insertions(+)

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 7d6397acdf..fdcba8978b 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -289,6 +289,7 @@ struct CPUArchState {
  
  /* trigger module */

  target_ulong trigger_cur;
+bool wp_hit;


It would be better to not add this, which duplicates cs->watchpoint_hit.
In riscv_cpu_debug_excp_handler, raise a synthetic exception number 
(RISCV_EXCP_WATCHPOINT?), then set tval in the same switch as the others.



r~



Re: [PATCH] tests/vm: allow running tests in an unconfigured source tree

2022-06-15 Thread John Snow
On Tue, Jun 14, 2022 at 12:51 PM Paolo Bonzini  wrote:
>
> tests/vm/Makefile.include used to assume that it could run in an unconfigured
> source tree, and Cirrus CI relies on that.  It was however broken by commit
> f4c66f1705 ("tests: use tests/venv to run basevm.py-based scripts", 
> 2022-06-06),
> which co-opted the virtual environment being used by avocado tests
> to also run the basevm.py tests.
>
> For now, reintroduce the usage of qemu.qmp from the source directory, but
> without the sys.path() hacks.  The CI configuration can be changed to
> install the package via pip when qemu.qmp is removed from the source tree.

Seems kinda fragile. If dependencies change etc they're not going to
get processed here unless someone notices and keeps it up to date
manually.
Can we change the Cirrus CI config to just create the venv and bypass
configure? (Like, just run mkvenv directly?)

Or ... actually, uh. what's the problem with running check-venv,
actually? I guess because of build system magic that requires a call
to configure and we can't do that for the Cirrus CI?

>
> Cc: John Snow 
> Signed-off-by: Paolo Bonzini 
> ---
>  tests/vm/Makefile.include | 26 +-
>  1 file changed, 17 insertions(+), 9 deletions(-)
>
> diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
> index 588bc999cc..5f5b1fbfe6 100644
> --- a/tests/vm/Makefile.include
> +++ b/tests/vm/Makefile.include
> @@ -1,8 +1,17 @@
>  # Makefile for VM tests
>
> -.PHONY: vm-build-all vm-clean-all
> +# Hack to allow running in an unconfigured build tree
> +ifeq ($(wildcard $(SRC_PATH)/config-host.mak),)
> +VM_PYTHON = PYTHONPATH=$(SRC_PATH)/python /usr/bin/env python3
> +VM_VENV =
> +HOST_ARCH := $(shell uname -m)
> +else
> +VM_PYTHON = $(TESTS_PYTHON)
> +VM_VENV = check-venv
> +HOST_ARCH = $(ARCH)
> +endif
>
> -HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
> +.PHONY: vm-build-all vm-clean-all
>
>  EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
>
> @@ -85,10 +94,10 @@ vm-clean-all:
>  $(IMAGES_DIR)/%.img:   $(SRC_PATH)/tests/vm/% \
> $(SRC_PATH)/tests/vm/basevm.py \
> $(SRC_PATH)/tests/vm/Makefile.include \
> -   check-venv
> +   $(VM_VENV)
> @mkdir -p $(IMAGES_DIR)
> $(call quiet-command, \
> -   $(TESTS_PYTHON) $< \
> +   $(VM_PYTHON) $< \
> $(if $(V)$(DEBUG), --debug) \
> $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
> $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
> @@ -100,11 +109,10 @@ $(IMAGES_DIR)/%.img:  $(SRC_PATH)/tests/vm/% \
> --build-image $@, \
> "  VM-IMAGE $*")
>
> -
>  # Build in VM $(IMAGE)
> -vm-build-%: $(IMAGES_DIR)/%.img check-venv
> +vm-build-%: $(IMAGES_DIR)/%.img $(VM_VENV)
> $(call quiet-command, \
> -   $(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \
> +   $(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
> $(if $(V)$(DEBUG), --debug) \
> $(if $(DEBUG), --interactive) \
> $(if $(J),--jobs $(J)) \
> @@ -128,9 +136,9 @@ vm-boot-serial-%: $(IMAGES_DIR)/%.img
> -device virtio-net-pci,netdev=vnet \
> || true
>
> -vm-boot-ssh-%: $(IMAGES_DIR)/%.img check-venv
> +vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(VM_VENV)
> $(call quiet-command, \
> -   $(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \
> +   $(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
> $(if $(J),--jobs $(J)) \
> $(if $(V)$(DEBUG), --debug) \
> $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
> --
> 2.36.1
>

as for this hack -- trusting your judgment on it for now, but I am not
sure I agree with your proposed long term fix just yet. I'll add it to
the list of criteria for the next series.

Acked-By: John Snow 




Re: [PATCH 2/5] tests/qemu-iotests: skip 108 when FUSE is not loaded

2022-06-15 Thread Daniel P . Berrangé
On Wed, Jun 15, 2022 at 09:41:32AM -0400, John Snow wrote:
> On Tue, Jun 14, 2022 at 10:30 AM John Snow  wrote:
> >
> > On Tue, Jun 14, 2022 at 4:59 AM Daniel P. Berrangé  
> > wrote:
> > >
> > > On Tue, Jun 14, 2022 at 06:46:35AM +0200, Thomas Huth wrote:
> > > > On 14/06/2022 03.50, John Snow wrote:
> > > > > In certain container environments we may not have FUSE at all, so skip
> > > > > the test in this circumstance too.
> > > > >
> > > > > Signed-off-by: John Snow 
> > > > > ---
> > > > >   tests/qemu-iotests/108 | 6 ++
> > > > >   1 file changed, 6 insertions(+)
> > > > >
> > > > > diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108
> > > > > index 9e923d6a59f..e401c5e9933 100755
> > > > > --- a/tests/qemu-iotests/108
> > > > > +++ b/tests/qemu-iotests/108
> > > > > @@ -60,6 +60,12 @@ if sudo -n losetup &>/dev/null; then
> > > > >   else
> > > > >   loopdev=false
> > > > > +# Check for fuse support in the host environment:
> > > > > +lsmod | grep fuse &>/dev/null;
> > > >
> > > > That doesn't work if fuse has been linked statically into the kernel. 
> > > > Would
> > > > it make sense to test for /sys/fs/fuse instead?
> > > >
> > > > (OTOH, we likely hardly won't run this on statically linked kernels 
> > > > anyway,
> > > > so it might not matter too much)
> > >
> > > But more importantly 'lsmod' may not be installed in our container
> > > images. So checking /sys/fs/fuse avoids introducing a dep on the
> > > 'kmod' package.
> > >
> > > >
> > > > > +if [[ $? -ne 0 ]]; then
> > > >
> > > > I'd prefer single "[" instead of "[[" ... but since we're requiring bash
> > > > anyway, it likely doesn't matter.
> > >
> > > Or
> > >
> > > if  test $? != 0 ; then
> > >
> > > >
> > > > > +_notrun 'No Passwordless sudo nor FUSE kernel module'
> > > > > +fi
> > > > > +
> > > > >   # QSD --export fuse will either yield "Parameter 'id' is 
> > > > > missing"
> > > > >   # or "Invalid parameter 'fuse'", depending on whether there is
> > > > >   # FUSE support or not.
> > > >
> >
> > Good suggestions, thanks!
> >
> 
> I think I need to test against /dev/fuse instead, because /sys/fs/fuse
> actually exists, but because of docker permissions (etc), FUSE isn't
> actually usable from the child container.
> 
> I wound up with this:
> 
> # Check for usable FUSE in the host environment:
> if test ! -c "/dev/fuse"; then
> _notrun 'No passwordless sudo nor usable /dev/fuse'
> fi
> 
> Seems to work for my case here, at least, but I don't have a good
> sense for how broadly flexible it might be. It might be nicer to
> concoct some kind of NOP fuse mount instead, but I wasn't able to
> figure out such a command quickly.
> 
> The next problem I have is actually related; test-qga (for the
> Centos.x86_64 run) is failing because the guest agent is reading
> /proc/self/mountinfo -- which contains entries for block devices that
> are not visible in the current container scope. I think when QGA goes
> to read info about these devices to populate a response, it chokes.
> This might be a genuine bug in QGA if we want it to tolerate existing
> inside of a container.

Yes, we should fix this. Even if you don't run QGA in a container,
someone might configure the systemd service to harden it, by
restricting what /dev it is able to see and thus trigger the
same issue.


With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




Re: [PATCH v4 3/7] tests/9pfs: compare QIDs in fs_walk_none() test

2022-06-15 Thread Greg Kurz
On Tue, 15 Mar 2022 11:08:35 +0100
Christian Schoenebeck  wrote:

> Extend previously added fs_walk_none() test by comparing the QID
> of the root fid with the QID of the cloned fid. They should be
> equal.
> 
> Signed-off-by: Christian Schoenebeck 
> ---

LGTM.

Reviewed-by: Greg Kurz 

>  tests/qtest/virtio-9p-test.c | 87 
>  1 file changed, 87 insertions(+)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index 6c00da03f4..a1160f4659 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -371,8 +371,15 @@ static P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, 
> uint32_t n_uname,
>  return req;
>  }
>  
> +/* type[1] version[4] path[8] */
>  typedef char v9fs_qid[13];
>  
> +static inline bool is_same_qid(v9fs_qid a, v9fs_qid b)
> +{
> +/* don't compare QID version for checking for file ID equalness */
> +return a[0] == b[0] && memcmp([5], [5], 8) == 0;
> +}
> +
>  /* size[4] Rattach tag[2] qid[13] */
>  static void v9fs_rattach(P9Req *req, v9fs_qid *qid)
>  {
> @@ -425,6 +432,79 @@ static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, 
> v9fs_qid **wqid)
>  v9fs_req_free(req);
>  }
>  
> +/* size[4] Tgetattr tag[2] fid[4] request_mask[8] */
> +static P9Req *v9fs_tgetattr(QVirtio9P *v9p, uint32_t fid, uint64_t 
> request_mask,
> +uint16_t tag)
> +{
> +P9Req *req;
> +
> +req = v9fs_req_init(v9p, 4 + 8, P9_TGETATTR, tag);
> +v9fs_uint32_write(req, fid);
> +v9fs_uint64_write(req, request_mask);
> +v9fs_req_send(req);
> +return req;
> +}
> +
> +typedef struct v9fs_attr {
> +uint64_t valid;
> +v9fs_qid qid;
> +uint32_t mode;
> +uint32_t uid;
> +uint32_t gid;
> +uint64_t nlink;
> +uint64_t rdev;
> +uint64_t size;
> +uint64_t blksize;
> +uint64_t blocks;
> +uint64_t atime_sec;
> +uint64_t atime_nsec;
> +uint64_t mtime_sec;
> +uint64_t mtime_nsec;
> +uint64_t ctime_sec;
> +uint64_t ctime_nsec;
> +uint64_t btime_sec;
> +uint64_t btime_nsec;
> +uint64_t gen;
> +uint64_t data_version;
> +} v9fs_attr;
> +
> +#define P9_GETATTR_BASIC0x07ffULL /* Mask for fields up to BLOCKS */
> +
> +/*
> + * size[4] Rgetattr tag[2] valid[8] qid[13] mode[4] uid[4] gid[4] nlink[8]
> + *  rdev[8] size[8] blksize[8] blocks[8]
> + *  atime_sec[8] atime_nsec[8] mtime_sec[8] mtime_nsec[8]
> + *  ctime_sec[8] ctime_nsec[8] btime_sec[8] btime_nsec[8]
> + *  gen[8] data_version[8]
> + */
> +static void v9fs_rgetattr(P9Req *req, v9fs_attr *attr)
> +{
> +v9fs_req_recv(req, P9_RGETATTR);
> +
> +v9fs_uint64_read(req, >valid);
> +v9fs_memread(req, >qid, 13);
> +v9fs_uint32_read(req, >mode);
> +v9fs_uint32_read(req, >uid);
> +v9fs_uint32_read(req, >gid);
> +v9fs_uint64_read(req, >nlink);
> +v9fs_uint64_read(req, >rdev);
> +v9fs_uint64_read(req, >size);
> +v9fs_uint64_read(req, >blksize);
> +v9fs_uint64_read(req, >blocks);
> +v9fs_uint64_read(req, >atime_sec);
> +v9fs_uint64_read(req, >atime_nsec);
> +v9fs_uint64_read(req, >mtime_sec);
> +v9fs_uint64_read(req, >mtime_nsec);
> +v9fs_uint64_read(req, >ctime_sec);
> +v9fs_uint64_read(req, >ctime_nsec);
> +v9fs_uint64_read(req, >btime_sec);
> +v9fs_uint64_read(req, >btime_nsec);
> +v9fs_uint64_read(req, >gen);
> +v9fs_uint64_read(req, >data_version);
> +
> +v9fs_req_free(req);
> +}
> +
>  /* size[4] Treaddir tag[2] fid[4] offset[8] count[4] */
>  static P9Req *v9fs_treaddir(QVirtio9P *v9p, uint32_t fid, uint64_t offset,
>  uint32_t count, uint16_t tag)
> @@ -1009,6 +1089,7 @@ static void fs_walk_none(void *obj, void *data, 
> QGuestAllocator *t_alloc)
>  v9fs_qid root_qid;
>  g_autofree v9fs_qid *wqid = NULL;
>  P9Req *req;
> +struct v9fs_attr attr;
>  
>  do_version(v9p);
>  req = v9fs_tattach(v9p, 0, getuid(), 0);
> @@ -1021,6 +1102,12 @@ static void fs_walk_none(void *obj, void *data, 
> QGuestAllocator *t_alloc)
>  
>  /* special case: no QID is returned if nwname=0 was sent */
>  g_assert(wqid == NULL);
> +
> +req = v9fs_tgetattr(v9p, 1, P9_GETATTR_BASIC, 0);
> +v9fs_req_wait_for_reply(req, NULL);
> +v9fs_rgetattr(req, );
> +
> +g_assert(is_same_qid(root_qid, attr.qid));
>  }
>  
>  static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc)




  1   2   3   >