Re: [Qemu-devel] [Qemu-ppc] [PULL 0/4] ppc patches for qemu-2.7 stable branch

2016-10-17 Thread Thomas Huth
On 14.10.2016 19:38, Peter Maydell wrote:
> On 14 October 2016 at 09:27, Greg Kurz  wrote:
>> On Fri, 14 Oct 2016 09:28:35 +1100
>> David Gibson  wrote:
>>
>>> On Thu, Oct 13, 2016 at 12:57:19PM +0100, Peter Maydell wrote:
 On 13 October 2016 at 12:54, Peter Maydell  
 wrote:
 More generally, we need to come up with something for distinguishing
 PULL requests not for master, because my current workflow basically
 says "anything that says 'for you to fetch changes up to' will get
 merged into master...
>>>
>>> Um.. yes.. this was intended for merge to the 2.7 branch, not master.
>>> Any ideas how I should express that?
>>>
>>
>> I'm not aware of any formal process, other than sending a mail to
>> qemu-stable and Cc: Michael Roth. This is often done by simply
>> replying to selected messages in the pull requests for the master
>> branch.
>>
>> Then Michael does all the cherry picking stuff and usually sends a
>> patch round-up two weeks before the stable release, for people to
>> review.
> 
> Yes, I think I was partly thrown because in general patches
> don't go into the stable branches via pull requests.
> That said, my current filter/workflow is clearly broken
> so I'm open to any suggestions for easy-for-me-to-filter-for
> ways to flag up that a pull request isn't aimed at master.

Maybe simply filter out the requests that include qemu-stable in "To:" ?

 Thomas




Re: [Qemu-devel] [PATCH 02/18] blockjob: introduce .drain callback for jobs

2016-10-17 Thread Paolo Bonzini


On 16/10/2016 12:02, Stefan Hajnoczi wrote:
> On Thu, Oct 13, 2016 at 07:34:06PM +0200, Paolo Bonzini wrote:
>> +static void backup_drain(BlockJob *job)
>> +{
>> +BackupBlockJob *s = container_of(job, BackupBlockJob, common);
>> +
>> +/* Need to keep a reference in case blk_drain triggers execution
>> + * of backup_complete...
>> + */
>> +if (s->target) {
>> +blk_ref(s->target);
>> +blk_drain(s->target);
>> +blk_unref(s->target);
>> +}
> [...]
>> @@ -331,6 +346,7 @@ static void backup_complete(BlockJob *job, void *opaque)
>>  BackupCompleteData *data = opaque;
>>  
>>  blk_unref(s->target);
>> +s->target = NULL;
> 
> Will blk_unref(s->target) segfault since backup_complete() has set it to
> NULL?  I expected backup_drain() to stash the pointer in a local
> variable to avoid using s->target.

Yes, indeed.

Paolo



Re: [Qemu-devel] [PATCH 07/18] block: introduce bdrv_poll_while and bdrv_wakeup

2016-10-17 Thread Paolo Bonzini


On 16/10/2016 12:25, Stefan Hajnoczi wrote:
> On Thu, Oct 13, 2016 at 07:34:11PM +0200, Paolo Bonzini wrote:
>> @@ -485,9 +474,14 @@ void bdrv_inc_in_flight(BlockDriverState *bs)
>>  atomic_inc(&bs->in_flight);
>>  }
>>  
>> +void bdrv_wakeup(BlockDriverState *bs)
>> +{
>> +}
> 
> Please write a doc comment explaining the semantics of this new API.
> 
> Since it's a nop here it may be better to introduce bdrv_wakeup() in
> another patch.

Okay, will do.

Paolo



Re: [Qemu-devel] [PATCH 15/18] block: only call aio_poll on the current thread's AioContext

2016-10-17 Thread Paolo Bonzini


On 16/10/2016 18:40, Stefan Hajnoczi wrote:
> >  void bdrv_wakeup(BlockDriverState *bs)
> >  {
> > +if (bs->wakeup) {
> > +aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL);
> > +}
> >  }
> 
> Why use a dummy BH instead of aio_notify()?

Originally I used aio_bh_schedule_oneshot() because aio_notify() is not
enough for aio_poll() to return true.  It's also true that I am not
using anymore the result of aio_poll, though.

Since this is not a fast path and it's not very much stressed by
qemu-iotests, I think it's better if we can move towards making
aio_notify() more or less an internal detail.  If you prefer
aio_notify(), however, I can look into that as well.

Thanks,

Paolo

