Re: [Qemu-devel] [PATCH 5/8] target/mips: Provide R/W access to SAARI and SAAR CP0 registers

2019-01-18 Thread Aleksandar Markovic
On Thursday, January 17, 2019, Stefan Markovic 
wrote:

>
> On 3.1.19. 17:34, Aleksandar Markovic wrote:
> > From: Yongbok Kim 
> >
> > Provide R/W access to SAARI and SAAR CP0 registers.
> >
> > Signed-off-by: Yongbok Kim 
> > Signed-off-by: Aleksandar Markovic 
> > ---
> >   target/mips/cpu.h   |  1 +
> >   target/mips/helper.h|  6 +
> >   target/mips/internal.h  |  1 +
> >   target/mips/op_helper.c | 50 +
> >   target/mips/translate.c | 66 ++
> ---
> >   5 files changed, 120 insertions(+), 4 deletions(-)
>
>
> Reviewed-by: Stefan Markovic 
>
>
The whole series contains this wrong address, but the pull request is fine.

Also, I expected much better and more detailed review, you logged four
whole days on the reviewing, and here is your result. Disappointing!



> > diff --git a/target/mips/cpu.h b/target/mips/cpu.h
> > index 1c2c682..185702d 100644
> > --- a/target/mips/cpu.h
> > +++ b/target/mips/cpu.h
> > @@ -901,6 +901,7 @@ struct CPUMIPSState {
> >   uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */
> >   uint32_t CP0_TCStatus_rw_bitmask; /* Read/write bits in
> CP0_TCStatus */
> >   uint64_t insn_flags; /* Supported instruction set */
> > +int saarp;
> >
> >   /* Fields up to this point are cleared by a CPU reset */
> >   struct {} end_reset_fields;
> > diff --git a/target/mips/helper.h b/target/mips/helper.h
> > index c23e4e5..8872c46 100644
> > --- a/target/mips/helper.h
> > +++ b/target/mips/helper.h
> > @@ -65,6 +65,8 @@ DEF_HELPER_1(mftc0_tcschedule, tl, env)
> >   DEF_HELPER_1(mfc0_tcschefback, tl, env)
> >   DEF_HELPER_1(mftc0_tcschefback, tl, env)
> >   DEF_HELPER_1(mfc0_count, tl, env)
> > +DEF_HELPER_1(mfc0_saar, tl, env)
> > +DEF_HELPER_1(mfhc0_saar, tl, env)
> >   DEF_HELPER_1(mftc0_entryhi, tl, env)
> >   DEF_HELPER_1(mftc0_status, tl, env)
> >   DEF_HELPER_1(mftc0_cause, tl, env)
> > @@ -87,6 +89,7 @@ DEF_HELPER_1(dmfc0_tcschefback, tl, env)
> >   DEF_HELPER_1(dmfc0_lladdr, tl, env)
> >   DEF_HELPER_1(dmfc0_maar, tl, env)
> >   DEF_HELPER_2(dmfc0_watchlo, tl, env, i32)
> > +DEF_HELPER_1(dmfc0_saar, tl, env)
> >   #endif /* TARGET_MIPS64 */
> >
> >   DEF_HELPER_2(mtc0_index, void, env, tl)
> > @@ -131,6 +134,9 @@ DEF_HELPER_2(mtc0_srsconf4, void, env, tl)
> >   DEF_HELPER_2(mtc0_hwrena, void, env, tl)
> >   DEF_HELPER_2(mtc0_pwctl, void, env, tl)
> >   DEF_HELPER_2(mtc0_count, void, env, tl)
> > +DEF_HELPER_2(mtc0_saari, void, env, tl)
> > +DEF_HELPER_2(mtc0_saar, void, env, tl)
> > +DEF_HELPER_2(mthc0_saar, void, env, tl)
> >   DEF_HELPER_2(mtc0_entryhi, void, env, tl)
> >   DEF_HELPER_2(mttc0_entryhi, void, env, tl)
> >   DEF_HELPER_2(mtc0_compare, void, env, tl)
> > diff --git a/target/mips/internal.h b/target/mips/internal.h
> > index 8b1b245..8f6fc91 100644
> > --- a/target/mips/internal.h
> > +++ b/target/mips/internal.h
> > @@ -61,6 +61,7 @@ struct mips_def_t {
> >   target_ulong CP0_EBaseWG_rw_bitmask;
> >   uint64_t insn_flags;
> >   enum mips_mmu_types mmu_type;
> > +int32_t SAARP;
> >   };
> >
> >   extern const struct mips_def_t mips_defs[];
> > diff --git a/target/mips/op_helper.c b/target/mips/op_helper.c
> > index d1f1d1a..409c136 100644
> > --- a/target/mips/op_helper.c
> > +++ b/target/mips/op_helper.c
> > @@ -938,6 +938,22 @@ target_ulong helper_mfc0_count(CPUMIPSState *env)
> >   return count;
> >   }
> >
> > +target_ulong helper_mfc0_saar(CPUMIPSState *env)
> > +{
> > +if ((env->CP0_SAARI & 0x3f) < 2) {
> > +return (int32_t) env->CP0_SAAR[env->CP0_SAARI & 0x3f];
> > +}
> > +return 0;
> > +}
> > +
> > +target_ulong helper_mfhc0_saar(CPUMIPSState *env)
> > +{
> > +if ((env->CP0_SAARI & 0x3f) < 2) {
> > +return env->CP0_SAAR[env->CP0_SAARI & 0x3f] >> 32;
> > +}
> > +return 0;
> > +}
> > +
> >   target_ulong helper_mftc0_entryhi(CPUMIPSState *env)
> >   {
> >   int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
> > @@ -1059,6 +1075,14 @@ target_ulong helper_dmfc0_watchlo(CPUMIPSState
> *env, uint32_t sel)
> >   {
> >   return env->CP0_WatchLo[sel];
> >   }
> > +
> > +target_ulong helper_dmfc0_saar(CPUMIPSState *env)
> > +{
> > +if ((env->CP0_SAARI & 0x3f) < 2) {
> > +return env->CP0_SAAR[env->CP0_SAARI & 0x3f];
> > +}
> > +return 0;
> > +}
> >   #endif /* TARGET_MIPS64 */
> >
> >   void helper_mtc0_index(CPUMIPSState *env, target_ulong arg1)
> > @@ -1598,6 +1622,32 @@ void helper_mtc0_count(CPUMIPSState *env,
> target_ulong arg1)
> >   qemu_mutex_unlock_iothread();
> >   }
> >
> > +void helper_mtc0_saari(CPUMIPSState *env, target_ulong arg1)
> > +{
> > +uint32_t target = arg1 & 0x3f;
> > +if (target <= 1) {
> > +env->CP0_SAARI = target;
> > +}
> > +}
> > +
> > +void helper_mtc0_saar(CPUMIPSState *env, target_ulong arg1)
> > +{
> > +uint32_t target = env->CP0_SAARI & 0x3f;
> > +if (target < 2) {
> > +

[Qemu-devel] [PATCH v1] GLib sucks - Remove any connections between me and GLib

2019-01-18 Thread Michael Clark via Qemu-devel
One has a basic command of English but one cannot think of a
more or less glib commit message for this commit so this is it.

Palmer, I would like to send you an invoice for this commit
but I do not know what value to place on it. 2^64-1, (-1)
or 0x in hex, sounds too little or too much.

You also will have to pay better for me to use nicer language,
and you can bet your bottom dollar it won’t be C. Also, as we
discussed, having one’s direct competitors in control of our
emulation infrastructure is not a great idea. I thought we
agreed on that then I find out we are in disagreement.

However, I feel comfortable because, while I haven’t been paid
since last August, I am arranging temporary support with
WINZ , however, one must
note, that when one’s work is sabotaged in the real world,
folk end up without jobs, whereas if we were just a student
then we probably only end up with a bruised ego and perhaps
lower grades if our supervisor is not happy. In the real world,
we get the shit scared out of us because we think we could be
fired at any moment. i.e. zero-day. I think because I dropped
out of school, I never learned that. Anyhow, I didn’t read
the contract. I just wanted to get a paycheck so I could play
games with folk on the Internet. That’s bullshit. I wasn’t
playing games, now I am. I was released from a mental ward
after a severe episode of anxiety and depression. True Story.
Anyway Palmer fired me today. Performance issues I suspect.
Could be trust, security, mistakes or simply misalignment on
basic issues. Haven't had post-mortem yet.

BTW What if we auctioned commits and if your commit didn’t
get in, you don’t get paid. Commits would become expensive?
(or cheap?). 樂

Also, do we have MIA and KIA tags for MAINTAINERS? We could
even put little Unicode medals next to titles like this:

   (sub³)∘maintainer ️  A. Nonymous

What is the operator binding precedence? i.e. do we that need
parenthesis there or does exponentiation bind more tightly
than the ring operator?

Otherwise, please just delete me. It’s bad memories all round.
as I got fired today because of my QEMU performance. I am a
terrible mess when using version control.

Maybe when I have a secure job we can meet up for a beer and
everything will be okay, but at this point we have the wolves
at the door and are worried about an imminent eviction by the
landlord. Also true story (the conditions of port submission).

I know a lot of you are going to say, send me back to the
mental ward, however, I will miss my partner/spouse. We were
actually looking for a house in Palmerston North over the
weekend in preparation for my imminent demise (she still thinks
we can afford to live here in Auckland and everything is fine),
as we thought it would be survivable on social security, however,
I suspect she may not support me any more given the number of
jobs I have lost in the past 6 years since we met. Indeed, rv8
was written mostly on a benefit from the Ministry of Social
Development, C/- New Zealand Government. Oesensibly Job Seeker
Support, but we were searching for a job that didn’t have too
many interruppts, and then SiFive put me to work on a bloody
interrupt controller. That’s ironic. Of course I am slow and
cannot multitask so QEMU queue management was neglected.

Note: the auction reserve on this commit is ten bucks, or
alternatively, /almost/ the price of a beer in Singapore,
so someone will need to top it up. i.e. free as in /almost/
free beer.

P.S. Don’t mess with the RISC-V Virtual Machine Model without
consulting RISC-V SW Dev list or RISC-V ISA Dev list or the
closed doors working groups in the RISC-V Foundation. Personally
I prefer open discussion. Also, it is not the QEMU virt machine,
it is the RISC-V virt machine because SiFive has a VirtIO model
on Amazon F1, so if you mess with it in QEMU you’ll break prod.

P.P.S. No offence to the GLib maintainers, but automatic
reference counting or garbage collection is much safer to
use in higher level code that does user interaction. We could
get all sorts of leaks and what not. As you know I missed free
(or g_free, although you know what I mean).

P.P.P.S I do not represent my employer because I just got
fired today. Anyone know of any jobs going for a crusty old C++
developer who prefers std::unique_ptr over malloc/free?

P.P.P.P.S Is firecracker written in C++? Rust I think dammit,
maybe I should learn Rust. Don’t worry I know nobody likes me,
so it won’t help me no matter how much I learn. I will still
be an overweight middle-aged (human) with no sense of humour
and a fond affection for C+.

P.P.P.P.P.S I’m not trying to rub it in (I lied, I am).

If you are curious about my alter-ego, it’s my (older) brother,
he’s clever, and I am the dumb one with no sense of humour.
I was trying to get a job in California by writing cloud apps
and he somehow ends up in Walnut Creek. Yes, FreeBSD user
apparently. We had a very long fight over what OS to 

Re: [Qemu-devel] [PATCH 1/8] target/mips: Move comment containing summary of CP0 registers

2019-01-18 Thread Aleksandar Markovic
On Thursday, January 17, 2019, Stefan Markovic 
wrote:

>
> On 3.1.19. 17:34, Aleksandar Markovic wrote:
> > From: Aleksandar Markovic 
> >
> > Move comment containing summary of CP0 registers. Checkpatch
> > script reported some tabs in the resutling diff, so convert
> > these tabs to spaces too.
> >
> > Signed-off-by: Aleksandar Markovic 
> > ---
> >   target/mips/cpu.h | 165 +++---
> 
> >   1 file changed, 84 insertions(+), 81 deletions(-)
>
>
> Reviewed-by: Stefan Markovic 


Wrong mail (two letters permuted - marokvic should be markovic), but I
corrected that in the pull request.

>
>
> > diff --git a/target/mips/cpu.h b/target/mips/cpu.h
> > index 03c03fd..6c2a7e4 100644
> > --- a/target/mips/cpu.h
> > +++ b/target/mips/cpu.h
> > @@ -123,87 +123,6 @@ typedef struct mips_def_t mips_def_t;
> >   #define MIPS_KSCRATCH_NUM 6
> >   #define MIPS_MAAR_MAX 16 /* Must be an even number. */
> >
> > -typedef struct TCState TCState;
> > -struct TCState {
> > -target_ulong gpr[32];
> > -target_ulong PC;
> > -target_ulong HI[MIPS_DSP_ACC];
> > -target_ulong LO[MIPS_DSP_ACC];
> > -target_ulong ACX[MIPS_DSP_ACC];
> > -target_ulong DSPControl;
> > -int32_t CP0_TCStatus;
> > -#define CP0TCSt_TCU3 31
> > -#define CP0TCSt_TCU2 30
> > -#define CP0TCSt_TCU1 29
> > -#define CP0TCSt_TCU0 28
> > -#define CP0TCSt_TMX  27
> > -#define CP0TCSt_RNST 23
> > -#define CP0TCSt_TDS  21
> > -#define CP0TCSt_DT   20
> > -#define CP0TCSt_DA   15
> > -#define CP0TCSt_A13
> > -#define CP0TCSt_TKSU 11
> > -#define CP0TCSt_IXMT 10
> > -#define CP0TCSt_TASID0
> > -int32_t CP0_TCBind;
> > -#define CP0TCBd_CurTC21
> > -#define CP0TCBd_TBE  17
> > -#define CP0TCBd_CurVPE   0
> > -target_ulong CP0_TCHalt;
> > -target_ulong CP0_TCContext;
> > -target_ulong CP0_TCSchedule;
> > -target_ulong CP0_TCScheFBack;
> > -int32_t CP0_Debug_tcstatus;
> > -target_ulong CP0_UserLocal;
> > -
> > -int32_t msacsr;
> > -
> > -#define MSACSR_FS   24
> > -#define MSACSR_FS_MASK  (1 << MSACSR_FS)
> > -#define MSACSR_NX   18
> > -#define MSACSR_NX_MASK  (1 << MSACSR_NX)
> > -#define MSACSR_CEF  2
> > -#define MSACSR_CEF_MASK (0x << MSACSR_CEF)
> > -#define MSACSR_RM   0
> > -#define MSACSR_RM_MASK  (0x3 << MSACSR_RM)
> > -#define MSACSR_MASK (MSACSR_RM_MASK | MSACSR_CEF_MASK |
> MSACSR_NX_MASK | \
> > -MSACSR_FS_MASK)
> > -
> > -float_status msa_fp_status;
> > -
> > -#define NUMBER_OF_MXU_REGISTERS 16
> > -target_ulong mxu_gpr[NUMBER_OF_MXU_REGISTERS - 1];
> > -target_ulong mxu_cr;
> > -#define MXU_CR_LC   31
> > -#define MXU_CR_RC   30
> > -#define MXU_CR_BIAS 2
> > -#define MXU_CR_RD_EN1
> > -#define MXU_CR_MXU_EN   0
> > -
> > -};
> > -
> > -typedef struct CPUMIPSState CPUMIPSState;
> > -struct CPUMIPSState {
> > -TCState active_tc;
> > -CPUMIPSFPUContext active_fpu;
> > -
> > -uint32_t current_tc;
> > -uint32_t current_fpu;
> > -
> > -uint32_t SEGBITS;
> > -uint32_t PABITS;
> > -#if defined(TARGET_MIPS64)
> > -# define PABITS_BASE 36
> > -#else
> > -# define PABITS_BASE 32
> > -#endif
> > -target_ulong SEGMask;
> > -uint64_t PAMask;
> > -#define PAMASK_BASE ((1ULL << PABITS_BASE) - 1)
> > -
> > -int32_t msair;
> > -#define MSAIR_ProcID8
> > -#define MSAIR_Rev   0
> >
> >   /*
> >* Summary of CP0 registers
> > @@ -314,6 +233,90 @@ struct CPUMIPSState {
> >* 7   TagLo TagHi
>  KScratch
> >*
> >*/
> > +
> > +
> > +typedef struct TCState TCState;
> > +struct TCState {
> > +target_ulong gpr[32];
> > +target_ulong PC;
> > +target_ulong HI[MIPS_DSP_ACC];
> > +target_ulong LO[MIPS_DSP_ACC];
> > +target_ulong ACX[MIPS_DSP_ACC];
> > +target_ulong DSPControl;
> > +int32_t CP0_TCStatus;
> > +#define CP0TCSt_TCU331
> > +#define CP0TCSt_TCU230
> > +#define CP0TCSt_TCU129
> > +#define CP0TCSt_TCU028
> > +#define CP0TCSt_TMX 27
> > +#define CP0TCSt_RNST23
> > +#define CP0TCSt_TDS 21
> > +#define CP0TCSt_DT  20
> > +#define CP0TCSt_DA  15
> > +#define CP0TCSt_A   13
> > +#define CP0TCSt_TKSU11
> > +#define CP0TCSt_IXMT10
> > +#define CP0TCSt_TASID   0
> > +int32_t CP0_TCBind;
> > +#define CP0TCBd_CurTC   21
> > +#define CP0TCBd_TBE 17
> > +#define CP0TCBd_CurVPE  0
> > +target_ulong CP0_TCHalt;
> > +target_ulong CP0_TCContext;
> > +target_ulong CP0_TCSchedule;
> > +target_ulong CP0_TCScheFBack;
> > +int32_t CP0_Debug_tcstatus;
> > +target_ulong CP0_UserLocal;
> > +
> > +int32_t msacsr;
> > +
> > +#define MSACSR_FS   24
> > +#define MSACSR_FS_MASK  (1 << MSACSR_FS)
> > +#define MSACSR_NX   18
> > +#define MSACSR_NX_MASK  (1 << MSACSR_NX)
> > +#define MSACSR_CEF  2
> > +#define MSACSR_CEF_MASK (0x << MSACSR_CEF)
> > +#define MSACSR_RM   0
> > +#define MSACSR_RM_MASK  (0x3 << MSACSR_RM)
> > 

Re: [Qemu-devel] [PATCH 10/14] tests: acpi: ignore SMBIOS tests when UEFI firmware is used

2019-01-18 Thread Laszlo Ersek
On 01/17/19 16:11, Igor Mammedov wrote:
> On Wed, 16 Jan 2019 17:22:31 +0100
> Laszlo Ersek  wrote:
> 
>> On 01/16/19 13:31, Igor Mammedov wrote:
>>> On Wed, 16 Jan 2019 12:52:17 +0100
>>> Gerd Hoffmann  wrote:
>>>   
   Hi,
  
> This approach allows the UEFI app source to live in the QEMU tree, and
> the affected maintainer(s) would be personally responsible for setting
> up their edk2 clones, and compilers. (The edk2 clone could even be a
> submodule of QEMU, for example at roms/edk2.) For example,
> "roms/Makefile" already calls an external EFIROM utility (also from
> edk2) in order to build the combined iPXE option ROMs.
>
> And yes, we could turn the UEFI binaries into bootable ISO images at once.
>
> I'll try to post some patches soon (or not so soon). I think the app's
> source code, and the edk2 submodule, should live under roms/, and the
> bootable images should live under pc-bios/.
>
> (In fact we could use this opportunity to build & bundle OVMF itself...
> not sure if that's in scope for now. Gerd, what's your take?)

 Well, there is still the idea to move over firmware submodules and
 prebuilt firmware blobs to a separate repo.  Expermimental repo:
 https://git.kraxel.org/cgit/qemu-firmware/.  Not touched for more than a
 year due to being busy with other stuff.  Oh well ...

 (if someone feels like picking this up feel free to do so).

 I think adding edk2 as submodule below roms/ makes sense.  Adding rules
 to roms/Makefile to build the blobs makes sense too.  Not sure we want
 the binaries actually copied over to pc-bios/ and commited as the uefi
 firmware is pretty big ...

 Not sure what a good place for the uefi app would be.  I'd tend to not
 use roms/, that is the place for firmware submodules.  
>>
>> I figured the source code for the UEFI app would fit due to the script
>> "configure-seabios.sh" and some actual config files being there already.
>> But, I'm happy to follow directions. :)
>>
  contrib/ or test/ maybe?  
>>
>>> Could be tests/data/acpi in this case  
>>
>> If "tests/data/acpi" is appropriate for source code, that works for me.
>> We already have "rebuild-expected-aml.sh" there, so I guess another
>> build script and the UEFI app source code would fit there too.
> I suggested tests/data/acpi for binary EFI app blobs
> For EFI app source maybe just 'tests' or sub-directory there and make
> 'make check-efi-app' build EFI app (doing all needed magic and asking for 
> things that missing)
> if source is newer than blobs.

I've been busy all day hacking and staying away from email, so when you see 
that my patches didn't follow this closely in the end, please know that I 
didn't deliberately ignore your point -- I'm just getting to it now. Let's 
continue the discussion under

  [qemu-devel] [PATCH 0/5] add the BiosTablesTest UEFI app, build it with the 
new roms/edk2 submodule

Thanks!
Laszlo

> 
>>
>> It would be nice if I could get around submitting some patches this
>> week. Sigh. :/
>>
>> Thanks,
>> Laszlo
>>
> 




Re: [Qemu-devel] [PATCH 11/14] tests: acpi: add AVMF firmware blobs

2019-01-18 Thread Laszlo Ersek
On 01/17/19 15:09, Gerd Hoffmann wrote:
> On Thu, Jan 17, 2019 at 01:54:51PM +0100, Laszlo Ersek wrote:
>> On 01/17/19 11:22, Gerd Hoffmann wrote:
>>>   Hi,
>>>
  create mode 100644 pc-bios/avmf.img
  create mode 100644 pc-bios/avmf_vars.img  
>>>
>>> "AVMF" is not a great name. "AAVMF" is a downstream name alright, but
>>> many dislike it in upstream use. "edk2-aarch64" or "edk2-ArmVirtQemu"
>>> would be more precise, but those are verbose. Sigh, why are names so
>>> hard. What does everyone think?
>> I'm fine with either version.
>>>
>>> How about placing them in pc-bios/efi-$arch subdirs and not renaming the
>>> files, i.e. that would be ...
>>>
>>> pc-bios/efi-aarch64/QEMU_EFI.fd
>>> pc-bios/efi-aarch64/QEMU_VARS.fd
>>>
>>> ... for arm, and ...
>>>
>>> pc-bios/efi-x86_64/OVMF_CODE.fd
>>> pc-bios/efi-x86_64/OVMF_VARS.fd
>>>
>>> ... for x86.
>>
>> That sounds good to me. One thing to note is that the arm/aarch64 images
>> have to be padded to 64MB, so I generally append ".padded" to those file
>> names. Would that be OK? Any better ideas?
> 
> Ah, right, the arm versions can't be used as-is with pflash.  In my rpm
> builds I've named the padded version "QEMU_EFI-pflash.raw".  Using
> .padded looks fine to me too.
> 
> Other idea:  Does it make sense to use qcow2 for the pflash images?
> i.e. "qemu-img create -f qcow2 -b QEMU_EFI.fd -F raw QEMU_EFI.qcow2 64M"?

That's a long story.

In a perfect world, the answer would be, "qcow2 (and all its features)
make perfect sense for pflash images". In the world we have however,
"savevm" exists, which might dump live guest RAM into whichever qcow2
disk it finds first. See
.

(I apologize to any non-RedHatters reading this; that's a private RHBZ
for some obscure reason, and I dare not open it up myself.)

See also libvirt commit 9e2465834f4b ("qemu: snapshot: Forbid internal
snapshots with pflash firmware", 2017-03-24).

So, for now, it remains the case that we're better off with raw, at
least for the writeable (=varstore) pflash chip.

In addition, when libvirt composes the cmdline, it specifies format=raw
for unit=0 (i.e., firmware image pflash) as well. (That's actually a
good thing, because we shouldn't auto-detect the format, and qcow2 is
out (for now), so we should specify format=raw. In the future, the
domain XML schema may have to be extended with "format" too.)

... For now, it's probably best to check the unpadded FDs into git, and
pad them only in "make install".

Thanks,
Laszlo



Re: [Qemu-devel] [PATCH v7 3/3] tcg/i386: enable dynamic TLB sizing

2019-01-18 Thread Richard Henderson
On 1/19/19 2:04 AM, Alex Bennée wrote:
> 
> Emilio G. Cota  writes:
> 
>> As the following experiments show, this series is a net perf gain,
>> particularly for memory-heavy workloads. Experiments are run on an
>> Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz.
>>
>> 1. System boot + shudown, debian aarch64:
>>
>> - Before (v3.1.0):
>>  Performance counter stats for './die.sh v3.1.0' (10 runs):
>>
>>9019.797015  task-clock (msec) #0.993 CPUs utilized   
>>  ( +-  0.23% )
>> 29,910,312,379  cycles#3.316 GHz 
>>  ( +-  0.14% )
>> 54,699,252,014  instructions  #1.83  insn per cycle  
>>  ( +-  0.08% )
>> 10,061,951,686  branches  # 1115.541 M/sec   
>>  ( +-  0.08% )
>>172,966,530  branch-misses #1.72% of all branches 
>>  ( +-  0.07% )
>>
>>9.084039051 seconds time elapsed  
>> ( +-  0.23% )
>>
>> - After:
>>  Performance counter stats for './die.sh tlb-dyn-v5' (10 runs):
>>
>>8624.084842  task-clock (msec) #0.993 CPUs utilized   
>>  ( +-  0.23% )
>> 28,556,123,404  cycles#3.311 GHz 
>>  ( +-  0.13% )
>> 51,755,089,512  instructions  #1.81  insn per cycle  
>>  ( +-  0.05% )
>>  9,526,513,946  branches  # 1104.641 M/sec   
>>  ( +-  0.05% )
>>166,578,509  branch-misses #1.75% of all branches 
>>  ( +-  0.19% )
>>
>>8.680540350 seconds time elapsed  
>> ( +-  0.24% )
>>
>> That is, a 4.4% perf increase.
>>
>> 2. System boot + shutdown, ubuntu 18.04 x86_64:
>>
>> - Before (v3.1.0):
>>   56100.574751  task-clock (msec) #1.016 CPUs utilized   
>>  ( +-  4.81% )
>>200,745,466,128  cycles#3.578 GHz 
>>  ( +-  5.24% )
>>431,949,100,608  instructions  #2.15  insn per cycle  
>>  ( +-  5.65% )
>> 77,502,383,330  branches  # 1381.490 M/sec   
>>  ( +-  6.18% )
>>844,681,191  branch-misses #1.09% of all branches 
>>  ( +-  3.82% )
>>
>>   55.221556378 seconds time elapsed  
>> ( +-  5.01% )
>>
>> - After:
>>   56603.419540  task-clock (msec) #1.019 CPUs utilized   
>>  ( +- 10.19% )
>>202,217,930,479  cycles#3.573 GHz 
>>  ( +- 10.69% )
>>439,336,291,626  instructions  #2.17  insn per cycle  
>>  ( +- 14.14% )
>> 80,538,357,447  branches  # 1422.853 M/sec   
>>  ( +- 16.09% )
>>776,321,622  branch-misses #0.96% of all branches 
>>  ( +-  3.77% )
>>
>>   55.549661409 seconds time elapsed  
>> ( +- 10.44% )
>>
>> No improvement (within noise range). Note that for this workload,
>> increasing the time window too much can lead to perf degradation,
>> since it flushes the TLB *very* frequently.
> 
> I would expect this to be fairly minimal in the amount of memory that is
> retouched. We spend a bunch of time paging things in just to drop
> everything and die. However heavy memory operations like my build stress
> test do see a performance boost.
> 
> Tested-by: Alex Bennée 
> Reviewed-by: Alex Bennée 
> 
> Do you have access to any aarch64 hardware? It would be nice to see if
> we could support it there as well.

I've already done some porting to other backends.
You should be able to cherry-pick from

  https://github.com/rth7680/qemu.git cputlb-resize

as I don't think the backend API has changed since v6.

(Most of my feedback that went into v7 was due to issues I encountered porting
to arm32).


r~



Re: [Qemu-devel] [PATCH v2 3/4] trace: forbid use of %m in trace event format strings

2019-01-18 Thread Alex Williamson
On Fri, 18 Jan 2019 11:50:39 -0600
Eric Blake  wrote:

> On 1/18/19 11:31 AM, Daniel P. Berrangé wrote:
> > The '%m' format specifier instructs glibc's printf() implementation to
> > insert the contents of strerror(errno).  
> 
> That is a glibc-only extension in printf(), but mandatory (and supported
> in ALL platforms) in syslog().  However, you are correct that:
> 
> > This is not something that
> > should ever be used in trace-events files because several of the
> > backends do not use the format string and so this error information is
> > invisible to them. The errno value should be given as an explicit
> > trace argument instead. Use of '%m' should also be avoided as it is not
> > portable to all QEMU build targets.  

It's portable to all QEMU build targets that support vfio, but we can
remove it if we want it out of the trace system, which of course does
support other targets.

> If all of our traces are compiled to syslog(), it would be portable, but
> that's not the case.
> 
> What's more, using %m is subject to race conditions - the more code you
> have between when the format string containing %m is given, and the
> point where the actual error message is emitted, the higher the
> probability that some of the intermediate code could have stomped on
> errno in the meantime, rendering the logged message incorrect.  And
> forcing logging wrappers to save/restore the current state of errno,
> just in case they might encounter %m, can get wasteful.
> 
> Should checkpatch be taught to flag %m as suspicious?
> 
> However, tracing the errno value is NOT what %m did; I'd rather see...
> 
> > 
> > Signed-off-by: Daniel P. Berrangé 
> > ---
> >  hw/vfio/pci.c | 2 +-
> >  hw/vfio/trace-events  | 2 +-
> >  scripts/tracetool/__init__.py | 4 
> >  3 files changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> > index c0cb1ec289..85f1908cfe 100644
> > --- a/hw/vfio/pci.c
> > +++ b/hw/vfio/pci.c
> > @@ -2581,7 +2581,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev, 
> > Error **errp)
> >  ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_IRQ_INFO, _info);
> >  if (ret) {
> >  /* This can fail for an old kernel or legacy PCI dev */
> > -trace_vfio_populate_device_get_irq_info_failure();
> > +trace_vfio_populate_device_get_irq_info_failure(errno);  
> 
> trace_vfio_populate_device_get_irq_info_failure(strerror(errno))

Yep, I agree, the intent of the original code is not maintained.
Thanks,

Alex

> >  } else if (irq_info.count == 1) {
> >  vdev->pci_aer = true;
> >  } else {
> > diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
> > index a85e8662ea..6d412afc83 100644
> > --- a/hw/vfio/trace-events
> > +++ b/hw/vfio/trace-events
> > @@ -37,7 +37,7 @@ vfio_pci_hot_reset_has_dep_devices(const char *name) "%s: 
> > hot reset dependent de
> >  vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int 
> > function, int group_id) "\t%04x:%02x:%02x.%x group %d"
> >  vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot 
> > reset: %s"
> >  vfio_populate_device_config(const char *name, unsigned long size, unsigned 
> > long offset, unsigned long flags) "Device %s config:\n  size: 0x%lx, 
> > offset: 0x%lx, flags: 0x%lx"
> > -vfio_populate_device_get_irq_info_failure(void) "VFIO_DEVICE_GET_IRQ_INFO 
> > failure: %m"
> > +vfio_populate_device_get_irq_info_failure(int err) 
> > "VFIO_DEVICE_GET_IRQ_INFO failure: %d"  
> 
> vfio_populate_device_get_irq_info_failur(const char *err)
> "VFIO_DEVICE_GET_IRQ_INFO failure: %s"
> 
> ...if we are trying to match the original intent.
> 
> >  vfio_realize(const char *name, int group_id) " (%s) group %d"
> >  vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d"
> >  vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) 
> > "%s 0x%x@0x%x"
> > diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
> > index 3478ac93ab..6fca674936 100644
> > --- a/scripts/tracetool/__init__.py
> > +++ b/scripts/tracetool/__init__.py
> > @@ -274,6 +274,10 @@ class Event(object):
> >  props = groups["props"].split()
> >  fmt = groups["fmt"]
> >  fmt_trans = groups["fmt_trans"]
> > +if fmt.find("%m") != -1 or fmt_trans.find("%m") != -1:
> > +raise ValueError("Event format '%m' is forbidden, pass the 
> > error "
> > + "as an explicit trace argument")  
> 
> Whether or not checkpatch decides to flag %m as suspicious in the
> overall code base, I like that you are forbidding it in trace files.
> 




Re: [Qemu-devel] [PATCH v4 00/21] nbd: add qemu-nbd --list

2019-01-18 Thread Eric Blake
On 1/18/19 7:47 AM, Vladimir Sementsov-Ogievskiy wrote:

> 
>  > Only expose MBR partition @var{num}.  Understands physical partitions
>  > 1-4 and logical partitions 5-8.
> 
> I'm afraid, I'm too lazy to sort out these things I don't know, so just 
> believe. It at least
> corresponds to limits in code that it should be 1 <= partition <= 8 ;)

It matches the code, but I just learned the code is buggy for anything
larger than 5.  According to
http://tldp.org/HOWTO/Large-Disk-HOWTO-13.html, MBR Extended/Logical
partitions form a linked-list, something like:

MBR:  EBR1  EBR2
+--+  +--+  +--+
+ Part 1   +   |->+ Part 5   +   |->+ Part 6   +
+ Part 2   +   |  + Next |  + 0+
+ Part 3   +   |  + 0+  + 0+
+ Part 4 ---  + 0+  + 0+
+--+  +--+  +--+

In reality, ANY of part 1-4 can point to the first EBR, as long as there
is at most one primary partition pointing to the extended partition -
even crazier is that there are different magic numbers in historical
use, such as type 5 for Part 3 and type 85 for Part 4, where MS-DOS
would treat Partition 3 as the extended partition and ignore Part 4, but
Linux would follow both chains (where the second extended partition thus
allowed Linux access to logical partitions residing in space beyond what
DOS could access).  But once you start the extended partition chain, all
logical partitions within the chain each have their own EBR table with
one entry for the partition and the next entry pointing to the next EBR,
meaning you can have more than 8 logical partitions (provided your disk
is big enough).

But our find_partition() code stupidly assumes that if there is any
extended partition type in the MBR (recognizing only type 5 or type F,
but not Linux' type 85), then all four entries in that EBR are logical
partitions 5-8 (and no more, rather than a linked list chain, as in:

MBR:  EBR
+--+  +--+
+ Part 1   +   |->+ Part 5   +
+ Part 2   +   |  + Part 6   +
+ Part 3   +   |  + Part 7   +
+ Part 4 ---  + Part 8   +
+--+  +--+

It's highly unlikely that there are any BIOS implementations that would
actually recognize such a partition beyond 5 as being bootable (there
might be OSs which are a bit more tolerant, since MBR doesn't seem to
have any one hard canonical specification).  I'd have to compare what
the Linux kernel MBR code does, to see if we even stand a chance of
being interoperable in any manner.  It doesn't help that nbdkit does not
yet support Logical MBR partitions.

Oh well, another project for another day; this documentation change is
going in as-is because it at least matches the code, even if the code is
buggy.  (I'm tempted to fix nbdkit to fully support MBR logical
partitions, then rip out the partitioning code in qemu as redundant as
you could get it via nbdkit if you really need it - qemu-nbd's -P 8 has
unchanged, and thus buggy, since at least commit 7a5ca8648 in May 2008,
with no user complaining of a bug for 11 years)

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [RFC] Questions on the I/O performance of emulated host cdrom device

2019-01-18 Thread John Snow



On 1/15/19 9:48 PM, Ying Fang wrote:
> 
> 
> On 2019/1/16 4:15, John Snow wrote:
>>
>>
>> On 1/8/19 10:20 PM, Ying Fang wrote:
>>>
>>>
>>> On 2019/1/8 20:46, Kevin Wolf wrote:
 Am 29.12.2018 um 07:33 hat Ying Fang geschrieben:
> Hi.
> Recently one of our customer complained about the I/O performance of QEMU 
> emulated host cdrom device.
> I did some investigation on it and there was still some point I could not 
> figure out. So I had to ask for your help.
>
> Here is the application scenario setup by our customer.
> filename.iso/dev/sr0   /dev/cdrom
> remote client-->  host(cdemu)  -->  Linux VM
> (1)A remote client maps an iso file to x86 host machine through network 
> using tcp.
> (2)The cdemu daemon then load it as a local virtual cdrom disk drive.
> (3)A VM is launched with the virtual cdrom disk drive configured.
> The VM can make use of this virtual cdrom to install an OS in the iso 
> file.
>
> The network bandwith btw the remote client and host is 100Mbps, we test 
> I/O perf using: dd if=/dev/sr0 of=/dev/null bs=32K count=10.
> And we have
> (1) I/O perf of host side /dev/sr0 is 11MB/s;
> (2) I/O perf of /dev/cdrom inside VM is 3.8MB/s.
>
> As we can see, I/O perf of cdrom inside the VM is about 34.5% compared 
> with host side.
> FlameGraph is used to find out the bottleneck of this operation and we 
> find out that too much time is occupied by calling *bdrv_is_inserted*.
> Then we dig into the code and figure out that the ioctl in 
> *cdrom_is_inserted* takes too much time, because it triggers 
> io_schdule_timeout in kernel.
> In the code path of emulated cdrom device, each DMA I/O request consists 
> of several *bdrv_is_inserted*, which degrades the I/O performance by 
> about 31% in our test.
> static bool cdrom_is_inserted(BlockDriverState *bs)
> {
> BDRVRawState *s = bs->opaque;
> int ret;
>
> ret = ioctl(s->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
> return ret == CDS_DISC_OK;
> }
> A flamegraph svg file (cdrom.svg) is attachieved in this email to show 
> the code timing profile we've tested.
>
> So here is my question.
> (1) Why do we regularly check the presence of a cdrom disk drive in the 
> code path?  Can we do it asynchronously?
>>
>> The ATAPI emulator needs to know if it has storage present to carry out
>> the request or to signal an error, so it checks. It might be the case
>> that the VM operator forcibly dismounted network storage without
>> awareness from the guest. (This is basically emulation of the case when
>> a user mechanically forces a CDROM tray open.)
>>
>> I wasn't aware this check was so slow.
> It is fast enough in most case, however it may be slow if the cdrom drive is 
> a virtual drive mapped from remote client.
> This is showed in 
> https://raw.githubusercontent.com/fangying/fangying.github.io/master/94E119FA-8BA1-41AB-A26A-FBDC635BCD2C.png
> The reason is ioctl(s->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) in 
> cdrom_is_inserted takes much time in this scenario.
> 
>>
>> Maybe we can just cache blk_is_inserted -- I don't remember if it's
>> possible to eject media without awareness from the device model, but if
>> this check winds up being slow in some configurations we can cache it.
> To cache media status is a good idea here, we check blk_is_inserted instead 
> and modify it when media status is changed.
>>
>> This won't help the bdrv_check_byte_request calls, though, just ones
>> from the device model, see below
>>
> (2) Can we drop some check point in the code path to improve the 
> performance?
> Thanks.

 I'm actually not sure why so many places check it. Just letting an I/O
 request fail if the CD was removed would probably be easier.

>>> You can see those check points as showed in the attached flamegraph file in 
>>> this thread (rename it to cdrom.svg).
>>> It is called mainly in bdrv_check_byte_request and ide_atapi_cmd, and only 
>>> the host_cdrom backend implements
>>> it using cdrom_is_inserted.
>>>
>>
>> in ide_atapi_cmd, try replacing:
>>
>> `!s->tray_open && blk_is_inserted(s->blk) && s->cdrom_changed)`
>>
>> with
>>
>> `!s->tray_open && s->cdrom_changed && blk_is_inserted(s->blk))`
>>
>> which should hopefully short-circuit calls to blk_is_inserted if
>> s->cdrom_changed is false, but it doesn't do much to fix the subsequent
>> call:
>>
>> `if ((cmd->flags & CHECK_READY) &&
>> (!media_present(s) || !blk_is_inserted(s->blk)))`
>>
>> which is unfortunately going to check blk_is_inserted quite a lot
>> because the read commands are tagged CHECK_READY...
> Yes you are right.
>>
>>
>> As alluded to above, too, I'm not sure what I can do about
>> bdrv_check_byte_request -- what happens if the io.c helpers don't
>> actually check this? Will they fail gracefully?
>>
>> I guess 

[Qemu-devel] [PATCH 5/5] tests/data: introduce "uefi-boot-images" with the "bios-tables-test" ISOs

2019-01-18 Thread Laszlo Ersek
Add UEFI-bootable qcow2-compressed ISO images built from:

  tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest

Cc: "Michael S. Tsirkin" 
Cc: Ard Biesheuvel 
Cc: Gerd Hoffmann 
Cc: Igor Mammedov 
Cc: Philippe Mathieu-Daudé 
Cc: Shannon Zhao 
Signed-off-by: Laszlo Ersek 
---

Notes:
Again, if needed, I'd be happy to be designated as Maintainer for the
files being added in this patch; please let me know the right spot in
"MAINTAINERS".

 tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2 | Bin 0 -> 
11776 bytes
 tests/data/uefi-boot-images/bios-tables-test.arm.iso.qcow2 | Bin 0 -> 
11776 bytes
 tests/data/uefi-boot-images/bios-tables-test.i386.iso.qcow2| Bin 0 -> 
12800 bytes
 tests/data/uefi-boot-images/bios-tables-test.x86_64.iso.qcow2  | Bin 0 -> 
13312 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2 
b/tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2
new file mode 100644
index 
..fa2cf9291215c2fce59e526e1147be950cdce818
GIT binary patch
literal 11776
zcmeHtbzECrmu_%(3s&4MSg~TI(BQ!xf?IJ4#oY=Ncc(xpQlPjMC|)GRT3m{|yA74^
zoBMlz^WAyxe{*MM?Q`<%XUR_1N^nV4
zg!@DOGeCTBu(Cq9(0agF0Km-J+0}#E#M<>gi~DVdGj(uwe(C7?HzVKxFN{4ssGZF%
zOdVd@ySn_nC;6Z5_46(IU-=(d0l0_n@$ZHXKz-=J|7i#h`1AbT5Fh$K+yBac(+c?i
z$_o|n8?pbJX8FHq{j~xTzZB?zKPdMHr+=v*9{%vvfAGKJZ#xFgU-f^N|B0vkyZ(Rm
z`xDRhSN-4Rf8quImH!`m^uMx0e;F_ee*0l+{y~>N_^{sjuPvsoZrmV{nc2bN2}U%e
z9V^oy@W$t`k5{4ti4a`?ib#uVvA76b3`BK`pf2c^2*wXW3})(RhszfP^RVwNs&2
zhk{mwxJZE3HzL@dLAcL?x+Lp@;Vtd*5mS<@ohWW3>sXxcBPC+3!ks
zii{cbu#`1*{FS8ZsS4^L%QM$wS2xVVlXFvQVlaNWGa)7`0C2s(V*-Wt
z^?}f37$4%yVxbRW21KGG_{jk9Xvi|5Dj-@ofSO4x6o7z+jE=*+|}NW
z`YZ}lE?6Bz1_Dc}gC(Bbzy#2=g=mh5*mXqs|6PB9`CO4ld1hSa0Kw?lWvnhe*K1uv(ZU@s6
z>4%{o$kSPKr)*{0kA^g@8(ktX#V9|vI5siIC_XhYp(Hk5C$s!rE^cf>x^`wsY?@Z4
zZZK_5a)J>A@;){-<@10BBvDr%(@c}q?42fS;tE?LA)NUr0q-&4$;k=ft45#<90Rp0
z5#aie3Q?N?I7to^Bmp^6K^J}6+wYgeJDGua4>kV38D0K8ku@lEQO9n@as?%iw7q>|
zNDU4h5we;FlCM}R{{*mGQ+*kAOowIdSX{DkS|`(8>W`-l)J1oWFXd
z{r2JwSj~FyqM#g7(4Tuk1XD1t``Zcb#?=Yci?>4W62emI4Sg1CKlhY$O$E
zCi(-BAt)VI^tphOEJHaHSy}}3VYmnxc!@o@*8K6z8?$0>0Dg4IaD?{x-`!39*S?(m
z^VLcG>R~qgQ}LJ1AN%}Y)c>Tv?O6ZM^U9yNN52sl00sOMyu{x~Aov>z^M50;lmy_X
z0NJ6xkTm@_lI=z|s+r=U7!ZGJJ7Iz$+Zu%ENE>ew=^(T$iqoIK
z%xp!aHaH4<)6isVPjb6;vb8M!T!7aNW+Ox8Mu*-%GfNl!qbQ^f+#l`l#{J^RPN~8v
zgi%Xq#&@e=1(75bj-OtkNXM+b=Acoyez3g#^vtCyb9IJ#$ejN2tDC;*|E;?02DC
z=a3(f%9#=+c8GxPdbg^G{B9TfYenQGE4M(8LJ(C?%4#hJR51_{+9lqL%jHgvoh{
z4X`?K=E%W5XRYn{Q`7tO8Q=R3dMd!4oP?muc9jt})NlL=)H1xMKsNC9
zN^7hHJS%A;I`$C64#QA@h0+tNFgLeeZ@9Z-DO8mx>OP<~$Y7aS$*$%QIx}`QN?
z`t*tT{5x~^KDI{~A0nMDvyO8Ol=|RVGi+E`h%7to7#MuWZG4D~BlSAIux`!hwoz^L
z@-7f>!3B+JONt`z#3(nad;t9ju%U>4rO~u3;l3=iW#IVM6uY9oIWSq2vm#Pxic=X}
zdjg)qLHe6(EGc_c(YHrR(Hn2|2hf)m$*;KIApYs_?ZdR}qSmX7fw
z=H4I$xAG5K5$%sJ{0qeiLxh=K_P?%RwCwR_V?b!(U^)IrB*D(h#Ujciyq#G_b@1h0
zyyrY*3`5d-_m?4}c~OshS~!|`n|0+yEbim37NQ~C;HN5tqWiWw#Dw$=G*7aw2>BT3
zg{-6n$KxGPF+V2fR?q=F{nsRfHNz(K(r#%3J5epYp;v^E?3gbTUfZx;^Ol_V
zefG1xh8vqyr60AsMM?(a>r}6jeVG3^YJ06lM0)Br)RFxNE)R|$GWgiy$SU|akD-%-
z;l_RTm`neMbOf=$ATwrlV@xI|^;UUP`*o-v(H=zkH$cRPfy$CRJ`3zt
z>?wx+i%8%G=Iz*3#I87$BRLETzIvW9%pT|Tn(nzOu+>Bk;^ZqKqUt9Fyr?TX28D{+
zPU#*l)*4(+XLv;!`6>B1SF%`QOf#O}pmT8~8Ox!9JGY7)#8pC^&3?{;*W0n7B>AJ#
zSFEudCDr!ft~gt>{+OyToV2$zf--(V<6Jybnf_l$^zoxZ6!ZEW+I
zx}#d_ynMX4+{4|j@1^UbJ`|lt>u>dD{^4=}B
zzFWDCcP*<>=MB@8e#>W`h{K`VVrnyKQT{jE3NjV?b1OOB;-eVo$`f@-%0bg
z+CnieiXW+!*Re*><`ntu%*>mA*oVb$<$`tYB@2AHF@!8xb-B*
z;I;Eml~qhjU_0%QjNy;>{KZ17AiSEOL*4HaqA;Y>qlSGdrZ(^P^Sm84NR0g(CN`P{
zo@KLuD)S86xu~;q`}srbIj+#0FgW5$G3z%}7s-b_mtP7-o~E_F46D(5W;Z`~bJ$Bzi#r$8gIR@`ZHD{g~fS4HRgnsQ2yC=O;zphD4Qxgc-jOU!^rFZAN`
z>$>-^p}UNbU0YT46Nr^dOwl7R|1Ri~J13_%n2sNh*@k2Q^UbgJ7tHBls(r|hx(=Q{ba#(u5`y6L$a
zc#jMZ(%@+7zjDPjUfzA~;loYzliS6Q)qDybz<7qmB3CRUOk4Y(g6@mZ%aSwHON!_XXB_YL!}l{-zS*kuUkxHmhY6)m=5@(6
ziIJ))TVD*^oL*p`>cj+w*L%Mbfvdq#E!K6azAZc8px}v)98ZBY)<+E}DT^_Alq4Le
z^Wsle1qpQ$zIX(ZA~={|{ISQ+sT1-R)5=rC8RBL7%H8MhQ
zWUT%=mE$s3C38NB1ws;%lI2%a8Y?HE^UVFs{WxUr6ixL4<6s3`-!a^lrtwoC;At=C
zN+utIa6KbMya*-X1gIb^o*>T|W98$A^YtM#X>)K1dp4G;(GSrypOQ$PQau>%
zl7AwzaFuVR`~?lfspd6I_Q-xQli~F)SiyndtV@wJq~wccwVUR5F8&%0+zBjdOSs_)
zSh2JFT2cagNwLo{on5g@>ZZ?kMD6UkVCPk-5LCbSldQMZC>0WTqd_)Q@8fIm7JU{$sn|wQ}LDNSlm?(hH(_gm-~T2JaO7w<~A^>
ztXiD9TTFwp5UlSTk_B1Gj~#zJt>!}u0h-P9wR5k9yoFY(q{NE6yGnYV(9`5dU)gh{
z2~J^9Z^F~(zYL#ZEb9(a*c{Sb+0qxerG<{kkc_KvpM6tQXDn^#{
zy;P`r!d(ePH%sUj)a!2@0^sI75*w43R%p=vW1^+5fWRt@USIdO6|Hm1^-@<%8gU}vP6%P>
z{mP_G!EWx;VAlM=AVJ-Ngwp_sh@iIqOFSe2B9avU$cHt~ift8jh?%ohSU#kyyVp#g
zqC7mGSW-Vq^TWC-hOqvfixAa9qfnYwoH#nQyS(vw_Q^bct+2XfLo`vkV78M>3#A79_)f+Ax`7itPaJgp3`;5TX00jkhE?Q@fP23pNP^ti
z*A3V3vUFs2^;p*1ICI
zdA!R0^rcLk*L4E7Lx5u=Vaq>UDgB-nXy>Gi}KpJ(96NYTd!JZslFdU+2DH<^R52jC`Y$W
zwzv`XObMCPUFQ3$ugm;~^4PmD>)v|SalsVYf7IVlqG
zqsJV8Tu`JJiXIV=hQ}551mp*a$Quws<6Dmi2tY++g|`XAh8Ea^S#IFX0tGb~z3Xs0
z$3!+oTleS5%fY60Ep)Wq}Pe!Ni+qx2l+QK2s>SV%-YNXwd~s8Z^#@z@V?rBU6D*drnJsh
zTVL|-yDQ@P+_>Mrd?_v|8xhHfhQyH4ku6xl@2$(*ZK8iu-b?wbAE;Xtx`{fkjFpQ*WA~;FBI=

[Qemu-devel] [PATCH 4/5] tests/uefi-test-tools: add build scripts

2019-01-18 Thread Laszlo Ersek
Introduce the following build scripts under "tests/uefi-test-tools":

* "build.sh" builds a single module (a UEFI application) from
  UefiTestToolsPkg, for a single QEMU emulation target.

  "build.sh" relies on cross-compilers when the emulation target and the
  build host architecture don't match. The cross-compiler prefix is
  computed according to a fixed, Linux-specific pattern. No attempt is
  made to copy or reimplement the GNU Make magic from "qemu/roms/Makefile"
  for cross-compiler prefix determination. The reason is that the build
  host OSes that are officially supported by edk2, and those that are
  supported by QEMU, intersect only in Linux. (Note that the UNIXGCC
  toolchain is being removed from edk2,
  .)

* "Makefile" currently builds the "UefiTestToolsPkg/BiosTablesTest"
  application, for arm, aarch64, i386, and x86_64, with the help of
  "build.sh".

  "Makefile" turns each resultant UEFI executable into a UEFI-bootable,
  qcow2-compressed ISO image. The ISO images are output as
  "tests/data/uefi-boot-images/bios-tables-test..iso.qcow2".

  Each ISO image should be passed to QEMU as follows:

-drive id=boot-cd,if=none,readonly,format=qcow2,file=$ISO \
-device virtio-scsi-pci,id=scsi0 \
-device scsi-cd,drive=boot-cd,bus=scsi0.0,bootindex=0 \

  "Makefile" assumes that "mkdosfs", "mtools", and "genisoimage" are
  present.

Cc: "Michael S. Tsirkin" 
Cc: Ard Biesheuvel 
Cc: Gerd Hoffmann 
Cc: Igor Mammedov 
Cc: Philippe Mathieu-Daudé 
Cc: Shannon Zhao 
Signed-off-by: Laszlo Ersek 
---
 tests/uefi-test-tools/Makefile   |  92 +
 tests/uefi-test-tools/.gitignore |   3 +
 tests/uefi-test-tools/build.sh   | 145 
 3 files changed, 240 insertions(+)

diff --git a/tests/uefi-test-tools/Makefile b/tests/uefi-test-tools/Makefile
new file mode 100644
index ..7b6dd227e433
--- /dev/null
+++ b/tests/uefi-test-tools/Makefile
@@ -0,0 +1,92 @@
+# Makefile for the test helper UEFI applications that run in guests.
+#
+# Copyright (C) 2019, Red Hat, Inc.
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License that accompanies this
+# distribution. The full text of the license may be found at
+# .
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+edk2_dir  := ../../roms/edk2
+images_dir:= ../data/uefi-boot-images
+emulation_targets := arm aarch64 i386 x86_64
+uefi_binaries := bios-tables-test
+intermediate_suffixes := .efi .fat .iso.raw
+
+images: $(foreach binary,$(uefi_binaries), \
+   $(foreach target,$(emulation_targets), \
+   $(images_dir)/$(binary).$(target).iso.qcow2))
+
+# Preserve all intermediate targets if the build succeeds.
+# - Intermediate targets help with development & debugging.
+# - Preserving intermediate targets also keeps spurious changes out of the
+#   final build products, in case the user re-runs "make" without any changes
+#   to the UEFI source code. Normally, the intermediate files would have been
+#   removed by the last "make" invocation, hence the re-run would rebuild them
+#   from the unchanged UEFI sources. Unfortunately, the "mkdosfs" and
+#   "genisoimage" utilities embed timestamp-based information in their outputs,
+#   which causes git to report differences for the tracked qcow2 ISO images.
+.SECONDARY: $(foreach binary,$(uefi_binaries), \
+   $(foreach target,$(emulation_targets), \
+   $(foreach suffix,$(intermediate_suffixes), \
+   Build/$(binary).$(target)$(suffix
+
+# In the pattern rules below, the stem (%, $*) stands for
+# "$(binary).$(target)".
+
+# Convert the raw ISO image to a qcow2 one, enabling compression, and using a
+# small cluster size. This allows for small binary files under git control,
+# hence for small binary patches.
+$(images_dir)/%.iso.qcow2: Build/%.iso.raw
+   mkdir -p -- $(images_dir)
+   $${QTEST_QEMU_IMG:-qemu-img} convert -f raw -O qcow2 -c \
+   -o cluster_size=512 -- $< $@
+
+# Embed the "UEFI system partition" into an ISO9660 file system as an ElTorito
+# boot image.
+Build/%.iso.raw: Build/%.fat
+   genisoimage -input-charset ASCII -efi-boot $(notdir $<) -no-emul-boot \
+   -quiet -o $@ -- $<
+
+# Define chained macros in order to map QEMU system emulation targets to
+# *short* UEFI architecture identifiers. Periods are allowed in, and ultimately
+# stripped from, the argument.
+map_arm_to_uefi = $(subst arm,ARM,$(1))
+map_aarch64_to_uefi = $(subst aarch64,AA64,$(call map_arm_to_uefi,$(1)))
+map_i386_to_uefi= $(subst i386,IA32,$(call map_aarch64_to_uefi,$(1)))
+map_x86_64_to_uefi  = $(subst x86_64,X64,$(call 

[Qemu-devel] [PATCH 2/5] roms: build the EfiRom utility from the roms/edk2 submodule

2019-01-18 Thread Laszlo Ersek
Building the EfiRom utility from "roms/edk2/BaseTools" should make
"roms/Makefile" more self-contained. Otherwise, we'd call the system-wide
EfiRom for building the combined iPXE option ROMs, but call the sibling
utilities from "roms/edk2/BaseTools" for building "roms/edk2" content.

Cc: "Michael S. Tsirkin" 
Cc: Ard Biesheuvel 
Cc: Gerd Hoffmann 
Cc: Igor Mammedov 
Cc: Philippe Mathieu-Daudé 
Cc: Shannon Zhao 
Signed-off-by: Laszlo Ersek 
---
 roms/Makefile | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/roms/Makefile b/roms/Makefile
index a6043eff37e9..78d5dd18c301 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -47,10 +47,7 @@ SEABIOS_EXTRAVERSION="-prebuilt.qemu.org"
 # We need that to combine multiple images (legacy bios,
 # efi ia32, efi x64) into a single rom binary.
 #
-# We try to find it in the path.  You can also pass the location on
-# the command line, i.e. "make EFIROM=/path/to/EfiRom efirom"
-#
-EFIROM ?= $(shell which EfiRom 2>/dev/null)
+EFIROM = edk2/BaseTools/Source/C/bin/EfiRom
 
 default:
@echo "nothing is build by default"
@@ -59,8 +56,7 @@ default:
@echo "  vgabios-- update vgabios binaries (seabios)"
@echo "  sgabios-- update sgabios binaries"
@echo "  pxerom -- update nic roms (bios only)"
-   @echo "  efirom -- update nic roms (bios+efi, this needs"
-   @echo "the EfiRom utility from edk2 / tianocore)"
+   @echo "  efirom -- update nic roms (bios+efi)"
@echo "  slof   -- update slof.bin"
@echo "  skiboot-- update skiboot.lid"
@echo "  u-boot.e500-- update u-boot.e500"
@@ -106,7 +102,7 @@ pxe-rom-%: build-pxe-roms
 
 efirom: $(patsubst %,efi-rom-%,$(pxerom_variants))
 
-efi-rom-%: build-pxe-roms build-efi-roms
+efi-rom-%: build-pxe-roms build-efi-roms $(EFIROM)
$(EFIROM) -f "0x$(VID)" -i "0x$(DID)" -l 0x02 \
-b ipxe/src/bin/$(VID)$(DID).rom \
-ec ipxe/src/bin-i386-efi/$(VID)$(DID).efidrv \
@@ -124,6 +120,8 @@ build-efi-roms: build-pxe-roms
$(patsubst %,bin-i386-efi/%.efidrv,$(pxerom_targets)) \
$(patsubst %,bin-x86_64-efi/%.efidrv,$(pxerom_targets))
 
+$(EFIROM):
+   $(MAKE) -C edk2/BaseTools
 
 slof:
$(MAKE) -C SLOF CROSS=$(powerpc64_cross_prefix) qemu
@@ -150,6 +148,7 @@ clean:
$(MAKE) -C sgabios clean
rm -f sgabios/.depend
$(MAKE) -C ipxe/src veryclean
+   $(MAKE) -C edk2/BaseTools clean
$(MAKE) -C SLOF clean
rm -rf u-boot/build.e500
$(MAKE) -C u-boot-sam460ex distclean
-- 
2.19.1.3.g30247aa5d201





[Qemu-devel] [PATCH 3/5] tests: introduce "uefi-test-tools" with the BiosTablesTest UEFI app

2019-01-18 Thread Laszlo Ersek
The "bios-tables-test" program in QEMU's test suite locates the RSD PTR
ACPI table in guest RAM, and (chasing pointers to other ACPI tables)
performs various sanity checks on the QEMU-generated and
firmware-installed tables.

Currently this set of test cases doesn't work with UEFI guests. The ACPI
spec defines distinct methods for OSPM to locate the RSD PTR on
traditional BIOS vs. UEFI platforms, and the UEFI method is more difficult
to implement from the hypervisor side with just raw guest memory access.

Add a UEFI application (to be booted in the UEFI guest) that populates a
small, MB-aligned structure in guest RAM. The structure begins with a
signature GUID. The hypervisor should loop over all MB-aligned pages in
guest RAM until one matches the signature GUID at offset 0, at which point
the hypervisor can fetch the RSDP address field(s) from the structure.

QEMU's test logic currently spins on a pre-determined guest address, until
that address assumes a magic value. The method described in this patch is
conceptually the same ("busy loop until match is found"), except there is
no hard-coded address. This plays a lot more nicely with UEFI guest
firmware (we'll be able to use the normal page allocation UEFI service).
Given the size of EFI_GUID (16 bytes -- 128 bits), mismatches should be
astronomically unlikely. In addition, given the typical guest RAM size for
such tests (128 MB), there are 128 locations to check in one iteration of
the "outer" loop, which shouldn't introduce an intolerable delay after the
guest stores the RSDP address(es), and then the GUID.

The GUID that the hypervisor should search for is

  AB87A6B1-2034-BDA0-71BD-375007757785

Expressed as a byte array:

 {
   0xb1, 0xa6, 0x87, 0xab,
   0x34, 0x20,
   0xa0, 0xbd,
   0x71, 0xbd, 0x37, 0x50, 0x07, 0x75, 0x77, 0x85
 }

Note that in the patch, we define "gBiosTablesTestGuid" with all bits
inverted. This is a simple method to prevent the UEFI binary, which
incorporates "gBiosTablesTestGuid", from matching the actual GUID in guest
RAM.

The UEFI application is written against the edk2 framework, which was
introduced earlier as a git submodule. The next patch will provide build
scripts for maintainers.

The source code follows the edk2 coding style, and is licensed under the
2-clause BSDL (in case someone would like to include UefiTestToolsPkg
content in a different edk2 platform).

The "UefiTestToolsPkg.dsc" platform description file resolves the used
edk2 library classes to instances (= library implementations) such that
the UEFI binaries inherit no platform dependencies. They are expected to
run on any system that conforms to the UEFI-2.3.1 spec (which was released
in 2012). The arch-specific build options are carried over from edk2's
ArmVirtPkg and OvmfPkg platforms.

Cc: "Michael S. Tsirkin" 
Cc: Ard Biesheuvel 
Cc: Gerd Hoffmann 
Cc: Igor Mammedov 
Cc: Philippe Mathieu-Daudé 
Cc: Shannon Zhao 
Signed-off-by: Laszlo Ersek 
---

Notes:
If that's necessary, I'd be glad to be designated as Maintainer or
Reviewer in "MAINTAINERS" for "tests/uefi-test-tools/", I just couldn't
figure out under what subsystem I should add the magic lines.
"MAINTAINERS" needs a Table of Contents! :)

 tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dec  |  27 

 tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dsc  |  69 
+++
 tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.inf |  41 
++
 tests/uefi-test-tools/UefiTestToolsPkg/Include/Guid/BiosTablesTest.h |  67 
++
 tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.c   | 130 

 tests/uefi-test-tools/LICENSE|  25 

 6 files changed, 359 insertions(+)

diff --git a/tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dec 
b/tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dec
new file mode 100644
index ..ed3a2fe11084
--- /dev/null
+++ b/tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dec
@@ -0,0 +1,27 @@
+## @file
+# edk2 package declaration for the test helper UEFI applications that run in
+# guests.
+#
+# Copyright (C) 2019, Red Hat, Inc.
+#
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License that accompanies this
+# distribution. The full text of the license may be found at
+# .
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+##
+
+[Defines]
+  DEC_SPECIFICATION = 1.27
+  PACKAGE_NAME  = UefiTestToolsPkg
+  PACKAGE_GUID  = 7b3f1794-0c85-4b27-a536-44dbf0b0669c
+  PACKAGE_VERSION   = 0.1
+
+[Includes]
+  Include
+
+[Guids]
+  gBiosTablesTestGuid = {0x5478594e, 0xdfcb, 0x425f, {0x8e, 0x42, 0xc8, 0xaf, 
0xf8, 0x8a, 0x88, 0x7a}}
+
diff --git 

[Qemu-devel] [PATCH 1/5] roms: add the edk2 project as a git submodule

2019-01-18 Thread Laszlo Ersek
The roms/edk2 submodule can help with three goals:
- build the OVMF and ArmVirtQemu virtual UEFI firmware platforms (to be
  implemented later),
- build the EfiRom tool on the fly, which is used in roms/Makefile, for
  building the "efirom" target,
- build UEFI test applications (to be run in guests), for qtest support.

Edk2 commit 85588389222a3636baf0f9ed8227f2434af4c3f9 stands for the latest
"stable tag", namely "edk2-stable201811".

The edk2 repository tracks some binary files that should not be removed by
QEMU's top-level "make clean"; exempt the full pathnames from the "find"
command.

Cc: "Michael S. Tsirkin" 
Cc: Ard Biesheuvel 
Cc: Gerd Hoffmann 
Cc: Igor Mammedov 
Cc: Philippe Mathieu-Daudé 
Cc: Shannon Zhao 
Signed-off-by: Laszlo Ersek 
---
 Makefile| 6 +-
 .gitmodules | 3 +++
 roms/edk2   | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index dccba1dca27f..1f768e2bcf8f 100644
--- a/Makefile
+++ b/Makefile
@@ -602,7 +602,11 @@ clean:
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
rm -f qemu-options.def
rm -f *.msi
-   find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name 
'*.[oda]' \) -type f -exec rm {} +
+   find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name 
'*.[oda]' \) -type f \
+   ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-aarch64.a \
+   ! -path ./roms/edk2/ArmPkg/Library/GccLto/liblto-arm.a \
+   ! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll 
\
+   -exec rm {} +
rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* 
*.pod *~ */*~
rm -f fsdev/*.pod scsi/*.pod
rm -f qemu-img-cmds.h
diff --git a/.gitmodules b/.gitmodules
index 6b91176098c8..ceafb0ee29a0 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -49,3 +49,6 @@
 [submodule "tests/fp/berkeley-softfloat-3"]
path = tests/fp/berkeley-softfloat-3
url = https://github.com/cota/berkeley-softfloat-3
+[submodule "roms/edk2"]
+   path = roms/edk2
+   url = https://github.com/tianocore/edk2.git
diff --git a/roms/edk2 b/roms/edk2
new file mode 16
index ..85588389222a
--- /dev/null
+++ b/roms/edk2
@@ -0,0 +1 @@
+Subproject commit 85588389222a3636baf0f9ed8227f2434af4c3f9
-- 
2.19.1.3.g30247aa5d201





[Qemu-devel] [PATCH 0/5] add the BiosTablesTest UEFI app, build it with the new roms/edk2 submodule

2019-01-18 Thread Laszlo Ersek
Igor's series

  [Qemu-devel] [PATCH 00/14] tests: acpi: add UEFI (ARM) testing support
  
1547566866-129386-1-git-send-email-imammedo@redhat.com">http://mid.mail-archive.com/1547566866-129386-1-git-send-email-imammedo@redhat.com

worked with my edk2 (guest firmware) series

  [edk2] [PATCH 0/4] OvmfPkg, ArmVirtPkg: add ACPI Test Support
  http://mid.mail-archive.com/20181125100152.25675-1-lersek@redhat.com

as long as the guest firmware was built with the necessary extra build
flag.

However, in the discussion under Igor's series, we seemed to reconsider
a standalone UEFI application for the QEMU tree to carry. This series
seeks to implement that option.

Cc: "Michael S. Tsirkin" 
Cc: Ard Biesheuvel 
Cc: Gerd Hoffmann 
Cc: Igor Mammedov 
Cc: Philippe Mathieu-Daudé 
Cc: Shannon Zhao 

Thanks,
Laszlo

Laszlo Ersek (5):
  roms: add the edk2 project as a git submodule
  roms: build the EfiRom utility from the roms/edk2 submodule
  tests: introduce "uefi-test-tools" with the BiosTablesTest UEFI app
  tests/uefi-test-tools: add build scripts
  tests/data: introduce "uefi-boot-images" with the "bios-tables-test"
ISOs

 .gitmodules  |   3 
+
 Makefile |   6 
+-
 roms/Makefile|  13 
+-
 roms/edk2|   1 
+
 tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2   | Bin 
0 -> 11776 bytes
 tests/data/uefi-boot-images/bios-tables-test.arm.iso.qcow2   | Bin 
0 -> 11776 bytes
 tests/data/uefi-boot-images/bios-tables-test.i386.iso.qcow2  | Bin 
0 -> 12800 bytes
 tests/data/uefi-boot-images/bios-tables-test.x86_64.iso.qcow2| Bin 
0 -> 13312 bytes
 tests/uefi-test-tools/.gitignore |   3 
+
 tests/uefi-test-tools/LICENSE|  25 

 tests/uefi-test-tools/Makefile   |  92 
+
 tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.c   | 130 
++
 tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.inf |  41 
++
 tests/uefi-test-tools/UefiTestToolsPkg/Include/Guid/BiosTablesTest.h |  67 
+
 tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dec  |  27 

 tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dsc  |  69 
++
 tests/uefi-test-tools/build.sh   | 145 

 17 files changed, 614 insertions(+), 8 deletions(-)
 create mode 16 roms/edk2
 create mode 100644 
tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2
 create mode 100644 tests/data/uefi-boot-images/bios-tables-test.arm.iso.qcow2
 create mode 100644 tests/data/uefi-boot-images/bios-tables-test.i386.iso.qcow2
 create mode 100644 
tests/data/uefi-boot-images/bios-tables-test.x86_64.iso.qcow2
 create mode 100644 tests/uefi-test-tools/.gitignore
 create mode 100644 tests/uefi-test-tools/LICENSE
 create mode 100644 tests/uefi-test-tools/Makefile
 create mode 100644 
tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.c
 create mode 100644 
tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.inf
 create mode 100644 
tests/uefi-test-tools/UefiTestToolsPkg/Include/Guid/BiosTablesTest.h
 create mode 100644 tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dec
 create mode 100644 tests/uefi-test-tools/UefiTestToolsPkg/UefiTestToolsPkg.dsc
 create mode 100755 tests/uefi-test-tools/build.sh

-- 
2.19.1.3.g30247aa5d201




[Qemu-devel] [PATCH] fw_cfg: fix the life cycle and the name of "qemu_extra_params_fw"

2019-01-18 Thread Laszlo Ersek
Commit 19bcc4bc3213 ("fw_cfg: Make qemu_extra_params_fw locally",
2019-01-04) changed the storage duration of the "qemu_extra_params_fw"
array from static to automatic. This broke the interface contract on the
fw_cfg_add_file() function, which is documented as follows, in
"include/hw/nvram/fw_cfg.h":

> [...] The data referenced by the starting pointer is only linked, NOT
> copied, into the data structure of the fw_cfg device. [...]

As a result, when guest firmware fetches the "etc/boot-menu-wait" fw_cfg
file, it now sees garbage. Fix the regression by changing the storage
duration to allocated. (The call is reached at most once, on the realize
path of the board-specific fw_cfg sysbus device.)

While at it, clean up the name and the assignment of the object as well.

Cc: Gerd Hoffmann 
Cc: Markus Armbruster 
Cc: Philippe Mathieu-Daudé 
Fixes: 19bcc4bc3213e78c303ad480a7a578f62258252d
Signed-off-by: Laszlo Ersek 
---
 hw/nvram/fw_cfg.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 53e8e010a8b7..7fdf04adc97f 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 {
 const char *boot_splash_filename = NULL;
 const char *boot_splash_time = NULL;
-uint8_t qemu_extra_params_fw[2];
 char *filename, *file_data;
 gsize file_size;
 int file_type;
@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 /* insert splash time if user configurated */
 if (boot_splash_time) {
 int64_t bst_val = qemu_opt_get_number(opts, "splash-time", -1);
+uint16_t bst_le16;
+
 /* validate the input */
 if (bst_val < 0 || bst_val > 0x) {
 error_report("splash-time is invalid,"
@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 exit(1);
 }
 /* use little endian format */
-qemu_extra_params_fw[0] = (uint8_t)(bst_val & 0xff);
-qemu_extra_params_fw[1] = (uint8_t)((bst_val >> 8) & 0xff);
-fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+bst_le16 = cpu_to_le16(bst_val);
+fw_cfg_add_file(s, "etc/boot-menu-wait",
+g_memdup(_le16, sizeof bst_le16), sizeof bst_le16);
 }
 
 /* insert splash file if user configurated */
-- 
2.19.1.3.g30247aa5d201




Re: [Qemu-devel] [PATCH] target/s390x: define TCG_GUEST_DEFAULT_MO for MTTCG

2019-01-18 Thread Richard Henderson
On 1/19/19 4:18 AM, Alex Bennée wrote:
> MTTCG should be enabled by default whenever the memory model allows
> it. s390x was missing its definition of TCG_GUEST_DEFAULT_MO meaning
> the user had to manually specify  --accel tcg,thread=multi.
> 
> Signed-off-by: Alex Bennée 
> Cc: David Hildenbrand 
> ---
>  target/s390x/cpu.h | 4 
>  1 file changed, 4 insertions(+)

I thought we had already done this...

Reviewed-by: Richard Henderson 


r~



Re: [Qemu-devel] [PATCH v10 14/14] target/arm: Send interrupts on PMU counter overflow

2019-01-18 Thread Aaron Lindsay
On Jan 18 07:26, Richard Henderson wrote:
> On 12/12/18 2:20 AM, Aaron Lindsay wrote:
> > Setup a QEMUTimer to get a callback when we expect counters to next
> > overflow and trigger an interrupt at that time.
> > 
> > Signed-off-by: Aaron Lindsay 
> > Signed-off-by: Aaron Lindsay 
> > ---
> >  target/arm/cpu.c|  12 +
> >  target/arm/cpu.h|   8 +++
> >  target/arm/helper.c | 126 +---
> >  3 files changed, 140 insertions(+), 6 deletions(-)
> 
> Well, this patch is doing several things at once -- adding the timer, adding
> the ns_per_count hook, updating irqs.  Not ideal, but I won't insist it be 
> split.
> 
> You'll need to re-run against scripts/checkpatch, it would seem.
> The goal-posts with respect to comments have been changed since
> you started this.

Okay, I'll check that again before I send the next version out.

> > @@ -1305,7 +1338,19 @@ void pmccntr_op_start(CPUARMState *env)
> >  eff_cycles /= 64;
> >  }
> >  
> > -env->cp15.c15_ccnt = eff_cycles - env->cp15.c15_ccnt_delta;
> > +uint64_t new_pmccntr = eff_cycles - env->cp15.c15_ccnt_delta;
> > +
> > +unsigned int overflow_bit = (env->cp15.c9_pmcr & PMCRLC) ? 63 : 31;
> > +uint64_t overflow_mask = (uint64_t)1 << overflow_bit;
> 
> Could just as easily be
> 
>   uint64_t overflow_mask = env->cp15.c9_pmcr & PMCRLC ? INT64_MIN : INT32_MIN;

Updated.

> > +if (env->cp15.c15_ccnt & ~new_pmccntr & overflow_mask) {
> > +env->cp15.c9_pmovsr |= (1 << 31);
> > +if (!(env->cp15.c9_pmcr & PMCRLC)) {
> > +new_pmccntr &= 0x;
> > +}
> 
> Why is this truncation buried within the overflow condition?  Simply because
> the high bits can't be set without overflow being noticed?  That could use a
> comment, because it looks odd.

Upon re-reading the spec, I don't think this is needed (or even correct
behavior). I must've been thinking that PMCR.LC == 0 implied that upper
32 bits could never be updated by the hardware and made PMCCNTR act like
its high bits didn't even exist, like one of the PMXEVCNTRs. I no longer
believe that is true and I'll remove this.

> > @@ -1340,8 +1399,15 @@ static void pmevcntr_op_start(CPUARMState *env, 
> > uint8_t counter)
> >  }
> >  
> >  if (pmu_counter_enabled(env, counter)) {
> > -env->cp15.c14_pmevcntr[counter] =
> > -count - env->cp15.c14_pmevcntr_delta[counter];
> > +uint64_t new_pmevcntr = count - 
> > env->cp15.c14_pmevcntr_delta[counter];
> > +
> > +if (!(new_pmevcntr & PMEVCNTR_OVERFLOW_MASK) &&
> > +(env->cp15.c14_pmevcntr[counter] & 
> > PMEVCNTR_OVERFLOW_MASK)) {
> > +env->cp15.c9_pmovsr |= (1 << counter);
> > +new_pmevcntr &= ~PMEVCNTR_OVERFLOW_MASK;
> 
> That, surely, does not do what you intend.  I can only imagine that you meant
> 
> new_pmevcntr = (uint32_t)new_pmevcntr;
> or
> new_pmevcntr &= PMEVCNTR_OVERFLOW_MASK - 1;
> 
> depending on how much you want to depend on the symbol defining the width.

In practice, I think only the 32nd bit would ever need to be cleared,
but I agree it is more correct to clear them all.

> Given that it is architecturally defined to 32-bits, I think you could really
> just drop the define and use
> 
> uint32_t new_pmevcntr = ...;
> if (env->cp15.c14_pmevcntr[counter] & ~new_pmevcntr & INT32_MIN)
>
> with equal clarity.

I don't know whether it is important for the resolution of this patch,
but what did you mean by the following?:

> The type of new_pmevcntr means you don't have to clear any
> high bits either.

> > +/* Detect if this write causes an overflow since we can't 
> > predict
> > + * PMSWINC overflows like we can for other events
> > + */
> > +uint64_t new_pmswinc = env->cp15.c14_pmevcntr[i] + 1;
> > +
> > +if (!(new_pmswinc & PMEVCNTR_OVERFLOW_MASK) &&
> > +(env->cp15.c14_pmevcntr[i] & PMEVCNTR_OVERFLOW_MASK)) {
> > +env->cp15.c9_pmovsr |= (1 << i);
> > +new_pmswinc &= ~PMEVCNTR_OVERFLOW_MASK;
> 
> Likewise.

Thanks,

Aaron



[Qemu-devel] [PATCH v6 47/49] linux-user: Move syscall_init to the end

2019-01-18 Thread Richard Henderson
No functional change.  This will aid moving everything
related to ioctls to a separate file.

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

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 33d536262f..82b7267b20 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4778,58 +4778,6 @@ _syscall1(int, sys_setgid, gid_t, gid)
 _syscall3(int, sys_setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
 _syscall3(int, sys_setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
 
-void syscall_init(void)
-{
-IOCTLEntry *ie;
-const argtype *arg_type;
-int size;
-int i;
-
-thunk_init(STRUCT_MAX);
-
-#define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, 
struct_ ## name ## _def);
-#define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, 
#name, _ ## name ## _def);
-#include "syscall_types.h"
-#undef STRUCT
-#undef STRUCT_SPECIAL
-
-/* Build target_to_host_errno_table[] table from
- * host_to_target_errno_table[]. */
-for (i = 0; i < ERRNO_TABLE_SIZE; i++) {
-target_to_host_errno_table[host_to_target_errno_table[i]] = i;
-}
-
-/* we patch the ioctl size if necessary. We rely on the fact that
-   no ioctl has all the bits at '1' in the size field */
-ie = ioctl_entries;
-while (ie->target_cmd != 0) {
-if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) ==
-TARGET_IOC_SIZEMASK) {
-arg_type = ie->arg_type;
-if (arg_type[0] != TYPE_PTR) {
-fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
-ie->target_cmd);
-exit(1);
-}
-arg_type++;
-size = thunk_type_size(arg_type, 0);
-ie->target_cmd = (ie->target_cmd &
-  ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) |
-(size << TARGET_IOC_SIZESHIFT);
-}
-
-/* automatic consistency check if same arch */
-#if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
-(defined(__x86_64__) && defined(TARGET_X86_64))
-if (unlikely(ie->target_cmd != ie->host_cmd)) {
-fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
-ie->name, ie->target_cmd, ie->host_cmd);
-}
-#endif
-ie++;
-}
-}
-
 static inline uint64_t target_offset64(abi_ulong word0, abi_ulong word1)
 {
 #if TARGET_ABI_BITS == 64
@@ -8983,3 +8931,64 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 trace_guest_user_syscall_ret(cpu, num, ret);
 return ret;
 }
+
+void syscall_init(void)
+{
+IOCTLEntry *ie;
+const argtype *arg_type;
+int size;
+int i;
+
+thunk_init(STRUCT_MAX);
+
+#define STRUCT(name, ...) \
+thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
+#define STRUCT_SPECIAL(name) \
+thunk_register_struct_direct(STRUCT_ ## name, #name, \
+ _ ## name ## _def);
+
+#include "syscall_types.h"
+
+#undef STRUCT
+#undef STRUCT_SPECIAL
+
+/*
+ * Build target_to_host_errno_table[] table from
+ * host_to_target_errno_table[].
+ */
+for (i = 0; i < ERRNO_TABLE_SIZE; i++) {
+target_to_host_errno_table[host_to_target_errno_table[i]] = i;
+}
+
+/*
+ * We patch the ioctl size if necessary.  We rely on the fact that
+ * no ioctl has all the bits at '1' in the size field.
+ */
+ie = ioctl_entries;
+while (ie->target_cmd != 0) {
+if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) ==
+TARGET_IOC_SIZEMASK) {
+arg_type = ie->arg_type;
+if (arg_type[0] != TYPE_PTR) {
+fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
+ie->target_cmd);
+exit(1);
+}
+arg_type++;
+size = thunk_type_size(arg_type, 0);
+ie->target_cmd = (ie->target_cmd &
+  ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) |
+(size << TARGET_IOC_SIZESHIFT);
+}
+
+/* automatic consistency check if same arch */
+#if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
+(defined(__x86_64__) && defined(TARGET_X86_64))
+if (unlikely(ie->target_cmd != ie->host_cmd)) {
+fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
+ie->name, ie->target_cmd, ie->host_cmd);
+}
+#endif
+ie++;
+}
+}
-- 
2.17.2




[Qemu-devel] [PATCH v6 44/49] linux-user: Split out pipe, pipe2

2019-01-18 Thread Richard Henderson
Note that pipe2 is universally available for guests.
Implement host support with syscall when !CONFIG_PIPE2.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h | 10 ++
 linux-user/syscall-file.inc.c | 51 +++
 linux-user/syscall.c  | 65 +++
 linux-user/strace.list|  6 
 4 files changed, 74 insertions(+), 58 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 062a75..bd3301a72f 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -132,6 +132,16 @@ SYSCALL_DEF(open_by_handle_at, ARG_DEC, ARG_PTR, 
ARG_OPENFLAG);
 #ifdef TARGET_NR_pause
 SYSCALL_DEF(pause);
 #endif
+#ifdef TARGET_NR_pipe
+# if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || \
+ defined(TARGET_SH4) || defined(TARGET_SPARC)
+/* ??? We have no way for strace to display the second returned fd.  */
+SYSCALL_DEF(pipe);
+# else
+SYSCALL_DEF(pipe, ARG_PTR);
+# endif
+#endif
+SYSCALL_DEF(pipe2, ARG_PTR, ARG_OPENFLAG);
 SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
  .args = args_pread64_pwrite64,
  .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 5e8298fdb3..90aacfacaf 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -720,6 +720,57 @@ SYSCALL_IMPL(open_by_handle_at)
 return ret;
 }
 
+static abi_long do_pipe(CPUArchState *cpu_env, abi_ulong target_fds,
+int target_flags, bool is_pipe2)
+{
+int host_flags = target_to_host_bitmask(target_flags, fcntl_flags_tbl);
+int host_fds[2];
+abi_long ret;
+
+ret = pipe2(host_fds, host_flags);
+if (is_error(ret)) {
+return get_errno(ret);
+}
+
+/*
+ * Several targets have special calling conventions for the original
+ * pipe syscall, but didn't replicate this into the pipe2 syscall.
+ */
+if (!is_pipe2) {
+#if defined(TARGET_ALPHA)
+cpu_env->ir[IR_A4] = host_fds[1];
+return host_fds[0];
+#elif defined(TARGET_MIPS)
+cpu_env->active_tc.gpr[3] = host_fds[1];
+return host_fds[0];
+#elif defined(TARGET_SH4)
+cpu_env->gregs[1] = host_fds[1];
+return host_fds[0];
+#elif defined(TARGET_SPARC)
+cpu_env->regwptr[1] = host_fds[1];
+return host_fds[0];
+#endif
+}
+
+if (put_user_s32(host_fds[0], target_fds)
+|| put_user_s32(host_fds[1], target_fds + 4)) {
+return -TARGET_EFAULT;
+}
+return 0;
+}
+
+#ifdef TARGET_NR_pipe
+SYSCALL_IMPL(pipe)
+{
+return do_pipe(cpu_env, arg1, 0, false);
+}
+#endif
+
+SYSCALL_IMPL(pipe2)
+{
+return do_pipe(cpu_env, arg1, arg2, true);
+}
+
 /*
  * Both pread64 and pwrite64 merge args into a 64-bit offset,
  * but the input registers and ordering are target specific.
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 29a9d5fce4..3a322a61ca 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -207,6 +207,9 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 
arg4,type5 arg5,   \
 #ifndef __NR_dup3
 #define __NR_dup3  -1
 #endif
+#ifndef __NR_pipe2
+#define __NR_pipe2  -1
+#endif
 #ifndef __NR_syncfs
 #define __NR_syncfs  -1
 #endif
@@ -283,6 +286,16 @@ _syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type,
 #ifndef CONFIG_SYNCFS
 _syscall1(int, syncfs, int, fd)
 #endif
+#ifndef CONFIG_PIPE2
+static int pipe2(int *fds, int flags)
+{
+if (flags) {
+return syscall(__NR_pipe2, fds, flags);
+} else {
+return pipe(fds);
+}
+}
+#endif
 
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,O_ACCMODE,   O_WRONLY,},
@@ -1134,49 +1147,6 @@ static abi_long do_old_select(abi_ulong arg1)
 #endif
 #endif
 
-static abi_long do_pipe2(int host_pipe[], int flags)
-{
-#ifdef CONFIG_PIPE2
-return pipe2(host_pipe, flags);
-#else
-return -ENOSYS;
-#endif
-}
-
-static abi_long do_pipe(void *cpu_env, abi_ulong pipedes,
-int flags, int is_pipe2)
-{
-int host_pipe[2];
-abi_long ret;
-ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe);
-
-if (is_error(ret))
-return get_errno(ret);
-
-/* Several targets have special calling conventions for the original
-   pipe syscall, but didn't replicate this into the pipe2 syscall.  */
-if (!is_pipe2) {
-#if defined(TARGET_ALPHA)
-((CPUAlphaState *)cpu_env)->ir[IR_A4] = host_pipe[1];
-return host_pipe[0];
-#elif defined(TARGET_MIPS)
-((CPUMIPSState*)cpu_env)->active_tc.gpr[3] = host_pipe[1];
-return host_pipe[0];
-#elif defined(TARGET_SH4)
-((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
-return host_pipe[0];
-#elif defined(TARGET_SPARC)
-((CPUSPARCState*)cpu_env)->regwptr[1] = host_pipe[1];
-return host_pipe[0];
-#endif
-}
-
-if 

[Qemu-devel] [PATCH v6 40/49] linux-user: Split out kill

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h|  1 +
 linux-user/syscall.h |  7 +++-
 linux-user/strace.c  | 76 ++--
 linux-user/syscall-sig.inc.c |  5 +++
 linux-user/syscall.c |  2 -
 linux-user/strace.list   |  3 --
 6 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 497fbdba66..c672b5ad99 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -58,6 +58,7 @@ SYSCALL_DEF(getxpid);
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
+SYSCALL_DEF(kill, ARG_DEC, ARG_SIGNAL);
 #ifdef TARGET_NR_link
 SYSCALL_DEF(link, ARG_STR, ARG_STR);
 #endif
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index 84a52b2d9a..642fb6dccb 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -55,8 +55,12 @@ typedef enum {
 ARG_HEX,
 ARG_OCT,
 
-/* These print as sets of flags.  */
+/* These numbers are interpreted.  */
 ARG_ATDIRFD,
+ARG_SIGNAL,
+ARG_LSEEKWHENCE,
+
+/* These print as sets of flags.  */
 ARG_ACCESSFLAG,
 ARG_ATFLAG,
 ARG_CLONEFLAG,
@@ -67,7 +71,6 @@ typedef enum {
 ARG_OPENFLAG,
 ARG_UMOUNTFLAG,
 ARG_UNLINKATFLAG,
-ARG_LSEEKWHENCE,
 
 /* These are interpreted as pointers.  */
 ARG_PTR,
diff --git a/linux-user/strace.c b/linux-user/strace.c
index da2cc30f82..ec36fcf2c2 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -70,35 +70,43 @@ UNUSED static void print_socket_protocol(int domain, int 
type, int protocol);
 /*
  * Utility functions
  */
+static int
+add_signal(char *buf, int size, int sig)
+{
+static const char * const signals[] = {
+[TARGET_SIGHUP]  = "SIGHUP",
+[TARGET_SIGINT]  = "SIGINT",
+[TARGET_SIGQUIT] = "SIGQUIT",
+[TARGET_SIGILL]  = "SIGILL",
+[TARGET_SIGABRT] = "SIGABRT",
+[TARGET_SIGFPE]  = "SIGFPE",
+[TARGET_SIGKILL] = "SIGKILL",
+[TARGET_SIGSEGV] = "SIGSEGV",
+[TARGET_SIGPIPE] = "SIGPIPE",
+[TARGET_SIGALRM] = "SIGALRM",
+[TARGET_SIGTERM] = "SIGTERM",
+[TARGET_SIGUSR1] = "SIGUSR1",
+[TARGET_SIGUSR2] = "SIGUSR2",
+[TARGET_SIGCHLD] = "SIGCHLD",
+[TARGET_SIGCONT] = "SIGCONT",
+[TARGET_SIGSTOP] = "SIGSTOP",
+[TARGET_SIGTTIN] = "SIGTTIN",
+[TARGET_SIGTTOU] = "SIGTTOU",
+};
+
+if (sig >= 0 && sig < ARRAY_SIZE(signals) && signals[sig]) {
+return snprintf(buf, size, "%s", signals[sig]);
+} else {
+return snprintf(buf, size, "%d", sig);
+}
+}
+
 static void
 print_signal(abi_ulong arg, int last)
 {
-const char *signal_name = NULL;
-switch(arg) {
-case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
-case TARGET_SIGINT: signal_name = "SIGINT"; break;
-case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
-case TARGET_SIGILL: signal_name = "SIGILL"; break;
-case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
-case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
-case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
-case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
-case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
-case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
-case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
-case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
-case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
-case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
-case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
-case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
-case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
-case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
-}
-if (signal_name == NULL) {
-print_raw_param("%ld", arg, last);
-return;
-}
-gemu_log("%s%s", signal_name, get_comma(last));
+char buf[16];
+add_signal(buf, sizeof(buf), arg);
+gemu_log("%s%s", buf, get_comma(last));
 }
 
 static void print_si_code(int arg)
@@ -2032,19 +2040,6 @@ print_futex(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_kill
-static void
-print_kill(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_raw_param("%d", arg0, 0);
-print_signal(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_tkill
 static void
 print_tkill(const struct syscallname *name,
@@ -2178,6 +2173,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_ATDIRFD:
 len = add_atdirfd(b, rest, arg);
 break;
+case ARG_SIGNAL:
+len = add_signal(b, rest, arg);
+break;
 case ARG_ACCESSFLAG:
 len = add_flags(b, rest, 

[Qemu-devel] [PATCH v6 33/49] linux-user: Split out umount, umount2

2019-01-18 Thread Richard Henderson
Note that umount2 is unconditionally available.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  4 
 linux-user/syscall.h  |  1 +
 linux-user/strace.c   | 30 --
 linux-user/syscall-file.inc.c | 25 +
 linux-user/syscall.c  | 16 
 linux-user/strace.list|  6 --
 6 files changed, 34 insertions(+), 48 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 2b331c6a6d..0d8da0c6d6 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -155,6 +155,10 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 #ifdef TARGET_NR_time
 SYSCALL_DEF(time, ARG_PTR);
 #endif
+#ifdef TARGET_NR_umount
+SYSCALL_DEF(umount, ARG_STR);
+#endif
+SYSCALL_DEF(umount2, ARG_STR, ARG_UMOUNTFLAG);
 #ifdef TARGET_NR_unlink
 SYSCALL_DEF(unlink, ARG_STR);
 #endif
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index 35dd3e5fa3..3c936b648a 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -64,6 +64,7 @@ typedef enum {
 ARG_MODEFLAG,
 ARG_MOUNTFLAG,
 ARG_OPENFLAG,
+ARG_UMOUNTFLAG,
 ARG_UNLINKATFLAG,
 ARG_LSEEKWHENCE,
 
diff --git a/linux-user/strace.c b/linux-user/strace.c
index eb02430eba..78781b8817 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -733,7 +733,7 @@ static struct flags const mount_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags umount2_flags[] = {
+static struct flags const umount2_flags[] = {
 #ifdef MNT_FORCE
 FLAG_GENERIC(MNT_FORCE),
 #endif
@@ -2003,31 +2003,6 @@ print_symlinkat(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_umount
-static void
-print_umount(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_umount2
-static void
-print_umount2(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_flags(umount2_flags, arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_utime
 static void
 print_utime(const struct syscallname *name,
@@ -2293,6 +2268,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_OPENFLAG:
 len = add_open_flags(b, rest, arg);
 break;
+case ARG_UMOUNTFLAG:
+len = add_flags(b, rest, umount2_flags, arg, false);
+break;
 case ARG_UNLINKATFLAG:
 len = add_flags(b, rest, unlinkat_flags, arg, true);
 break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index d7eb72cc31..7ec1c26347 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -810,6 +810,31 @@ SYSCALL_IMPL(readlinkat)
 }
 #endif
 
+static abi_long do_umount2(abi_ulong target_path, int flags)
+{
+char *p = lock_user_string(target_path);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(umount2(p, flags));
+unlock_user(p, target_path, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_umount
+SYSCALL_IMPL(umount)
+{
+return do_umount2(arg1, 0);
+}
+#endif
+
+SYSCALL_IMPL(umount2)
+{
+return do_umount2(arg1, arg2);
+}
+
 static abi_long do_unlinkat(int dirfd, abi_ulong target_path, int flags)
 {
 char *p = lock_user_string(target_path);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 39e749a985..b35d84794f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5327,14 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_umount
-case TARGET_NR_umount:
-if (!(p = lock_user_string(arg1)))
-return -TARGET_EFAULT;
-ret = get_errno(umount(p));
-unlock_user(p, arg1, 0);
-return ret;
-#endif
 #ifdef TARGET_NR_stime /* not on alpha */
 case TARGET_NR_stime:
 {
@@ -,14 +5547,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 unlock_user(p, arg1, 0);
 }
 return ret;
-#ifdef TARGET_NR_umount2
-case TARGET_NR_umount2:
-if (!(p = lock_user_string(arg1)))
-return -TARGET_EFAULT;
-ret = get_errno(umount2(p, arg2));
-unlock_user(p, arg1, 0);
-return ret;
-#endif
 case TARGET_NR_ioctl:
 return do_ioctl(arg1, arg2, arg3);
 #ifdef TARGET_NR_fcntl
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 5f07e0e23d..0f32c456cd 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1368,12 +1368,6 @@
 #ifdef TARGET_NR_umask
 { TARGET_NR_umask, "umask" , "%s(%#o)", NULL, NULL },
 #endif

[Qemu-devel] [PATCH v6 29/49] linux-user: Split out chmod, fchmod, fchmodat

2019-01-18 Thread Richard Henderson
Note that fchmodat is universally provided.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  5 +
 linux-user/strace.c   | 28 
 linux-user/syscall-file.inc.c | 30 ++
 linux-user/syscall.c  | 18 --
 linux-user/strace.list|  9 -
 5 files changed, 35 insertions(+), 55 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index b5951e6911..3ddf8aa0e3 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -20,6 +20,9 @@ SYSCALL_DEF_FULL(brk, .impl = impl_brk,
  .print_ret = print_syscall_ptr_ret,
  .arg_type = { ARG_PTR });
 SYSCALL_DEF(chdir, ARG_STR);
+#ifdef TARGET_NR_chmod
+SYSCALL_DEF(chmod, ARG_STR, ARG_MODEFLAG);
+#endif
 SYSCALL_DEF_ARGS(clone, ARG_CLONEFLAG, ARG_PTR, ARG_PTR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(close, ARG_DEC);
 #ifdef TARGET_NR_creat
@@ -28,6 +31,8 @@ SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
 SYSCALL_DEF(exit, ARG_DEC);
 SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
+SYSCALL_DEF(fchmod, ARG_DEC, ARG_MODEFLAG);
+SYSCALL_DEF(fchmodat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG);
 #ifdef TARGET_NR_fork
 SYSCALL_DEF(fork);
 #endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 668e6a4759..66d981b9e6 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1113,19 +1113,6 @@ print_access(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_chmod
-static void
-print_chmod(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_file_mode(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_clock_adjtime
 static void
 print_clock_adjtime(const struct syscallname *name,
@@ -1167,21 +1154,6 @@ print_faccessat(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_fchmodat
-static void
-print_fchmodat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_file_mode(arg2, 0);
-print_flags(at_file_flags, arg3, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_fchownat
 static void
 print_fchownat(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 3b5a79fe74..9844382166 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -30,6 +30,26 @@ SYSCALL_IMPL(chdir)
 return ret;
 }
 
+static abi_long do_fchmodat(int dirfd, abi_ulong target_path, mode_t mode)
+{
+char *p = lock_user_string(target_path);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(fchmodat(dirfd, p, mode, 0));
+unlock_user(p, target_path, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_chmod
+SYSCALL_IMPL(chmod)
+{
+return do_fchmodat(AT_FDCWD, arg1, arg2);
+}
+#endif
+
 SYSCALL_IMPL(close)
 {
 int fd = arg1;
@@ -54,6 +74,16 @@ SYSCALL_IMPL(creat)
 }
 #endif
 
+SYSCALL_IMPL(fchmod)
+{
+return get_errno(fchmod(arg1, arg2));
+}
+
+SYSCALL_IMPL(fchmodat)
+{
+return do_fchmodat(arg1, arg2, arg3);
+}
+
 static abi_long do_linkat(int olddirfd, abi_ulong target_oldpath,
   int newdirfd, abi_ulong target_newpath,
   int flags)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d46b4df677..f9101d0b08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5331,14 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_chmod
-case TARGET_NR_chmod:
-if (!(p = lock_user_string(arg1)))
-return -TARGET_EFAULT;
-ret = get_errno(chmod(p, arg2));
-unlock_user(p, arg1, 0);
-return ret;
-#endif
 #ifdef TARGET_NR_lseek
 case TARGET_NR_lseek:
 return get_errno(lseek(arg1, arg2, arg3));
@@ -6410,16 +6402,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #ifdef TARGET_NR_ftruncate
 case TARGET_NR_ftruncate:
 return get_errno(ftruncate(arg1, arg2));
-#endif
-case TARGET_NR_fchmod:
-return get_errno(fchmod(arg1, arg2));
-#if defined(TARGET_NR_fchmodat)
-case TARGET_NR_fchmodat:
-if (!(p = lock_user_string(arg2)))
-return -TARGET_EFAULT;
-ret = get_errno(fchmodat(arg1, p, arg3, 0));
-unlock_user(p, arg2, 0);
-return ret;
 #endif
 case TARGET_NR_getpriority:
 /* Note that negative values are valid for getpriority, so we must
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 

[Qemu-devel] [PATCH v6 28/49] linux-user: Split out mknod, mknodat

2019-01-18 Thread Richard Henderson
Note that mknodat is universally provided.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  4 
 linux-user/strace.c   | 39 ---
 linux-user/syscall-file.inc.c | 26 +++
 linux-user/syscall.c  | 16 --
 linux-user/strace.list|  6 --
 5 files changed, 30 insertions(+), 61 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 9950b73e76..b5951e6911 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -38,6 +38,10 @@ SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, 
ARG_PTR, ARG_HEX);
 SYSCALL_DEF(link, ARG_STR, ARG_STR);
 #endif
 SYSCALL_DEF(linkat, ARG_ATDIRFD, ARG_STR, ARG_ATDIRFD, ARG_STR, ARG_ATFLAG);
+#ifdef TARGET_NR_mknod
+SYSCALL_DEF(mknod, ARG_STR, ARG_MODEFLAG, ARG_HEX);
+#endif
+SYSCALL_DEF(mknodat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG, ARG_HEX);
 SYSCALL_DEF(mlock, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(mlockall, ARG_HEX);
 #ifdef TARGET_NR_mmap
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 5133998c4f..668e6a4759 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1911,45 +1911,6 @@ print_syslog(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_mknod
-static void
-print_mknod(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
-
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_file_mode(arg1, (hasdev == 0));
-if (hasdev) {
-print_raw_param("makedev(%d", major(arg2), 0);
-print_raw_param("%d)", minor(arg2), 1);
-}
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_mknodat
-static void
-print_mknodat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
-
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_file_mode(arg2, (hasdev == 0));
-if (hasdev) {
-print_raw_param("makedev(%d", major(arg3), 0);
-print_raw_param("%d)", minor(arg3), 1);
-}
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_mq_open
 static void
 print_mq_open(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 7a4751d460..3b5a79fe74 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -82,6 +82,32 @@ SYSCALL_IMPL(linkat)
 return do_linkat(arg1, arg2, arg3, arg4, arg5);
 }
 
+static abi_long do_mknodat(int dirfd, abi_ulong target_path,
+   mode_t mode, dev_t dev)
+{
+char *p = lock_user_string(target_path);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(mknodat(dirfd, p, mode, dev));
+unlock_user(p, target_path, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_mknod
+SYSCALL_IMPL(mknod)
+{
+return do_mknodat(AT_FDCWD, arg1, arg2, arg3);
+}
+#endif
+
+SYSCALL_IMPL(mknodat)
+{
+return do_mknodat(arg1, arg2, arg3, arg4);
+}
+
 /*
  * Helpers for do_openat, manipulating /proc/self/foo.
  */
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index cc5360ae43..d46b4df677 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5331,22 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_mknod
-case TARGET_NR_mknod:
-if (!(p = lock_user_string(arg1)))
-return -TARGET_EFAULT;
-ret = get_errno(mknod(p, arg2, arg3));
-unlock_user(p, arg1, 0);
-return ret;
-#endif
-#if defined(TARGET_NR_mknodat)
-case TARGET_NR_mknodat:
-if (!(p = lock_user_string(arg2)))
-return -TARGET_EFAULT;
-ret = get_errno(mknodat(arg1, p, arg3, arg4));
-unlock_user(p, arg2, 0);
-return ret;
-#endif
 #ifdef TARGET_NR_chmod
 case TARGET_NR_chmod:
 if (!(p = lock_user_string(arg1)))
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 3505014501..adf8955278 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -518,12 +518,6 @@
 #ifdef TARGET_NR_mkdirat
 { TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL },
 #endif
-#ifdef TARGET_NR_mknod
-{ TARGET_NR_mknod, "mknod" , NULL, print_mknod, NULL },
-#endif
-#ifdef TARGET_NR_mknodat
-{ TARGET_NR_mknodat, "mknodat" , NULL, print_mknodat, NULL },
-#endif
 #ifdef TARGET_NR_modify_ldt
 { TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 24/49] linux-user: Split out execve

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |   1 +
 linux-user/strace.c   |  32 --
 linux-user/syscall-proc.inc.c | 110 ++
 linux-user/syscall.c  |  97 --
 linux-user/strace.list|   3 -
 5 files changed, 111 insertions(+), 132 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 78d3f600eb..58fef48666 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -25,6 +25,7 @@ SYSCALL_DEF(close, ARG_DEC);
 SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(exit, ARG_DEC);
+SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
 #ifdef TARGET_NR_fork
 SYSCALL_DEF(fork);
 #endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index a41b6dcfe7..43865e9df9 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -568,38 +568,6 @@ print_newselect(const struct syscallname *name,
 }
 #endif
 
-static void
-print_execve(const struct syscallname *name,
- abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6)
-{
-abi_ulong arg_ptr_addr;
-char *s;
-
-if (!(s = lock_user_string(arg1)))
-return;
-gemu_log("%s(\"%s\",{", name->name, s);
-unlock_user(s, arg1, 0);
-
-for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
-abi_ulong *arg_ptr, arg_addr;
-
-arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
-if (!arg_ptr)
-return;
-arg_addr = tswapal(*arg_ptr);
-unlock_user(arg_ptr, arg_ptr_addr, 0);
-if (!arg_addr)
-break;
-if ((s = lock_user_string(arg_addr))) {
-gemu_log("\"%s\",", s);
-unlock_user(s, arg_addr, 0);
-}
-}
-
-gemu_log("NULL})");
-}
-
 /*
  * Variants for the return value output function
  */
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index de4efed9f4..552aea60ae 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -269,6 +269,116 @@ SYSCALL_IMPL(clone)
 return do_clone(cpu_env, arg1, arg2, arg3, arg4, arg5);
 }
 
+SYSCALL_IMPL(execve)
+{
+char **argp, **envp;
+int argc, envc;
+abi_ulong gp;
+abi_ulong guest_path = arg1;
+abi_ulong guest_argp = arg2;
+abi_ulong guest_envp = arg3;
+abi_ulong addr;
+char **q, *p;
+int total_size = 0;
+abi_long ret = -TARGET_EFAULT;
+
+argc = 0;
+for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
+if (get_user_ual(addr, gp)) {
+goto execve_nofree;
+}
+if (!addr) {
+break;
+}
+argc++;
+}
+envc = 0;
+for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
+if (get_user_ual(addr, gp)) {
+goto execve_nofree;
+}
+if (!addr) {
+break;
+}
+envc++;
+}
+
+argp = g_new0(char *, argc + 1);
+envp = g_new0(char *, envc + 1);
+
+for (gp = guest_argp, q = argp; gp; gp += sizeof(abi_ulong), q++) {
+char *this_q;
+
+if (get_user_ual(addr, gp)) {
+goto execve_free;
+}
+if (!addr) {
+break;
+}
+this_q = lock_user_string(addr);
+if (!this_q) {
+goto execve_free;
+}
+*q = this_q;
+total_size += strlen(this_q) + 1;
+}
+
+for (gp = guest_envp, q = envp; gp; gp += sizeof(abi_ulong), q++) {
+char *this_q;
+
+if (get_user_ual(addr, gp)) {
+goto execve_free;
+}
+if (!addr) {
+break;
+}
+this_q = lock_user_string(addr);
+if (!this_q) {
+goto execve_free;
+}
+*q = this_q;
+total_size += strlen(this_q) + 1;
+}
+
+p = lock_user_string(guest_path);
+if (!p) {
+goto execve_free;
+}
+
+/*
+ * Although execve() is not an interruptible syscall it is
+ * a special case where we must use the safe_syscall wrapper:
+ * if we allow a signal to happen before we make the host
+ * syscall then we will 'lose' it, because at the point of
+ * execve the process leaves QEMU's control. So we use the
+ * safe syscall wrapper to ensure that we either take the
+ * signal as a guest signal, or else it does not happen
+ * before the execve completes and makes it the other
+ * program's problem.
+ */
+ret = get_errno(safe_execve(p, argp, envp));
+unlock_user(p, guest_path, 0);
+
+ execve_free:
+for (gp = guest_argp, q = argp; *q; gp += sizeof(abi_ulong), q++) {
+if (get_user_ual(addr, gp) || !addr) {
+break;
+}
+unlock_user(*q, addr, 0);
+}
+for (gp = guest_envp, q = envp; *q; gp += sizeof(abi_ulong), q++) {
+if (get_user_ual(addr, gp) || !addr) {
+break;
+}
+

[Qemu-devel] [PATCH v6 42/49] linux-user: Split out mkdir, mkdirat

2019-01-18 Thread Richard Henderson
Note that mkdirat is universally available.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  4 
 linux-user/strace.c   | 27 ---
 linux-user/syscall-file.inc.c | 25 +
 linux-user/syscall.c  | 16 
 linux-user/strace.list|  6 --
 5 files changed, 29 insertions(+), 49 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 0ed01aa100..8b6d8f75ff 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -69,6 +69,10 @@ SYSCALL_DEF(lseek, ARG_DEC, ARG_DEC, ARG_LSEEKWHENCE);
 #ifdef TARGET_NR_llseek
 SYSCALL_DEF_ARGS(llseek, ARG_DEC, ARG_DEC, ARG_PTR, ARG_LSEEKWHENCE);
 #endif
+#ifdef TARGET_NR_mkdir
+SYSCALL_DEF(mkdir, ARG_STR, ARG_MODEFLAG);
+#endif
+SYSCALL_DEF(mkdirat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG);
 #ifdef TARGET_NR_mknod
 SYSCALL_DEF(mknod, ARG_STR, ARG_MODEFLAG, ARG_HEX);
 #endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 6dce7e52c0..ca8e110675 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1664,33 +1664,6 @@ print_fstat(const struct syscallname *name,
 #define print_fstat64 print_fstat
 #endif
 
-#ifdef TARGET_NR_mkdir
-static void
-print_mkdir(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_file_mode(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_mkdirat
-static void
-print_mkdirat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_file_mode(arg2, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_rt_sigaction
 static void
 print_rt_sigaction(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 9099107631..83174c5781 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -205,6 +205,31 @@ SYSCALL_IMPL(llseek)
 }
 #endif
 
+static abi_long do_mkdirat(int dirfd, abi_ulong target_path, mode_t mode)
+{
+char *p = lock_user_string(target_path);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(mkdirat(dirfd, p, mode));
+unlock_user(p, target_path, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_mkdir
+SYSCALL_IMPL(mkdir)
+{
+return do_mkdirat(AT_FDCWD, arg1, arg2);
+}
+#endif
+
+SYSCALL_IMPL(mkdirat)
+{
+return do_mkdirat(arg1, arg2, arg3);
+}
+
 static abi_long do_mknodat(int dirfd, abi_ulong target_path,
mode_t mode, dev_t dev)
 {
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index fe38ec59d4..7874a48840 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5320,22 +5320,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_mkdir
-case TARGET_NR_mkdir:
-if (!(p = lock_user_string(arg1)))
-return -TARGET_EFAULT;
-ret = get_errno(mkdir(p, arg2));
-unlock_user(p, arg1, 0);
-return ret;
-#endif
-#if defined(TARGET_NR_mkdirat)
-case TARGET_NR_mkdirat:
-if (!(p = lock_user_string(arg2)))
-return -TARGET_EFAULT;
-ret = get_errno(mkdirat(arg1, p, arg3));
-unlock_user(p, arg2, 0);
-return ret;
-#endif
 case TARGET_NR_dup:
 ret = get_errno(dup(arg1));
 if (ret >= 0) {
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 56aab25d9f..678feeeb7b 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -473,12 +473,6 @@
 #ifdef TARGET_NR_mincore
 { TARGET_NR_mincore, "mincore" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_mkdir
-{ TARGET_NR_mkdir, "mkdir" , NULL, print_mkdir, NULL },
-#endif
-#ifdef TARGET_NR_mkdirat
-{ TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL },
-#endif
 #ifdef TARGET_NR_modify_ldt
 { TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




Re: [Qemu-devel] [PATCH v10 14/14] target/arm: Send interrupts on PMU counter overflow

2019-01-18 Thread Richard Henderson
On 1/19/19 8:40 AM, Aaron Lindsay wrote:
> In practice, I think only the 32nd bit would ever need to be cleared,
> but I agree it is more correct to clear them all.
> 
>> Given that it is architecturally defined to 32-bits, I think you could really
>> just drop the define and use
>>
>> uint32_t new_pmevcntr = ...;
>> if (env->cp15.c14_pmevcntr[counter] & ~new_pmevcntr & INT32_MIN)
>>
>> with equal clarity.
> 
> I don't know whether it is important for the resolution of this patch,
> but what did you mean by the following?:
> 
>> The type of new_pmevcntr means you don't have to clear any
>> high bits either.

If you use uint32_t, then no *explicit* clearing of the high bits is necessary,
and is implied by the assignment back to env->cp15.c14_pmevcntr[counter].


r~



[Qemu-devel] [PATCH v6 41/49] linux-user: Split out rename, renameat, renameat2

2019-01-18 Thread Richard Henderson
Note that renameat2 is universally available for guests.
Merge sys_renameat2 into the new do_renameat2 helper.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  8 +
 linux-user/syscall.h  |  1 +
 linux-user/strace.c   | 39 ++---
 linux-user/syscall-file.inc.c | 45 
 linux-user/syscall.c  | 64 ---
 linux-user/strace.list|  9 -
 6 files changed, 65 insertions(+), 101 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index c672b5ad99..0ed01aa100 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -142,6 +142,14 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_readlinkat
 SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
+#ifdef TARGET_NR_rename
+SYSCALL_DEF(rename, ARG_STR, ARG_STR);
+#endif
+#ifdef TARGET_NR_renameat
+SYSCALL_DEF(renameat, ARG_ATDIRFD, ARG_STR, ARG_ATDIRFD, ARG_STR);
+#endif
+SYSCALL_DEF(renameat2, ARG_ATDIRFD, ARG_STR,
+ARG_ATDIRFD, ARG_STR, ARG_RENAMEFLAG);
 SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_rmdir
 SYSCALL_DEF(rmdir, ARG_STR);
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index 642fb6dccb..7b197840f5 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -69,6 +69,7 @@ typedef enum {
 ARG_MODEFLAG,
 ARG_MOUNTFLAG,
 ARG_OPENFLAG,
+ARG_RENAMEFLAG,
 ARG_UMOUNTFLAG,
 ARG_UNLINKATFLAG,
 
diff --git a/linux-user/strace.c b/linux-user/strace.c
index ec36fcf2c2..6dce7e52c0 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "qemu.h"
 #include "syscall.h"
@@ -741,6 +742,13 @@ static struct flags const mount_flags[] = {
 FLAG_END,
 };
 
+static struct flags const renameat2_flags[] = {
+FLAG_GENERIC(RENAME_EXCHANGE),
+FLAG_GENERIC(RENAME_NOREPLACE),
+FLAG_GENERIC(RENAME_WHITEOUT),
+FLAG_END,
+};
+
 static struct flags const umount2_flags[] = {
 #ifdef MNT_FORCE
 FLAG_GENERIC(MNT_FORCE),
@@ -1887,34 +1895,6 @@ print_fstatat64(const struct syscallname *name,
 #define print_newfstatatprint_fstatat64
 #endif
 
-#ifdef TARGET_NR_rename
-static void
-print_rename(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_string(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_renameat
-static void
-print_renameat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_at_dirfd(arg2, 0);
-print_string(arg3, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_statfs
 static void
 print_statfs(const struct syscallname *name,
@@ -2200,6 +2180,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_OPENFLAG:
 len = add_open_flags(b, rest, arg);
 break;
+case ARG_RENAMEFLAG:
+len = add_flags(b, rest, renameat2_flags, arg, false);
+break;
 case ARG_UMOUNTFLAG:
 len = add_flags(b, rest, umount2_flags, arg, false);
 break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 80dec33971..9099107631 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -867,6 +867,51 @@ SYSCALL_IMPL(readlinkat)
 }
 #endif
 
+static abi_long do_renameat2(int oldfd, abi_ulong target_oldpath,
+ int newfd, abi_ulong target_newpath,
+ unsigned int flags)
+{
+char *p_old = lock_user_string(target_oldpath);
+char *p_new = lock_user_string(target_newpath);
+abi_long ret = -TARGET_EFAULT;
+
+if (p_old && p_new) {
+if (flags == 0) {
+ret = renameat(oldfd, p_old, newfd, p_new);
+} else {
+#ifdef __NR_renameat2
+ret = syscall(__NR_renameat2, oldfd, p_old, newfd, p_new, flags);
+#else
+errno = ENOSYS;
+ret = -1;
+#endif
+}
+ret = get_errno(ret);
+}
+unlock_user(p_old, target_oldpath, 0);
+unlock_user(p_new, target_newpath, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_rename
+SYSCALL_IMPL(rename)
+{
+return do_renameat2(AT_FDCWD, arg1, AT_FDCWD, arg2, 0);
+}
+#endif
+
+#ifdef TARGET_NR_renameat
+SYSCALL_IMPL(renameat)
+{
+return do_renameat2(arg1, arg2, arg3, arg4, 0);
+}
+#endif
+
+SYSCALL_IMPL(renameat2)
+{
+return do_renameat2(arg1, arg2, arg3, arg4, arg5);
+}
+
 SYSCALL_IMPL(sync)
 {
 sync();
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index fef955ce66..fe38ec59d4 100644

[Qemu-devel] [PATCH v6 26/49] linux-user: Split out chdir

2019-01-18 Thread Richard Henderson
Note that chdir is universally provided.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  1 +
 linux-user/strace.c   | 12 
 linux-user/syscall-file.inc.c | 14 ++
 linux-user/syscall.c  |  6 --
 linux-user/strace.list|  3 ---
 5 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 392bd1579c..3fad9d51f0 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -19,6 +19,7 @@
 SYSCALL_DEF_FULL(brk, .impl = impl_brk,
  .print_ret = print_syscall_ptr_ret,
  .arg_type = { ARG_PTR });
+SYSCALL_DEF(chdir, ARG_STR);
 SYSCALL_DEF_ARGS(clone, ARG_CLONEFLAG, ARG_PTR, ARG_PTR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(close, ARG_DEC);
 #ifdef TARGET_NR_creat
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 43865e9df9..5133998c4f 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1113,18 +1113,6 @@ print_access(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_chdir
-static void
-print_chdir(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_chmod
 static void
 print_chmod(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 2dd57176b3..7a4751d460 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -16,6 +16,20 @@
  *  along with this program; if not, see .
  */
 
+SYSCALL_IMPL(chdir)
+{
+abi_ulong target_path = arg1;
+char *p = lock_user_string(target_path);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(chdir(p));
+unlock_user(p, target_path, 0);
+return ret;
+}
+
 SYSCALL_IMPL(close)
 {
 int fd = arg1;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3a027651e3..1cdc9727a9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5331,12 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-case TARGET_NR_chdir:
-if (!(p = lock_user_string(arg1)))
-return -TARGET_EFAULT;
-ret = get_errno(chdir(p));
-unlock_user(p, arg1, 0);
-return ret;
 #ifdef TARGET_NR_time
 case TARGET_NR_time:
 {
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 202bfa8f9e..357984dd6f 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -61,9 +61,6 @@
 #ifdef TARGET_NR_capset
 { TARGET_NR_capset, "capset" , "%s(%p,%p)", NULL, NULL },
 #endif
-#ifdef TARGET_NR_chdir
-{ TARGET_NR_chdir, "chdir" , NULL, print_chdir, NULL },
-#endif
 #ifdef TARGET_NR_chmod
 { TARGET_NR_chmod, "chmod" , NULL, print_chmod, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 37/49] linux-user: Split out access, faccessat

2019-01-18 Thread Richard Henderson
Note that faccessat is unconditionally available.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  4 
 linux-user/syscall.h  |  1 +
 linux-user/strace.c   | 33 -
 linux-user/syscall-file.inc.c | 25 +
 linux-user/syscall.c  | 18 --
 linux-user/strace.list|  6 --
 6 files changed, 34 insertions(+), 53 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 2767e335d8..39e3ae3c21 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -16,6 +16,9 @@
  *  along with this program; if not, see .
  */
 
+#ifdef TARGET_NR_access
+SYSCALL_DEF(access, ARG_STR, ARG_ACCESSFLAG);
+#endif
 #ifdef TARGET_NR_alarm
 SYSCALL_DEF(alarm, ARG_DEC);
 #endif
@@ -34,6 +37,7 @@ SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
 SYSCALL_DEF(exit, ARG_DEC);
 SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
+SYSCALL_DEF(faccessat, ARG_ATDIRFD, ARG_STR, ARG_ACCESSFLAG);
 SYSCALL_DEF(fchmod, ARG_DEC, ARG_MODEFLAG);
 SYSCALL_DEF(fchmodat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG);
 #ifdef TARGET_NR_futimesat
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index 3c936b648a..84a52b2d9a 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -57,6 +57,7 @@ typedef enum {
 
 /* These print as sets of flags.  */
 ARG_ATDIRFD,
+ARG_ACCESSFLAG,
 ARG_ATFLAG,
 ARG_CLONEFLAG,
 ARG_MMAPFLAG,
diff --git a/linux-user/strace.c b/linux-user/strace.c
index b54949df27..da2cc30f82 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -634,7 +634,7 @@ print_syscall_ret_adjtimex(const struct syscallname *name, 
abi_long ret)
 gemu_log("\n");
 }
 
-UNUSED static struct flags access_flags[] = {
+static struct flags const access_flags[] = {
 FLAG_GENERIC(F_OK),
 FLAG_GENERIC(R_OK),
 FLAG_GENERIC(W_OK),
@@ -1114,19 +1114,6 @@ print_accept(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_access
-static void
-print_access(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_flags(access_flags, arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_clock_adjtime
 static void
 print_clock_adjtime(const struct syscallname *name,
@@ -1153,21 +1140,6 @@ print_execv(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_faccessat
-static void
-print_faccessat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_flags(access_flags, arg2, 0);
-print_flags(at_file_flags, arg3, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_fchownat
 static void
 print_fchownat(const struct syscallname *name,
@@ -2206,6 +2178,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_ATDIRFD:
 len = add_atdirfd(b, rest, arg);
 break;
+case ARG_ACCESSFLAG:
+len = add_flags(b, rest, access_flags, arg, false);
+break;
 case ARG_ATFLAG:
 len = add_flags(b, rest, at_file_flags, arg, false);
 break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 6a7ef80bfc..3111abd861 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -16,6 +16,26 @@
  *  along with this program; if not, see .
  */
 
+static abi_long do_faccessat(int dirfd, abi_ulong target_path, int mode)
+{
+char *p = lock_user_string(target_path);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(faccessat(dirfd, p, mode, 0));
+unlock_user(p, target_path, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_access
+SYSCALL_IMPL(access)
+{
+return do_faccessat(AT_FDCWD, arg1, arg2);
+}
+#endif
+
 SYSCALL_IMPL(chdir)
 {
 abi_ulong target_path = arg1;
@@ -74,6 +94,11 @@ SYSCALL_IMPL(creat)
 }
 #endif
 
+SYSCALL_IMPL(faccessat)
+{
+return do_faccessat(arg1, arg2, arg3);
+}
+
 SYSCALL_IMPL(fchmod)
 {
 return get_errno(fchmod(arg1, arg2));
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ca462fde61..9074cf8b8d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5327,24 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_access
-case TARGET_NR_access:
-if (!(p = lock_user_string(arg1))) {
-return -TARGET_EFAULT;
-}
-ret = get_errno(access(path(p), arg2));
-unlock_user(p, arg1, 0);

[Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h  |   1 +
 linux-user/syscall-ioctl.inc.c | 873 +
 linux-user/syscall.c   | 843 +--
 linux-user/strace.list |   3 -
 4 files changed, 875 insertions(+), 845 deletions(-)
 create mode 100644 linux-user/syscall-ioctl.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index f8f280f376..f58b9745a4 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -61,6 +61,7 @@ SYSCALL_DEF(getppid);
 #ifdef TARGET_NR_getxpid
 SYSCALL_DEF(getxpid);
 #endif
+SYSCALL_DEF(ioctl, ARG_DEC, ARG_HEX);
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
diff --git a/linux-user/syscall-ioctl.inc.c b/linux-user/syscall-ioctl.inc.c
new file mode 100644
index 00..820994105f
--- /dev/null
+++ b/linux-user/syscall-ioctl.inc.c
@@ -0,0 +1,873 @@
+/*
+ *  Linux ioctl syscall implementation
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see .
+ */
+
+typedef struct IOCTLEntry IOCTLEntry;
+
+typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp,
+ int fd, int cmd, abi_long arg);
+
+struct IOCTLEntry {
+int target_cmd;
+unsigned int host_cmd;
+const char *name;
+int access;
+do_ioctl_fn *do_ioctl;
+const argtype arg_type[5];
+};
+
+#define IOC_R 0x0001
+#define IOC_W 0x0002
+#define IOC_RW (IOC_R | IOC_W)
+
+#define MAX_STRUCT_SIZE 4096
+
+#ifdef CONFIG_FIEMAP
+/*
+ * So fiemap access checks don't overflow on 32 bit systems.
+ * This is very slightly smaller than the limit imposed by
+ * the underlying kernel.
+ */
+#define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap))  \
+/ sizeof(struct fiemap_extent))
+
+static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry *ie, uint8_t *buf_temp,
+   int fd, int cmd, abi_long arg)
+{
+/*
+ * The parameter for this ioctl is a struct fiemap followed
+ * by an array of struct fiemap_extent whose size is set
+ * in fiemap->fm_extent_count. The array is filled in by the
+ * ioctl.
+ */
+int target_size_in, target_size_out;
+struct fiemap *fm;
+const argtype *arg_type = ie->arg_type;
+const argtype extent_arg_type[] = { MK_STRUCT(STRUCT_fiemap_extent) };
+void *argptr, *p;
+abi_long ret;
+int i, extent_size = thunk_type_size(extent_arg_type, 0);
+uint32_t outbufsz;
+int free_fm = 0;
+
+assert(arg_type[0] == TYPE_PTR);
+assert(ie->access == IOC_RW);
+arg_type++;
+target_size_in = thunk_type_size(arg_type, 0);
+argptr = lock_user(VERIFY_READ, arg, target_size_in, 1);
+if (!argptr) {
+return -TARGET_EFAULT;
+}
+thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST);
+unlock_user(argptr, arg, 0);
+fm = (struct fiemap *)buf_temp;
+if (fm->fm_extent_count > FIEMAP_MAX_EXTENTS) {
+return -TARGET_EINVAL;
+}
+
+outbufsz = sizeof(*fm) + sizeof(struct fiemap_extent) * 
fm->fm_extent_count;
+
+if (outbufsz > MAX_STRUCT_SIZE) {
+/*
+ * We can't fit all the extents into the fixed size buffer.
+ * Allocate one that is large enough and use it instead.
+ */
+fm = g_try_malloc(outbufsz);
+if (!fm) {
+return -TARGET_ENOMEM;
+}
+memcpy(fm, buf_temp, sizeof(struct fiemap));
+free_fm = 1;
+}
+ret = get_errno(safe_ioctl(fd, ie->host_cmd, fm));
+if (!is_error(ret)) {
+target_size_out = target_size_in;
+/*
+ * An extent_count of 0 means we were only counting the extents
+ * so there are no structs to copy
+ */
+if (fm->fm_extent_count != 0) {
+target_size_out += fm->fm_mapped_extents * extent_size;
+}
+argptr = lock_user(VERIFY_WRITE, arg, target_size_out, 0);
+if (!argptr) {
+ret = -TARGET_EFAULT;
+} else {
+/* Convert the struct fiemap */
+thunk_convert(argptr, fm, arg_type, THUNK_TARGET);
+if (fm->fm_extent_count != 0) {
+p = argptr + target_size_in;
+/* ...and then all the struct fiemap_extents */
+

[Qemu-devel] [PATCH v6 21/49] linux-user: Split out creat

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  3 +++
 linux-user/strace.c   | 13 -
 linux-user/syscall-file.inc.c | 16 
 linux-user/syscall.c  |  9 -
 linux-user/strace.list|  3 ---
 5 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index f099d98fa3..de7a99f0c6 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -21,6 +21,9 @@ SYSCALL_DEF_FULL(brk, .impl = impl_brk,
  .arg_type = { ARG_PTR });
 SYSCALL_DEF_ARGS(clone, ARG_CLONEFLAG, ARG_PTR, ARG_PTR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(close, ARG_DEC);
+#ifdef TARGET_NR_creat
+SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
+#endif
 SYSCALL_DEF(exit, ARG_DEC);
 #ifdef TARGET_NR_fork
 SYSCALL_DEF(fork);
diff --git a/linux-user/strace.c b/linux-user/strace.c
index d7847e7cd6..5cb77223fd 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1183,19 +1183,6 @@ print_clock_adjtime(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_creat
-static void
-print_creat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_file_mode(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_execv
 static void
 print_execv(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 81423cfd64..62e1790e3b 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -24,6 +24,22 @@ SYSCALL_IMPL(close)
 return get_errno(close(fd));
 }
 
+#ifdef TARGET_NR_creat
+SYSCALL_IMPL(creat)
+{
+char *p = lock_user_string(arg1);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(creat(p, arg2));
+fd_trans_unregister(ret);
+unlock_user(p, arg1, 0);
+return ret;
+}
+#endif
+
 /*
  * Helpers for do_openat, manipulating /proc/self/foo.
  */
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8da92dd188..1e9478611c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5330,15 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_creat /* not on alpha */
-case TARGET_NR_creat:
-if (!(p = lock_user_string(arg1)))
-return -TARGET_EFAULT;
-ret = get_errno(creat(p, arg2));
-fd_trans_unregister(ret);
-unlock_user(p, arg1, 0);
-return ret;
-#endif
 #ifdef TARGET_NR_link
 case TARGET_NR_link:
 {
diff --git a/linux-user/strace.list b/linux-user/strace.list
index afa1521e2d..be0392810c 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -94,9 +94,6 @@
 #ifdef TARGET_NR_connect
 { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL },
 #endif
-#ifdef TARGET_NR_creat
-{ TARGET_NR_creat, "creat" , NULL, print_creat, NULL },
-#endif
 #ifdef TARGET_NR_create_module
 { TARGET_NR_create_module, "create_module" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 20/49] linux-user: Implement rusage argument to waitid

2019-01-18 Thread Richard Henderson
The kernel interface, which we are supposed to be implementing,
takes a fifth argument: an rusage pointer akin to wait4.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  2 +-
 linux-user/syscall-proc.inc.c | 27 +++
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index a84050a318..f099d98fa3 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -119,7 +119,7 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 SYSCALL_DEF_FULL(vfork, .impl = impl_fork);
 #endif
 SYSCALL_DEF(wait4, ARG_DEC, ARG_PTR, ARG_HEX, ARG_PTR);
-SYSCALL_DEF(waitid, ARG_HEX, ARG_DEC, ARG_PTR, ARG_HEX);
+SYSCALL_DEF(waitid, ARG_HEX, ARG_DEC, ARG_PTR, ARG_HEX, ARG_PTR);
 #ifdef TARGET_NR_waitpid
 SYSCALL_DEF(waitpid, ARG_DEC, ARG_PTR, ARG_HEX);
 #endif
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index 37f5bbe197..de4efed9f4 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -370,19 +370,30 @@ SYSCALL_IMPL(waitid)
 id_t id = arg2;
 abi_ulong target_info = arg3;
 int options = arg4;
+abi_ulong target_rusage = arg5;
 siginfo_t info, *info_ptr = target_info ?  : NULL;
+struct rusage rusage;
+struct rusage *rusage_ptr = target_rusage ?  : NULL;
 abi_long ret;
 
 info.si_pid = 0;
-ret = get_errno(safe_waitid(idtype, id, info_ptr, options, NULL));
-if (!is_error(ret) && target_info && info.si_pid != 0) {
-target_siginfo_t *p = lock_user(VERIFY_WRITE, target_info,
-sizeof(target_siginfo_t), 0);
-if (!p) {
-return -TARGET_EFAULT;
+ret = get_errno(safe_waitid(idtype, id, info_ptr, options, rusage_ptr));
+if (!is_error(ret)) {
+if (target_info && info.si_pid != 0) {
+target_siginfo_t *p = lock_user(VERIFY_WRITE, target_info,
+sizeof(target_siginfo_t), 0);
+if (!p) {
+return -TARGET_EFAULT;
+}
+host_to_target_siginfo(p, );
+unlock_user(p, target_info, sizeof(target_siginfo_t));
+}
+if (target_rusage) {
+abi_long err = host_to_target_rusage(target_rusage, );
+if (err) {
+ret = err;
+}
 }
-host_to_target_siginfo(p, );
-unlock_user(p, target_info, sizeof(target_siginfo_t));
 }
 return ret;
 }
-- 
2.17.2




[Qemu-devel] [PATCH v6 34/49] linux-user: Split out stime

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  3 +++
 linux-user/syscall-time.inc.c | 12 
 linux-user/syscall.c  |  9 -
 linux-user/strace.list|  3 ---
 4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 0d8da0c6d6..6ca82af397 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -152,6 +152,9 @@ SYSCALL_DEF(shmdt, ARG_PTR);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmget)
 SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 #endif
+#ifdef TARGET_NR_stime
+SYSCALL_DEF(stime, ARG_PTR);
+#endif
 #ifdef TARGET_NR_time
 SYSCALL_DEF(time, ARG_PTR);
 #endif
diff --git a/linux-user/syscall-time.inc.c b/linux-user/syscall-time.inc.c
index 14fec88e47..d1fb72bde0 100644
--- a/linux-user/syscall-time.inc.c
+++ b/linux-user/syscall-time.inc.c
@@ -16,6 +16,18 @@
  *  along with this program; if not, see .
  */
 
+#ifdef TARGET_NR_stime
+SYSCALL_IMPL(stime)
+{
+time_t host_time;
+
+if (get_user_sal(host_time, arg1)) {
+return -TARGET_EFAULT;
+}
+return get_errno(stime(_time));
+}
+#endif
+
 #ifdef TARGET_NR_time
 SYSCALL_IMPL(time)
 {
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b35d84794f..c0ce4068b6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5327,15 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_stime /* not on alpha */
-case TARGET_NR_stime:
-{
-time_t host_time;
-if (get_user_sal(host_time, arg1))
-return -TARGET_EFAULT;
-return get_errno(stime(_time));
-}
-#endif
 #ifdef TARGET_NR_alarm /* not on alpha */
 case TARGET_NR_alarm:
 return alarm(arg1);
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 0f32c456cd..a5f308c497 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1254,9 +1254,6 @@
 #ifdef TARGET_NR_statfs64
 { TARGET_NR_statfs64, "statfs64" , NULL, print_statfs64, NULL },
 #endif
-#ifdef TARGET_NR_stime
-{ TARGET_NR_stime, "stime" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_streams1
 { TARGET_NR_streams1, "streams1" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 49/49] linux-user: Split out fcntl, fcntl64

2019-01-18 Thread Richard Henderson
Preserving strace functionality is tricky with this one.
Rearrange to lookup structures that contain the data for
both execution and strace for each command.

Do not allow lookup of 64-bit fcntl commands from 32-bit fcntl.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h  |   6 +
 linux-user/strace.c| 100 --
 linux-user/syscall-fcntl.inc.c | 322 +
 linux-user/syscall.c   | 256 +-
 linux-user/strace.list |   6 -
 5 files changed, 329 insertions(+), 361 deletions(-)
 create mode 100644 linux-user/syscall-fcntl.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index f58b9745a4..5cf39f2bb9 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -46,6 +46,12 @@ SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, 
ARG_PTR, ARG_ATFLAG);
 SYSCALL_DEF(faccessat, ARG_ATDIRFD, ARG_STR, ARG_ACCESSFLAG);
 SYSCALL_DEF(fchmod, ARG_DEC, ARG_MODEFLAG);
 SYSCALL_DEF(fchmodat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG);
+#ifdef TARGET_NR_fcntl
+SYSCALL_DEF_FULL(fcntl, .impl = impl_fcntl, .print = print_fcntl);
+#endif
+#if TARGET_ABI_BITS == 32
+SYSCALL_DEF_FULL(fcntl64, .impl = impl_fcntl64, .print = print_fcntl64);
+#endif
 #ifdef TARGET_NR_futimesat
 SYSCALL_DEF(futimesat, ARG_ATDIRFD, ARG_STR, ARG_PTR);
 #endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index ca8e110675..787bf41307 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1172,106 +1172,6 @@ print_fchownat(const struct syscallname *name,
 }
 #endif
 
-#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
-static void
-print_fcntl(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_raw_param("%d", arg0, 0);
-switch(arg1) {
-case TARGET_F_DUPFD:
-gemu_log("F_DUPFD,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
-break;
-case TARGET_F_GETFD:
-gemu_log("F_GETFD");
-break;
-case TARGET_F_SETFD:
-gemu_log("F_SETFD,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
-break;
-case TARGET_F_GETFL:
-gemu_log("F_GETFL");
-break;
-case TARGET_F_SETFL:
-gemu_log("F_SETFL,");
-print_open_flags(arg2, 1);
-break;
-case TARGET_F_GETLK:
-gemu_log("F_GETLK,");
-print_pointer(arg2, 1);
-break;
-case TARGET_F_SETLK:
-gemu_log("F_SETLK,");
-print_pointer(arg2, 1);
-break;
-case TARGET_F_SETLKW:
-gemu_log("F_SETLKW,");
-print_pointer(arg2, 1);
-break;
-case TARGET_F_GETOWN:
-gemu_log("F_GETOWN");
-break;
-case TARGET_F_SETOWN:
-gemu_log("F_SETOWN,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
-break;
-case TARGET_F_GETSIG:
-gemu_log("F_GETSIG");
-break;
-case TARGET_F_SETSIG:
-gemu_log("F_SETSIG,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
-break;
-#if TARGET_ABI_BITS == 32
-case TARGET_F_GETLK64:
-gemu_log("F_GETLK64,");
-print_pointer(arg2, 1);
-break;
-case TARGET_F_SETLK64:
-gemu_log("F_SETLK64,");
-print_pointer(arg2, 1);
-break;
-case TARGET_F_SETLKW64:
-gemu_log("F_SETLKW64,");
-print_pointer(arg2, 1);
-break;
-#endif
-case TARGET_F_SETLEASE:
-gemu_log("F_SETLEASE,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
-break;
-case TARGET_F_GETLEASE:
-gemu_log("F_GETLEASE");
-break;
-case TARGET_F_SETPIPE_SZ:
-gemu_log("F_SETPIPE_SZ,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
-break;
-case TARGET_F_GETPIPE_SZ:
-gemu_log("F_GETPIPE_SZ");
-break;
-case TARGET_F_DUPFD_CLOEXEC:
-gemu_log("F_DUPFD_CLOEXEC,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
-break;
-case TARGET_F_NOTIFY:
-gemu_log("F_NOTIFY,");
-print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
-break;
-default:
-print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
-print_pointer(arg2, 1);
-break;
-}
-print_syscall_epilogue(name);
-}
-#define print_fcntl64   print_fcntl
-#endif
-
-
 #if defined(TARGET_NR_socket)
 static void
 print_socket(const struct syscallname *name,
diff --git a/linux-user/syscall-fcntl.inc.c b/linux-user/syscall-fcntl.inc.c
new file mode 100644
index 00..768682bd17
--- /dev/null
+++ b/linux-user/syscall-fcntl.inc.c
@@ -0,0 +1,322 @@
+/*
+ *  Linux fcntl syscall implementation
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the 

[Qemu-devel] [PATCH v6 31/49] linux-user: Split out getpid, getppid, getxpid

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  9 +
 linux-user/syscall-proc.inc.c | 23 +++
 linux-user/syscall.c  | 14 --
 linux-user/strace.list|  9 -
 4 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 3453e7afdf..d163bbf409 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -36,6 +36,15 @@ SYSCALL_DEF(fchmodat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG);
 #ifdef TARGET_NR_fork
 SYSCALL_DEF(fork);
 #endif
+#ifdef TARGET_NR_getpid
+SYSCALL_DEF(getpid);
+#endif
+#ifdef TARGET_NR_getppid
+SYSCALL_DEF(getppid);
+#endif
+#ifdef TARGET_NR_getxpid
+SYSCALL_DEF(getxpid);
+#endif
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index 699370c290..c09c83775c 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -438,6 +438,29 @@ SYSCALL_IMPL(fork)
 }
 #endif
 
+#ifdef TARGET_NR_getpid
+SYSCALL_IMPL(getpid)
+{
+return getpid();
+}
+#endif
+
+#ifdef TARGET_NR_getppid
+SYSCALL_IMPL(getppid)
+{
+return getppid();
+}
+#endif
+
+#ifdef TARGET_NR_getxpid
+SYSCALL_IMPL(getxpid)
+{
+/* Alpha specific */
+cpu_env->ir[IR_A4] = getppid();
+return getpid();
+}
+#endif
+
 /*
  * Map host to target signal numbers for the wait family of syscalls.
  * Assume all other status bits are the same.
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 09fcec7812..6ea1a67345 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5327,16 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
-/* Alpha specific */
-case TARGET_NR_getxpid:
-((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid();
-return get_errno(getpid());
-#endif
-#ifdef TARGET_NR_getpid
-case TARGET_NR_getpid:
-return get_errno(getpid());
-#endif
 case TARGET_NR_mount:
 {
 /* need to look at the data field */
@@ -5668,10 +5658,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 return ret;
 }
 #endif
-#ifdef TARGET_NR_getppid /* not on alpha */
-case TARGET_NR_getppid:
-return get_errno(getppid());
-#endif
 #ifdef TARGET_NR_getpgrp
 case TARGET_NR_getpgrp:
 return get_errno(getpgrp());
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 18c93ccc2d..344a2232d6 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -298,15 +298,9 @@
 #ifdef TARGET_NR_getpgrp
 { TARGET_NR_getpgrp, "getpgrp" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_getpid
-{ TARGET_NR_getpid, "getpid" , "%s()", NULL, NULL },
-#endif
 #ifdef TARGET_NR_getpmsg
 { TARGET_NR_getpmsg, "getpmsg" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_getppid
-{ TARGET_NR_getppid, "getppid" , "%s()", NULL, NULL },
-#endif
 #ifdef TARGET_NR_getpriority
 { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
 #endif
@@ -365,9 +359,6 @@
 #ifdef TARGET_NR_getxgid
 { TARGET_NR_getxgid, "getxgid" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_getxpid
-{ TARGET_NR_getxpid, "getxpid" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_getxuid
 { TARGET_NR_getxuid, "getxuid" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 19/49] linux-user: Split out wait4, waitid, waitpid

2019-01-18 Thread Richard Henderson
Note that waitid is universally provided and need not be conditional.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  5 ++
 linux-user/syscall-proc.inc.c | 88 +++
 linux-user/syscall.c  | 67 --
 linux-user/strace.list|  9 
 4 files changed, 93 insertions(+), 76 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 6f6f77927b..a84050a318 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -118,5 +118,10 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 /* Emulate vfork() with fork().  */
 SYSCALL_DEF_FULL(vfork, .impl = impl_fork);
 #endif
+SYSCALL_DEF(wait4, ARG_DEC, ARG_PTR, ARG_HEX, ARG_PTR);
+SYSCALL_DEF(waitid, ARG_HEX, ARG_DEC, ARG_PTR, ARG_HEX);
+#ifdef TARGET_NR_waitpid
+SYSCALL_DEF(waitpid, ARG_DEC, ARG_PTR, ARG_HEX);
+#endif
 SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index b89ac56552..37f5bbe197 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -318,3 +318,91 @@ SYSCALL_IMPL(fork)
 return do_clone(cpu_env, TARGET_SIGCHLD, 0, 0, 0, 0);
 }
 #endif
+
+/*
+ * Map host to target signal numbers for the wait family of syscalls.
+ * Assume all other status bits are the same.
+ */
+int host_to_target_waitstatus(int status)
+{
+if (WIFSIGNALED(status)) {
+return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f);
+}
+if (WIFSTOPPED(status)) {
+return (host_to_target_signal(WSTOPSIG(status)) << 8)
+   | (status & 0xff);
+}
+return status;
+}
+
+SYSCALL_IMPL(wait4)
+{
+int status;
+pid_t pid = arg1;
+abi_ulong status_ptr = arg2;
+int options = arg3;
+abi_ulong target_rusage = arg4;
+struct rusage rusage;
+struct rusage *rusage_ptr = target_rusage ?  : NULL;
+abi_long ret;
+
+ret = get_errno(safe_wait4(pid, , options, rusage_ptr));
+if (!is_error(ret)) {
+if (status_ptr && ret) {
+status = host_to_target_waitstatus(status);
+if (put_user_s32(status, status_ptr)) {
+return -TARGET_EFAULT;
+}
+}
+if (target_rusage) {
+abi_long err = host_to_target_rusage(target_rusage, );
+if (err) {
+ret = err;
+}
+}
+}
+return ret;
+}
+
+SYSCALL_IMPL(waitid)
+{
+idtype_t idtype = arg1;
+id_t id = arg2;
+abi_ulong target_info = arg3;
+int options = arg4;
+siginfo_t info, *info_ptr = target_info ?  : NULL;
+abi_long ret;
+
+info.si_pid = 0;
+ret = get_errno(safe_waitid(idtype, id, info_ptr, options, NULL));
+if (!is_error(ret) && target_info && info.si_pid != 0) {
+target_siginfo_t *p = lock_user(VERIFY_WRITE, target_info,
+sizeof(target_siginfo_t), 0);
+if (!p) {
+return -TARGET_EFAULT;
+}
+host_to_target_siginfo(p, );
+unlock_user(p, target_info, sizeof(target_siginfo_t));
+}
+return ret;
+}
+
+#ifdef TARGET_NR_waitpid
+SYSCALL_IMPL(waitpid)
+{
+pid_t pid = arg1;
+abi_ulong target_status = arg2;
+int options = arg3;
+int status;
+abi_long ret;
+
+ret = get_errno(safe_wait4(pid, , options, NULL));
+if (!is_error(ret)
+&& target_status
+&& ret
+&& put_user_s32(host_to_target_waitstatus(status), target_status)) {
+return -TARGET_EFAULT;
+}
+return ret;
+}
+#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1d18d28fbe..8da92dd188 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5218,20 +5218,6 @@ static abi_long do_signalfd4(int fd, abi_long mask, int 
flags)
 }
 #endif
 
-/* Map host to target signal numbers for the wait family of syscalls.
-   Assume all other status bits are the same.  */
-int host_to_target_waitstatus(int status)
-{
-if (WIFSIGNALED(status)) {
-return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f);
-}
-if (WIFSTOPPED(status)) {
-return (host_to_target_signal(WSTOPSIG(status)) << 8)
-   | (status & 0xff);
-}
-return status;
-}
-
 #define TIMER_MAGIC 0x0caf
 #define TIMER_MAGIC_MASK 0x
 
@@ -5344,32 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_waitpid
-case TARGET_NR_waitpid:
-{
-int status;
-ret = get_errno(safe_wait4(arg1, , arg3, 0));
-if (!is_error(ret) && arg2 && ret
-&& put_user_s32(host_to_target_waitstatus(status), arg2))
-return -TARGET_EFAULT;
-}
-return ret;
-#endif
-#ifdef TARGET_NR_waitid
-case TARGET_NR_waitid:
-{
-siginfo_t info;
-  

[Qemu-devel] [PATCH v6 45/49] linux-user: Split out times

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  1 +
 linux-user/syscall-proc.inc.c | 25 +
 linux-user/syscall.c  | 18 --
 linux-user/strace.list|  3 ---
 4 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index bd3301a72f..25d5aaccd1 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -204,6 +204,7 @@ SYSCALL_DEF(syncfs, ARG_DEC);
 #ifdef TARGET_NR_time
 SYSCALL_DEF(time, ARG_PTR);
 #endif
+SYSCALL_DEF(times, ARG_PTR);
 #ifdef TARGET_NR_umount
 SYSCALL_DEF(umount, ARG_STR);
 #endif
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index 58c0a22300..09a0306406 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -468,6 +468,31 @@ SYSCALL_IMPL(nice)
 }
 #endif
 
+SYSCALL_IMPL(times)
+{
+abi_ulong target_buf = arg1;
+struct tms tms;
+abi_long ret;
+
+ret = get_errno(times());
+if (target_buf) {
+struct target_tms *tmsp = lock_user(VERIFY_WRITE, target_buf,
+sizeof(struct target_tms), 0);
+if (!tmsp) {
+return -TARGET_EFAULT;
+}
+tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime));
+tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime));
+tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime));
+tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime));
+unlock_user(tmsp, target_buf, sizeof(struct target_tms));
+}
+if (!is_error(ret)) {
+ret = host_to_target_clock_t(ret);
+}
+return ret;
+}
+
 /*
  * Map host to target signal numbers for the wait family of syscalls.
  * Assume all other status bits are the same.
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3a322a61ca..d0bf339281 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5293,24 +5293,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-case TARGET_NR_times:
-{
-struct target_tms *tmsp;
-struct tms tms;
-ret = get_errno(times());
-if (arg1) {
-tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct 
target_tms), 0);
-if (!tmsp)
-return -TARGET_EFAULT;
-tmsp->tms_utime = 
tswapal(host_to_target_clock_t(tms.tms_utime));
-tmsp->tms_stime = 
tswapal(host_to_target_clock_t(tms.tms_stime));
-tmsp->tms_cutime = 
tswapal(host_to_target_clock_t(tms.tms_cutime));
-tmsp->tms_cstime = 
tswapal(host_to_target_clock_t(tms.tms_cstime));
-}
-if (!is_error(ret))
-ret = host_to_target_clock_t(ret);
-}
-return ret;
 case TARGET_NR_acct:
 if (arg1 == 0) {
 ret = get_errno(acct(NULL));
diff --git a/linux-user/strace.list b/linux-user/strace.list
index ac25e13bfa..4ea11f162e 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1290,9 +1290,6 @@
 #ifdef TARGET_NR_timerfd_settime
 { TARGET_NR_timerfd_settime, "timerfd_settime" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_times
-{ TARGET_NR_times, "times" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_tkill
 { TARGET_NR_tkill, "tkill" , NULL, print_tkill, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 13/49] linux-user: Split out name_to_handle_at, open_by_handle_at

2019-01-18 Thread Richard Henderson
All targets have these syscalls, so they need not be ifdefed.
If we provide safe syscalls for the host, we can remove the
configure test for this too.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |   3 +
 linux-user/syscall.h  |   1 +
 linux-user/strace.c   |   5 +-
 linux-user/syscall-file.inc.c |  81 +++
 linux-user/syscall.c  | 102 ++
 configure |  20 ---
 linux-user/strace.list|   3 -
 7 files changed, 93 insertions(+), 122 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index ae89be0e87..1fc89c1b08 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -17,10 +17,13 @@
  */
 
 SYSCALL_DEF(close, ARG_DEC);
+SYSCALL_DEF(name_to_handle_at,
+ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
 #ifdef TARGET_NR_open
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+SYSCALL_DEF(open_by_handle_at, ARG_DEC, ARG_PTR, ARG_OPENFLAG);
 SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
  .args = args_pread64_pwrite64,
  .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index 43b5dc0684..83f602f8e7 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -57,6 +57,7 @@ typedef enum {
 
 /* These print as sets of flags.  */
 ARG_ATDIRFD,
+ARG_ATFLAG,
 ARG_MODEFLAG,
 ARG_OPENFLAG,
 
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 4faeb8c031..ed311b081b 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -780,7 +780,7 @@ UNUSED static struct flags access_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags at_file_flags[] = {
+static struct flags const at_file_flags[] = {
 #ifdef AT_EACCESS
 FLAG_GENERIC(AT_EACCESS),
 #endif
@@ -2681,6 +2681,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_ATDIRFD:
 len = add_atdirfd(b, rest, arg);
 break;
+case ARG_ATFLAG:
+len = add_flags(b, rest, at_file_flags, arg, false);
+break;
 case ARG_MODEFLAG:
 len = add_flags(b, rest, mode_flags, arg, true);
 break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 63401684c3..81423cfd64 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -317,6 +317,87 @@ SYSCALL_IMPL(openat)
 return do_openat(cpu_env, arg1, arg2, arg3, arg4);
 }
 
+SYSCALL_IMPL(name_to_handle_at)
+{
+struct file_handle *target_fh;
+struct file_handle *fh;
+int mid = 0;
+abi_long ret;
+char *name;
+uint32_t size, total_size;
+
+if (get_user_s32(size, arg3)) {
+return -TARGET_EFAULT;
+}
+total_size = sizeof(struct file_handle) + size;
+target_fh = lock_user(VERIFY_WRITE, arg3, total_size, 0);
+if (!target_fh) {
+return -TARGET_EFAULT;
+}
+
+name = lock_user_string(arg2);
+if (!name) {
+unlock_user(target_fh, arg3, 0);
+return -TARGET_EFAULT;
+}
+
+fh = g_malloc0(total_size);
+fh->handle_bytes = size;
+
+ret = get_errno(safe_name_to_handle_at(arg1, path(name), fh, , arg5));
+unlock_user(name, arg2, 0);
+
+/*
+ * man name_to_handle_at(2):
+ * Other than the use of the handle_bytes field, the caller should treat
+ * the file_handle structure as an opaque data type
+ */
+if (!is_error(ret)) {
+memcpy(target_fh, fh, total_size);
+target_fh->handle_bytes = tswap32(fh->handle_bytes);
+target_fh->handle_type = tswap32(fh->handle_type);
+g_free(fh);
+unlock_user(target_fh, arg3, total_size);
+
+if (put_user_s32(mid, arg4)) {
+return -TARGET_EFAULT;
+}
+}
+return ret;
+}
+
+SYSCALL_IMPL(open_by_handle_at)
+{
+abi_long mount_fd = arg1;
+abi_long handle = arg2;
+int host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl);
+struct file_handle *target_fh;
+struct file_handle *fh;
+unsigned int size, total_size;
+abi_long ret;
+
+if (get_user_s32(size, handle)) {
+return -TARGET_EFAULT;
+}
+total_size = sizeof(struct file_handle) + size;
+target_fh = lock_user(VERIFY_READ, handle, total_size, 1);
+if (!target_fh) {
+return -TARGET_EFAULT;
+}
+
+fh = g_memdup(target_fh, total_size);
+fh->handle_bytes = size;
+fh->handle_type = tswap32(target_fh->handle_type);
+
+ret = get_errno(safe_open_by_handle_at(mount_fd, fh, host_flags));
+
+g_free(fh);
+unlock_user(target_fh, handle, total_size);
+
+fd_trans_unregister(ret);
+return ret;
+}
+
 /*
  * Both pread64 and pwrite64 merge args into a 64-bit offset,
  * but the input registers and ordering are target 

[Qemu-devel] [PATCH v6 46/49] linux-user: Split out acct

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  1 +
 linux-user/syscall-file.inc.c | 18 ++
 linux-user/syscall.c  | 11 ---
 linux-user/strace.list|  3 ---
 4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 25d5aaccd1..f8f280f376 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -19,6 +19,7 @@
 #ifdef TARGET_NR_access
 SYSCALL_DEF(access, ARG_STR, ARG_ACCESSFLAG);
 #endif
+SYSCALL_DEF(acct, ARG_STR);
 #ifdef TARGET_NR_alarm
 SYSCALL_DEF(alarm, ARG_DEC);
 #endif
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 90aacfacaf..dd0bf877d5 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -36,6 +36,24 @@ SYSCALL_IMPL(access)
 }
 #endif
 
+SYSCALL_IMPL(acct)
+{
+abi_ulong target_path = arg1;
+abi_long ret;
+
+if (target_path == 0) {
+ret = get_errno(acct(NULL));
+} else {
+char *p = lock_user_string(target_path);
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(acct(path(p)));
+unlock_user(p, target_path, 0);
+}
+return ret;
+}
+
 SYSCALL_IMPL(chdir)
 {
 abi_ulong target_path = arg1;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d0bf339281..33d536262f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5293,17 +5293,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-case TARGET_NR_acct:
-if (arg1 == 0) {
-ret = get_errno(acct(NULL));
-} else {
-if (!(p = lock_user_string(arg1))) {
-return -TARGET_EFAULT;
-}
-ret = get_errno(acct(path(p)));
-unlock_user(p, arg1, 0);
-}
-return ret;
 case TARGET_NR_ioctl:
 return do_ioctl(arg1, arg2, arg3);
 #ifdef TARGET_NR_fcntl
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 4ea11f162e..9f2f8977b4 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -9,9 +9,6 @@
 #ifdef TARGET_NR_accept4
 { TARGET_NR_accept4, "accept4" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_acct
-{ TARGET_NR_acct, "acct" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_add_key
 { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 30/49] linux-user: Split out lseek, llseek

2019-01-18 Thread Richard Henderson
Canonicalise the target syscall name on llseek (new kernels)
instead of _llseek (old kernels).  Always use host lseek(3)
rather than attempting to use the host llseek(2).

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  6 ++
 linux-user/syscall.h  |  1 +
 linux-user/strace.c   | 39 +++
 linux-user/syscall-file.inc.c | 36 
 linux-user/syscall.c  | 32 ++--
 linux-user/strace.list|  6 --
 6 files changed, 62 insertions(+), 58 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 3ddf8aa0e3..3453e7afdf 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -43,6 +43,12 @@ SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, 
ARG_PTR, ARG_HEX);
 SYSCALL_DEF(link, ARG_STR, ARG_STR);
 #endif
 SYSCALL_DEF(linkat, ARG_ATDIRFD, ARG_STR, ARG_ATDIRFD, ARG_STR, ARG_ATFLAG);
+#ifdef TARGET_NR_lseek
+SYSCALL_DEF(lseek, ARG_DEC, ARG_DEC, ARG_LSEEKWHENCE);
+#endif
+#ifdef TARGET_NR_llseek
+SYSCALL_DEF_ARGS(llseek, ARG_DEC, ARG_DEC, ARG_PTR, ARG_LSEEKWHENCE);
+#endif
 #ifdef TARGET_NR_mknod
 SYSCALL_DEF(mknod, ARG_STR, ARG_MODEFLAG, ARG_HEX);
 #endif
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index bdc4d653c4..c16c0a3f1e 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -64,6 +64,7 @@ typedef enum {
 ARG_MODEFLAG,
 ARG_OPENFLAG,
 ARG_UNLINKATFLAG,
+ARG_LSEEKWHENCE,
 
 /* These are interpreted as pointers.  */
 ARG_PTR,
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 66d981b9e6..c08dbdff0c 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -934,6 +934,20 @@ print_open_flags(abi_long flags, int last)
 gemu_log("%s%s", buf, get_comma(last));
 }
 
+static int add_lseek_whence(char *buf, int size, int whence)
+{
+switch (whence) {
+case SEEK_SET:
+return snprintf(buf, size, "SEEK_SET");
+case SEEK_CUR:
+return snprintf(buf, size, "SEEK_CUR");
+case SEEK_END:
+return snprintf(buf, size, "SEEK_END");
+default:
+return snprintf(buf, size, "%#x", whence);
+}
+}
+
 static void
 print_syscall_prologue(const struct syscallname *sc)
 {
@@ -1285,28 +1299,6 @@ print_futimesat(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR__llseek
-static void
-print__llseek(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-const char *whence = "UNKNOWN";
-print_syscall_prologue(name);
-print_raw_param("%d", arg0, 0);
-print_raw_param("%ld", arg1, 0);
-print_raw_param("%ld", arg2, 0);
-print_pointer(arg3, 0);
-switch(arg4) {
-case SEEK_SET: whence = "SEEK_SET"; break;
-case SEEK_CUR: whence = "SEEK_CUR"; break;
-case SEEK_END: whence = "SEEK_END"; break;
-}
-gemu_log("%s",whence);
-print_syscall_epilogue(name);
-}
-#endif
-
 #if defined(TARGET_NR_socket)
 static void
 print_socket(const struct syscallname *name,
@@ -2317,6 +2309,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_UNLINKATFLAG:
 len = add_flags(b, rest, unlinkat_flags, arg, true);
 break;
+case ARG_LSEEKWHENCE:
+len = add_lseek_whence(b, rest, arg);
+break;
 case ARG_PTR:
 len = add_pointer(b, rest, arg);
 break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 9844382166..e23d21bdfc 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -112,6 +112,42 @@ SYSCALL_IMPL(linkat)
 return do_linkat(arg1, arg2, arg3, arg4, arg5);
 }
 
+#ifdef TARGET_NR_lseek
+SYSCALL_IMPL(lseek)
+{
+return get_errno(lseek(arg1, arg2, arg3));
+}
+#endif
+
+#ifdef TARGET_NR_llseek
+SYSCALL_ARGS(llseek)
+{
+/* The parts for offset are *always* in big-endian order.  */
+abi_ulong lo = in[2], hi = in[1];
+out[1] = (((uint64_t)hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+out[2] = in[3];
+out[3] = in[4];
+return def;
+}
+
+SYSCALL_IMPL(llseek)
+{
+int fd = arg1;
+int64_t offset = arg2;
+abi_ulong target_res = arg3;
+int whence = arg4;
+
+off_t res = lseek(fd, offset, whence);
+
+if (res == -1) {
+return get_errno(-1);
+} else if (put_user_s64(res, target_res)) {
+return -TARGET_EFAULT;
+}
+return 0;
+}
+#endif
+
 static abi_long do_mknodat(int dirfd, abi_ulong target_path,
mode_t mode, dev_t dev)
 {
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f9101d0b08..09fcec7812 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -195,8 +195,8 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 
arg4,type5 arg5,   \
 #endif
 
 /* Newer kernel ports have llseek() instead of _llseek() */
-#if 

[Qemu-devel] [PATCH v6 39/49] linux-user: Split out sync, syncfs

2019-01-18 Thread Richard Henderson
Note that syncfs is universally available.
If !CONFIG_SYNCFS, provide our own syscall replacement.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  2 ++
 linux-user/syscall-file.inc.c | 11 +++
 linux-user/syscall.c  | 20 
 linux-user/strace.list|  6 --
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 860754aaca..497fbdba66 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -171,6 +171,8 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 #ifdef TARGET_NR_stime
 SYSCALL_DEF(stime, ARG_PTR);
 #endif
+SYSCALL_DEF(sync);
+SYSCALL_DEF(syncfs, ARG_DEC);
 #ifdef TARGET_NR_time
 SYSCALL_DEF(time, ARG_PTR);
 #endif
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 3111abd861..80dec33971 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -867,6 +867,17 @@ SYSCALL_IMPL(readlinkat)
 }
 #endif
 
+SYSCALL_IMPL(sync)
+{
+sync();
+return 0;
+}
+
+SYSCALL_IMPL(syncfs)
+{
+return get_errno(syncfs(arg1));
+}
+
 static abi_long do_umount2(abi_ulong target_path, int flags)
 {
 char *p = lock_user_string(target_path);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 351b2a6288..6668e4ada8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -199,6 +199,15 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 
arg4,type5 arg5,  \
 #define TARGET_NR_llseek TARGET_NR__llseek
 #endif
 
+/*
+ * These definitions produce an ENOSYS from the host kernel.
+ * Performing a bogus sysacll is lazier than boilerplating
+ * the replacement functions here in C.
+ */
+#ifndef __NR_syncfs
+#define __NR_syncfs  -1
+#endif
+
 #ifdef __NR_gettid
 _syscall0(int, gettid)
 #else
@@ -264,11 +273,13 @@ _syscall3(int, ioprio_set, int, which, int, who, int, 
ioprio)
 #if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)
 _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)
 #endif
-
 #if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)
 _syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type,
   unsigned long, idx1, unsigned long, idx2)
 #endif
+#ifndef CONFIG_SYNCFS
+_syscall1(int, syncfs, int, fd)
+#endif
 
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,O_ACCMODE,   O_WRONLY,},
@@ -5327,13 +5338,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-case TARGET_NR_sync:
-sync();
-return 0;
-#if defined(TARGET_NR_syncfs) && defined(CONFIG_SYNCFS)
-case TARGET_NR_syncfs:
-return get_errno(syncfs(arg1));
-#endif
 case TARGET_NR_kill:
 return get_errno(safe_kill(arg1, target_to_host_signal(arg2)));
 #ifdef TARGET_NR_rename
diff --git a/linux-user/strace.list b/linux-user/strace.list
index aaea23d433..56f25c15b7 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1260,12 +1260,6 @@
 #ifdef TARGET_NR_symlinkat
 { TARGET_NR_symlinkat, "symlinkat", NULL, print_symlinkat, NULL },
 #endif
-#ifdef TARGET_NR_sync
-{ TARGET_NR_sync, "sync" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_syncfs
-{ TARGET_NR_syncfs, "syncfs" , "%s(%d)", NULL, NULL },
-#endif
 #ifdef TARGET_NR_syscall
 { TARGET_NR_syscall, "syscall" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 43/49] linux-user: Split out dup, dup2, dup3

2019-01-18 Thread Richard Henderson
Note that dup3 is universally available for guests.
Implement host support with syscall when !CONFIG_DUP3.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  5 +
 linux-user/syscall-file.inc.c | 42 +++
 linux-user/syscall.c  | 33 +++
 linux-user/strace.list|  6 -
 4 files changed, 50 insertions(+), 36 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 8b6d8f75ff..062a75 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -34,6 +34,11 @@ SYSCALL_DEF(close, ARG_DEC);
 #ifdef TARGET_NR_creat
 SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
 #endif
+SYSCALL_DEF(dup, ARG_DEC);
+#ifdef TARGET_NR_dup2
+SYSCALL_DEF(dup2, ARG_DEC, ARG_DEC);
+#endif
+SYSCALL_DEF(dup3, ARG_DEC, ARG_DEC, ARG_OPENFLAG);
 SYSCALL_DEF(exit, ARG_DEC);
 SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 83174c5781..5e8298fdb3 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -94,6 +94,48 @@ SYSCALL_IMPL(creat)
 }
 #endif
 
+SYSCALL_IMPL(dup)
+{
+abi_long ret = get_errno(dup(arg1));
+if (ret >= 0) {
+fd_trans_dup(arg1, ret);
+}
+return ret;
+}
+
+#ifdef TARGET_NR_dup2
+SYSCALL_IMPL(dup2)
+{
+abi_long ret = get_errno(dup2(arg1, arg2));
+if (ret >= 0) {
+fd_trans_dup(arg1, arg2);
+}
+return ret;
+}
+#endif
+
+SYSCALL_IMPL(dup3)
+{
+int ofd = arg1;
+int nfd = arg2;
+int host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl);
+abi_long ret;
+
+#ifdef CONFIG_DUP3
+ret = dup3(ofd, nfd, host_flags);
+#else
+if (host_flags == 0) {
+if (ofd == nfd) {
+return -TARGET_EINVAL;
+}
+ret = dup2(ofd, nfd);
+} else {
+ret = syscall(__NR_dup3, ofd, nfd, host_flags);
+}
+#endif
+return get_errno(ret);
+}
+
 SYSCALL_IMPL(faccessat)
 {
 return do_faccessat(arg1, arg2, arg3);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7874a48840..29a9d5fce4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -204,6 +204,9 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 
arg4,type5 arg5,   \
  * Performing a bogus sysacll is lazier than boilerplating
  * the replacement functions here in C.
  */
+#ifndef __NR_dup3
+#define __NR_dup3  -1
+#endif
 #ifndef __NR_syncfs
 #define __NR_syncfs  -1
 #endif
@@ -5320,12 +5323,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-case TARGET_NR_dup:
-ret = get_errno(dup(arg1));
-if (ret >= 0) {
-fd_trans_dup(arg1, ret);
-}
-return ret;
 #ifdef TARGET_NR_pipe
 case TARGET_NR_pipe:
 return do_pipe(cpu_env, arg1, 0, 0);
@@ -5380,30 +5377,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 ret = get_errno(chroot(p));
 unlock_user(p, arg1, 0);
 return ret;
-#ifdef TARGET_NR_dup2
-case TARGET_NR_dup2:
-ret = get_errno(dup2(arg1, arg2));
-if (ret >= 0) {
-fd_trans_dup(arg1, arg2);
-}
-return ret;
-#endif
-#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
-case TARGET_NR_dup3:
-{
-int host_flags;
-
-if ((arg3 & ~TARGET_O_CLOEXEC) != 0) {
-return -EINVAL;
-}
-host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl);
-ret = get_errno(dup3(arg1, arg2, host_flags));
-if (ret >= 0) {
-fd_trans_dup(arg1, arg2);
-}
-return ret;
-}
-#endif
 #ifdef TARGET_NR_getpgrp
 case TARGET_NR_getpgrp:
 return get_errno(getpgrp());
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 678feeeb7b..151b0eb42d 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -91,12 +91,6 @@
 #ifdef TARGET_NR_dipc
 { TARGET_NR_dipc, "dipc" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_dup
-{ TARGET_NR_dup, "dup" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_dup2
-{ TARGET_NR_dup2, "dup2" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_epoll_create
 { TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 11/49] linux-user: Split out pread64, pwrite64

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  6 
 linux-user/syscall-file.inc.c | 62 +++
 linux-user/syscall.c  | 36 
 linux-user/strace.list|  6 
 4 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 130ba7e344..027793d5d0 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -21,6 +21,12 @@ SYSCALL_DEF(close, ARG_DEC);
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
+ .args = args_pread64_pwrite64,
+ .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
+SYSCALL_DEF_FULL(pwrite64, .impl = impl_pwrite64,
+ .args = args_pread64_pwrite64,
+ .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
 SYSCALL_DEF(read, ARG_DEC, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_readlink
 SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 9bd21ac5cd..e79cfabf56 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -317,6 +317,68 @@ SYSCALL_IMPL(openat)
 return do_openat(cpu_env, arg1, arg2, arg3, arg4);
 }
 
+/*
+ * Both pread64 and pwrite64 merge args into a 64-bit offset,
+ * but the input registers and ordering are target specific.
+ */
+#if TARGET_ABI_BITS == 32
+SYSCALL_ARGS(pread64_pwrite64)
+{
+/* We have already assigned out[0-2].  */
+int off = regpairs_aligned(cpu_env, TARGET_NR_pread64);
+out[3] = target_offset64(in[3 + off], in[4 + off]);
+return def;
+}
+#else
+#define args_pread64_pwrite64 NULL
+#endif
+
+SYSCALL_IMPL(pread64)
+{
+int fd = arg1;
+abi_ulong target_buf = arg2;
+abi_ulong len = arg3;
+uint64_t off = arg4;
+void *p;
+abi_long ret;
+
+if (target_buf == 0 && len == 0) {
+/* Special-case NULL buffer and zero length, which should succeed */
+p = NULL;
+} else {
+p = lock_user(VERIFY_WRITE, target_buf, len, 0);
+if (!p) {
+return -TARGET_EFAULT;
+}
+}
+ret = get_errno(pread64(fd, p, len, off));
+unlock_user(p, target_buf, ret);
+return ret;
+}
+
+SYSCALL_IMPL(pwrite64)
+{
+int fd = arg1;
+abi_ulong target_buf = arg2;
+abi_ulong len = arg3;
+uint64_t off = arg4;
+void *p;
+abi_long ret;
+
+if (target_buf == 0 && len == 0) {
+/* Special-case NULL buffer and zero length, which should succeed */
+p = 0;
+} else {
+p = lock_user(VERIFY_READ, target_buf, len, 1);
+if (!p) {
+return -TARGET_EFAULT;
+}
+}
+ret = get_errno(pwrite64(fd, p, len, off));
+unlock_user(p, target_buf, 0);
+return ret;
+}
+
 SYSCALL_IMPL(read)
 {
 int fd = arg1;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index df47ee106e..80806c0150 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9312,42 +9312,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #else
 #error unreachable
 #endif
-#endif
-#ifdef TARGET_NR_pread64
-case TARGET_NR_pread64:
-if (regpairs_aligned(cpu_env, num)) {
-arg4 = arg5;
-arg5 = arg6;
-}
-if (arg2 == 0 && arg3 == 0) {
-/* Special-case NULL buffer and zero length, which should succeed 
*/
-p = 0;
-} else {
-p = lock_user(VERIFY_WRITE, arg2, arg3, 0);
-if (!p) {
-return -TARGET_EFAULT;
-}
-}
-ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
-unlock_user(p, arg2, ret);
-return ret;
-case TARGET_NR_pwrite64:
-if (regpairs_aligned(cpu_env, num)) {
-arg4 = arg5;
-arg5 = arg6;
-}
-if (arg2 == 0 && arg3 == 0) {
-/* Special-case NULL buffer and zero length, which should succeed 
*/
-p = 0;
-} else {
-p = lock_user(VERIFY_READ, arg2, arg3, 1);
-if (!p) {
-return -TARGET_EFAULT;
-}
-}
-ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
-unlock_user(p, arg2, 0);
-return ret;
 #endif
 case TARGET_NR_getcwd:
 if (!(p = lock_user(VERIFY_WRITE, arg1, arg2, 0)))
diff --git a/linux-user/strace.list b/linux-user/strace.list
index e02a854cea..c7e573669d 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1025,9 +1025,6 @@
 #ifdef TARGET_NR_prctl
 { TARGET_NR_prctl, "prctl" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_pread64
-{ TARGET_NR_pread64, "pread64" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_preadv
 { TARGET_NR_preadv, "preadv" , NULL, NULL, NULL },
 #endif
@@ 

[Qemu-devel] [PATCH v6 23/49] linux-user: Split out unlink, unlinkat, rmdir

2019-01-18 Thread Richard Henderson
Note that unlinkat is universally provided.
Implement rmdir in terms of unlinkat.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  7 ++
 linux-user/syscall.h  |  1 +
 linux-user/strace.c   | 43 ---
 linux-user/syscall-file.inc.c | 32 ++
 linux-user/syscall.c  | 24 ---
 linux-user/strace.list|  9 
 6 files changed, 44 insertions(+), 72 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 41dd887dbc..78d3f600eb 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -98,6 +98,9 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
 SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC);
+#ifdef TARGET_NR_rmdir
+SYSCALL_DEF(rmdir, ARG_STR);
+#endif
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semctl)
 SYSCALL_DEF(semctl, ARG_DEC, ARG_DEC, ARG_DEC, ARG_HEX);
 #endif
@@ -121,6 +124,10 @@ SYSCALL_DEF(shmdt, ARG_PTR);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmget)
 SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 #endif
+#ifdef TARGET_NR_unlink
+SYSCALL_DEF(unlink, ARG_STR);
+#endif
+SYSCALL_DEF(unlinkat, ARG_ATDIRFD, ARG_STR, ARG_UNLINKATFLAG);
 #ifdef TARGET_NR_vfork
 /* Emulate vfork() with fork().  */
 SYSCALL_DEF_FULL(vfork, .impl = impl_fork);
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index f75cd3ddd0..bdc4d653c4 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -63,6 +63,7 @@ typedef enum {
 ARG_MMAPPROT,
 ARG_MODEFLAG,
 ARG_OPENFLAG,
+ARG_UNLINKATFLAG,
 
 /* These are interpreted as pointers.  */
 ARG_PTR,
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 5b78eb137b..a41b6dcfe7 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -684,7 +684,7 @@ static struct flags const at_file_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags unlinkat_flags[] = {
+static struct flags const unlinkat_flags[] = {
 #ifdef AT_REMOVEDIR
 FLAG_GENERIC(AT_REMOVEDIR),
 #endif
@@ -1798,18 +1798,6 @@ print_mkdirat(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_rmdir
-static void
-print_rmdir(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_rt_sigaction
 static void
 print_rt_sigaction(const struct syscallname *name,
@@ -2175,32 +2163,6 @@ print_umount2(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_unlink
-static void
-print_unlink(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_unlinkat
-static void
-print_unlinkat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_flags(unlinkat_flags, arg2, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_utime
 static void
 print_utime(const struct syscallname *name,
@@ -2463,6 +2425,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_OPENFLAG:
 len = add_open_flags(b, rest, arg);
 break;
+case ARG_UNLINKATFLAG:
+len = add_flags(b, rest, unlinkat_flags, arg, true);
+break;
 case ARG_PTR:
 len = add_pointer(b, rest, arg);
 break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index c6ca80955b..2dd57176b3 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -656,6 +656,38 @@ SYSCALL_IMPL(readlinkat)
 }
 #endif
 
+static abi_long do_unlinkat(int dirfd, abi_ulong target_path, int flags)
+{
+char *p = lock_user_string(target_path);
+abi_long ret;
+
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(unlinkat(dirfd, p, flags));
+unlock_user(p, target_path, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_unlink
+SYSCALL_IMPL(unlink)
+{
+return do_unlinkat(AT_FDCWD, arg1, 0);
+}
+#endif
+
+#ifdef TARGET_NR_rmdir
+SYSCALL_IMPL(rmdir)
+{
+return do_unlinkat(AT_FDCWD, arg1, AT_REMOVEDIR);
+}
+#endif
+
+SYSCALL_IMPL(unlinkat)
+{
+return do_unlinkat(arg1, arg2, arg3);
+}
+
 SYSCALL_IMPL(write)
 {
 int fd = arg1;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f1e8d06996..eda199d46f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5330,22 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 

[Qemu-devel] [PATCH v6 35/49] linux-user: Split out alarm, pause

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h|  6 ++
 linux-user/syscall-sig.inc.c | 36 
 linux-user/syscall.c | 12 +---
 linux-user/strace.list   |  6 --
 4 files changed, 43 insertions(+), 17 deletions(-)
 create mode 100644 linux-user/syscall-sig.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 6ca82af397..9d0dd7457b 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -16,6 +16,9 @@
  *  along with this program; if not, see .
  */
 
+#ifdef TARGET_NR_alarm
+SYSCALL_DEF(alarm, ARG_DEC);
+#endif
 SYSCALL_DEF_FULL(brk, .impl = impl_brk,
  .print_ret = print_syscall_ptr_ret,
  .arg_type = { ARG_PTR });
@@ -106,6 +109,9 @@ SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 SYSCALL_DEF(open_by_handle_at, ARG_DEC, ARG_PTR, ARG_OPENFLAG);
+#ifdef TARGET_NR_pause
+SYSCALL_DEF(pause);
+#endif
 SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
  .args = args_pread64_pwrite64,
  .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
diff --git a/linux-user/syscall-sig.inc.c b/linux-user/syscall-sig.inc.c
new file mode 100644
index 00..f4e43eb00e
--- /dev/null
+++ b/linux-user/syscall-sig.inc.c
@@ -0,0 +1,36 @@
+/*
+ *  Linux signal related syscalls
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see .
+ */
+
+#ifdef TARGET_NR_alarm
+SYSCALL_IMPL(alarm)
+{
+return alarm(arg1);
+}
+#endif
+
+#ifdef TARGET_NR_pause
+SYSCALL_IMPL(pause)
+{
+if (!block_signals()) {
+CPUState *cpu = ENV_GET_CPU(cpu_env);
+TaskState *ts = cpu->opaque;
+sigsuspend(>signal_mask);
+}
+return -TARGET_EINTR;
+}
+#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c0ce4068b6..f3ea9600c8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5327,17 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_alarm /* not on alpha */
-case TARGET_NR_alarm:
-return alarm(arg1);
-#endif
-#ifdef TARGET_NR_pause /* not on alpha */
-case TARGET_NR_pause:
-if (!block_signals()) {
-sigsuspend(&((TaskState *)cpu->opaque)->signal_mask);
-}
-return -TARGET_EINTR;
-#endif
 #ifdef TARGET_NR_utime
 case TARGET_NR_utime:
 {
@@ -9135,6 +9124,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #include "syscall-ipc.inc.c"
 #include "syscall-mem.inc.c"
 #include "syscall-proc.inc.c"
+#include "syscall-sig.inc.c"
 #include "syscall-time.inc.c"
 
 #undef SYSCALL_IMPL
diff --git a/linux-user/strace.list b/linux-user/strace.list
index a5f308c497..b119b7a20c 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -25,9 +25,6 @@
 #ifdef TARGET_NR_afs_syscall
 { TARGET_NR_afs_syscall, "afs_syscall" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_alarm
-{ TARGET_NR_alarm, "alarm" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_aplib
 { TARGET_NR_aplib, "aplib" , NULL, NULL, NULL },
 #endif
@@ -872,9 +869,6 @@
 #ifdef TARGET_NR_osf_waitid
 { TARGET_NR_osf_waitid, "osf_waitid" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_pause
-{ TARGET_NR_pause, "pause" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_pciconfig_iobase
 { TARGET_NR_pciconfig_iobase, "pciconfig_iobase" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 38/49] linux-user: Split out nice

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h | 3 +++
 linux-user/syscall-proc.inc.c | 7 +++
 linux-user/syscall.c  | 4 
 linux-user/strace.list| 3 ---
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 39e3ae3c21..860754aaca 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -111,6 +111,9 @@ SYSCALL_DEF(munlockall);
 SYSCALL_DEF(munmap, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(name_to_handle_at,
 ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
+#ifdef TARGET_NR_nice
+SYSCALL_DEF(nice, ARG_DEC);
+#endif
 #ifdef TARGET_NR_open
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index c09c83775c..58c0a22300 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -461,6 +461,13 @@ SYSCALL_IMPL(getxpid)
 }
 #endif
 
+#ifdef TARGET_NR_nice
+SYSCALL_IMPL(nice)
+{
+return get_errno(nice(arg1));
+}
+#endif
+
 /*
  * Map host to target signal numbers for the wait family of syscalls.
  * Assume all other status bits are the same.
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9074cf8b8d..351b2a6288 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5327,10 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_nice /* not on alpha */
-case TARGET_NR_nice:
-return get_errno(nice(arg1));
-#endif
 case TARGET_NR_sync:
 sync();
 return 0;
diff --git a/linux-user/strace.list b/linux-user/strace.list
index fc0eb91e29..aaea23d433 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -527,9 +527,6 @@
 #ifdef TARGET_NR_nfsservctl
 { TARGET_NR_nfsservctl, "nfsservctl" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_nice
-{ TARGET_NR_nice, "nice" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_old_adjtimex
 { TARGET_NR_old_adjtimex, "old_adjtimex" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 32/49] linux-user: Split out mount

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  1 +
 linux-user/syscall.h  |  1 +
 linux-user/strace.c   | 21 +++--
 linux-user/syscall-file.inc.c | 48 ++
 linux-user/syscall.c  | 55 ---
 linux-user/strace.list|  3 --
 6 files changed, 54 insertions(+), 75 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index d163bbf409..2b331c6a6d 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -78,6 +78,7 @@ SYSCALL_DEF_FULL(mmap2, .impl = impl_mmap,
  .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT,
ARG_MMAPFLAG, ARG_DEC, ARG_DEC64 });
 #endif
+SYSCALL_DEF(mount, ARG_STR, ARG_STR, ARG_STR, ARG_MOUNTFLAG, ARG_PTR);
 SYSCALL_DEF(mprotect, ARG_PTR, ARG_DEC, ARG_MMAPPROT);
 SYSCALL_DEF_FULL(mremap, .impl = impl_mremap,
  .print_ret = print_syscall_ptr_ret,
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index c16c0a3f1e..35dd3e5fa3 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -62,6 +62,7 @@ typedef enum {
 ARG_MMAPFLAG,
 ARG_MMAPPROT,
 ARG_MODEFLAG,
+ARG_MOUNTFLAG,
 ARG_OPENFLAG,
 ARG_UNLINKATFLAG,
 ARG_LSEEKWHENCE,
diff --git a/linux-user/strace.c b/linux-user/strace.c
index c08dbdff0c..eb02430eba 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -708,7 +708,7 @@ static struct flags const open_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags mount_flags[] = {
+static struct flags const mount_flags[] = {
 #ifdef MS_BIND
 FLAG_GENERIC(MS_BIND),
 #endif
@@ -2003,22 +2003,6 @@ print_symlinkat(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_mount
-static void
-print_mount(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_string(arg1, 0);
-print_string(arg2, 0);
-print_flags(mount_flags, arg3, 0);
-print_pointer(arg4, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_umount
 static void
 print_umount(const struct syscallname *name,
@@ -2303,6 +2287,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_MODEFLAG:
 len = add_flags(b, rest, mode_flags, arg, true);
 break;
+case ARG_MOUNTFLAG:
+len = add_flags(b, rest, mount_flags, arg, true);
+break;
 case ARG_OPENFLAG:
 len = add_open_flags(b, rest, arg);
 break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index e23d21bdfc..d7eb72cc31 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -174,6 +174,54 @@ SYSCALL_IMPL(mknodat)
 return do_mknodat(arg1, arg2, arg3, arg4);
 }
 
+SYSCALL_IMPL(mount)
+{
+abi_ulong target_src = arg1;
+abi_ulong target_tgt = arg2;
+abi_ulong target_fst = arg3;
+abi_ulong mountflags = arg4;
+abi_ulong target_data = arg5;
+char *p_src = NULL, *p_tgt = NULL, *p_fst = NULL, *p_data = NULL;
+abi_long ret = -TARGET_EFAULT;
+
+if (target_src) {
+p_src = lock_user_string(target_src);
+if (!p_src) {
+goto exit0;
+}
+}
+
+p_tgt = lock_user_string(target_tgt);
+if (!p_tgt) {
+goto exit1;
+}
+
+if (target_fst) {
+p_fst = lock_user_string(target_fst);
+if (!p_fst) {
+goto exit2;
+}
+}
+
+/*
+ * FIXME - arg5 should be locked, but it isn't clear how to
+ * do that since it's not guaranteed to be a NULL-terminated
+ * string.
+ */
+if (target_data) {
+p_data = g2h(target_data);
+}
+ret = get_errno(mount(p_src, p_tgt, p_fst, mountflags, p_data));
+
+unlock_user(p_fst, target_fst, 0);
+ exit2:
+unlock_user(p_tgt, target_tgt, 0);
+ exit1:
+unlock_user(p_src, target_src, 0);
+ exit0:
+return ret;
+}
+
 /*
  * Helpers for do_openat, manipulating /proc/self/foo.
  */
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 6ea1a67345..39e749a985 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5327,61 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-case TARGET_NR_mount:
-{
-/* need to look at the data field */
-void *p2, *p3;
-
-if (arg1) {
-p = lock_user_string(arg1);
-if (!p) {
-return -TARGET_EFAULT;
-}
-} else {
-p = NULL;
-}
-
-p2 = lock_user_string(arg2);
-if (!p2) {
-if (arg1) {
-unlock_user(p, arg1, 0);
-}
-return -TARGET_EFAULT;
-   

[Qemu-devel] [PATCH v6 22/49] linux-user: Split out link, linkat

2019-01-18 Thread Richard Henderson
Note that linkat is universally provided.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  4 
 linux-user/strace.c   | 29 -
 linux-user/syscall-file.inc.c | 28 
 linux-user/syscall.c  | 32 
 linux-user/strace.list|  6 --
 5 files changed, 32 insertions(+), 67 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index de7a99f0c6..41dd887dbc 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -31,6 +31,10 @@ SYSCALL_DEF(fork);
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
+#ifdef TARGET_NR_link
+SYSCALL_DEF(link, ARG_STR, ARG_STR);
+#endif
+SYSCALL_DEF(linkat, ARG_ATDIRFD, ARG_STR, ARG_ATDIRFD, ARG_STR, ARG_ATFLAG);
 SYSCALL_DEF(mlock, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(mlockall, ARG_HEX);
 #ifdef TARGET_NR_mmap
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 5cb77223fd..5b78eb137b 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1357,35 +1357,6 @@ print_futimesat(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_link
-static void
-print_link(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_string(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_linkat
-static void
-print_linkat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_at_dirfd(arg2, 0);
-print_string(arg3, 0);
-print_flags(at_file_flags, arg4, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR__llseek
 static void
 print__llseek(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 62e1790e3b..c6ca80955b 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -40,6 +40,34 @@ SYSCALL_IMPL(creat)
 }
 #endif
 
+static abi_long do_linkat(int olddirfd, abi_ulong target_oldpath,
+  int newdirfd, abi_ulong target_newpath,
+  int flags)
+{
+char *oldpath = lock_user_string(target_oldpath);
+char *newpath = lock_user_string(target_newpath);
+abi_long ret = -TARGET_EFAULT;
+
+if (oldpath && newpath) {
+ret = get_errno(linkat(olddirfd, oldpath, newdirfd, newpath, flags));
+}
+unlock_user(oldpath, target_oldpath, 0);
+unlock_user(newpath, target_newpath, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_link
+SYSCALL_IMPL(link)
+{
+return do_linkat(AT_FDCWD, arg1, AT_FDCWD, arg2, 0);
+}
+#endif
+
+SYSCALL_IMPL(linkat)
+{
+return do_linkat(arg1, arg2, arg3, arg4, arg5);
+}
+
 /*
  * Helpers for do_openat, manipulating /proc/self/foo.
  */
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1e9478611c..f1e8d06996 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5330,38 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_link
-case TARGET_NR_link:
-{
-void * p2;
-p = lock_user_string(arg1);
-p2 = lock_user_string(arg2);
-if (!p || !p2)
-ret = -TARGET_EFAULT;
-else
-ret = get_errno(link(p, p2));
-unlock_user(p2, arg2, 0);
-unlock_user(p, arg1, 0);
-}
-return ret;
-#endif
-#if defined(TARGET_NR_linkat)
-case TARGET_NR_linkat:
-{
-void * p2 = NULL;
-if (!arg2 || !arg4)
-return -TARGET_EFAULT;
-p  = lock_user_string(arg2);
-p2 = lock_user_string(arg4);
-if (!p || !p2)
-ret = -TARGET_EFAULT;
-else
-ret = get_errno(linkat(arg1, p, arg3, p2, arg5));
-unlock_user(p, arg2, 0);
-unlock_user(p2, arg4, 0);
-}
-return ret;
-#endif
 #ifdef TARGET_NR_unlink
 case TARGET_NR_unlink:
 if (!(p = lock_user_string(arg1)))
diff --git a/linux-user/strace.list b/linux-user/strace.list
index be0392810c..c369915759 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -461,12 +461,6 @@
 #ifdef TARGET_NR_lgetxattr
 { TARGET_NR_lgetxattr, "lgetxattr" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_link
-{ TARGET_NR_link, "link" , NULL, print_link, NULL },
-#endif
-#ifdef TARGET_NR_linkat
-{ TARGET_NR_linkat, "linkat" , NULL, print_linkat, NULL },
-#endif
 #ifdef TARGET_NR_Linux
 { TARGET_NR_Linux, "Linux" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 03/49] linux-user: Split out open, open_at

2019-01-18 Thread Richard Henderson
For the moment, leave a forward declaration for is_proc_myself
until the readlink syscalls are also moved to syscall-file.inc.c.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |   5 +
 linux-user/strace.c   |  35 
 linux-user/syscall-file.inc.c | 319 ++
 linux-user/syscall.c  | 282 +-
 linux-user/strace.list|   6 -
 5 files changed, 326 insertions(+), 321 deletions(-)
 create mode 100644 linux-user/syscall-file.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 8c0490425a..1f3a9c47ab 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -15,3 +15,8 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see .
  */
+
+#ifdef TARGET_NR_open
+SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+#endif
+SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 8c467da48e..1e4f6c9b53 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -2216,41 +2216,6 @@ print_mq_open(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_open
-static void
-print_open(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-int is_creat = (arg1 & TARGET_O_CREAT);
-
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_open_flags(arg1, (is_creat == 0));
-if (is_creat)
-print_file_mode(arg2, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_openat
-static void
-print_openat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-int is_creat = (arg2 & TARGET_O_CREAT);
-
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_open_flags(arg2, (is_creat == 0));
-if (is_creat)
-print_file_mode(arg3, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_mq_unlink
 static void
 print_mq_unlink(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
new file mode 100644
index 00..ca777da753
--- /dev/null
+++ b/linux-user/syscall-file.inc.c
@@ -0,0 +1,319 @@
+/*
+ *  Linux file-related syscall implementations
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see .
+ */
+
+/*
+ * Helpers for do_openat, manipulating /proc/self/foo.
+ */
+
+static int open_self_cmdline(void *cpu_env, int fd)
+{
+CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env);
+struct linux_binprm *bprm = ((TaskState *)cpu->opaque)->bprm;
+int i;
+
+for (i = 0; i < bprm->argc; i++) {
+size_t len = strlen(bprm->argv[i]) + 1;
+
+if (write(fd, bprm->argv[i], len) != len) {
+return -1;
+}
+}
+
+return 0;
+}
+
+static int open_self_maps(void *cpu_env, int fd)
+{
+CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env);
+TaskState *ts = cpu->opaque;
+FILE *fp;
+char *line = NULL;
+size_t len = 0;
+ssize_t read;
+
+fp = fopen("/proc/self/maps", "r");
+if (fp == NULL) {
+return -1;
+}
+
+while ((read = getline(, , fp)) != -1) {
+int fields, dev_maj, dev_min, inode;
+uint64_t min, max, offset;
+char flag_r, flag_w, flag_x, flag_p;
+char path[512] = "";
+fields = sscanf(line, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %x:%x %d"
+" %512s", , , _r, _w, _x,
+_p, , _maj, _min, , path);
+
+if ((fields < 10) || (fields > 11)) {
+continue;
+}
+if (h2g_valid(min)) {
+int flags = page_get_flags(h2g(min));
+max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX) + 
1;
+if (page_check_range(h2g(min), max - min, flags) == -1) {
+continue;
+}
+if (h2g(min) == ts->info->stack_limit) {
+pstrcpy(path, sizeof(path), "  [stack]");
+}
+dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr
+" %c%c%c%c 

[Qemu-devel] [PATCH v6 15/49] linux-user: Split out memory syscalls

2019-01-18 Thread Richard Henderson
This includes mmap, mmap2, munmap, mlock, mlockall, munlock,
munlockall, mprotect, mremap, msync.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h|  24 ++
 linux-user/syscall.h |   2 +
 linux-user/strace.c  |  55 ++---
 linux-user/syscall-mem.inc.c | 154 +++
 linux-user/syscall.c | 119 +--
 linux-user/strace.list   |  33 
 6 files changed, 189 insertions(+), 198 deletions(-)
 create mode 100644 linux-user/syscall-mem.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 6d6349da01..88f433e998 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -20,6 +20,26 @@ SYSCALL_DEF(close, ARG_DEC);
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
+SYSCALL_DEF(mlock, ARG_PTR, ARG_DEC);
+SYSCALL_DEF(mlockall, ARG_HEX);
+#ifdef TARGET_NR_mmap
+SYSCALL_DEF_FULL(mmap, .impl = impl_mmap,
+ .args = args_mmap,
+ .print_ret = print_syscall_ptr_ret,
+ .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT,
+   ARG_MMAPFLAG, ARG_DEC, ARG_DEC });
+#endif
+#ifdef TARGET_NR_mmap2
+SYSCALL_DEF_FULL(mmap2, .impl = impl_mmap,
+ .args = args_mmap2,
+ .print_ret = print_syscall_ptr_ret,
+ .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT,
+   ARG_MMAPFLAG, ARG_DEC, ARG_DEC64 });
+#endif
+SYSCALL_DEF(mprotect, ARG_PTR, ARG_DEC, ARG_MMAPPROT);
+SYSCALL_DEF_FULL(mremap, .impl = impl_mremap,
+ .print_ret = print_syscall_ptr_ret,
+ .arg_type = { ARG_PTR, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR });
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgctl)
 SYSCALL_DEF(msgctl, ARG_DEC, ARG_DEC, ARG_PTR);
 #endif
@@ -32,6 +52,10 @@ SYSCALL_DEF(msgrcv, ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC, 
ARG_HEX);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgsnd)
 SYSCALL_DEF(msgsnd, ARG_DEC, ARG_PTR, ARG_DEC, ARG_HEX);
 #endif
+SYSCALL_DEF(msync, ARG_PTR, ARG_DEC, ARG_HEX);
+SYSCALL_DEF(munlock, ARG_PTR, ARG_DEC);
+SYSCALL_DEF(munlockall);
+SYSCALL_DEF(munmap, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(name_to_handle_at,
 ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
 #ifdef TARGET_NR_open
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index 83f602f8e7..8175de4c31 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -58,6 +58,8 @@ typedef enum {
 /* These print as sets of flags.  */
 ARG_ATDIRFD,
 ARG_ATFLAG,
+ARG_MMAPFLAG,
+ARG_MMAPPROT,
 ARG_MODEFLAG,
 ARG_OPENFLAG,
 
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 3233230527..5619defec8 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -801,7 +801,7 @@ UNUSED static struct flags umount2_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags mmap_prot_flags[] = {
+static struct flags const mmap_prot_flags[] = {
 FLAG_GENERIC(PROT_NONE),
 FLAG_GENERIC(PROT_EXEC),
 FLAG_GENERIC(PROT_READ),
@@ -812,7 +812,7 @@ UNUSED static struct flags mmap_prot_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags mmap_flags[] = {
+static struct flags const mmap_flags[] = {
 FLAG_TARGET(MAP_SHARED),
 FLAG_TARGET(MAP_PRIVATE),
 FLAG_TARGET(MAP_ANONYMOUS),
@@ -2350,51 +2350,6 @@ print_utimensat(const struct syscallname *name,
 }
 #endif
 
-#if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
-static void
-print_mmap(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_pointer(arg0, 0);
-print_raw_param("%d", arg1, 0);
-print_flags(mmap_prot_flags, arg2, 0);
-print_flags(mmap_flags, arg3, 0);
-print_raw_param("%d", arg4, 0);
-print_raw_param("%#x", arg5, 1);
-print_syscall_epilogue(name);
-}
-#define print_mmap2 print_mmap
-#endif
-
-#ifdef TARGET_NR_mprotect
-static void
-print_mprotect(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_pointer(arg0, 0);
-print_raw_param("%d", arg1, 0);
-print_flags(mmap_prot_flags, arg2, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_munmap
-static void
-print_munmap(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_pointer(arg0, 0);
-print_raw_param("%d", arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_futex
 static void print_futex_op(abi_long tflag, int last)
 {
@@ -2601,6 +2556,12 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_ATFLAG:
 len = 

[Qemu-devel] [PATCH v6 36/49] linux-user: Split out utime, utimes, futimesat

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  9 
 linux-user/strace.c   | 41 ---
 linux-user/syscall-file.inc.c | 95 +++
 linux-user/syscall.c  | 63 ---
 linux-user/strace.list|  9 
 5 files changed, 104 insertions(+), 113 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 9d0dd7457b..2767e335d8 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -36,6 +36,9 @@ SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
 SYSCALL_DEF(fchmod, ARG_DEC, ARG_MODEFLAG);
 SYSCALL_DEF(fchmodat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG);
+#ifdef TARGET_NR_futimesat
+SYSCALL_DEF(futimesat, ARG_ATDIRFD, ARG_STR, ARG_PTR);
+#endif
 #ifdef TARGET_NR_fork
 SYSCALL_DEF(fork);
 #endif
@@ -172,6 +175,12 @@ SYSCALL_DEF(umount2, ARG_STR, ARG_UMOUNTFLAG);
 SYSCALL_DEF(unlink, ARG_STR);
 #endif
 SYSCALL_DEF(unlinkat, ARG_ATDIRFD, ARG_STR, ARG_UNLINKATFLAG);
+#ifdef TARGET_NR_utime
+SYSCALL_DEF(utime, ARG_STR, ARG_PTR);
+#endif
+#ifdef TARGET_NR_utimes
+SYSCALL_DEF(utimes, ARG_STR, ARG_PTR);
+#endif
 #ifdef TARGET_NR_vfork
 /* Emulate vfork() with fork().  */
 SYSCALL_DEF_FULL(vfork, .impl = impl_fork);
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 78781b8817..b54949df27 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1284,21 +1284,6 @@ print_fcntl(const struct syscallname *name,
 #endif
 
 
-#ifdef TARGET_NR_futimesat
-static void
-print_futimesat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_timeval(arg2, 0);
-print_timeval(arg2 + sizeof (struct target_timeval), 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #if defined(TARGET_NR_socket)
 static void
 print_socket(const struct syscallname *name,
@@ -2003,32 +1988,6 @@ print_symlinkat(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_utime
-static void
-print_utime(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_pointer(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_utimes
-static void
-print_utimes(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_pointer(arg1, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_utimensat
 static void
 print_utimensat(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 7ec1c26347..6a7ef80bfc 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -84,6 +84,38 @@ SYSCALL_IMPL(fchmodat)
 return do_fchmodat(arg1, arg2, arg3);
 }
 
+#ifdef TARGET_NR_futimesat
+SYSCALL_IMPL(futimesat)
+{
+int dirfd = arg1;
+abi_ulong target_path = arg2;
+abi_ulong target_tv = arg3;
+struct timeval *tvp, tv[2];
+char *p;
+abi_long ret;
+
+if (target_tv) {
+if (copy_from_user_timeval([0], target_tv)
+|| copy_from_user_timeval([1],
+  target_tv +
+  sizeof(struct target_timeval))) {
+return -TARGET_EFAULT;
+}
+tvp = tv;
+} else {
+tvp = NULL;
+}
+
+p = lock_user_string(target_path);
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(futimesat(dirfd, path(p), tvp));
+unlock_user(p, target_path, 0);
+return ret;
+}
+#endif
+
 static abi_long do_linkat(int olddirfd, abi_ulong target_oldpath,
   int newdirfd, abi_ulong target_newpath,
   int flags)
@@ -867,6 +899,69 @@ SYSCALL_IMPL(unlinkat)
 return do_unlinkat(arg1, arg2, arg3);
 }
 
+#ifdef TARGET_NR_utime
+SYSCALL_IMPL(utime)
+{
+abi_ulong target_path = arg1;
+abi_ulong target_times = arg2;
+struct utimbuf tbuf, *host_tbuf;
+struct target_utimbuf *target_tbuf;
+char *p;
+abi_long ret;
+
+if (target_times) {
+if (!lock_user_struct(VERIFY_READ, target_tbuf, target_times, 1)) {
+return -TARGET_EFAULT;
+}
+tbuf.actime = tswapal(target_tbuf->actime);
+tbuf.modtime = tswapal(target_tbuf->modtime);
+unlock_user_struct(target_tbuf, arg2, 0);
+host_tbuf = 
+} else {
+host_tbuf = NULL;
+}
+
+p = lock_user_string(target_path);
+if (!p) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(utime(p, host_tbuf));
+unlock_user(p, 

[Qemu-devel] [PATCH v6 01/49] linux-user: Setup split syscall infrastructure

2019-01-18 Thread Richard Henderson
Defines a unified structure for implementation and strace.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  17 ++
 linux-user/syscall.h  |  89 +
 linux-user/strace.c   | 388 +++---
 linux-user/syscall.c  | 103 +-
 4 files changed, 484 insertions(+), 113 deletions(-)
 create mode 100644 linux-user/syscall-defs.h
 create mode 100644 linux-user/syscall.h

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
new file mode 100644
index 00..8c0490425a
--- /dev/null
+++ b/linux-user/syscall-defs.h
@@ -0,0 +1,17 @@
+/*
+ *  Linux syscall definitions
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see .
+ */
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
new file mode 100644
index 00..43b5dc0684
--- /dev/null
+++ b/linux-user/syscall.h
@@ -0,0 +1,89 @@
+/*
+ *  Linux syscalls internals
+ *  Copyright (c) 2018 Linaro, Limited.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see .
+ */
+
+#ifndef LINUX_USER_SYSCALL_H
+#define LINUX_USER_SYSCALL_H 1
+
+typedef struct SyscallDef SyscallDef;
+
+/*
+ * This hook extracts max 6 arguments from max 8 input registers.
+ * In the process, register pairs that store 64-bit arguments are merged.
+ * Finally, syscalls are demultipliexed; e.g. the hook for socketcall will
+ * return the SyscallDef for bind, listen, etc.  In the process the hook
+ * may need to read from guest memory, or otherwise validate operands.
+ * On failure, set errno (to a host value) and return NULL;
+ * the (target adjusted) errno will be returned to the guest.
+ */
+typedef const SyscallDef *SyscallArgsFn(const SyscallDef *, int64_t out[6],
+abi_long in[8]);
+
+/* This hook implements the syscall.  */
+typedef abi_long SyscallImplFn(CPUArchState *, int64_t, int64_t, int64_t,
+   int64_t, int64_t, int64_t);
+
+/* This hook prints the arguments to the syscall for strace.  */
+typedef void SyscallPrintFn(const SyscallDef *, int64_t arg[6]);
+
+/* This hook print the return value from the syscall for strace.  */
+typedef void SyscallPrintRetFn(const SyscallDef *, abi_long);
+
+/*
+ * These flags describe the arguments for the generic fallback to
+ * SyscallPrintFn.  ARG_NONE indicates that the argument is not present.
+ */
+typedef enum {
+ARG_NONE = 0,
+
+/* These print as numbers of abi_long.  */
+ARG_DEC,
+ARG_HEX,
+ARG_OCT,
+
+/* These print as sets of flags.  */
+ARG_ATDIRFD,
+ARG_MODEFLAG,
+ARG_OPENFLAG,
+
+/* These are interpreted as pointers.  */
+ARG_PTR,
+ARG_STR,
+ARG_BUF,
+
+/* For a 32-bit host, force printing as a 64-bit operand.  */
+#if TARGET_ABI_BITS == 32
+ARG_DEC64,
+#else
+ARG_DEC64 = ARG_DEC,
+#endif
+} SyscallArgType;
+
+struct SyscallDef {
+const char *name;
+SyscallArgsFn *args;
+SyscallImplFn *impl;
+SyscallPrintFn *print;
+SyscallPrintRetFn *print_ret;
+SyscallArgType arg_type[6];
+};
+
+void print_syscall_def(const SyscallDef *def, int64_t args[6]);
+void print_syscall_def_ret(const SyscallDef *def, abi_long ret);
+void print_syscall_ptr_ret(const SyscallDef *def, abi_long ret);
+
+#endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 7318392e57..8c467da48e 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include "qemu.h"
+#include "syscall.h"
 
 int do_strace=0;
 
@@ -796,7 +797,7 @@ UNUSED static struct flags unlinkat_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags mode_flags[] = {
+static struct flags const mode_flags[] = {
 FLAG_GENERIC(S_IFSOCK),
 FLAG_GENERIC(S_IFLNK),

[Qemu-devel] [PATCH v6 18/49] linux-user: Split out clone, fork, vfork

2019-01-18 Thread Richard Henderson
Rename do_fork to do_clone, since that is what it does.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |   8 ++
 linux-user/syscall.h  |   1 +
 linux-user/strace.c   |  36 +
 linux-user/syscall-proc.inc.c | 259 ++
 linux-user/syscall.c  | 218 
 linux-user/strace.list|   9 --
 6 files changed, 272 insertions(+), 259 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index c3ed22ff16..6f6f77927b 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -19,8 +19,12 @@
 SYSCALL_DEF_FULL(brk, .impl = impl_brk,
  .print_ret = print_syscall_ptr_ret,
  .arg_type = { ARG_PTR });
+SYSCALL_DEF_ARGS(clone, ARG_CLONEFLAG, ARG_PTR, ARG_PTR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(close, ARG_DEC);
 SYSCALL_DEF(exit, ARG_DEC);
+#ifdef TARGET_NR_fork
+SYSCALL_DEF(fork);
+#endif
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
@@ -110,5 +114,9 @@ SYSCALL_DEF(shmdt, ARG_PTR);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmget)
 SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 #endif
+#ifdef TARGET_NR_vfork
+/* Emulate vfork() with fork().  */
+SYSCALL_DEF_FULL(vfork, .impl = impl_fork);
+#endif
 SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index 8175de4c31..f75cd3ddd0 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -58,6 +58,7 @@ typedef enum {
 /* These print as sets of flags.  */
 ARG_ATDIRFD,
 ARG_ATFLAG,
+ARG_CLONEFLAG,
 ARG_MMAPFLAG,
 ARG_MMAPPROT,
 ARG_MODEFLAG,
diff --git a/linux-user/strace.c b/linux-user/strace.c
index ba541432eb..d7847e7cd6 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -813,7 +813,7 @@ static struct flags const mmap_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags clone_flags[] = {
+static struct flags const clone_flags[] = {
 FLAG_GENERIC(CLONE_VM),
 FLAG_GENERIC(CLONE_FS),
 FLAG_GENERIC(CLONE_FILES),
@@ -1183,37 +1183,6 @@ print_clock_adjtime(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_clone
-static void do_print_clone(unsigned int flags, abi_ulong newsp,
-   abi_ulong parent_tidptr, target_ulong newtls,
-   abi_ulong child_tidptr)
-{
-print_flags(clone_flags, flags, 0);
-print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
-print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
-print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
-print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
-}
-
-static void
-print_clone(const struct syscallname *name,
-abi_long arg1, abi_long arg2, abi_long arg3,
-abi_long arg4, abi_long arg5, abi_long arg6)
-{
-print_syscall_prologue(name);
-#if defined(TARGET_MICROBLAZE)
-do_print_clone(arg1, arg2, arg4, arg6, arg5);
-#elif defined(TARGET_CLONE_BACKWARDS)
-do_print_clone(arg1, arg2, arg3, arg4, arg5);
-#elif defined(TARGET_CLONE_BACKWARDS2)
-do_print_clone(arg2, arg1, arg3, arg5, arg4);
-#else
-do_print_clone(arg1, arg2, arg3, arg5, arg4);
-#endif
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_creat
 static void
 print_creat(const struct syscallname *name,
@@ -2521,6 +2490,9 @@ static void print_syscall_def1(const SyscallDef *def, 
int64_t args[6])
 case ARG_ATFLAG:
 len = add_flags(b, rest, at_file_flags, arg, false);
 break;
+case ARG_CLONEFLAG:
+len = add_flags(b, rest, clone_flags, arg, false);
+break;
 case ARG_MMAPFLAG:
 len = add_flags(b, rest, mmap_flags, arg, false);
 break;
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index 96ad363c1a..b89ac56552 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -16,6 +16,258 @@
  *  along with this program; if not, see .
  */
 
+#ifndef CLONE_IO
+#define CLONE_IO0x8000  /* Clone io context */
+#endif
+
+/*
+ * We can't directly call the host clone syscall, because this will
+ * badly confuse libc (breaking mutexes, for example). So we must
+ * divide clone flags into:
+ *  * flag combinations that look like pthread_create()
+ *  * flag combinations that look like fork()
+ *  * flags we can implement within QEMU itself
+ *  * flags we can't support and will return an error for
+ *
+ * For thread creation, all these flags must be present; for
+ * fork, none must be present.
+ */
+#define CLONE_THREAD_FLAGS  \
+(CLONE_VM | CLONE_FS | CLONE_FILES |\
+ CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM)
+
+/*
+ * These flags are ignored:
+ * 

[Qemu-devel] [PATCH v6 27/49] linux-user: Split out time

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  3 +++
 linux-user/syscall-time.inc.c | 32 
 linux-user/syscall.c  | 13 +
 linux-user/strace.list|  3 ---
 4 files changed, 36 insertions(+), 15 deletions(-)
 create mode 100644 linux-user/syscall-time.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 3fad9d51f0..9950b73e76 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -127,6 +127,9 @@ SYSCALL_DEF(shmdt, ARG_PTR);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmget)
 SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 #endif
+#ifdef TARGET_NR_time
+SYSCALL_DEF(time, ARG_PTR);
+#endif
 #ifdef TARGET_NR_unlink
 SYSCALL_DEF(unlink, ARG_STR);
 #endif
diff --git a/linux-user/syscall-time.inc.c b/linux-user/syscall-time.inc.c
new file mode 100644
index 00..14fec88e47
--- /dev/null
+++ b/linux-user/syscall-time.inc.c
@@ -0,0 +1,32 @@
+/*
+ *  Linux time related syscalls
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see .
+ */
+
+#ifdef TARGET_NR_time
+SYSCALL_IMPL(time)
+{
+time_t host_time;
+abi_long ret = get_errno(time(_time));
+
+if (!is_error(ret)
+&& arg1
+&& put_user_sal(host_time, arg1)) {
+return -TARGET_EFAULT;
+}
+return ret;
+}
+#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1cdc9727a9..cc5360ae43 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5331,18 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-#ifdef TARGET_NR_time
-case TARGET_NR_time:
-{
-time_t host_time;
-ret = get_errno(time(_time));
-if (!is_error(ret)
-&& arg1
-&& put_user_sal(host_time, arg1))
-return -TARGET_EFAULT;
-}
-return ret;
-#endif
 #ifdef TARGET_NR_mknod
 case TARGET_NR_mknod:
 if (!(p = lock_user_string(arg1)))
@@ -9303,6 +9291,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #include "syscall-ipc.inc.c"
 #include "syscall-mem.inc.c"
 #include "syscall-proc.inc.c"
+#include "syscall-time.inc.c"
 
 #undef SYSCALL_IMPL
 #undef SYSCALL_ARGS
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 357984dd6f..3505014501 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1350,9 +1350,6 @@
 #ifdef TARGET_NR_tgkill
 { TARGET_NR_tgkill, "tgkill" , NULL, print_tgkill, NULL },
 #endif
-#ifdef TARGET_NR_time
-{ TARGET_NR_time, "time" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_timer_create
 { TARGET_NR_timer_create, "timer_create" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 16/49] linux-user: Split out exit

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  1 +
 linux-user/syscall-proc.inc.c | 61 +++
 linux-user/syscall.c  | 38 +-
 3 files changed, 63 insertions(+), 37 deletions(-)
 create mode 100644 linux-user/syscall-proc.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 88f433e998..88aa1a6bfd 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -17,6 +17,7 @@
  */
 
 SYSCALL_DEF(close, ARG_DEC);
+SYSCALL_DEF(exit, ARG_DEC);
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
new file mode 100644
index 00..96ad363c1a
--- /dev/null
+++ b/linux-user/syscall-proc.inc.c
@@ -0,0 +1,61 @@
+/*
+ *  Linux process related syscalls
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see .
+ */
+
+
+SYSCALL_IMPL(exit)
+{
+CPUState *cpu = ENV_GET_CPU(cpu_env);
+int status = arg1;
+
+/*
+ * In old applications this may be used to implement _exit(2).
+ * However in threaded applictions it is used for thread termination,
+ * and _exit_group is used for application termination.
+ * Do thread termination if we have more then one thread.
+ */
+if (block_signals()) {
+return -TARGET_ERESTARTSYS;
+}
+
+cpu_list_lock();
+
+if (CPU_NEXT(first_cpu)) {
+TaskState *ts;
+
+/* Remove the CPU from the list.  */
+QTAILQ_REMOVE_RCU(, cpu, node);
+
+cpu_list_unlock();
+
+ts = cpu->opaque;
+if (ts->child_tidptr) {
+put_user_u32(0, ts->child_tidptr);
+sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
+  NULL, NULL, 0);
+}
+thread_cpu = NULL;
+object_unref(OBJECT(cpu));
+g_free(ts);
+rcu_unregister_thread();
+pthread_exit(NULL);
+}
+
+cpu_list_unlock();
+preexit_cleanup(cpu_env, status);
+_exit(status);
+}
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 142654a0a0..02010f9ae0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5626,43 +5626,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 void *p;
 
 switch(num) {
-case TARGET_NR_exit:
-/* In old applications this may be used to implement _exit(2).
-   However in threaded applictions it is used for thread termination,
-   and _exit_group is used for application termination.
-   Do thread termination if we have more then one thread.  */
-
-if (block_signals()) {
-return -TARGET_ERESTARTSYS;
-}
-
-cpu_list_lock();
-
-if (CPU_NEXT(first_cpu)) {
-TaskState *ts;
-
-/* Remove the CPU from the list.  */
-QTAILQ_REMOVE_RCU(, cpu, node);
-
-cpu_list_unlock();
-
-ts = cpu->opaque;
-if (ts->child_tidptr) {
-put_user_u32(0, ts->child_tidptr);
-sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
-  NULL, NULL, 0);
-}
-thread_cpu = NULL;
-object_unref(OBJECT(cpu));
-g_free(ts);
-rcu_unregister_thread();
-pthread_exit(NULL);
-}
-
-cpu_list_unlock();
-preexit_cleanup(cpu_env, arg1);
-_exit(arg1);
-return 0; /* avoid warning */
 case TARGET_NR_brk:
 return do_brk(arg1);
 #ifdef TARGET_NR_fork
@@ -9884,6 +9847,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #include "syscall-file.inc.c"
 #include "syscall-ipc.inc.c"
 #include "syscall-mem.inc.c"
+#include "syscall-proc.inc.c"
 
 #undef SYSCALL_IMPL
 #undef SYSCALL_ARGS
-- 
2.17.2




[Qemu-devel] [PATCH v6 08/49] linux-user: Split out read, write

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  2 ++
 linux-user/syscall-file.inc.c | 58 +++
 linux-user/syscall.c  | 34 
 linux-user/strace.list|  6 
 4 files changed, 60 insertions(+), 40 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 797426ae6f..b031de1375 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -21,9 +21,11 @@ SYSCALL_DEF(close, ARG_DEC);
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+SYSCALL_DEF(read, ARG_DEC, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_readlink
 SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
 #ifdef TARGET_NR_readlinkat
 SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
+SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index feb83c4e87..9c8025b252 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -317,6 +317,32 @@ SYSCALL_IMPL(openat)
 return do_openat(cpu_env, arg1, arg2, arg3, arg4);
 }
 
+SYSCALL_IMPL(read)
+{
+int fd = arg1;
+abi_ulong target_p = arg2;
+abi_ulong size = arg3;
+void *p;
+abi_long ret;
+
+if (size == 0) {
+return 0;
+}
+p = lock_user(VERIFY_WRITE, target_p, size, 0);
+if (p == NULL) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(safe_read(fd, p, size));
+if (!is_error(ret)) {
+TargetFdDataFunc trans = fd_trans_host_to_target_data(fd);
+if (trans) {
+ret = trans(p, ret);
+}
+}
+unlock_user(p, target_p, ret);
+return ret;
+}
+
 static abi_long do_readlinkat(int dirfd, abi_ulong target_path,
   abi_ulong target_buf, abi_ulong bufsiz)
 {
@@ -361,3 +387,35 @@ SYSCALL_IMPL(readlinkat)
 return do_readlinkat(arg1, arg2, arg3, arg4);
 }
 #endif
+
+SYSCALL_IMPL(write)
+{
+int fd = arg1;
+abi_ulong target_p = arg2;
+abi_ulong size = arg3;
+TargetFdDataFunc trans;
+abi_long ret;
+void *p;
+
+if (target_p == 0 && size == 0) {
+return get_errno(safe_write(fd, 0, 0));
+}
+p = lock_user(VERIFY_READ, target_p, size, 1);
+if (p == NULL) {
+return -TARGET_EFAULT;
+}
+trans = fd_trans_target_to_host_data(fd);
+if (trans) {
+void *copy = g_malloc(size);
+memcpy(copy, p, size);
+ret = trans(copy, size);
+if (ret >= 0) {
+ret = get_errno(safe_write(fd, copy, ret));
+}
+g_free(copy);
+} else {
+ret = get_errno(safe_write(fd, p, size));
+}
+unlock_user(p, target_p, 0);
+return ret;
+}
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f230fe161e..d4d5c25803 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6726,40 +6726,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 preexit_cleanup(cpu_env, arg1);
 _exit(arg1);
 return 0; /* avoid warning */
-case TARGET_NR_read:
-if (arg3 == 0) {
-return 0;
-} else {
-if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
-return -TARGET_EFAULT;
-ret = get_errno(safe_read(arg1, p, arg3));
-if (ret >= 0 &&
-fd_trans_host_to_target_data(arg1)) {
-ret = fd_trans_host_to_target_data(arg1)(p, ret);
-}
-unlock_user(p, arg2, ret);
-}
-return ret;
-case TARGET_NR_write:
-if (arg2 == 0 && arg3 == 0) {
-return get_errno(safe_write(arg1, 0, 0));
-}
-if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
-return -TARGET_EFAULT;
-if (fd_trans_target_to_host_data(arg1)) {
-void *copy = g_malloc(arg3);
-memcpy(copy, p, arg3);
-ret = fd_trans_target_to_host_data(arg1)(copy, arg3);
-if (ret >= 0) {
-ret = get_errno(safe_write(arg1, copy, ret));
-}
-g_free(copy);
-} else {
-ret = get_errno(safe_write(arg1, p, arg3));
-}
-unlock_user(p, arg2, 0);
-return ret;
-
 #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
 case TARGET_NR_name_to_handle_at:
 ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5);
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 71a18123bf..f3a1b0fe31 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1067,9 +1067,6 @@
 #ifdef TARGET_NR_quotactl
 { TARGET_NR_quotactl, "quotactl" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_read
-{ TARGET_NR_read, "read" , "%s(%d,%#x,%d)", NULL, NULL },
-#endif
 #ifdef TARGET_NR_readahead
 { TARGET_NR_readahead, "readahead" , NULL, NULL, NULL },
 #endif
@@ 

[Qemu-devel] [PATCH v6 14/49] linux-user: Split out ipc syscalls

2019-01-18 Thread Richard Henderson
Because of the ipc multiplex syscall, these must be done all at once.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h|   38 ++
 linux-user/strace.c  |   83 ---
 linux-user/syscall-ipc.inc.c | 1086 ++
 linux-user/syscall.c |  972 +-
 linux-user/strace.list   |   42 --
 5 files changed, 1127 insertions(+), 1094 deletions(-)
 create mode 100644 linux-user/syscall-ipc.inc.c

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 1fc89c1b08..6d6349da01 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -17,6 +17,21 @@
  */
 
 SYSCALL_DEF(close, ARG_DEC);
+#ifdef TARGET_NR_ipc
+SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgctl)
+SYSCALL_DEF(msgctl, ARG_DEC, ARG_DEC, ARG_PTR);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgget)
+SYSCALL_DEF(msgget, ARG_DEC, ARG_DEC);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgrcv)
+SYSCALL_DEF(msgrcv, ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgsnd)
+SYSCALL_DEF(msgsnd, ARG_DEC, ARG_PTR, ARG_DEC, ARG_HEX);
+#endif
 SYSCALL_DEF(name_to_handle_at,
 ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
 #ifdef TARGET_NR_open
@@ -44,5 +59,28 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
 SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC);
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semctl)
+SYSCALL_DEF(semctl, ARG_DEC, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semget)
+SYSCALL_DEF(semget, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semop)
+SYSCALL_DEF(semop, ARG_DEC, ARG_PTR, ARG_DEC);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmat)
+SYSCALL_DEF_FULL(shmat, .impl = impl_shmat,
+ .print_ret = print_syscall_ptr_ret,
+ .arg_type = { ARG_DEC, ARG_PTR, ARG_HEX });
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmctl)
+SYSCALL_DEF(shmctl, ARG_DEC, ARG_DEC, ARG_PTR);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmdt)
+SYSCALL_DEF(shmdt, ARG_PTR);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmget)
+SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
 SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
diff --git a/linux-user/strace.c b/linux-user/strace.c
index ed311b081b..3233230527 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1,8 +1,4 @@
 #include "qemu/osdep.h"
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -74,54 +70,6 @@ UNUSED static void print_socket_protocol(int domain, int 
type, int protocol);
 /*
  * Utility functions
  */
-static void
-print_ipc_cmd(int cmd)
-{
-#define output_cmd(val) \
-if( cmd == val ) { \
-gemu_log(#val); \
-return; \
-}
-
-cmd &= 0xff;
-
-/* General IPC commands */
-output_cmd( IPC_RMID );
-output_cmd( IPC_SET );
-output_cmd( IPC_STAT );
-output_cmd( IPC_INFO );
-/* msgctl() commands */
-output_cmd( MSG_STAT );
-output_cmd( MSG_INFO );
-/* shmctl() commands */
-output_cmd( SHM_LOCK );
-output_cmd( SHM_UNLOCK );
-output_cmd( SHM_STAT );
-output_cmd( SHM_INFO );
-/* semctl() commands */
-output_cmd( GETPID );
-output_cmd( GETVAL );
-output_cmd( GETALL );
-output_cmd( GETNCNT );
-output_cmd( GETZCNT );
-output_cmd( SETVAL );
-output_cmd( SETALL );
-output_cmd( SEM_STAT );
-output_cmd( SEM_INFO );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-output_cmd( IPC_RMID );
-
-/* Some value we don't recognize */
-gemu_log("%d",cmd);
-}
-
 static void
 print_signal(abi_ulong arg, int last)
 {
@@ -620,18 +568,6 @@ print_newselect(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_semctl
-static void
-print_semctl(const struct syscallname *name,
- abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6)
-{
-gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, 
arg1, arg2);
-print_ipc_cmd(arg3);
-gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
-}
-#endif
-
 static void
 print_execve(const struct syscallname *name,
  abi_long arg1, abi_long arg2, abi_long arg3,
@@ -664,25 +600,6 @@ print_execve(const struct syscallname *name,
 gemu_log("NULL})");
 }
 
-#ifdef TARGET_NR_ipc
-static void
-print_ipc(const struct syscallname *name,
-  abi_long arg1, abi_long arg2, abi_long 

[Qemu-devel] [PATCH v6 25/49] linux-user: Implement execveat

2019-01-18 Thread Richard Henderson
A trivial extension to our current execve implementation
to support the new(ish) syscall.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  1 +
 linux-user/syscall-proc.inc.c | 19 ++-
 linux-user/syscall.c  |  3 ++-
 linux-user/strace.list|  3 ---
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 58fef48666..392bd1579c 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -26,6 +26,7 @@ SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(exit, ARG_DEC);
 SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
+SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
 #ifdef TARGET_NR_fork
 SYSCALL_DEF(fork);
 #endif
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index 552aea60ae..699370c290 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -269,14 +269,13 @@ SYSCALL_IMPL(clone)
 return do_clone(cpu_env, arg1, arg2, arg3, arg4, arg5);
 }
 
-SYSCALL_IMPL(execve)
+static abi_long do_execveat(int dirfd, abi_ulong guest_path,
+abi_ulong guest_argp, abi_ulong guest_envp,
+int flags)
 {
 char **argp, **envp;
 int argc, envc;
 abi_ulong gp;
-abi_ulong guest_path = arg1;
-abi_ulong guest_argp = arg2;
-abi_ulong guest_envp = arg3;
 abi_ulong addr;
 char **q, *p;
 int total_size = 0;
@@ -356,7 +355,7 @@ SYSCALL_IMPL(execve)
  * before the execve completes and makes it the other
  * program's problem.
  */
-ret = get_errno(safe_execve(p, argp, envp));
+ret = get_errno(safe_execveat(dirfd, p, argp, envp, flags));
 unlock_user(p, guest_path, 0);
 
  execve_free:
@@ -379,6 +378,16 @@ SYSCALL_IMPL(execve)
 return ret;
 }
 
+SYSCALL_IMPL(execve)
+{
+return do_execveat(AT_FDCWD, arg1, arg2, arg3, 0);
+}
+
+SYSCALL_IMPL(execveat)
+{
+return do_execveat(arg1, arg2, arg3, arg4, arg5);
+}
+
 SYSCALL_IMPL(exit)
 {
 CPUState *cpu = ENV_GET_CPU(cpu_env);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9b5b2eb7f1..3a027651e3 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -682,7 +682,8 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, 
options, \
   struct rusage *, rusage)
 safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \
   int, options, struct rusage *, rusage)
-safe_syscall3(int, execve, const char *, filename, char **, argv, char **, 
envp)
+safe_syscall5(int, execveat, int, dirfd, const char *, filename,
+  char **, argv, char **, envp, int, flags)
 safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, 
\
   fd_set *, exceptfds, struct timespec *, timeout, void *, sig)
 safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 8bc3fe6088..202bfa8f9e 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -139,9 +139,6 @@
 #ifdef TARGET_NR_execv
 { TARGET_NR_execv, "execv" , NULL, print_execv, NULL },
 #endif
-#ifdef TARGET_NR_execveat
-{ TARGET_NR_execveat, "execveat" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_exec_with_loader
 { TARGET_NR_exec_with_loader, "exec_with_loader" , NULL, NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 10/49] linux-user: Split out readv, writev

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  2 ++
 linux-user/syscall-file.inc.c | 34 ++
 linux-user/syscall.c  | 22 --
 linux-user/strace.list|  6 --
 4 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index b031de1375..130ba7e344 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -28,4 +28,6 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_readlinkat
 SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
+SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
+SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 9c8025b252..9bd21ac5cd 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -343,6 +343,23 @@ SYSCALL_IMPL(read)
 return ret;
 }
 
+SYSCALL_IMPL(readv)
+{
+int fd = arg1;
+abi_ulong target_vec = arg2;
+int count = arg3;
+struct iovec *vec = lock_iovec(VERIFY_WRITE, target_vec, count, 0);
+abi_long ret;
+
+if (vec != NULL) {
+ret = get_errno(safe_readv(fd, vec, count));
+unlock_iovec(vec, target_vec, count, 1);
+} else {
+ret = -host_to_target_errno(errno);
+}
+return ret;
+}
+
 static abi_long do_readlinkat(int dirfd, abi_ulong target_path,
   abi_ulong target_buf, abi_ulong bufsiz)
 {
@@ -419,3 +436,20 @@ SYSCALL_IMPL(write)
 unlock_user(p, target_p, 0);
 return ret;
 }
+
+SYSCALL_IMPL(writev)
+{
+int fd = arg1;
+abi_ulong target_vec = arg2;
+int count = arg3;
+struct iovec *vec = lock_iovec(VERIFY_READ, target_vec, count, 1);
+abi_long ret;
+
+if (vec != NULL) {
+ret = get_errno(safe_writev(fd, vec, count));
+unlock_iovec(vec, target_vec, count, 0);
+} else {
+ret = -host_to_target_errno(errno);
+}
+return ret;
+}
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c236a80437..df47ee106e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8949,28 +8949,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 /* NOTE: the flock constant seems to be the same for every
Linux platform */
 return get_errno(safe_flock(arg1, arg2));
-case TARGET_NR_readv:
-{
-struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
-if (vec != NULL) {
-ret = get_errno(safe_readv(arg1, vec, arg3));
-unlock_iovec(vec, arg2, arg3, 1);
-} else {
-ret = -host_to_target_errno(errno);
-}
-}
-return ret;
-case TARGET_NR_writev:
-{
-struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
-if (vec != NULL) {
-ret = get_errno(safe_writev(arg1, vec, arg3));
-unlock_iovec(vec, arg2, arg3, 0);
-} else {
-ret = -host_to_target_errno(errno);
-}
-}
-return ret;
 #if defined(TARGET_NR_preadv)
 case TARGET_NR_preadv:
 {
diff --git a/linux-user/strace.list b/linux-user/strace.list
index f3a1b0fe31..e02a854cea 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1073,9 +1073,6 @@
 #ifdef TARGET_NR_readdir
 { TARGET_NR_readdir, "readdir" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_readv
-{ TARGET_NR_readv, "readv" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_reboot
 { TARGET_NR_reboot, "reboot" , NULL, NULL, NULL },
 #endif
@@ -1608,9 +1605,6 @@
 #ifdef TARGET_NR_waitpid
 { TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL },
 #endif
-#ifdef TARGET_NR_writev
-{ TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL },
-#endif
 #ifdef TARGET_NR_utimensat
 { TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 06/49] linux-user: Split out readlink, readlinkat

2019-01-18 Thread Richard Henderson
Split out a shared implementation for both of these;
unify the best parts of /proc/self/exe checking.

Remove the temporary forward declaration for is_proc_self.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  6 
 linux-user/strace.c   | 29 --
 linux-user/syscall-file.inc.c | 45 
 linux-user/syscall.c  | 55 ---
 linux-user/strace.list|  6 
 5 files changed, 51 insertions(+), 90 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 1f3a9c47ab..d1a6c6fa3c 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -20,3 +20,9 @@
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+#ifdef TARGET_NR_readlink
+SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
+#endif
+#ifdef TARGET_NR_readlinkat
+SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
+#endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 1e4f6c9b53..4faeb8c031 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -2244,35 +2244,6 @@ print_fstatat64(const struct syscallname *name,
 #define print_newfstatatprint_fstatat64
 #endif
 
-#ifdef TARGET_NR_readlink
-static void
-print_readlink(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_string(arg0, 0);
-print_pointer(arg1, 0);
-print_raw_param("%u", arg2, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_readlinkat
-static void
-print_readlinkat(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_at_dirfd(arg0, 0);
-print_string(arg1, 0);
-print_pointer(arg2, 0);
-print_raw_param("%u", arg3, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_rename
 static void
 print_rename(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index f202a4c8f4..841795f8aa 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -308,3 +308,48 @@ SYSCALL_IMPL(openat)
 {
 return do_openat(cpu_env, arg1, arg2, arg3, arg4);
 }
+
+static abi_long do_readlinkat(int dirfd, abi_ulong target_path,
+  abi_ulong target_buf, abi_ulong bufsiz)
+{
+char *p = lock_user_string(target_path);
+void *buf = lock_user(VERIFY_WRITE, target_buf, bufsiz, 0);
+abi_long ret;
+
+if (!p || !buf) {
+ret = -TARGET_EFAULT;
+} else if (!bufsiz) {
+/* Short circuit this for the magic exe check. */
+ret = -TARGET_EINVAL;
+} else if (is_proc_myself((const char *)p, "exe")) {
+char real[PATH_MAX];
+char *temp = realpath(exec_path, real);
+
+if (temp == NULL) {
+ret = -host_to_target_errno(errno);
+} else {
+ret = MIN(strlen(real), bufsiz);
+/* We cannot NUL terminate the string. */
+memcpy(buf, real, ret);
+}
+} else {
+ret = get_errno(readlinkat(dirfd, path(p), buf, bufsiz));
+}
+unlock_user(buf, target_buf, ret);
+unlock_user(p, target_path, 0);
+return ret;
+}
+
+#ifdef TARGET_NR_readlink
+SYSCALL_IMPL(readlink)
+{
+return do_readlinkat(AT_FDCWD, arg1, arg2, arg3);
+}
+#endif
+
+#ifdef TARGET_NR_readlinkat
+SYSCALL_IMPL(readlinkat)
+{
+return do_readlinkat(arg1, arg2, arg3, arg4);
+}
+#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 32d1a285eb..035f17c0d9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6577,8 +6577,6 @@ int host_to_target_waitstatus(int status)
 return status;
 }
 
-static int is_proc_myself(const char *filename, const char *entry);
-
 #define TIMER_MAGIC 0x0caf
 #define TIMER_MAGIC_MASK 0x
 
@@ -8052,59 +8050,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 }
 return ret;
 #endif
-#ifdef TARGET_NR_readlink
-case TARGET_NR_readlink:
-{
-void *p2;
-p = lock_user_string(arg1);
-p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
-if (!p || !p2) {
-ret = -TARGET_EFAULT;
-} else if (!arg3) {
-/* Short circuit this for the magic exe check. */
-ret = -TARGET_EINVAL;
-} else if (is_proc_myself((const char *)p, "exe")) {
-char real[PATH_MAX], *temp;
-temp = realpath(exec_path, real);
-/* Return value is # of bytes that we wrote to the buffer. */
-if (temp == NULL) {
-ret = get_errno(-1);
-} else {
-/* Don't worry 

[Qemu-devel] [PATCH v6 17/49] linux-user: Split out brk

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h|  3 ++
 linux-user/strace.c  | 35 --
 linux-user/syscall-mem.inc.c | 90 ++
 linux-user/syscall.c | 93 
 linux-user/strace.list   |  3 --
 5 files changed, 93 insertions(+), 131 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 88aa1a6bfd..c3ed22ff16 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -16,6 +16,9 @@
  *  along with this program; if not, see .
  */
 
+SYSCALL_DEF_FULL(brk, .impl = impl_brk,
+ .print_ret = print_syscall_ptr_ret,
+ .arg_type = { ARG_PTR });
 SYSCALL_DEF(close, ARG_DEC);
 SYSCALL_DEF(exit, ARG_DEC);
 #ifdef TARGET_NR_ipc
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 5619defec8..ba541432eb 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -604,29 +604,6 @@ print_execve(const struct syscallname *name,
  * Variants for the return value output function
  */
 
-static void
-print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
-{
-const char *errstr = NULL;
-
-if (ret < 0) {
-errstr = target_strerror(-ret);
-}
-if (errstr) {
-gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
-} else {
-gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
-}
-}
-
-#if 0 /* currently unused */
-static void
-print_syscall_ret_raw(struct syscallname *name, abi_long ret)
-{
-gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
-}
-#endif
-
 #ifdef TARGET_NR__newselect
 static void
 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
@@ -1168,18 +1145,6 @@ print_access(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_brk
-static void
-print_brk(const struct syscallname *name,
-abi_long arg0, abi_long arg1, abi_long arg2,
-abi_long arg3, abi_long arg4, abi_long arg5)
-{
-print_syscall_prologue(name);
-print_pointer(arg0, 1);
-print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_chdir
 static void
 print_chdir(const struct syscallname *name,
diff --git a/linux-user/syscall-mem.inc.c b/linux-user/syscall-mem.inc.c
index d2ce0cb8cc..17ba8e3d97 100644
--- a/linux-user/syscall-mem.inc.c
+++ b/linux-user/syscall-mem.inc.c
@@ -42,6 +42,96 @@ static bitmask_transtbl const mmap_flags_tbl[] = {
 { 0, 0, 0, 0 }
 };
 
+static abi_ulong target_brk;
+static abi_ulong target_original_brk;
+static abi_ulong brk_page;
+
+void target_set_brk(abi_ulong new_brk)
+{
+target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk);
+brk_page = HOST_PAGE_ALIGN(target_brk);
+}
+
+/* do_brk() must return target values and target errnos. */
+abi_long do_brk(abi_ulong new_brk)
+{
+abi_long mapped_addr;
+abi_ulong new_alloc_size;
+
+if (!new_brk) {
+return target_brk;
+}
+if (new_brk < target_original_brk) {
+return target_brk;
+}
+
+/*
+ * If the new brk is less than the highest page reserved to the
+ * target heap allocation, set it and we're almost done...
+ */
+if (new_brk <= brk_page) {
+/*
+ * Heap contents are initialized to zero,
+ * as for anonymous mapped pages.
+ */
+if (new_brk > target_brk) {
+memset(g2h(target_brk), 0, new_brk - target_brk);
+}
+target_brk = new_brk;
+return target_brk;
+}
+
+/*
+ * We need to allocate more memory after the brk... Note that
+ * we don't use MAP_FIXED because that will map over the top of
+ * any existing mapping (like the one with the host libc or qemu
+ * itself); instead we treat "mapped but at wrong address" as
+ * a failure and unmap again.
+ */
+new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page);
+mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
+PROT_READ | PROT_WRITE,
+MAP_ANON | MAP_PRIVATE, 0, 0));
+
+if (mapped_addr == brk_page) {
+/*
+ * Heap contents are initialized to zero, as for anonymous
+ * mapped pages.  Technically the new pages are already
+ * initialized to zero since they *are* anonymous mapped
+ * pages, however we have to take care with the contents that
+ * come from the remaining part of the previous page: it may
+ * contains garbage data due to a previous heap usage (grown
+ * then shrunken).
+ */
+memset(g2h(target_brk), 0, brk_page - target_brk);
+
+target_brk = new_brk;
+brk_page = HOST_PAGE_ALIGN(target_brk);
+return target_brk;
+} else if (mapped_addr != -1) {
+/*
+ * Mapped but at wrong address, meaning there wasn't actually
+ * enough space for this brk.
+ */
+target_munmap(mapped_addr, 

[Qemu-devel] [PATCH v6 07/49] linux-user: Split out close

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h | 1 +
 linux-user/syscall-file.inc.c | 8 
 linux-user/syscall.c  | 4 
 linux-user/strace.list| 3 ---
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index d1a6c6fa3c..797426ae6f 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -16,6 +16,7 @@
  *  along with this program; if not, see .
  */
 
+SYSCALL_DEF(close, ARG_DEC);
 #ifdef TARGET_NR_open
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 841795f8aa..feb83c4e87 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -16,6 +16,14 @@
  *  along with this program; if not, see .
  */
 
+SYSCALL_IMPL(close)
+{
+int fd = arg1;
+
+fd_trans_unregister(fd);
+return get_errno(close(fd));
+}
+
 /*
  * Helpers for do_openat, manipulating /proc/self/foo.
  */
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 035f17c0d9..f230fe161e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6771,10 +6771,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 fd_trans_unregister(ret);
 return ret;
 #endif
-case TARGET_NR_close:
-fd_trans_unregister(arg1);
-return get_errno(close(arg1));
-
 case TARGET_NR_brk:
 return do_brk(arg1);
 #ifdef TARGET_NR_fork
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 2f466e5699..71a18123bf 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -97,9 +97,6 @@
 #ifdef TARGET_NR_clone
 { TARGET_NR_clone, "clone" , NULL, print_clone, NULL },
 #endif
-#ifdef TARGET_NR_close
-{ TARGET_NR_close, "close" , "%s(%d)", NULL, NULL },
-#endif
 #ifdef TARGET_NR_connect
 { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL },
 #endif
-- 
2.17.2




[Qemu-devel] [PATCH v6 12/49] linux-user: Split out preadv, pwritev

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall-defs.h |  6 
 linux-user/syscall-file.inc.c | 64 +++
 linux-user/syscall.c  | 49 ---
 linux-user/strace.list|  6 
 4 files changed, 70 insertions(+), 55 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 027793d5d0..ae89be0e87 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -27,6 +27,12 @@ SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
 SYSCALL_DEF_FULL(pwrite64, .impl = impl_pwrite64,
  .args = args_pread64_pwrite64,
  .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
+SYSCALL_DEF_FULL(preadv, .impl = impl_preadv,
+ .args = args_preadv_pwritev,
+ .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
+SYSCALL_DEF_FULL(pwritev, .impl = impl_pwritev,
+ .args = args_preadv_pwritev,
+ .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
 SYSCALL_DEF(read, ARG_DEC, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_readlink
 SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index e79cfabf56..63401684c3 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -379,6 +379,70 @@ SYSCALL_IMPL(pwrite64)
 return ret;
 }
 
+/*
+ * Both preadv and pwritev merge args 4/5 into a 64-bit offset.
+ * Moreover, the parts are *always* in little-endian order.
+ */
+#if TARGET_ABI_BITS == 32
+SYSCALL_ARGS(preadv_pwritev)
+{
+/* We have already assigned out[0-2].  */
+abi_ulong lo = in[3], hi = in[4];
+out[3] = (((uint64_t)hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+return def;
+}
+#else
+#define args_preadv_pwritev NULL
+#endif
+
+/* Perform the inverse operation for the host.  */
+static inline void host_offset64_low_high(unsigned long *l, unsigned long *h,
+  uint64_t off)
+{
+*l = off;
+*h = (off >> (HOST_LONG_BITS - 1)) >> 1;
+}
+
+SYSCALL_IMPL(preadv)
+{
+int fd = arg1;
+abi_ulong target_vec = arg2;
+int count = arg3;
+uint64_t off = arg4;
+struct iovec *vec = lock_iovec(VERIFY_WRITE, target_vec, count, 0);
+unsigned long lo, hi;
+abi_long ret;
+
+if (vec == NULL) {
+return -TARGET_EFAULT;
+}
+
+host_offset64_low_high(, , off);
+ret = get_errno(safe_preadv(fd, vec, count, lo, hi));
+unlock_iovec(vec, target_vec, count, 1);
+return ret;
+}
+
+SYSCALL_IMPL(pwritev)
+{
+int fd = arg1;
+abi_ulong target_vec = arg2;
+int count = arg3;
+uint64_t off = arg4;
+struct iovec *vec = lock_iovec(VERIFY_READ, target_vec, count, 1);
+unsigned long lo, hi;
+abi_long ret;
+
+if (vec == NULL) {
+return -TARGET_EFAULT;
+}
+
+host_offset64_low_high(, , off);
+ret = get_errno(safe_pwritev(fd, vec, count, lo, hi));
+unlock_iovec(vec, target_vec, count, 0);
+return ret;
+}
+
 SYSCALL_IMPL(read)
 {
 int fd = arg1;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 80806c0150..9606f15a09 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2403,23 +2403,6 @@ static abi_long do_getsockopt(int sockfd, int level, int 
optname,
 return ret;
 }
 
-/* Convert target low/high pair representing file offset into the host
- * low/high pair. This function doesn't handle offsets bigger than 64 bits
- * as the kernel doesn't handle them either.
- */
-static void target_to_host_low_high(abi_ulong tlow,
-abi_ulong thigh,
-unsigned long *hlow,
-unsigned long *hhigh)
-{
-uint64_t off = tlow |
-((unsigned long long)thigh << TARGET_LONG_BITS / 2) <<
-TARGET_LONG_BITS / 2;
-
-*hlow = off;
-*hhigh = (off >> HOST_LONG_BITS / 2) >> HOST_LONG_BITS / 2;
-}
-
 static struct iovec *lock_iovec(int type, abi_ulong target_addr,
 abi_ulong count, int copy)
 {
@@ -8949,38 +8932,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 /* NOTE: the flock constant seems to be the same for every
Linux platform */
 return get_errno(safe_flock(arg1, arg2));
-#if defined(TARGET_NR_preadv)
-case TARGET_NR_preadv:
-{
-struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
-if (vec != NULL) {
-unsigned long low, high;
-
-target_to_host_low_high(arg4, arg5, , );
-ret = get_errno(safe_preadv(arg1, vec, arg3, low, high));
-unlock_iovec(vec, arg2, arg3, 1);
-} else {
-ret = -host_to_target_errno(errno);
-   }
-}
-return ret;
-#endif
-#if defined(TARGET_NR_pwritev)
-case TARGET_NR_pwritev:
-{
-struct 

[Qemu-devel] [PATCH v6 04/49] linux-user: Share more code for open and openat

2019-01-18 Thread Richard Henderson
The do_openat helper can have all of the code that is not directly
related to the argument ordering of these two syscalls.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-file.inc.c | 69 ---
 1 file changed, 31 insertions(+), 38 deletions(-)

diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index ca777da753..ffa70bbea8 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -221,8 +221,8 @@ static int open_net_route(void *cpu_env, int fd)
 }
 #endif
 
-static int do_openat(void *cpu_env, int dirfd, const char *pathname,
- int flags, mode_t mode)
+static abi_long do_openat(void *cpu_env, int dirfd, abi_ulong target_path,
+  int target_flags, mode_t mode)
 {
 struct fake_open {
 const char *filename;
@@ -241,9 +241,20 @@ static int do_openat(void *cpu_env, int dirfd, const char 
*pathname,
 { NULL, NULL, NULL }
 };
 
+char *pathname = lock_user_string(target_path);
+int flags = target_to_host_bitmask(target_flags, fcntl_flags_tbl);
+abi_long ret;
+
+if (!pathname) {
+return -TARGET_EFAULT;
+}
+
 if (is_proc_myself(pathname, "exe")) {
-int execfd = qemu_getauxval(AT_EXECFD);
-return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode);
+ret = qemu_getauxval(AT_EXECFD);
+if (ret == 0) {
+ret = get_errno(safe_openat(dirfd, exec_path, flags, mode));
+}
+goto done;
 }
 
 for (fake_open = fakes; fake_open->filename; fake_open++) {
@@ -255,7 +266,7 @@ static int do_openat(void *cpu_env, int dirfd, const char 
*pathname,
 if (fake_open->filename) {
 const char *tmpdir;
 char filename[PATH_MAX];
-int fd, r;
+int fd;
 
 /* create temporary file to map stat to */
 tmpdir = getenv("TMPDIR");
@@ -265,55 +276,37 @@ static int do_openat(void *cpu_env, int dirfd, const char 
*pathname,
 snprintf(filename, sizeof(filename), "%s/qemu-open.XX", tmpdir);
 fd = mkstemp(filename);
 if (fd < 0) {
-return fd;
+ret = -TARGET_ENOENT;
+goto done;
 }
 unlink(filename);
 
-r = fake_open->fill(cpu_env, fd);
-if (r) {
-int e = errno;
+ret = fake_open->fill(cpu_env, fd);
+if (ret) {
+ret = get_errno(ret);
 close(fd);
-errno = e;
-return r;
+goto done;
 }
 lseek(fd, 0, SEEK_SET);
-
-return fd;
+ret = fd;
+goto done;
 }
 
-return safe_openat(dirfd, path(pathname), flags, mode);
+ret = get_errno(safe_openat(dirfd, path(pathname), flags, mode));
+ done:
+fd_trans_unregister(ret);
+unlock_user(pathname, target_path, 0);
+return ret;
 }
 
 #ifdef TARGET_NR_open
 SYSCALL_IMPL(open)
 {
-char *p = lock_user_string(arg1);
-abi_long ret;
-
-if (!p) {
-return -TARGET_EFAULT;
-}
-ret = get_errno(do_openat(cpu_env, AT_FDCWD, p,
-  target_to_host_bitmask(arg2, fcntl_flags_tbl),
-  arg3));
-fd_trans_unregister(ret);
-unlock_user(p, arg1, 0);
-return ret;
+return do_openat(cpu_env, AT_FDCWD, arg1, arg2, arg3);
 }
 #endif
 
 SYSCALL_IMPL(openat)
 {
-char *p = lock_user_string(arg2);
-abi_long ret;
-
-if (!p) {
-return -TARGET_EFAULT;
-}
-ret = get_errno(do_openat(cpu_env, arg1, p,
-  target_to_host_bitmask(arg3, fcntl_flags_tbl),
-  arg4));
-fd_trans_unregister(ret);
-unlock_user(p, arg2, 0);
-return ret;
+return do_openat(cpu_env, arg1, arg2, arg3, arg4);
 }
-- 
2.17.2




[Qemu-devel] [PATCH v6 09/49] linux-user: Reduce regpairs_aligned & target_offset64 ifdefs

2019-01-18 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 linux-user/syscall.c | 54 
 1 file changed, 25 insertions(+), 29 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d4d5c25803..c236a80437 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -474,37 +474,38 @@ static inline int next_free_host_timer(void)
 }
 #endif
 
-/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
+/*
+ * Returns true if syscall NUM expects 64bit types aligned even
+ * on pairs of registers.
+ */
+static inline bool regpairs_aligned(void *cpu_env, int num)
+{
 #ifdef TARGET_ARM
-static inline int regpairs_aligned(void *cpu_env, int num)
-{
-return CPUARMState *)cpu_env)->eabi) == 1) ;
-}
-#elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32)
-static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+return ((CPUARMState *)cpu_env)->eabi;
+#elif defined(TARGET_MIPS) && TARGET_ABI_BITS == 32
+return true;
 #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
-/* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
- * of registers which translates to the same as ARM/MIPS, because we start with
- * r3 as arg1 */
-static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+/*
+ * SysV AVI for PPC32 expects 64bit parameters to be passed on
+ * odd/even pairs of registers which translates to the same as
+ * we start with r3 as arg1.
+ */
+return true;
 #elif defined(TARGET_SH4)
-/* SH4 doesn't align register pairs, except for p{read,write}64 */
-static inline int regpairs_aligned(void *cpu_env, int num)
-{
+/* SH4 doesn't align register pairs, except for p{read,write}64.  */
 switch (num) {
 case TARGET_NR_pread64:
 case TARGET_NR_pwrite64:
-return 1;
-
+return true;
 default:
-return 0;
+return false;
 }
-}
 #elif defined(TARGET_XTENSA)
-static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+return true;
 #else
-static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
+return false;
 #endif
+}
 
 #define ERRNO_TABLE_SIZE 1200
 
@@ -6105,21 +6106,16 @@ void syscall_init(void)
 }
 }
 
-#if TARGET_ABI_BITS == 32
-static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
+static inline uint64_t target_offset64(abi_ulong word0, abi_ulong word1)
 {
-#ifdef TARGET_WORDS_BIGENDIAN
+#if TARGET_ABI_BITS == 64
+return word0;
+#elif defined(TARGET_WORDS_BIGENDIAN)
 return ((uint64_t)word0 << 32) | word1;
 #else
 return ((uint64_t)word1 << 32) | word0;
 #endif
 }
-#else /* TARGET_ABI_BITS == 32 */
-static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
-{
-return word0;
-}
-#endif /* TARGET_ABI_BITS != 32 */
 
 #ifdef TARGET_NR_truncate64
 static inline abi_long target_truncate64(void *cpu_env, const char *arg1,
-- 
2.17.2




[Qemu-devel] [PATCH v6 00/49] linux-user: Split do_syscall

2019-01-18 Thread Richard Henderson
Since v5, I've split the patches into smaller pieces, and done
a few more syscalls.  But I've also been approaching them in a
more "systematic" way -- taking from the top of the switch.

I've been trying to fix up checkpatch failures as I've moved
code, but I've surely missed some.  I've also been trying to
share code between the "*at" syscalls and their original.

I've tested x86_64->armhf and aarch64->i386 vs LTP.

FYI, as measured by the line count of do_syscall1, this is
about 25% of the total job to be done.


r~


PS: Patch 2/49 is a debugging patch I forgot to remove.
Rather than regenerate the series, I just omitted it here.


Richard Henderson (49):
  linux-user: Setup split syscall infrastructure
  linux-user: Split out open, open_at
  linux-user: Share more code for open and openat
  linux-user: Tidy do_openat loop over fakes
  linux-user: Split out readlink, readlinkat
  linux-user: Split out close
  linux-user: Split out read, write
  linux-user: Reduce regpairs_aligned & target_offset64 ifdefs
  linux-user: Split out readv, writev
  linux-user: Split out pread64, pwrite64
  linux-user: Split out preadv, pwritev
  linux-user: Split out name_to_handle_at, open_by_handle_at
  linux-user: Split out ipc syscalls
  linux-user: Split out memory syscalls
  linux-user: Split out exit
  linux-user: Split out brk
  linux-user: Split out clone, fork, vfork
  linux-user: Split out wait4, waitid, waitpid
  linux-user: Implement rusage argument to waitid
  linux-user: Split out creat
  linux-user: Split out link, linkat
  linux-user: Split out unlink, unlinkat, rmdir
  linux-user: Split out execve
  linux-user: Implement execveat
  linux-user: Split out chdir
  linux-user: Split out time
  linux-user: Split out mknod, mknodat
  linux-user: Split out chmod, fchmod, fchmodat
  linux-user: Split out lseek, llseek
  linux-user: Split out getpid, getppid, getxpid
  linux-user: Split out mount
  linux-user: Split out umount, umount2
  linux-user: Split out stime
  linux-user: Split out alarm, pause
  linux-user: Split out utime, utimes, futimesat
  linux-user: Split out access, faccessat
  linux-user: Split out nice
  linux-user: Split out sync, syncfs
  linux-user: Split out kill
  linux-user: Split out rename, renameat, renameat2
  linux-user: Split out mkdir, mkdirat
  linux-user: Split out dup, dup2, dup3
  linux-user: Split out pipe, pipe2
  linux-user: Split out times
  linux-user: Split out acct
  linux-user: Move syscall_init to the end
  linux-user: Split out ioctl
  linux-user: Split out fcntl, fcntl64

 linux-user/syscall-defs.h  |  240 ++
 linux-user/syscall.h   |  102 +
 linux-user/strace.c| 1258 +++---
 linux-user/syscall-fcntl.inc.c |  322 +++
 linux-user/syscall-file.inc.c  | 1229 ++
 linux-user/syscall-ioctl.inc.c |  873 +++
 linux-user/syscall-ipc.inc.c   | 1086 +
 linux-user/syscall-mem.inc.c   |  244 ++
 linux-user/syscall-proc.inc.c  |  593 +
 linux-user/syscall-sig.inc.c   |   41 +
 linux-user/syscall-time.inc.c  |   44 +
 linux-user/syscall.c   | 4128 ++--
 configure  |   20 -
 linux-user/strace.list |  285 ---
 14 files changed, 5376 insertions(+), 5089 deletions(-)
 create mode 100644 linux-user/syscall-defs.h
 create mode 100644 linux-user/syscall.h
 create mode 100644 linux-user/syscall-fcntl.inc.c
 create mode 100644 linux-user/syscall-file.inc.c
 create mode 100644 linux-user/syscall-ioctl.inc.c
 create mode 100644 linux-user/syscall-ipc.inc.c
 create mode 100644 linux-user/syscall-mem.inc.c
 create mode 100644 linux-user/syscall-proc.inc.c
 create mode 100644 linux-user/syscall-sig.inc.c
 create mode 100644 linux-user/syscall-time.inc.c

-- 
2.17.2




[Qemu-devel] [PATCH v6 05/49] linux-user: Tidy do_openat loop over fakes

2019-01-18 Thread Richard Henderson
Cleaner to use ARRAY_SIZE to loop over elements instead of
using a sentinel within the data structure.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall-file.inc.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index ffa70bbea8..f202a4c8f4 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -229,7 +229,6 @@ static abi_long do_openat(void *cpu_env, int dirfd, 
abi_ulong target_path,
 int (*fill)(void *cpu_env, int fd);
 int (*cmp)(const char *s1, const char *s2);
 };
-const struct fake_open *fake_open;
 static const struct fake_open fakes[] = {
 { "maps", open_self_maps, is_proc_myself },
 { "stat", open_self_stat, is_proc_myself },
@@ -238,12 +237,12 @@ static abi_long do_openat(void *cpu_env, int dirfd, 
abi_ulong target_path,
 #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
 { "/proc/net/route", open_net_route, is_proc },
 #endif
-{ NULL, NULL, NULL }
 };
 
 char *pathname = lock_user_string(target_path);
 int flags = target_to_host_bitmask(target_flags, fcntl_flags_tbl);
 abi_long ret;
+size_t i;
 
 if (!pathname) {
 return -TARGET_EFAULT;
@@ -257,17 +256,16 @@ static abi_long do_openat(void *cpu_env, int dirfd, 
abi_ulong target_path,
 goto done;
 }
 
-for (fake_open = fakes; fake_open->filename; fake_open++) {
-if (fake_open->cmp(pathname, fake_open->filename)) {
-break;
-}
-}
-
-if (fake_open->filename) {
+for (i = 0; i < ARRAY_SIZE(fakes); ++i) {
+const struct fake_open *fake_open = [i];
 const char *tmpdir;
 char filename[PATH_MAX];
 int fd;
 
+if (!fake_open->cmp(pathname, fake_open->filename)) {
+continue;
+}
+
 /* create temporary file to map stat to */
 tmpdir = getenv("TMPDIR");
 if (!tmpdir) {
-- 
2.17.2




Re: [Qemu-devel] [PULL 0/7] check-softfloat, fp-bench and clang compile fixes

2019-01-18 Thread Emilio G. Cota
On Fri, Jan 18, 2019 at 17:41:15 +, Alex Bennée wrote:
> 
> Emilio G. Cota  writes:
> 
> > On Thu, Jan 17, 2019 at 18:55:33 +, Peter Maydell wrote:
> >> On Thu, 17 Jan 2019 at 18:30, Emilio G. Cota  wrote:
> >> > What are the contents of "int-to-float.err"?
> >>
> >> linux1@lxub05:~$ cat qemu/build/all/tests/fp/int-to-float.err
(snip)
> >> >> Testing i32_to_f128
> >> 372 tests total.
> >> 21 tests performed; 20 errors found.
> >
> > I see, so i32_to_f128 is failing on this host. Is there
> > a s390x machine I could access? I don't see one in the
> > gcc compile farm.
> 
> I've managed to reproduce this in a s390x VM, for Debian install runes:
> 
>   
> https://wiki.qemu.org/Documentation/Platforms/S390X#Debian_Install_Example_.28TCG.29

It's an endianness issue -- I've reproduced it on both gcc110
(POWER7) from gcc's compile farm and on the s390 machine provided
by Peter (thanks!). Both machines are big endian.

I have a fix for the 128 conversions (below), but not for the
int-to-f80 conversions (the ones that work on little endian).
I have no more time to look into this, so if someone can take
a look, I'd appreciate it.

I'm a little puzzled because given these definitions:

// our floatx80
typedef struct {
uint64_t low;
uint16_t high;
} floatx80;

// softfloat's
#ifdef LITTLEENDIAN
struct extFloat80M { uint64_t signif; uint16_t signExp; };
#else
struct extFloat80M { uint16_t signExp; uint64_t signif; };
#endif

I fail to see why just copying low/high to/from signif/signExp
to convert between them fails to work.

Thanks,

Emilio

---
diff --git a/tests/fp/wrap.inc.c b/tests/fp/wrap.inc.c
index d3bf600cd0..68f57bc167 100644
--- a/tests/fp/wrap.inc.c
+++ b/tests/fp/wrap.inc.c
@@ -87,8 +87,13 @@ static float128_t qemu_to_soft128(float128 a)
 float128_t ret;
 struct uint128 *to = (struct uint128 *)

+#ifdef LITTLEENDIAN
 to->v0 = a.low;
 to->v64 = a.high;
+#else
+to->v0 = a.high;
+to->v64 = a.low;
+#endif
 return ret;
 }

@@ -97,8 +102,13 @@ static float128 soft_to_qemu128(float128_t a)
 struct uint128 *from = (struct uint128 *)
 float128 ret;

+#ifdef LITTLEENDIAN
 ret.low = from->v0;
 ret.high = from->v64;
+#else
+ret.low = from->v64;
+ret.high = from->v0;
+#endif
 return ret;
 }





Re: [Qemu-devel] [PULL 0/7] check-softfloat, fp-bench and clang compile fixes

2019-01-18 Thread Alex Bennée


Peter Maydell  writes:

> On Fri, 18 Jan 2019 at 18:16, Emilio G. Cota  wrote:
>>
>> On Fri, Jan 18, 2019 at 17:00:17 +, Alex Bennée wrote:
>> > Philippe Mathieu-Daudé  writes:
>> > > Can you modify the Makefile.include to use:
>> > >  "fp-test ... 2>int-to-float.err || {cat int-to-float.err && exit 1;}"
>> >
>> > Well it's in the test-softfloat macro but sure...
>>
>> Actually, can we do &> instead of 2> ?
>
> "&>" is a bashism. The POSIX equivalent is >file.err 2>&1
>
> thanks
> -- PMM

I've gone for this:

 # $1 = tests, $2 = description
 test-softfloat = $(call quiet-command, \
-cd $(BUILD_DIR)/tests/fp && ./fp-test -s $(FP_TL) $1 > 
$2.out 2> $2.err, \
+cd $(BUILD_DIR)/tests/fp && \
+./fp-test -s $(FP_TL) $1 > $2.out 2>&1 || \
+(cat $2.out && exit 1;), \
 "FLOAT TEST", $2)

As for the tests it seems quite a lot are broken on s390x for a reason I
don't quite follow yet:

 i32_to_f128
 i64_to_f128
 ui64_to_f128
 extF80_to_i32
 extF80_to_i32_r_minMag
 extF80_eq

and more which I haven't confirmed yet. I'm tempted to ifndef the tests
for s390 for now while we sort out what's going on. Should I re-send
with that?

--
Alex Bennée



Re: [Qemu-devel] [PATCH] qemu-gdb: add a QObject pretty printer

2019-01-18 Thread Eduardo Habkost
On Fri, Jan 18, 2019 at 05:48:43PM +0400, Marc-André Lureau wrote:
> Inspired by GObject/GType pretty printer.
> 
> Example:
> machine_set_accel (obj=0x56807550 [pc-i440fx-4.0-machine],...
> 
> Signed-off-by: Marc-André Lureau 
> ---
>  scripts/qemu-gdb.py | 58 +
>  1 file changed, 58 insertions(+)
>  mode change 100644 => 100755 scripts/qemu-gdb.py
> 
> diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py
> old mode 100644
> new mode 100755
> index 690827e6fc6..90c6fd13b93
> --- a/scripts/qemu-gdb.py
> +++ b/scripts/qemu-gdb.py
> @@ -21,6 +21,9 @@ import gdb
>  
>  import os, sys
>  
> +if sys.version_info[0] >= 3:
> +long = int
[...]
> +class QObjectPrinter:
> +def __init__(self, val):
> +self.val = val
> +
> +def to_string(self):
> +name = object_class_name(self.val)
> +if name:
> +return ("0x%x [%s]")% (long(self.val), name)
> +return  ("0x%x") % (long(self.val))

I took a while to find out that int(v) doesn't work if v is a
pointer gdb value.  This is surprising, because int(long_number)
(e.g. int(2**65)) works on Python 2.

Also, this works on Python 2:

  int(self.val.cast(gdb.lookup_type("unsigned long long")))

But it's so ugly that a sys.version_info check still sounds
better.

I would prefer this, though:

  if sys.version_info[0] < 3:
  int = long
  ...
  def to_string(self):
  ...
  return  ("0x%x") % (int(self.val))

Because it makes the python2-specific code easier to remove in
the future.

> +
> +
> +def lookup_type(val):
> +if is_object(val):
> +return QObjectPrinter(val)
> +return None
> +
> +
> +gdb.pretty_printers.append(lookup_type)
> -- 
> 2.20.1.98.gecbdaf0899
> 

-- 
Eduardo



Re: [Qemu-devel] Live migration from Qemu 2.12 hosts to Qemu 3.2 hosts, with VMX flag enabled in the guest?

2019-01-18 Thread Dr. David Alan Gilbert
* Paolo Bonzini (pbonz...@redhat.com) wrote:
> On 18/01/19 14:41, Mark Mielke wrote:
> > It is useful to understand the risk. However, this is the same risk we
> > have been successfully living with for several years now, and it seems
> > abrupt to declare 3.1 and 3.2 as the Qemu version beyond which migration
> > requires a whole cluster restart whether or not a L2 guest had been, or
> > will ever be started on any of the guests.
> 
> Only if nested was enabled for the kvm_intel module.  If you didn't
> enable it, you didn't see any change with 3.1.
> 
> Nested was enabled for kvm_amd years ago.  It was a mistake, but that's
> why we didn't add such a blocker for AMD.

Still, it should have probably been machine-type tied;  there's lots and
lots of broken things we've done in the past which we've kept
compatibility with on old machine types.

Dave

> Paolo
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [RFC PATCH v3 28/43] hw/pci/Makefile.objs: make pcie configurable

2019-01-18 Thread Michael S. Tsirkin
On Fri, Jan 18, 2019 at 06:28:37PM +0100, Paolo Bonzini wrote:
> 
> 
> I think PCIE should depend on PCI or something like this.
> That's because there are places in code that test CONFIG_PCI,
> you want PCIE to enable them as well.
> 
> 
> I agree, it should select PCI, so that PCIe bridges only need to select PCIE
> (the model in QEMU is that you enable boards and pluggable devices; everything
> else, especially buses, is then selected automatically based on whether any
> controllers/bridges are enabled for those buses).
> 
> Paolo
> 

OK, and I also think we should rename it PCIE -> PCI_EXPRESS_, this way
everything PCI starts with PCI.

-- 
MST



Re: [Qemu-devel] [RFC PATCH v3 29/43] build: convert pci.mak to Kconfig

2019-01-18 Thread Michael S. Tsirkin
On Fri, Jan 18, 2019 at 06:03:46PM +0100, Paolo Bonzini wrote:
> On 18/01/19 17:36, Michael S. Tsirkin wrote:
> >>  config PCI_GENERIC
> >>  bool
> >> +select PCIE
> >>
> > 
> > why is this?
> >   
> 
> PCI_GENERIC is hw/pci-host/gpex.c, the "QEMU Generic PCI Express Bridge
> Emulation".

Oh. Not really descriptive.
I guess we should rename it to PCI_EXPRESS_GENERIC_BRIDGE or something?

> >>  config PCI_XILINX
> >>  bool
> >> +select PCIE
> >>  
> >>  config PCI_DESIGNWARE
> >>  bool
> >> +select PCIE
> > 
> > 
> > sure about the above?
> 
> The comments at the top of the two files say they are PCIe.
> 
> Paolo


So I guess the part that I find confusing is which module
it is. Module should be a prefix. So if module is PCI
then everything should be PCI_ and PCIE should be
PCI_EXPRESS. If PCIE is the module then all these guys
should be renamed.

-- 
MST



Re: [Qemu-devel] [PATCH] hw/virtio/virtio-balloon: zero-initialize the virtio_balloon_config struct

2019-01-18 Thread Michael S. Tsirkin
On Fri, Jan 18, 2019 at 06:36:03PM +, Peter Maydell wrote:
> In virtio_balloon_get_config() we initialize a struct virtio_balloon_config
> which we then copy to guest memory. However, the local variable is not
> zero initialized. This works OK at the moment because we initialize
> all the fields in it; however an upcoming kernel header change will
> add some new fields. If we don't zero out the whole struct then we
> will start leaking a small amount of the contents of QEMU's stack
> to the guest as soon as we update linux-headers/ to a set of headers
> that includes the new fields.
> 
> Signed-off-by: Peter Maydell 

Reviewed-by: Michael S. Tsirkin 

> ---
> It looks like none of the other virtio devices have this bug.
> Tested with "make check" only.
> As the commit message notes, must go in before our next headers update.

Want me to merge it? Or you can pick it up directly if you like
to make sure that happens.

> ---
>  hw/virtio/virtio-balloon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index 1728e4f83af..a12677d4d5b 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -311,7 +311,7 @@ out:
>  static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t 
> *config_data)
>  {
>  VirtIOBalloon *dev = VIRTIO_BALLOON(vdev);
> -struct virtio_balloon_config config;
> +struct virtio_balloon_config config = {};
>  
>  config.num_pages = cpu_to_le32(dev->num_pages);
>  config.actual = cpu_to_le32(dev->actual);
> -- 
> 2.20.1



Re: [Qemu-devel] [PULL 00/11] s390x updates

2019-01-18 Thread Peter Maydell
On Fri, 18 Jan 2019 at 12:19, Cornelia Huck  wrote:
>
> The following changes since commit 681d61362d3f766a00806b89d6581869041f73cb:
>
>   Merge remote-tracking branch 'remotes/jnsnow/tags/bitmaps-pull-request' 
> into staging (2019-01-17 12:48:42 +)
>
> are available in the Git repository at:
>
>   https://github.com/cohuck/qemu tags/s390x-20190118
>
> for you to fetch changes up to 6e92c70c37547b6a247a206651dfcc583a57f484:
>
>   s390x/pci: add common function measurement block (2019-01-18 11:52:01 +0100)
>
> 
> s390x updates:
> - clang compilation fixes
> - fixes in zpci hotplug code
> - handle unimplemented diag 308 subcodes correctly
> - add common fmb in zpci
>


Applied, thanks.

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

-- PMM



[Qemu-devel] [PATCH] tests: Disable ipmi-bt-test

2019-01-18 Thread Peter Maydell
The ipmi-bt-test fails intermittently, especially on the NetBSD VM.
The frequency of this failure has recently gone up sharply to the
point that I'm having to retry the NetBSD build multiple times
to get a pass when merging pull requests.

Disable the test until we can figure out why it's failing.

Signed-off-by: Peter Maydell 
---
Fed up with this failing all the time so let's just turn it off.
Feel free to investigate what's actually going wrong with it...

 tests/Makefile.include | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index eaa81ee1d07..5e6b2c7058d 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -186,7 +186,8 @@ check-qtest-i386-$(CONFIG_SGA) += 
tests/boot-serial-test$(EXESUF)
 check-qtest-i386-$(CONFIG_SLIRP) += tests/pxe-test$(EXESUF)
 check-qtest-i386-y += tests/rtc-test$(EXESUF)
 check-qtest-i386-y += tests/ipmi-kcs-test$(EXESUF)
-check-qtest-i386-y += tests/ipmi-bt-test$(EXESUF)
+# Disabled temporarily as it fails intermittently especially under NetBSD VM
+# check-qtest-i386-y += tests/ipmi-bt-test$(EXESUF)
 check-qtest-i386-y += tests/i440fx-test$(EXESUF)
 check-qtest-i386-y += tests/fw_cfg-test$(EXESUF)
 check-qtest-i386-y += tests/drive_del-test$(EXESUF)
-- 
2.20.1




[Qemu-devel] [PATCH] hw/virtio/virtio-balloon: zero-initialize the virtio_balloon_config struct

2019-01-18 Thread Peter Maydell
In virtio_balloon_get_config() we initialize a struct virtio_balloon_config
which we then copy to guest memory. However, the local variable is not
zero initialized. This works OK at the moment because we initialize
all the fields in it; however an upcoming kernel header change will
add some new fields. If we don't zero out the whole struct then we
will start leaking a small amount of the contents of QEMU's stack
to the guest as soon as we update linux-headers/ to a set of headers
that includes the new fields.

Signed-off-by: Peter Maydell 
---
It looks like none of the other virtio devices have this bug.
Tested with "make check" only.
As the commit message notes, must go in before our next headers update.
---
 hw/virtio/virtio-balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 1728e4f83af..a12677d4d5b 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -311,7 +311,7 @@ out:
 static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
 VirtIOBalloon *dev = VIRTIO_BALLOON(vdev);
-struct virtio_balloon_config config;
+struct virtio_balloon_config config = {};
 
 config.num_pages = cpu_to_le32(dev->num_pages);
 config.actual = cpu_to_le32(dev->actual);
-- 
2.20.1




Re: [Qemu-devel] [PULL v3 00/28] ivshmem deprecation, qtests, typedefs and gnu99

2019-01-18 Thread Peter Maydell
On Fri, 18 Jan 2019 at 18:26, Philippe Mathieu-Daudé  wrote:
>
> On 1/18/19 3:20 PM, Peter Maydell wrote:
> > I tried the "raise the timeout" change you suggested on IRC.
> > That gave me a pass the first time around but the same failure
> > second time I tried it:
> >
> > MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}
> > QTEST_QEMU_BINARY=i386-softmmu/qemu-system-i386
> > QTEST_QEMU_IMG=qemu-img tests/ipmi-bt-test -m=quick -k --tap <
> > /dev/null | ./scripts/tap-driver.pl --test-name="ipmi-bt-test"
> > **
> > ERROR:tests/ipmi-bt-test.c:319:test_connect: assertion failed: (rv == 1)
> > ERROR - too few tests run (expected 4, got 0)
> > [1]   Abort trap (core dumped) MALLOC_PERTURB_=... |
> >   Done(1) ./scripts/tap-dr...
> > /var/tmp/qemu-test.TATvqX/tests/Makefile.include:856: recipe for
> > target 'check-qtest-i386' failed
>
> I guess I finally figured it out, the test binds IPv4 and on the NetBSD
> VM, 'localhost' resolves as IPv6 so the guest can't connect to the test.

This theory doesn't explain why the test sometimes passes and
sometimes fails, though...

thanks
-- PMM



[Qemu-devel] Implementing Memory Tag Extention - ARM

2019-01-18 Thread Vishnu Dev
Hello,
I am a undergraduate Binary Exploitation enthusiast who would like to
participate in GSoC with qemu on some security related project . While
enquiring on IRC @agraf suggested a idea of implementing memory tag
extension on ARM, this seems to be a good project . I have some experience
reversing ARM binaries and exploitation on ARM architecture but have not
done any open source contribution but I feel GSoC will be a great
opportunity for me to begin and since I am really found of low level stuff,
qemu seems to be a good organization to work with . also Qemu have helped
me while working on ARM exploitation and Linux kernel Exploitation.

Is this project feasible to implement as a GSoC project this year .

Reference :
https://en.wikichip.org/wiki/arm/mte
https://community.arm.com/processors/b/blog/posts/arm-a-profile-architecture-2018-developments-armv85a


-- 
Vishnu Dev TJ


Re: [Qemu-devel] [PULL 0/7] check-softfloat, fp-bench and clang compile fixes

2019-01-18 Thread Peter Maydell
On Fri, 18 Jan 2019 at 18:16, Emilio G. Cota  wrote:
>
> On Fri, Jan 18, 2019 at 17:00:17 +, Alex Bennée wrote:
> > Philippe Mathieu-Daudé  writes:
> > > Can you modify the Makefile.include to use:
> > >  "fp-test ... 2>int-to-float.err || {cat int-to-float.err && exit 1;}"
> >
> > Well it's in the test-softfloat macro but sure...
>
> Actually, can we do &> instead of 2> ?

"&>" is a bashism. The POSIX equivalent is >file.err 2>&1

thanks
-- PMM



Re: [Qemu-devel] [PULL v3 00/28] ivshmem deprecation, qtests, typedefs and gnu99

2019-01-18 Thread Philippe Mathieu-Daudé
On 1/18/19 3:20 PM, Peter Maydell wrote:
> On Fri, 18 Jan 2019 at 11:47, Peter Maydell  wrote:
>>
>> On Thu, 17 Jan 2019 at 13:38, Thomas Huth  wrote:
>>>
>>>  Hi Peter!
>>>
>>> The following changes since commit 6f2f34177a25bffd6fd92a05e6e66c8d22d97094:
>>>
>>>   Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into 
>>> staging (2019-01-15 18:32:57 +)
>>>
>>> are available in the git repository at:
>>>
>>>   https://gitlab.com/huth/qemu.git tags/pull-request-2019-01-17
>>>
>>> for you to fetch changes up to 3f0832c85380321ef697d64342b389648f8abb1c:
>>>
>>>   tests/hexloader-test: Don't pass -nographic to the QEMU under test 
>>> (2019-01-17 14:25:12 +0100)
>>>
>>> 
>>> - Remove deprecated "ivshmem" legacy device
>>> - Bug fix for vhost-user-test
>>> - Use more CONFIG Makefile switches for qtests
>>> - Get rid of global_qtests in some more qtests
>>> - typedef cleanups
>>> - Fixes for compiling with Clang
>>> - Force C standard to gnu99
>>> 
>>
>> In the netbsd VM, the ipmi-bt-test is consistently failing:
>>
>> MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}
>> QTEST_QEMU_BINARY=i386-softmmu
>> /qemu-system-i386 QTEST_QEMU_IMG=qemu-img tests/ipmi-bt-test -m=quick
>> -k --tap < /dev/null | ./s
>> cripts/tap-driver.pl --test-name="ipmi-bt-test"
>> **
>> ERROR:tests/ipmi-bt-test.c:319:test_connect: assertion failed: (rv == 1)
>> ERROR - too few tests run (expected 4, got 0)
>> [1]   Abort trap (core dumped) MALLOC_PERTURB_=... |
>>   Done(1) ./scripts/tap-dr...
>> /var/tmp/qemu-test.7opHvo/tests/Makefile.include:856: recipe for
>> target 'check-qtest-i386' faile
>> d
>> gmake: *** [check-qtest-i386] Error 1
>> gmake: *** Waiting for unfinished jobs
>>
>>
>> This has been kind of intermittent for a while, I've seen
>> it on-and-off, but with this pullreq it's failed four times
>> in a row, so maybe something in here is making it less
>> intermittent.
> 
> I tried the "raise the timeout" change you suggested on IRC.
> That gave me a pass the first time around but the same failure
> second time I tried it:
> 
> MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}
> QTEST_QEMU_BINARY=i386-softmmu/qemu-system-i386
> QTEST_QEMU_IMG=qemu-img tests/ipmi-bt-test -m=quick -k --tap <
> /dev/null | ./scripts/tap-driver.pl --test-name="ipmi-bt-test"
> **
> ERROR:tests/ipmi-bt-test.c:319:test_connect: assertion failed: (rv == 1)
> ERROR - too few tests run (expected 4, got 0)
> [1]   Abort trap (core dumped) MALLOC_PERTURB_=... |
>   Done(1) ./scripts/tap-dr...
> /var/tmp/qemu-test.TATvqX/tests/Makefile.include:856: recipe for
> target 'check-qtest-i386' failed

I guess I finally figured it out, the test binds IPv4 and on the NetBSD
VM, 'localhost' resolves as IPv6 so the guest can't connect to the test.

I'm not sure what's the best way to fix this (yet), meanwhile the tests
succeed using:

-- >8 --
 global_qtest = qtest_initf(
-" -chardev socket,id=ipmi0,host=localhost,port=%d,reconnect=10"
+" -chardev socket,id=ipmi0,host=127.0.0.1,port=%d,reconnect=10"
 " -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0"
---

Regards,

Phil.



Re: [Qemu-devel] [PULL 0/7] check-softfloat, fp-bench and clang compile fixes

2019-01-18 Thread Emilio G. Cota
On Fri, Jan 18, 2019 at 17:00:17 +, Alex Bennée wrote:
> Philippe Mathieu-Daudé  writes:
> > Can you modify the Makefile.include to use:
> >  "fp-test ... 2>int-to-float.err || {cat int-to-float.err && exit 1;}"
> 
> Well it's in the test-softfloat macro but sure...

Actually, can we do &> instead of 2> ?

The errors coming from berkeley-testfloat are printed to stdout,
so we should get those too. (We could fix testfloat to print
to stderr, but I'd rather only make strictly necessary changes
to berkeley-testfloat.)

Thanks,

E.



Re: [Qemu-devel] [PATCH v2 4/4] trace: add ability to do simple printf logging via systemtap

2019-01-18 Thread Eric Blake
On 1/18/19 11:31 AM, Daniel P. Berrangé wrote:
> The dtrace systemtap trace backend for QEMU is very powerful but it is
> also somewhat unfriendly to users who aren't familiar with systemtap,
> or who don't need its power right now.
> 
>   stap -e "some strange script"
> 

> We go one step further though and introduce a 'qemu-trace-stap' tool to
> make this even easier
> 
>  $ qemu-trace-stap run qemu-system-x86_64 qio*
>  22806@1547735341399856820 qio_channel_socket_new Socket new 
> ioc=0x56135d1d7c00

One thing I did not immediately get on the first read, and therefore
which may be worth mentioning in the docs portion of the patch:

Am I correct that stap is always run as a separate process from the
process(es) being traced, and that you can start the two in either order
(qemu first, then stap; or stap first, then qemu), where the tracing is
effectively output as long as both processes are running and trace
points being hit in the qemu process?


> Signed-off-by: Daniel P. Berrangé 
> ---
>  Makefile |   3 +
>  Makefile.target  |  11 +-
>  docs/devel/tracing.txt   |  32 +
>  scripts/qemu-trace-stap  | 167 +++
>  scripts/tracetool/format/log_stap.py | 127 

Overall, I'm impressed with the concept, but my familiarity with stap
and python is weak enough that I'm not leaving a formal R-b.  Still,
I'll give it a shot at looking for anything that stands out as I read
through.

>  5 files changed, 339 insertions(+), 1 deletion(-)
>  create mode 100755 scripts/qemu-trace-stap
>  create mode 100644 scripts/tracetool/format/log_stap.py
> 
> diff --git a/Makefile b/Makefile
> index dccba1dca2..22e481e7ba 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -736,6 +736,9 @@ endif
>  ifneq ($(HELPERS-y),)
>   $(call install-prog,$(HELPERS-y),$(DESTDIR)$(libexecdir))
>  endif
> +ifdef CONFIG_TRACE_SYSTEMTAP
> + $(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir)
> +endif

No man page being installed?  If we're planning on this binary being
available on a similar par with qemu-io, it deserves some installed
documentation.


> +++ b/docs/devel/tracing.txt
> @@ -317,6 +317,38 @@ probes:
>   --target-name x86_64 \
>   qemu.stp
>  
> +To facilitate simple usage of systemtap where there merely needs to be printf
> +logging of certain probes, a helper script "qemu-trace-stap" is provided
> +

Trailing '.' would look better

> +This can list all probes available for a given QEMU emulator binary:
> +
> + $ qemu-trace-stap list qemu-system-x86_64
> + ahci_check_irq
> + ahci_cmd_done
> + ahci_dma_prepare_buf
> + ahci_dma_prepare_buf_fail
> + ahci_dma_rw_buf
> + ahci_irq_lower
> + ...snip...
> +
> +Optionally restricted to a pattern prefix:
> +
> + $ qemu-trace-stap list qemu-system-x86_64 qio*
> + qio_channel_command_abort
> + qio_channel_command_new_pid
> + qio_channel_command_new_spawn
> + qio_channel_command_wait
> + qio_channel_file_new_fd
> + ...snip...
> +
> +It can then run a simple systemtap script which prints each requested probe

Trailing ':' would look better

> +
> + $ qemu-trace-stap run qemu-system-x86_64 qio*
> + 22806@1547735341399856820 qio_channel_socket_new Socket new 
> ioc=0x56135d1d7c00
> + 22806@1547735341399862570 qio_task_new Task new task=0x56135cd66eb0 
> source=0x56135d1d7c00 func=0x56135af746c0 opaque=0x56135bf06400
> + 22806@1547735341399865943 qio_task_thread_start Task thread start 
> task=0x56135cd66eb0 worker=0x56135af72e50 opaque=0x56135c071d70
> + 22806@1547735341399976816 qio_task_thread_run Task thread run 
> task=0x56135cd66eb0
> +

> +++ b/scripts/qemu-trace-stap

> +
> +def main():
> +parser = argparse.ArgumentParser(description="QEMU SystemTap trace tool")
> +
> +subparser = parser.add_subparsers(help="commands")
> +subparser.required = True
> +subparser.dest = "command"
> +
> +runparser = subparser.add_parser("run", help="Run a trace session",
> + 
> formatter_class=argparse.RawDescriptionHelpFormatter,
> + epilog="""
> +
> +To watch all trace points on the qemu-system-x86_64 binary:
> +
> +   %(argv0)s run qemu-system-x86_64
> +
> +To only watch the trace points matching the qio* and qcrypto* patterns
> +
> +   %(argv0)s run qemu-system-x86_64 qio* qcrypto*

This output is not copy-pastable - it includes shell globs which might
inadvertantly expand based on the contents of $PWD. Should you amend the
output to be properly quoted for reuse in shell commands?

> +""" % {"argv0": sys.argv[0]})
> +runparser.set_defaults(func=cmd_run)
> +runparser.add_argument("-v", "--verbose", help="Print verbose progress 
> info",
> +   action='store_true')
> +runparser.add_argument("binary", help="QEMU system or 

Re: [Qemu-devel] [PATCH V9 4/6] util/mmap-alloc: support MAP_SYNC in qemu_ram_mmap()

2019-01-18 Thread Eduardo Habkost
On Wed, Jan 16, 2019 at 10:58:44AM -0500, Michael S. Tsirkin wrote:
> On Wed, Jan 16, 2019 at 04:10:58PM +0800, Zhang Yi wrote:
> > When a file supporting DAX is used as vNVDIMM backend, mmap it with
> > MAP_SYNC flag in addition which can ensure file system metadata
> > synced in each guest writes to the backend file, without other QEMU
> > actions (e.g., periodic fsync() by QEMU).
> > 
> > Signed-off-by: Haozhong Zhang 
> > Signed-off-by: Zhang Yi 
> > ---
> >  include/qemu/mmap-alloc.h |  1 +
> >  include/qemu/osdep.h  | 16 
> >  util/mmap-alloc.c |  7 ++-
> >  3 files changed, 23 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
> > index 6fe6ed4..a95d91c 100644
> > --- a/include/qemu/mmap-alloc.h
> > +++ b/include/qemu/mmap-alloc.h
> > @@ -18,6 +18,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path);
> >   *  @flags: specifies additional properties of the mapping, which can be 
> > one or
> >   *  bit-or of following values
> >   *  - RAM_SHARED: mmap with MAP_SHARED flag
> > + *  - RAM_PMEM: mmap with MAP_SYNC flag
> >   *  Other bits are ignored.
> >   *
> >   * Return:
> > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> > index 457d24e..27a6bfe 100644
> > --- a/include/qemu/osdep.h
> > +++ b/include/qemu/osdep.h
> > @@ -419,6 +419,22 @@ void qemu_anon_ram_free(void *ptr, size_t size);
> >  #  define QEMU_VMALLOC_ALIGN getpagesize()
> >  #endif
> >  
> > +/*
> > + * MAP_SHARED_VALIDATE and MAP_SYNC are introduced in Linux kernel
> > + * 4.15, so they may not be defined when compiling on older kernels.
> > + */
> > +#ifdef CONFIG_LINUX
> > +
> > +#include 
> 
> I suspect this is a wrong way to pull in this header.
> 
> You are normally supposed to use
>#include 
> 
> but see below.
> 
> 
> > +
> > +#ifndef MAP_SYNC
> > +#define MAP_SYNC 0x0
> > +#endif
> 
> Oh that's bad.
> 
> So if you run with a new kernel but
> your installed headers are old, you get MAP_SYNC 0
> and no persistence transparently with no warning.

Yes. The semantics of the command-line to not change depending on
build time circumstances.

Anyway, I see a more fundamental problem in each version of this
patch: the semantics of the command-line options are not clearly
documented.

We have at least 3 different possible use cases we might need to
support:

1) pmem=on, MAP_SYNC not desired
2) pmem=on, MAP_SYNC desired but optional
3) pmem=on, MAP_SYNC required, not optional

Which cases from the list above we need to support?

>From the cases above, what's the expected semantics of "pmem=on"
with no extra options?

If these questions are not answered (in the commit message and
user documentation), we won't be able to review and discuss the
code.


> 
> > +
> > +#else  /* !CONFIG_LINUX */
> > +#define MAP_SYNC  0x0
> > +#endif /* CONFIG_LINUX */
> > +
> >  #ifdef CONFIG_POSIX
> >  struct qemu_signalfd_siginfo {
> >  uint32_t ssi_signo;   /* Signal number */
> > diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> > index 8f0a740..cba961c 100644
> > --- a/util/mmap-alloc.c
> > +++ b/util/mmap-alloc.c
> > @@ -99,6 +99,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, 
> > uint32_t flags)
> >  void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 
> > 0);
> >  #endif
> >  bool shared = flags & RAM_SHARED;
> > +bool is_pmem = flags & RAM_PMEM;
> > +int mmap_xflags = 0;
> >  size_t offset;
> >  void *ptr1;
> >  
> > @@ -109,12 +111,15 @@ void *qemu_ram_mmap(int fd, size_t size, size_t 
> > align, uint32_t flags)
> >  assert(is_power_of_2(align));
> >  /* Always align to host page size */
> >  assert(align >= getpagesize());
> > +if (shared && is_pmem) {
> > +mmap_xflags |= MAP_SYNC;
> > +}
> >  
> >  offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
> >  ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,
> >  MAP_FIXED |
> >  (fd == -1 ? MAP_ANONYMOUS : 0) |
> > -(shared ? MAP_SHARED : MAP_PRIVATE),
> > +(shared ? MAP_SHARED : MAP_PRIVATE) | mmap_xflags,
> >  fd, 0);
> >  if (ptr1 == MAP_FAILED) {
> >  munmap(ptr, total);
> > -- 
> > 2.7.4
> 

-- 
Eduardo



Re: [Qemu-devel] [PATCH v2] Fix linux-user crashes in ioctl(SIOCGIFCONF) when ifc_buf is NULL.

2019-01-18 Thread Laurent Vivier

On 18/01/2019 18:09, Peter Maydell wrote:

On Wed, 24 Oct 2018 at 22:05, Laurent Vivier  wrote:


On 24/10/2018 21:13, Kan Li wrote:

Summary:
This is to fix bug https://bugs.launchpad.net/qemu/+bug/1796754.
It is valid for ifc_buf to be NULL according to
http://man7.org/linux/man-pages/man7/netdevice.7.html.

Signed-off-by: Kan Li 
---
  linux-user/syscall.c | 55 
  1 file changed, 30 insertions(+), 25 deletions(-)



Reviewed-by: Laurent Vivier 


Hi Laurent -- did this patch get lost? It doesn't seem to have
made it into master.


Yes, thank you Peter.

It is applied now to my linux-user-for-4.0 branch.

Laurent



Re: [Qemu-devel] [PATCH v2 3/4] trace: forbid use of %m in trace event format strings

2019-01-18 Thread Eric Blake
On 1/18/19 11:31 AM, Daniel P. Berrangé wrote:
> The '%m' format specifier instructs glibc's printf() implementation to
> insert the contents of strerror(errno).

That is a glibc-only extension in printf(), but mandatory (and supported
in ALL platforms) in syslog().  However, you are correct that:

> This is not something that
> should ever be used in trace-events files because several of the
> backends do not use the format string and so this error information is
> invisible to them. The errno value should be given as an explicit
> trace argument instead. Use of '%m' should also be avoided as it is not
> portable to all QEMU build targets.

If all of our traces are compiled to syslog(), it would be portable, but
that's not the case.

What's more, using %m is subject to race conditions - the more code you
have between when the format string containing %m is given, and the
point where the actual error message is emitted, the higher the
probability that some of the intermediate code could have stomped on
errno in the meantime, rendering the logged message incorrect.  And
forcing logging wrappers to save/restore the current state of errno,
just in case they might encounter %m, can get wasteful.

Should checkpatch be taught to flag %m as suspicious?

However, tracing the errno value is NOT what %m did; I'd rather see...

> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  hw/vfio/pci.c | 2 +-
>  hw/vfio/trace-events  | 2 +-
>  scripts/tracetool/__init__.py | 4 
>  3 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index c0cb1ec289..85f1908cfe 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2581,7 +2581,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev, 
> Error **errp)
>  ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_IRQ_INFO, _info);
>  if (ret) {
>  /* This can fail for an old kernel or legacy PCI dev */
> -trace_vfio_populate_device_get_irq_info_failure();
> +trace_vfio_populate_device_get_irq_info_failure(errno);

trace_vfio_populate_device_get_irq_info_failure(strerror(errno))

>  } else if (irq_info.count == 1) {
>  vdev->pci_aer = true;
>  } else {
> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
> index a85e8662ea..6d412afc83 100644
> --- a/hw/vfio/trace-events
> +++ b/hw/vfio/trace-events
> @@ -37,7 +37,7 @@ vfio_pci_hot_reset_has_dep_devices(const char *name) "%s: 
> hot reset dependent de
>  vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, 
> int group_id) "\t%04x:%02x:%02x.%x group %d"
>  vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot 
> reset: %s"
>  vfio_populate_device_config(const char *name, unsigned long size, unsigned 
> long offset, unsigned long flags) "Device %s config:\n  size: 0x%lx, offset: 
> 0x%lx, flags: 0x%lx"
> -vfio_populate_device_get_irq_info_failure(void) "VFIO_DEVICE_GET_IRQ_INFO 
> failure: %m"
> +vfio_populate_device_get_irq_info_failure(int err) "VFIO_DEVICE_GET_IRQ_INFO 
> failure: %d"

vfio_populate_device_get_irq_info_failur(const char *err)
"VFIO_DEVICE_GET_IRQ_INFO failure: %s"

...if we are trying to match the original intent.

>  vfio_realize(const char *name, int group_id) " (%s) group %d"
>  vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d"
>  vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) 
> "%s 0x%x@0x%x"
> diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
> index 3478ac93ab..6fca674936 100644
> --- a/scripts/tracetool/__init__.py
> +++ b/scripts/tracetool/__init__.py
> @@ -274,6 +274,10 @@ class Event(object):
>  props = groups["props"].split()
>  fmt = groups["fmt"]
>  fmt_trans = groups["fmt_trans"]
> +if fmt.find("%m") != -1 or fmt_trans.find("%m") != -1:
> +raise ValueError("Event format '%m' is forbidden, pass the error 
> "
> + "as an explicit trace argument")

Whether or not checkpatch decides to flag %m as suspicious in the
overall code base, I like that you are forbidding it in trace files.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 1/4] display: ensure qxl log_buf is a nul terminated string

2019-01-18 Thread Daniel P . Berrangé
On Fri, Jan 18, 2019 at 11:40:29AM -0600, Eric Blake wrote:
> On 1/18/19 11:31 AM, Daniel P. Berrangé wrote:
> > The QXL_IO_LOG command allows the guest to send log messages to the host
> > via a buffer in the QXLRam struct. QEMU prints these to the console if
> > the qxl 'guestdebug' option is set to non-zero. It will also feed them
> > to the trace subsystem if any backends are built-in.
> > 
> > In both cases the log_buf data will get treated as being as a nul
> > terminated string, by the printf '%s' format specifier and / or other
> > code reading the buffer.
> > 
> > QEMU does nothing to guarantee that the log_buf really is nul terminated,
> > so there is potential for out of bounds array access.
> > 
> > This would affect any QEMU which has the log, syslog or ftrace trace
> > backends built into QEMU. It can only be triggered if the 'qxl_io_log'
> > trace event is enabled, however, so they are not vulnerable without
> > specific administrative action to enable this.
> > 
> > It would also affect QEMU if the 'guestdebug' parameter is set to a
> > non-zero value, which again is not the default and requires explicit
> > admin opt-in.
> > 
> > Signed-off-by: Daniel P. Berrangé 
> > ---
> >  hw/display/qxl.c| 3 ++-
> >  hw/display/trace-events | 2 +-
> >  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> Reviewed-by: Eric Blake 
> 
> > +++ b/hw/display/qxl.c
> > @@ -1763,7 +1763,8 @@ async_common:
> >  qxl_set_mode(d, val, 0);
> >  break;
> >  case QXL_IO_LOG:
> > -trace_qxl_io_log(d->id, d->ram->log_buf);
> > +d->ram->log_buf[sizeof(d->ram->log_buf) - 1] = '\0';
> 
> May lose a character from the log, but the improved safety is worth it.

In practice it won't.  The Xorg QXL driver and Windows XDDM DOD driver
don't use this feature at all. The Windows QXL miniport driver uses snprintf
when populating the buffer so will already have truncated if it was going
to overflow.

> 
> > +trace_qxl_io_log(d->id, (const char *)d->ram->log_buf);
> >  if (d->guestdebug) {
> >  fprintf(stderr, "qxl/guest-%d: %" PRId64 ": %s", d->id,
> >  qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), 
> > d->ram->log_buf);
> > diff --git a/hw/display/trace-events b/hw/display/trace-events
> > index 5a48c6cb6a..387c6b8931 100644
> > --- a/hw/display/trace-events
> > +++ b/hw/display/trace-events
> > @@ -72,7 +72,7 @@ qxl_interface_update_area_complete_rest(int qid, uint32_t 
> > num_updated_rects) "%d
> >  qxl_interface_update_area_complete_overflow(int qid, int max) "%d max=%d"
> >  qxl_interface_update_area_complete_schedule_bh(int qid, uint32_t 
> > num_dirty) "%d #dirty=%d"
> >  qxl_io_destroy_primary_ignored(int qid, const char *mode) "%d %s"
> > -qxl_io_log(int qid, const uint8_t *log_buf) "%d %s"
> > +qxl_io_log(int qid, const char *log_buf) "%d %s"
> >  qxl_io_read_unexpected(int qid) "%d"
> >  qxl_io_unexpected_vga_mode(int qid, uint64_t addr, uint64_t val, const 
> > char *desc) "%d 0x%"PRIx64"=%"PRIu64" (%s)"
> >  qxl_io_write(int qid, const char *mode, uint64_t addr, const char *aname, 
> > uint64_t val, unsigned size, int async) "%d %s addr=%"PRIu64 " (%s) 
> > val=%"PRIu64" size=%u async=%d"
> > 
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3226
> Virtualization:  qemu.org | libvirt.org
> 




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: [Qemu-devel] [PULL 0/7] check-softfloat, fp-bench and clang compile fixes

2019-01-18 Thread Peter Maydell
On Fri, 18 Jan 2019 at 17:41, Alex Bennée  wrote:
>
>
> Emilio G. Cota  writes:
>
> > On Thu, Jan 17, 2019 at 18:55:33 +, Peter Maydell wrote:
> >> configure has logic to check whether it can use particular
> >> warning enable/disable flags. Newer gcc (and I hope clang
> >> but forget) will happily silently allow -Wno-random-new-thing
> >> even if they don't support -Wrandom-new-thing) but I'm not
> >> sure our minimum compiler version is yet new enough to
> >> be able to rely on that (indeed the warning messages suggest
> >> it is not).
> >
> > I figured that -Wno-unitialized is documented to work on both
> > gcc and clang, and the change in testfloat drops the need
> > for no-discarded-qualifiers, so we can go with this without
> > messing with configure.
>
> Works for me, OK with you Peter?

If it builds on all the build machines it's ok. If it doesn't
I'll bounce the pullreq and you can figure out a different
approach :-)

thanks
-- PMM



Re: [Qemu-devel] [PULL 0/7] check-softfloat, fp-bench and clang compile fixes

2019-01-18 Thread Alex Bennée


Emilio G. Cota  writes:

> On Thu, Jan 17, 2019 at 18:55:33 +, Peter Maydell wrote:
>> On Thu, 17 Jan 2019 at 18:30, Emilio G. Cota  wrote:
>> > What are the contents of "int-to-float.err"?
>>
>> linux1@lxub05:~$ cat qemu/build/all/tests/fp/int-to-float.err
>> >> Testing i32_to_f16, rounding near_even
>> 372 tests total.
>> 372 tests performed.
>> >> Testing i64_to_f16, rounding near_even
>> 756 tests total.
>> 756 tests performed.
>> >> Testing i32_to_f32, rounding near_even
>> 372 tests total.
>> 372 tests performed.
>> >> Testing i64_to_f32, rounding near_even
>> 756 tests total.
>> 756 tests performed.
>> >> Testing i32_to_f64
>> 372 tests total.
>> 372 tests performed.
>> >> Testing i64_to_f64, rounding near_even
>> 756 tests total.
>> 756 tests performed.
>> >> Testing i32_to_f128
>> 372 tests total.
>> 21 tests performed; 20 errors found.
>
> I see, so i32_to_f128 is failing on this host. Is there
> a s390x machine I could access? I don't see one in the
> gcc compile farm.

I've managed to reproduce this in a s390x VM, for Debian install runes:

  
https://wiki.qemu.org/Documentation/Platforms/S390X#Debian_Install_Example_.28TCG.29

>
>> > diff --git a/tests/fp/Makefile b/tests/fp/Makefile
>> > index 5019dcdca0..5a35e7c210 100644
>> > --- a/tests/fp/Makefile
>> > +++ b/tests/fp/Makefile
>> > @@ -65,8 +65,7 @@ QEMU_CFLAGS += $(TF_OPTS)
>> >  TF_CFLAGS :=
>> >  TF_CFLAGS += -Wno-strict-prototypes
>> >  TF_CFLAGS += -Wno-unknown-pragmas
>> > -TF_CFLAGS += -Wno-discarded-qualifiers
>> > -TF_CFLAGS += -Wno-maybe-uninitialized
>> > +TF_CFLAGS += -Wno-uninitialized
>> >  TF_CFLAGS += -Wno-missing-prototypes
>> >  TF_CFLAGS += -Wno-return-type
>> >  TF_CFLAGS += -Wno-unused-function
>>
>> configure has logic to check whether it can use particular
>> warning enable/disable flags. Newer gcc (and I hope clang
>> but forget) will happily silently allow -Wno-random-new-thing
>> even if they don't support -Wrandom-new-thing) but I'm not
>> sure our minimum compiler version is yet new enough to
>> be able to rely on that (indeed the warning messages suggest
>> it is not).
>
> I figured that -Wno-unitialized is documented to work on both
> gcc and clang, and the change in testfloat drops the need
> for no-discarded-qualifiers, so we can go with this without
> messing with configure.

Works for me, OK with you Peter?

--
Alex Bennée



Re: [Qemu-devel] [PATCH v2 2/4] trace: enforce that every trace-events file has a final newline

2019-01-18 Thread Eric Blake
On 1/18/19 11:31 AM, Daniel P. Berrangé wrote:
> When generating the trace-events-all file, the build system simply
> concatenates all the individual trace-events files. If any one of those
> files does not have a final newline, the printf format string will have
> the contents of the first line of the next file appended to it, which is
> usually a '#' comment.
> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  hw/gpio/trace-events  | 2 +-
>  scripts/tracetool/__init__.py | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake 

Does checkpatch and/or patchew flag what are intended to be text files
but which lack a trailing newline?  If not, how hard would it be to get
them to do so?

> diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events
> index cb41a89756..5d4dd200c2 100644
> --- a/hw/gpio/trace-events
> +++ b/hw/gpio/trace-events
> @@ -4,4 +4,4 @@
>  nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 
> 0x%" PRIx64
>  nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " 
> value 0x%" PRIx64
>  nrf51_gpio_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64
> -nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " 
> value %" PRIi64
> \ No newline at end of file
> +nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " 
> value %" PRIi64
> diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py

Fixes the problem file...

> index 0e3c9e146c..3478ac93ab 100644
> --- a/scripts/tracetool/__init__.py
> +++ b/scripts/tracetool/__init__.py
> @@ -350,6 +350,8 @@ def read_events(fobj, fname):
>  
>  events = []
>  for lineno, line in enumerate(fobj, 1):
> +if line[-1] != '\n':
> +raise ValueError("%s does not end with a new line" % fname)

and ensures that no future trace-events files will have the problem,
whether or not checkpatch flags other such files.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 1/4] display: ensure qxl log_buf is a nul terminated string

2019-01-18 Thread Eric Blake
On 1/18/19 11:31 AM, Daniel P. Berrangé wrote:
> The QXL_IO_LOG command allows the guest to send log messages to the host
> via a buffer in the QXLRam struct. QEMU prints these to the console if
> the qxl 'guestdebug' option is set to non-zero. It will also feed them
> to the trace subsystem if any backends are built-in.
> 
> In both cases the log_buf data will get treated as being as a nul
> terminated string, by the printf '%s' format specifier and / or other
> code reading the buffer.
> 
> QEMU does nothing to guarantee that the log_buf really is nul terminated,
> so there is potential for out of bounds array access.
> 
> This would affect any QEMU which has the log, syslog or ftrace trace
> backends built into QEMU. It can only be triggered if the 'qxl_io_log'
> trace event is enabled, however, so they are not vulnerable without
> specific administrative action to enable this.
> 
> It would also affect QEMU if the 'guestdebug' parameter is set to a
> non-zero value, which again is not the default and requires explicit
> admin opt-in.
> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  hw/display/qxl.c| 3 ++-
>  hw/display/trace-events | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Eric Blake 

> +++ b/hw/display/qxl.c
> @@ -1763,7 +1763,8 @@ async_common:
>  qxl_set_mode(d, val, 0);
>  break;
>  case QXL_IO_LOG:
> -trace_qxl_io_log(d->id, d->ram->log_buf);
> +d->ram->log_buf[sizeof(d->ram->log_buf) - 1] = '\0';

May lose a character from the log, but the improved safety is worth it.

> +trace_qxl_io_log(d->id, (const char *)d->ram->log_buf);
>  if (d->guestdebug) {
>  fprintf(stderr, "qxl/guest-%d: %" PRId64 ": %s", d->id,
>  qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), d->ram->log_buf);
> diff --git a/hw/display/trace-events b/hw/display/trace-events
> index 5a48c6cb6a..387c6b8931 100644
> --- a/hw/display/trace-events
> +++ b/hw/display/trace-events
> @@ -72,7 +72,7 @@ qxl_interface_update_area_complete_rest(int qid, uint32_t 
> num_updated_rects) "%d
>  qxl_interface_update_area_complete_overflow(int qid, int max) "%d max=%d"
>  qxl_interface_update_area_complete_schedule_bh(int qid, uint32_t num_dirty) 
> "%d #dirty=%d"
>  qxl_io_destroy_primary_ignored(int qid, const char *mode) "%d %s"
> -qxl_io_log(int qid, const uint8_t *log_buf) "%d %s"
> +qxl_io_log(int qid, const char *log_buf) "%d %s"
>  qxl_io_read_unexpected(int qid) "%d"
>  qxl_io_unexpected_vga_mode(int qid, uint64_t addr, uint64_t val, const char 
> *desc) "%d 0x%"PRIx64"=%"PRIu64" (%s)"
>  qxl_io_write(int qid, const char *mode, uint64_t addr, const char *aname, 
> uint64_t val, unsigned size, int async) "%d %s addr=%"PRIu64 " (%s) 
> val=%"PRIu64" size=%u async=%d"
> 

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH V9 1/6] numa: Fixed the memory leak of numa error message

2019-01-18 Thread Eduardo Habkost
On Wed, Jan 16, 2019 at 10:56:14AM -0500, Michael S. Tsirkin wrote:
> On Wed, Jan 16, 2019 at 04:10:17PM +0800, Zhang Yi wrote:
> > object_get_canonical_path_component() returns a string which
> > must be freed using g_free().
> > 
> > Signed-off-by: Zhang Yi 
> > Reviewed-by: Pankaj gupta 
> > Reviewed-by: Igor Mammedov 
> > Reviewed-by: Eduardo Habkost 
> 
> Reviewed-by: Michael S. Tsirkin 
> 
> Pls post this separately as it's just a bugfix that
> is not a dependency of map_sync.

I have already queued it on machine-next, there's no need to
resubmit.

-- 
Eduardo



[Qemu-devel] [Bug 1801073] Re: util/zbin.c:390:37: error: absolute value function 'abs' given an argument of type 'long int' but has parameter of type 'int' which may cause truncation of value [-Werro

2019-01-18 Thread Peter Maydell
This bug would be better reported to the upstream for the ipxe rom -- we
just ship the source code because we ship the binary.

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

Title:
  util/zbin.c:390:37: error: absolute value function 'abs' given an
  argument of type 'long int' but has parameter of type 'int' which may
  cause truncation of value [-Werror=absolute-value]

Status in QEMU:
  New

Bug description:
  For qemu-3.0.0 I see with GCC 9 compiler a new warning:

  $ make -j1 -C roms pxerom VERBOSE=1 V=1
  make: Entering directory '/home/abuild/rpmbuild/BUILD/qemu-3.0.0/roms'
  make -C ipxe/src CONFIG=qemu \
PACKAGING_TIMESTAMP=1534273834 \
CROSS_COMPILE= \
bin/8086100e.rom bin/808610d3.rom bin/80861209.rom bin/10500940.rom 
bin/10222000.rom bin/10ec8139.rom bin/1af41000.rom bin/15ad07b0.rom
  make[1]: Entering directory 
'/home/abuild/rpmbuild/BUILD/qemu-3.0.0/roms/ipxe/src'
  gcc  -Wall -W -Wformat-nonliteral -O2 -g -Werror util/zbin.c -llzma -o 
util/zbin
  util/zbin.c: In function 'process_zinfo_add':
  util/zbin.c:390:37: error: absolute value function 'abs' given an argument of 
type 'long int' but has parameter of type 'int' which may cause truncation of 
value [-Werror=absolute-value]
390 |  ( ( addend < 0 ) ? "-" : "" ), abs ( addend ), size,
| ^~~
  util/zbin.c:398:37: error: absolute value function 'abs' given an argument of 
type 'long int' but has parameter of type 'int' which may cause truncation of 
value [-Werror=absolute-value]
398 |  ( ( addend < 0 ) ? "-" : "" ), abs ( addend ), size,
| ^~~
  util/zbin.c:419:37: error: absolute value function 'abs' given an argument of 
type 'long int' but has parameter of type 'int' which may cause truncation of 
value [-Werror=absolute-value]
419 |  ( ( addend < 0 ) ? "-" : "" ), abs ( addend ),
| ^~~
  cc1: all warnings being treated as errors
  make[1]: *** [Makefile.housekeeping:1368: util/zbin] Error 1

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



Re: [Qemu-devel] [PATCH] target/s390x: define TCG_GUEST_DEFAULT_MO for MTTCG

2019-01-18 Thread David Hildenbrand
On 18.01.19 18:18, Alex Bennée wrote:
> MTTCG should be enabled by default whenever the memory model allows
> it. s390x was missing its definition of TCG_GUEST_DEFAULT_MO meaning
> the user had to manually specify  --accel tcg,thread=multi.
> 
> Signed-off-by: Alex Bennée 
> Cc: David Hildenbrand 
> ---
>  target/s390x/cpu.h | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
> index 8c2320e882..47d2c2e9cf 100644
> --- a/target/s390x/cpu.h
> +++ b/target/s390x/cpu.h
> @@ -35,6 +35,10 @@
>  #define CPUArchState struct CPUS390XState
>  
>  #include "exec/cpu-defs.h"
> +
> +/* The z/Architecture has a strong memory model with some store-after-load 
> re-ordering */
> +#define TCG_GUEST_DEFAULT_MO  (TCG_MO_ALL & ~TCG_MO_ST_LD)

Didn't know this was the way to make it be enabled as default.

As discussed on IRC

Reviewed-by: David Hildenbrand 

Thanks!

> +
>  #define TARGET_PAGE_BITS 12
>  
>  #define TARGET_PHYS_ADDR_SPACE_BITS 64
> 


-- 

Thanks,

David / dhildenb



[Qemu-devel] [PATCH v2 3/4] trace: forbid use of %m in trace event format strings

2019-01-18 Thread Daniel P . Berrangé
The '%m' format specifier instructs glibc's printf() implementation to
insert the contents of strerror(errno). This is not something that
should ever be used in trace-events files because several of the
backends do not use the format string and so this error information is
invisible to them. The errno value should be given as an explicit
trace argument instead. Use of '%m' should also be avoided as it is not
portable to all QEMU build targets.

Signed-off-by: Daniel P. Berrangé 
---
 hw/vfio/pci.c | 2 +-
 hw/vfio/trace-events  | 2 +-
 scripts/tracetool/__init__.py | 4 
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index c0cb1ec289..85f1908cfe 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2581,7 +2581,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev, 
Error **errp)
 ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_IRQ_INFO, _info);
 if (ret) {
 /* This can fail for an old kernel or legacy PCI dev */
-trace_vfio_populate_device_get_irq_info_failure();
+trace_vfio_populate_device_get_irq_info_failure(errno);
 } else if (irq_info.count == 1) {
 vdev->pci_aer = true;
 } else {
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index a85e8662ea..6d412afc83 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -37,7 +37,7 @@ vfio_pci_hot_reset_has_dep_devices(const char *name) "%s: hot 
reset dependent de
 vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, 
int group_id) "\t%04x:%02x:%02x.%x group %d"
 vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot reset: 
%s"
 vfio_populate_device_config(const char *name, unsigned long size, unsigned 
long offset, unsigned long flags) "Device %s config:\n  size: 0x%lx, offset: 
0x%lx, flags: 0x%lx"
-vfio_populate_device_get_irq_info_failure(void) "VFIO_DEVICE_GET_IRQ_INFO 
failure: %m"
+vfio_populate_device_get_irq_info_failure(int err) "VFIO_DEVICE_GET_IRQ_INFO 
failure: %d"
 vfio_realize(const char *name, int group_id) " (%s) group %d"
 vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d"
 vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) "%s 
0x%x@0x%x"
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 3478ac93ab..6fca674936 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -274,6 +274,10 @@ class Event(object):
 props = groups["props"].split()
 fmt = groups["fmt"]
 fmt_trans = groups["fmt_trans"]
+if fmt.find("%m") != -1 or fmt_trans.find("%m") != -1:
+raise ValueError("Event format '%m' is forbidden, pass the error "
+ "as an explicit trace argument")
+
 if len(fmt_trans) > 0:
 fmt = [fmt_trans, fmt]
 args = Arguments.build(groups["args"])
-- 
2.20.1




[Qemu-devel] [Bug 1798659] Re: Replace comma with semicolon in trace/simple.c

2019-01-18 Thread Peter Maydell
Fixed in commit 7ff5920717d413d8b7c3ba13d9, which will be in the
upcoming 4.0 release.


** Changed in: qemu
   Status: New => Fix Committed

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

Title:
  Replace comma with semicolon in trace/simple.c

Status in QEMU:
  Fix Committed

Bug description:
  In the master branch in trace/simple.c in writeout_thread 
(https://github.com/qemu/qemu/blob/master/trace/simple.c#L174) we currently 
have:
dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t),
dropped.rec.pid = trace_pid;

  It seems to me like a typo that the first line ends with a comma.
  Currently this causes no harm, but I think this should be fixed.

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



Re: [Qemu-devel] [PATCH v2 4/4] hw/i386/pc: use PVH option rom

2019-01-18 Thread Eduardo Habkost
On Tue, Jan 15, 2019 at 01:57:22PM -0500, Michael S. Tsirkin wrote:
> On Tue, Jan 15, 2019 at 11:00:58AM +0100, Stefano Garzarella wrote:
> > Use pvh.bin option rom when we are booting an uncompressed
> > kernel using the x86/HVM direct boot ABI.
> > 
> > Signed-off-by: Stefano Garzarella 
> > Based-on: <1545422632-2-5-git-send-email-liam.merw...@oracle.com>
> 
> I don't think this is a great way to give attribution.
> Can you pls include the author name and the S.O.B from there as well?
> 
> 
> > ---
> >  hw/i386/pc.c | 5 +
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > index 06bce6a101..7564ba51d2 100644
> > --- a/hw/i386/pc.c
> > +++ b/hw/i386/pc.c
> > @@ -1005,6 +1005,10 @@ static void load_linux(PCMachineState *pcms,
> >  fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA,
> >   header, sizeof(header));
> >  
> > +option_rom[nb_option_roms].bootindex = 0;
> > +option_rom[nb_option_roms].name = "pvh.bin";
> > +nb_option_roms++;
> > +
> >  return;
> >  }
> >  /* This looks like a multiboot kernel. If it is, let's stop
> > @@ -1456,6 +1460,7 @@ void xen_load_linux(PCMachineState *pcms)
> >  for (i = 0; i < nb_option_roms; i++) {
> >  assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
> > !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
> > +   !strcmp(option_rom[i].name, "pvh.bin") ||
> > !strcmp(option_rom[i].name, "multiboot.bin"));
> >  rom_add_option(option_rom[i].name, option_rom[i].bootindex);
> >  }
> 
> OK but this is guest visible so needs to be guarded by the
> new machine type.

Aren't option ROMs treated like other firmware?  i.e.: guest
visible, but copied during live migration and not considered part
of guest ABI.

-- 
Eduardo



[Qemu-devel] [PATCH v2 0/4] trace: make systemtap easier to use for simple logging

2019-01-18 Thread Daniel P . Berrangé
This is a followup to

 v1: https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg04173.html

Changed in v2:

 - Fix safety of QXL logging
 - Handle format specifier macros is a more reliable manner
 - Fix trace-events files missing newline
 - Remove use of %m formats

Daniel P. Berrangé (4):
  display: ensure qxl log_buf is a nul terminated string
  trace: enforce that every trace-events file has a final newline
  trace: forbid use of %m in trace event format strings
  trace: add ability to do simple printf logging via systemtap

 Makefile |   3 +
 Makefile.target  |  11 +-
 docs/devel/tracing.txt   |  32 +
 hw/display/qxl.c |   3 +-
 hw/display/trace-events  |   2 +-
 hw/gpio/trace-events |   2 +-
 hw/vfio/pci.c|   2 +-
 hw/vfio/trace-events |   2 +-
 scripts/qemu-trace-stap  | 167 +++
 scripts/tracetool/__init__.py|   6 +
 scripts/tracetool/format/log_stap.py | 127 
 11 files changed, 351 insertions(+), 6 deletions(-)
 create mode 100755 scripts/qemu-trace-stap
 create mode 100644 scripts/tracetool/format/log_stap.py

-- 
2.20.1




[Qemu-devel] [PATCH v2 2/4] trace: enforce that every trace-events file has a final newline

2019-01-18 Thread Daniel P . Berrangé
When generating the trace-events-all file, the build system simply
concatenates all the individual trace-events files. If any one of those
files does not have a final newline, the printf format string will have
the contents of the first line of the next file appended to it, which is
usually a '#' comment.

Signed-off-by: Daniel P. Berrangé 
---
 hw/gpio/trace-events  | 2 +-
 scripts/tracetool/__init__.py | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events
index cb41a89756..5d4dd200c2 100644
--- a/hw/gpio/trace-events
+++ b/hw/gpio/trace-events
@@ -4,4 +4,4 @@
 nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" 
PRIx64
 nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 
0x%" PRIx64
 nrf51_gpio_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64
-nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " 
value %" PRIi64
\ No newline at end of file
+nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " 
value %" PRIi64
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 0e3c9e146c..3478ac93ab 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -350,6 +350,8 @@ def read_events(fobj, fname):
 
 events = []
 for lineno, line in enumerate(fobj, 1):
+if line[-1] != '\n':
+raise ValueError("%s does not end with a new line" % fname)
 if not line.strip():
 continue
 if line.lstrip().startswith('#'):
-- 
2.20.1




  1   2   3   4   5   >