>> >  void bdrv_dec_in_flight(BlockDriverState *bs)
>> > diff --git a/include/block/block.h b/include/block/block.h
>> > index ba4318b..72d5d8e 100644
>> > --- a/include/block/block.h
>> > +++ b/include/block/block.h
>> > @@ -343,9 +343,27 @@ void bdrv_drain_all(void);
>> >  #define bdrv_poll_while(bs, cond) ({   \
>> >  bool waited_ = false;  \
>> >  BlockDriverState *bs_ = (bs);  \
>> > -while ((cond)) {   \
>> > -aio_poll(bdrv_get_aio_context(bs_), true); \
>> > -waited_ = true;\
>> > +AioContext *ctx_ = bdrv_get_aio_context(bs_);  \
>> > +if (aio_context_in_iothread(ctx_)) {   \
>> > +while ((cond)) {   \
>> > +aio_poll(ctx_, true);  \
>> > +waited_ = true;\
>> > +}  \
>> > +} else {   \
>> > +assert(qemu_get_current_aio_context() ==   \
>> > +   qemu_get_aio_context());\
> The assumption is that IOThread #1 will never call bdrv_poll_while() on
> IOThread #2's AioContext.  I believe that is true today.  Is this what
> you had in mind?
> 
> Please add a comment since it's not completely obvious from the assert
> expression.
> 



Re: [Qemu-devel] [PATCH v4 10/20] ppc/xics: Make the ICSState a list

2016-10-17 Thread Cédric Le Goater
On 10/17/2016 01:53 AM, David Gibson wrote:
> On Fri, Oct 14, 2016 at 09:35:46AM +0200, Cédric Le Goater wrote:
>> On 10/14/2016 07:32 AM, David Gibson wrote:
>>> On Mon, Oct 03, 2016 at 09:24:46AM +0200, Cédric Le Goater wrote:
 From: Benjamin Herrenschmidt 

 Instead of an array of fixed sized blocks, use a list, as we will need
 to have sources with variable number of interrupts. SPAPR only uses
 a single entry. Native will create more. If performance becomes an
 issue we can add some hashed lookup but for now this will do fine.

 Signed-off-by: Benjamin Herrenschmidt 
 [ move the initialization of list to xics_common_initfn,
   restore xirr_owner after migration and move restoring to
   icp_post_load]
 Signed-off-by: Nikunj A Dadhania 
 [ clg: removed the icp_post_load() changes from nikunj patchset v3:
http://patchwork.ozlabs.org/patch/646008/ ]
 Signed-off-by: Cédric Le Goater 
>>>
>>> I think this and 11/20 are good enough and sufficiently standalone
>>> that I've merged them into ppc-for-2.8.
>>
>> These are a prereq for the patchset.
> 
> Sorry, I wasn't clear.  I realize they're prerequisites for the rest
> of the patchset.  What I meant is that they don't require the rest of
> the patchset to apply themselves, and they make some sense even
> without the rest of the series.

OK. I think there are a couple more cleanups we could do because the 
initialization is bit difficult to track. The way the ICPs are allocated 
is bit curious. I hope to have sometime for that after xics native is
merged.

I have made some migration tests on power8 tcg and kvm, we should be
fine.

Thanks,

C.
 




Re: [Qemu-devel] [PATCH v6 00/35] cmpxchg-based emulation of atomics

2016-10-17 Thread Alex Bennée

Emilio G. Cota  writes:

> On Tue, Oct 11, 2016 at 14:40:26 -0500, Richard Henderson wrote:
>> Sixth time is the charm, right?  This time I'm certain that it
>> compiles with centos6, and contains the previously missing update
>> from Emilio to atomic_add-bench.
>
> For patches 03-16 (including the elusive patch 06 for which I reviewed 
> 1bfe0cdf8
> from your atomic-4 branch on github):
>
>   Reviewed-by: Emilio G. Cota 
>
> I just tested the patchset by running concurrencykit's ck_pr regression test 
> (which
> tests lock'ed ops) for [guest-on-host bits, all x86] 64-on-64, 32-on-32 and
> 64-on-32. I ran it with TCG debugging enabled. It passes all tests.

How odd, did you not see the double temp free for target-arm/translate.c?

>
> I also checked (on x86_64 for several target architectures) that all patches
> build OK.
>
> Thanks,
>
>   Emilio


--
Alex Bennée



Re: [Qemu-devel] [PATCH v4 17/20] ppc/pnv: Add cut down PSI bridge model and hookup external interrupt

2016-10-17 Thread Cédric Le Goater
On 10/17/2016 01:52 AM, David Gibson wrote:
> On Fri, Oct 14, 2016 at 10:07:53AM +0200, Cédric Le Goater wrote:
 --- a/hw/ppc/pnv.c
 +++ b/hw/ppc/pnv.c
 @@ -318,15 +318,24 @@ static void ppc_powernv_reset(void)
   * have a CPLD that will collect the SerIRQ and shoot them as a
   * single level interrupt to the P8 chip. So let's setup a hook
   * for doing just that.
 - *
 - * Note: The actual interrupt input isn't emulated yet, this will
 - * come with the PSI bridge model.
   */
  static void pnv_lpc_isa_irq_handler_cpld(void *opaque, int n, int level)
  {
 -/* We don't yet emulate the PSI bridge which provides the external
 - * interrupt, so just drop interrupts on the floor
 - */
 +static uint32_t irqstate;
>>>
>>> Hmm.. static local with important state?  That it's not clear whether
>>> it should be per-chip or not?
>>>
>>> I'm not averse to hacks for early bringup, but it should at least have
>>> a FIXME comment on it.
>>
>> yes. I will see if I can make a "irq_cpld' attribute of the chip instead. 
>> It should be cleaner.
> 
> Wouldn't it be in the machine, not the chip?  IIUC there's only one
> CPLD on the whole board.

yes. You are right, it is a board device.

C.




Re: [Qemu-devel] Provide safe_syscall for s390x

2016-10-17 Thread Thomas Huth
On 14.10.2016 20:58, Michael Tokarev wrote:
> Hi.
> 
> This commit: c9bc3437a905b660561a26cd4ecc64579843267b
> Author: Richard Henderson 
> Date:   Tue Jun 21 17:32:12 2016 -0700
> 
> linux-user: Provide safe_syscall for s390x
> 
> does not build on debian unstable porterbox for s390x, with
> the following error message:
> 
> linux-user/host/s390x/safe-syscall.inc.S: Assembler messages:
> linux-user/host/s390x/safe-syscall.inc.S:75: Error: Unrecognized opcode:
> `lt'
> rules.mak:72: recipe for target 'linux-user/safe-syscall.o' failed
> 
> Since I know nothing about s390, I've no idea what's at fault
> here... :)  Thought I'd report this :)

"lt" seems to be a newer s390x opcode which has been added to the
architecture within the last ten years or so. So maybe you've got to add
some "-march=xxx" flag when compiling this file?
Could you maybe start with finding out the exact comand line that is
used to compile this file?

 Thomas




Re: [Qemu-devel] [PATCH] include/qemu: Add documentation to functions in include/qemu/id.h

2016-10-17 Thread Paolo Bonzini


On 16/10/2016 23:03, Veronia Bahaa wrote:
> Add documentation to the functions id_generate and id_wellformed in 
> include/qemu/id.h
> 
> Signed-off-by: Veronia Bahaa 
> ---
>  include/qemu/id.h |   23 +++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/include/qemu/id.h b/include/qemu/id.h
> index 40c7010..7bbcdc0 100644
> --- a/include/qemu/id.h
> +++ b/include/qemu/id.h
> @@ -7,7 +7,30 @@ typedef enum IdSubSystems {
>  ID_MAX  /* last element, used as array size */
>  } IdSubSystems;
>  
> +/**
> + * id_generate: Generates an ID of the form PREFIX SUBSYSTEM NUMBER
> + *  where:
> + *
> + *  - PREFIX is the reserved character '#'
> + *  - SUBSYSTEM identifies the subsystem creating the ID
> + *  - NUMBER is a decimal number unique within SUBSYSTEM.
> + *
> + *Example: "#block146"
> + *
> + * Returns the generated id string for the subsystem
> + *
> + * @id: the subsystem to generate an id for
> + */
>  char *id_generate(IdSubSystems id);
> +
> +/**
> + * id_wellformed: checks that an id starts with a letter
> + *  followed by numbers, digits, '-','.', or '_'
> + *
> + * Returns %true if the id is well-formed
> + *
> + * @id: the id to be checked
> + */
>  bool id_wellformed(const char *id);
>  
>  #endif
> 

Queued, thanks.

Paolo



Re: [Qemu-devel] [PATCH v4 09/12] iotests.py: Add qemu_nbd function

2016-10-17 Thread Kevin Wolf
Am 15.10.2016 um 19:17 hat Max Reitz geschrieben:
> On 13.10.2016 15:11, Kevin Wolf wrote:
> > Am 28.09.2016 um 22:55 hat Max Reitz geschrieben:
> >> Signed-off-by: Max Reitz 
> >> ---
> >>  tests/qemu-iotests/iotests.py | 8 
> >>  1 file changed, 8 insertions(+)
> >>
> >> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> >> index 3329bc1..5a2678f 100644
> >> --- a/tests/qemu-iotests/iotests.py
> >> +++ b/tests/qemu-iotests/iotests.py
> >> @@ -39,6 +39,10 @@ qemu_io_args = [os.environ.get('QEMU_IO_PROG', 
> >> 'qemu-io')]
> >>  if os.environ.get('QEMU_IO_OPTIONS'):
> >>  qemu_io_args += os.environ['QEMU_IO_OPTIONS'].strip().split(' ')
> >>  
> >> +qemu_nbd_args = [os.environ.get('QEMU_NBD_PROG', 'qemu-nbd')]
> >> +if os.environ.get('QEMU_NBD_OPTIONS'):
> >> +qemu_nbd_args += os.environ['QEMU_NBD_OPTIONS'].strip().split(' ')
> >> +
> >>  qemu_prog = os.environ.get('QEMU_PROG', 'qemu')
> >>  qemu_opts = os.environ.get('QEMU_OPTIONS', '').strip().split(' ')
> >>  
> >> @@ -87,6 +91,10 @@ def qemu_io(*args):
> >>  sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, 
> >> ' '.join(args)))
> >>  return subp.communicate()[0]
> >>  
> >> +def qemu_nbd(*args):
> >> +'''Run qemu-nbd in daemon mode and return the parent's exit code'''
> >> +return subprocess.call(qemu_nbd_args + ['--fork'] + list(args))
> > 
> > Wouldn't it be better to always use -t, track the PID and shut it down
> > explicitly when the test exits?
> 
> Probably. It's a lot more complicated, though. I'll see what I can do
> but I'm not sure if I can do a lot before 2.8.

In that case, I'd prefer to have this series in 2.8 and improve the test
case later, so don't let this stop you from sending the next version.

Kevin


pgp8A61pE8O8U.pgp
Description: PGP signature


Re: [Qemu-devel] bug introduced by "block: Move throttling fields from BDS to BB"

2016-10-17 Thread Alberto Garcia
On Fri 14 Oct 2016 04:11:46 PM CEST, Paolo Bonzini wrote:
> Here is next_throttle_token:
>
> -ThrottleGroup *tg = container_of(blk_bs(blk)->throttle_state,
> - ThrottleGroup, ts);
> +BlockBackendPublic *blkp = blk_get_public(blk);
> +ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, 
> ts);
>  BlockBackend *token, *start;
>  
>  start = token = tg->tokens[is_write];
>  
>  /* get next bs round in round robin style */
>  token = throttle_group_next_blk(token);
> -while (token != start && !blk_bs(token)->pending_reqs[is_write]) {
> +while (token != start && !blkp->pending_reqs[is_write]) {
>  token = throttle_group_next_blk(token);
>  }
>
>
> blkp isn't updated every time token is updated.

You're right, I'll write a patch. I'd also try to check why this was not
detected by any iotest.

Thanks!

Berto



Re: [Qemu-devel] [PATCH v2 3/4] fdc: Move qdev properties to FloppyDrive

2016-10-17 Thread Kevin Wolf
Am 15.10.2016 um 00:32 hat John Snow geschrieben:
> On 09/30/2016 03:39 PM, Kevin Wolf wrote:
> >This makes the FloppyDrive qdev object actually useful: Now that it has
> >all properties that don't belong to the controller, you can actually
> >use '-device floppy' and get a working result.
> >
> >Command line semantics is consistent with CD-ROM drives: By default you
> >get a single empty floppy drive. You can override it with -drive and
> >using the same index, but if you use -drive to add a floppy to a
> >different index, you get both of them. However, as soon as you use any
> >'-device floppy', even to a different slot, the default drive is
> >disabled.
> >
> >Using '-device floppy' without specifying the unit will choose the first
> >free slot on the controller.
> >
> >Signed-off-by: Kevin Wolf 
> >---
> > hw/block/fdc.c | 112 
> > ++---
> > vl.c   |   1 +
> > 2 files changed, 85 insertions(+), 28 deletions(-)
> >
> >diff --git a/hw/block/fdc.c b/hw/block/fdc.c
> >index 5aa8e52..00c0ec6 100644
> >--- a/hw/block/fdc.c
> >+++ b/hw/block/fdc.c
> >@@ -35,6 +35,7 @@
> > #include "qemu/timer.h"
> > #include "hw/isa/isa.h"
> > #include "hw/sysbus.h"
> >+#include "hw/block/block.h"
> > #include "sysemu/block-backend.h"
> > #include "sysemu/blockdev.h"
> > #include "sysemu/sysemu.h"
> >@@ -487,12 +488,18 @@ static const BlockDevOps fd_block_ops = {
> >  OBJECT_CHECK(FloppyDrive, (obj), TYPE_FLOPPY_DRIVE)
> >
> > typedef struct FloppyDrive {
> >-DeviceState qdev;
> >-uint32_tunit;
> >+DeviceState qdev;
> >+uint32_tunit;
> >+BlockConf   conf;
> >+FloppyDriveType type;
> > } FloppyDrive;
> >
> > static Property floppy_drive_properties[] = {
> > DEFINE_PROP_UINT32("unit", FloppyDrive, unit, -1),
> >+DEFINE_BLOCK_PROPERTIES(FloppyDrive, conf),
> >+DEFINE_PROP_DEFAULT("drive-type", FloppyDrive, type,
> >+FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
> >+FloppyDriveType),
> > DEFINE_PROP_END_OF_LIST(),
> > };
> >
> >@@ -501,6 +508,7 @@ static int floppy_drive_init(DeviceState *qdev)
> > FloppyDrive *dev = FLOPPY_DRIVE(qdev);
> > FloppyBus *bus = DO_UPCAST(FloppyBus, bus, dev->qdev.parent_bus);
> > FDrive *drive;
> >+int ret;
> >
> > if (dev->unit == -1) {
> > for (dev->unit = 0; dev->unit < MAX_FD; dev->unit++) {
> >@@ -517,29 +525,57 @@ static int floppy_drive_init(DeviceState *qdev)
> > return -1;
> > }
> >
> >-/* TODO Check whether unit is in use */
> >-
> > drive = get_drv(bus->fdc, dev->unit);
> >-
> > if (drive->blk) {
> >-if (blk_get_on_error(drive->blk, 0) != BLOCKDEV_ON_ERROR_ENOSPC) {
> >-error_report("fdc doesn't support drive option werror");
> >-return -1;
> >-}
> >-if (blk_get_on_error(drive->blk, 1) != BLOCKDEV_ON_ERROR_REPORT) {
> >-error_report("fdc doesn't support drive option rerror");
> >-return -1;
> >-}
> >-} else {
> >+error_report("Floppy unit %d is in use", dev->unit);
> >+return -1;
> >+}
> >+
> >+if (!dev->conf.blk) {
> > /* Anonymous BlockBackend for an empty drive */
> >-drive->blk = blk_new();
> >+dev->conf.blk = blk_new();
> >+ret = blk_attach_dev(dev->conf.blk, dev);
> 
> Missing a 'q' here:   ^

Yes. It has the same value, but after my last pull request we need a
DeviceState* here indeed rather than a void*.

> >@@ -2782,8 +2838,8 @@ static const VMStateDescription vmstate_sysbus_fdc ={
> > };
> >
> > static Property sysbus_fdc_properties[] = {
> >-DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.drives[0].blk),
> >-DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.drives[1].blk),
> >+DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.qdev_for_drives[0].blk),
> >+DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.qdev_for_drives[1].blk),
> > DEFINE_PROP_DEFAULT("fdtypeA", FDCtrlSysBus, state.drives[0].drive,
> > FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
> > FloppyDriveType),
> 
> ^ Does sysbus' type property not need updating ...?

Doing half of the properties here felt like a good transitional step
from fully converting the PC device to completely ignoring Sun.

Well, I guess, I should fix that...

Kevin



Re: [Qemu-devel] [PATCH] vfio: fix duplicate function call

2016-10-17 Thread Cao jin

Hi,

On 10/14/2016 11:50 PM, Alex Williamson wrote:

On Fri, 14 Oct 2016 19:16:59 +0800
Cao jin  wrote:


When vfio device is reset(encounter FLR, or bus reset), if need to do
bus reset(vfio_pci_hot_reset_one is called), vfio_pci_pre_reset &
vfio_pci_post_reset will be called twice.

Signed-off-by: Cao jin 
---
Also has a little question on vfio_pci_reset. it will be called when encounter
bus reset, or FLR. The reset method's priority in this function now is:

 1. If has "device specific reset function", then do it
 2. If has FLR, then do it.
 3. If it can do bus reset(only 1 affected device), then do it
 4. If has pm_reset, then do it

The question is: why pm reset has low priority than bus reset(if it does
can do a bus reset)? why bus reset is not the last choice? In PCI driver
of kernel, pls see __pci_dev_reset, we can see, if device support pm reset,
it won't do bus reset.


The PCI spec doesn't really define what sort of reset is done with a PM
reset.  My thinking was that if a device advertises an FLR capability
then the hardware has made a concerted effort to have a per function
reset mechanism available.  NoSoftRst- is not terribly common and it's
not entirely clear to me that the hardware has made a conscious effort
to provide this for the purposes of per function reset mechanism.
Therefore I've opt'd to prioritize a bus reset over a PM reset.



I still have a question about vfio_pci_reset. I checked commit message 
in f16f39c3, if I understand right, couldn't we put


/* See if we can do our own bus reset */
if (!vfio_pci_hot_reset_one(vdev)) {
goto post_reset;
}

in the 1st priority? Because if there is 1 affected device, then it will 
do bus reset which is the best reset we can do; if there are more than 1 
affected devices, after this patch, vfio_pci_hot_reset_one will do 
nothing, and then try other reset methods.


--
Yours Sincerely,

Cao jin





Re: [Qemu-devel] [PATCH 00/18] dataplane: remove RFifoLock (including almost all previously sent patches)

2016-10-17 Thread Christian Borntraeger
On 10/13/2016 07:34 PM, Paolo Bonzini wrote:
> This patch reorganizes aio_poll callers to establish new rules for
> dataplane locking.  The idea is that I/O operations on a dataplane
> BDS (i.e. one where the AioContext is not the main one) do not call
> aio_poll anymore.  Instead, they wait for the operation to end in the
> other I/O thread, at which point the other I/O thread calls bdrv_wakeup
> to wake up the main thread.
> 
> With this change, only one thread runs aio_poll for an AioContext.
> While aio_context_acquire/release is still needed to protect the BDSes,
> it need not interrupt the other thread's event loop anymore, and therefore
> it does not need contention callbacks anymore.  Thus the patch can remove
> RFifoLock.  This fixes possible hangs in bdrv_drain_all, reproducible (for
> example) by unplugging a virtio-scsi-dataplane device while there is I/O
> going on for a virtio-blk-dataplane on the same I/O thread.


Have you seen improvements or deteriorations in performance with single disks
or multiple disks? Is there a branch? 




Re: [Qemu-devel] [PATCH] eepro100: Fix memory leak and simplify code for VMStateDescription

2016-10-17 Thread Dr. David Alan Gilbert
* Stefan Weil (s...@weilnetz.de) wrote:
> On 10/14/16 10:25, Dr. David Alan Gilbert wrote:
> > * Stefan Weil (s...@weilnetz.de) wrote:
> > > Instead of allocating a VMStateDescription for each NIC instance,
> > > the code now uses a single constant VMStateDescription for all
> > > instances. That implies that the name field is always the same.
> > 
> > Doesn't this break migration compatibility?
> > 
> > You might be able to get around that (in the forward direction only)
> > by adding an entry to qdev_alias_table but I'm not sure.
> > 
> > Dave
> 
> I'm not an expert for migration (never used it myself).
> 
> Is migration compatibility a must, even for non default settings
> like the NICs implemented by eepro100.c? I assume that applications
> which use migration will usually run with an e1000 NIC.
> 
> Or can we break migration compatibility and add that information
> to the release notes?

We normally keep migration compatibility for all devices
in the forward direction unless it's something really obscure;
I don't think an e100 is.

> How does e1000 handle migration if QEMU was started with a
> e1000-82544gc NIC and migrated to a e1000-82545em NIC?

That's not required to work; you're required to have the same device
configuration on the destination as the source.

$ qemu-system-x86_64 -nographic -device e1000-82544gc
(qemu) migrate "exec:cat > t.mig"

$ qemu-system-x86_64 -nographic -device e1000-82545em -incoming "exec:cat t.mig"
qemu-system-x86_64: get_pci_config_device: Bad config data: i=0x2 read: c 
device: f cmask: ff wmask: 0 w1cmask:0
qemu-system-x86_64: error while loading state for instance 0x0 of device 
':00:04.0/e1000'
qemu-system-x86_64: load of migration failed: Invalid argument

Now, note that what's happening here is that e1000 is doing a similar
trick to what you're doing - i.e. all devices end up getting
migrated as 'e1000' in the device string (:00:04.0/e1000).

The scheme you end up with is OK, but the problem is it's just
different from what we have now, so existing streams
with device names like ':00:04.0/i82550' won't load.

Dave

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



Re: [Qemu-devel] [PATCH v2 10/11] blockjob: refactor backup_start as backup_job_create

2016-10-17 Thread Fam Zheng
On Tue, 10/11 11:35, Kevin Wolf wrote:
> > >By the way, why did we allow to add a 'bitmap' option for DriveBackup
> > >without adding it to BlockdevBackup at the same time?
> > 
> > I don't remember. I'm not sure anyone ever audited it to convince
> > themselves it was a useful or safe thing to do. I believe at the
> > time I was pushing for bitmaps in DriveBackup, Fam was still
> > authoring the BlockdevBackup interface.
> 
> Hm, maybe that's why. I checked the commit dates of both (and there
> BlockdevBackup was earlier), but I didn't check the development history.
> 
> Should we add it now or is it a bad idea?

Yes, we should add it. I'll send a separate patch. Thanks for catching that.

Fam



[Qemu-devel] CVE-2016-5403 results in a bug

2016-10-17 Thread yue
hi, all:
i apply this patch, 
https://git.centos.org/blob/rpms!!qemu-kvm/6078803a0db76660aef491907f795bb23ad33357/SOURCES!kvm-virtio-error-out-if-guest-exceeds-virtqueue-size.patch;jsessionid=124pfc40q9ejezgb0b5qrnv6m#L33
 .
  but this patch always results in a bug(bug?).  a vm always exits with 
'2016-10-17T07:33:40.393592Z qemu-kvm: Virtqueue size exceeded', if you suspend 
and resume . (please refer to https://wiki.openstack.org/wiki/Kvm-Pause-Suspend 
 to see the definiton of suspend and resume in openstack). this operation is 
very commonly used in openstack. i  am not sure if this patch is elegant .


what is your opinion?


thanks

Re: [Qemu-devel] [PATCH 00/18] dataplane: remove RFifoLock (including almost all previously sent patches)

2016-10-17 Thread Paolo Bonzini
> On 10/13/2016 07:34 PM, Paolo Bonzini wrote:
> > This patch reorganizes aio_poll callers to establish new rules for
> > dataplane locking.  The idea is that I/O operations on a dataplane
> > BDS (i.e. one where the AioContext is not the main one) do not call
> > aio_poll anymore.  Instead, they wait for the operation to end in the
> > other I/O thread, at which point the other I/O thread calls bdrv_wakeup
> > to wake up the main thread.
> > 
> > With this change, only one thread runs aio_poll for an AioContext.
> > While aio_context_acquire/release is still needed to protect the BDSes,
> > it need not interrupt the other thread's event loop anymore, and therefore
> > it does not need contention callbacks anymore.  Thus the patch can remove
> > RFifoLock.  This fixes possible hangs in bdrv_drain_all, reproducible (for
> > example) by unplugging a virtio-scsi-dataplane device while there is I/O
> > going on for a virtio-blk-dataplane on the same I/O thread.
> 
> Have you seen improvements or deteriorations in performance with single disks
> or multiple disks? Is there a branch?

I will prepare a branch for v2.

This should have no performance effect.  The affected code only runs during QMP
operations such as live snapshots or completing a block job.

Paolo



Re: [Qemu-devel] [PATCH v3] fsdev: add IO throttle support to fsdev devices

2016-10-17 Thread Pradeep Jagadeesh

Hi Alberto,

On Fri 16 Sep 2016 10:33:36 AM CEST, Pradeep Jagadeesh wrote:

Hi,

first of all, sorry for the late reply! Here are my comments:


--- a/fsdev/qemu-fsdev-opts.c
+++ b/fsdev/qemu-fsdev-opts.c
@@ -37,6 +37,82 @@ static QemuOptsList qemu_fsdev_opts = {
 }, {
 .name = "sock_fd",
 .type = QEMU_OPT_NUMBER,
+}, {
+.name = "throttling.iops-total",
+.type = QEMU_OPT_NUMBER,
+.help = "limit total I/O operations per second",

  /*...*/

+},{
+.name = "throttling.iops-size",
+.type = QEMU_OPT_NUMBER,
+.help = "when limiting by iops max size of an I/O in bytes",


It would be nice if we could factor these so we don't have to have them
twice in the code. I think it should be doable with qemu_opts_append().

It can be done later in a separate patch if you prefer.


+typedef struct FsThrottle {
+ThrottleState ts;
+ThrottleTimers tt;
+AioContext   *aioctx;
+ThrottleConfig cfg;
+bool enabled;
+CoQueue  throttled_reqs[2];
+unsigned pending_reqs[2];
+bool any_timer_armed[2];
+QemuMutex lock;
+} FsThrottle;


You based your implementation on block/throttle-groups.c. I think yours
can be made simpler because one of the problems with mine is that it
needs to support multiple parallel I/O operations on the same throttling
group, and that's why the locking rules are more complex. With a single
user per ThrottleConfig this is not necessary.

Have you checked if you really need them? My impression is that you
might be able to get rid of the 'lock', 'any_timer_armed' and
'pending_reqs' fields.

Please check commit 76f4afb40fa076ed23fe0ab42c7a768ddb71123f to see how
was the transition from single-drive throttling to group throttling,
specifically the bdrv_io_limits_intercept() function. You will see that
it was simpler.


I tried removing the lock, I got into rcu issues, and the qemu hangs.
Once I put them back, it works fine.

-Pradeep



@@ -436,8 +436,8 @@ static ssize_t local_pwritev(FsContext *ctx, 
V9fsFidOpenState *fs,
  const struct iovec *iov,
  int iovcnt, off_t offset)
 {
-ssize_t ret
-;
+ssize_t ret;
+


This could go to a separate patch, but I'm fine if you include it in
this one.


@@ -1213,6 +1213,8 @@ static int local_parse_opts(QemuOpts *opts, struct 
FsDriverEntry *fse)
 const char *sec_model = qemu_opt_get(opts, "security_model");
 const char *path = qemu_opt_get(opts, "path");

+FsThrottle *fst = &fse->fst;
+


I'd remove the empty line between the declarations of 'path' and 'fst',
however...


 if (!sec_model) {
 error_report("Security model not specified, local fs needs security 
model");
 error_printf("valid options are:"
@@ -1240,6 +1242,11 @@ static int local_parse_opts(QemuOpts *opts, struct 
FsDriverEntry *fse)
 error_report("fsdev: No path specified");
 return -1;
 }
+
+if (fsdev_throttle_configure_iolimits(opts, fst) < 0) {
+return -1;
+}


...you don't need to declare fst here, you could also pass &fse->fst
directly.

Berto






[Qemu-devel] [PATCH V4] colo-proxy: fix memory leak

2016-10-17 Thread Zhang Chen
Fix memory leak in colo-compare.c and filter-rewriter.c
Report by Coverity and add some comments.

v3:
   - rebase this patch for upstream codes 

v2:
   - use traces instead of fprintf in colo-compare.c

v1:
   - initial patch 


Zhang Chen (1):
  colo-proxy: fix memory leak

 net/colo-compare.c| 34 +++---
 net/filter-rewriter.c | 17 +
 net/trace-events  |  1 +
 3 files changed, 21 insertions(+), 31 deletions(-)

-- 
2.7.4






[Qemu-devel] [PATCH V4] colo-proxy: fix memory leak

2016-10-17 Thread Zhang Chen
Fix memory leak in colo-compare.c and filter-rewriter.c
Report by Coverity and add some comments.

Signed-off-by: Zhang Chen 
---
 net/colo-compare.c| 34 +++---
 net/filter-rewriter.c | 17 +
 net/trace-events  |  1 +
 3 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 47703c5..834b1f5 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -188,7 +188,6 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet 
*ppkt)
 {
 struct tcphdr *ptcp, *stcp;
 int res;
-char *sdebug, *ddebug;
 
 trace_colo_compare_main("compare tcp");
 if (ppkt->size != spkt->size) {
@@ -219,24 +218,21 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet 
*ppkt)
 (spkt->size - ETH_HLEN));
 
 if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
-sdebug = strdup(inet_ntoa(ppkt->ip->ip_src));
-ddebug = strdup(inet_ntoa(ppkt->ip->ip_dst));
-fprintf(stderr, "%s: src/dst: %s/%s p: seq/ack=%u/%u"
-" s: seq/ack=%u/%u res=%d flags=%x/%x\n",
-__func__, sdebug, ddebug,
-(unsigned int)ntohl(ptcp->th_seq),
-(unsigned int)ntohl(ptcp->th_ack),
-(unsigned int)ntohl(stcp->th_seq),
-(unsigned int)ntohl(stcp->th_ack),
-res, ptcp->th_flags, stcp->th_flags);
-
-fprintf(stderr, "Primary len = %d\n", ppkt->size);
-qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", ppkt->size);
-fprintf(stderr, "Secondary len = %d\n", spkt->size);
-qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
-
-g_free(sdebug);
-g_free(ddebug);
+trace_colo_compare_pkt_info(inet_ntoa(ppkt->ip->ip_src),
+inet_ntoa(ppkt->ip->ip_dst),
+ntohl(ptcp->th_seq),
+ntohl(ptcp->th_ack),
+ntohl(stcp->th_seq),
+ntohl(stcp->th_ack),
+res, ptcp->th_flags,
+stcp->th_flags,
+ppkt->size,
+spkt->size);
+
+qemu_hexdump((char *)ppkt->data, stderr,
+ "colo-compare ppkt", ppkt->size);
+qemu_hexdump((char *)spkt->data, stderr,
+ "colo-compare spkt", spkt->size);
 }
 
 return res;
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index 89abe72..c4ab91c 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -68,15 +68,11 @@ static int handle_primary_tcp_pkt(NetFilterState *nf,
 
 tcp_pkt = (struct tcphdr *)pkt->transport_header;
 if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
-char *sdebug, *ddebug;
-sdebug = strdup(inet_ntoa(pkt->ip->ip_src));
-ddebug = strdup(inet_ntoa(pkt->ip->ip_dst));
-trace_colo_filter_rewriter_pkt_info(__func__, sdebug, ddebug,
+trace_colo_filter_rewriter_pkt_info(__func__,
+inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
 ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
 tcp_pkt->th_flags);
 trace_colo_filter_rewriter_conn_offset(conn->offset);
-g_free(sdebug);
-g_free(ddebug);
 }
 
 if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) {
@@ -116,15 +112,11 @@ static int handle_secondary_tcp_pkt(NetFilterState *nf,
 tcp_pkt = (struct tcphdr *)pkt->transport_header;
 
 if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
-char *sdebug, *ddebug;
-sdebug = strdup(inet_ntoa(pkt->ip->ip_src));
-ddebug = strdup(inet_ntoa(pkt->ip->ip_dst));
-trace_colo_filter_rewriter_pkt_info(__func__, sdebug, ddebug,
+trace_colo_filter_rewriter_pkt_info(__func__,
+inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
 ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
 tcp_pkt->th_flags);
 trace_colo_filter_rewriter_conn_offset(conn->offset);
-g_free(sdebug);
-g_free(ddebug);
 }
 
 if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN))) {
@@ -162,6 +154,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
 
 iov_to_buf(iov, iovcnt, 0, buf, size);
 pkt = packet_new(buf, size);
+g_free(buf);
 
 /*
  * if we get tcp packet
diff --git a/net/trace-events b/net/trace-events
index d67f048..b1913a6 100644
--- a/net/trace-events
+++ b/net/trace-events
@@ -13,6 +13,7 @@ colo_compare_icmp_miscompare(const char *sta, int size) ": %s 
= %d"
 colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, 
const char *stc, const char *std) "ppkt size = %d, ip_src =

[Qemu-devel] [Bug 1634069] [NEW] Exclude keys from grab

2016-10-17 Thread Constantine
Public bug reported:

Feature request: pressing every time a shortcut to release grab for
switching windows/desktops is pretty annoying, especially for users of
tiling WMs.

QEMU have to have a way to specify keys or shortcuts (possibly something
like "everything with the specified modifier key"), which would not be
intercepted.

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: configuration feature-request keys shortcuts

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

Title:
  Exclude keys from grab

Status in QEMU:
  New

Bug description:
  Feature request: pressing every time a shortcut to release grab for
  switching windows/desktops is pretty annoying, especially for users of
  tiling WMs.

  QEMU have to have a way to specify keys or shortcuts (possibly
  something like "everything with the specified modifier key"), which
  would not be intercepted.

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



Re: [Qemu-devel] invtsc + migration + TSC scaling

2016-10-17 Thread Marcelo Tosatti
On Fri, Oct 14, 2016 at 06:20:31PM -0300, Eduardo Habkost wrote:
> I have been wondering: should we allow live migration with the
> invtsc flag enabled, if TSC scaling is available on the
> destination?

TSC scaling and invtsc flag, yes.

> 
> For reference, this is what the Intel SDM says about invtsc:
> 
>   The time stamp counter in newer processors may support an
>   enhancement, referred to as invariant TSC. Processor’s support
>   for invariant TSC is indicated by CPUID.8007H:EDX[8].
> 
>   The invariant TSC will run at a constant rate in all ACPI P-,
>   C-. and T-states. This is the architectural behavior moving
>   forward. On processors with invariant TSC support, the OS may
>   use the TSC for wall clock timer services (instead of ACPI or
>   HPET timers). TSC reads are much more efficient and do not
>   incur the overhead associated with a ring transition or access
>   to a platform resource.
> 
> -- 
> Eduardo

Yes. The blockage happened for different reasons:

1) Migration: to host with different TSC frequency.

2) Savevm: It is not safe to use the TSC for wall clock timer
services.

By allowing savevm, you make a commitment to allow a feature
at the expense of not complying with the spec (specifically the "
the OS may use the TSC for wall clock timer services", because the
TSC stops relative to realtime for the duration of the savevm stop
window).

But since Linux guests use kvmclock and Windows guests use Hyper-V
enlightenment, it should be fine to disable 2).

There is a bug open for this, btw: 
https://bugzilla.redhat.com/show_bug.cgi?id=1353073





[Qemu-devel] [Bug 1634069] Re: Exclude keys from grab

2016-10-17 Thread Constantine
Alternatively/additionally it would be nice to be able to disable keys
grabbing at all.

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

Title:
  Exclude keys from grab

Status in QEMU:
  New

Bug description:
  Feature request: pressing every time a shortcut to release grab for
  switching windows/desktops is pretty annoying, especially for users of
  tiling WMs.

  QEMU have to have a way to specify keys or shortcuts (possibly
  something like "everything with the specified modifier key"), which
  would not be intercepted.

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



[Qemu-devel] [PATCH v8 11/11] virtio-crypto: add myself as virtio-crypto and cryptodev backends maintainer

2016-10-17 Thread Gonglei
This patch includes two parts: Cryptodev Backends
and virtio-crypto stuff. I can maintain cryptodev backends
which introduced by myself. For virtio-crypto stuff, I can
share the work with Michael (The whole virtio supporter).

Signed-off-by: Gonglei 
---
 MAINTAINERS | 13 +
 1 file changed, 13 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b01fec0..96fd24f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1003,6 +1003,13 @@ F: include/sysemu/rng*.h
 F: backends/rng*.c
 F: tests/virtio-rng-test.c
 
+virtio-crypto
+M: Gonglei 
+S: Supported
+F: hw/virtio/virtio-crypto.c
+F: hw/virtio/virtio-crypto-pci.c
+F: include/hw/virtio/virtio-crypto.h
+
 nvme
 M: Keith Busch 
 L: qemu-bl...@nongnu.org
@@ -1248,6 +1255,12 @@ S: Maintained
 F: backends/hostmem*.c
 F: include/sysemu/hostmem.h
 
+Cryptodev Backends
+M: Gonglei 
+S: Maintained
+F: include/sysemu/cryptodev*.h
+F: backends/cryptodev*.c
+
 QAPI
 M: Markus Armbruster 
 M: Michael Roth 
-- 
1.8.3.1





[Qemu-devel] [PATCH v8 10/11] cryptodev: introduce an unified wrapper for crypto operation

2016-10-17 Thread Gonglei
We use an opaque point to the VirtIOCryptoReq which
can support different packets based on different
algorithms.

Signed-off-by: Gonglei 
---
 backends/cryptodev.c   | 28 ++--
 hw/virtio/virtio-crypto.c  | 10 +-
 include/sysemu/cryptodev.h | 13 +++--
 3 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index 47521cf..4a49f97 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -30,6 +30,8 @@
 #include "qapi-visit.h"
 #include "qemu/config-file.h"
 #include "qom/object_interfaces.h"
+#include "hw/virtio/virtio-crypto.h"
+
 
 static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients;
 
@@ -105,7 +107,7 @@ int cryptodev_backend_sym_close_session(
 return -1;
 }
 
-int cryptodev_backend_sym_operation(
+static int cryptodev_backend_sym_operation(
  CryptoDevBackend *backend,
  CryptoDevBackendSymOpInfo *op_info,
  uint32_t queue_index, Error **errp)
@@ -117,7 +119,29 @@ int cryptodev_backend_sym_operation(
 return bc->do_sym_op(backend, op_info, queue_index, errp);
 }
 
-return -1;
+return -VIRTIO_CRYPTO_ERR;
+}
+
+int cryptodev_backend_crypto_operation(
+ CryptoDevBackend *backend,
+ void *opaque,
+ uint32_t queue_index, Error **errp)
+{
+VirtIOCryptoReq *req = opaque;
+
+if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) {
+CryptoDevBackendSymOpInfo *op_info;
+op_info = req->u.sym_op_info;
+
+return cryptodev_backend_sym_operation(backend,
+ op_info, queue_index, errp);
+} else {
+error_setg(errp, "Unsupported cryptodev alg type: %" PRIu32 "",
+   req->flags);
+   return -VIRTIO_CRYPTO_NOTSUPP;
+}
+
+return -VIRTIO_CRYPTO_ERR;
 }
 
 static void
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 5cd749f..13a7885 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -625,15 +625,15 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request)
 /* Set request's parameter */
 request->flags = CRYPTODEV_BACKEND_ALG_SYM;
 request->u.sym_op_info = sym_op_info;
-ret = cryptodev_backend_sym_operation(vcrypto->cryptodev,
-sym_op_info, queue_index, &local_err);
+ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev,
+request, queue_index, &local_err);
 if (ret < 0) {
-status = VIRTIO_CRYPTO_ERR;
+status = -ret;
 if (local_err) {
 error_report_err(local_err);
 }
-} else { /* ret >= 0 */
-status = VIRTIO_CRYPTO_OK;
+} else { /* ret == VIRTIO_CRYPTO_OK */
+status = ret;
 }
 virtio_crypto_req_complete(request, status);
 virtio_crypto_free_request(request);
diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h
index e4510da..f9a4b36 100644
--- a/include/sysemu/cryptodev.h
+++ b/include/sysemu/cryptodev.h
@@ -275,20 +275,21 @@ int cryptodev_backend_sym_close_session(
uint32_t queue_index, Error **errp);
 
 /**
- * cryptodev_backend_sym_operation:
+ * cryptodev_backend_crypto_operation:
  * @backend: the cryptodev backend object
- * @op_info: parameters needed by symmetric crypto operation
+ * @opaque: pointer to a VirtIOCryptoReq object
  * @queue_index: queue index of cryptodev backend client
  * @errp: pointer to a NULL-initialized error object
  *
- * Do symmetric crypto operation, such as encryption and
+ * Do crypto operation, such as encryption and
  * decryption
  *
- * Returns: 0 on success, or Negative on error
+ * Returns: VIRTIO_CRYPTO_OK on success,
+ * or -VIRTIO_CRYPTO_* on error
  */
-int cryptodev_backend_sym_operation(
+int cryptodev_backend_crypto_operation(
  CryptoDevBackend *backend,
- CryptoDevBackendSymOpInfo *op_info,
+ void *opaque,
  uint32_t queue_index, Error **errp);
 
 #endif /* CRYPTODEV_H */
-- 
1.8.3.1





[Qemu-devel] [PATCH v8 09/11] virtio-crypto: add data queue processing handler

2016-10-17 Thread Gonglei
Introduces VirtIOCryptoReq structure to store
crypto request so that we can support synchronous
and asynchronous crypto operation in the future.

At present, we only support cipher and algorithm
chaining.

Signed-off-by: Gonglei 
---
 hw/virtio/virtio-crypto.c | 358 +-
 include/hw/virtio/virtio-crypto.h |   4 +
 2 files changed, 361 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 4be65e0..5cd749f 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -311,6 +311,362 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, 
VirtQueue *vq)
 } /* end for loop */
 }
 
+static void virtio_crypto_init_request(VirtIOCrypto *vcrypto, VirtQueue *vq,
+VirtIOCryptoReq *req)
+{
+req->vcrypto = vcrypto;
+req->vq = vq;
+req->in = NULL;
+req->in_iov = NULL;
+req->in_num = 0;
+req->in_len = 0;
+req->flags = CRYPTODEV_BACKEND_ALG__MAX;
+req->u.sym_op_info = NULL;
+}
+
+static void virtio_crypto_free_request(VirtIOCryptoReq *req)
+{
+if (req) {
+if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) {
+g_free(req->u.sym_op_info);
+}
+g_free(req);
+}
+}
+
+static void
+virtio_crypto_sym_input_data_helper(VirtIODevice *vdev,
+VirtIOCryptoReq *req,
+uint32_t status,
+CryptoDevBackendSymOpInfo *sym_op_info)
+{
+size_t s, len;
+
+if (status != VIRTIO_CRYPTO_OK) {
+return;
+}
+
+len = sym_op_info->dst_len;
+/* Save the cipher result */
+s = iov_from_buf(req->in_iov, req->in_num, 0, sym_op_info->dst, len);
+if (s != len) {
+virtio_error(vdev, "virtio-crypto dest data incorrect");
+return;
+}
+
+iov_discard_front(&req->in_iov, &req->in_num, len);
+
+if (sym_op_info->op_type ==
+  VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING) {
+/* Save the digest result */
+s = iov_from_buf(req->in_iov, req->in_num, 0,
+ sym_op_info->digest_result,
+ sym_op_info->digest_result_len);
+if (s != sym_op_info->digest_result_len) {
+virtio_error(vdev, "virtio-crypto digest result incorrect");
+}
+}
+}
+
+static void virtio_crypto_req_complete(VirtIOCryptoReq *req, uint8_t status)
+{
+VirtIOCrypto *vcrypto = req->vcrypto;
+VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto);
+
+if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) {
+virtio_crypto_sym_input_data_helper(vdev, req, status,
+req->u.sym_op_info);
+}
+stb_p(&req->in->status, status);
+virtqueue_push(req->vq, &req->elem, req->in_len);
+virtio_notify(vdev, req->vq);
+}
+
+static VirtIOCryptoReq *
+virtio_crypto_get_request(VirtIOCrypto *s, VirtQueue *vq)
+{
+VirtIOCryptoReq *req = virtqueue_pop(vq, sizeof(VirtIOCryptoReq));
+
+if (req) {
+virtio_crypto_init_request(s, vq, req);
+}
+return req;
+}
+
+static CryptoDevBackendSymOpInfo *
+virtio_crypto_sym_op_helper(VirtIODevice *vdev,
+   struct virtio_crypto_cipher_para *cipher_para,
+   struct virtio_crypto_alg_chain_data_para *alg_chain_para,
+   struct iovec *iov, unsigned int out_num)
+{
+CryptoDevBackendSymOpInfo *op_info;
+uint32_t src_len = 0, dst_len = 0;
+uint32_t iv_len = 0;
+uint32_t aad_len = 0, hash_result_len = 0;
+uint32_t hash_start_src_offset = 0, len_to_hash = 0;
+uint32_t cipher_start_src_offset = 0, len_to_cipher = 0;
+
+size_t max_len, curr_size = 0;
+size_t s;
+
+/* Plain cipher */
+if (cipher_para) {
+iv_len = virtio_ldl_p(vdev, &cipher_para->iv_len);
+src_len = virtio_ldl_p(vdev, &cipher_para->src_data_len);
+dst_len = virtio_ldl_p(vdev, &cipher_para->dst_data_len);
+} else if (alg_chain_para) { /* Algorithm chain */
+iv_len = virtio_ldl_p(vdev, &alg_chain_para->iv_len);
+src_len = virtio_ldl_p(vdev, &alg_chain_para->src_data_len);
+dst_len = virtio_ldl_p(vdev, &alg_chain_para->dst_data_len);
+
+aad_len = virtio_ldl_p(vdev, &alg_chain_para->aad_len);
+hash_result_len = virtio_ldl_p(vdev,
+  &alg_chain_para->hash_result_len);
+hash_start_src_offset = virtio_ldl_p(vdev,
+ &alg_chain_para->hash_start_src_offset);
+cipher_start_src_offset = virtio_ldl_p(vdev,
+ &alg_chain_para->cipher_start_src_offset);
+len_to_cipher = virtio_ldl_p(vdev, &alg_chain_para->len_to_cipher);
+len_to_hash = virtio_ldl_p(vdev, &alg_chain_para->len_to_hash);
+} else {
+return NULL;
+}
+
+max_len = iv_len + aad_len + src_len + dst_len + hash_result_len;
+if (max_len == LONG_MAX - sizeof(CryptoDevBackendSymOpInfo)) {
+virtio_error(vdev, "virtio-crypto too big len

[Qemu-devel] [PATCH v8 02/11] cryptodev: add symmetric algorithm operation stuff

2016-10-17 Thread Gonglei
This patch adds session operation and crypto operation
stuff in the cryptodev backend, including function
pointers and corresponding structures.

Signed-off-by: Gonglei 
---
 backends/cryptodev.c   |  45 ++
 include/sysemu/cryptodev.h | 149 +
 2 files changed, 194 insertions(+)

diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index e8582cd..47521cf 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -75,6 +75,51 @@ void cryptodev_backend_cleanup(
 backend->ready = false;
 }
 
+int64_t cryptodev_backend_sym_create_session(
+   CryptoDevBackend *backend,
+   CryptoDevBackendSymSessionInfo *sess_info,
+   uint32_t queue_index, Error **errp)
+{
+CryptoDevBackendClass *bc =
+  CRYPTODEV_BACKEND_GET_CLASS(backend);
+
+if (bc->create_session) {
+return bc->create_session(backend, sess_info, queue_index, errp);
+}
+
+return -1;
+}
+
+int cryptodev_backend_sym_close_session(
+   CryptoDevBackend *backend,
+   uint64_t session_id,
+   uint32_t queue_index, Error **errp)
+{
+CryptoDevBackendClass *bc =
+  CRYPTODEV_BACKEND_GET_CLASS(backend);
+
+if (bc->close_session) {
+return bc->close_session(backend, session_id, queue_index, errp);
+}
+
+return -1;
+}
+
+int cryptodev_backend_sym_operation(
+ CryptoDevBackend *backend,
+ CryptoDevBackendSymOpInfo *op_info,
+ uint32_t queue_index, Error **errp)
+{
+CryptoDevBackendClass *bc =
+  CRYPTODEV_BACKEND_GET_CLASS(backend);
+
+if (bc->do_sym_op) {
+return bc->do_sym_op(backend, op_info, queue_index, errp);
+}
+
+return -1;
+}
+
 static void
 cryptodev_backend_get_queues(Object *obj, Visitor *v, const char *name,
  void *opaque, Error **errp)
diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h
index de9d3e3..e4510da 100644
--- a/include/sysemu/cryptodev.h
+++ b/include/sysemu/cryptodev.h
@@ -56,12 +56,111 @@ typedef struct CryptoDevBackendClient
  CryptoDevBackendClient;
 typedef struct CryptoDevBackend CryptoDevBackend;
 
+enum CryptoDevBackendAlgType {
+CRYPTODEV_BACKEND_ALG_SYM,
+CRYPTODEV_BACKEND_ALG__MAX,
+};
+
+/**
+ * CryptoDevBackendSymSessionInfo:
+ *
+ * @op_code: operation code (refer to virtio_crypto.h)
+ * @cipher_alg: algorithm type of CIPHER
+ * @key_len: byte length of cipher key
+ * @hash_alg: algorithm type of HASH/MAC
+ * @hash_result_len: byte length of HASH operation result
+ * @auth_key_len: byte length of authenticated key
+ * @add_len: byte length of additional authenticated data
+ * @op_type: operation type (refer to virtio_crypto.h)
+ * @direction: encryption or direction for CIPHER
+ * @hash_mode: HASH mode for HASH operation (refer to virtio_crypto.h)
+ * @alg_chain_order: order of algorithm chaining (CIPHER then HASH,
+ *   or HASH then CIPHER)
+ * @cipher_key: point to a key of CIPHER
+ * @auth_key: point to an authenticated key of MAC
+ *
+ */
+typedef struct CryptoDevBackendSymSessionInfo {
+/* corresponding with virtio crypto spec */
+uint32_t op_code;
+uint32_t cipher_alg;
+uint32_t key_len;
+uint32_t hash_alg;
+uint32_t hash_result_len;
+uint32_t auth_key_len;
+uint32_t add_len;
+uint8_t op_type;
+uint8_t direction;
+uint8_t hash_mode;
+uint8_t alg_chain_order;
+uint8_t *cipher_key;
+uint8_t *auth_key;
+} CryptoDevBackendSymSessionInfo;
+
+/**
+ * CryptoDevBackendSymOpInfo:
+ *
+ * @session_id: session index which was previously
+ *  created by cryptodev_backend_sym_create_session()
+ * @aad_len: byte length of additional authenticated data
+ * @iv_len: byte length of initialization vector or counter
+ * @src_len: byte length of source data
+ * @dst_len: byte length of destination data
+ * @digest_result_len: byte length of hash digest result
+ * @hash_start_src_offset: Starting point for hash processing, specified
+ *  as number of bytes from start of packet in source data, only used for
+ *  algorithm chain
+ * @cipher_start_src_offset: Starting point for cipher processing, specified
+ *  as number of bytes from start of packet in source data, only used for
+ *  algorithm chain
+ * @len_to_hash: byte length of source data on which the hash
+ *  operation will be computed, only used for algorithm chain
+ * @len_to_cipher: byte length of source data on which the cipher
+ *  operation will be computed, only used for algorithm chain
+ * @op_type: operation type (refer to virtio_crypto.h)
+ * @iv: point to the initialization vector or counter
+ * @src: point to the source data
+ * @dst: point to the destination data
+ * @aad_data: point to the additional authenticated data
+ * @digest_result: point to the digest result data
+ * @data[0]: point to the extensional memory by one memo

[Qemu-devel] [PATCH v8 01/11] cryptodev: introduce cryptodev backend interface

2016-10-17 Thread Gonglei
cryptodev backend interface is used to realize the active work for
virtual crypto device.

This patch only add the framework, doesn't include specific operations.

Signed-off-by: Gonglei 
---
 backends/Makefile.objs |   2 +
 backends/cryptodev.c   | 176 +
 include/sysemu/cryptodev.h | 145 +
 3 files changed, 323 insertions(+)
 create mode 100644 backends/cryptodev.c
 create mode 100644 include/sysemu/cryptodev.h

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 31a3a89..55bd43d 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -9,3 +9,5 @@ common-obj-$(CONFIG_TPM) += tpm.o
 
 common-obj-y += hostmem.o hostmem-ram.o
 common-obj-$(CONFIG_LINUX) += hostmem-file.o
+
+common-obj-y += cryptodev.o
diff --git a/backends/cryptodev.c b/backends/cryptodev.c
new file mode 100644
index 000..e8582cd
--- /dev/null
+++ b/backends/cryptodev.c
@@ -0,0 +1,176 @@
+/*
+ * QEMU Crypto Device Implementation
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ * Authors:
+ *Gonglei 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/cryptodev.h"
+#include "hw/boards.h"
+#include "qapi/error.h"
+#include "qapi/visitor.h"
+#include "qapi-types.h"
+#include "qapi-visit.h"
+#include "qemu/config-file.h"
+#include "qom/object_interfaces.h"
+
+static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients;
+
+
+CryptoDevBackendClient *
+cryptodev_backend_new_client(const char *model,
+const char *name)
+{
+CryptoDevBackendClient *cc;
+
+cc = g_malloc0(sizeof(CryptoDevBackendClient));
+cc->model = g_strdup(model);
+if (name) {
+cc->name = g_strdup(name);
+}
+
+QTAILQ_INSERT_TAIL(&crypto_clients, cc, next);
+
+return cc;
+}
+
+void cryptodev_backend_free_client(
+  CryptoDevBackendClient *cc)
+{
+QTAILQ_REMOVE(&crypto_clients, cc, next);
+g_free(cc->name);
+g_free(cc->model);
+g_free(cc->info_str);
+g_free(cc);
+}
+
+void cryptodev_backend_cleanup(
+ CryptoDevBackend *backend,
+ Error **errp)
+{
+CryptoDevBackendClass *bc =
+  CRYPTODEV_BACKEND_GET_CLASS(backend);
+
+if (bc->cleanup) {
+bc->cleanup(backend, errp);
+}
+
+backend->ready = false;
+}
+
+static void
+cryptodev_backend_get_queues(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj);
+uint32_t value = backend->conf.peers.queues;
+
+visit_type_uint32(v, name, &value, errp);
+}
+
+static void
+cryptodev_backend_set_queues(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj);
+Error *local_err = NULL;
+uint32_t value;
+
+visit_type_uint32(v, name, &value, &local_err);
+if (local_err) {
+goto out;
+}
+if (!value) {
+error_setg(&local_err, "Property '%s.%s' doesn't take value '%"
+   PRIu32 "'", object_get_typename(obj), name, value);
+goto out;
+}
+backend->conf.peers.queues = value;
+out:
+error_propagate(errp, local_err);
+}
+
+static void
+cryptodev_backend_complete(UserCreatable *uc, Error **errp)
+{
+CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
+CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
+Error *local_err = NULL;
+
+if (bc->init) {
+bc->init(backend, &local_err);
+if (local_err) {
+goto out;
+}
+}
+backend->ready = true;
+return;
+
+out:
+backend->ready = false;
+error_propagate(errp, local_err);
+}
+
+static void cryptodev_backend_instance_init(Object *obj)
+{
+object_property_add(obj, "queues", "int",
+  cryptodev_backend_get_queues,
+  cryptodev_backend_set_queues,
+  NULL, NULL, NULL);
+/* Initialize devices' queues property to 1 */
+object_property_set_int(obj, 1, "queues", NULL);
+}
+
+static void cryptodev_backend_finalize(Object *obj)
+{
+
+}
+
+static void
+cryptodev_backend_class_init(ObjectClass *oc, void *data)
+{
+

Re: [Qemu-devel] [Qemu-block] [PATCH v5 1/1] block: improve error handling in raw_open

2016-10-17 Thread Kevin Wolf
Am 14.10.2016 um 17:59 hat Stefan Hajnoczi geschrieben:
> On Tue, Oct 11, 2016 at 04:12:35PM +0200, Halil Pasic wrote:
> > Make raw_open for POSIX more consistent in handling errors by setting
> > the error object also when qemu_open fails. The error object was set
> > generally set in case of errors, but I guess this case was overlooked.
> > Do the same for win32.
> > 
> > Signed-off-by: Halil Pasic 
> > Reviewed-by: Sascha Silbe 
> > Tested-by: Marc Hartmayer  (POSIX only)
> > 
> > ---
> > 
> > Stumbled upon this (POSIX) while testing VMs with too many SCSI disks in
> > respect to my nofile limit. When open hits the nofile limit while trying
> > to hotplug yet another SCSI disk via libvirt we end up with no adequate
> > error message (one stating too many files). Sadly this patch in not
> > sufficient to fix this problem because drive_new (/qemu/blockdev.c)
> > handles errors using error_report_err which is documented as not to be
> > used in QMP context.
> > 
> > The win32 part was not tested, and the sole reason I touched it is
> > to not introduce unnecessary divergence.
> > 
> > v4 -> v5:
> > * fix qemu-iotests by adding the filename to the message
> 
> This patch doesn't modify any iotests golden master files.  Does this
> mean the iotests output is unchanged?
> 
> > v3 -> v4:
> > * rebased on current master
> > v2 -> v3:
> > * first save errno then error_setg_errno
> > v1 -> v2:
> > * fixed win32 by the correct error_setg_*
> > * use the original errno consequently
> > ---
> >  block/raw-posix.c | 1 +
> >  block/raw-win32.c | 1 +
> >  2 files changed, 2 insertions(+)
> 
> Reviewed-by: Stefan Hajnoczi 

Thanks, applied to the block branch.

Kevin


pgpP05teabqzG.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH] target-i386: Don't cpu->migratable field when filtering features

2016-10-17 Thread Ján Tomko

On Fri, Oct 14, 2016 at 04:28:14PM -0300, Eduardo Habkost wrote:

When explicitly enabling unmigratable flags using "-cpu host"
(e.g. "-cpu host,+invtsc"), the requested feature won't be
enabled because cpu->migratable is true by default.



[...]



Signed-off-by: Eduardo Habkost 
---
target-i386/cpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



Tested-by: Ján Tomko 


signature.asc
Description: Digital signature


Re: [Qemu-devel] [PULL v2 19/20] trace: introduce a formal group name for trace events

2016-10-17 Thread Greg Kurz
On Thu, 13 Oct 2016 15:58:55 +0200
Paolo Bonzini  wrote:

> On 12/10/2016 10:47, Stefan Hajnoczi wrote:
> > +def make_group_name(filename):
> > +dirname = os.path.realpath(os.path.dirname(filename))
> > +basedir = os.path.join(os.path.dirname(__file__), os.pardir)
> > +basedir = os.path.realpath(os.path.abspath(basedir))
> > +dirname = dirname[len(basedir) + 1:]
> > +
> > +if dirname == "":
> > +return "common"
> > +return re.sub(r"/|-", "_", dirname)
> >
> 
> The group is based on the build directory, so it includes the relative
> path from srcdir to builddir.  My build directory is weird ("+build")
> and breaks because of this.  Since the group is not really used for
> anything yet, perhaps this patch could be reverted?
> 
> Paolo
> 

As pointed out in other mails, the real problem isn't even about ending
up with weird characters in the group name, but about including the
build directory itself...

--
Greg



[Qemu-devel] [PATCH v5 0/6] tests: enable virtio tests on SPAPR

2016-10-17 Thread Laurent Vivier
This series enables virtio tests on SPAPR by starting
machines using qtest_pc_boot() or qtest_spapr_boot() to
use the good libqos PCI framework (pc or spapr).

It adds also some byte-swapping in virtio-pci.c as
PCI is always little-endian and the endianness of
the virtio device depends on the endianness of the
guest.

This series does not enable virtio PCI MSI-X tests on
SPAPR as this needs more work and will be the aim
of another series.

v5:
- minor updates:
  - remove declaration within the code
  - update comment about qtest_vboot()
(terminates on failure)
v4:
- rebase on papr/ppc-for-2.8
- add a patch to rename target_big_endian() to qvirtio_is_big_endian()
- Add a patch to remove the QVirtioBus arguments from all virtio functions

v3:
- remove "ppc" from allowed archs for virtio-blk-test
- remove g_assert_nonnull() after g_malloc()
- add a patch to fix "vs" memory leak in virtio-scsi-test
- add a patch to remove g_assert() after qtest_spapr_boot()
  and update comment qtest_vboot() to explain it never
  returns NULL.

v2:
- update comments (virtio-1.0, log)
- move g_assert_nonnull() to qtest_boot()
- exit gracefully if the architecture is not supported
- replace qtest_pc_shutdown() by qtest_shutdown()
- move qvirtio_scsi_stop() to qvirtio_scsi_pci_free()

Laurent Vivier (6):
  tests: fix memory leak in virtio-scsi-test
  tests: don't check if qtest_spapr_boot() returns NULL
  tests: move QVirtioBus pointer into QVirtioDevice
  tests: rename target_big_endian() as qvirtio_is_big_endian()
  tests: use qtest_pc_boot()/qtest_shutdown() in virtio tests
  tests: enable virtio tests on SPAPR

 tests/Makefile.include |   3 +-
 tests/libqos/libqos.c  |   2 +
 tests/libqos/virtio-mmio.c |   1 +
 tests/libqos/virtio-pci.c  |  28 +++-
 tests/libqos/virtio.c  |  77 +--
 tests/libqos/virtio.h  |  57 
 tests/libqtest.h   |  10 --
 tests/rtas-test.c  |   1 -
 tests/vhost-user-test.c|  33 +++--
 tests/virtio-9p-test.c |  69 +-
 tests/virtio-blk-test.c| 322 +
 tests/virtio-net-test.c| 106 +++
 tests/virtio-rng-test.c|   7 +-
 tests/virtio-scsi-test.c   |  91 ++---
 14 files changed, 400 insertions(+), 407 deletions(-)

-- 
2.7.4




[Qemu-devel] [PATCH v5 1/6] tests: fix memory leak in virtio-scsi-test

2016-10-17 Thread Laurent Vivier
vs is allocated in qvirtio_scsi_pci_init() and never freed.

Signed-off-by: Laurent Vivier 
Reviewed-by: Greg Kurz 
---
 tests/virtio-scsi-test.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 79088bb..94d75b1 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -64,6 +64,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
 qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
 g_free(vs->dev);
 qpci_free_pc(vs->bus);
+g_free(vs);
 }
 
 static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size,
-- 
2.7.4




[Qemu-devel] [PATCH v5 2/6] tests: don't check if qtest_spapr_boot() returns NULL

2016-10-17 Thread Laurent Vivier
qtest_spapr_boot()/qtest_pc_boot()/qtest_boot() call qtest_vboot()
and qtest_vboot() calls g_malloc(),
and g_malloc() never fails:
if memory allocation fails, the application is terminated.

Signed-off-by: Laurent Vivier 
---
 tests/libqos/libqos.c | 2 ++
 tests/rtas-test.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
index 7abb482..6226546 100644
--- a/tests/libqos/libqos.c
+++ b/tests/libqos/libqos.c
@@ -10,6 +10,8 @@
 /**
  * Launch QEMU with the given command line,
  * and then set up interrupts and our guest malloc interface.
+ * Never returns NULL:
+ * Terminates the application in case an error is encountered.
  */
 QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
 {
diff --git a/tests/rtas-test.c b/tests/rtas-test.c
index ba0867a..276c87e 100644
--- a/tests/rtas-test.c
+++ b/tests/rtas-test.c
@@ -14,7 +14,6 @@ static void test_rtas_get_time_of_day(void)
 time_t t1, t2;
 
 qs = qtest_spapr_boot("-machine pseries");
-g_assert(qs != NULL);
 
 t1 = time(NULL);
 ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);
-- 
2.7.4




[Qemu-devel] [PATCH v5 4/6] tests: rename target_big_endian() as qvirtio_is_big_endian()

2016-10-17 Thread Laurent Vivier
Move the definition to libqos/virtio.h as it must be used
only with virtio functions.

Add a QVirtioDevice parameter as it will be needed to
know if the virtio device is using virtio 1.0 specification
and thus is always little-endian (to do)

Signed-off-by: Laurent Vivier 
Reviewed-by: Greg Kurz 
---
 tests/libqos/virtio-pci.c |  2 +-
 tests/libqos/virtio.h |  6 ++
 tests/libqtest.h  | 10 --
 tests/virtio-blk-test.c   | 36 ++--
 4 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index bbfed58..7aa29b1 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -86,7 +86,7 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, 
uint64_t addr)
 int i;
 uint64_t u64 = 0;
 
-if (target_big_endian()) {
+if (qvirtio_is_big_endian(d)) {
 for (i = 0; i < 8; ++i) {
 u64 |= (uint64_t)qpci_io_readb(dev->pdev,
 (void *)(uintptr_t)addr + i) << (7 - i) * 8;
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index ac4669a..3397a08 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -89,6 +89,12 @@ struct QVirtioBus {
 void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq);
 };
 
+static inline bool qvirtio_is_big_endian(QVirtioDevice *d)
+{
+/* FIXME: virtio 1.0 is always little-endian */
+return qtest_big_endian(global_qtest);
+}
+
 static inline uint32_t qvring_size(uint32_t num, uint32_t align)
 {
 return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num)
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 4be1f77..0224f06 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -881,16 +881,6 @@ static inline int64_t clock_set(int64_t val)
 return qtest_clock_set(global_qtest, val);
 }
 
-/**
- * target_big_endian:
- *
- * Returns: True if the architecture under test has a big endian configuration.
- */
-static inline bool target_big_endian(void)
-{
-return qtest_big_endian(global_qtest);
-}
-
 QDict *qmp_fd_receive(int fd);
 void qmp_fd_sendv(int fd, const char *fmt, va_list ap);
 void qmp_fd_send(int fd, const char *fmt, ...);
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 9a6f2cf..79e21c5 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -117,23 +117,23 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus 
*bus, int slot)
 return dev;
 }
 
-static inline void virtio_blk_fix_request(QVirtioBlkReq *req)
+static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req)
 {
 #ifdef HOST_WORDS_BIGENDIAN
-bool host_endian = true;
+const bool host_is_big_endian = true;
 #else
-bool host_endian = false;
+const bool host_is_big_endian = false;
 #endif
 
-if (target_big_endian() != host_endian) {
+if (qvirtio_is_big_endian(d) != host_is_big_endian) {
 req->type = bswap32(req->type);
 req->ioprio = bswap32(req->ioprio);
 req->sector = bswap64(req->sector);
 }
 }
 
-static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,
-uint64_t data_size)
+static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,
+   QVirtioBlkReq *req, uint64_t data_size)
 {
 uint64_t addr;
 uint8_t status = 0xFF;
@@ -141,7 +141,7 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, 
QVirtioBlkReq *req,
 g_assert_cmpuint(data_size % 512, ==, 0);
 addr = guest_alloc(alloc, sizeof(*req) + data_size);
 
-virtio_blk_fix_request(req);
+virtio_blk_fix_request(d, req);
 
 memwrite(addr, req, 16);
 memwrite(addr + 16, req->data, data_size);
@@ -182,7 +182,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator 
*alloc,
 req.data = g_malloc0(512);
 strcpy(req.data, "TEST");
 
-req_addr = virtio_blk_request(alloc, &req, 512);
+req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
 g_free(req.data);
 
@@ -204,7 +204,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator 
*alloc,
 req.sector = 0;
 req.data = g_malloc0(512);
 
-req_addr = virtio_blk_request(alloc, &req, 512);
+req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
 g_free(req.data);
 
@@ -234,7 +234,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator 
*alloc,
 req.data = g_malloc0(512);
 strcpy(req.data, "TEST");
 
-req_addr = virtio_blk_request(alloc, &req, 512);
+req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
 g_free(req.data);
 
@@ -254,7 +254,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator 
*alloc,
 req.sector = 1;
 req.data = g_malloc0(512);
 
-req_addr = virtio_blk_request(alloc, &req, 512);
+req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
 g_free(req.data);

[Qemu-devel] [PATCH v5 3/6] tests: move QVirtioBus pointer into QVirtioDevice

2016-10-17 Thread Laurent Vivier
This allows to not have to pass bus and device for every virtio functions.

Signed-off-by: Laurent Vivier 
Reviewed-by: Greg Kurz 
---
 tests/libqos/virtio-mmio.c |   1 +
 tests/libqos/virtio-pci.c  |   2 +
 tests/libqos/virtio.c  |  77 +++-
 tests/libqos/virtio.h  |  51 +++-
 tests/vhost-user-test.c|  33 +-
 tests/virtio-9p-test.c |  15 +++--
 tests/virtio-blk-test.c| 147 -
 tests/virtio-net-test.c|  59 +-
 tests/virtio-scsi-test.c   |  17 +++---
 9 files changed, 185 insertions(+), 217 deletions(-)

diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c
index 0cab38f..bced680 100644
--- a/tests/libqos/virtio-mmio.c
+++ b/tests/libqos/virtio-mmio.c
@@ -199,6 +199,7 @@ QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, 
uint32_t page_size)
 dev->addr = addr;
 dev->page_size = page_size;
 dev->vdev.device_type = readl(addr + QVIRTIO_MMIO_DEVICE_ID);
+dev->vdev.bus = &qvirtio_mmio;
 
 writel(addr + QVIRTIO_MMIO_GUEST_PAGE_SIZE, page_size);
 
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index 6e005c1..bbfed58 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -286,6 +286,8 @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, 
uint16_t device_type)
 QVirtioPCIDevice *dev = NULL;
 qvirtio_pci_foreach(bus, device_type, qvirtio_pci_assign_device, &dev);
 
+dev->vdev.bus = &qvirtio_pci;
+
 return dev;
 }
 
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index 105bcce..ffa2ad1 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -13,45 +13,39 @@
 #include "standard-headers/linux/virtio_config.h"
 #include "standard-headers/linux/virtio_ring.h"
 
-uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d,
-uint64_t addr)
+uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t addr)
 {
-return bus->config_readb(d, addr);
+return d->bus->config_readb(d, addr);
 }
 
-uint16_t qvirtio_config_readw(const QVirtioBus *bus, QVirtioDevice *d,
-uint64_t addr)
+uint16_t qvirtio_config_readw(QVirtioDevice *d, uint64_t addr)
 {
-return bus->config_readw(d, addr);
+return d->bus->config_readw(d, addr);
 }
 
-uint32_t qvirtio_config_readl(const QVirtioBus *bus, QVirtioDevice *d,
-uint64_t addr)
+uint32_t qvirtio_config_readl(QVirtioDevice *d, uint64_t addr)
 {
-return bus->config_readl(d, addr);
+return d->bus->config_readl(d, addr);
 }
 
-uint64_t qvirtio_config_readq(const QVirtioBus *bus, QVirtioDevice *d,
-uint64_t addr)
+uint64_t qvirtio_config_readq(QVirtioDevice *d, uint64_t addr)
 {
-return bus->config_readq(d, addr);
+return d->bus->config_readq(d, addr);
 }
 
-uint32_t qvirtio_get_features(const QVirtioBus *bus, QVirtioDevice *d)
+uint32_t qvirtio_get_features(QVirtioDevice *d)
 {
-return bus->get_features(d);
+return d->bus->get_features(d);
 }
 
-void qvirtio_set_features(const QVirtioBus *bus, QVirtioDevice *d,
-uint32_t features)
+void qvirtio_set_features(QVirtioDevice *d, uint32_t features)
 {
-bus->set_features(d, features);
+d->bus->set_features(d, features);
 }
 
-QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,
-QGuestAllocator *alloc, uint16_t index)
+QVirtQueue *qvirtqueue_setup(QVirtioDevice *d, QGuestAllocator *alloc, 
uint16_t index)
 {
-return bus->virtqueue_setup(d, alloc, index);
+return d->bus->virtqueue_setup(d, alloc, index);
 }
 
 void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,
@@ -60,40 +54,40 @@ void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue 
*vq,
 return bus->virtqueue_cleanup(vq, alloc);
 }
 
-void qvirtio_reset(const QVirtioBus *bus, QVirtioDevice *d)
+void qvirtio_reset(QVirtioDevice *d)
 {
-bus->set_status(d, 0);
-g_assert_cmphex(bus->get_status(d), ==, 0);
+d->bus->set_status(d, 0);
+g_assert_cmphex(d->bus->get_status(d), ==, 0);
 }
 
-void qvirtio_set_acknowledge(const QVirtioBus *bus, QVirtioDevice *d)
+void qvirtio_set_acknowledge(QVirtioDevice *d)
 {
-bus->set_status(d, bus->get_status(d) | VIRTIO_CONFIG_S_ACKNOWLEDGE);
-g_assert_cmphex(bus->get_status(d), ==, VIRTIO_CONFIG_S_ACKNOWLEDGE);
+d->bus->set_status(d, d->bus->get_status(d) | VIRTIO_CONFIG_S_ACKNOWLEDGE);
+g_assert_cmphex(d->bus->get_status(d), ==, VIRTIO_CONFIG_S_ACKNOWLEDGE);
 }
 
-void qvirtio_set_driver(const QVirtioBus *bus, QVirtioDevice *d)
+void qvirtio_set_driver(QVirtioDevice *d)
 {
-bus->set_status(d, bus->get_status(d) | VIRTIO_CONFIG_S_DRIVER);
-g_assert_cmp

Re: [Qemu-devel] [PATCH v5 1/6] tests: fix memory leak in virtio-scsi-test

2016-10-17 Thread Thomas Huth
On 17.10.2016 12:30, Laurent Vivier wrote:
> vs is allocated in qvirtio_scsi_pci_init() and never freed.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Greg Kurz 
> ---
>  tests/virtio-scsi-test.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
> index 79088bb..94d75b1 100644
> --- a/tests/virtio-scsi-test.c
> +++ b/tests/virtio-scsi-test.c
> @@ -64,6 +64,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
>  qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, 
> vdev));
>  g_free(vs->dev);
>  qpci_free_pc(vs->bus);
> +g_free(vs);
>  }
>  
>  static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size,
> 

Reviewed-by: Thomas Huth 




[Qemu-devel] [PATCH v5 5/6] tests: use qtest_pc_boot()/qtest_shutdown() in virtio tests

2016-10-17 Thread Laurent Vivier
This patch replaces calls to qtest_start() and qtest_end() by
calls to qtest_pc_boot() and qtest_shutdown().

This allows to initialize memory allocator and PCI interface
functions. This will ease to enable virtio tests on other
architectures by only adding a specific qtest_XXX_boot() (like
qtest_spapr_boot()).

Signed-off-by: Laurent Vivier 
Reviewed-by: Greg Kurz 
---
 tests/virtio-9p-test.c   |  50 +++-
 tests/virtio-blk-test.c  | 148 ---
 tests/virtio-net-test.c  |  39 +
 tests/virtio-scsi-test.c |  67 ++---
 4 files changed, 128 insertions(+), 176 deletions(-)

diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index 2341622..851ec99 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -10,62 +10,57 @@
 #include "qemu/osdep.h"
 #include "libqtest.h"
 #include "qemu-common.h"
-#include "libqos/pci-pc.h"
+#include "libqos/libqos-pc.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
-#include "libqos/malloc.h"
-#include "libqos/malloc-pc.h"
 #include "standard-headers/linux/virtio_ids.h"
 #include "standard-headers/linux/virtio_pci.h"
 
 static const char mount_tag[] = "qtest";
 static char *test_share;
 
-static void qvirtio_9p_start(void)
+
+static QOSState *qvirtio_9p_start(void)
 {
-char *args;
+const char *cmd = "-fsdev local,id=fsdev0,security_model=none,path=%s "
+  "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=%s";
 
 test_share = g_strdup("/tmp/qtest.XX");
 g_assert_nonnull(mkdtemp(test_share));
 
-args = g_strdup_printf("-fsdev local,id=fsdev0,security_model=none,path=%s 
"
-   "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=%s",
-   test_share, mount_tag);
-
-qtest_start(args);
-g_free(args);
+return qtest_pc_boot(cmd, test_share, mount_tag);
 }
 
-static void qvirtio_9p_stop(void)
+static void qvirtio_9p_stop(QOSState *qs)
 {
-qtest_end();
+qtest_shutdown(qs);
 rmdir(test_share);
 g_free(test_share);
 }
 
 static void pci_nop(void)
 {
-qvirtio_9p_start();
-qvirtio_9p_stop();
+QOSState *qs;
+
+qs = qvirtio_9p_start();
+qvirtio_9p_stop(qs);
 }
 
 typedef struct {
 QVirtioDevice *dev;
-QGuestAllocator *alloc;
-QPCIBus *bus;
+QOSState *qs;
 QVirtQueue *vq;
 } QVirtIO9P;
 
-static QVirtIO9P *qvirtio_9p_pci_init(void)
+static QVirtIO9P *qvirtio_9p_pci_init(QOSState *qs)
 {
 QVirtIO9P *v9p;
 QVirtioPCIDevice *dev;
 
 v9p = g_new0(QVirtIO9P, 1);
-v9p->alloc = pc_alloc_init();
-v9p->bus = qpci_init_pc(NULL);
 
-dev = qvirtio_pci_device_find(v9p->bus, VIRTIO_ID_9P);
+v9p->qs = qs;
+dev = qvirtio_pci_device_find(v9p->qs->pcibus, VIRTIO_ID_9P);
 g_assert_nonnull(dev);
 g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_9P);
 v9p->dev = (QVirtioDevice *) dev;
@@ -75,17 +70,15 @@ static QVirtIO9P *qvirtio_9p_pci_init(void)
 qvirtio_set_acknowledge(v9p->dev);
 qvirtio_set_driver(v9p->dev);
 
-v9p->vq = qvirtqueue_setup(v9p->dev, v9p->alloc, 0);
+v9p->vq = qvirtqueue_setup(v9p->dev, v9p->qs->alloc, 0);
 return v9p;
 }
 
 static void qvirtio_9p_pci_free(QVirtIO9P *v9p)
 {
-qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->alloc);
-pc_alloc_uninit(v9p->alloc);
+qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->qs->alloc);
 qvirtio_pci_device_disable(container_of(v9p->dev, QVirtioPCIDevice, vdev));
 g_free(v9p->dev);
-qpci_free_pc(v9p->bus);
 g_free(v9p);
 }
 
@@ -96,9 +89,10 @@ static void pci_basic_config(void)
 size_t tag_len;
 char *tag;
 int i;
+QOSState *qs;
 
-qvirtio_9p_start();
-v9p = qvirtio_9p_pci_init();
+qs = qvirtio_9p_start();
+v9p = qvirtio_9p_pci_init(qs);
 
 addr = ((QVirtioPCIDevice *) v9p->dev)->addr + 
VIRTIO_PCI_CONFIG_OFF(false);
 tag_len = qvirtio_config_readw(v9p->dev,
@@ -114,7 +108,7 @@ static void pci_basic_config(void)
 g_free(tag);
 
 qvirtio_9p_pci_free(v9p);
-qvirtio_9p_stop();
+qvirtio_9p_stop(qs);
 }
 
 int main(int argc, char **argv)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 79e21c5..2382eb5 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -10,12 +10,10 @@
 
 #include "qemu/osdep.h"
 #include "libqtest.h"
+#include "libqos/libqos-pc.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
 #include "libqos/virtio-mmio.h"
-#include "libqos/pci-pc.h"
-#include "libqos/malloc.h"
-#include "libqos/malloc-pc.h"
 #include "libqos/malloc-generic.h"
 #include "qemu/bswap.h"
 #include "standard-headers/linux/virtio_ids.h"
@@ -58,24 +56,21 @@ static char *drive_create(void)
 return tmp_path;
 }
 
-static QPCIBus *pci_test_start(void)
+static QOSState *pci_test_start(void)
 {
-char *cmdline;
+QOSState *qs;
 char *tmp_path;
+const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "
+ 

Re: [Qemu-devel] [PATCH v5 2/6] tests: don't check if qtest_spapr_boot() returns NULL

2016-10-17 Thread Thomas Huth
On 17.10.2016 12:30, Laurent Vivier wrote:
> qtest_spapr_boot()/qtest_pc_boot()/qtest_boot() call qtest_vboot()
> and qtest_vboot() calls g_malloc(),
> and g_malloc() never fails:
> if memory allocation fails, the application is terminated.
> 
> Signed-off-by: Laurent Vivier 
> ---
>  tests/libqos/libqos.c | 2 ++
>  tests/rtas-test.c | 1 -
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
> index 7abb482..6226546 100644
> --- a/tests/libqos/libqos.c
> +++ b/tests/libqos/libqos.c
> @@ -10,6 +10,8 @@
>  /**
>   * Launch QEMU with the given command line,
>   * and then set up interrupts and our guest malloc interface.
> + * Never returns NULL:
> + * Terminates the application in case an error is encountered.
>   */
>  QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
>  {
> diff --git a/tests/rtas-test.c b/tests/rtas-test.c
> index ba0867a..276c87e 100644
> --- a/tests/rtas-test.c
> +++ b/tests/rtas-test.c
> @@ -14,7 +14,6 @@ static void test_rtas_get_time_of_day(void)
>  time_t t1, t2;
>  
>  qs = qtest_spapr_boot("-machine pseries");
> -g_assert(qs != NULL);
>  
>  t1 = time(NULL);
>  ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);
> 

Reviewed-by: Thomas Huth 




Re: [Qemu-devel] Provide safe_syscall for s390x

2016-10-17 Thread Michael Tokarev
17.10.2016 11:26, Thomas Huth пишет:
> On 14.10.2016 20:58, Michael Tokarev wrote:
>> Hi.
>>
>> This commit: c9bc3437a905b660561a26cd4ecc64579843267b
>> Author: Richard Henderson 
>> Date:   Tue Jun 21 17:32:12 2016 -0700
>>
>> linux-user: Provide safe_syscall for s390x
>>
>> does not build on debian unstable porterbox for s390x, with
>> the following error message:
>>
>> linux-user/host/s390x/safe-syscall.inc.S: Assembler messages:
>> linux-user/host/s390x/safe-syscall.inc.S:75: Error: Unrecognized opcode:
>> `lt'
>> rules.mak:72: recipe for target 'linux-user/safe-syscall.o' failed
>>
>> Since I know nothing about s390, I've no idea what's at fault
>> here... :)  Thought I'd report this :)
> 
> "lt" seems to be a newer s390x opcode which has been added to the
> architecture within the last ten years or so. So maybe you've got to add
> some "-march=xxx" flag when compiling this file?
> Could you maybe start with finding out the exact comand line that is
> used to compile this file?

Here we go:

cc -I/«BUILDDIR»/qemu-2.7+dfsg/tcg -I/«BUILDDIR»/qemu-2.7+dfsg/tcg/s390
-I/«BUILDDIR»/qemu-2.7+dfsg/linux-headers
-I/«BUILDDIR»/qemu-2.7+dfsg/qemu-build/linux-headers -I.
-I/«BUILDDIR»/qemu-2.7+dfsg -I/«BUILDDIR»/qemu-2.7+dfsg/include
-I/«BUILDDIR»/qemu-2.7+dfsg/linux-user -Ilinux-user
-I/usr/include/pixman-1  -DHAS_LIBSSH2_SFTP_FSYNC -m64 -D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes
-fno-strict-aliasing -fno-common  -g -O2
-fdebug-prefix-map=/«BUILDDIR»/qemu-2.7+dfsg=. -fstack-protector-strong
-Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2
-DCONFIG_QEMU_DATAPATH='"/usr/share/qemu:/usr/share/seabios:/usr/lib/ipxe/qemu"'
-DVENDOR_DEBIAN -Wendif-labels -Wno-shift-negative-value
-Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration
-Wold-style-definition -Wtype-limits -fstack-protector-strong
-I/usr/include/p11-kit-1-I/usr/include/libpng16
-I/usr/include/cacard -I/usr/include/libusb-1.0   -I../linux-headers
-I.. -I/«BUILDDIR»/qemu-2.7+dfsg/target-alpha -DNEED_CPU_H
-I/«BUILDDIR»/qemu-2.7+dfsg/include
-I/«BUILDDIR»/qemu-2.7+dfsg/linux-user/alpha
-I/«BUILDDIR»/qemu-2.7+dfsg/linux-user/host/s390x
-I/«BUILDDIR»/qemu-2.7+dfsg/linux-user -MMD -MP -MT
linux-user/safe-syscall.o -MF linux-user/safe-syscall.d -O2
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -pthread -I/usr/include/glib-2.0
-I/usr/lib/s390x-linux-gnu/glib-2.0/include -pthread
-I/usr/include/glib-2.0 -I/usr/lib/s390x-linux-gnu/glib-2.0/include -g
-c -o linux-user/safe-syscall.o
/«BUILDDIR»/qemu-2.7+dfsg/linux-user/safe-syscall.S
/«BUILDDIR»/qemu-2.7+dfsg/linux-user/host/s390x/safe-syscall.inc.S:
Assembler messages:
/«BUILDDIR»/qemu-2.7+dfsg/linux-user/host/s390x/safe-syscall.inc.S:75:
Error: Unrecognized opcode: `lt'
/«BUILDDIR»/qemu-2.7+dfsg/rules.mak:72: recipe for target
'linux-user/safe-syscall.o' failed
make[2]: *** [linux-user/safe-syscall.o] Error 1

(cc is gcc 6.2.0)

I've no idea which -march is the default and what choices are available.

/mjt



[Qemu-devel] [PATCH v5 6/6] tests: enable virtio tests on SPAPR

2016-10-17 Thread Laurent Vivier
but disable MSI-X tests on SPAPR as we can't check the result
(the memory region used on PC is not readable on SPAPR).

Signed-off-by: Laurent Vivier 
---
 tests/Makefile.include|  3 ++-
 tests/libqos/virtio-pci.c | 24 ++--
 tests/virtio-9p-test.c| 12 +++-
 tests/virtio-blk-test.c   | 25 -
 tests/virtio-net-test.c   | 18 --
 tests/virtio-rng-test.c   |  7 ++-
 tests/virtio-scsi-test.c  | 12 +++-
 7 files changed, 88 insertions(+), 13 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index a7c..4480b08 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -278,6 +278,7 @@ check-qtest-ppc64-y += tests/usb-hcd-uhci-test$(EXESUF)
 gcov-files-ppc64-y += hw/usb/hcd-uhci.c
 check-qtest-ppc64-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-ppc64-y += hw/usb/hcd-xhci.c
+check-qtest-ppc64-y += $(check-qtest-virtio-y)
 
 check-qtest-sh4-y = tests/endianness-test$(EXESUF)
 
@@ -604,7 +605,7 @@ libqos-pc-obj-y += tests/libqos/ahci.o
 libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
 libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o
 libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o
-libqos-virtio-obj-y = $(libqos-pc-obj-y) tests/libqos/virtio.o 
tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o 
tests/libqos/malloc-generic.o
+libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) 
tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o 
tests/libqos/malloc-generic.o
 
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
 tests/rtc-test$(EXESUF): tests/rtc-test.o
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index 7aa29b1..7e60b3a 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -68,16 +68,36 @@ static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, 
uint64_t addr)
 return qpci_io_readb(dev->pdev, (void *)(uintptr_t)addr);
 }
 
+/* PCI is always read in little-endian order
+ * but virtio ( < 1.0) is in guest order
+ * so with a big-endian guest the order has been reversed,
+ * reverse it again
+ * virtio-1.0 is always little-endian, like PCI, but this
+ * case will be managed inside qvirtio_is_big_endian()
+ */
+
 static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t addr)
 {
 QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-return qpci_io_readw(dev->pdev, (void *)(uintptr_t)addr);
+uint16_t value;
+
+value = qpci_io_readw(dev->pdev, (void *)(uintptr_t)addr);
+if (qvirtio_is_big_endian(d)) {
+value = bswap16(value);
+}
+return value;
 }
 
 static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t addr)
 {
 QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-return qpci_io_readl(dev->pdev, (void *)(uintptr_t)addr);
+uint32_t value;
+
+value = qpci_io_readl(dev->pdev, (void *)(uintptr_t)addr);
+if (qvirtio_is_big_endian(d)) {
+value = bswap32(value);
+}
+return value;
 }
 
 static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index 851ec99..693920a 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -11,6 +11,7 @@
 #include "libqtest.h"
 #include "qemu-common.h"
 #include "libqos/libqos-pc.h"
+#include "libqos/libqos-spapr.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
 #include "standard-headers/linux/virtio_ids.h"
@@ -22,13 +23,22 @@ static char *test_share;
 
 static QOSState *qvirtio_9p_start(void)
 {
+const char *arch = qtest_get_arch();
 const char *cmd = "-fsdev local,id=fsdev0,security_model=none,path=%s "
   "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=%s";
 
 test_share = g_strdup("/tmp/qtest.XX");
 g_assert_nonnull(mkdtemp(test_share));
 
-return qtest_pc_boot(cmd, test_share, mount_tag);
+if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+return qtest_pc_boot(cmd, test_share, mount_tag);
+}
+if (strcmp(arch, "ppc64") == 0) {
+return qtest_spapr_boot(cmd, test_share, mount_tag);
+}
+
+g_printerr("virtio-9p tests are only available on x86 or ppc64\n");
+exit(EXIT_FAILURE);
 }
 
 static void qvirtio_9p_stop(QOSState *qs)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 2382eb5..f737c40 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -11,6 +11,7 @@
 #include "qemu/osdep.h"
 #include "libqtest.h"
 #include "libqos/libqos-pc.h"
+#include "libqos/libqos-spapr.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
 #include "libqos/virtio-mmio.h"
@@ -59,6 +60,7 @@ static char *drive_create(void)
 static QOSState *pci_test_start(void)
 {
 QOSState *qs;
+const char *arch = qtest_get_arch();
 char *tmp_path;
 const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "

[Qemu-devel] is there a way to optimize vhost of virtio-net

2016-10-17 Thread yue
hi, jasowang:
 according to my test , the vm's network performance is just 20% of 
physical ethernet, the thread of vhost  easily eat up 100% cpu when under 
pressure.
when using multi queue(two queues) the performance goes up by 50%, but it uses 
more threads.
if we can come to a conclusion that vhost is bottomneck?  or do you have any 
idea to improve , first we do not need to care how  violent  the idea   is.




thanks

[Qemu-devel] [PATCH v8 08/11] virtio-crypto: add control queue handler

2016-10-17 Thread Gonglei
Realize the symmetric algorithm control queue handler,
including plain cipher and chainning algorithms.

Currently the control queue is used to create and
close session for symmetric algorithm.

Signed-off-by: Gonglei 
---
 hw/virtio/virtio-crypto.c | 290 +-
 1 file changed, 289 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 2032d31..4be65e0 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -23,6 +23,294 @@
 
 #define VIRTIO_CRYPTO_VM_VERSION 1
 
+/*
+ * Transfer virtqueue index to crypto queue index.
+ * The control virtqueue is after the data virtqueues
+ * so the input value doesn't need to be adjusted
+ */
+static inline int virtio_crypto_vq2q(int queue_index)
+{
+return queue_index;
+}
+
+static int
+virtio_crypto_cipher_session_helper(VirtIODevice *vdev,
+   CryptoDevBackendSymSessionInfo *info,
+   struct virtio_crypto_cipher_session_para *cipher_para,
+   struct iovec **iov, unsigned int *out_num)
+{
+unsigned int num = *out_num;
+
+info->cipher_alg = virtio_ldl_p(vdev, &cipher_para->algo);
+info->key_len = virtio_ldl_p(vdev, &cipher_para->keylen);
+info->direction = virtio_ldl_p(vdev, &cipher_para->op);
+DPRINTF("cipher_alg=%" PRIu32 ", info->direction=%" PRIu32 "\n",
+ info->cipher_alg, info->direction);
+/* Get cipher key */
+if (info->key_len > 0) {
+size_t s;
+DPRINTF("keylen=%" PRIu32 "\n", info->key_len);
+
+info->cipher_key = g_malloc(info->key_len);
+s = iov_to_buf(*iov, num, 0, info->cipher_key, info->key_len);
+if (unlikely(s != info->key_len)) {
+virtio_error(vdev, "virtio-crypto cipher key incorrect");
+return -EFAULT;
+}
+iov_discard_front(iov, &num, info->key_len);
+*out_num = num;
+}
+
+return 0;
+}
+
+static int64_t
+virtio_crypto_create_sym_session(VirtIOCrypto *vcrypto,
+   struct virtio_crypto_sym_create_session_req *sess_req,
+   uint32_t queue_id,
+   uint32_t opcode,
+   struct iovec *iov, unsigned int out_num)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto);
+CryptoDevBackendSymSessionInfo info;
+int64_t session_id;
+int queue_index;
+uint32_t op_type;
+Error *local_err = NULL;
+int ret;
+
+memset(&info, 0, sizeof(info));
+op_type = virtio_ldl_p(vdev, &sess_req->op_type);
+info.op_type = op_type;
+info.op_code = opcode;
+
+if (op_type == VIRTIO_CRYPTO_SYM_OP_CIPHER) {
+ret = virtio_crypto_cipher_session_helper(vdev, &info,
+   &sess_req->u.cipher.para,
+   &iov, &out_num);
+if (ret < 0) {
+ret = -EFAULT;
+goto err;
+}
+} else if (op_type == VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING) {
+size_t s;
+/* cipher part */
+ret = virtio_crypto_cipher_session_helper(vdev, &info,
+   &sess_req->u.chain.para.cipher_param,
+   &iov, &out_num);
+if (ret < 0) {
+ret = -EFAULT;
+goto err;
+}
+/* hash part */
+info.alg_chain_order = virtio_ldl_p(vdev,
+   
&sess_req->u.chain.para.alg_chain_order);
+info.add_len = virtio_ldl_p(vdev, &sess_req->u.chain.para.aad_len);
+info.hash_mode = virtio_ldl_p(vdev, &sess_req->u.chain.para.hash_mode);
+if (info.hash_mode == VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH) {
+info.hash_alg = virtio_ldl_p(vdev,
+   &sess_req->u.chain.para.u.mac_param.algo);
+info.auth_key_len = virtio_ldl_p(vdev,
+ &sess_req->u.chain.para.u.mac_param.auth_key_len);
+info.hash_result_len = virtio_ldl_p(vdev,
+   
&sess_req->u.chain.para.u.mac_param.hash_result_len);
+/* get auth key */
+if (info.auth_key_len > 0) {
+DPRINTF("auth_keylen=%" PRIu32 "\n", info.auth_key_len);
+info.auth_key = g_malloc(info.auth_key_len);
+s = iov_to_buf(iov, out_num, 0, info.auth_key,
+   info.auth_key_len);
+if (unlikely(s != info.auth_key_len)) {
+virtio_error(vdev,
+  "virtio-crypto authenticated key incorrect");
+ret = -EFAULT;
+goto err;
+}
+iov_discard_front(&iov, &out_num, info.auth_key_len);
+}
+} else if (info.hash_mode == VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN) {
+info.hash_alg = virtio_ldl_p(vdev,
+ &sess_req->u.chain.para.u.hash_param.algo);
+info.hash_result_len = virtio_ldl_p(vdev,
+&sess_req->u.chain.para.u.h

[Qemu-devel] [PATCH v8 07/11] virtio-crypto: set capacity of algorithms supported

2016-10-17 Thread Gonglei
Expose the capacity of algorithms supported by
virtio crypto device to the frontend driver using
pci configuration space.

Signed-off-by: Gonglei 
---
 hw/virtio/virtio-crypto.c | 40 ++-
 include/hw/virtio/virtio-crypto.h | 11 +++
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 109a504..2032d31 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -42,6 +42,22 @@ static void virtio_crypto_reset(VirtIODevice *vdev)
 }
 }
 
+static void virtio_crypto_init_config(VirtIODevice *vdev)
+{
+VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
+
+vcrypto->conf.crypto_services =
+ vcrypto->conf.cryptodev->conf.crypto_services;
+vcrypto->conf.cipher_algo_l =
+ vcrypto->conf.cryptodev->conf.cipher_algo_l;
+vcrypto->conf.cipher_algo_h =
+ vcrypto->conf.cryptodev->conf.cipher_algo_h;
+vcrypto->conf.hash_algo = vcrypto->conf.cryptodev->conf.hash_algo;
+vcrypto->conf.mac_algo_l = vcrypto->conf.cryptodev->conf.mac_algo_l;
+vcrypto->conf.mac_algo_h = vcrypto->conf.cryptodev->conf.mac_algo_h;
+vcrypto->conf.aead_algo = vcrypto->conf.cryptodev->conf.aead_algo;
+}
+
 static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
 {
 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -75,6 +91,8 @@ static void virtio_crypto_device_realize(DeviceState *dev, 
Error **errp)
 } else {
 vcrypto->status |= VIRTIO_CRYPTO_S_HW_READY;
 }
+
+virtio_crypto_init_config(vdev);
 }
 
 static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp)
@@ -100,7 +118,27 @@ static Property virtio_crypto_properties[] = {
 
 static void virtio_crypto_get_config(VirtIODevice *vdev, uint8_t *config)
 {
-
+VirtIOCrypto *c = VIRTIO_CRYPTO(vdev);
+struct virtio_crypto_config crypto_cfg;
+
+virtio_stl_p(vdev, &crypto_cfg.status, c->status);
+virtio_stl_p(vdev, &crypto_cfg.max_dataqueues, c->max_queues);
+virtio_stl_p(vdev, &crypto_cfg.crypto_services,
+   c->conf.crypto_services);
+virtio_stl_p(vdev, &crypto_cfg.cipher_algo_l,
+   c->conf.cipher_algo_l);
+virtio_stl_p(vdev, &crypto_cfg.cipher_algo_h,
+   c->conf.cipher_algo_h);
+virtio_stl_p(vdev, &crypto_cfg.hash_algo,
+   c->conf.hash_algo);
+virtio_stl_p(vdev, &crypto_cfg.mac_algo_l,
+   c->conf.mac_algo_l);
+virtio_stl_p(vdev, &crypto_cfg.mac_algo_h,
+   c->conf.mac_algo_h);
+virtio_stl_p(vdev, &crypto_cfg.aead_algo,
+   c->conf.aead_algo);
+
+memcpy(config, &crypto_cfg, c->config_size);
 }
 
 static void virtio_crypto_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/virtio/virtio-crypto.h 
b/include/hw/virtio/virtio-crypto.h
index 4652c21..4a4b3da 100644
--- a/include/hw/virtio/virtio-crypto.h
+++ b/include/hw/virtio/virtio-crypto.h
@@ -39,6 +39,17 @@ do { \
 
 typedef struct VirtIOCryptoConf {
 CryptoDevBackend *cryptodev;
+
+/* Supported service mask */
+uint32_t crypto_services;
+
+/* Detailed algorithms mask */
+uint32_t cipher_algo_l;
+uint32_t cipher_algo_h;
+uint32_t hash_algo;
+uint32_t mac_algo_l;
+uint32_t mac_algo_h;
+uint32_t aead_algo;
 } VirtIOCryptoConf;
 
 struct VirtIOCrypto;
-- 
1.8.3.1





[Qemu-devel] [PATCH v8 03/11] virtio-crypto: introduce virtio_crypto.h

2016-10-17 Thread Gonglei
Introduce the virtio_crypto.h which follows
virtio-crypto specification.

Signed-off-by: Gonglei 
---
 include/standard-headers/linux/virtio_crypto.h | 420 +
 1 file changed, 420 insertions(+)
 create mode 100644 include/standard-headers/linux/virtio_crypto.h

diff --git a/include/standard-headers/linux/virtio_crypto.h 
b/include/standard-headers/linux/virtio_crypto.h
new file mode 100644
index 000..a9ed885
--- /dev/null
+++ b/include/standard-headers/linux/virtio_crypto.h
@@ -0,0 +1,420 @@
+#ifndef _LINUX_VIRTIO_CRYPTO_H
+#define _LINUX_VIRTIO_CRYPTO_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 
IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+#include "standard-headers/linux/types.h"
+#include "standard-headers/linux/virtio_config.h"
+#include "standard-headers/linux/virtio_types.h"
+
+
+#define VIRTIO_CRYPTO_SERVICE_CIPHER 0
+#define VIRTIO_CRYPTO_SERVICE_HASH 1
+#define VIRTIO_CRYPTO_SERVICE_MAC  2
+#define VIRTIO_CRYPTO_SERVICE_AEAD 3
+
+#define VIRTIO_CRYPTO_OPCODE(service, op)   (((service) << 8) | (op))
+
+struct virtio_crypto_ctrl_header {
+#define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02)
+#define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03)
+#define VIRTIO_CRYPTO_HASH_CREATE_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02)
+#define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03)
+#define VIRTIO_CRYPTO_MAC_CREATE_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02)
+#define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03)
+#define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02)
+#define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \
+   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03)
+__virtio32 opcode;
+__virtio32 algo;
+__virtio32 flag;
+/* data virtqueue id */
+__virtio32 queue_id;
+};
+
+struct virtio_crypto_cipher_session_para {
+#define VIRTIO_CRYPTO_NO_CIPHER 0
+#define VIRTIO_CRYPTO_CIPHER_ARC4   1
+#define VIRTIO_CRYPTO_CIPHER_AES_ECB2
+#define VIRTIO_CRYPTO_CIPHER_AES_CBC3
+#define VIRTIO_CRYPTO_CIPHER_AES_CTR4
+#define VIRTIO_CRYPTO_CIPHER_DES_ECB5
+#define VIRTIO_CRYPTO_CIPHER_DES_CBC6
+#define VIRTIO_CRYPTO_CIPHER_3DES_ECB   7
+#define VIRTIO_CRYPTO_CIPHER_3DES_CBC   8
+#define VIRTIO_CRYPTO_CIPHER_3DES_CTR   9
+#define VIRTIO_CRYPTO_CIPHER_KASUMI_F8  10
+#define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA211
+#define VIRTIO_CRYPTO_CIPHER_AES_F8 12
+#define VIRTIO_CRYPTO_CIPHER_AES_XTS13
+#define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3   14
+__virtio32 algo;
+/* length of key */
+__virtio32 keylen;
+
+#define VIRTIO_CRYPTO_OP_ENCRYPT  1
+#define VIRTIO_CRYPTO_OP_DECRYPT  2
+/* encrypt or decrypt */
+__virtio32 op;
+__virtio32 padding;
+};
+
+struct virtio_crypto_session_input {
+/* Device-writable part */
+__virtio64 session_id;
+__virtio32 status;
+__virtio32 padding;
+};
+
+struct virtio_crypto_cipher_session_req {
+struct virtio_crypto_cipher_session_para para;
+};
+
+struct virtio_crypto_hash_session_para {
+#define VIRTIO_CRYPTO_NO_HASH

[Qemu-devel] [PATCH v8 06/11] virtio-crypto-pci: add virtio crypto pci support

2016-10-17 Thread Gonglei
This patch adds virtio-crypto-pci, which is the pci proxy for the virtio
crypto device.

Signed-off-by: Gonglei 
---
 hw/virtio/Makefile.objs   |  1 +
 hw/virtio/virtio-crypto-pci.c | 77 +++
 hw/virtio/virtio-pci.h| 15 +
 3 files changed, 93 insertions(+)
 create mode 100644 hw/virtio/virtio-crypto-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 968f392..95c4c30 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -8,3 +8,4 @@ obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
 
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
 obj-y += virtio-crypto.o
+obj-$(CONFIG_VIRTIO_PCI) += virtio-crypto-pci.o
diff --git a/hw/virtio/virtio-crypto-pci.c b/hw/virtio/virtio-crypto-pci.c
new file mode 100644
index 000..21d9984
--- /dev/null
+++ b/hw/virtio/virtio-crypto-pci.c
@@ -0,0 +1,77 @@
+/*
+ * Virtio crypto device
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ * Authors:
+ *Gonglei 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ *
+ */
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-pci.h"
+#include "hw/virtio/virtio-crypto.h"
+#include "qapi/error.h"
+
+static Property virtio_crypto_pci_properties[] = {
+DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VirtIOCryptoPCI *vcrypto = VIRTIO_CRYPTO_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(&vcrypto->vdev);
+
+qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
+virtio_pci_force_virtio_1(vpci_dev);
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+object_property_set_link(OBJECT(vcrypto),
+ OBJECT(vcrypto->vdev.conf.cryptodev), "cryptodev",
+ NULL);
+}
+
+static void virtio_crypto_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+k->realize = virtio_crypto_pci_realize;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->props = virtio_crypto_pci_properties;
+
+pcidev_k->class_id = PCI_CLASS_OTHERS;
+}
+
+static void virtio_crypto_initfn(Object *obj)
+{
+VirtIOCryptoPCI *dev = VIRTIO_CRYPTO_PCI(obj);
+
+virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_CRYPTO);
+object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev),
+  "cryptodev", &error_abort);
+}
+
+static const TypeInfo virtio_crypto_pci_info = {
+.name  = TYPE_VIRTIO_CRYPTO_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VirtIOCryptoPCI),
+.instance_init = virtio_crypto_initfn,
+.class_init= virtio_crypto_pci_class_init,
+};
+
+static void virtio_crypto_pci_register_types(void)
+{
+type_register_static(&virtio_crypto_pci_info);
+}
+type_init(virtio_crypto_pci_register_types)
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index b4edea6..27801f0 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -25,6 +25,8 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-input.h"
 #include "hw/virtio/virtio-gpu.h"
+#include "hw/virtio/virtio-crypto.h"
+
 #ifdef CONFIG_VIRTFS
 #include "hw/9pfs/virtio-9p.h"
 #endif
@@ -48,6 +50,7 @@ typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
 typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 typedef struct VHostVSockPCI VHostVSockPCI;
+typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
 
 /* virtio-pci-bus */
 
@@ -352,6 +355,18 @@ struct VHostVSockPCI {
 };
 #endif
 
+/*
+ * virtio-crypto-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
+#define VIRTIO_CRYPTO_PCI(obj) \
+OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
+
+struct VirtIOCryptoPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOCrypto vdev;
+};
+
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION  0
 
-- 
1.8.3.1





[Qemu-devel] [PATCH v8 05/11] virtio-crypto: add virtio crypto device emulation

2016-10-17 Thread Gonglei
Introduce the virtio crypto realization, I'll
finish the core code in the following patches. The
thoughts came from virtio net realization.

For more information see:
http://qemu-project.org/Features/VirtioCrypto

Signed-off-by: Gonglei 
---
 hw/virtio/Makefile.objs |   1 +
 hw/virtio/virtio-crypto.c   | 151 
 include/hw/virtio/virtio-crypto.h   |  73 ++
 include/standard-headers/linux/virtio_ids.h |   2 +-
 4 files changed, 226 insertions(+), 1 deletion(-)
 create mode 100644 hw/virtio/virtio-crypto.c
 create mode 100644 include/hw/virtio/virtio-crypto.h

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index e716308..968f392 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -7,3 +7,4 @@ obj-y += virtio.o virtio-balloon.o
 obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
 
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
+obj-y += virtio-crypto.o
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
new file mode 100644
index 000..109a504
--- /dev/null
+++ b/hw/virtio/virtio-crypto.c
@@ -0,0 +1,151 @@
+/*
+ * Virtio crypto Support
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ * Authors:
+ *Gonglei 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "qemu/iov.h"
+#include "hw/qdev.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-crypto.h"
+#include "hw/virtio/virtio-access.h"
+#include "standard-headers/linux/virtio_ids.h"
+
+#define VIRTIO_CRYPTO_VM_VERSION 1
+
+static uint64_t virtio_crypto_get_features(VirtIODevice *vdev,
+   uint64_t features,
+   Error **errp)
+{
+return features;
+}
+
+static void virtio_crypto_reset(VirtIODevice *vdev)
+{
+VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
+/* multiqueue is disabled by default */
+vcrypto->curr_queues = 1;
+if (!vcrypto->cryptodev->ready) {
+vcrypto->status &= ~VIRTIO_CRYPTO_S_HW_READY;
+} else {
+vcrypto->status |= VIRTIO_CRYPTO_S_HW_READY;
+}
+}
+
+static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(dev);
+int i;
+
+vcrypto->cryptodev = vcrypto->conf.cryptodev;
+if (vcrypto->cryptodev == NULL) {
+error_setg(errp, "'cryptodev' parameter expects a valid object");
+return;
+}
+
+vcrypto->max_queues = MAX(vcrypto->cryptodev->conf.peers.queues, 1);
+if (vcrypto->max_queues + 1 > VIRTIO_QUEUE_MAX) {
+error_setg(errp, "Invalid number of queues (= %" PRIu16 "), "
+   "must be a postive integer less than %d.",
+   vcrypto->max_queues, VIRTIO_QUEUE_MAX);
+return;
+}
+
+virtio_init(vdev, "virtio-crypto", VIRTIO_ID_CRYPTO, vcrypto->config_size);
+vcrypto->curr_queues = 1;
+
+for (i = 0; i < vcrypto->max_queues; i++) {
+virtio_add_queue(vdev, 1024, NULL);
+}
+
+vcrypto->ctrl_vq = virtio_add_queue(vdev, 64, NULL);
+if (!vcrypto->cryptodev->ready) {
+vcrypto->status &= ~VIRTIO_CRYPTO_S_HW_READY;
+} else {
+vcrypto->status |= VIRTIO_CRYPTO_S_HW_READY;
+}
+}
+
+static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp)
+{
+VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+
+virtio_cleanup(vdev);
+}
+
+static const VMStateDescription vmstate_virtio_crypto = {
+.name = "virtio-crypto",
+.minimum_version_id = VIRTIO_CRYPTO_VM_VERSION,
+.version_id = VIRTIO_CRYPTO_VM_VERSION,
+.fields = (VMStateField[]) {
+VMSTATE_VIRTIO_DEVICE,
+VMSTATE_END_OF_LIST()
+},
+};
+
+static Property virtio_crypto_properties[] = {
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_crypto_get_config(VirtIODevice *vdev, uint8_t *config)
+{
+
+}
+
+static void virtio_crypto_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+
+dc->props = virtio_crypto_properties;
+dc->vmsd = &vmstate_virtio_crypto;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+vdc->realize = virtio_crypto_device_realize;
+vdc->unrealize = virtio_crypto_device_unrealize;
+vdc->get_config = virtio_crypto_get_config;
+vdc->get_features = virtio_crypto_get_features;
+vdc->reset = virtio_crypto_reset;
+}
+
+static void virtio_crypto_instance_init(Object *obj)
+{
+VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(obj);
+
+/*
+ * The default config_size is sizeof(struct virtio_crypto_config).
+ * Can be overriden with virtio_crypto_set_config_size.
+ */
+vcrypto->config_size = 

Re: [Qemu-devel] Provide safe_syscall for s390x

2016-10-17 Thread Michael Tokarev
17.10.2016 13:39, Michael Tokarev wrote:

> (cc is gcc 6.2.0)
> 
> I've no idea which -march is the default and what choices are available.

$ gcc -march=?
gcc: error: unrecognized argument in option '-march=?'
gcc: note: valid arguments to '-march=' are: g5 g6 native z10 z13 z196
z9-109 z9-ec z900 z990 zEC12

I guess g5 is the default?

Thanks,

/mjt



[Qemu-devel] [PATCH v8 04/11] cryptodev: introduce a new cryptodev backend

2016-10-17 Thread Gonglei
The new cryptodev backend named cryptodev-builtin,
which realized by QEMU cipher APIs. These APIs can
be backed by either nettle or gcrypt.

Signed-off-by: Gonglei 
---
 backends/Makefile.objs   |   1 +
 backends/cryptodev-builtin.c | 351 +++
 qemu-options.hx  |  18 +++
 3 files changed, 370 insertions(+)
 create mode 100644 backends/cryptodev-builtin.c

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 55bd43d..1846998 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -11,3 +11,4 @@ common-obj-y += hostmem.o hostmem-ram.o
 common-obj-$(CONFIG_LINUX) += hostmem-file.o
 
 common-obj-y += cryptodev.o
+common-obj-y += cryptodev-builtin.o
diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c
new file mode 100644
index 000..9ad79ad
--- /dev/null
+++ b/backends/cryptodev-builtin.c
@@ -0,0 +1,351 @@
+/*
+ * QEMU Cryptodev backend for QEMU cipher APIs
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ * Authors:
+ *Gonglei 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/cryptodev.h"
+#include "hw/boards.h"
+#include "qapi/error.h"
+#include "standard-headers/linux/virtio_crypto.h"
+#include "crypto/cipher.h"
+
+
+/**
+ * @TYPE_CRYPTODEV_BACKEND_BUILTIN:
+ * name of backend that uses QEMU cipher API
+ */
+#define TYPE_CRYPTODEV_BACKEND_BUILTIN "cryptodev-backend-builtin"
+
+#define CRYPTODEV_BACKEND_BUILTIN(obj) \
+OBJECT_CHECK(CryptoDevBackendBuiltin, \
+ (obj), TYPE_CRYPTODEV_BACKEND_BUILTIN)
+
+typedef struct CryptoDevBackendBuiltin
+ CryptoDevBackendBuiltin;
+
+typedef struct CryptoDevBackendBuiltinSession {
+QCryptoCipher *cipher;
+uint8_t direction; /* encryption or decryption */
+uint8_t type; /* cipher? hash? aead? */
+QTAILQ_ENTRY(CryptoDevBackendBuiltinSession) next;
+} CryptoDevBackendBuiltinSession;
+
+/* Max number of symmetric sessions */
+#define MAX_NUM_SESSIONS 256
+
+
+struct CryptoDevBackendBuiltin {
+CryptoDevBackend parent_obj;
+
+CryptoDevBackendBuiltinSession *sessions[MAX_NUM_SESSIONS];
+};
+
+static void cryptodev_builtin_init(
+ CryptoDevBackend *backend, Error **errp)
+{
+/* Only support one queue */
+int queues = backend->conf.peers.queues;
+CryptoDevBackendClient *cc;
+
+if (queues != 1) {
+error_setg(errp,
+  "Only support one queue in cryptdov-builtin backend");
+return;
+}
+
+cc = cryptodev_backend_new_client(
+  "cryptodev-builtin", NULL);
+cc->info_str = g_strdup_printf("cryptodev-builtin0");
+cc->queue_index = 0;
+backend->conf.peers.ccs[0] = cc;
+
+backend->conf.crypto_services =
+ 1u << VIRTIO_CRYPTO_SERVICE_CIPHER |
+ 1u << VIRTIO_CRYPTO_SERVICE_HASH |
+ 1u << VIRTIO_CRYPTO_SERVICE_MAC;
+backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC;
+backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1;
+}
+
+static int
+cryptodev_builtin_get_unused_session_index(
+ CryptoDevBackendBuiltin *builtin)
+{
+size_t i;
+
+for (i = 0; i < MAX_NUM_SESSIONS; i++) {
+if (builtin->sessions[i] == NULL) {
+return i;
+}
+}
+
+return -1;
+}
+
+static int
+cryptodev_builtin_get_aes_algo(uint32_t key_len, Error **errp)
+{
+int algo;
+
+if (key_len == 128 / 8) {
+algo = QCRYPTO_CIPHER_ALG_AES_128;
+} else if (key_len == 192 / 8) {
+algo = QCRYPTO_CIPHER_ALG_AES_192;
+} else if (key_len == 256 / 8) {
+algo = QCRYPTO_CIPHER_ALG_AES_256;
+} else {
+error_setg(errp, "Unsupported key length :%u", key_len);
+return -1;
+}
+
+return algo;
+}
+
+static int cryptodev_builtin_create_cipher_session(
+CryptoDevBackendBuiltin *builtin,
+CryptoDevBackendSymSessionInfo *sess_info,
+Error **errp)
+{
+int algo;
+int mode;
+QCryptoCipher *cipher;
+int index;
+CryptoDevBackendBuiltinSession *sess;
+
+if (sess_info->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) {
+error_setg(errp, "Unsupported optype :%u", sess_info->op_type);
+return -1;
+}
+
+

Re: [Qemu-devel] Provide safe_syscall for s390x

2016-10-17 Thread Thomas Huth
On 17.10.2016 12:49, Michael Tokarev wrote:
> 17.10.2016 13:39, Michael Tokarev wrote:
> 
>> (cc is gcc 6.2.0)
>>
>> I've no idea which -march is the default and what choices are available.
> 
> $ gcc -march=?
> gcc: error: unrecognized argument in option '-march=?'
> gcc: note: valid arguments to '-march=' are: g5 g6 native z10 z13 z196
> z9-109 z9-ec z900 z990 zEC12
> 
> I guess g5 is the default?

I hope it is not the default - at least not for -m64.

Could you please run the following and post the results:

gcc  -Q --help=target

 Thanks,
  Thomas




Re: [Qemu-devel] [PATCH] include/qemu: Add documentation to functions in include/qemu/id.h

2016-10-17 Thread Markus Armbruster
Veronia Bahaa  writes:

> Add documentation to the functions id_generate and id_wellformed in 
> include/qemu/id.h
>
> Signed-off-by: Veronia Bahaa 
> ---
>  include/qemu/id.h |   23 +++
>  1 file changed, 23 insertions(+)
>
> diff --git a/include/qemu/id.h b/include/qemu/id.h
> index 40c7010..7bbcdc0 100644
> --- a/include/qemu/id.h
> +++ b/include/qemu/id.h
> @@ -7,7 +7,30 @@ typedef enum IdSubSystems {
>  ID_MAX  /* last element, used as array size */
>  } IdSubSystems;
>  
> +/**
> + * id_generate: Generates an ID of the form PREFIX SUBSYSTEM NUMBER
> + *  where:
> + *
> + *  - PREFIX is the reserved character '#'
> + *  - SUBSYSTEM identifies the subsystem creating the ID
> + *  - NUMBER is a decimal number unique within SUBSYSTEM.
> + *
> + *Example: "#block146"
> + *
> + * Returns the generated id string for the subsystem
> + *
> + * @id: the subsystem to generate an id for
> + */

This copies the function comment from the definition.  Not a good idea,
because the copies are prone to get inconsistent over time.

There are two schools of thought on where to put function comments: next
to the definition, or next to a declaration.

The latter school argues that it produces headers that do double-duty as
interface documentation.

The former school points out that separating the function comment from
the actual function reduces the chance of the function comment to stay
correct.  Also, editors worth using can take you to the definition
quickly.

id.c and id.h conform to the the latter school.  Changeable, but change
requires justification.

>  char *id_generate(IdSubSystems id);
> +
> +/**
> + * id_wellformed: checks that an id starts with a letter
> + *  followed by numbers, digits, '-','.', or '_'
> + *
> + * Returns %true if the id is well-formed
> + *
> + * @id: the id to be checked
> + */
>  bool id_wellformed(const char *id);
>  
>  #endif

Here's my try:

/*
 * Is @id a well-formed identifier?
 *
 * Well-formed identifiers consists only of letters, digits, '-', '.'
 * and '_', starting with a letter.
 */



[Qemu-devel] [PATCH v8 00/11] virtio-crypto: introduce framework and device emulation

2016-10-17 Thread Gonglei
Hi,

The virtio crypto is a virtual crypto device as well as a kind
of virtual hardware accelerator for virtual machines. The
encryption and decryption requests are placed in the data
queue and handled by the real crypto accelerators finally.
The second queue is the control queue used to create or
destroy sessions for symmetric algorithms and control
some advanced features in the future. The virtio crypto
device provides the following crypto services: CIPHER,
MAC, HASH, AEAD etc.

TODO:
 - add vhost-user as a high performance cryptodev backend.
 - more crypto services support.
 - mirgration support.

Changes since v7:
 - handle endianess problems in input path [Stefan]
 - fix two possiable memory leak  [Stefan]
 - use the iov_*() functions on in_iov/in_num instead of directly accessing the 
iovecs
 - handle possible integer overflow [Stefan]
 - fix a typo  [Stefan]
 - define struct virtio_crypto_inhdr in virtio_crypto.h [Stefan]
 - use uint8_t instead of uint32_t for status in struct virtio_crypto_inhdr
 - remove unused field in VirtIOCryptoConf. [Stefan]
 - squash the VIRTIO_CRYPTO_OK changes into the patches that introduced the old 
code. [Stefan]
 - squash the previous patch 12 to patch 3 and patch 9 so that we can import 
the final version of
   external header file from Linux. [Stefan]

Changes since v6:
 - add copyright and license for virtio_crypto.h [Eric]
 - add/remove (bracket pair for macro definition in virtio_crypto.h  [Eric]
 - add missing dc->vmsd and fix a typo in patch 5
 - fix a checkpatch.pl complaint
 - rebase on the QEMU master branch

Changes since v5:
 - rebase the patch 14 in v5, using the correct at the beginning of whole patch 
series. [Eric]
 - perfect algorithm chain support in patch 12.
 - more friendly error handler in both controlq and dataq.
 - drop patch "virtio-crypto: emulate virtio crypto as a legacy device by 
default" because
  we shouldn't support transitional virtio devices any more. [Michael] 
 - drop patch "virtio-crypto-test: add qtest case for virtio-crypto" because
  libqtest doesn't support virtio-1.0 device yet.
 - rebase the patch set based on Michael's pull request:
[PULL 00/33] virtio, pc: fixes and features

Changes since v4: (Thanks to Stefan)
 - drop scatter-gather I/O identification in virtio crypto spec and 
corresponding code [Stefan]
 - remove qcrypto perfix for cryptdov stuff [Stefan]
 - use virtio_error() in virtio-crypto device's functions. [Stefan]
 - fix endianness handling. [Stefan]
 - use VMSTATE_VIRTIO_DEVICE() instead of calling register_savevm(). [Stefan]
 - redefine DPRINTF in virtio-crypto.h [Stefan]
 - fix some typos [Stefan]
 - fix other farraginous problems suggested by Stefan.

Changes since v3:
 - rename cryptodev-gcrypt to cryptodev-buitlin. [Daniel]
 - move cryptodev stuff from crypto/ directory to backends/ directory
   in order to keep the crypto subsystem influence by syetem
   emulators. [Daniel]
 - emulate virtio-crypto device as a legacy device by default in patch 11
 - introduce virtio-crypto qtest case in patch 12
 - add myself as cryptdoev backends mainatainer and vitio-crypto
   co-maintainer in patch 13
 - add CRT support for cryptodev-builtin, it based on my previous crypto
   patch serial queued by Daniel.
   https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg06607.html
 - add queue_index for qcrypto_cryptodev_backend_sym_close_session()

Changes since v2:
 According to Daniel's comments:
 - drop cryptodev kernel module as a cryptodev backend
 - rename crypto stuff to cryptodev stuff
 - change some files' license to GPLv2+
 - remove cryptodev command line instead of QOM to define the cryptodev backend
 - rename all functions and structures in crypto sub-directory.
 - add full inline documentation for cryptodev.h
 And:
 - drop crypto-queue.c [Paolo]
 - merge some patches

Great thanks to Daniel and Paolo. Please review again, thanks!

Changes since v1:
 - rmmove mixed endian-ness handler for virtio-crypto device, just
   use little-endian. [mst]
 - add sg list support according virtio-crypto spec v10 (will be posted soon).
 - fix a memory leak in session handler.
 - add a feature page link in qemu.org 
(http://qemu-project.org/Features/VirtioCrypto)
 - fix some trivial problems, sush as 's/Since 2.7/Since 2.8/g' in 
qapi-schema.json
 - rebase the latest qemu master tree.


This patch series realize the framework and emulation of a new
virtio crypto device, which is similar with virtio net device.
 
 - I introduce the cryptodev backend as the client of virtio crypto device
   which can be realized by different methods, such as cryptodev-backend-gcrypt 
in my series,
   vhost-crypto kernel module, vhost-user etc.
 - The patch set abides by the virtio crypto speccification.
 - The virtio crypto support symmetric algorithms (including CIPHER and 
algorithm chainning)
   at present, except HASH, MAC and AEAD services.
 - unsupport hot plug/unplug cryptodev backend at this moment.

Firstly build QEMU with libgcrypt 

Re: [Qemu-devel] Provide safe_syscall for s390x

2016-10-17 Thread Michael Tokarev
17.10.2016 13:53, Thomas Huth wrote:
> On 17.10.2016 12:49, Michael Tokarev wrote:
>> 17.10.2016 13:39, Michael Tokarev wrote:
>>
>>> (cc is gcc 6.2.0)
>>>
>>> I've no idea which -march is the default and what choices are available.
>>
>> $ gcc -march=?
>> gcc: error: unrecognized argument in option '-march=?'
>> gcc: note: valid arguments to '-march=' are: g5 g6 native z10 z13 z196
>> z9-109 z9-ec z900 z990 zEC12
>>
>> I guess g5 is the default?
> 
> I hope it is not the default - at least not for -m64.

Nope, z900 is the default.  For it and z990, asm generates that error.

> Could you please run the following and post the results:
> 
> gcc  -Q --help=target


The following options are target specific:
  -m31  [disabled]
  -m64  [enabled]
  -march=   z900
  -mbackchain   [disabled]
  -mbionic  [disabled]
  -mbranch-cost=0x1
  -mdebug   [disabled]
  -mesa [disabled]
  -mfused-madd  
  -mglibc   [enabled]
  -mhard-dfp[enabled]
  -mhard-float  [enabled]
  -mhotpatch=   
  -mhtm [enabled]
  -mlong-double-128 [disabled]
  -mlong-double-64  [enabled]
  -mlra [enabled]
  -mmusl[disabled]
  -mmvcle   [disabled]
  -mno-stack-guard  
  -mno-stack-size   
  -mpacked-stack[disabled]
  -msmall-exec  [disabled]
  -msoft-float  [disabled]
  -mstack-guard=0
  -mstack-size= 0
  -mtune=   [default]
  -muclibc  [disabled]
  -mvx  [enabled]
  -mwarn-dynamicstack   [disabled]
  -mwarn-framesize= 0
  -mzarch   [enabled]
  -mzvector [disabled]

Thanks,

/mjt



Re: [Qemu-devel] Provide safe_syscall for s390x

2016-10-17 Thread Michael Tokarev
17.10.2016 13:49, Michael Tokarev wrote:
> 17.10.2016 13:39, Michael Tokarev wrote:
> 
>> (cc is gcc 6.2.0)
>>
>> I've no idea which -march is the default and what choices are available.
> 
> $ gcc -march=?
> gcc: error: unrecognized argument in option '-march=?'
> gcc: note: valid arguments to '-march=' are: g5 g6 native z10 z13 z196
> z9-109 z9-ec z900 z990 zEC12
> 
> I guess g5 is the default?

No it is not.

g5 and g6 are deprecated. z900 is the default, and this one produces the
error with `lt' instruction. All other variants works fine.

Thanks,

/mjt




Re: [Qemu-devel] [PATCH v8 00/11] virtio-crypto: introduce framework and device emulation

2016-10-17 Thread no-reply
Hi,

Your series failed automatic build test. Please find the testing commands and
their output below. If you have docker installed, you can probably reproduce it
locally.

Subject: [Qemu-devel] [PATCH v8 00/11] virtio-crypto: introduce framework and 
device emulation
Type: series
Message-id: 1476698623-149992-1-git-send-email-arei.gong...@huawei.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
# Let docker tests dump environment info
export SHOW_ENV=1
export J=16
make docker-test-quick@centos6
make docker-test-mingw@fedora
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]  
patchew/1476473294-11052-1-git-send-email-ehabk...@redhat.com -> 
patchew/1476473294-11052-1-git-send-email-ehabk...@redhat.com
 * [new tag] 
patchew/1476698623-149992-1-git-send-email-arei.gong...@huawei.com -> 
patchew/1476698623-149992-1-git-send-email-arei.gong...@huawei.com
Switched to a new branch 'test'
e30ade1 virtio-crypto: add myself as virtio-crypto and cryptodev backends 
maintainer
49bfbc1 cryptodev: introduce an unified wrapper for crypto operation
4d2072b virtio-crypto: add data queue processing handler
7a3c1bb virtio-crypto: add control queue handler
715a754 virtio-crypto: set capacity of algorithms supported
56c9f32 virtio-crypto-pci: add virtio crypto pci support
917892e virtio-crypto: add virtio crypto device emulation
627a3e6 cryptodev: introduce a new cryptodev backend
38f2895 virtio-crypto: introduce virtio_crypto.h
ef24b19 cryptodev: add symmetric algorithm operation stuff
4b941d0 cryptodev: introduce cryptodev backend interface

=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf'
  BUILD   centos6
  ARCHIVE qemu.tgz
  ARCHIVE dtc.tgz
  COPYRUNNER
  RUN test-quick in centos6
Packages installed:
SDL-devel-1.2.14-7.el6_7.1.x86_64
ccache-3.1.6-2.el6.x86_64
epel-release-6-8.noarch
gcc-4.4.7-17.el6.x86_64
git-1.7.1-4.el6_7.1.x86_64
glib2-devel-2.28.8-5.el6.x86_64
libfdt-devel-1.4.0-1.el6.x86_64
make-3.81-23.el6.x86_64
package g++ is not installed
pixman-devel-0.32.8-1.el6.x86_64
tar-1.23-15.el6_8.x86_64
zlib-devel-1.2.3-29.el6.x86_64

Environment variables:
PACKAGES=libfdt-devel ccache tar git make gcc g++ zlib-devel 
glib2-devel SDL-devel pixman-devel epel-release
HOSTNAME=89216f29eea5
TERM=xterm
MAKEFLAGS= -j16
HISTSIZE=1000
J=16
USER=root
CCACHE_DIR=/var/tmp/ccache
EXTRA_CONFIGURE_OPTS=
V=
SHOW_ENV=1
MAIL=/var/spool/mail/root
PATH=/usr/lib/ccache:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
LANG=en_US.UTF-8
TARGET_LIST=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
TEST_DIR=/tmp/qemu-test
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
FEATURES= dtc
DEBUG=
G_BROKEN_FILENAMES=1
CCACHE_HASHDIR=
_=/usr/bin/env

Configure options:
--enable-werror --target-list=x86_64-softmmu,aarch64-softmmu 
--prefix=/var/tmp/qemu-build/install
No C++ compiler available; disabling C++ specific optional code
Install prefix/var/tmp/qemu-build/install
BIOS directory/var/tmp/qemu-build/install/share/qemu
binary directory  /var/tmp/qemu-build/install/bin
library directory /var/tmp/qemu-build/install/lib
module directory  /var/tmp/qemu-build/install/lib/qemu
libexec directory /var/tmp/qemu-build/install/libexec
include directory /var/tmp/qemu-build/install/include
config directory  /var/tmp/qemu-build/install/etc
local state directory   /var/tmp/qemu-build/install/var
Manual directory  /var/tmp/qemu-build/install/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path   /tmp/qemu-test/src
C compilercc
Host C compiler   cc
C++ compiler  
Objective-C compiler cc
ARFLAGS   rv
CFLAGS-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g 
QEMU_CFLAGS   -I/usr/include/pixman-1-pthread -I/usr/include/glib-2.0 
-I/usr/lib64/glib-2.0/include   -fPIE -DPIE -m64 -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes 
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes 
-fno-strict-aliasing -fno-common -fwrapv  -Wendif-labels -Wmissing-include-dirs 
-Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self 
-Wignored-qualifiers -Wold-style-declaration -Wold-style-definition 
-Wtype-limits -fstack-protector-all
LDFLAGS   -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
make  make
install   install
pythonpython -B
smbd  /usr/sbin/smbd
module supportno
host CPU  x86_64
host big endian   no
target list   x86_64-softmmu aarch64-softmmu
tcg debug enabled no
gprof enabled no
sparse enabledno
strip binariesyes
profiler  no
static build  no
pixmansystem
SDL support   yes (1.2.14)
GTK support   no 
GTK GL supportno

Re: [Qemu-devel] Provide safe_syscall for s390x

2016-10-17 Thread Christian Borntraeger
On 10/17/2016 10:26 AM, Thomas Huth wrote:
> On 14.10.2016 20:58, Michael Tokarev wrote:
>> Hi.
>>
>> This commit: c9bc3437a905b660561a26cd4ecc64579843267b
>> Author: Richard Henderson 
>> Date:   Tue Jun 21 17:32:12 2016 -0700
>>
>> linux-user: Provide safe_syscall for s390x
>>
>> does not build on debian unstable porterbox for s390x, with
>> the following error message:
>>
>> linux-user/host/s390x/safe-syscall.inc.S: Assembler messages:
>> linux-user/host/s390x/safe-syscall.inc.S:75: Error: Unrecognized opcode:
>> `lt'
>> rules.mak:72: recipe for target 'linux-user/safe-syscall.o' failed
>>
>> Since I know nothing about s390, I've no idea what's at fault
>> here... :)  Thought I'd report this :)
> 
> "lt" seems to be a newer s390x opcode which has been added to the
> architecture within the last ten years or so. So maybe you've got to add
> some "-march=xxx" flag when compiling this file?
> Could you maybe start with finding out the exact comand line that is
> used to compile this file?

Yes, lt was added with the extended immidiate facility. So either use 
-march=z9-109 (introduced in
2005) or replace the lt with an l + ltr to also run on older models.




Re: [Qemu-devel] [PULL 00/15] Migration v2

2016-10-17 Thread Peter Maydell
On 14 October 2016 at 16:28, Juan Quintela  wrote:
> The following changes since commit 6aa5a3679449cdf0b6fe5a6829b22e642ded57fd:
>
>   Merge remote-tracking branch 'remotes/kraxel/tags/pull-ui-20161013-1' into 
> staging (2016-10-13 14:27:58 +0100)
>
> are available in the git repository at:
>
>   git://github.com/juanquintela/qemu.git tags/migration/20161014
>
> for you to fetch changes up to 7c2b0f65cc2b6b14ad797549b8bde13aa97f6ba2:
>
>   docs/xbzrle: correction (2016-10-13 17:23:53 +0200)
>
> 
> migration/next for 20161014
>
> Hi
>
> Rebased and it should fix the SIZE_MAX issues on mac os
>
> This get:
> - documentation fix: Cao
> - improve max-bandwidth and downtime-limit (Ashijeet)
> - move migration commands to "boxed" (Eric)
> - rdma fixes (David)
> - postcopy fixes (David)
> - better errors (David)
>
> Please apply
>
> Thanks, Juan
>

Applied, thanks.

-- PMM



Re: [Qemu-devel] [PATCH] machine: Fix replacement of '_' by '-' in machine property names

2016-10-17 Thread Markus Armbruster
Eduardo Habkost  writes:

> On Thu, Oct 13, 2016 at 06:44:14PM +0200, Markus Armbruster wrote:
>> machine_set_property() replaces '_' by '-' in the property name.
>> Except it fails to replace an initial '_'.  Screwed up in commit
>> b0ddb8b.  Reproducer: "-M pc,__foo_bar=true" produces "Property
>> '._-foo-bar' not found".
>> 
>> Error messages using a mangled name rather than the name the user
>> actually wrote is user-hostile, but that's a different topic.
>> 
>> Signed-off-by: Markus Armbruster 
>
> Reviewed-by: Eduardo Habkost 
>
> I suggest we follow the same approach we used in the x86 CPU
> code: instead of requiring a special parser that magically
> translate strings, just add property aliases for the old names
> that contained "_". It would fix the user-hostile error messages
> as well.

Adding the aliases is slightly annoying, but it's probably the easiest
way to get decent error messages.  How can we ensure no new
alias-requiring names get added?



Re: [Qemu-devel] [PATCH v3 1/3] exec: split cpu_exec_init()

2016-10-17 Thread Igor Mammedov
On Sat, 15 Oct 2016 00:52:47 +0200
Laurent Vivier  wrote:

> Put in cpu_exec_initfn() what initializes the CPU,
> and let in cpu_exec_init() what adds it to the environment.
s/let/leave/
> 
> As cpu_exec_initfn() is called by all XX_cpu_initfn()
maybe add comma before "call it"
> call it
> directly in cpu_common_initfn().
> cpu_exec_init() is now a realize function, it will be renamed
> to cpu_exec_realizefn() and moved to the XX_cpu_realizefn()
> function in a following patch.
> 
> Signed-off-by: Laurent Vivier 
With commit message amended

Reviewed-by: Igor Mammedov 

> ---
>  exec.c| 10 ++
>  include/qom/cpu.h |  1 +
>  qom/cpu.c |  2 ++
>  3 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 374c364..d1e57c4 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -610,11 +610,8 @@ void cpu_exec_exit(CPUState *cpu)
>  }
>  }
>  
> -void cpu_exec_init(CPUState *cpu, Error **errp)
> +void cpu_exec_initfn(CPUState *cpu)
>  {
> -CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu);
> -Error *local_err ATTRIBUTE_UNUSED = NULL;
> -
>  cpu->as = NULL;
>  cpu->num_ases = 0;
>  
> @@ -635,6 +632,11 @@ void cpu_exec_init(CPUState *cpu, Error **errp)
>  cpu->memory = system_memory;
>  object_ref(OBJECT(cpu->memory));
>  #endif
> +}
> +
> +void cpu_exec_init(CPUState *cpu, Error **errp)
> +{
> +CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu);
>  
>  cpu_list_add(cpu);
>  
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 6d481a1..d7648a9 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -946,6 +946,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int 
> asidx);
>  
>  void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
>  GCC_FMT_ATTR(2, 3);
> +void cpu_exec_initfn(CPUState *cpu);
>  void cpu_exec_exit(CPUState *cpu);
>  
>  #ifdef CONFIG_SOFTMMU
> diff --git a/qom/cpu.c b/qom/cpu.c
> index c40f774..85f1132 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -362,6 +362,8 @@ static void cpu_common_initfn(Object *obj)
>  QTAILQ_INIT(&cpu->watchpoints);
>  
>  cpu->trace_dstate = bitmap_new(trace_get_vcpu_event_count());
> +
> +cpu_exec_initfn(cpu);
>  }
>  
>  static void cpu_common_finalize(Object *obj)




Re: [Qemu-devel] bug introduced by "block: Move throttling fields from BDS to BB"

2016-10-17 Thread Kevin Wolf
Am 17.10.2016 um 10:49 hat Alberto Garcia geschrieben:
> On Fri 14 Oct 2016 04:11:46 PM CEST, Paolo Bonzini wrote:
> > Here is next_throttle_token:
> >
> > -ThrottleGroup *tg = container_of(blk_bs(blk)->throttle_state,
> > - ThrottleGroup, ts);
> > +BlockBackendPublic *blkp = blk_get_public(blk);
> > +ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, 
> > ts);
> >  BlockBackend *token, *start;
> >  
> >  start = token = tg->tokens[is_write];
> >  
> >  /* get next bs round in round robin style */
> >  token = throttle_group_next_blk(token);
> > -while (token != start && !blk_bs(token)->pending_reqs[is_write]) {
> > +while (token != start && !blkp->pending_reqs[is_write]) {
> >  token = throttle_group_next_blk(token);
> >  }
> >
> >
> > blkp isn't updated every time token is updated.
> 
> You're right, I'll write a patch. I'd also try to check why this was not
> detected by any iotest.
> 
> Thanks!

Thanks a lot, Berto! (Both for fixing my bug and thinking of test cases)

Kevin



Re: [Qemu-devel] [PATCH v3 2/3] exec: rename cpu_exec_init() as cpu_exec_realizefn()

2016-10-17 Thread Igor Mammedov
On Sat, 15 Oct 2016 00:52:48 +0200
Laurent Vivier  wrote:

> Modify all CPUs to call it from XXX_cpu_realizefn() function.
> 
> Remove all the cannot_destroy_with_object_finalize_yet as
> unsafe references have been moved to cpu_exec_realizefn().
> (tested with QOM command provided by commit 4c315c27)
> 
> for arm:
> 
> Setting of cpu->mp_affinity is moved from arm_cpu_initfn()
> to arm_cpu_realizefn() as setting of cpu_index is now done
> in cpu_exec_realizefn().
> 
> Signed-off-by: Laurent Vivier 
For target-i386 part:
Reviewed-by: Igor Mammedov 

> ---
>  exec.c  |  2 +-
>  include/exec/exec-all.h |  1 -
>  include/qom/cpu.h   |  1 +
>  target-alpha/cpu.c  | 15 +++
>  target-arm/cpu.c| 39 +--
>  target-cris/cpu.c   | 15 +++
>  target-i386/cpu.c   | 11 +--
>  target-lm32/cpu.c   | 15 +++
>  target-m68k/cpu.c   | 15 +++
>  target-microblaze/cpu.c | 14 +++---
>  target-mips/cpu.c   | 15 +++
>  target-moxie/cpu.c  | 15 +++
>  target-openrisc/cpu.c   | 15 +++
>  target-ppc/translate_init.c |  2 +-
>  target-s390x/cpu.c  |  8 +---
>  target-sh4/cpu.c| 15 +++
>  target-sparc/cpu.c  | 18 +-
>  target-tilegx/cpu.c | 15 +++
>  target-tricore/cpu.c| 15 +++
>  target-unicore32/cpu.c  | 18 +-
>  target-xtensa/cpu.c | 15 +++
>  21 files changed, 128 insertions(+), 151 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index d1e57c4..203eb52 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -634,7 +634,7 @@ void cpu_exec_initfn(CPUState *cpu)
>  #endif
>  }
>  
> -void cpu_exec_init(CPUState *cpu, Error **errp)
> +void cpu_exec_realizefn(CPUState *cpu, Error **errp)
>  {
>  CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu);
>  
> diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
> index 336a57c..9797d55 100644
> --- a/include/exec/exec-all.h
> +++ b/include/exec/exec-all.h
> @@ -57,7 +57,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
>uint32_t flags,
>int cflags);
>  
> -void cpu_exec_init(CPUState *cpu, Error **errp);
>  void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);
>  void QEMU_NORETURN cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
>  
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index d7648a9..5520c6c 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -947,6 +947,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int 
> asidx);
>  void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
>  GCC_FMT_ATTR(2, 3);
>  void cpu_exec_initfn(CPUState *cpu);
> +void cpu_exec_realizefn(CPUState *cpu, Error **errp);
>  void cpu_exec_exit(CPUState *cpu);
>  
>  #ifdef CONFIG_SOFTMMU
> diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c
> index 6d01d7f..30d77ce 100644
> --- a/target-alpha/cpu.c
> +++ b/target-alpha/cpu.c
> @@ -59,6 +59,13 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error 
> **errp)
>  {
>  CPUState *cs = CPU(dev);
>  AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
> +Error *local_err = NULL;
> +
> +cpu_exec_realizefn(cs, &local_err);
> +if (local_err != NULL) {
> +error_propagate(errp, local_err);
> +return;
> +}
>  
>  qemu_init_vcpu(cs);
>  
> @@ -266,7 +273,6 @@ static void alpha_cpu_initfn(Object *obj)
>  CPUAlphaState *env = &cpu->env;
>  
>  cs->env_ptr = env;
> -cpu_exec_init(cs, &error_abort);
>  tlb_flush(cs, 1);
>  
>  alpha_translate_init();
> @@ -309,13 +315,6 @@ static void alpha_cpu_class_init(ObjectClass *oc, void 
> *data)
>  cc->disas_set_info = alpha_cpu_disas_set_info;
>  
>  cc->gdb_num_core_regs = 67;
> -
> -/*
> - * Reason: alpha_cpu_initfn() calls cpu_exec_init(), which saves
> - * the object in cpus -> dangling pointer after final
> - * object_unref().
> - */
> -dc->cannot_destroy_with_object_finalize_yet = true;
>  }
>  
>  static const TypeInfo alpha_cpu_type_info = {
> diff --git a/target-arm/cpu.c b/target-arm/cpu.c
> index 1b9540e..364a45d 100644
> --- a/target-arm/cpu.c
> +++ b/target-arm/cpu.c
> @@ -441,22 +441,11 @@ static void arm_cpu_initfn(Object *obj)
>  CPUState *cs = CPU(obj);
>  ARMCPU *cpu = ARM_CPU(obj);
>  static bool inited;
> -uint32_t Aff1, Aff0;
>  
>  cs->env_ptr = &cpu->env;
> -cpu_exec_init(cs, &error_abort);
>  cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal,
>   g_free, g_free);
>  
> -/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override 
> it.
> - * We don't support setting cluster ID ([16..23]) (known as Aff2
> - * in later ARM ARM versions), or a

Re: [Qemu-devel] [v2 2/5] block/ssh: Add InetSocketAddress and accept it

2016-10-17 Thread Kevin Wolf
Am 16.10.2016 um 00:30 hat Max Reitz geschrieben:
> > +static InetSocketAddress *ssh_config(BDRVSSHState *s, QDict *options,
> > + Error **errp)
> > +{
> > +InetSocketAddress *inet = NULL;
> > +QDict *addr = NULL;
> > +QObject *crumpled_addr = NULL;
> > +Visitor *iv = NULL;
> > +Error *local_error = NULL;
> > +
> > +qdict_extract_subqdict(options, &addr, "server.");
> > +if (!qdict_size(addr)) {
> > +error_setg(errp, "SSH server address missing");
> > +goto out;
> > +}
> > +
> > +crumpled_addr = qdict_crumple(addr, true, errp);
> > +if (!crumpled_addr) {
> > +goto out;
> > +}
> > +
> > +iv = qobject_input_visitor_new_autocast(crumpled_addr, true, 1, true);
> 
> In contrast to what Kevin said in v1, I think you do not want to use
> autocast here.
> 
> Or, to be more specific, it's difficult. The thing is that the autocast
> documentation says: "Any scalar values in the @obj input data structure
> should always be represented as strings".
> 
> So if you do use the autocast version, command line works great because
> from there everything comes as a string. But blockdev-add no longer
> works because from there everything comes with the correct type (and you
> cannot give it the wrong type).
> [...]
> In contrast, if you do not use the autocast version, blockdev-add will
> work just fine, but you can no longer specify non-string values from the
> command line.

Ah, right, I missed that. :-/

> I don't think this is your problem, though. There should be a way for
> the command line options to be converted to the correct types while we
> continue to use strict type-checking for blockdev-add.
> 
> Therefore, I think you'll have to sacrifice one or the other here. All
> of the non-string options are optional, so it won't be too bad in any case.

If we have to sacrifice one, then yes, blockdev-add is the one that must
work. The new -blockdev command line option will then automatically
work, too, so at least there will be a way to create such nodes.

The usual way to get around the type conflicts is going through a
QemuOpts. So maybe qemu_opts_from_dict() with a QemuOptionsList that
accepts anythign, and then qobject_input_visitor_new_opts() could be a
workaround to keep -drive working at the same time. It's kind of ugly,
though.

Kevin


pgpc0nEk2dX3A.pgp
Description: PGP signature


Re: [Qemu-devel] [v2 0/5] Allow blockdev-add for SSH

2016-10-17 Thread Kevin Wolf
Am 15.10.2016 um 11:04 hat Ashijeet Acharya geschrieben:
> Previously posted series patches:
> v1: http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg02137.html

One general remark: The subject line should still include the PATCH
keyword, so it should be like "[PATCH v2 0/5] Allow blockdev-add for
SSH".

This is also what you automatically get with 'git format-patch -v2 ...'

Kevin



Re: [Qemu-devel] [PATCH v3 3/3] exec: call cpu_exec_exit() from a CPU unrealize common function

2016-10-17 Thread Igor Mammedov
On Sat, 15 Oct 2016 00:52:49 +0200
Laurent Vivier  wrote:

> As cpu_exec_exit() mirrors the cpu_exec_realizefn(),
> rename it as cpu_exec_unrealizefn().
> 
> Create and register a cpu_common_unrealizefn() function for
> the CPU device class and call cpu_exec_unrealizefn() from
> this function.
> 
> Remove cpu_exec_exit() from cpu_common_finalize()
> (which mirrors init, not realize), and as x86_cpu_unrealizefn()
> overwrites the device class unrealize function, add a call to
> cpu_exec_unrealizefn() (as in ppc_cpu_unrealizefn()).
> 
> Signed-off-by: Laurent Vivier 
> ---
>  exec.c  | 2 +-
>  include/qom/cpu.h   | 2 +-
>  qom/cpu.c   | 8 +++-
>  target-i386/cpu.c   | 2 ++
>  target-ppc/translate_init.c | 2 +-
>  5 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 203eb52..3cd25db 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -596,7 +596,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int 
> asidx)
>  }
>  #endif
>  
> -void cpu_exec_exit(CPUState *cpu)
> +void cpu_exec_unrealizefn(CPUState *cpu)
>  {
>  CPUClass *cc = CPU_GET_CLASS(cpu);
>  
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 5520c6c..633c3fc 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -948,7 +948,7 @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char 
> *fmt, ...)
>  GCC_FMT_ATTR(2, 3);
>  void cpu_exec_initfn(CPUState *cpu);
>  void cpu_exec_realizefn(CPUState *cpu, Error **errp);
> -void cpu_exec_exit(CPUState *cpu);
> +void cpu_exec_unrealizefn(CPUState *cpu);
>  
>  #ifdef CONFIG_SOFTMMU
>  extern const struct VMStateDescription vmstate_cpu_common;
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 85f1132..03d9190 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -345,6 +345,12 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
> **errp)
>  trace_init_vcpu(cpu);
>  }
>  
> +static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
> +{
> +CPUState *cpu = CPU(dev);
> +cpu_exec_unrealizefn(cpu);
> +}
> +
>  static void cpu_common_initfn(Object *obj)
>  {
>  CPUState *cpu = CPU(obj);
> @@ -369,7 +375,6 @@ static void cpu_common_initfn(Object *obj)
>  static void cpu_common_finalize(Object *obj)
>  {
>  CPUState *cpu = CPU(obj);
> -cpu_exec_exit(cpu);
>  g_free(cpu->trace_dstate);
>  }
>  
> @@ -403,6 +408,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
>  k->cpu_exec_exit = cpu_common_noop;
>  k->cpu_exec_interrupt = cpu_common_exec_interrupt;
>  dc->realize = cpu_common_realizefn;
> +dc->unrealize = cpu_common_unrealizefn;
>  /*
>   * Reason: CPUs still need special care by board code: wiring up
>   * IRQs, adding reset handlers, halting non-first CPUs, ...
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 3476d46..399a3e4 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -3253,6 +3253,8 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error 
> **errp)
>  object_unparent(OBJECT(cpu->apic_state));
>  cpu->apic_state = NULL;
>  }
> +
> +cpu_exec_unrealizefn(CPU(dev));
perhaps it should mirror the same pattern as realize override

i.e.
child class is it has it's own unrealize()
should have parent_unrealize field where it save original
unrealize pointer before override.

grep for parent_realize to see used pattern.

>  }
>  
>  typedef struct BitProperty {
> diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
> index 40dae70..2de6a06 100644
> --- a/target-ppc/translate_init.c
> +++ b/target-ppc/translate_init.c
> @@ -9910,7 +9910,7 @@ static void ppc_cpu_unrealizefn(DeviceState *dev, Error 
> **errp)
>  opc_handler_t **table, **table_2;
>  int i, j, k;
>  
> -cpu_exec_exit(CPU(dev));
> +cpu_exec_unrealizefn(CPU(dev));
>  
>  for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
>  if (env->opcodes[i] == &invalid_handler) {




Re: [Qemu-devel] [PATCH v5 3/6] tests: move QVirtioBus pointer into QVirtioDevice

2016-10-17 Thread Thomas Huth
On 17.10.2016 12:30, Laurent Vivier wrote:
> This allows to not have to pass bus and device for every virtio functions.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Greg Kurz 
> ---
>  tests/libqos/virtio-mmio.c |   1 +
>  tests/libqos/virtio-pci.c  |   2 +
>  tests/libqos/virtio.c  |  77 +++-
>  tests/libqos/virtio.h  |  51 +++-
>  tests/vhost-user-test.c|  33 +-
>  tests/virtio-9p-test.c |  15 +++--
>  tests/virtio-blk-test.c| 147 
> -
>  tests/virtio-net-test.c|  59 +-
>  tests/virtio-scsi-test.c   |  17 +++---
>  9 files changed, 185 insertions(+), 217 deletions(-)


Reviewed-by: Thomas Huth 




Re: [Qemu-devel] [PATCH v5 4/6] tests: rename target_big_endian() as qvirtio_is_big_endian()

2016-10-17 Thread Thomas Huth
On 17.10.2016 12:30, Laurent Vivier wrote:
> Move the definition to libqos/virtio.h as it must be used
> only with virtio functions.
> 
> Add a QVirtioDevice parameter as it will be needed to
> know if the virtio device is using virtio 1.0 specification
> and thus is always little-endian (to do)
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Greg Kurz 
> ---
>  tests/libqos/virtio-pci.c |  2 +-
>  tests/libqos/virtio.h |  6 ++
>  tests/libqtest.h  | 10 --
>  tests/virtio-blk-test.c   | 36 ++--
>  4 files changed, 25 insertions(+), 29 deletions(-)
> 

Reviewed-by: Thomas Huth 




Re: [Qemu-devel] [PATCH v5 2/6] tests: don't check if qtest_spapr_boot() returns NULL

2016-10-17 Thread Greg Kurz
On Mon, 17 Oct 2016 12:30:20 +0200
Laurent Vivier  wrote:

> qtest_spapr_boot()/qtest_pc_boot()/qtest_boot() call qtest_vboot()
> and qtest_vboot() calls g_malloc(),
> and g_malloc() never fails:
> if memory allocation fails, the application is terminated.
> 
> Signed-off-by: Laurent Vivier 
> ---

Reviewed-by: Greg Kurz 

>  tests/libqos/libqos.c | 2 ++
>  tests/rtas-test.c | 1 -
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
> index 7abb482..6226546 100644
> --- a/tests/libqos/libqos.c
> +++ b/tests/libqos/libqos.c
> @@ -10,6 +10,8 @@
>  /**
>   * Launch QEMU with the given command line,
>   * and then set up interrupts and our guest malloc interface.
> + * Never returns NULL:
> + * Terminates the application in case an error is encountered.
>   */
>  QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
>  {
> diff --git a/tests/rtas-test.c b/tests/rtas-test.c
> index ba0867a..276c87e 100644
> --- a/tests/rtas-test.c
> +++ b/tests/rtas-test.c
> @@ -14,7 +14,6 @@ static void test_rtas_get_time_of_day(void)
>  time_t t1, t2;
>  
>  qs = qtest_spapr_boot("-machine pseries");
> -g_assert(qs != NULL);
>  
>  t1 = time(NULL);
>  ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);




Re: [Qemu-devel] [PULL v2 0/4] Docker patches

2016-10-17 Thread Peter Maydell
On 17 October 2016 at 03:10, Fam Zheng  wrote:
> The following changes since commit 6aa5a3679449cdf0b6fe5a6829b22e642ded57fd:
>
>   Merge remote-tracking branch 'remotes/kraxel/tags/pull-ui-20161013-1' into 
> staging (2016-10-13 14:27:58 +0100)
>
> are available in the git repository at:
>
>   g...@github.com:famz/qemu tags/for-upstream
>
> for you to fetch changes up to e86c9a64f455018fb04d631e14c5f926e36c69fb:
>
>   tests/docker/Makefile.include: add a generic docker-run target (2016-10-17 
> 10:05:48 +0800)
>
> 
>
> v2: Fix $(MAKE) in patch 4. [Paolo]
>
> 

Applied, thanks.

-- PMM



Re: [Qemu-devel] [PATCH V2 RESEND] docs: add PCIe devices placement guidelines

2016-10-17 Thread Gerd Hoffmann
  Hi,

> {26} Another remark (important to me) in this section: the document
> doesn't state firmware expectations. It's clear the firmware is expected
> to reserve no IO space for PCI Express Downstream Ports and Root Ports,
> but what about MMIO?
> 
> We discussed this at length with Alex, but I think we didn't conclude
> anything. It would be nice if firmware received some instructions from
> this document in this regard, even before we implement our own ports and
> bridges in QEMU.

Where do we stand in terms of generic pcie ports btw?

I think the plan is still to communicate suggestions to the firmware via
pci config space, either by using reset defaults of the limit register,
or of that doesn't work due to initialization order issues using some
vendor specific pcie capability.

As long as we don't have that there is nothing do document, other than
maybe briefly mentioning the plans we have and documenting the current
state (2M mmio in seabios, and I think the same for ovmf).

The patches adding the generic ports can also update the documentation
of course.

> 
> 
> If we think such recommendations are out of scope at this point, *and*
> noone disagrees strongly (Gerd?), then I could add some experimental
> fw_cfg knobs to OVMF for this, such as (units in MB):

Why?  Given that the virtio mmio bar size issue is solved I don't see a
strong reason to hurry with this.  Just wait until the generic ports are
there.

cheers,
  Gerd




[Qemu-devel] [PATCH/RFC] vl: add no-panic option

2016-10-17 Thread Christian Borntraeger
Some testcase will trigger a guest panic state. For testing purposes
it can be useful to exit QEMU anyway.

Signed-off-by: Christian Borntraeger 
---
 qemu-options.hx | 9 +
 vl.c| 6 ++
 2 files changed, 15 insertions(+)

diff --git a/qemu-options.hx b/qemu-options.hx
index 01f01df..ee6d3d0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3301,6 +3301,15 @@ This allows for instance switching to monitor to commit 
changes to the
 disk image.
 ETEXI
 
+DEF("no-panic", 0, QEMU_OPTION_no_panic, \
+"-no-panic   exit QEMU also in guest panic state\n", QEMU_ARCH_ALL)
+STEXI
+@item -no-panic
+@findex -no-panic
+Exit QEMU on guest panic instead of keeping it alive. This allows for
+instance running tests that are known to panic at the end.
+ETEXI
+
 DEF("loadvm", HAS_ARG, QEMU_OPTION_loadvm, \
 "-loadvm [tag|id]\n" \
 "start right away with a saved state (loadvm in 
monitor)\n",
diff --git a/vl.c b/vl.c
index f3abd99..57e1d91 100644
--- a/vl.c
+++ b/vl.c
@@ -164,6 +164,7 @@ int no_hpet = 0;
 int fd_bootchk = 1;
 static int no_reboot;
 int no_shutdown = 0;
+int no_panic = 0;
 int cursor_hide = 1;
 int graphic_rotate = 0;
 const char *watchdog;
@@ -1774,6 +1775,8 @@ void qemu_system_reset(bool report)
 
 void qemu_system_guest_panicked(void)
 {
+if (no_panic)
+   return qemu_system_shutdown_request();
 if (current_cpu) {
 current_cpu->crash_occurred = true;
 }
@@ -3780,6 +3783,9 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_no_shutdown:
 no_shutdown = 1;
 break;
+case QEMU_OPTION_no_panic:
+no_panic = 1;
+break;
 case QEMU_OPTION_show_cursor:
 cursor_hide = 0;
 break;
-- 
2.5.5




Re: [Qemu-devel] [kvm-unit-tests PATCH v3 03/10] arm/arm64: smp: support more than 8 cpus

2016-10-17 Thread Andrew Jones
On Tue, Aug 30, 2016 at 04:28:52PM +0200, Auger Eric wrote:
> Hi Drew,
> 
> Proper commit message?
> ... also selects the vgic model corresponding to the host

Sure

> > Reviewed-by: Alex Bennée 
> > Signed-off-by: Andrew Jones 
> > ---
> >  arm/run   | 19 ---
> >  arm/selftest.c|  5 -
> >  lib/arm/asm/processor.h   |  9 +++--
> >  lib/arm/asm/setup.h   |  4 ++--
> >  lib/arm/setup.c   | 12 +++-
> >  lib/arm64/asm/processor.h |  9 +++--
> >  6 files changed, 43 insertions(+), 15 deletions(-)
> > 
> > diff --git a/arm/run b/arm/run
> > index a2f35ef6a7e63..2d0698619606e 100755
> > --- a/arm/run
> > +++ b/arm/run
> > @@ -31,13 +31,6 @@ if [ -z "$ACCEL" ]; then
> > fi
> >  fi
> >  
> > -if [ "$HOST" = "aarch64" ] && [ "$ACCEL" = "kvm" ]; then
> > -   processor="host"
> > -   if [ "$ARCH" = "arm" ]; then
> > -   processor+=",aarch64=off"
> > -   fi
> > -fi
> > -
> >  qemu="${QEMU:-qemu-system-$ARCH_NAME}"
> >  qpath=$(which $qemu 2>/dev/null)
> >  
> > @@ -53,6 +46,18 @@ fi
> >  
> >  M='-machine virt'
> >  
> > +if [ "$ACCEL" = "kvm" ]; then
> > +   if $qemu $M,\? 2>&1 | grep gic-version > /dev/null; then
> > +   M+=',gic-version=host'
> > +   fi
> > +   if [ "$HOST" = "aarch64" ]; then
> > +   processor="host"
> > +   if [ "$ARCH" = "arm" ]; then
> > +   processor+=",aarch64=off"
> > +   fi
> > +   fi
> > +fi
> > +
> >  if ! $qemu $M -device '?' 2>&1 | grep virtconsole > /dev/null; then
> > echo "$qpath doesn't support virtio-console for chr-testdev. Exiting."
> > exit 2
> > diff --git a/arm/selftest.c b/arm/selftest.c
> > index 196164f5313de..2f117f795d2dc 100644
> > --- a/arm/selftest.c
> > +++ b/arm/selftest.c
> > @@ -312,9 +312,10 @@ static bool psci_check(void)
> >  static cpumask_t smp_reported;
> >  static void cpu_report(void)
> >  {
> > +   unsigned long mpidr = get_mpidr();
> > int cpu = smp_processor_id();
> >  
> > -   report("CPU%d online", true, cpu);
> > +   report("CPU(%3d) mpidr=%lx", mpidr_to_cpu(mpidr) == cpu, cpu, mpidr);
> > cpumask_set_cpu(cpu, &smp_reported);
> > halt();
> >  }
> > @@ -343,6 +344,7 @@ int main(int argc, char **argv)
> >  
> > } else if (strcmp(argv[1], "smp") == 0) {
> >  
> > +   unsigned long mpidr = get_mpidr();
> > int cpu;
> >  
> > report("PSCI version", psci_check());
> > @@ -353,6 +355,7 @@ int main(int argc, char **argv)
> > smp_boot_secondary(cpu, cpu_report);
> > }
> >  
> > +   report("CPU(%3d) mpidr=%lx", mpidr_to_cpu(mpidr) == 0, 0, 
> > mpidr);
> > cpumask_set_cpu(0, &smp_reported);
> > while (!cpumask_full(&smp_reported))
> > cpu_relax();
> > diff --git a/lib/arm/asm/processor.h b/lib/arm/asm/processor.h
> > index f25e7eee3666c..d2048f5f5f7e6 100644
> > --- a/lib/arm/asm/processor.h
> > +++ b/lib/arm/asm/processor.h
> > @@ -40,8 +40,13 @@ static inline unsigned int get_mpidr(void)
> > return mpidr;
> >  }
> >  
> > -/* Only support Aff0 for now, up to 4 cpus */
> > -#define mpidr_to_cpu(mpidr) ((int)((mpidr) & 0xff))
> > +#define MPIDR_HWID_BITMASK 0xff
> > +extern int mpidr_to_cpu(unsigned long mpidr);
> > +
> > +#define MPIDR_LEVEL_SHIFT(level) \
> > +   (((1 << level) >> 1) << 3)
> can't we have level << 3?
> > +#define MPIDR_AFFINITY_LEVEL(mpidr, level) \
> > +   ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & 0xff)
> >  
> >  extern void start_usr(void (*func)(void *arg), void *arg, unsigned long 
> > sp_usr);
> >  extern bool is_user(void);
> > diff --git a/lib/arm/asm/setup.h b/lib/arm/asm/setup.h
> > index cb8fdbd38dd5d..c501c6ddd8657 100644
> > --- a/lib/arm/asm/setup.h
> > +++ b/lib/arm/asm/setup.h
> > @@ -10,8 +10,8 @@
> >  #include 
> >  #include 
> >  
> > -#define NR_CPUS8
> > -extern u32 cpus[NR_CPUS];
> > +#define NR_CPUS255
> 256?

The kernel defines KVM_MAX_VCPUS as VGIC_V3_MAX_CPUS, which is
currently defined as 255. I was just being consistent.

> > +extern u64 cpus[NR_CPUS];
> maybe worth commenting the semantic of cpus[i]?

sure

> >  extern int nr_cpus;
> what about MAX_CPUS instead of NR_CPUS?

kernel uses NR_CPUS, I want to be consistent.

> >  
> >  #define NR_MEM_REGIONS 8
> > diff --git a/lib/arm/setup.c b/lib/arm/setup.c
> > index 7e7b39f11dde1..b6e2d5815e723 100644
> > --- a/lib/arm/setup.c
> > +++ b/lib/arm/setup.c
> > @@ -24,12 +24,22 @@ extern unsigned long stacktop;
> >  extern void io_init(void);
> >  extern void setup_args_progname(const char *args);
> >  
> > -u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
> > +u64 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
> >  int nr_cpus;
> >  
> >  struct mem_region mem_regions[NR_MEM_REGIONS];
> >  phys_addr_t __phys_offset, __phys_end;
> >  
> > +int mpidr_to_cpu(unsigned long mpidr)
> > +{
> > +   int i;
> > +
> > +   for (i = 0; i < nr_cpus; ++i)

[Qemu-devel] [PATCH v3 1/2] ACPI: Add IORT Structure definition

2016-10-17 Thread Eric Auger
From: Prem Mallappa 

ACPI Spec 6.0 introduces IO Remapping Table Structure. This patch
introduces the definitions required to describe the IO relationship
between the PCIe root complex and the ITS.

This conforms to:
"IO Remapping Table System Software on ARM Platforms",
Document number: ARM DEN 0049B, October 2015.

Signed-off-by: Prem Mallappa 
Signed-off-by: Eric Auger 

---
v2 -> v3:
- removed backlash at ACPI_IORT_NODE_HEADER_DEF last line

v1 -> v2:
- took into account Drew's comments:
  cleanup comments, remove most defines, add ACPI_IORT_NODE_HEADER_DEF
---
 include/hw/acpi/acpi-defs.h | 68 +
 1 file changed, 68 insertions(+)

diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 9c1b7cb..90a5353 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -609,4 +609,72 @@ typedef struct AcpiDmarHardwareUnit AcpiDmarHardwareUnit;
 /* Masks for Flags field above */
 #define ACPI_DMAR_INCLUDE_PCI_ALL   1
 
+/*
+ * Input Output Remapping Table (IORT)
+ * Conforms to "IO Remapping Table System Software on ARM Platforms",
+ * Document number: ARM DEN 0049B, October 2015
+ */
+
+struct AcpiIortTable {
+ACPI_TABLE_HEADER_DEF /* ACPI common table header */
+uint32_t node_count;
+uint32_t node_offset;
+uint32_t reserved;
+} QEMU_PACKED;
+typedef struct AcpiIortTable AcpiIortTable;
+
+/*
+ * IORT node types
+ */
+
+#define ACPI_IORT_NODE_HEADER_DEF   /* Node format common fields */ \
+uint8_t  type;  \
+uint16_t length;\
+uint8_t  revision;  \
+uint32_t reserved;  \
+uint32_t mapping_count; \
+uint32_t mapping_offset;
+
+/* Values for node Type above */
+enum {
+ACPI_IORT_NODE_ITS_GROUP = 0x00,
+ACPI_IORT_NODE_NAMED_COMPONENT = 0x01,
+ACPI_IORT_NODE_PCI_ROOT_COMPLEX = 0x02,
+ACPI_IORT_NODE_SMMU = 0x03,
+ACPI_IORT_NODE_SMMU_V3 = 0x04
+};
+
+struct AcpiIortIdMapping {
+uint32_t input_base;
+uint32_t id_count;
+uint32_t output_base;
+uint32_t output_reference;
+uint32_t flags;
+} QEMU_PACKED;
+typedef struct AcpiIortIdMapping AcpiIortIdMapping;
+
+struct AcpiIortMemoryAccess {
+uint32_t cache_coherency;
+uint8_t  hints;
+uint16_t reserved;
+uint8_t  memory_flags;
+} QEMU_PACKED;
+typedef struct AcpiIortMemoryAccess AcpiIortMemoryAccess;
+
+struct AcpiIortItsGroup {
+ACPI_IORT_NODE_HEADER_DEF
+uint32_t its_count;
+uint32_t identifiers[0];
+} QEMU_PACKED;
+typedef struct AcpiIortItsGroup AcpiIortItsGroup;
+
+struct AcpiIortRC {
+ACPI_IORT_NODE_HEADER_DEF
+AcpiIortMemoryAccess memory_properties;
+uint32_t ats_attribute;
+uint32_t pci_segment_number;
+AcpiIortIdMapping id_mapping_array[0];
+} QEMU_PACKED;
+typedef struct AcpiIortRC AcpiIortRC;
+
 #endif
-- 
2.5.5




[Qemu-devel] [PATCH v3 2/2] ARM: Virt: ACPI: Build an IORT table with RC and ITS nodes

2016-10-17 Thread Eric Auger
From: Prem Mallappa 

This patch builds an IORT table that features a root complex node and
an ITS node. This complements the ITS description in the ACPI MADT
table and allows vhost-net on ACPI guest.

Signed-off-by: Prem Mallappa 
Signed-off-by: Eric Auger 

---
v2 -> v3:
- used sizeof(*iort) as node_offset
- removed idmap->flags = 0;
- misc cosmetic cleanups

v1 -> v2:
- its_class_name() || !guest_info->no_its now wraps acpi_add_table
  and build_iort
- add cpu_to_le*
- CCA = CPM = DACS = 1
- cleanup according to Drew's comments
- remove comments listing tables and spec revisions
---
 hw/arm/virt-acpi-build.c | 71 
 1 file changed, 60 insertions(+), 11 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index fa0655a..5fc10df 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -384,6 +384,61 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, 
unsigned rsdt_tbl_offset)
 }
 
 static void
+build_iort(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info)
+{
+int iort_start = table_data->len;
+AcpiIortIdMapping *idmap;
+AcpiIortItsGroup *its;
+AcpiIortTable *iort;
+size_t node_size, iort_length;
+AcpiIortRC *rc;
+
+iort = acpi_data_push(table_data, sizeof(*iort));
+
+iort_length = sizeof(*iort);
+iort->node_count = cpu_to_le32(2); /* RC and ITS nodes */
+iort->node_offset = cpu_to_le32(sizeof(*iort));
+
+/* ITS group node */
+node_size =  sizeof(*its) + sizeof(uint32_t);
+iort_length += node_size;
+its = acpi_data_push(table_data, node_size);
+
+its->type = ACPI_IORT_NODE_ITS_GROUP;
+its->length = cpu_to_le16(node_size);
+its->its_count = cpu_to_le32(1);
+its->identifiers[0] = 0; /* MADT translation_id */
+
+/* Root Complex Node */
+node_size = sizeof(*rc) + sizeof(*idmap);
+iort_length += node_size;
+rc = acpi_data_push(table_data, node_size);
+
+rc->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX;
+rc->length = cpu_to_le16(node_size);
+rc->mapping_count = cpu_to_le32(1);
+rc->mapping_offset = cpu_to_le32(sizeof(*rc));
+
+/* fully coherent device */
+rc->memory_properties.cache_coherency = cpu_to_le32(1);
+rc->memory_properties.memory_flags = 0x3; /* CCA = CPM = DCAS = 1 */
+rc->pci_segment_number = 0; /* MCFG pci_segment */
+
+/* Identity RID mapping covering the whole input RID range */
+idmap = &rc->id_mapping_array[0];
+idmap->input_base = 0;
+idmap->id_count = cpu_to_le32(0x);
+idmap->output_base = 0;
+/* output IORT node is the ITS group node (the first node) */
+idmap->output_reference = cpu_to_le32(iort->node_offset);
+
+iort->length = cpu_to_le32(iort_length);
+
+build_header(linker, table_data, (void *)(table_data->data + iort_start),
+ "IORT", table_data->len - iort_start, 0, NULL, NULL);
+}
+
+static void
 build_spcr(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info)
 {
 AcpiSerialPortConsoleRedirection *spcr;
@@ -667,17 +722,6 @@ void virt_acpi_build(VirtGuestInfo *guest_info, 
AcpiBuildTables *tables)
  ACPI_BUILD_TABLE_FILE, tables_blob,
  64, false /* high memory */);
 
-/*
- * The ACPI v5.1 tables for Hardware-reduced ACPI platform are:
- * RSDP
- * RSDT
- * FADT
- * GTDT
- * MADT
- * MCFG
- * DSDT
- */
-
 /* DSDT is pointed to by FADT */
 dsdt = tables_blob->len;
 build_dsdt(tables_blob, tables->linker, guest_info);
@@ -703,6 +747,11 @@ void virt_acpi_build(VirtGuestInfo *guest_info, 
AcpiBuildTables *tables)
 build_srat(tables_blob, tables->linker, guest_info);
 }
 
+if (its_class_name() && !guest_info->no_its) {
+acpi_add_table(table_offsets, tables_blob);
+build_iort(tables_blob, tables->linker, guest_info);
+}
+
 /* RSDT is pointed to by RSDP */
 rsdt = tables_blob->len;
 build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
-- 
2.5.5




[Qemu-devel] [PATCH v3 0/2] ACPI IORT generation for ITS support

2016-10-17 Thread Eric Auger
This series completes the support of MSIs for ACPI guest featuring an ITS.

It generates an ACPI IORT table which describes the IO relationship between
the root complex and the ITS. This typically enables vhost-net support on
such guest.

The series applies on top of Drew's [PATCH 0/2] couple ITS support fixups,
which is now on target-arm.next:
https://lists.gnu.org/archive/html/qemu-devel/2016-10/msg02013.html

Original contribution was sent by Prem Mallapa in
[PATCH v2 9/9] [optional] arm: smmu-v3: ACPI IORT initial support,
part of [PATCH v2 0/9] SMMUv3 Emulation support.
https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg04350.html

Prem's 1st integration targetted Root Complex - vSMMU relationship
description whereas this series targets RC - ITS description.

This was tested with a v4.8 guest + rebased Tomasz' series:
- [PATCH V11 0/8] Introduce ACPI world to ITS,
  https://lkml.org/lkml/2016/9/12/926

History:
v2 -> v3:
- used sizeof(*iort) as node_offset
- removed idmap->flags = 0;
- misc cleanups

v1 -> v2:
- addressed Drew's comments, see individual patches

Prem's version -> v1:
- split into 2 separate patches
- iort struct field names match include/acpi/actbl2.h 's ones
- added ITS node
- added ID mapping in RC node
- removed smmu mode


Prem Mallappa (2):
  ACPI: Add IORT Structure definition
  ARM: Virt: ACPI: Build an IORT table with RC and ITS nodes

 hw/arm/virt-acpi-build.c| 71 ++---
 include/hw/acpi/acpi-defs.h | 68 +++
 2 files changed, 128 insertions(+), 11 deletions(-)

-- 
2.5.5




Re: [Qemu-devel] [PATCH v4 09/13] pc: kvm_apic: pass APIC ID depending on xAPIC/x2APIC mode

2016-10-17 Thread Radim Krčmář
2016-10-14 13:21+0200, Igor Mammedov:
> Signed-off-by: Igor Mammedov 
> ---

Reviewed-by: Radim Krčmář 

> v4:
>  - restore kvm_has_x2apic_api() and use it to avoid side-effects
>of kvm_enable_x2apic(). x2APIC API will be enabled by iommu
>if it's present or not enabled at all.
> v3:
>  - drop kvm_has_x2apic_api() and reuse kvm_enable_x2apic() instead
> ---



Re: [Qemu-devel] [v2 2/5] block/ssh: Add InetSocketAddress and accept it

2016-10-17 Thread Ashijeet Acharya
On Sun, Oct 16, 2016 at 4:00 AM, Max Reitz  wrote:
> On 15.10.2016 11:04, Ashijeet Acharya wrote:
>> Add InetSocketAddress compatibility to SSH driver.
>>
>> Add a new option "server" to the SSH block driver which then accepts
>> a InetSocketAddress.
>>
>> "host" and "port" are supported as legacy options and are mapped to
>> their InetSocketAddress representation.
>>
>> Signed-off-by: Ashijeet Acharya 
>> ---
>>  block/ssh.c | 83 
>> ++---
>>  1 file changed, 74 insertions(+), 9 deletions(-)
>>
>>
>>  /* Open the socket and connect. */
>>  s->sock = inet_connect(s->hostport, errp);
>> @@ -634,7 +698,8 @@ static int connect_to_ssh(BDRVSSHState *s, QDict 
>> *options,
>>  }
>>
>>  /* Check the remote host's key against known_hosts. */
>> -ret = check_host_key(s, host, port, host_key_check, errp);
>> +ret = check_host_key(s, s->inet->host, port, host_key_check,
>
> But then you're still using the port here... And I can't come up with a
> way (not even a bad one) to get the numeric port. Maybe interpret the
> addrinfo in inet_connect_saddr()? But getting that information out would
> be ugly, if even possible...
>
> So maybe the best is to keep it this way and put a FIXME above the
> atoi() call. :-/

Kevin, I believe (after talking with Max) that regarding the atoi()
issue, I can't use any string to integer function since it won't
succeed for cases like port = 'ssh' and putting a FIXME over it seems
to be the only option. But Max did warn me, though, to get everybody's
opinion before I do so. So I am awaiting your response on this one.
Much better will be if you have a workaround solution in mind!! :-)

Ashijeet
>
> Max



Re: [Qemu-devel] [v2 0/5] Allow blockdev-add for SSH

2016-10-17 Thread Ashijeet Acharya
On Mon, Oct 17, 2016 at 4:59 PM, Kevin Wolf  wrote:
> Am 15.10.2016 um 11:04 hat Ashijeet Acharya geschrieben:
>> Previously posted series patches:
>> v1: http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg02137.html
>
> One general remark: The subject line should still include the PATCH
> keyword, so it should be like "[PATCH v2 0/5] Allow blockdev-add for
> SSH".
>
> This is also what you automatically get with 'git format-patch -v2 ...'
>
Noted, won't happen again.

Ashijeet
> Kevin



Re: [Qemu-devel] [PATCH v3 0/2] ACPI IORT generation for ITS support

2016-10-17 Thread no-reply
Hi,

Your series failed automatic build test. Please find the testing commands and
their output below. If you have docker installed, you can probably reproduce it
locally.

Subject: [Qemu-devel] [PATCH v3 0/2] ACPI IORT generation for ITS support
Type: series
Message-id: 1476707466-14300-1-git-send-email-eric.au...@redhat.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
# Let docker tests dump environment info
export SHOW_ENV=1
export J=16
make docker-test-quick@centos6
make docker-test-mingw@fedora
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]  
patchew/1476485569-6744-1-git-send-email-lviv...@redhat.com -> 
patchew/1476485569-6744-1-git-send-email-lviv...@redhat.com
 * [new tag] 
patchew/1476707466-14300-1-git-send-email-eric.au...@redhat.com -> 
patchew/1476707466-14300-1-git-send-email-eric.au...@redhat.com
Switched to a new branch 'test'
0fb6ea0 ARM: Virt: ACPI: Build an IORT table with RC and ITS nodes
f887d5f ACPI: Add IORT Structure definition

=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf'
  BUILD   centos6
make[1]: Entering directory '/var/tmp/patchew-tester-tmp-b0aykr8h/src'
  ARCHIVE qemu.tgz
  ARCHIVE dtc.tgz
  COPYRUNNER
RUN test-quick in qemu:centos6 
Packages installed:
SDL-devel-1.2.14-7.el6_7.1.x86_64
ccache-3.1.6-2.el6.x86_64
epel-release-6-8.noarch
gcc-4.4.7-17.el6.x86_64
git-1.7.1-4.el6_7.1.x86_64
glib2-devel-2.28.8-5.el6.x86_64
libfdt-devel-1.4.0-1.el6.x86_64
make-3.81-23.el6.x86_64
package g++ is not installed
pixman-devel-0.32.8-1.el6.x86_64
tar-1.23-15.el6_8.x86_64
zlib-devel-1.2.3-29.el6.x86_64

Environment variables:
PACKAGES=libfdt-devel ccache tar git make gcc g++ zlib-devel 
glib2-devel SDL-devel pixman-devel epel-release
HOSTNAME=3371bb10f2b3
TERM=xterm
MAKEFLAGS= -j16
HISTSIZE=1000
J=16
USER=root
CCACHE_DIR=/var/tmp/ccache
EXTRA_CONFIGURE_OPTS=
V=
SHOW_ENV=1
MAIL=/var/spool/mail/root
PATH=/usr/lib/ccache:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
LANG=en_US.UTF-8
TARGET_LIST=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
TEST_DIR=/tmp/qemu-test
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
FEATURES= dtc
DEBUG=
G_BROKEN_FILENAMES=1
CCACHE_HASHDIR=
_=/usr/bin/env

Configure options:
--enable-werror --target-list=x86_64-softmmu,aarch64-softmmu 
--prefix=/var/tmp/qemu-build/install
No C++ compiler available; disabling C++ specific optional code
Install prefix/var/tmp/qemu-build/install
BIOS directory/var/tmp/qemu-build/install/share/qemu
binary directory  /var/tmp/qemu-build/install/bin
library directory /var/tmp/qemu-build/install/lib
module directory  /var/tmp/qemu-build/install/lib/qemu
libexec directory /var/tmp/qemu-build/install/libexec
include directory /var/tmp/qemu-build/install/include
config directory  /var/tmp/qemu-build/install/etc
local state directory   /var/tmp/qemu-build/install/var
Manual directory  /var/tmp/qemu-build/install/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path   /tmp/qemu-test/src
C compilercc
Host C compiler   cc
C++ compiler  
Objective-C compiler cc
ARFLAGS   rv
CFLAGS-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g 
QEMU_CFLAGS   -I/usr/include/pixman-1-pthread -I/usr/include/glib-2.0 
-I/usr/lib64/glib-2.0/include   -fPIE -DPIE -m64 -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes 
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes 
-fno-strict-aliasing -fno-common -fwrapv  -Wendif-labels -Wmissing-include-dirs 
-Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self 
-Wignored-qualifiers -Wold-style-declaration -Wold-style-definition 
-Wtype-limits -fstack-protector-all
LDFLAGS   -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
make  make
install   install
pythonpython -B
smbd  /usr/sbin/smbd
module supportno
host CPU  x86_64
host big endian   no
target list   x86_64-softmmu aarch64-softmmu
tcg debug enabled no
gprof enabled no
sparse enabledno
strip binariesyes
profiler  no
static build  no
pixmansystem
SDL support   yes (1.2.14)
GTK support   no 
GTK GL supportno
VTE support   no 
TLS priority  NORMAL
GNUTLS supportno
GNUTLS rndno
libgcrypt no
libgcrypt kdf no
nettleno 
nettle kdfno
libtasn1  no
curses supportno
virgl support no
curl support  no
mingw32 support   no
Audio drivers oss
Block whitelist (rw) 
Block whitelist (ro) 
VirtFS supportno
VNC support   yes
VNC SASL support  no
VNC JPEG support  no
VNC PNG support   no
xen support   no
brlapi supportno
bluez  sup

Re: [Qemu-devel] [PATCH/RFC] vl: add no-panic option

2016-10-17 Thread Paolo Bonzini
> Some testcase will trigger a guest panic state. For testing purposes
> it can be useful to exit QEMU anyway.

I wonder if this should be done by default *unless* -no-shutdown is
provided.  This would require some planning (and delay this to 2.9,
in all likelihood), but it probably would be pretty nice for general
usage.

Paolo

> Signed-off-by: Christian Borntraeger 
> ---
>  qemu-options.hx | 9 +
>  vl.c| 6 ++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 01f01df..ee6d3d0 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -3301,6 +3301,15 @@ This allows for instance switching to monitor to
> commit changes to the
>  disk image.
>  ETEXI
>  
> +DEF("no-panic", 0, QEMU_OPTION_no_panic, \
> +"-no-panic   exit QEMU also in guest panic state\n", QEMU_ARCH_ALL)
> +STEXI
> +@item -no-panic
> +@findex -no-panic
> +Exit QEMU on guest panic instead of keeping it alive. This allows for
> +instance running tests that are known to panic at the end.
> +ETEXI
> +
>  DEF("loadvm", HAS_ARG, QEMU_OPTION_loadvm, \
>  "-loadvm [tag|id]\n" \
>  "start right away with a saved state (loadvm in
>  monitor)\n",
> diff --git a/vl.c b/vl.c
> index f3abd99..57e1d91 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -164,6 +164,7 @@ int no_hpet = 0;
>  int fd_bootchk = 1;
>  static int no_reboot;
>  int no_shutdown = 0;
> +int no_panic = 0;
>  int cursor_hide = 1;
>  int graphic_rotate = 0;
>  const char *watchdog;
> @@ -1774,6 +1775,8 @@ void qemu_system_reset(bool report)
>  
>  void qemu_system_guest_panicked(void)
>  {
> +if (no_panic)
> + return qemu_system_shutdown_request();
>  if (current_cpu) {
>  current_cpu->crash_occurred = true;
>  }
> @@ -3780,6 +3783,9 @@ int main(int argc, char **argv, char **envp)
>  case QEMU_OPTION_no_shutdown:
>  no_shutdown = 1;
>  break;
> +case QEMU_OPTION_no_panic:
> +no_panic = 1;
> +break;
>  case QEMU_OPTION_show_cursor:
>  cursor_hide = 0;
>  break;
> --
> 2.5.5
> 
> 



Re: [Qemu-devel] [PATCH/RFC] vl: add no-panic option

2016-10-17 Thread Christian Borntraeger
On 10/17/2016 02:50 PM, Paolo Bonzini wrote:
>> Some testcase will trigger a guest panic state. For testing purposes
>> it can be useful to exit QEMU anyway.
> 
> I wonder if this should be done by default *unless* -no-shutdown is
> provided.  This would require some planning (and delay this to 2.9,
> in all likelihood), but it probably would be pretty nice for general
> usage.

Yes, might also an option. There are basically two cases
a: guest panic
b: qemu panic (e.g. if KVM_RUN return EFAULT)

I think for b, the current behaviour might be better. In any
case I want a tuneable and either -no-panic or the new -no-shutdown
would allow that.


> 
> Paolo
> 
>> Signed-off-by: Christian Borntraeger 
>> ---
>>  qemu-options.hx | 9 +
>>  vl.c| 6 ++
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/qemu-options.hx b/qemu-options.hx
>> index 01f01df..ee6d3d0 100644
>> --- a/qemu-options.hx
>> +++ b/qemu-options.hx
>> @@ -3301,6 +3301,15 @@ This allows for instance switching to monitor to
>> commit changes to the
>>  disk image.
>>  ETEXI
>>  
>> +DEF("no-panic", 0, QEMU_OPTION_no_panic, \
>> +"-no-panic   exit QEMU also in guest panic state\n", QEMU_ARCH_ALL)
>> +STEXI
>> +@item -no-panic
>> +@findex -no-panic
>> +Exit QEMU on guest panic instead of keeping it alive. This allows for
>> +instance running tests that are known to panic at the end.
>> +ETEXI
>> +
>>  DEF("loadvm", HAS_ARG, QEMU_OPTION_loadvm, \
>>  "-loadvm [tag|id]\n" \
>>  "start right away with a saved state (loadvm in
>>  monitor)\n",
>> diff --git a/vl.c b/vl.c
>> index f3abd99..57e1d91 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -164,6 +164,7 @@ int no_hpet = 0;
>>  int fd_bootchk = 1;
>>  static int no_reboot;
>>  int no_shutdown = 0;
>> +int no_panic = 0;
>>  int cursor_hide = 1;
>>  int graphic_rotate = 0;
>>  const char *watchdog;
>> @@ -1774,6 +1775,8 @@ void qemu_system_reset(bool report)
>>  
>>  void qemu_system_guest_panicked(void)
>>  {
>> +if (no_panic)
>> +return qemu_system_shutdown_request();
>>  if (current_cpu) {
>>  current_cpu->crash_occurred = true;
>>  }
>> @@ -3780,6 +3783,9 @@ int main(int argc, char **argv, char **envp)
>>  case QEMU_OPTION_no_shutdown:
>>  no_shutdown = 1;
>>  break;
>> +case QEMU_OPTION_no_panic:
>> +no_panic = 1;
>> +break;
>>  case QEMU_OPTION_show_cursor:
>>  cursor_hide = 0;
>>  break;
>> --
>> 2.5.5
>>
>>
> 




Re: [Qemu-devel] [PULL 00/16] ppc-for-2.8 queue 20161017

2016-10-17 Thread Peter Maydell
On 17 October 2016 at 03:43, David Gibson  wrote:
> The following changes since commit 6aa5a3679449cdf0b6fe5a6829b22e642ded57fd:
>
>   Merge remote-tracking branch 'remotes/kraxel/tags/pull-ui-20161013-1' into 
> staging (2016-10-13 14:27:58 +0100)
>
> are available in the git repository at:
>
>   git://github.com/dgibson/qemu.git tags/ppc-for-2.8-20161017
>
> for you to fetch changes up to 357d1e3bc7d2d80e5271bc4f3ac8537e30dc8046:
>
>   spapr: Improved placement of PCI host bridges in guest memory map 
> (2016-10-16 12:04:15 +1100)
>
> 
> ppc patch queue 2016-10-17
>
> Highlights:
> * Significant rework of how PCI IO windows are placed for the
>   pseries machine type
> * A number of extra tests added for ppc
> * Other tests clean up / fixed
> * Some cleanups to the XICS interrupt controller in preparation
>   for the 'powernv' machine type
>
> A number of the test changes aren't strictly in ppc related code, but
> are included via my tree because they're primarily focused on
> improving test coverage for ppc.
>

Applied, thanks.

-- PMM



Re: [Qemu-devel] [v2 2/5] block/ssh: Add InetSocketAddress and accept it

2016-10-17 Thread Kevin Wolf
Am 17.10.2016 um 14:33 hat Ashijeet Acharya geschrieben:
> On Sun, Oct 16, 2016 at 4:00 AM, Max Reitz  wrote:
> > On 15.10.2016 11:04, Ashijeet Acharya wrote:
> >> Add InetSocketAddress compatibility to SSH driver.
> >>
> >> Add a new option "server" to the SSH block driver which then accepts
> >> a InetSocketAddress.
> >>
> >> "host" and "port" are supported as legacy options and are mapped to
> >> their InetSocketAddress representation.
> >>
> >> Signed-off-by: Ashijeet Acharya 
> >> ---
> >>  block/ssh.c | 83 
> >> ++---
> >>  1 file changed, 74 insertions(+), 9 deletions(-)
> >>
> >>
> >>  /* Open the socket and connect. */
> >>  s->sock = inet_connect(s->hostport, errp);
> >> @@ -634,7 +698,8 @@ static int connect_to_ssh(BDRVSSHState *s, QDict 
> >> *options,
> >>  }
> >>
> >>  /* Check the remote host's key against known_hosts. */
> >> -ret = check_host_key(s, host, port, host_key_check, errp);
> >> +ret = check_host_key(s, s->inet->host, port, host_key_check,
> >
> > But then you're still using the port here... And I can't come up with a
> > way (not even a bad one) to get the numeric port. Maybe interpret the
> > addrinfo in inet_connect_saddr()? But getting that information out would
> > be ugly, if even possible...
> >
> > So maybe the best is to keep it this way and put a FIXME above the
> > atoi() call. :-/
> 
> Kevin, I believe (after talking with Max) that regarding the atoi()
> issue, I can't use any string to integer function since it won't
> succeed for cases like port = 'ssh' and putting a FIXME over it seems
> to be the only option. But Max did warn me, though, to get everybody's
> opinion before I do so. So I am awaiting your response on this one.
> Much better will be if you have a workaround solution in mind!! :-)

The integer port is only needed for libssh2_knownhost_checkp(). One
option could be to consider passing -1 instead:

port is the port number used by the host (or a negative number to
check the generic host). If the port number is given, libssh2 will
check the key for the specific host + port number combination in
addition to the plain host name only check.

In 99% of the cases, this shouldn't make any difference.

Alternatively it could be possible to use getservbyname() to get the
port number from the name, but maybe that's a bit too much for a feature
that most people don't even know of.

I'm also not completely opposed to simply requiring a numeric argument
for SSH. There is no real use to support service names here other than
being consistent with other places in qemu.

Kevin



Re: [Qemu-devel] [PATCH v2 0/5] linux-user: Several Mips-related patches

2016-10-17 Thread Riku Voipio
On Wed, Oct 12, 2016 at 02:30:20PM +0200, Aleksandar Markovic wrote:
> From: Aleksandar Markovic 
> 
> v2 -> v3:
> 
> - Updated commit message for patch 5.
> 
> v1 -> v2:
> 
> - Added patches 1 and 2.
> - Omitted patch on sysfs(); this patch will be treated separately,
>   as it is not Mips-specific, and logicaly does not belong to this
>   series; it will be sent at later time.
> 
> This is just a set of several Qemu Linux user Mips-specific patches that
> are mostly updating certain Mips-specific data in Qemu code.

Thanks, series applied to linux-user.

> Aleksandar Markovic (5):
>   linux-user: Update syscall numbers tables for Mips
>   linux-user: Update mips_syscall_args[] array in main.c
>   linux-user: Update ioctls definitions for Mips32
>   linux-user: Redirect termbits.h for Mips64 to termbits.h for Mips32
>   linux-user: Fix fadvise64() syscall support for Mips32
> 
>  linux-user/main.c  |  24 +++-
>  linux-user/mips/syscall_nr.h   |   5 +-
>  linux-user/mips/termbits.h |  12 ++
>  linux-user/mips64/syscall_nr.h |   7 ++
>  linux-user/mips64/termbits.h   | 245 
> +
>  5 files changed, 46 insertions(+), 247 deletions(-)
> 
> -- 
> 2.9.3
> 



Re: [Qemu-devel] [PATCH/RFC] vl: add no-panic option

2016-10-17 Thread no-reply
Hi,

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

Subject: [Qemu-devel] [PATCH/RFC] vl: add no-panic option
Type: series
Message-id: 1476706440-112198-1-git-send-email-borntrae...@de.ibm.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
fe3696a vl: add no-panic option

=== OUTPUT BEGIN ===
Checking PATCH 1/1: vl: add no-panic option...
ERROR: do not initialise globals to 0 or NULL
#40: FILE: vl.c:167:
+int no_panic = 0;

ERROR: braces {} are necessary for all arms of this statement
#48: FILE: vl.c:1782:
+if (no_panic)
[...]

ERROR: code indent should never use tabs
#49: FILE: vl.c:1783:
+^Ireturn qemu_system_shutdown_request();$

total: 3 errors, 0 warnings, 39 lines checked

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

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@freelists.org

Re: [Qemu-devel] [PATCH v3 0/2] linux-user: preadv and pwritev emulation support

2016-10-17 Thread Riku Voipio
On Tue, Oct 11, 2016 at 11:52:45AM +0200, Dejan Jovicevic wrote:
> v2 -> v3:
> - Changed from safe_syscall4() to safe_syscall5() to rightly fit the
> kernel implementation of preadv() and pwritev().
> - Modified commit message.
> 
> v1 -> v2:
> - Being that both of these system calls are interruptible, in QEMU
> they should be implemented via the safe_syscall() wrapper. This
> version implements the preadv() and pwritev() using safe_preadv() 
> and safe_pwritev() for the respective syscalls, as suggested.
> As the result of these changes, the patch from the v1 that checks
> the support of pwritev on the host is dropped.
> 
> In this series the support for preadv and pwritev system call emulation
> in linux-user mode is implemented.

Applied to linux-user, thanks
 
> Dejan Jovicevic (2):
>   linux-user: added support for preadv() system call.
>   linux-user: added support for pwritev() system call.
> 
>  linux-user/syscall.c | 30 ++
>  1 file changed, 30 insertions(+)
> 
> -- 
> 1.9.1
> 



Re: [Qemu-devel] [kvm-unit-tests PATCH v3 06/10] arm/arm64: add initial gicv2 support

2016-10-17 Thread Andrew Jones
On Thu, Sep 01, 2016 at 12:20:06PM +0200, Auger Eric wrote:
> 
> 
> On 15/07/2016 15:00, Andrew Jones wrote:
> > Add some gicv2 support. This just adds init and enable
> > functions, allowing unit tests to start messing with it.
> > 
> > Signed-off-by: Andrew Jones 
> > ---
> >  arm/Makefile.common|  1 +
> >  lib/arm/asm/gic-v2.h   | 74 
> > ++
> >  lib/arm/asm/gic.h  | 20 ++
> >  lib/arm/gic.c  | 69 ++
> >  lib/arm64/asm/gic-v2.h |  1 +
> >  lib/arm64/asm/gic.h|  1 +
> >  6 files changed, 166 insertions(+)
> >  create mode 100644 lib/arm/asm/gic-v2.h
> >  create mode 100644 lib/arm/asm/gic.h
> >  create mode 100644 lib/arm/gic.c
> >  create mode 100644 lib/arm64/asm/gic-v2.h
> >  create mode 100644 lib/arm64/asm/gic.h
> > 
> > diff --git a/arm/Makefile.common b/arm/Makefile.common
> > index ccb554d9251a4..41239c37e0920 100644
> > --- a/arm/Makefile.common
> > +++ b/arm/Makefile.common
> > @@ -42,6 +42,7 @@ cflatobjs += lib/arm/mmu.o
> >  cflatobjs += lib/arm/bitops.o
> >  cflatobjs += lib/arm/psci.o
> >  cflatobjs += lib/arm/smp.o
> > +cflatobjs += lib/arm/gic.o
> >  
> >  libeabi = lib/arm/libeabi.a
> >  eabiobjs = lib/arm/eabi_compat.o
> > diff --git a/lib/arm/asm/gic-v2.h b/lib/arm/asm/gic-v2.h
> > new file mode 100644
> > index 0..973c2bf3cc796
> > --- /dev/null
> > +++ b/lib/arm/asm/gic-v2.h
> > @@ -0,0 +1,74 @@
> > +/*
> > + * All GIC* defines are lifted from include/linux/irqchip/arm-gic.h
> > + *
> > + * Copyright (C) 2016, Red Hat Inc, Andrew Jones 
> > + *
> > + * This work is licensed under the terms of the GNU LGPL, version 2.
> > + */
> > +#ifndef _ASMARM_GIC_V2_H_
> > +#define _ASMARM_GIC_V2_H_
> > +
> > +#define GIC_CPU_CTRL   0x00
> > +#define GIC_CPU_PRIMASK0x04
> > +#define GIC_CPU_BINPOINT   0x08
> > +#define GIC_CPU_INTACK 0x0c
> > +#define GIC_CPU_EOI0x10
> > +#define GIC_CPU_RUNNINGPRI 0x14
> > +#define GIC_CPU_HIGHPRI0x18
> > +#define GIC_CPU_ALIAS_BINPOINT 0x1c
> > +#define GIC_CPU_ACTIVEPRIO 0xd0
> > +#define GIC_CPU_IDENT  0xfc
> > +#define GIC_CPU_DEACTIVATE 0x1000
> > +
> > +#define GICC_ENABLE0x1
> > +#define GICC_INT_PRI_THRESHOLD 0xf0
> > +
> > +#define GIC_CPU_CTRL_EOImodeNS (1 << 9)
> > +
> > +#define GICC_IAR_INT_ID_MASK   0x3ff
> > +#define GICC_INT_SPURIOUS  1023
> > +#define GICC_DIS_BYPASS_MASK   0x1e0
> > +
> > +#define GIC_DIST_CTRL  0x000
> > +#define GIC_DIST_CTR   0x004
> you could add #define GIC_DIST_IIDR   0x008
> which can be found in arm-gic.h

I'll resync with the latest kernel headers.

> > +#define GIC_DIST_IGROUP0x080
> > +#define GIC_DIST_ENABLE_SET0x100
> > +#define GIC_DIST_ENABLE_CLEAR  0x180
> > +#define GIC_DIST_PENDING_SET   0x200
> > +#define GIC_DIST_PENDING_CLEAR 0x280
> > +#define GIC_DIST_ACTIVE_SET0x300
> > +#define GIC_DIST_ACTIVE_CLEAR  0x380
> > +#define GIC_DIST_PRI   0x400
> > +#define GIC_DIST_TARGET0x800
> > +#define GIC_DIST_CONFIG0xc00
> > +#define GIC_DIST_SOFTINT   0xf00
> > +#define GIC_DIST_SGI_PENDING_CLEAR 0xf10
> > +#define GIC_DIST_SGI_PENDING_SET   0xf20
> > +
> > +#define GICD_ENABLE0x1
> > +#define GICD_DISABLE   0x0
> > +#define GICD_INT_ACTLOW_LVLTRIG0x0
> > +#define GICD_INT_EN_CLR_X320x
> > +#define GICD_INT_EN_SET_SGI0x
> > +#define GICD_INT_EN_CLR_PPI0x
> > +#define GICD_INT_DEF_PRI   0xa0
> > +#define GICD_INT_DEF_PRI_X4((GICD_INT_DEF_PRI << 24) |\
> > +   (GICD_INT_DEF_PRI << 16) |\
> > +   (GICD_INT_DEF_PRI << 8) |\
> > +   GICD_INT_DEF_PRI)
> > +#ifndef __ASSEMBLY__
> > +
> > +struct gicv2_data {
> > +   void *dist_base;
> > +   void *cpu_base;
> > +};
> > +extern struct gicv2_data gicv2_data;
> > +
> > +#define gicv2_dist_base()  (gicv2_data.dist_base)
> > +#define gicv2_cpu_base()   (gicv2_data.cpu_base)
> > +
> > +extern int gicv2_init(void);
> > +extern void gicv2_enable_defaults(void);
> > +
> > +#endif /* !__ASSEMBLY__ */
> > +#endif /* _ASMARM_GIC_V2_H_ */
> > diff --git a/lib/arm/asm/gic.h b/lib/arm/asm/gic.h
> > new file mode 100644
> > index 0..b1237d1c5ef22
> > --- /dev/null
> > +++ b/lib/arm/asm/gic.h
> > @@ -0,0 +1,20 @@
> > +/*
> > + * Copyright (C) 2016, Red Hat Inc, Andrew Jones 
> > + *
> > + * This work is licensed under the te

Re: [Qemu-devel] A question about this commit "char: convert from GIOChannel to QIOChannel"

2016-10-17 Thread Paolo Bonzini


- Original Message -
> From: "wangyunjian" 
> To: berra...@redhat.com, pbonz...@redhat.com, qemu-devel@nongnu.org
> Cc: "caihe" 
> Sent: Monday, October 17, 2016 3:02:32 PM
> Subject: A question about this commit "char: convert from GIOChannel to 
> QIOChannel"
> 
> Commit 9894dc0cdcc397ee5b26370bc53da6d360a363c2 “char: convert from
> GIOChannel to QIOChannel”,
> the old version will call closesocket when tcp_chr_close and udp_chr_close
> are called. But the new version will not call closesocket.
> 
> This can bring to a socket leak?

Hi, closesocket is called in io/channel-socket.c (qio_channel_socket_finalize).

Thanks,

Paolo



[Qemu-devel] A question about this commit "char: convert from GIOChannel to QIOChannel"

2016-10-17 Thread wangyunjian
Commit 9894dc0cdcc397ee5b26370bc53da6d360a363c2 “char: convert from GIOChannel 
to QIOChannel”,
about the below code segment:

・・・ ・・・
@@ -3107,22 +2965,16 @@ static void tcp_chr_close(CharDriverState *chr)
 s->reconnect_timer = 0;
 }
 qapi_free_SocketAddress(s->addr);
-if (s->fd >= 0) {
-remove_fd_in_watch(chr);
-if (s->chan) {
-g_io_channel_unref(s->chan);
-}
-closesocket(s->fd);
+remove_fd_in_watch(chr);
+if (s->ioc) {
+object_unref(OBJECT(s->ioc));
 }
-if (s->listen_fd >= 0) {
-if (s->listen_tag) {
-g_source_remove(s->listen_tag);
-s->listen_tag = 0;
-}
-if (s->listen_chan) {
-g_io_channel_unref(s->listen_chan);
-}
-closesocket(s->listen_fd);
+if (s->listen_tag) {
+g_source_remove(s->listen_tag);
+s->listen_tag = 0;
+}
+if (s->listen_ioc) {
+object_unref(OBJECT(s->listen_ioc));
 }
・・・ ・・・
@@ -2544,17 +2496,16 @@ static void udp_chr_close(CharDriverState *chr)
 NetCharDriver *s = chr->opaque;
 remove_fd_in_watch(chr);
-if (s->chan) {
-g_io_channel_unref(s->chan);
-closesocket(s->fd);
+if (s->ioc) {
+object_unref(OBJECT(s->ioc));
 }
 g_free(s);
 qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
}


The old version will call closesocket when tcp_chr_close and udp_chr_close are 
called. But the new version will not call closesocket.


This can bring to a socket leak?




[Qemu-devel] [PULL 03/22] linux-user: Fix mq_open() syscall support

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic 

Conversion of file creation flags (O_CREAT, ...) from target to host
was missing.

Also, this patch implements better error handling.

Signed-off-by: Aleksandar Markovic 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 88007e0..e031ecf 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11476,16 +11476,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
 case TARGET_NR_mq_open:
 {
-struct mq_attr posix_mq_attr, *attrp;
+struct mq_attr posix_mq_attr;
+int host_flags;
 
+host_flags = target_to_host_bitmask(arg2, fcntl_flags_tbl);
+if (copy_from_user_mq_attr(&posix_mq_attr, arg4) != 0) {
+goto efault;
+}
 p = lock_user_string(arg1 - 1);
-if (arg4 != 0) {
-copy_from_user_mq_attr (&posix_mq_attr, arg4);
-attrp = &posix_mq_attr;
-} else {
-attrp = 0;
+if (!p) {
+goto efault;
 }
-ret = get_errno(mq_open(p, arg2, arg3, attrp));
+ret = get_errno(mq_open(p, host_flags, arg3, &posix_mq_attr));
 unlock_user (p, arg1, 0);
 }
 break;
-- 
2.1.4




[Qemu-devel] [PULL 08/22] linux-user: sparc64: Use correct target SHMLBA in shmat()

2016-10-17 Thread riku . voipio
From: Peter Maydell 

In commit 40df8c0c0722 support was added for target-specific
handling of SHMLBA. Unfortunately the sparc64-specific part
of the change got lost somewhere between the patch being
posted to the list and going into master:
 http://patchwork.ozlabs.org/patch/646980/
 http://patchwork.ozlabs.org/patch/673339/

Add the accidentally-dropped code.

Signed-off-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/sparc64/target_syscall.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/linux-user/sparc64/target_syscall.h 
b/linux-user/sparc64/target_syscall.h
index b7e3bf8..2cbbaae 100644
--- a/linux-user/sparc64/target_syscall.h
+++ b/linux-user/sparc64/target_syscall.h
@@ -23,4 +23,11 @@ struct target_pt_regs {
 #define TARGET_MLOCKALL_MCL_CURRENT 0x2000
 #define TARGET_MLOCKALL_MCL_FUTURE  0x4000
 
+#define TARGET_FORCE_SHMLBA
+
+static inline abi_ulong target_shmlba(CPUSPARCState *env)
+{
+return MAX(TARGET_PAGE_SIZE, 16 * 1024);
+}
+
 #endif /* SPARC64_TARGET_SYSCALL_H */
-- 
2.1.4




[Qemu-devel] [PULL 02/22] linux-user: Add support for ustat() syscall

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic 

This patch implements Qemu user mode ustat() syscall support.

Syscall ustat() returns information about a mounted filesystem.

Its declaration is:

int ustat(dev_t dev, struct ustat *ubuf);

Its Linux kernel implementation is at fs/compat.c, line 334.

The Qemu implementation proposed in this patch is similar to the
Qemu implementations of statfs(), fstatfs() and other related syscalls.
It is based on invocation of host's ustat(), and its key part is in the
correspondent case segment of the main switch statement of the function
do_syscall(), in file linux-user/syscalls.c. All necessary conversions
of data structures from target to host and from host to target are
covered. Support for target_ustat is included. Sufficient support for
"-strace" option for this syscall is already present, and this patch
does not change it.

This patch also fixes failures of LTP tests ustat01, and ustat02, if
executed on Qemu-emulated systems.

Signed-off-by: Aleksandar Markovic 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c  | 23 +--
 linux-user/syscall_defs.h |  6 ++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0379b8a..88007e0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -48,6 +48,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -8227,9 +8228,27 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 ret = get_errno(chroot(p));
 unlock_user(p, arg1, 0);
 break;
-#ifdef TARGET_NR_ustat
+#if defined(TARGET_NR_ustat)
 case TARGET_NR_ustat:
-goto unimplemented;
+{
+struct ustat ust;
+
+ret = get_errno(ustat(arg1, &ust));
+if (!is_error(ret)) {
+struct target_ustat *target_ust;
+
+if (!lock_user_struct(VERIFY_WRITE, target_ust, arg2, 0)) {
+goto efault;
+}
+__put_user(ust.f_tfree, &target_ust->f_tfree);
+__put_user(ust.f_tinode, &target_ust->f_tinode);
+memcpy(target_ust->f_fname, ust.f_fname, 6);
+memcpy(target_ust->f_fpack, ust.f_fpack, 6);
+unlock_user_struct(target_ust, arg2, 1);
+}
+}
+break;
+
 #endif
 #ifdef TARGET_NR_dup2
 case TARGET_NR_dup2:
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index ca8fa6e..7872b9d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2168,6 +2168,12 @@ struct target_statfs64 {
 };
 #endif
 
+struct target_ustat {
+abi_ulong f_tfree;
+abi_int f_tinode;
+char f_fname[6];
+char f_fpack[6];
+};
 
 #define TARGET_F_DUPFD 0   /* dup */
 #define TARGET_F_GETFD 1   /* get close_on_exec */
-- 
2.1.4




[Qemu-devel] [PULL 01/22] linux-user: Add support for adjtimex() syscall

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic 

This patch implements Qemu user mode adjtimex() syscall support.

Syscall adjtimex() reads and optionally sets parameters for a clock
adjustment algorithm used in network synchonization or similar scenarios.

Its declaration is:

int adjtimex(struct timex *buf);

The correspondent source code in the Linux kernel is at kernel/time.c,
line 206.

The Qemu implementation is based on invocation of host's adjtimex(), and
its key part is in the "TARGET_NR_adjtimex" case segment of the the main
switch statement of the function do_syscall(), in linux-user/syscalls.c. All
necessary conversions of the data structures from target to host and from
host to target are covered. Two new functions, target_to_host_timex() and
host_to_target_timex(), are provided for the purpose of such conversions.
For that purpose, the support for related structure "timex" had tp be added
to the file linux-user/syscall_defs.h, based on its definition in Linux
kernel. Also, the relevant support for "-strace" Qemu option is included
in files linux-user/strace.c and linux-user/strace.list.

This patch also fixes failures of LTP tests adjtimex01 and adjtimex02, if
executed in Qemu user mode.

Signed-off-by: Aleksandar Rikalo 
Signed-off-by: Aleksandar Markovic 
Signed-off-by: Riku Voipio 
---
 linux-user/strace.c   | 46 +
 linux-user/strace.list|  3 +-
 linux-user/syscall.c  | 87 ++-
 linux-user/syscall_defs.h | 28 +++
 4 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 1e51360..f37b386 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -577,6 +577,52 @@ print_syscall_ret_newselect(const struct syscallname 
*name, abi_long ret)
 }
 #endif
 
+/* special meanings of adjtimex()' non-negative return values */
+#define TARGET_TIME_OK   0   /* clock synchronized, no leap second */
+#define TARGET_TIME_INS  1   /* insert leap second */
+#define TARGET_TIME_DEL  2   /* delete leap second */
+#define TARGET_TIME_OOP  3   /* leap second in progress */
+#define TARGET_TIME_WAIT 4   /* leap second has occurred */
+#define TARGET_TIME_ERROR5   /* clock not synchronized */
+static void
+print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
+{
+const char *errstr = NULL;
+
+gemu_log(" = ");
+if (ret < 0) {
+gemu_log("-1 errno=%d", errno);
+errstr = target_strerror(-ret);
+if (errstr) {
+gemu_log(" (%s)", errstr);
+}
+} else {
+gemu_log(TARGET_ABI_FMT_ld, ret);
+switch (ret) {
+case TARGET_TIME_OK:
+gemu_log(" TIME_OK (clock synchronized, no leap second)");
+break;
+case TARGET_TIME_INS:
+gemu_log(" TIME_INS (insert leap second)");
+break;
+case TARGET_TIME_DEL:
+gemu_log(" TIME_DEL (delete leap second)");
+break;
+case TARGET_TIME_OOP:
+gemu_log(" TIME_OOP (leap second in progress)");
+break;
+case TARGET_TIME_WAIT:
+gemu_log(" TIME_WAIT (leap second has occurred)");
+break;
+case TARGET_TIME_ERROR:
+gemu_log(" TIME_ERROR (clock not synchronized)");
+break;
+}
+}
+
+gemu_log("\n");
+}
+
 UNUSED static struct flags access_flags[] = {
 FLAG_GENERIC(F_OK),
 FLAG_GENERIC(R_OK),
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 608f7e0..f6dd044 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -19,7 +19,8 @@
 { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_adjtimex
-{ TARGET_NR_adjtimex, "adjtimex" , NULL, NULL, NULL },
+{ TARGET_NR_adjtimex, "adjtimex" , "%s(%p)", NULL,
+  print_syscall_ret_adjtimex },
 #endif
 #ifdef TARGET_NR_afs_syscall
 { TARGET_NR_afs_syscall, "afs_syscall" , NULL, NULL, NULL },
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 03339ba..0379b8a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #ifdef __ia64__
 int __clone2(int (*fn)(void *), void *child_stack_base,
  size_t stack_size, int flags, void *arg, ...);
@@ -6770,6 +6771,77 @@ static inline abi_long 
host_to_target_itimerspec(abi_ulong target_addr,
 return 0;
 }
 
+static inline abi_long target_to_host_timex(struct timex *host_tx,
+abi_long target_addr)
+{
+struct target_timex *target_tx;
+
+if (!lock_user_struct(VERIFY_READ, target_tx, target_addr, 1)) {
+return -TARGET_EFAULT;
+}
+
+__get_user(host_tx->modes, &target_tx->modes);
+__get_user(host_tx->offset, &target_tx->offset);
+__get_user(host_tx->freq, &target_tx->freq);
+__get_user(host_tx->maxerror, &target_tx->maxerror);
+__get_user(host_tx

[Qemu-devel] [PULL 00/22] linux-user changes

2016-10-17 Thread riku . voipio
From: Riku Voipio 

The following changes since commit 7bf59dfec4234e75e31b3f397374cb5bab1a5b2c:

  Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.8-20161017' into 
staging (2016-10-17 12:59:54 +0100)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20161017

for you to fetch changes up to f2dbe98d6668b5ef98717410129098981e5df520:

  linux-user: disable unicore32 linux-user build (2016-10-17 16:13:54 +0300)


Linux-user pull request for October 2017



Linux-user changes, mostly bugfixes and adding support for some
new syscalls and some obscure syscalls as well. Includes some
missed patches from earlier rounds, and dropping unicore32 target.

Aleksandar Markovic (13):
  linux-user: Add support for adjtimex() syscall
  linux-user: Add support for ustat() syscall
  linux-user: Fix mq_open() syscall support
  linux-user: Fix msgrcv() and msgsnd() syscalls support
  linux-user: Fix socketcall() syscall support
  linux-user: Fix syslog() syscall support
  linux-user: Remove a duplicate item from strace.list
  linux-user: Add support for clock_adjtime() syscall
  linux-user: Add support for syncfs() syscall
  linux-user: Update mips_syscall_args[] array in main.c
  linux-user: Update ioctls definitions for Mips32
  linux-user: Redirect termbits.h for Mips64 to termbits.h for Mips32
  linux-user: Fix fadvise64() syscall support for Mips32

Dejan Jovicevic (2):
  linux-user: added support for preadv() system call.
  linux-user: added support for pwritev() system call.

Felix Janda (1):
  linux-user: use libc wrapper instead of direct mremap syscall

Laurent Vivier (2):
  linux-user: add kcmp() syscall
  linux-user: add RTA_PRIORITY in netlink

Peter Maydell (3):
  linux-user: sparc64: Use correct target SHMLBA in shmat()
  linux-user: Don't use alloca() for epoll_wait's epoll event array
  linux-user: Fix definition of target_sigevent for 32-bit guests

Riku Voipio (1):
  linux-user: disable unicore32 linux-user build

 configure|  36 +++
 default-configs/unicore32-linux-user.mak |   1 -
 linux-user/main.c|  24 +-
 linux-user/mips/syscall_nr.h |   2 +-
 linux-user/mips/termbits.h   |  12 +
 linux-user/mips64/termbits.h | 245 +---
 linux-user/mmap.c|  14 +-
 linux-user/sparc64/target_syscall.h  |   7 +
 linux-user/strace.c  | 233 +--
 linux-user/strace.list   |  13 +-
 linux-user/syscall.c | 378 ---
 linux-user/syscall_defs.h| 117 +++---
 12 files changed, 697 insertions(+), 385 deletions(-)
 delete mode 100644 default-configs/unicore32-linux-user.mak

-- 
2.1.4




[Qemu-devel] [PULL 11/22] linux-user: Don't use alloca() for epoll_wait's epoll event array

2016-10-17 Thread riku . voipio
From: Peter Maydell 

The epoll event array which epoll_wait() allocates has a size
determined by the guest which could potentially be quite large.
Use g_try_new() rather than alloca() so that we can fail more
cleanly if the guest hands us an oversize value. (ENOMEM is
not a documented return value for epoll_wait() but in practice
some kernel configurations can return it -- see for instance
sys_oabi_epoll_wait() on ARM.)

This rearrangement includes fixing a bug where we were
incorrectly passing a negative length to unlock_user() in
the error-exit codepath.

Signed-off-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d66efa1..4e557a6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11795,7 +11795,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 goto efault;
 }
 
-ep = alloca(maxevents * sizeof(struct epoll_event));
+ep = g_try_new(struct epoll_event, maxevents);
+if (!ep) {
+unlock_user(target_ep, arg2, 0);
+ret = -TARGET_ENOMEM;
+break;
+}
 
 switch (num) {
 #if defined(TARGET_NR_epoll_pwait)
@@ -11813,8 +11818,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 target_set = lock_user(VERIFY_READ, arg5,
sizeof(target_sigset_t), 1);
 if (!target_set) {
-unlock_user(target_ep, arg2, 0);
-goto efault;
+ret = -TARGET_EFAULT;
+break;
 }
 target_to_host_sigset(set, target_set);
 unlock_user(target_set, arg5, 0);
@@ -11842,8 +11847,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 target_ep[i].events = tswap32(ep[i].events);
 target_ep[i].data.u64 = tswap64(ep[i].data.u64);
 }
+unlock_user(target_ep, arg2,
+ret * sizeof(struct target_epoll_event));
+} else {
+unlock_user(target_ep, arg2, 0);
 }
-unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event));
+g_free(ep);
 break;
 }
 #endif
-- 
2.1.4




[Qemu-devel] [PULL 07/22] linux-user: Remove a duplicate item from strace.list

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic 

There is a duplicate item in strace.list. It is benign, but it
shouldn't be there, since it may lead to confusion and even bugs
in the future. It is the only duplicate in strace.list. This
patch removes it.

Signed-off-by: Aleksandar Markovic 
Signed-off-by: Riku Voipio 
---
 linux-user/strace.list | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index 2c7ad2b..4bbe0d3 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1455,9 +1455,6 @@
 #ifdef TARGET_NR_sync
 { TARGET_NR_sync, "sync" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_sync_file_range
-{ TARGET_NR_sync_file_range, "sync_file_range" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_syncfs
 { TARGET_NR_syncfs, "syncfs" , NULL, NULL, NULL },
 #endif
-- 
2.1.4




[Qemu-devel] [PULL 04/22] linux-user: Fix msgrcv() and msgsnd() syscalls support

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic 

If syscalls msgrcv() and msgsnd() fail, they return E2BIG, EACCES,
EAGAIN, EFAULT, EIDRM, EINTR, EINVAL, ENOMEM, or ENOMSG.

By examining negative scenarios of these syscalls for Mips, it was
established that ENOMSG does not have the same value accross all
platforms, but it is nevertheless not included for conversion in
the correspondant conversion table defined in linux-user/syscall.c.
This is certainly a bug, since it leads to the incorrect emulation
of msgrcv() and msgsnd() for scenarios involving ENOMSG.

This patch fixes this by extending the conversion table to include
ENOMSG.

Also, LTP test msgrcv04 will be fixed for some platforms.

Signed-off-by: Aleksandar Markovic 
Reviewed-by: Laurent Vivier 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e031ecf..032cb76 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -790,6 +790,9 @@ static uint16_t 
host_to_target_errno_table[ERRNO_TABLE_SIZE] = {
 #ifdef ENOTRECOVERABLE
 [ENOTRECOVERABLE]  = TARGET_ENOTRECOVERABLE,
 #endif
+#ifdef ENOMSG
+[ENOMSG]= TARGET_ENOMSG,
+#endif
 };
 
 static inline int host_to_target_errno(int err)
-- 
2.1.4




[Qemu-devel] [PULL 06/22] linux-user: Fix syslog() syscall support

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic 

There are currently several problems related to syslog() support.

For example, if the second argument "bufp" of target syslog() syscall
is NULL, the current implementation always returns error code EFAULT.
However, NULL is a perfectly valid value for the second argument for
many use cases of this syscall. This is, for example, visible from
this excerpt of man page for syslog(2):

> EINVAL Bad arguments (e.g., bad type; or for type 2, 3, or 4, buf is
>NULL, or len is less than zero; or for type 8, the level is
>outside the range 1 to 8).

Moreover, the argument "bufp" is ignored for all cases of values of the
first argument, except 2, 3 and 4. This means that for such cases
(the first argument is not 2, 3 or 4), there is no need to pass "buf"
between host and target, and it can be set to NULL while calling host's
syslog(), without loss of emulation accuracy.

Note also that if "bufp" is NULL and the first argument is 2, 3 or 4, the
correct returned error code is EINVAL, not EFAULT.

All these details are reflected in this patch.

"#ifdef TARGET_NR_syslog" is also proprerly inserted when needed.

Support for Qemu's "-strace" switch for syslog() syscall is included too.

LTP tests syslog11 and syslog12 pass with this patch (while fail without
it), on any platform.

Signed-off-by: Aleksandar Markovic 
Signed-off-by: Riku Voipio 
---
 linux-user/strace.c   | 72 +++
 linux-user/strace.list|  2 +-
 linux-user/syscall.c  | 49 
 linux-user/syscall_defs.h | 25 
 4 files changed, 141 insertions(+), 7 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index a0e45b5..679f840 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1827,6 +1827,78 @@ print_rt_sigprocmask(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_syslog
+static void
+print_syslog_action(abi_ulong arg, int last)
+{
+const char *type;
+
+switch (arg) {
+case TARGET_SYSLOG_ACTION_CLOSE: {
+type = "SYSLOG_ACTION_CLOSE";
+break;
+}
+case TARGET_SYSLOG_ACTION_OPEN: {
+type = "SYSLOG_ACTION_OPEN";
+break;
+}
+case TARGET_SYSLOG_ACTION_READ: {
+type = "SYSLOG_ACTION_READ";
+break;
+}
+case TARGET_SYSLOG_ACTION_READ_ALL: {
+type = "SYSLOG_ACTION_READ_ALL";
+break;
+}
+case TARGET_SYSLOG_ACTION_READ_CLEAR: {
+type = "SYSLOG_ACTION_READ_CLEAR";
+break;
+}
+case TARGET_SYSLOG_ACTION_CLEAR: {
+type = "SYSLOG_ACTION_CLEAR";
+break;
+}
+case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
+type = "SYSLOG_ACTION_CONSOLE_OFF";
+break;
+}
+case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
+type = "SYSLOG_ACTION_CONSOLE_ON";
+break;
+}
+case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
+type = "SYSLOG_ACTION_CONSOLE_LEVEL";
+break;
+}
+case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
+type = "SYSLOG_ACTION_SIZE_UNREAD";
+break;
+}
+case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
+type = "SYSLOG_ACTION_SIZE_BUFFER";
+break;
+}
+default: {
+print_raw_param("%ld", arg, last);
+return;
+}
+}
+gemu_log("%s%s", type, get_comma(last));
+}
+
+static void
+print_syslog(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_syslog_action(arg0, 0);
+print_pointer(arg1, 0);
+print_raw_param("%d", arg2, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_mknod
 static void
 print_mknod(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index f6dd044..2c7ad2b 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1486,7 +1486,7 @@
 { TARGET_NR_sys_kexec_load, "sys_kexec_load" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_syslog
-{ TARGET_NR_syslog, "syslog" , NULL, NULL, NULL },
+{ TARGET_NR_syslog, "syslog" , NULL, print_syslog, NULL },
 #endif
 #ifdef TARGET_NR_sysmips
 { TARGET_NR_sysmips, "sysmips" , NULL, NULL, NULL },
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 05b4c41..a3e7d51 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9339,14 +9339,51 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5);
 break;
 #endif
-
+#if defined(TARGET_NR_syslog)
 case TARGET_NR_syslog:
-if (!(p = lock_user_string(arg2)))
-goto efault;
-ret = get_errno(sys_syslog((int)arg1, p, (int)arg3));
-unlock_us

[Qemu-devel] [PULL 09/22] linux-user: add kcmp() syscall

2016-10-17 Thread riku . voipio
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
Reviewed-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a3e7d51..bcd97ba 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -306,6 +306,11 @@ _syscall3(int, ioprio_set, int, which, int, who, int, 
ioprio)
 _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
+
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,O_ACCMODE,   O_WRONLY,},
   { TARGET_O_ACCMODE,   TARGET_O_RDWR,  O_ACCMODE,   O_RDWR,  },
@@ -12098,6 +12103,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 ret = get_errno(unshare(arg1));
 break;
 #endif
+#if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)
+case TARGET_NR_kcmp:
+ret = get_errno(kcmp(arg1, arg2, arg3, arg4, arg5));
+break;
+#endif
 
 default:
 unimplemented:
-- 
2.1.4




[Qemu-devel] [PULL 05/22] linux-user: Fix socketcall() syscall support

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic 

Since not all Linux host platforms support socketcall() (most notably
Intel), do_socketcall() function in Qemu's syscalls.c is implemented to
mirror the corespondant implementation of socketcall() in Linux kernel,
and to utilise individual socket operations that are supported on all
Linux platforms. (see kernel source file net/socket.c, definition of
socketcall).

However, error codes produced by Qemu implementation are wrong for the
cases of invalid values of the first argument. Also, naming of constants
is not consistent with kernel one, and not consistant with Qemu convention
of prefixing such constants with "TARGET_". This patch in that light
brings do_socketcall() closer to its kernel counterpart, and in that way
fixes the errors and yields more consisrtent Qemu code.

There were also three missing cases (among 20) for strace support for
socketcall(). The array that contains pointers for appropriate printing
functions is updated with 3 elements, however pointers to functions are
left NULL, and its implementation is left for future.

Also, this patch fixes failure of LTP test socketcall02, if executed on some
Qemu emulated sywstems (uer mode).

Signed-off-by: Aleksandar Markovic 
Signed-off-by: Riku Voipio 
---
 linux-user/strace.c   |  39 ---
 linux-user/syscall.c  | 119 --
 linux-user/syscall_defs.h |  42 
 3 files changed, 105 insertions(+), 95 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index f37b386..a0e45b5 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1675,29 +1675,32 @@ print_optint:
 }
 
 #define PRINT_SOCKOP(name, func) \
-[SOCKOP_##name] = { #name, func }
+[TARGET_SYS_##name] = { #name, func }
 
 static struct {
 const char *name;
 void (*print)(const char *, abi_long);
 } scall[] = {
-PRINT_SOCKOP(socket, do_print_socket),
-PRINT_SOCKOP(bind, do_print_sockaddr),
-PRINT_SOCKOP(connect, do_print_sockaddr),
-PRINT_SOCKOP(listen, do_print_listen),
-PRINT_SOCKOP(accept, do_print_sockaddr),
-PRINT_SOCKOP(getsockname, do_print_sockaddr),
-PRINT_SOCKOP(getpeername, do_print_sockaddr),
-PRINT_SOCKOP(socketpair, do_print_socketpair),
-PRINT_SOCKOP(send, do_print_sendrecv),
-PRINT_SOCKOP(recv, do_print_sendrecv),
-PRINT_SOCKOP(sendto, do_print_msgaddr),
-PRINT_SOCKOP(recvfrom, do_print_msgaddr),
-PRINT_SOCKOP(shutdown, do_print_shutdown),
-PRINT_SOCKOP(sendmsg, do_print_msg),
-PRINT_SOCKOP(recvmsg, do_print_msg),
-PRINT_SOCKOP(setsockopt, do_print_sockopt),
-PRINT_SOCKOP(getsockopt, do_print_sockopt),
+PRINT_SOCKOP(SOCKET, do_print_socket),
+PRINT_SOCKOP(BIND, do_print_sockaddr),
+PRINT_SOCKOP(CONNECT, do_print_sockaddr),
+PRINT_SOCKOP(LISTEN, do_print_listen),
+PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
+PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
+PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
+PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
+PRINT_SOCKOP(SEND, do_print_sendrecv),
+PRINT_SOCKOP(RECV, do_print_sendrecv),
+PRINT_SOCKOP(SENDTO, do_print_msgaddr),
+PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
+PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
+PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
+PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
+PRINT_SOCKOP(SENDMSG, do_print_msg),
+PRINT_SOCKOP(RECVMSG, do_print_msg),
+PRINT_SOCKOP(ACCEPT4, NULL),
+PRINT_SOCKOP(RECVMMSG, NULL),
+PRINT_SOCKOP(SENDMMSG, NULL),
 };
 
 static void
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 032cb76..05b4c41 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3898,89 +3898,94 @@ fail:
 }
 
 #ifdef TARGET_NR_socketcall
-/* do_socketcall() Must return target values and target errnos. */
+/* do_socketcall() must return target values and target errnos. */
 static abi_long do_socketcall(int num, abi_ulong vptr)
 {
-static const unsigned ac[] = { /* number of arguments per call */
-[SOCKOP_socket] = 3,  /* domain, type, protocol */
-[SOCKOP_bind] = 3,/* sockfd, addr, addrlen */
-[SOCKOP_connect] = 3, /* sockfd, addr, addrlen */
-[SOCKOP_listen] = 2,  /* sockfd, backlog */
-[SOCKOP_accept] = 3,  /* sockfd, addr, addrlen */
-[SOCKOP_accept4] = 4, /* sockfd, addr, addrlen, flags */
-[SOCKOP_getsockname] = 3, /* sockfd, addr, addrlen */
-[SOCKOP_getpeername] = 3, /* sockfd, addr, addrlen */
-[SOCKOP_socketpair] = 4,  /* domain, type, protocol, tab */
-[SOCKOP_send] = 4,/* sockfd, msg, len, flags */
-[SOCKOP_recv] = 4,/* sockfd, msg, len, flags */
-[SOCKOP_sendto] = 6,  /* sockfd, msg, len, flags, addr, addrlen */
-[SOCKOP_recvfrom] = 6,/* sockfd, msg, len, flags, addr, addrlen */
-[SOCKOP_shutdown] = 2,/* sockfd, how */
-[SOCK

  1   2   3   4   >