Re: [Qemu-devel] [PATCH 24/56] json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8")

2018-08-13 Thread Markus Armbruster
Eric Blake  writes:

> On 08/10/2018 10:48 AM, Eric Blake wrote:
>> On 08/08/2018 07:03 AM, Markus Armbruster wrote:
>>> This is consistent with qobject_to_json().  See commit e2ec3f97680.
>>
>> Side note: that commit mentions that on output, ASCII DEL (0x7f) is
>> always escaped. RFC 7159 does not require it to be escaped on input,

Weird, isn't it?

>> but I wonder if any of your earlier testsuite improvements should
>> specifically cover \x7f vs. \u007f on input being canonicalized to
>> \u007f on round trip output.

>From utf8_string():

/* 2.2.1  1 byte U+007F */
{
"\x7F",
"\x7F",
"\\u007F",
},

We test parsing of JSON "\x7F" (expecting C string "\x7F"), unparsing of
that C string (expecting JSON "\\u007F"), and after PATCH 29 parsing of
that JSON (expecting the C string again).  Sufficient?

>>>
>>> Signed-off-by: Markus Armbruster 
>>> ---
>>>   qobject/json-lexer.c  | 2 +-
>>>   qobject/json-parser.c | 2 +-
>>>   tests/check-qjson.c   | 8 +---
>>>   3 files changed, 3 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
>>> index ca1e0e2c03..36fb665b12 100644
>>> --- a/qobject/json-lexer.c
>>> +++ b/qobject/json-lexer.c
>>> @@ -93,7 +93,7 @@
>>>*   interpolation = %((l|ll|I64)[du]|[ipsf])
>>>*
>>>    * Note:
>>> - * - Input must be encoded in UTF-8.
>>> + * - Input must be encoded in modified UTF-8.
>>
>> Worth documenting this in the QMP doc as an explicit extension?

qmp-spec.txt:

The sever expects its input to be encoded in UTF-8, and sends its
output encoded in ASCII.

The obvious update would be to stick in "modified".

>> In
>> general, our QMP interfaces that take binary input do so via base64
>> encoding, rather than via a modified UTF-8 string -

Agreed.

However, whether QMP has a use for funny characters or not, the JSON
parser has to handle them *somehow*.  "Handle" in the broadest possible
sense, including "reject".  Not including misbehavior like "crash" and
"silently ignore some input following ASCII NUL".

>> and I don't know
>> how yajl or jansson would feel about an extension for producing
>> modified UTF-8 for QMP to consume if we really did want to pass NUL
>> bytes without the overhead of UTF-8; what's more, even if you can
>> pass NUL, you still have to worry about all other byte sequences
>> being valid (so base64 is still better for true binary data - it's
>> hard to argue that we'd ever have an interface where we want UTF-8
>> including embedded NUL rather than true binary).  I guess it can
>> also be argued that outputting modified UTF-8 is a violation of
>> JSON, so the fact that we can round-trip NUL doesn't help if the
>> client can't read it.
>>
>> So having typed all that, I guess the answer is no, we don't want to
>> document it; for now, the fact that we accept \xc0\x80 on input and
>> produce it on output is only for the testsuite, and unlikely to
>> matter to any real client of QMP.
>
> Actually, I guess we never output \xc0\x80; but would output the C
> string "\\u" (since any byte above 0x1f is passed through our UTF
> decoder back into a codepoint then output with \u).

to_json() converts the C string sequence by sequence.  Valid sequences
in the BMP other than ASCII control characters (\x00..\x1F and \x7F) are
copied unchanged.  Everything else is escaped.

> So it's really
> only a question of whether our input engine can pass "\x00"
> vs. "\\u" when we NEED an input NUL, and except for the testsuite,
> our QAPI schema never really needs an input NUL.

The question is how the JSON parser is to handle "\u" escapes in
JSON strings and NUL bytes anywhere.

The answer for NUL bytes is obvious: reject them just like any other
byte <= 0x1F, as required by the RFC.

My answer for \u is to treat it as much like any other codepoint <=
0x1F as possible.  Treating it exactly like them isn't possible, because
NUL bytes in C strings aren't possible.  However, \xC0\x80 sequences
are.

Reasonably simple and consistent, don't you think?



Re: [Qemu-devel] [PATCH 25/56] json: Leave rejecting invalid escape sequences to parser

2018-08-13 Thread Markus Armbruster
Eric Blake  writes:

> On 08/08/2018 07:03 AM, Markus Armbruster wrote:
>> Both lexer and parser reject invalid escape sequences in strings.  The
>> parser's check is useless.
>>
>
>>
>> Drop the lexer's escape sequence checking, and make it accept the same
>> characters after '\' it accepts elsewhere in strings.  It now produces
>>
>>  JSON_LCURLY   {
>>  JSON_STRING   "abc\@ijk"
>>  JSON_COLON:
>>  JSON_INTEGER  1
>>  JSON_RCURLY
>>
>> and the parser reports just
>>
>>  JSON parse error, invalid escape sequence in string
>>
>> While there, fix parse_string()'s inaccurate function comment.
>
> Worthwhile improvement.
>
>>
>> Signed-off-by: Markus Armbruster 
>> ---
>>   qobject/json-lexer.c  | 72 +++
>>   qobject/json-parser.c | 56 +++--
>>   2 files changed, 37 insertions(+), 91 deletions(-)
>
> and shorter!
>
>>   [IN_DQ_STRING_ESCAPE] = {
>> -['b'] = IN_DQ_STRING,
>> -['f'] =  IN_DQ_STRING,
>> -['n'] =  IN_DQ_STRING,
>> -['r'] =  IN_DQ_STRING,
>> -['t'] =  IN_DQ_STRING,
>> -['/'] = IN_DQ_STRING,
>> -['\\'] = IN_DQ_STRING,
>> -['\''] = IN_DQ_STRING,
>> -['\"'] = IN_DQ_STRING,
>> -['u'] = IN_DQ_UCODE0,
>> +[0x20 ... 0xFD] = IN_DQ_STRING,
>
> Among other things, this means the parser now has to flag "\u" as an
> incomplete escape - but your added testsuite coverage earlier in the
> series ensures that we do.

Yes.

>> +++ b/qobject/json-parser.c
>> @@ -106,30 +106,40 @@ static int hex2decimal(char ch)
>>   }
>> /**
>> - * parse_string(): Parse a json string and return a QObject
>> + * parse_string(): Parse a JSON string
>>*
>> - *  string
>
>> + * From RFC 7159 "The JavaScript Object Notation (JSON) Data
>> + * Interchange Format":
>> + *
>> + *char = unescaped /
>> + *escape (
>> + *%x22 /  ; "quotation mark  U+0022
>> + *%x5C /  ; \reverse solidus U+005C
>> + *%x2F /  ; /solidus U+002F
>> + *%x62 /  ; bbackspace   U+0008
>> + *%x66 /  ; fform feed   U+000C
>> + *%x6E /  ; nline feed   U+000A
>> + *%x72 /  ; rcarriage return U+000D
>> + *%x74 /  ; ttab U+0009
>> + *%x75 4HEXDIG )  ; uU+
>> + *escape = %x5C  ; \
>> + *quotation-mark = %x22  ; "
>> + *unescaped = %x20-21 / %x23-5B / %x5D-10
>> + *
>> + * Extensions over RFC 7159:
>> + * - Extra escape sequence in strings:
>> + *   0x27 (apostrophe) is recognized after escape, too
>> + * - Single-quoted strings:
>> + *   Like double-quoted strings, except they're delimited by %x27
>> + *   (apostrophe) instead of %x22 (quotation mark), and can't contain
>> + *   unescaped apostrophe, but can contain unescaped quotation mark.
>> + *
>> + * Note:
>> + * - Encoding is modified UTF-8.
>
> That is an extension over RFC 7159. But I'm okay with leaving it in
> the Notes section.
>
>> + * - Invalid Unicode characters are rejected.
>> + * - Control characters are rejected by the lexer.
>
> Worth being explicit that this is 00-1f, fe, and ff?

\xFE and \xFF are invalid, not control.

What about:

 * - Invalid Unicode characters are rejected.
 * - Control characters \x00..\x1F are rejected by the lexer.



Re: [Qemu-devel] [PATCH] acpi: SRAT: do not create reserved gap entries

2018-08-13 Thread Igor Mammedov
On Fri, 10 Aug 2018 15:28:35 -0300
Eduardo Habkost  wrote:

> On Fri, Aug 10, 2018 at 06:01:06PM +0200, Igor Mammedov wrote:
> > On Fri, 10 Aug 2018 16:06:57 +0200
> > Igor Mammedov  wrote:
> >   
> > > Commit 848a1cc1e8b04 while introducing SRAT entries for DIMM and NVDIMM
> > > also introduced fake entries for gaps between memory devices, assuming
> > > that we need all possible range covered with SRAT entries.
> > > And it did it wrong since gap would overlap with preceeding entry.
> > > Reproduced with following CLI:
> > > 
> > >  -m 1G,slots=4,maxmem=8 \
> > >  -object memory-backend-ram,size=1G,id=m0 \
> > >  -device pc-dimm,memdev=m0,addr=0x10100 \
> > >  -object memory-backend-ram,size=1G,id=m1 \
> > >  -device pc-dimm,memdev=m1
> > > 
> > > However recent development (10efd7e108) showed that gap entries might
> > > be not need. And indeed testing with WS2008DC-WS2016DC guests range
> > > shows that memory hotplug works just fine without gap entries.
> > > 
> > > So rather than fixing gap entry borders, just drop them altogether
> > > and simplify code around it.
> > > 
> > > Spotted-by: Laszlo Ersek 
> > > Signed-off-by: Igor Mammedov 
> > > ---
> > > There is no need to update reference blobs since gaps beween dimms
> > > aren't generated by any exsting test case.
> > > 
> > > Considering issue is not visible by default lets just merge it into 3.1
> > > and stable 3.0.1  
> > Pls ignore it for now I'll need to do more extensive testing with old 
> > kernels,
> > we might need these holes for old kernels or even new ones.
> > /me goes to read kernel code
> > 
> > /per spec possible to hotplug range could be in SRAT,
> >  even though I don't like it bu we might end up with static
> >  partitioning of hotplug area between nodes like on bare metal
> >  to avoid chasing after unknown requirements from windows /  
> 
> Does that mean we might want to pair DIMM slots with NUMA nodes
> in advance?  Do you have a suggestion on how the command-line
> would look like, in this case?
> 
> Maybe "-numa mem-slot,slot=X,node=Y"?
it's either, to make it per slot (it implies fixed maximum size per slot)
or a bit more flexible maxmem per node, might be something like:
  -numa memory,node=X,maxmem=Y






Re: [Qemu-devel] [PATCH 28/56] json: Fix \uXXXX for surrogate pairs

2018-08-13 Thread Markus Armbruster
Eric Blake  writes:

> On 08/08/2018 07:03 AM, Markus Armbruster wrote:
>> The JSON parser treats each half of a surrogate pair as unpaired
>> surrogate.  Fix it to recognize surrogate pairs.
>>
>> Signed-off-by: Markus Armbruster 
>> ---
>>   qobject/json-parser.c | 16 +++-
>>   tests/check-qjson.c   |  3 +--
>>   2 files changed, 16 insertions(+), 3 deletions(-)
>>
>
>> @@ -168,6 +170,18 @@ static QString *parse_string(JSONParserContext *ctxt, 
>> JSONToken *token)
>>  cp |= hex2decimal(*ptr);
>>  }
>> +if (cp >= 0xD800 && cp <= 0xDBFF && !leading_surrogate
>> +&& ptr[1] == '\\' && ptr[2] == 'u') {
>> +ptr += 2;
>> +leading_surrogate = cp;
>> +goto hex;
>> +}
>> +if (cp >= 0xDC00 && cp <= 0xDFFF && leading_surrogate) {
>> +cp &= 0x3FF;
>> +cp |= (leading_surrogate & 0x3FF) << 10;
>> +cp += 0x01;
>> +}
>> +
>>   if (mod_utf8_encode(utf8_buf, sizeof(utf8_buf), cp) < 0) {
>>   parse_error(ctxt, token,
>>   "\\u%.4s is not a valid Unicode character",
>
> Consider "\\udbff\\udfff" - a valid surrogate pair (in terms of being
> in range), but which decodes to u+10.  Since is_valid_codepoint()
> (part of mod_utf8_encode()) rejects it due to (codepoint & 0xfffe) ==
> 0xfffe, it means we end up printing this error message, but only using
> the second half of the surrogate pair.  Is that okay?

It's not horrible, but I wouldn't call it okay.  I'll try to improve it.

> Otherwise,
> Reviewed-by: Eric Blake 

Thanks!



Re: [Qemu-devel] [PATCH 28/56] json: Fix \uXXXX for surrogate pairs

2018-08-13 Thread Markus Armbruster
Paolo Bonzini  writes:

> On 08/08/2018 14:03, Markus Armbruster wrote:
>> +if (cp >= 0xD800 && cp <= 0xDBFF && !leading_surrogate
>> +&& ptr[1] == '\\' && ptr[2] == 'u') {
>> +ptr += 2;
>> +leading_surrogate = cp;
>> +goto hex;
>> +}
>> +if (cp >= 0xDC00 && cp <= 0xDFFF && leading_surrogate) {
>> +cp &= 0x3FF;
>> +cp |= (leading_surrogate & 0x3FF) << 10;
>> +cp += 0x01;
>> +}
>> +
>
> The leading surrogate is discarded for \uD800\uCAFE, I think.  Is this
> desired?

Certainly not.  I'll fix it.  Thanks!



Re: [Qemu-devel] [PATCH v4] tests/libqtest: Improve kill_qemu()

2018-08-13 Thread Markus Armbruster
Eric Blake  writes:

> On 08/10/2018 08:28 AM, Eric Blake wrote:
>> Instead of using a raw assert, print the information in an
>> easier to understand way:
>>
>> /i386/ahci/sanity: tests/libqtest.c:119: kill_qemu() detected QEMU death 
>> from signal 11 (Segmentation fault) (core dumped)
>
> Well, it would help if my commit message actually matched...
>
>
>> +if (wstatus) {
>> +if (WIFEXITED(wstatus)) {
>> +fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU 
>> "
>> +"process but encountered exit status %d\n",
>> +__FILE__, __LINE__, WEXITSTATUS(wstatus));
>> +} else if (WIFSIGNALED(wstatus)) {
>> +int sig = WTERMSIG(wstatus);
>> +const char *signame = strsignal(sig) ?: "unknown ???";
>> +const char *dump = WCOREDUMP(wstatus) ? " (dumped core)" : 
>> "";
>> +
>> +fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
>> +"from signal %d (%s)%s\n",
>
> ...the code.

I got libqtest patches in my queue, and I could stick this patch in.
Would you like me to touch up the commit message when I apply?  Or
should I expect v5?



Re: [Qemu-devel] [PATCH] virtio: add support for in-order feature

2018-08-13 Thread Ilya Maximets
On 10.08.2018 22:19, Michael S. Tsirkin wrote:
> On Fri, Aug 10, 2018 at 02:04:47PM +0300, Ilya Maximets wrote:
>> On 10.08.2018 12:34, Michael S. Tsirkin wrote:
>>> On Fri, Aug 10, 2018 at 11:28:47AM +0300, Ilya Maximets wrote:
 On 10.08.2018 01:51, Michael S. Tsirkin wrote:
> On Thu, Aug 09, 2018 at 07:54:37PM +0300, Ilya Maximets wrote:
>> New feature bit for in-order feature of the upcoming
>> virtio 1.1. It's already supported by DPDK vhost-user
>> and virtio implementations. These changes required to
>> allow feature negotiation.
>>
>> Signed-off-by: Ilya Maximets 
>> ---
>>
>> I just wanted to test this new feature in DPDK but failed
>> to found required patch for QEMU side. So, I implemented it.
>> At least it will be helpful for someone like me, who wants
>> to evaluate VIRTIO_F_IN_ORDER with DPDK.
>>
>>  hw/net/vhost_net.c |  1 +
>>  include/hw/virtio/virtio.h | 12 +++-
>>  include/standard-headers/linux/virtio_config.h |  7 +++
>>  3 files changed, 15 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
>> index e037db6..86879c5 100644
>> --- a/hw/net/vhost_net.c
>> +++ b/hw/net/vhost_net.c
>> @@ -78,6 +78,7 @@ static const int user_feature_bits[] = {
>>  VIRTIO_NET_F_MRG_RXBUF,
>>  VIRTIO_NET_F_MTU,
>>  VIRTIO_F_IOMMU_PLATFORM,
>> +VIRTIO_F_IN_ORDER,
>>  
>>  /* This bit implies RARP isn't sent by QEMU out of band */
>>  VIRTIO_NET_F_GUEST_ANNOUNCE,
>> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
>> index 9c1fa07..a422025 100644
>> --- a/include/hw/virtio/virtio.h
>> +++ b/include/hw/virtio/virtio.h
>> @@ -254,16 +254,18 @@ typedef struct virtio_input_conf virtio_input_conf;
>>  typedef struct VirtIOSCSIConf VirtIOSCSIConf;
>>  typedef struct VirtIORNGConf VirtIORNGConf;
>>  
>> -#define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
>> +#define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
>>  DEFINE_PROP_BIT64("indirect_desc", _state, _field,\
>>VIRTIO_RING_F_INDIRECT_DESC, true), \
>>  DEFINE_PROP_BIT64("event_idx", _state, _field,\
>>VIRTIO_RING_F_EVENT_IDX, true), \
>>  DEFINE_PROP_BIT64("notify_on_empty", _state, _field,  \
>> -  VIRTIO_F_NOTIFY_ON_EMPTY, true), \
>> -DEFINE_PROP_BIT64("any_layout", _state, _field, \
>> -  VIRTIO_F_ANY_LAYOUT, true), \
>> -DEFINE_PROP_BIT64("iommu_platform", _state, _field, \
>> +  VIRTIO_F_NOTIFY_ON_EMPTY, true),\
>> +DEFINE_PROP_BIT64("any_layout", _state, _field,   \
>> +  VIRTIO_F_ANY_LAYOUT, true), \
>> +DEFINE_PROP_BIT64("in_order", _state, _field, \
>> +  VIRTIO_F_IN_ORDER, true),   \
>> +DEFINE_PROP_BIT64("iommu_platform", _state, _field,   \
>>VIRTIO_F_IOMMU_PLATFORM, false)
>
> Is in_order really right for all virtio devices?

 I see nothing device specific in this feature. It just specifies
 some restrictions on the descriptors handling. All virtio devices
 could use it to have performance benefits. Also, upcoming packed
 rings should give a good performance boost in case of enabled
 in-order feature. And packed rings RFC [1] implements
 VIRTIO_F_RING_PACKED for all virtio devices. So, I see no issues
 in enabling in-order negotiation for all of them.

 What do you think?

 [1] https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg01028.html

 Best regards, Ilya Maximets.
>>>
>>> If guest assumes in-order use of buffers but device uses them out of
>>> order then guest will crash. So there's a missing piece where
>>> you actually make devices use buffers in order when the flag is set.
>>
>> I thought that feature negotiation is the mechanism that should
>> protect us from situations like that. Isn't it?
>> If device negotiates in-order feature, when it MUST (as described
>> in spec) use buffers in the same order in which they have been
>> available.
> 
> Exactly. And your patch does nothing to ensure that,

Are you requesting to validate every single ring operation?

Anyway,
Buggy/malicious device is able to crash guest in a variety of ways.
Device that flags support of the feature, but breaks this promise,
IMHO, is buggy or malicious. So, why we need to protect from these
devices only for this particular feature flag?
If your HW is broken, you're replacing it with a better one.

Do you have an example where both (device and driver) are compliant
to virtio spec and something goes wrong?

> or limit to devices which use buffers in order.
Do you have a full l

Re: [Qemu-devel] [PATCH] MAINTAINERS: Fix F: patterns that don't match anything

2018-08-13 Thread Thomas Huth
On 08/10/2018 01:55 PM, Markus Armbruster wrote:
> Commit ba51ef25571 moved hw/dma/sun4m_iommu.c to
> hw/sparc/sun4m_iommu.c without updating MAINTAINERS.
> 
> Commit f5980f757c0 deleted include/hw/sparc/sun4m.h without updating
> MAINTAINERS.
> 
> Commit 0bcc8e5bd8d fat-fingered tests/check-block-qdict.c.
> 
> Commit 33e9e9bd62d fat-fingered include/qemu/job.h.
> 
> Commit eb815e248f5 moved qapi-schema.json to qapi/ without updating
> MAINTAINERS.
> 
> Commit 2e3c8f8dbdd converted docs/devel/migration.txt to
> docs/devel/migration.rst without updating MAINTAINERS.
> 
> Offenders tracked down with the following shell loop:
> 
> shopt -s nullglob
> for i in `sed -n 's/^F: //p'  do
> glob="`echo $i`"
>   if [ "$glob" = "$i" ]
>   then [ ! -e $i ]
>   else [ -z "$glob" ]
>   fi && echo "$i"
> done

Maybe we could check something like this with patchew automatically one day?

> Signed-off-by: Markus Armbruster 
> ---
>  MAINTAINERS | 10 --
>  1 file changed, 4 insertions(+), 6 deletions(-)

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH] scripts/checkpatch.pl: Enforce multiline comment syntax

2018-08-13 Thread Paolo Bonzini
On 13/08/2018 08:18, Thomas Huth wrote:
> On 08/10/2018 02:45 PM, Paolo Bonzini wrote:
>> On 10/08/2018 11:10, Peter Maydell wrote:
 So my proposal, which is actually consistent with what QEMU is doing, is
 the following:

 1) the first line of a file should always be "/*", otherwise warn

 2) a comment that starts with "/**" should have it on a lone line

 3) every other multiline comment should start with
 "/*"
>>> Personally I would prefer your suggestion, but as I say, there
>>> was no consensus in the thread for it, and there was consensus
>>> for "use the kernel's style here". I don't think we gain much
>>> from reopening the debate at this point.
>>
>> What we lose is that 3000 more new warnings appear.  So if we make an
>> exception and convert all of the comments, I'm okay.
> 
> Why do you want to enforce to convert all of them in one go? For example
> we still have also some TABs in some source files, and nobody cares
> about converting them all in one go. If we enforce the comments in new
> code, that should IMHO be good enough. Or make it a BiteSizeTask for the
> next GSoC maybe.

Because TABs are usually very few in a file and crept in by mistake (100
files have 5 or fewer TABs).  If there are many, it's almost always in
files that nobody touches (exception: linux-user/syscall.c and
linux-user/syscall_defs.h).  For what it's worth, I'd be in favor of
changing TABs to spaces in files that only have a few of them or in
those two linux-user files.

The 3-line comment style is in files that are actively developed and
would become inconsistent over a very short time.

Paolo



[Qemu-devel] [Bug 1785698] Re: Solaris build error: unknown type name ‘gcry_error_t’

2018-08-13 Thread Thomas Huth
For providing a Solaris build machine, you best get in touch with Peter
Maydell (see MAINTAINERS file for his mail address).

Now for your build problems, it seems like "libgcrypt-config --cflags"
already should add /opt/csw/include to the list of header search paths,
so I wonder why the "#include " does not pick up that file yet
and you had to add "#include " instead? Is
there maybe another gcrypt.h file somewhere else on your system which
conflicts with the one from /opt/csw/include ?

Concerning the "-lutil" problem - no clue where this is coming from.
Could you maybe try to compile with "gmake V=1" and post the line where
the executable is linked? Maybe that gives some more indication what is
going on here...

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

Title:
  Solaris build error: unknown type name ‘gcry_error_t’

Status in QEMU:
  New

Bug description:
  Building qemu 2.12.0 on a Sun Oracle Enterprise M3000 SPARC64 VII,
  Solaris 10 Update 11, opencsw toolchain and gcc 7.3.0, gmake fails
  with a bunch of related errors all in cypher-gcrypt.c:

  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:262:32: error: 
‘gcry_cipher_hd_t’ undeclared (first use in this function); did you mean 
‘gcry_cipher_info’?
   err = gcry_cipher_encrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);^~~~
  gcry_cipher_info
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:262:49: error: 
expected ‘)’ before ‘ctx’
   err = gcry_cipher_encrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length); ^~~
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:262:11: error: too few 
arguments to function ‘gcry_cipher_encrypt’
   err = gcry_cipher_encrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);   ^~~
  In file included from 
/export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:25:0,
   from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:
  /usr/include/gcrypt.h:566:5: note: declared here
   int gcry_cipher_encrypt (GcryCipherHd h,
   ^~~
  In file included from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:0:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c: In function 
‘qcrypto_gcrypt_xts_decrypt’:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:271:5: error: unknown 
type name ‘gcry_error_t’; did you mean ‘g_error’?
   gcry_error_t err;
   ^~~~
   g_error
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:272:32: error: 
‘gcry_cipher_hd_t’ undeclared (first use in this function); did you mean 
‘gcry_cipher_info’?
   err = gcry_cipher_decrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);^~~~
  gcry_cipher_info
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:272:49: error: 
expected ‘)’ before ‘ctx’
   err = gcry_cipher_decrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length); ^~~
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:272:11: error: too few 
arguments to function ‘gcry_cipher_decrypt’
   err = gcry_cipher_decrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);   ^~~
  In file included from 
/export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:25:0,
   from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:
  /usr/include/gcrypt.h:571:5: note: declared here
   int gcry_cipher_decrypt (GcryCipherHd h,
   ^~~
  In file included from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:0:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c: In function 
‘qcrypto_gcrypt_cipher_encrypt’:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:284:5: error: unknown 
type name ‘gcry_error_t’; did you mean ‘g_error’?
   gcry_error_t err;
   ^~~~
   g_error
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:293:21: warning: 
passing argument 1 of ‘xts_encrypt’ makes pointer from integer without a cast 
[-Wint-conversion]
   xts_encrypt(ctx->handle, ctx->tweakhandle,
   ^~~
  In file included from 
/export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:22:0,
   from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:
  /export/home/denber/qemu-2.12.0/include/crypto/xts.h:73:6: note: expected 
‘const void *’ but argument is of type ‘int’
   void xts_encrypt(const void *datactx,
    ^~~
  In file included from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:0:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:293:34: warning: 
passing argument 2 of ‘xts_encrypt’ makes pointer from integer without a cast 
[-Wint-conversion]
     

Re: [Qemu-devel] [Qemu-block] [PATCH v0 0/2] Postponed actions

2018-08-13 Thread Denis Plotnikov

Ping ping!

On 16.07.2018 21:59, John Snow wrote:



On 07/16/2018 11:01 AM, Denis Plotnikov wrote:

Ping!



I never saw a reply to Stefan's question on July 2nd, did you reply
off-list?

--js

Yes, I did. I talked to Stefan why the patch set appeared.



On 29.06.2018 15:40, Denis Plotnikov wrote:

There are cases when a request to a block driver state shouldn't have
appeared producing dangerous race conditions.
This misbehaviour is usually happens with storage devices emulated
without eventfd for guest to host notifications like IDE.

The issue arises when the context is in the "drained" section
and doesn't expect the request to come, but request comes from the
device not using iothread and which context is processed by the main
loop.

The main loop apart of the iothread event loop isn't blocked by the
"drained" section.
The request coming and processing while in "drained" section can spoil
the
block driver state consistency.

This behavior can be observed in the following KVM-based case:

1. Setup a VM with an IDE disk.
2. Inside a VM start a disk writing load for the IDE device
    e.g: dd if= of= bs=X count=Y oflag=direct
3. On the host create a mirroring block job for the IDE device
    e.g: drive_mirror  
4. On the host finish the block job
    e.g: block_job_complete 
   Having done the 4th action, you could get an assert:
assert(QLIST_EMPTY(&bs->tracked_requests)) from mirror_run.
On my setup, the assert is 1/3 reproducible.

The patch series introduces the mechanism to postpone the requests
until the BDS leaves "drained" section for the devices not using
iothreads.
Also, it modifies the asynchronous block backend infrastructure to use
that mechanism to release the assert bug for IDE devices.

Denis Plotnikov (2):
    async: add infrastructure for postponed actions
    block: postpone the coroutine executing if the BDS's is drained

   block/block-backend.c | 58 ++-
   include/block/aio.h   | 63 +++
   util/async.c  | 33 +++
   3 files changed, 142 insertions(+), 12 deletions(-)





--
Best,
Denis



Re: [Qemu-devel] QEMU on Solaris

2018-08-13 Thread Daniel P . Berrangé
On Sun, Aug 12, 2018 at 11:40:09AM -0400, Michele Denber wrote:
> After configuring QEMU on my Sun I got this message:
> 
> "Host OS SunOS support is not currently maintained.
> The QEMU project intends to remove support for this host OS in
> a future release if nobody volunteers to maintain it and to
> provide a build host for our continuous integration setup.
> configure has succeeded and you can continue to build, but
> if you care about QEMU on this platform you should contact
> us upstream at qemu-devel@nongnu.org."
> 
> Well I do care about QEMU on my platform so I'd like to volunteer to provide
> a host for support.  I can provide you with a free account on my Sun Oracle
> Enterprise M3000 quad-core 2.75 GHz. SPARC64 VII running Solaris 10 Update
> 11.  I've got plenty of spare CPU cycles and lots of free disk.  Please let
> me know.

Copying Peter, as he would need access to a Solaris host to do GIT pre-merge
build testing.

Then there's the question of what ordinary developers would use for their own
testing if they needed to work on some portability issue. We've got support
in tree for running builds against VM images for the various *BSDs, and have
mingw cross build toolchain for Windows. Is it possible to provide free-to-use
VM disk images for Solaris build testing, or are software licensing requirements
going to get in the way of developers using them ?

There is OpenIndiana that forked off OpenSolaris, but I'm unclear how far
OpenIndiana and commercial Solaris have diverged since then ?

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



Re: [Qemu-devel] [qemu-s390x] [PATCH 5/7] target/s390x: add EX support for TRT and TRTR

2018-08-13 Thread David Hildenbrand
On 10.08.2018 05:01, Pavel Zbitskiy wrote:
> Improves "b213c9f5: target/s390x: Implement TRTR" by introducing the
> intermediate functions, which are compatible with dx_helper type.
> 
> Signed-off-by: Pavel Zbitskiy 
> ---
>  target/s390x/mem_helper.c   | 16 +++
>  tests/tcg/s390x/Makefile.target |  2 ++
>  tests/tcg/s390x/exrl-trt.c  | 48 +
>  tests/tcg/s390x/exrl-trtr.c | 48 +
>  4 files changed, 114 insertions(+)
>  create mode 100644 tests/tcg/s390x/exrl-trt.c
>  create mode 100644 tests/tcg/s390x/exrl-trtr.c
> 
> diff --git a/target/s390x/mem_helper.c b/target/s390x/mem_helper.c
> index c94dbf3fcb..704d0193b5 100644
> --- a/target/s390x/mem_helper.c
> +++ b/target/s390x/mem_helper.c
> @@ -1299,12 +1299,26 @@ static inline uint32_t do_helper_trt(CPUS390XState 
> *env, int len,
>  return 0;
>  }
>  
> +static uint32_t do_helper_trt_fwd(CPUS390XState *env, uint32_t len,
> +  uint64_t array, uint64_t trans,
> +  uintptr_t ra)
> +{
> +return do_helper_trt(env, len, array, trans, 1, ra);
> +}
> +
>  uint32_t HELPER(trt)(CPUS390XState *env, uint32_t len, uint64_t array,
>   uint64_t trans)
>  {
>  return do_helper_trt(env, len, array, trans, 1, GETPC());
>  }
>  
> +static uint32_t do_helper_trt_bkwd(CPUS390XState *env, uint32_t len,
> +   uint64_t array, uint64_t trans,
> +   uintptr_t ra)
> +{
> +return do_helper_trt(env, len, array, trans, -1, ra);
> +}
> +
>  uint32_t HELPER(trtr)(CPUS390XState *env, uint32_t len, uint64_t array,
>uint64_t trans)
>  {
> @@ -2193,12 +2207,14 @@ void HELPER(ex)(CPUS390XState *env, uint32_t ilen, 
> uint64_t r1, uint64_t addr)
>  typedef uint32_t (*dx_helper)(CPUS390XState *, uint32_t, uint64_t,
>uint64_t, uintptr_t);
>  static const dx_helper dx[16] = {
> +[0x0] = do_helper_trt_bkwd,
>  [0x2] = do_helper_mvc,
>  [0x4] = do_helper_nc,
>  [0x5] = do_helper_clc,
>  [0x6] = do_helper_oc,
>  [0x7] = do_helper_xc,
>  [0xc] = do_helper_tr,
> +[0xd] = do_helper_trt_fwd,
>  };
>  dx_helper helper = dx[opc & 0xf];
>  
> diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
> index c800a582e5..7de4376f52 100644
> --- a/tests/tcg/s390x/Makefile.target
> +++ b/tests/tcg/s390x/Makefile.target
> @@ -3,3 +3,5 @@ CFLAGS+=-march=zEC12 -m64
>  TESTS+=hello-s390x
>  TESTS+=csst
>  TESTS+=ipm
> +TESTS+=exrl-trt
> +TESTS+=exrl-trtr
> diff --git a/tests/tcg/s390x/exrl-trt.c b/tests/tcg/s390x/exrl-trt.c
> new file mode 100644
> index 00..3c5323aecb
> --- /dev/null
> +++ b/tests/tcg/s390x/exrl-trt.c
> @@ -0,0 +1,48 @@
> +#include 
> +#include 
> +
> +int main(void)
> +{
> +char op1[] = "hello";
> +char op2[256];
> +uint64_t r1 = 0xull;
> +uint64_t r2 = 0xull;
> +uint64_t cc;
> +int i;
> +
> +for (i = 0; i < 256; i++) {
> +if (i == 0) {
> +op2[i] = 0xaa;
> +} else {
> +op2[i] = 0;
> +}
> +}
> +asm volatile(
> +"j 2f\n"
> +"1:  trt 0(1,%[op1]),0(%[op2])\n"
> +"2:  exrl %[op1_len],1b\n"
> +"lgr %[r1],%%r1\n"
> +"lgr %[r2],%%r2\n"
> +"ipm %[cc]\n"
> +: [r1] "+r" (r1),
> +  [r2] "+r" (r2),
> +  [cc] "=r" (cc)
> +: [op1] "r" (&op1),
> +  [op1_len] "r" (5),
> +  [op2] "r" (&op2)
> +: "r1", "r2", "cc");
> +cc = (cc >> 28) & 3;
> +if (cc != 2) {
> +write(1, "bad cc\n", 7);
> +return 1;
> +}
> +if ((char *)r1 != &op1[5]) {
> +write(1, "bad r1\n", 7);
> +return 1;
> +}
> +if (r2 != 0xffaaull) {
> +write(1, "bad r2\n", 7);
> +return 1;
> +}
> +return 0;
> +}
> diff --git a/tests/tcg/s390x/exrl-trtr.c b/tests/tcg/s390x/exrl-trtr.c
> new file mode 100644
> index 00..c33153ad7e
> --- /dev/null
> +++ b/tests/tcg/s390x/exrl-trtr.c
> @@ -0,0 +1,48 @@
> +#include 
> +#include 
> +
> +int main(void)
> +{
> +char op1[] = {0, 1, 2, 3};
> +char op2[256];
> +uint64_t r1 = 0xull;
> +uint64_t r2 = 0xull;
> +uint64_t cc;
> +int i;
> +
> +for (i = 0; i < 256; i++) {
> +if (i == 1) {
> +op2[i] = 0xbb;
> +} else {
> +op2[i] = 0;
> +}
> +}
> +asm volatile(
> +"j 2f\n"
> +"1:  trtr 3(1,%[op1]),0(%[op2])\n"
> +"2:  exrl %[op1_len],1b\n"
> +"lgr %[r1],%%r1\n"
> +"lgr %[r2],%%r2\n"
> +"ipm %[cc]\n"
> +: [r1] "+r" (r1),
> +  [r2] "+r" (r2),
> +  

[Qemu-devel] vTPM 2.0 is recognized as vTPM 1.2 on the Win 10 virtual machine

2018-08-13 Thread 汤福
Hi,

I want to use the vTPM in a qemu Windows image. Unfortunately, it didn't work.
First, the equipment:
TPM 2.0 hardware
CentOS 7.2
Qemu v2.10.2
SeaBIOS 1.11.0
libtpm and so on

My host is centos 7.2 with the TPM 2.0 hardware and qemu v2.10.2.
I make the libtpm and seabios with ./configure, make and so on. I checked 
seabios with make menuconfig the TPM setting. It is enabled tpm by default.
Eventually, all works without errors.

I start the Widnows 10 image with:
qemu-system-x86_64 -display sdl -enable-kvm -m 2048 -boot d -bios bios.bin 
-boot menu=on -tpmdev 
cuse-tpm,id=tpm0,cancel-path=/dev/null,type=passthrough,path=/dev/tpm0  -device 
tpm-tis,tpmdev=tpm0 win10.img


First it looks all fine. Windows 10 booted up but the vTPM was recognized as 
TPM 1.2 instead of TPM 2.0 in device manager. I open the tpm Manager with 
tpm.msc but get error with No compatible TPM found.
If I use vTPM in a qemu linux image, everything gose well.


So, what could be the problem?
Thanks

Re: [Qemu-devel] [PATCH] file-posix: Skip effectiveless OFD lock operations

2018-08-13 Thread Kevin Wolf
Am 13.08.2018 um 03:45 hat Fam Zheng geschrieben:
> On Fri, 08/10 14:14, Kevin Wolf wrote:
> > Am 18.07.2018 um 10:43 hat Fam Zheng geschrieben:
> > > If we know we've already locked the bytes, don't do it again; similarly
> > > don't unlock a byte if we haven't locked it. This doesn't change the
> > > behavior, but fixes a corner case explained below.
> > > 
> > > Libvirt had an error handling bug that an image can get its (ownership,
> > > file mode, SELinux) permissions changed (RHBZ 1584982) by mistake behind
> > > QEMU. Specifically, an image in use by Libvirt VM has:
> > > 
> > > $ ls -lhZ b.img
> > > -rw-r--r--. qemu qemu system_u:object_r:svirt_image_t:s0:c600,c690 
> > > b.img
> > > 
> > > Trying to attach it a second time won't work because of image locking.
> > > And after the error, it becomes:
> > > 
> > > $ ls -lhZ b.img
> > > -rw-r--r--. root root system_u:object_r:virt_image_t:s0 b.img
> > > 
> > > Then, we won't be able to do OFD lock operations with the existing fd.
> > > In other words, the code such as in blk_detach_dev:
> > > 
> > > blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort);
> > > 
> > > can abort() QEMU, out of environmental changes.
> > > 
> > > This patch is an easy fix to this and the change is regardlessly
> > > reasonable, so do it.
> > > 
> > > Signed-off-by: Fam Zheng 
> > > ---
> > >  block/file-posix.c | 27 +--
> > >  1 file changed, 17 insertions(+), 10 deletions(-)
> > > 
> > > diff --git a/block/file-posix.c b/block/file-posix.c
> > > index 60af4b3d51..45d44c9947 100644
> > > --- a/block/file-posix.c
> > > +++ b/block/file-posix.c
> > > @@ -680,23 +680,28 @@ typedef enum {
> > >   * file; if @unlock == true, also unlock the unneeded bytes.
> > >   * @shared_perm_lock_bits is the mask of all permissions that are NOT 
> > > shared.
> > >   */
> > > -static int raw_apply_lock_bytes(int fd,
> > > +static int raw_apply_lock_bytes(BDRVRawState *s, int fd,
> > >  uint64_t perm_lock_bits,
> > >  uint64_t shared_perm_lock_bits,
> > >  bool unlock, Error **errp)
> > >  {
> > >  int ret;
> > >  int i;
> > > +uint64_t locked_perm, locked_shared_perm;
> > > +
> > > +locked_perm = s ? s->perm : 0;
> > > +locked_shared_perm = s ? ~s->shared_perm & BLK_PERM_ALL : 0;
> > 
> > For the s == NULL case, using 0 is okay for locking because we will
> > always consider the bit as previously unlocked, so we will lock it.
> > 
> > For unlocking, however, we'll also see it as previously unlocked, so we
> > will never actually unlock anything any more.
> > 
> > Am I missing something?
> 
> You are right. Though s == NULL only happens in raw_co_create and the fd will 
> be
> closed before the function returns, I agree for the correctness of this 
> function
> it's better to do a blanket unlock when unlocking. Will respin.

At least one reason why you can't rely on file descriptors being closed
and releasing the locks is fdsets, where there are still more file
descriptors for the same OFD.

Kevin



Re: [Qemu-devel] [qemu-s390x] [PATCH 2/7] target/s390x: add BAL and BALR instructions

2018-08-13 Thread David Hildenbrand
On 10.08.2018 05:01, Pavel Zbitskiy wrote:
> These instructions are provided for compatibility purposes and are
> used only by old software, in the new code BAS and BASR are preferred.
> The difference between the old and new instruction exists only in the
> 24-bit mode.
> 
> Signed-off-by: Pavel Zbitskiy 
> ---
>  target/s390x/insn-data.def |  3 +++
>  target/s390x/translate.c   | 33 +
>  2 files changed, 36 insertions(+)
> 
> diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
> index 5c6f33ed9c..9c7b434fca 100644
> --- a/target/s390x/insn-data.def
> +++ b/target/s390x/insn-data.def
> @@ -102,6 +102,9 @@
>  D(0x9400, NI,  SI,Z,   la1, i2_8u, new, 0, ni, nz64, MO_UB)
>  D(0xeb54, NIY, SIY,   LD,  la1, i2_8u, new, 0, ni, nz64, MO_UB)
>  
> +/* BRANCH AND LINK */
> +C(0x0500, BALR,RR_a,  Z,   0, r2_nz, r1, 0, bal, 0)
> +C(0x4500, BAL, RX_a,  Z,   0, a2, r1, 0, bal, 0)
>  /* BRANCH AND SAVE */
>  C(0x0d00, BASR,RR_a,  Z,   0, r2_nz, r1, 0, bas, 0)
>  C(0x4d00, BAS, RX_a,  Z,   0, a2, r1, 0, bas, 0)
> diff --git a/target/s390x/translate.c b/target/s390x/translate.c
> index 57c03cbf58..316ff79250 100644
> --- a/target/s390x/translate.c
> +++ b/target/s390x/translate.c
> @@ -1463,6 +1463,39 @@ static DisasJumpType op_bas(DisasContext *s, DisasOps 
> *o)
>  }
>  }
>  
> +static void save_link_info(DisasContext *s, DisasOps *o)
> +{
> +TCGv_i64 t;
> +
> +if (s->base.tb->flags & (FLAG_MASK_32 | FLAG_MASK_64)) {
> +tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->pc_tmp));

"In the 24-bit or 31-bit addressing mode, bits 0-31 of
the first-operand location remain unchanged." I think this is also right
now broken for BAS.


> +return;
> +}
> +gen_op_calc_cc(s);
> +tcg_gen_andi_i64(o->out, o->out, 0xull);
> +tcg_gen_ori_i64(o->out, o->out, ((s->ilen / 2) << 30) | s->pc_tmp);
> +t = tcg_temp_new_i64();
> +tcg_gen_shri_i64(t, psw_mask, 16);
> +tcg_gen_andi_i64(t, t, 0x0f00);
> +tcg_gen_or_i64(o->out, o->out, t);
> +tcg_gen_extu_i32_i64(t, cc_op);
> +tcg_gen_shli_i64(t, t, 28);
> +tcg_gen_or_i64(o->out, o->out, t);
> +tcg_temp_free_i64(t);

This looks good to me (ilen really belongs to the current instruction
(not pc_tmp), which seems to be what BAL expects)

> +}
> +
> +static DisasJumpType op_bal(DisasContext *s, DisasOps *o)
> +{
> +save_link_info(s, o);
> +if (o->in2) {
> +tcg_gen_mov_i64(psw_addr, o->in2);
> +per_branch(s, false);
> +return DISAS_PC_UPDATED;
> +} else {
> +return DISAS_NEXT;
> +}
> +}
> +
>  static DisasJumpType op_basi(DisasContext *s, DisasOps *o)
>  {
>  tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->pc_tmp));
> 


-- 

Thanks,

David / dhildenb



Re: [Qemu-devel] [qemu-s390x] [PATCH 1/7] tests/tcg: add a simple s390x test

2018-08-13 Thread David Hildenbrand
On 10.08.2018 05:01, Pavel Zbitskiy wrote:
> Copied from alpha.
> 
> Signed-off-by: Pavel Zbitskiy 
> ---
>  tests/tcg/s390x/Makefile.target | 3 +++
>  tests/tcg/s390x/hello-s390x.c   | 7 +++
>  2 files changed, 10 insertions(+)
>  create mode 100644 tests/tcg/s390x/Makefile.target
>  create mode 100644 tests/tcg/s390x/hello-s390x.c
> 
> diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
> new file mode 100644
> index 00..9f4076901f
> --- /dev/null
> +++ b/tests/tcg/s390x/Makefile.target
> @@ -0,0 +1,3 @@
> +VPATH+=$(SRC_PATH)/tests/tcg/s390x
> +CFLAGS+=-march=zEC12 -m64
> +TESTS+=hello-s390x
> diff --git a/tests/tcg/s390x/hello-s390x.c b/tests/tcg/s390x/hello-s390x.c
> new file mode 100644
> index 00..3dc0a05f2b
> --- /dev/null
> +++ b/tests/tcg/s390x/hello-s390x.c
> @@ -0,0 +1,7 @@
> +#include 
> +
> +int main(void)
> +{
> +write(1, "hello\n", 6);
> +return 0;
> +}
> 

Reviewed-by: David Hildenbrand 

-- 

Thanks,

David / dhildenb



Re: [Qemu-devel] [RFC PATCH 0/3] tweaks for QEMU's C standard

2018-08-13 Thread Daniel P . Berrangé
On Fri, Aug 10, 2018 at 06:10:58PM +0100, Alex Bennée wrote:
> Hi,
> 
> While I was reviewing Richard's SVE series I found Travis choking on
> some perfectly valid c99. It turns out that Travis default image is
> old enough that gcc defaults to -std=gnu89 hence the problem. However
> switching to c99 isn't enough as we use GNUisms and even gnu99 still
> trips up on qemu-secomp.
> 
> Of course we could just jump to C11 already?

We've always required GCC or a compatible compiler (CLang is only viable
alternative option really). We use a number of GCC extensions to the C
standard and I don't see a compelling reason to stop using them.

>From that POV I think we do *NOT* need to care about official C standards
(c89, c99, c11, etc), only the GNU C standards (gnu89, gnu99, gnu11, etc).

> This is an RFC because this could descend into a C standards
> bike-shedding exercise but I thought I'd at least put it out there on
> a Friday afternoon ;-)

I did some archeology to inform our plans...

The default GCC C standards across various versions are:

  8.2.1: gnu17
  7.3.1: gnu11
  6.4.1: gnu11
  5.3.1: gnu11
  4.9.1: gnu89
  4.4.7: gnu89

Interesting to note that no version of GCC ever defaulted to gnu99. It was
not fully implemented initially and by the time the standard was fully
implemented, gnu11 was already good enough to be the default. So GCC jumped
straight from gnu89 as default to gnu11 as default.

Across the various distros we aim to support we have:

  RHEL-7: 4.8.5
  Debian (Stretch): 6.3.0
  Debian (Jessie): 4.9.2
  OpenBSD (Ports): 4.9.4
  FreeBSD (Ports): 8.2.0
  OpenSUSE Leap 15: 7.3.1
  SLE12-SP2:
  Ubuntu (Xenial): 5.4.0
  macOS (Homebrew): 8.2.0

IOW plenty of our plaforms are still on 4.x which defaults to gnu89.

In GCC 4.x, gnu99 is said to be incomplete (but usable) and gnu11
are said to be incomplete and experimental (ie don't use it).

The lowest common denominator supported by all our platforms is thus
gnu89.

If we don't mind that gnu99 is not fully complete in 4.x, we could use
that standard.

We definitely can't use gnu11 any time soon.

Given that many modern platforms default to gnu11, I think we should
set an explicit -std=gnu89, or -std=gnu99, because otherwise we risk
accidentally introducing code that relies on gnu11 features.

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



Re: [Qemu-devel] [PATCH v2 1/4] hw/char: Implement nRF51 SoC UART

2018-08-13 Thread Julia Suvorova via Qemu-devel

On 10.08.2018 09:02, Stefan Hajnoczi wrote:

On Wed, Aug 8, 2018 at 10:07 PM, Julia Suvorova  wrote:

+static uint64_t uart_read(void *opaque, hwaddr addr, unsigned int size)
+{
+NRF51UARTState *s = NRF51_UART(opaque);
+uint64_t r;
+
+if (!s->enabled) {
+return 0;
+}
+
+switch (addr) {
+case A_UART_RXD:
+r = s->rx_fifo[s->rx_fifo_pos];
+if (s->rx_started && s->rx_fifo_len) {
+qemu_chr_fe_accept_input(&s->chr);


Should this be called after popping a byte from the rx fifo?  That way
.can_receive() will return true again.


Could you explain more, please?


+static void nrf51_uart_realize(DeviceState *dev, Error **errp)
+{
+NRF51UARTState *s = NRF51_UART(dev);
+
+qemu_chr_fe_set_handlers(&s->chr, uart_can_receive, uart_receive,
+ uart_event, NULL, s, NULL, true);
+}


unrealize() should set the handlers to NULL.  That way the device can
be removed without leaving callbacks registered.


I don't know the reason, but almost all char devices do not implement
this function. Maybe, because when you quit qemu, qemu_chr_cleanup() is called.

Best regards, Julia Suvorova.




Re: [Qemu-devel] [PATCH v9 6/6] tpm: add ACPI memory clear interface

2018-08-13 Thread Igor Mammedov
On Fri, 10 Aug 2018 17:32:23 +0200
Marc-André Lureau  wrote:

> This allows to pass the last failing test from the Windows HLK TPM 2.0
> TCG PPI 1.3 tests.
> 
> The interface is described in the "TCG Platform Reset Attack
> Mitigation Specification", chapter 6 "ACPI _DSM Function". According
> to Laszlo, it's not so easy to implement in OVMF, he suggested to do
> it in qemu instead.
> 
> Signed-off-by: Marc-André Lureau 
> ---
>  hw/tpm/tpm_ppi.h |  2 ++
>  hw/i386/acpi-build.c | 46 
>  hw/tpm/tpm_crb.c |  1 +
>  hw/tpm/tpm_ppi.c | 23 ++
>  hw/tpm/tpm_tis.c |  1 +
>  docs/specs/tpm.txt   |  2 ++
>  hw/tpm/trace-events  |  3 +++
>  7 files changed, 78 insertions(+)
> 
> diff --git a/hw/tpm/tpm_ppi.h b/hw/tpm/tpm_ppi.h
> index f6458bf87e..3239751e9f 100644
> --- a/hw/tpm/tpm_ppi.h
> +++ b/hw/tpm/tpm_ppi.h
> @@ -23,4 +23,6 @@ typedef struct TPMPPI {
>  bool tpm_ppi_init(TPMPPI *tpmppi, struct MemoryRegion *m,
>hwaddr addr, Object *obj, Error **errp);
>  
> +void tpm_ppi_reset(TPMPPI *tpmppi);
> +
>  #endif /* TPM_TPM_PPI_H */
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index c5e9a6e11d..271c7240dc 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -1824,6 +1824,13 @@ build_tpm_ppi(TPMIf *tpm, Aml *dev)
>  pprq = aml_name("PPRQ");
>  pprm = aml_name("PPRM");
>  
> +aml_append(dev,
> +   aml_operation_region("TPP3", AML_SYSTEM_MEMORY,
> +aml_int(TPM_PPI_ADDR_BASE + 0x200),
> +0x1));
> +field = aml_field("TPP3", AML_BYTE_ACC, AML_NOLOCK, AML_PRESERVE);
> +aml_append(field, aml_named_field("MOVV", 8));
> +aml_append(dev, field);
>  /*
>   * DerefOf in Windows is broken with SYSTEM_MEMORY.  Use a dynamic
>   * operation region inside of a method for getting FUNC[op].
> @@ -2166,7 +2173,46 @@ build_tpm_ppi(TPMIf *tpm, Aml *dev)
>  aml_append(ifctx, aml_return(aml_buffer(1, zerobyte)));
>  }
>  aml_append(method, ifctx);
> +
> +ifctx = aml_if(
> +aml_equal(uuid,
> +  aml_touuid("376054ED-CC13-4675-901C-4756D7F2D45D")));
> +{
> +/* standard DSM query function */
> +ifctx2 = aml_if(aml_equal(function, zero));
> +{
> +uint8_t byte_list[1] = { 0x03 };
> +aml_append(ifctx2, aml_return(aml_buffer(1, byte_list)));
> +}
> +aml_append(ifctx, ifctx2);
> +
> +/*
> + * TCG Platform Reset Attack Mitigation Specification 1.0 Ch.6
> + *
> + * Arg 2 (Integer): Function Index = 1
> + * Arg 3 (Package): Arguments = Package: Type: Integer
> + *  Operation Value of the Request
> + * Returns: Type: Integer
> + *  0: Success
> + *  1: General Failure
> + */
> +ifctx2 = aml_if(aml_equal(function, one));
> +{
> +aml_append(ifctx2,
> +   aml_store(aml_derefof(aml_index(arguments, zero)),
> + op));
> +{
> +aml_append(ifctx2, aml_store(op, aml_name("MOVV")));
> +
> +/* 0: success */
> +aml_append(ifctx2, aml_return(zero));
> +}
> +}
> +aml_append(ifctx, ifctx2);
> +}
> +aml_append(method, ifctx);
>  }
> +
>  aml_append(dev, method);
>  }
>  
> diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
> index b243222fd6..48f6a716ad 100644
> --- a/hw/tpm/tpm_crb.c
> +++ b/hw/tpm/tpm_crb.c
> @@ -233,6 +233,7 @@ static void tpm_crb_reset(void *dev)
>  {
>  CRBState *s = CRB(dev);
>  
> +tpm_ppi_reset(&s->ppi);
>  tpm_backend_reset(s->tpmbe);
>  
>  memset(s->regs, 0, sizeof(s->regs));
> diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c
> index 8b46b9dd4b..dbfe342ca2 100644
> --- a/hw/tpm/tpm_ppi.c
> +++ b/hw/tpm/tpm_ppi.c
> @@ -16,8 +16,30 @@
>  #include "qapi/error.h"
>  #include "cpu.h"
>  #include "sysemu/memory_mapping.h"
> +#include "sysemu/reset.h"
>  #include "migration/vmstate.h"
>  #include "tpm_ppi.h"
> +#include "trace.h"
> +
> +void tpm_ppi_reset(TPMPPI *tpmppi)
> +{
> +char *ptr = memory_region_get_ram_ptr(&tpmppi->ram);
> +
> +if (ptr[0x200] & 0x1) {
> +GuestPhysBlockList guest_phys_blocks;
> +GuestPhysBlock *block;
> +
> +guest_phys_blocks_init(&guest_phys_blocks);
> +guest_phys_blocks_append(&guest_phys_blocks);
> +QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) {
> +trace_tpm_ppi_memset(block->host_addr,
> + block->target_end - block->target_start);
> +memset(block->host_addr, 0,
> +   block->target_end -

Re: [Qemu-devel] [PATCH 1/2] commit: Add top-node/base-node options

2018-08-13 Thread Kevin Wolf
Am 10.08.2018 um 19:33 hat Eric Blake geschrieben:
> On 08/10/2018 11:26 AM, Kevin Wolf wrote:
> > The block-commit QMP command required specifying the top and base nodes
> > of the commit jobs using the file name of that node. While this works
> > in simple cases (local files with absolute paths), the file names
> > generated for more complicated setups can be hard to predict.
> > 
> > This adds two new options top-node and base-node to the command, which
> > allow specifying node names instead. They are mutually exclusive with
> > the old options.
> > 
> > Signed-off-by: Kevin Wolf 
> > ---
> >   qapi/block-core.json | 24 ++--
> >   blockdev.c   | 32 ++--
> >   2 files changed, 48 insertions(+), 8 deletions(-)
> > 
> > diff --git a/qapi/block-core.json b/qapi/block-core.json
> > index 5b9084a394..91dd075c84 100644
> > --- a/qapi/block-core.json
> > +++ b/qapi/block-core.json
> > @@ -1455,12 +1455,23 @@
> >   #
> >   # @device:  the device name or node-name of a root node
> >   #
> > -# @base:   The file name of the backing image to write data into.
> > -#If not specified, this is the deepest backing image.
> > +# @base-node: The node name of the backing image to write data into.
> > +# If not specified, this is the deepest backing image.
> > +# (since: 2.10)
> 
> I'd word this as (since 3.1)...

Whoops. Apparently I didn't read the documentation change carefully
enough when resurrecting this patch from an old branch.

> >  #
> > -# @top:The file name of the backing image within the image chain,
> > -#which contains the topmost data to be committed down. 
> > If
> > -#not specified, this is the active layer.
> > +# @base: Same as @base-node, except that it is a file name rather than a 
> > node
> > +#name. This must be the exact filename string that was used to 
> > open the
> > +#node; other strings, even if addressing the same file, are not
> > +#accepted (deprecated, use @base-node instead)
> 
> ...and this as (since 2.10).

No, 2.10 is just completely wrong. @base exists since the command was
introduced, which is commit ed61fc10e8c or QEMU 1.3.

> When we finish the deprecation and remove @base, then we might
> consolidate the 'since' documentation at that time, but until then, I
> think listing the two separate releases gives users an idea of how far
> back they might have been using the deprecated code, and when the
> preferred form was introduced.

Yes, obviously.

> > +#
> > +# @top-node: The node name of the backing image within the image chain
> > +#which contains the topmost data to be committed down. If
> > +#not specified, this is the active layer. (since: 2.10)
> > +#
> > +# @top: Same as @top-node, except that it is a file name rather than a node
> > +#   name. This must be the exact filename string that was used to open 
> > the
> > +#   node; other strings, even if addressing the same file, are not
> > +#   accepted (deprecated, use @base-node instead)
> 
> Likewise.
> 
> Actually, do we NEED new arguments? Can we just make @base and @top accept
> either an exact file name OR a node name?

No, no, no, no, no!

You can't tell whether "foo" is a file name or a node name, and they
could both exist at the same time, so it would be ambiguous. We should
avoid mixing semantically different things in a single field whenever
it's possible.

The reason why node name and BlockBackend name can be used in the same
option is that they share a name space, i.e. if there is already a node
name "foo", trying to create a BlockBackend "foo" will fail, and vice
versa.

> On the other hand, new arguments are introspectible, overloading the
> old argument to take two forms is not.
> So that doesn't help :(

That, too, yes.

> Or, here's an idea:
> 
> Keep the name @base and @top, but add a new '*by-node':'bool' parameter,
> defaulting to false for now, but perhaps with a deprecation warning that
> we'll switch the default to true in one release and delete the parameter
> altogether in an even later release. When false, @base and @top are
> filenames, as before; when true, @base and @top are node names instead.
> Introspectible, nicer names in the long run, and avoids having to detect a
> user providing two mutually-exclusive options at once.

I don't like options that completely change the semantics of other
options, but maybe that's just personal preference.

Anyway, thinking about the long term for block-commit is useless, the
command is just broken (for example, the @device option doesn't make any
sense) and will have to be replaced. But libvirt needs something _now_
for the -blockdev support, so I decided to add this as a quick hack
before we get the proper replacement.

I think it makes more sense to create a new blockdev-commit (which
would be a name more in line with the other block job commands) and
dep

Re: [Qemu-devel] [RFC PATCH 0/3] tweaks for QEMU's C standard

2018-08-13 Thread Daniel P . Berrangé
On Mon, Aug 13, 2018 at 10:07:05AM +0100, Daniel P. Berrangé wrote:
> On Fri, Aug 10, 2018 at 06:10:58PM +0100, Alex Bennée wrote:
> > Hi,
> > 
> > While I was reviewing Richard's SVE series I found Travis choking on
> > some perfectly valid c99. It turns out that Travis default image is
> > old enough that gcc defaults to -std=gnu89 hence the problem. However
> > switching to c99 isn't enough as we use GNUisms and even gnu99 still
> > trips up on qemu-secomp.
> > 
> > Of course we could just jump to C11 already?
> 
> We've always required GCC or a compatible compiler (CLang is only viable
> alternative option really). We use a number of GCC extensions to the C
> standard and I don't see a compelling reason to stop using them.
> 
> From that POV I think we do *NOT* need to care about official C standards
> (c89, c99, c11, etc), only the GNU C standards (gnu89, gnu99, gnu11, etc).
> 
> > This is an RFC because this could descend into a C standards
> > bike-shedding exercise but I thought I'd at least put it out there on
> > a Friday afternoon ;-)
> 
> I did some archeology to inform our plans...
> 
> The default GCC C standards across various versions are:
> 
>   8.2.1: gnu17
>   7.3.1: gnu11
>   6.4.1: gnu11
>   5.3.1: gnu11
>   4.9.1: gnu89
>   4.4.7: gnu89
> 
> Interesting to note that no version of GCC ever defaulted to gnu99. It was
> not fully implemented initially and by the time the standard was fully
> implemented, gnu11 was already good enough to be the default. So GCC jumped
> straight from gnu89 as default to gnu11 as default.
> 
> Across the various distros we aim to support we have:
> 
>   RHEL-7: 4.8.5
>   Debian (Stretch): 6.3.0
>   Debian (Jessie): 4.9.2
>   OpenBSD (Ports): 4.9.4
>   FreeBSD (Ports): 8.2.0
>   OpenSUSE Leap 15: 7.3.1
>   SLE12-SP2:
>   Ubuntu (Xenial): 5.4.0
>   macOS (Homebrew): 8.2.0
> 
> IOW plenty of our plaforms are still on 4.x which defaults to gnu89.
> 
> In GCC 4.x, gnu99 is said to be incomplete (but usable) and gnu11
> are said to be incomplete and experimental (ie don't use it).
> 
> The lowest common denominator supported by all our platforms is thus
> gnu89.
> 
> If we don't mind that gnu99 is not fully complete in 4.x, we could use
> that standard.
> 
> We definitely can't use gnu11 any time soon.
> 
> Given that many modern platforms default to gnu11, I think we should
> set an explicit -std=gnu89, or -std=gnu99, because otherwise we risk
> accidentally introducing code that relies on gnu11 features.

Also, we should ensure the min required GCC version via biuld time
check of some kind. eg something like

#if !(__GNUC_PREREQ(4, 4) || defined(__clang__))
# error "QEMU requires GCC >= 4.4, or CLang"
#endif


We can even check the C standard at build time if desired. eg I see
these symbols defined for various -std=xxx args:

 gnu89: #undef __STDC_VERSION__
 gnu99: #define __STDC_VERSION__ 199901
 gnu11: #define __STDC_VERSION__ 201112L
 gnu17: #define __STDC_VERSION__ 201710L


(See  "gcc -std=XXX  -dM -E - < /dev/null")

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



Re: [Qemu-devel] [RFC PATCH 0/3] tweaks for QEMU's C standard

2018-08-13 Thread Thomas Huth
On 08/13/2018 11:07 AM, Daniel P. Berrangé wrote:
> On Fri, Aug 10, 2018 at 06:10:58PM +0100, Alex Bennée wrote:
>> Hi,
>>
>> While I was reviewing Richard's SVE series I found Travis choking on
>> some perfectly valid c99. It turns out that Travis default image is
>> old enough that gcc defaults to -std=gnu89 hence the problem. However
>> switching to c99 isn't enough as we use GNUisms and even gnu99 still
>> trips up on qemu-secomp.
>>
>> Of course we could just jump to C11 already?
> 
> We've always required GCC or a compatible compiler (CLang is only viable
> alternative option really). We use a number of GCC extensions to the C
> standard and I don't see a compelling reason to stop using them.
> 
> From that POV I think we do *NOT* need to care about official C standards
> (c89, c99, c11, etc), only the GNU C standards (gnu89, gnu99, gnu11, etc).
> 
>> This is an RFC because this could descend into a C standards
>> bike-shedding exercise but I thought I'd at least put it out there on
>> a Friday afternoon ;-)
> 
> I did some archeology to inform our plans...
> 
> The default GCC C standards across various versions are:
> 
>   8.2.1: gnu17
>   7.3.1: gnu11
>   6.4.1: gnu11
>   5.3.1: gnu11
>   4.9.1: gnu89
>   4.4.7: gnu89
> 
> Interesting to note that no version of GCC ever defaulted to gnu99. It was
> not fully implemented initially and by the time the standard was fully
> implemented, gnu11 was already good enough to be the default. So GCC jumped
> straight from gnu89 as default to gnu11 as default.
> 
> Across the various distros we aim to support we have:
> 
>   RHEL-7: 4.8.5
>   Debian (Stretch): 6.3.0
>   Debian (Jessie): 4.9.2
>   OpenBSD (Ports): 4.9.4
>   FreeBSD (Ports): 8.2.0
>   OpenSUSE Leap 15: 7.3.1
>   SLE12-SP2:
>   Ubuntu (Xenial): 5.4.0
>   macOS (Homebrew): 8.2.0
> 
> IOW plenty of our plaforms are still on 4.x which defaults to gnu89.

Thanks for the great summary!

> In GCC 4.x, gnu99 is said to be incomplete (but usable) and gnu11
> are said to be incomplete and experimental (ie don't use it).
> 
> The lowest common denominator supported by all our platforms is thus
> gnu89.
> 
> If we don't mind that gnu99 is not fully complete in 4.x, we could use
> that standard.
> 
> We definitely can't use gnu11 any time soon.
> 
> Given that many modern platforms default to gnu11, I think we should
> set an explicit -std=gnu89, or -std=gnu99, because otherwise we risk
> accidentally introducing code that relies on gnu11 features.

Sounds good. What about trying -std=gnu99 first, and if we run into
problems, switch back to -std=gnu89 later?

 Thomas



Re: [Qemu-devel] [RFC PATCH 0/3] tweaks for QEMU's C standard

2018-08-13 Thread Peter Maydell
On 13 August 2018 at 10:18, Daniel P. Berrangé  wrote:
> Also, we should ensure the min required GCC version via biuld time
> check of some kind. eg something like
>
> #if !(__GNUC_PREREQ(4, 4) || defined(__clang__))
> # error "QEMU requires GCC >= 4.4, or CLang"
> #endif

Our current minimum is 4.1, I think (per commit fa54abb8c298f),
though we could bump that if there's utility in doing so.

Overall I think we should prefer to avoid specific gcc
version checks wherever we can. clang supports a useful
set of tests like __has_feature and __has_attribute;
gcc supports some of these (eg __has_attribute from gcc 5).

Random aside: I just stumbled across a comment in configure
about a workaround for a gcc 4.6.x bug which says "We should
be able to delete this at the end of 2013" :-)

thanks
-- PMM



[Qemu-devel] [PATCH] chardev/char-fe: Fix typos

2018-08-13 Thread Julia Suvorova via Qemu-devel
Fixup some typos in the comments.

Signed-off-by: Julia Suvorova 
---
 include/chardev/char-fe.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h
index 71cd069478..c67271f1ba 100644
--- a/include/chardev/char-fe.h
+++ b/include/chardev/char-fe.h
@@ -113,7 +113,7 @@ void qemu_chr_fe_accept_input(CharBackend *be);
 /**
  * @qemu_chr_fe_disconnect:
  *
- * Close a fd accpeted by character backend.
+ * Close a fd accepted by character backend.
  * Without associated Chardev, do nothing.
  */
 void qemu_chr_fe_disconnect(CharBackend *be);
@@ -122,7 +122,7 @@ void qemu_chr_fe_disconnect(CharBackend *be);
  * @qemu_chr_fe_wait_connected:
  *
  * Wait for characted backend to be connected, return < 0 on error or
- * if no assicated Chardev.
+ * if no associated Chardev.
  */
 int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp);
 
@@ -186,7 +186,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition 
cond,
  * @buf the data
  * @len the number of bytes to send
  *
- * Returns: the number of bytes consumed (0 if no assicated Chardev)
+ * Returns: the number of bytes consumed (0 if no associated Chardev)
  */
 int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);
 
@@ -201,7 +201,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, 
int len);
  * @buf the data
  * @len the number of bytes to send
  *
- * Returns: the number of bytes consumed (0 if no assicated Chardev)
+ * Returns: the number of bytes consumed (0 if no associated Chardev)
  */
 int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);
 
@@ -213,7 +213,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t 
*buf, int len);
  * @buf the data buffer
  * @len the number of bytes to read
  *
- * Returns: the number of bytes read (0 if no assicated Chardev)
+ * Returns: the number of bytes read (0 if no associated Chardev)
  */
 int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len);
 
-- 
2.17.1




Re: [Qemu-devel] Question about dirty page statistics for live migration

2018-08-13 Thread Dr. David Alan Gilbert
* Li Qiang (liq...@gmail.com) wrote:
> Hello Dave, Juan and all,
> 
> It is useful to get the dirty page rates in guest to evaluate the guest
> loads
> so that we can make a decide to live migrate it or not. So I think we can
> add a on-demand qmp for showing the dirty page rates.
> 
> I found someone has done this work in here:
> -->https://github.com/grivon/yabusame-qemu-dpt
> and here:
> https://github.com/btrplace/qemu-patch
> 
> But seems not go to the upstream.
> 
> I want to know your opinions about adding this qmp.

Something like that could be good;  one easy idea we had was
a 'migrate null:' uri and then you would use most of the existing
migration code to do the measurement; you would only have to
add a dummy file backend, and something to stop the migration ever
terminating (maybe just set the downtime very low).


Dave


> Thanks,
> Li Qiang
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [PATCH] chardev/char-fe: Fix typos

2018-08-13 Thread Peter Maydell
On 13 August 2018 at 10:34, Julia Suvorova via Qemu-devel
 wrote:
> Fixup some typos in the comments.
>
> Signed-off-by: Julia Suvorova 
> ---
Reviewed-by: Peter Maydell 

thanks
-- PMM



Re: [Qemu-devel] [PATCH 1/2] commit: Add top-node/base-node options

2018-08-13 Thread Markus Armbruster
Kevin Wolf  writes:

> Am 10.08.2018 um 19:33 hat Eric Blake geschrieben:
>> On 08/10/2018 11:26 AM, Kevin Wolf wrote:
>> > The block-commit QMP command required specifying the top and base nodes
>> > of the commit jobs using the file name of that node. While this works
>> > in simple cases (local files with absolute paths), the file names
>> > generated for more complicated setups can be hard to predict.
>> > 
>> > This adds two new options top-node and base-node to the command, which
>> > allow specifying node names instead. They are mutually exclusive with
>> > the old options.
>> > 
>> > Signed-off-by: Kevin Wolf 
>> > ---
>> >   qapi/block-core.json | 24 ++--
>> >   blockdev.c   | 32 ++--
>> >   2 files changed, 48 insertions(+), 8 deletions(-)
>> > 
>> > diff --git a/qapi/block-core.json b/qapi/block-core.json
>> > index 5b9084a394..91dd075c84 100644
>> > --- a/qapi/block-core.json
>> > +++ b/qapi/block-core.json
[...]
>> Or, here's an idea:
>> 
>> Keep the name @base and @top, but add a new '*by-node':'bool' parameter,
>> defaulting to false for now, but perhaps with a deprecation warning that
>> we'll switch the default to true in one release and delete the parameter
>> altogether in an even later release. When false, @base and @top are
>> filenames, as before; when true, @base and @top are node names instead.
>> Introspectible, nicer names in the long run, and avoids having to detect a
>> user providing two mutually-exclusive options at once.
>
> I don't like options that completely change the semantics of other
> options, but maybe that's just personal preference.

I happen to share it.

> Anyway, thinking about the long term for block-commit is useless, the
> command is just broken (for example, the @device option doesn't make any
> sense) and will have to be replaced. But libvirt needs something _now_
> for the -blockdev support, so I decided to add this as a quick hack
> before we get the proper replacement.
>
> I think it makes more sense to create a new blockdev-commit (which
> would be a name more in line with the other block job commands) and
> deprecate the old block-commit command as a whole.
>
>> > +++ b/blockdev.c
>> > @@ -3308,7 +3308,9 @@ out:
>> >   }
>> >   void qmp_block_commit(bool has_job_id, const char *job_id, const char 
>> > *device,
>> > +  bool has_base_node, const char *base_node,
>> > bool has_base, const char *base,
>> > +  bool has_top_node, const char *top_node,
>> > bool has_top, const char *top,
>> > bool has_backing_file, const char *backing_file,
>> > bool has_speed, int64_t speed,
>> 
>> Getting to be a long signature. Should we use 'boxed':true in the QAPI file
>> to make this easier to write?  (Separate commit)
>
> It's an option.
>
> Has any progress been made on the plan to support defaults in QAPI, so
> that we could get rid of the has_* parameters?

No.  It's one of those things that keep getting pushed out by more
important or urgent stuff.

I expect it to be straightforward, if tedious.



Re: [Qemu-devel] [PATCH v2 1/4] hw/char: Implement nRF51 SoC UART

2018-08-13 Thread Stefan Hajnoczi
On Mon, Aug 13, 2018 at 10:08 AM Julia Suvorova  wrote:
> On 10.08.2018 09:02, Stefan Hajnoczi wrote:
> > On Wed, Aug 8, 2018 at 10:07 PM, Julia Suvorova  wrote:
> >> +static uint64_t uart_read(void *opaque, hwaddr addr, unsigned int size)
> >> +{
> >> +NRF51UARTState *s = NRF51_UART(opaque);
> >> +uint64_t r;
> >> +
> >> +if (!s->enabled) {
> >> +return 0;
> >> +}
> >> +
> >> +switch (addr) {
> >> +case A_UART_RXD:
> >> +r = s->rx_fifo[s->rx_fifo_pos];
> >> +if (s->rx_started && s->rx_fifo_len) {
> >> +qemu_chr_fe_accept_input(&s->chr);
> >
> > Should this be called after popping a byte from the rx fifo?  That way
> > .can_receive() will return true again.
>
> Could you explain more, please?

This calls into the chardev's ->chr_accept_input() function.  That
function may do anything it wants.

At this point we haven't popped a byte from our rx fifo yet, so if
->chr_accept_input() calls back into the chardev frontend (us!) it
sees that we cannot receive.  That's strange since we just told the
backend we want to accept input!

I haven't checked if there is any code path where this can happen, but
it's safer to first update internal state before letting the outside
world know that we can accept more input.

> >> +static void nrf51_uart_realize(DeviceState *dev, Error **errp)
> >> +{
> >> +NRF51UARTState *s = NRF51_UART(dev);
> >> +
> >> +qemu_chr_fe_set_handlers(&s->chr, uart_can_receive, uart_receive,
> >> + uart_event, NULL, s, NULL, true);
> >> +}
> >
> > unrealize() should set the handlers to NULL.  That way the device can
> > be removed without leaving callbacks registered.
>
> I don't know the reason, but almost all char devices do not implement
> this function. Maybe, because when you quit qemu, qemu_chr_cleanup() is 
> called.

It's an assumption that on-board devices cannot be hot unplugged and
that the machine type stays alive until QEMU terminates.

Making this assumption saves 1 call to qemu_chr_fe_set_handlers().
The cost is that we cannot safely stop the system-on-chip because its
devices don't clean up properly.

Since cleanup is so trivial here I think it's worthwhile.

Stefan



Re: [Qemu-devel] [RFC PATCH 0/3] tweaks for QEMU's C standard

2018-08-13 Thread Alex Bennée


Daniel P. Berrangé  writes:

> On Mon, Aug 13, 2018 at 10:07:05AM +0100, Daniel P. Berrangé wrote:
>> On Fri, Aug 10, 2018 at 06:10:58PM +0100, Alex Bennée wrote:
>> > Hi,
>> >
>> > While I was reviewing Richard's SVE series I found Travis choking on
>> > some perfectly valid c99. It turns out that Travis default image is
>> > old enough that gcc defaults to -std=gnu89 hence the problem. However
>> > switching to c99 isn't enough as we use GNUisms and even gnu99 still
>> > trips up on qemu-secomp.
>> >
>> > Of course we could just jump to C11 already?
>>
>> We've always required GCC or a compatible compiler (CLang is only viable
>> alternative option really). We use a number of GCC extensions to the C
>> standard and I don't see a compelling reason to stop using them.
>>
>> From that POV I think we do *NOT* need to care about official C standards
>> (c89, c99, c11, etc), only the GNU C standards (gnu89, gnu99, gnu11, etc).
>>
>> > This is an RFC because this could descend into a C standards
>> > bike-shedding exercise but I thought I'd at least put it out there on
>> > a Friday afternoon ;-)
>>
>> I did some archeology to inform our plans...
>>
>> The default GCC C standards across various versions are:
>>
>>   8.2.1: gnu17
>>   7.3.1: gnu11
>>   6.4.1: gnu11
>>   5.3.1: gnu11
>>   4.9.1: gnu89
>>   4.4.7: gnu89
>>
>> Interesting to note that no version of GCC ever defaulted to gnu99. It was
>> not fully implemented initially and by the time the standard was fully
>> implemented, gnu11 was already good enough to be the default. So GCC jumped
>> straight from gnu89 as default to gnu11 as default.
>>
>> Across the various distros we aim to support we have:
>>
>>   RHEL-7: 4.8.5
>>   Debian (Stretch): 6.3.0
>>   Debian (Jessie): 4.9.2
>>   OpenBSD (Ports): 4.9.4
>>   FreeBSD (Ports): 8.2.0
>>   OpenSUSE Leap 15: 7.3.1
>>   SLE12-SP2:
>>   Ubuntu (Xenial): 5.4.0
>>   macOS (Homebrew): 8.2.0
>>
>> IOW plenty of our plaforms are still on 4.x which defaults to gnu89.
>>
>> In GCC 4.x, gnu99 is said to be incomplete (but usable) and gnu11
>> are said to be incomplete and experimental (ie don't use it).
>>
>> The lowest common denominator supported by all our platforms is thus
>> gnu89.
>>
>> If we don't mind that gnu99 is not fully complete in 4.x, we could use
>> that standard.

Thanks for the digging. I wonder what is missing in 4.x?

As far as I can tell we make heavy use of typeof() but I don't know how
to audit for other GNUisms? Everything should be in a compiler.h right?

I just noticed we have a C11-like generics macro in there ;-)

>>
>> We definitely can't use gnu11 any time soon.
>>
>> Given that many modern platforms default to gnu11, I think we should
>> set an explicit -std=gnu89, or -std=gnu99, because otherwise we risk
>> accidentally introducing code that relies on gnu11 features.
>
> Also, we should ensure the min required GCC version via biuld time
> check of some kind. eg something like
>
> #if !(__GNUC_PREREQ(4, 4) || defined(__clang__))
> # error "QEMU requires GCC >= 4.4, or CLang"
> #endif
>
>
> We can even check the C standard at build time if desired. eg I see
> these symbols defined for various -std=xxx args:
>
>  gnu89: #undef __STDC_VERSION__
>  gnu99: #define __STDC_VERSION__ 199901
>  gnu11: #define __STDC_VERSION__ 201112L
>  gnu17: #define __STDC_VERSION__ 201710L
>
>
> (See  "gcc -std=XXX  -dM -E - < /dev/null")
>
> Regards,
> Daniel


--
Alex Bennée



Re: [Qemu-devel] [PATCH] virtio: add support for in-order feature

2018-08-13 Thread Michael S. Tsirkin
On Mon, Aug 13, 2018 at 10:55:23AM +0300, Ilya Maximets wrote:
> On 10.08.2018 22:19, Michael S. Tsirkin wrote:
> > On Fri, Aug 10, 2018 at 02:04:47PM +0300, Ilya Maximets wrote:
> >> On 10.08.2018 12:34, Michael S. Tsirkin wrote:
> >>> On Fri, Aug 10, 2018 at 11:28:47AM +0300, Ilya Maximets wrote:
>  On 10.08.2018 01:51, Michael S. Tsirkin wrote:
> > On Thu, Aug 09, 2018 at 07:54:37PM +0300, Ilya Maximets wrote:
> >> New feature bit for in-order feature of the upcoming
> >> virtio 1.1. It's already supported by DPDK vhost-user
> >> and virtio implementations. These changes required to
> >> allow feature negotiation.
> >>
> >> Signed-off-by: Ilya Maximets 
> >> ---
> >>
> >> I just wanted to test this new feature in DPDK but failed
> >> to found required patch for QEMU side. So, I implemented it.
> >> At least it will be helpful for someone like me, who wants
> >> to evaluate VIRTIO_F_IN_ORDER with DPDK.
> >>
> >>  hw/net/vhost_net.c |  1 +
> >>  include/hw/virtio/virtio.h | 12 +++-
> >>  include/standard-headers/linux/virtio_config.h |  7 +++
> >>  3 files changed, 15 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> >> index e037db6..86879c5 100644
> >> --- a/hw/net/vhost_net.c
> >> +++ b/hw/net/vhost_net.c
> >> @@ -78,6 +78,7 @@ static const int user_feature_bits[] = {
> >>  VIRTIO_NET_F_MRG_RXBUF,
> >>  VIRTIO_NET_F_MTU,
> >>  VIRTIO_F_IOMMU_PLATFORM,
> >> +VIRTIO_F_IN_ORDER,
> >>  
> >>  /* This bit implies RARP isn't sent by QEMU out of band */
> >>  VIRTIO_NET_F_GUEST_ANNOUNCE,
> >> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> >> index 9c1fa07..a422025 100644
> >> --- a/include/hw/virtio/virtio.h
> >> +++ b/include/hw/virtio/virtio.h
> >> @@ -254,16 +254,18 @@ typedef struct virtio_input_conf 
> >> virtio_input_conf;
> >>  typedef struct VirtIOSCSIConf VirtIOSCSIConf;
> >>  typedef struct VirtIORNGConf VirtIORNGConf;
> >>  
> >> -#define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
> >> +#define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
> >>  DEFINE_PROP_BIT64("indirect_desc", _state, _field,\
> >>VIRTIO_RING_F_INDIRECT_DESC, true), \
> >>  DEFINE_PROP_BIT64("event_idx", _state, _field,\
> >>VIRTIO_RING_F_EVENT_IDX, true), \
> >>  DEFINE_PROP_BIT64("notify_on_empty", _state, _field,  \
> >> -  VIRTIO_F_NOTIFY_ON_EMPTY, true), \
> >> -DEFINE_PROP_BIT64("any_layout", _state, _field, \
> >> -  VIRTIO_F_ANY_LAYOUT, true), \
> >> -DEFINE_PROP_BIT64("iommu_platform", _state, _field, \
> >> +  VIRTIO_F_NOTIFY_ON_EMPTY, true),\
> >> +DEFINE_PROP_BIT64("any_layout", _state, _field,   \
> >> +  VIRTIO_F_ANY_LAYOUT, true), \
> >> +DEFINE_PROP_BIT64("in_order", _state, _field, \
> >> +  VIRTIO_F_IN_ORDER, true),   \
> >> +DEFINE_PROP_BIT64("iommu_platform", _state, _field,   \
> >>VIRTIO_F_IOMMU_PLATFORM, false)
> >
> > Is in_order really right for all virtio devices?
> 
>  I see nothing device specific in this feature. It just specifies
>  some restrictions on the descriptors handling. All virtio devices
>  could use it to have performance benefits. Also, upcoming packed
>  rings should give a good performance boost in case of enabled
>  in-order feature. And packed rings RFC [1] implements
>  VIRTIO_F_RING_PACKED for all virtio devices. So, I see no issues
>  in enabling in-order negotiation for all of them.
> 
>  What do you think?
> 
>  [1] https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg01028.html
> 
>  Best regards, Ilya Maximets.
> >>>
> >>> If guest assumes in-order use of buffers but device uses them out of
> >>> order then guest will crash. So there's a missing piece where
> >>> you actually make devices use buffers in order when the flag is set.
> >>
> >> I thought that feature negotiation is the mechanism that should
> >> protect us from situations like that. Isn't it?
> >> If device negotiates in-order feature, when it MUST (as described
> >> in spec) use buffers in the same order in which they have been
> >> available.
> > 
> > Exactly. And your patch does nothing to ensure that,

Let me elaborate. Your patch adds an in order property to
all virtio devices. When set, guests will assume that
all buffers are used in the order they have been made
available. However, IIUC current virtio code in qemu
sometimes uses buffers out of order. Therefore
with your patch applied devices behave ou

Re: [Qemu-devel] [PATCH v4 4/6] loader: add rom transaction API

2018-08-13 Thread Stefan Hajnoczi
On Wed, Aug 8, 2018 at 10:32 PM Alistair Francis  wrote:
> On Fri, Aug 3, 2018 at 7:47 AM, Stefan Hajnoczi  wrote:
> > @@ -1168,6 +1172,34 @@ void rom_reset_order_override(void)
> >  fw_cfg_reset_order_override(fw_cfg);
> >  }
> >
> > +void rom_transaction_begin(void)
> > +{
> > +Rom *rom;
> > +
> > +/* Ignore ROMs added without the transaction API */
> > +QTAILQ_FOREACH(rom, &roms, next) {
> > +rom->committed = true;
>
> My only thought is that maybe this should produce a warning or error
> if a ROM isn't committed.

Not all loaders use the transaction API.  Therefore it is likely that
some pre-existing ROMs will have ->committed = false.

For example, imagine a firmware ROM is loaded by the machine type and
then -kernel is used to load a file.  The -kernel loader shouldn't
worry about the firmware ROM, which was added without the transaction
API.

If we want to be strict I'd have to audit all ROM API users and wrap
them in add rom_transaction_begin/end() even if they cannot fail.
This is why I decided to simply ignore pre-existing ROMs.

Stefan



Re: [Qemu-devel] QEMU on Solaris

2018-08-13 Thread Peter Tribble
On Mon, Aug 13, 2018 at 9:34 AM, Daniel P. Berrangé 
wrote:

> On Sun, Aug 12, 2018 at 11:40:09AM -0400, Michele Denber wrote:
> > After configuring QEMU on my Sun I got this message:
> >
> > "Host OS SunOS support is not currently maintained.
> > The QEMU project intends to remove support for this host OS in
> > a future release if nobody volunteers to maintain it and to
> > provide a build host for our continuous integration setup.
> > configure has succeeded and you can continue to build, but
> > if you care about QEMU on this platform you should contact
> > us upstream at qemu-devel@nongnu.org."
> >
> > Well I do care about QEMU on my platform so I'd like to volunteer to
> provide
> > a host for support.  I can provide you with a free account on my Sun
> Oracle
> > Enterprise M3000 quad-core 2.75 GHz. SPARC64 VII running Solaris 10
> Update
> > 11.  I've got plenty of spare CPU cycles and lots of free disk.  Please
> let
> > me know.
>
> Copying Peter, as he would need access to a Solaris host to do GIT
> pre-merge
> build testing.
>
> Then there's the question of what ordinary developers would use for their
> own
> testing if they needed to work on some portability issue. We've got support
> in tree for running builds against VM images for the various *BSDs, and
> have
> mingw cross build toolchain for Windows. Is it possible to provide
> free-to-use
> VM disk images for Solaris build testing, or are software licensing
> requirements
> going to get in the way of developers using them ?
>
> There is OpenIndiana that forked off OpenSolaris, but I'm unclear how far
> OpenIndiana and commercial Solaris have diverged since then ?
>

>From the point of view of software such as qemu, divergences should be
slight
(there are going to be changes around packaging, shipped compilers, but
that's
true for different Linux distros in the same family). If it builds and
works on
Solaris, it'll build and work on one of the illumos distributions, and vice
versa.
(Although I note that's Solaris 10 mentioned above, which is now EOL, and
may be a little more problematic due to its age.)

You can certainly run illumos (such as OpenIndiana or Tribblix) in a VM
easily,
and freely. I can help with that.

That's for x86, of course. Building on a SPARC platform is a different
matter
entirely. (Although that's one of the reasons some of us are interested in
qemu
in the first place.)

Thanks,

-- 
-Peter Tribble
http://www.petertribble.co.uk/ - http://ptribble.blogspot.com/


Re: [Qemu-devel] [PATCH] chardev/char-fe: Fix typos

2018-08-13 Thread Paolo Bonzini
On 13/08/2018 11:34, Julia Suvorova wrote:
> Fixup some typos in the comments.
> 
> Signed-off-by: Julia Suvorova 
> ---
>  include/chardev/char-fe.h | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h
> index 71cd069478..c67271f1ba 100644
> --- a/include/chardev/char-fe.h
> +++ b/include/chardev/char-fe.h
> @@ -113,7 +113,7 @@ void qemu_chr_fe_accept_input(CharBackend *be);
>  /**
>   * @qemu_chr_fe_disconnect:
>   *
> - * Close a fd accpeted by character backend.
> + * Close a fd accepted by character backend.
>   * Without associated Chardev, do nothing.
>   */
>  void qemu_chr_fe_disconnect(CharBackend *be);
> @@ -122,7 +122,7 @@ void qemu_chr_fe_disconnect(CharBackend *be);
>   * @qemu_chr_fe_wait_connected:
>   *
>   * Wait for characted backend to be connected, return < 0 on error or
> - * if no assicated Chardev.
> + * if no associated Chardev.
>   */
>  int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp);
>  
> @@ -186,7 +186,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition 
> cond,
>   * @buf the data
>   * @len the number of bytes to send
>   *
> - * Returns: the number of bytes consumed (0 if no assicated Chardev)
> + * Returns: the number of bytes consumed (0 if no associated Chardev)
>   */
>  int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);
>  
> @@ -201,7 +201,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t 
> *buf, int len);
>   * @buf the data
>   * @len the number of bytes to send
>   *
> - * Returns: the number of bytes consumed (0 if no assicated Chardev)
> + * Returns: the number of bytes consumed (0 if no associated Chardev)
>   */
>  int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);
>  
> @@ -213,7 +213,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t 
> *buf, int len);
>   * @buf the data buffer
>   * @len the number of bytes to read
>   *
> - * Returns: the number of bytes read (0 if no assicated Chardev)
> + * Returns: the number of bytes read (0 if no associated Chardev)
>   */
>  int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len);
>  
> 

Queued, thanks.

Paolo



[Qemu-devel] [PATCH 00/33] Qtest driver framework

2018-08-13 Thread Emanuele Giuseppe Esposito
Qgraph API for the qtest driver framework

This series of patches introduce a different qtest driver
organization, viewing machines, drivers and tests as node in a
graph, each having one or multiple edges relations.

The idea is to have a framework where each test asks for a specific
driver, and the framework takes care of allocating the proper devices
required and passing the correct command line arguments to QEMU.

A node can be of four types:
- MACHINE:   for example "arm/raspi2"
- DRIVER:for example "generic-sdhci"
- INTERFACE: for example "sdhci" (interface for all "-sdhci" drivers)
- TEST:  for example "sdhci-test", consumes an interface and tests
 the functions provided

An edge relation between two nodes (drivers or machines) X and Y can be:
- X CONSUMES Y: Y can be plugged into X
- X PRODUCES Y: X provides the interface Y
- X CONTAINS Y: Y is part of X component

Basic framework steps are the following:
- All nodes and edges are created in their respective machine/driver/test files
- The framework starts QEMU and asks for a list of available devices
  and machines
- The framework walks the graph starting from the available machines and
  performs a Depth First Search for tests
- Once a test is found, the path is walked again and all drivers are
  allocated accordingly and the final interface is passed to the test
- The test is executed
- Unused objects are cleaned and the path discovery is continued

Depending on the QEMU binary used, only some drivers/machines will be available
and only test that are reached by them will be executed.

This work is being done as Google Summer of Code 2018 project for QEMU,
my mentors are Paolo Bonzini and Laurent Vivier.
Additional infos on the project can be found at:
https://wiki.qemu.org/Features/qtest_driver_framework

v3:
- Minor fixes regarding memory leaks and naming

Signed-off-by: Emanuele Giuseppe Esposito 

Emanuele Giuseppe Esposito (32):
  tests: qgraph API for the qtest driver framework
  tests/qgraph: rename qpci_init_pc and qpci_init_spapr functions
  tests/qgraph: pci-pc driver and interface nodes
  tests/qgraph: x86_64/pc machine node
  tests/qgraph: sdhci driver and interface nodes
  tests/qgraph: sdhci test node
  tests/qgraph: arm/raspi2 machine node
  tests/qgraph: pci-spapr driver and interface nodes
  tests/qgraph: ppc64/pseries machine node
  tests/qgraph: has_buggy_msi flag
  tests/qgraph: e1000e driver and interface nodes
  tests/qgraph: e1000e-test node
  tests/qgraph: virtio_start_device function
  tests/qgraph: virtio-pci driver and interface nodes
  tests/qgraph: virtio-mmio driver and interface nodes
  tests/qgraph: arm/virt machine node
  tests/qgraph: virtio-serial driver and interface nodes
  tests/qgraph: virtio-console test node
  tests/qgraph: virtio-serial test node
  tests/qgraph: virtio-9p driver and interface nodes
  tests/qgraph: virtio-9p test node
  tests/qgraph: virtio-balloon driver and interface nodes
  tests/qgraph: virtio-balloon test node
  tests/qgraph: virtio-rng driver and interface nodes
  tests/qgraph: virtio-rng test node
  tests/qgraph: virtio-blk driver and interface nodes
  tests/qgraph: virtio-blk test node
  tests/qgraph: virtio-net driver and interface nodes
  tests/qgraph: virtio-net test node
  tests/qgraph: virtio-scsi driver and interface nodes
  tests/qgraph: virtio-scsi test node
  tests/qgraph: temporarly commented vhost-user-test

Paolo Bonzini (1):
  tests: virtio: separate ccw tests from libqos

 configure|   2 +-
 include/qemu/module.h|   2 +
 tests/Makefile.include   |  79 +--
 tests/e1000e-test.c  | 354 +++--
 tests/i440fx-test.c  |   2 +-
 tests/ide-test.c |   2 +-
 tests/libqos/ahci.c  |   2 +-
 tests/libqos/e1000e.c| 262 ++
 tests/libqos/e1000e.h|  53 ++
 tests/libqos/libqos-pc.c |   2 +-
 tests/libqos/libqos-spapr.c  |   2 +-
 tests/libqos/libqos.c|   2 +-
 tests/libqos/libqos.h|   2 +-
 tests/libqos/pci-pc.c|  86 ++--
 tests/libqos/pci-pc.h|  22 +-
 tests/libqos/pci-spapr.c | 119 +++--
 tests/libqos/pci-spapr.h |  26 +-
 tests/libqos/pci.c   |  37 +-
 tests/libqos/pci.h   |  15 +
 tests/libqos/ppc64_pseries-machine.c | 111 +
 tests/libqos/qgraph.c| 721 +++
 tests/libqos/qgraph.h| 515 +++
 tests/libqos/qgraph_extra.h  | 263 ++
 tests/libqos/raspi2-machine.c|  82 +++
 tests/libqos/sdhci.c | 163 ++
 tests/libqos/sdhci.h |  69 +++
 tests/libqos/virt-machine.c  |  90 
 tests/libqos/virtio-9p.c | 165 ++
 tests/libqos/virtio-9p.h |  42 ++
 tests/libqos/virtio-balloon.c| 111 +
 test

[Qemu-devel] [PATCH 04/33] tests/qgraph: x86_64/pc machine node

2018-08-13 Thread Emanuele Giuseppe Esposito
Add pc machine for the x86_64 QEMU binary. This machine contains an 
i440FX-pcihost
driver, that contains itself a pci-bus-pc that produces the pci-bus interface.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include   |   3 +
 tests/libqos/x86_64_pc-machine.c | 110 +++
 2 files changed, 113 insertions(+)
 create mode 100644 tests/libqos/x86_64_pc-machine.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index d99a58894b..2154e53944 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -771,7 +771,10 @@ 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-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
 
+libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
+
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
+libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
diff --git a/tests/libqos/x86_64_pc-machine.c b/tests/libqos/x86_64_pc-machine.c
new file mode 100644
index 00..d8db18d0ff
--- /dev/null
+++ b/tests/libqos/x86_64_pc-machine.c
@@ -0,0 +1,110 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/qgraph.h"
+#include "pci-pc.h"
+#include "malloc-pc.h"
+
+typedef struct QX86_64_PCMachine QX86_64_PCMachine;
+typedef struct i440FX_pcihost i440FX_pcihost;
+typedef struct QSDHCI_PCI  QSDHCI_PCI;
+
+struct i440FX_pcihost {
+QOSGraphObject obj;
+QPCIBusPC pci;
+};
+
+struct QX86_64_PCMachine {
+QOSGraphObject obj;
+QGuestAllocator *alloc;
+i440FX_pcihost bridge;
+};
+
+/* i440FX_pcihost */
+
+static QOSGraphObject *i440FX_host_get_device(void *obj, const char *device)
+{
+i440FX_pcihost *host = obj;
+if (!g_strcmp0(device, "pci-bus-pc")) {
+return &host->pci.obj;
+}
+fprintf(stderr, "%s not present in i440FX-pcihost\n", device);
+g_assert_not_reached();
+}
+
+static void qos_create_i440FX_host(i440FX_pcihost *host,
+   QGuestAllocator *alloc)
+{
+host->obj.get_device = i440FX_host_get_device;
+qpci_init_pc(&host->pci, global_qtest, alloc);
+}
+
+/* x86_64/pc machine */
+
+static void pc_destructor(QOSGraphObject *obj)
+{
+QX86_64_PCMachine *machine = (QX86_64_PCMachine *) obj;
+pc_alloc_uninit(machine->alloc);
+g_free(machine);
+}
+
+static void *pc_get_driver(void *object, const char *interface)
+{
+QX86_64_PCMachine *machine = object;
+if (!g_strcmp0(interface, "memory")) {
+return machine->alloc;
+}
+
+fprintf(stderr, "%s not present in x86_64/pc\n", interface);
+g_assert_not_reached();
+}
+
+static QOSGraphObject *pc_get_device(void *obj, const char *device)
+{
+QX86_64_PCMachine *machine = obj;
+if (!g_strcmp0(device, "i440FX-pcihost")) {
+return &machine->bridge.obj;
+}
+
+fprintf(stderr, "%s not present in x86_64/pc\n", device);
+g_assert_not_reached();
+}
+
+static void *qos_create_machine_pc(void)
+{
+QX86_64_PCMachine *machine = g_new0(QX86_64_PCMachine, 1);
+machine->obj.get_device = pc_get_device;
+machine->obj.get_driver = pc_get_driver;
+machine->obj.destructor = pc_destructor;
+machine->alloc = pc_alloc_init_flags(global_qtest, ALLOC_NO_FLAGS);
+qos_create_i440FX_host(&machine->bridge, machine->alloc);
+
+return &machine->obj;
+}
+
+static void pc_machine_register_nodes(void)
+{
+qos_node_create_machine("x86_64/pc", qos_create_machine_pc);
+qos_node_create_driver("i440FX-pcihost", NULL);
+qos_node_contains("x86_64/pc", "i440FX-pcihost", NULL);
+qos_node_contains("i440FX-pcihost", "pci-bus-pc", NULL);
+}
+
+libqos_init(pc_machine_register_nodes);
-- 
2.17.1




[Qemu-devel] [PATCH 02/33] tests/qgraph: rename qpci_init_pc and qpci_init_spapr functions

2018-08-13 Thread Emanuele Giuseppe Esposito
Rename qpci_init_pc in qpci_pc_new and qpci_init_spapr in qpci_spapr_new,
since theese function actually allocate a new pci struct and initialize it.
Changed QOSOps field name from qpci_init to qpci_new.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/e1000e-test.c | 2 +-
 tests/i440fx-test.c | 2 +-
 tests/ide-test.c| 2 +-
 tests/libqos/ahci.c | 2 +-
 tests/libqos/libqos-pc.c| 2 +-
 tests/libqos/libqos-spapr.c | 2 +-
 tests/libqos/libqos.c   | 2 +-
 tests/libqos/libqos.h   | 2 +-
 tests/libqos/pci-pc.c   | 2 +-
 tests/libqos/pci-pc.h   | 9 -
 tests/libqos/pci-spapr.c| 2 +-
 tests/libqos/pci-spapr.h| 2 +-
 tests/q35-test.c| 4 ++--
 tests/rtl8139-test.c| 2 +-
 tests/sdhci-test.c  | 2 +-
 tests/tco-test.c| 2 +-
 tests/usb-hcd-ehci-test.c   | 2 +-
 tests/vhost-user-test.c | 2 +-
 18 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c
index 32aa738b72..574801fd38 100644
--- a/tests/e1000e-test.c
+++ b/tests/e1000e-test.c
@@ -395,7 +395,7 @@ static void data_test_init(e1000e_device *d)
 test_alloc = pc_alloc_init(global_qtest);
 g_assert_nonnull(test_alloc);
 
-test_bus = qpci_init_pc(global_qtest, test_alloc);
+test_bus = qpci_new_pc(global_qtest, test_alloc);
 g_assert_nonnull(test_bus);
 
 e1000e_device_init(test_bus, d);
diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c
index 4390e5591e..69205b58a8 100644
--- a/tests/i440fx-test.c
+++ b/tests/i440fx-test.c
@@ -38,7 +38,7 @@ static QPCIBus *test_start_get_bus(const TestData *s)
 cmdline = g_strdup_printf("-smp %d", s->num_cpus);
 qtest_start(cmdline);
 g_free(cmdline);
-return qpci_init_pc(global_qtest, NULL);
+return qpci_new_pc(global_qtest, NULL);
 }
 
 static void test_i440fx_defaults(gconstpointer opaque)
diff --git a/tests/ide-test.c b/tests/ide-test.c
index 2384c2c3e2..ab1fac6074 100644
--- a/tests/ide-test.c
+++ b/tests/ide-test.c
@@ -150,7 +150,7 @@ static QPCIDevice *get_pci_device(QPCIBar *bmdma_bar, 
QPCIBar *ide_bar)
 uint16_t vendor_id, device_id;
 
 if (!pcibus) {
-pcibus = qpci_init_pc(global_qtest, NULL);
+pcibus = qpci_new_pc(global_qtest, NULL);
 }
 
 /* Find PCI device and verify it's the right one */
diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c
index 42d3f76933..36814b4a38 100644
--- a/tests/libqos/ahci.c
+++ b/tests/libqos/ahci.c
@@ -130,7 +130,7 @@ QPCIDevice *get_ahci_device(QTestState *qts, uint32_t 
*fingerprint)
 uint32_t ahci_fingerprint;
 QPCIBus *pcibus;
 
-pcibus = qpci_init_pc(qts, NULL);
+pcibus = qpci_new_pc(qts, NULL);
 
 /* Find the AHCI PCI device and verify it's the right one. */
 ahci = qpci_device_find(pcibus, QPCI_DEVFN(0x1F, 0x02));
diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c
index a9c1aceaa7..293f9b6fe6 100644
--- a/tests/libqos/libqos-pc.c
+++ b/tests/libqos/libqos-pc.c
@@ -6,7 +6,7 @@
 static QOSOps qos_ops = {
 .init_allocator = pc_alloc_init_flags,
 .uninit_allocator = pc_alloc_uninit,
-.qpci_init = qpci_init_pc,
+.qpci_new = qpci_new_pc,
 .qpci_free = qpci_free_pc,
 .shutdown = qtest_pc_shutdown,
 };
diff --git a/tests/libqos/libqos-spapr.c b/tests/libqos/libqos-spapr.c
index a37791e5d0..64addfe577 100644
--- a/tests/libqos/libqos-spapr.c
+++ b/tests/libqos/libqos-spapr.c
@@ -6,7 +6,7 @@
 static QOSOps qos_ops = {
 .init_allocator = spapr_alloc_init_flags,
 .uninit_allocator = spapr_alloc_uninit,
-.qpci_init = qpci_init_spapr,
+.qpci_new = qpci_new_spapr,
 .qpci_free = qpci_free_spapr,
 .shutdown = qtest_spapr_shutdown,
 };
diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
index 013ca68581..48b9682d81 100644
--- a/tests/libqos/libqos.c
+++ b/tests/libqos/libqos.c
@@ -25,7 +25,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, 
va_list ap)
 qs->ops = ops;
 if (ops) {
 qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS);
-qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
+qs->pcibus = ops->qpci_new(qs->qts, qs->alloc);
 }
 
 g_free(cmdline);
diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h
index 07d4b93d1d..1af6035db4 100644
--- a/tests/libqos/libqos.h
+++ b/tests/libqos/libqos.h
@@ -10,7 +10,7 @@ typedef struct QOSState QOSState;
 typedef struct QOSOps {
 QGuestAllocator *(*init_allocator)(QTestState *qts, QAllocOpts);
 void (*uninit_allocator)(QGuestAllocator *);
-QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc);
+QPCIBus *(*qpci_new)(QTestState *qts, QGuestAllocator *alloc);
 void (*qpci_free)(QPCIBus *bus);
 void (*shutdown)(QOSState *);
 } QOSOps;
diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c
index a7803308b7..644f45d8b0 100644
--- a/tests/libqos/pci-pc.c
+++ b/tests/libqos/pci-pc.c
@@ -115,7 +115,7 @@ static void qpci_pc_config_w

[Qemu-devel] [PATCH 07/33] tests/qgraph: arm/raspi2 machine node

2018-08-13 Thread Emanuele Giuseppe Esposito
Add arm/raspi2 machine to the graph. This machine contains a generic-sdhci, so
its constructor must take care of setting it properly when called.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include|  1 +
 tests/libqos/raspi2-machine.c | 82 +++
 2 files changed, 83 insertions(+)
 create mode 100644 tests/libqos/raspi2-machine.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index c4c7c8d56a..67dbec0d35 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -769,6 +769,7 @@ libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) 
tests/libqos/usb.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
 
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
+libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/raspi2-machine.c b/tests/libqos/raspi2-machine.c
new file mode 100644
index 00..72fe7f3d4f
--- /dev/null
+++ b/tests/libqos/raspi2-machine.c
@@ -0,0 +1,82 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/malloc.h"
+#include "libqos/qgraph.h"
+#include "sdhci.h"
+
+typedef struct QRaspi2Machine QRaspi2Machine;
+
+struct QRaspi2Machine {
+QOSGraphObject obj;
+QGuestAllocator *alloc;
+QSDHCI_MemoryMapped sdhci;
+};
+
+static void raspi2_destructor(QOSGraphObject *obj)
+{
+g_free(obj);
+}
+
+static void *raspi2_get_driver(void *object, const char *interface)
+{
+QRaspi2Machine *machine = object;
+if (!g_strcmp0(interface, "memory")) {
+return &machine->alloc;
+}
+
+fprintf(stderr, "%s not present in arm/raspi2\n", interface);
+g_assert_not_reached();
+}
+
+static QOSGraphObject *raspi2_get_device(void *obj, const char *device)
+{
+QRaspi2Machine *machine = obj;
+if (!g_strcmp0(device, "generic-sdhci")) {
+return &machine->sdhci.obj;
+}
+
+fprintf(stderr, "%s not present in arm/raspi2\n", device);
+g_assert_not_reached();
+}
+
+static void *qos_create_machine_arm_raspi2(void)
+{
+QRaspi2Machine *machine = g_new0(QRaspi2Machine, 1);
+
+machine->obj.get_device = raspi2_get_device;
+machine->obj.get_driver = raspi2_get_driver;
+machine->obj.destructor = raspi2_destructor;
+qos_init_sdhci_smm(&machine->sdhci, 0x3f30, &(QSDHCIProperties) {
+.version = 3,
+.baseclock = 52,
+.capab.sdma = false,
+.capab.reg = 0x052134b4
+});
+return &machine->obj;
+}
+
+static void raspi2_register_nodes(void)
+{
+qos_node_create_machine("arm/raspi2", qos_create_machine_arm_raspi2);
+qos_node_contains("arm/raspi2", "generic-sdhci", NULL);
+}
+
+libqos_init(raspi2_register_nodes);
-- 
2.17.1




[Qemu-devel] [PATCH 05/33] tests/qgraph: sdhci driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for sdhci-pci and generic-sdhci (memory mapped) drivers.
Both drivers implement (produce) the same interface sdhci, that provides the
readw - readq - writeq functions.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |   1 +
 tests/libqos/sdhci.c   | 163 +
 tests/libqos/sdhci.h   |  69 +
 3 files changed, 233 insertions(+)
 create mode 100644 tests/libqos/sdhci.c
 create mode 100644 tests/libqos/sdhci.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 2154e53944..90a74854b8 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -775,6 +775,7 @@ libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 
 libqgraph-pci-obj-y = $(libqos-pc-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += tests/libqos/sdhci.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
diff --git a/tests/libqos/sdhci.c b/tests/libqos/sdhci.c
new file mode 100644
index 00..65b407d741
--- /dev/null
+++ b/tests/libqos/sdhci.c
@@ -0,0 +1,163 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/qgraph.h"
+#include "pci.h"
+#include "sdhci.h"
+#include "hw/pci/pci.h"
+
+static void set_qsdhci_fields(QSDHCI *s, uint8_t version, uint8_t baseclock,
+  bool sdma, uint64_t reg)
+{
+s->props.version = version;
+s->props.baseclock = baseclock;
+s->props.capab.sdma = sdma;
+s->props.capab.reg = reg;
+}
+
+/* Memory mapped implementation of QSDHCI */
+
+static uint16_t sdhci_mm_readw(QSDHCI *s, uint32_t reg)
+{
+QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci);
+return qtest_readw(global_qtest, smm->addr + reg);
+}
+
+static uint64_t sdhci_mm_readq(QSDHCI *s, uint32_t reg)
+{
+QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci);
+return qtest_readq(global_qtest, smm->addr + reg);
+}
+
+static void sdhci_mm_writeq(QSDHCI *s, uint32_t reg, uint64_t val)
+{
+QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci);
+qtest_writeq(global_qtest, smm->addr + reg, val);
+}
+
+static void *sdhci_mm_get_driver(void *obj, const char *interface)
+{
+QSDHCI_MemoryMapped *smm = obj;
+if (!g_strcmp0(interface, "sdhci")) {
+return &smm->sdhci;
+}
+fprintf(stderr, "%s not present in generic-sdhci\n", interface);
+g_assert_not_reached();
+}
+
+void qos_init_sdhci_smm(QSDHCI_MemoryMapped *sdhci, uint32_t addr,
+   QSDHCIProperties *common)
+{
+sdhci->obj.get_driver = sdhci_mm_get_driver;
+sdhci->sdhci.readw = sdhci_mm_readw;
+sdhci->sdhci.readq = sdhci_mm_readq;
+sdhci->sdhci.writeq = sdhci_mm_writeq;
+memcpy(&sdhci->sdhci.props, common, sizeof(QSDHCIProperties));
+sdhci->addr = addr;
+}
+
+/* PCI implementation of QSDHCI */
+
+static uint16_t sdhci_pci_readw(QSDHCI *s, uint32_t reg)
+{
+QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci);
+return qpci_io_readw(&spci->dev, spci->mem_bar, reg);
+}
+
+static uint64_t sdhci_pci_readq(QSDHCI *s, uint32_t reg)
+{
+QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci);
+return qpci_io_readq(&spci->dev, spci->mem_bar, reg);
+}
+
+static void sdhci_pci_writeq(QSDHCI *s, uint32_t reg, uint64_t val)
+{
+QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci);
+return qpci_io_writeq(&spci->dev, spci->mem_bar, reg, val);
+}
+
+static void *sdhci_pci_get_driver(void *object, const char *interface)
+{
+QSDHCI_PCI *spci = object;
+if (!g_strcmp0(interface, "sdhci")) {
+return &spci->sdhci;
+}
+
+fprintf(stderr, "%s not present in sdhci-pci\n", interface);
+g_assert_not_reached();
+}
+
+static void sdhci_pci_start_hw(QOSGraphObject *obj)
+{
+QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+qpci_device_enable(&spci->dev);
+}
+
+static void sdhci_destructor(QOSGraphObject *obj)
+{
+QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+qpci_iounmap(&spci->dev, spci->mem_bar);
+g_free(spci);
+}
+
+static void *sdhci_pci_create(void *pci_bus, QGuestAllocator *alloc, void 
*addr)
+{
+QSDHCI_PCI *spci = g_new0(QSDHCI_PCI, 1);
+QPCIBus *bus = pci_bus;
+   

[Qemu-devel] [PATCH 06/33] tests/qgraph: sdhci test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/sdhci-test in first qgraph test node, sdhci-test. This test
consumes an sdhci interface and checks that its function return the
expected values.

Note that this test does not allocate any sdhci structure, it's all done by the
qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |   9 +-
 tests/sdhci-test.c | 222 -
 2 files changed, 68 insertions(+), 163 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 90a74854b8..c4c7c8d56a 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -311,7 +311,6 @@ check-qtest-i386-y += tests/migration-test$(EXESUF)
 check-qtest-i386-y += tests/test-x86-cpuid-compat$(EXESUF)
 check-qtest-i386-y += tests/numa-test$(EXESUF)
 check-qtest-x86_64-y += $(check-qtest-i386-y)
-check-qtest-x86_64-y += tests/sdhci-test$(EXESUF)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
 gcov-files-x86_64-y = $(subst 
i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
 
@@ -385,10 +384,8 @@ gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
-check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
-check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
@@ -777,11 +774,14 @@ libqgraph-pci-obj-y = $(libqos-pc-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 
+libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
+libqgraph-tests-obj-y += tests/sdhci-test.o
+
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
 
 check-qtest-generic-y += tests/qos-test$(EXESUF)
-tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-obj-y)
+tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-tests-obj-y)
 
 tests/qmp-test$(EXESUF): tests/qmp-test.o
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
@@ -867,7 +867,6 @@ tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o
 tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y)
 tests/numa-test$(EXESUF): tests/numa-test.o
 tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o 
tests/acpi-utils.o
-tests/sdhci-test$(EXESUF): tests/sdhci-test.o $(libqos-pc-obj-y)
 tests/cdrom-test$(EXESUF): tests/cdrom-test.o tests/boot-sector.o 
$(libqos-obj-y)
 
 tests/migration/stress$(EXESUF): tests/migration/stress.o
diff --git a/tests/sdhci-test.c b/tests/sdhci-test.c
index be3bad6ceb..ed29839f3d 100644
--- a/tests/sdhci-test.c
+++ b/tests/sdhci-test.c
@@ -12,6 +12,8 @@
 #include "libqtest.h"
 #include "libqos/pci-pc.h"
 #include "hw/pci/pci.h"
+#include "libqos/qgraph.h"
+#include "libqos/sdhci.h"
 
 #define SDHC_CAPAB  0x40
 FIELD(SDHC_CAPAB, BASECLKFREQ,   8, 8); /* since v2 */
@@ -20,99 +22,60 @@ FIELD(SDHC_CAPAB, SDR,  32, 3); /* 
since v3 */
 FIELD(SDHC_CAPAB, DRIVER,   36, 3); /* since v3 */
 #define SDHC_HCVER  0xFE
 
-static const struct sdhci_t {
-const char *arch, *machine;
-struct {
-uintptr_t addr;
-uint8_t version;
-uint8_t baseclock;
+/**
+ * Old sdhci_t structure:
+ *
+struct sdhci_t {
+const char *arch, *machine;
 struct {
-bool sdma;
-uint64_t reg;
-} capab;
-} sdhci;
-struct {
-uint16_t vendor_id, device_id;
-} pci;
-} models[] = {
-/* PC via PCI */
-{ "x86_64", "pc",
-{-1, 2, 0,  {1, 0x057834b4} },
-.pci = { PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_SDHCI } },
-
-/* Exynos4210 */
-{ "arm","smdkc210",
-{0x1251, 2, 0,  {1, 0x5e80080} } },
-
-/* i.MX 6 */
-{ "arm","sabrelite",
-{0x0219, 3, 0,  {1, 0x057834b4} } },
-
-/* BCM2835 */
-{ "arm","raspi2",
-{0x3f30, 3, 52, {0, 0x052134b4} } },
-
-/* Zynq-7000 */
-{ "arm","xilinx-zynq-a9",   /* Datasheet: UG585 (v1.12.1) */
-{0xe010, 2, 0,  {1, 0x69ec0080} } },
-
-/* ZynqMP */
-{ "aarch64", "xlnx-zcu102", /* Datasheet: UG1085 (v1.7) */
-{0xff16, 3, 0,  {1, 0x280737ec6481} } },
-
-};
-
-typedef struct QSDHCI {
-struct {
-QPCIBus *bus;
-QPCIDevice *dev;
-} pci;
-union {
-QPCIBar mem_bar;
-uint64_t addr;
-};
-} QSDHCI;
-
-static uint16_t sdhci_readw(QSDHCI *s, uint32_t reg)
-{
-uint16_t val;
-
-if (s->pci.dev) {
-val = qpci_io_readw(s->pci.dev, s->mem_bar, reg);
-} else {
-val = qtest_readw(global_qtest, s->addr + reg);
+uintptr_t addr;
+uint8_t version;
+  

[Qemu-devel] [PATCH 10/33] tests/qgraph: has_buggy_msi flag

2018-08-13 Thread Emanuele Giuseppe Esposito
The Qgraph framework makes any test using
pci bus run the same function using pci-pci and
pci-spapr bus. However, some tests are not ready to use
the spapr bus, due to a MSI bug. Until it does not get
fixed, this flag allows them to skip the test

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/libqos/pci-pc.c| 3 +++
 tests/libqos/pci-spapr.c | 3 +++
 tests/libqos/pci.c   | 5 +
 tests/libqos/pci.h   | 3 +++
 4 files changed, 14 insertions(+)

diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c
index 93cbfbce6b..0cf87f51b5 100644
--- a/tests/libqos/pci-pc.c
+++ b/tests/libqos/pci-pc.c
@@ -123,6 +123,9 @@ void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, 
QGuestAllocator *alloc)
 {
 assert(qts);
 
+/* tests can use pci-bus */
+qpci->bus.has_buggy_msi = FALSE;
+
 qpci->bus.pio_readb = qpci_pc_pio_readb;
 qpci->bus.pio_readw = qpci_pc_pio_readw;
 qpci->bus.pio_readl = qpci_pc_pio_readl;
diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c
index 24f2c2c60d..502a0e5129 100644
--- a/tests/libqos/pci-spapr.c
+++ b/tests/libqos/pci-spapr.c
@@ -155,6 +155,9 @@ void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qts,
 {
 assert(qts);
 
+/* tests cannot use spapr, needs to be fixed first */
+qpci->bus.has_buggy_msi = TRUE;
+
 qpci->alloc = alloc;
 
 qpci->bus.pio_readb = qpci_spapr_pio_readb;
diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c
index 080e87533e..d5bace9d6a 100644
--- a/tests/libqos/pci.c
+++ b/tests/libqos/pci.c
@@ -51,6 +51,11 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int 
device_id,
 }
 }
 
+bool qpci_has_buggy_msi(QPCIDevice *dev)
+{
+return dev->bus->has_buggy_msi;
+}
+
 static void qpci_device_set(QPCIDevice *dev, QPCIBus *bus, int devfn)
 {
 g_assert(dev);
diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h
index bcfa6d85a4..5fb3c550c5 100644
--- a/tests/libqos/pci.h
+++ b/tests/libqos/pci.h
@@ -53,6 +53,7 @@ struct QPCIBus {
 QTestState *qts;
 uint16_t pio_alloc_ptr;
 uint64_t mmio_alloc_ptr, mmio_limit;
+bool has_buggy_msi; /* TRUE for spapr, FALSE for pci */
 
 };
 
@@ -80,6 +81,8 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int 
device_id,
  void *data);
 QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn);
 void qpci_device_init(QPCIDevice *dev, QPCIBus *bus, QPCIAddress *addr);
+/* returns the bus has_buggy_msi flag */
+bool qpci_has_buggy_msi(QPCIDevice *dev);
 
 void qpci_device_enable(QPCIDevice *dev);
 uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id);
-- 
2.17.1




[Qemu-devel] [PATCH 03/33] tests/qgraph: pci-pc driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add pci-bus-pc node, move QPCIBusPC struct declaration in its header
(since it will be needed by other drivers) and introduce a setter method
for drivers that do not need to allocate but have to initialize QPCIBusPC.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |  2 +
 tests/libqos/pci-pc.c  | 83 +++---
 tests/libqos/pci-pc.h  | 17 -
 tests/libqos/pci.c | 32 +++-
 tests/libqos/pci.h | 12 ++
 5 files changed, 112 insertions(+), 34 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index d3ac711db2..d99a58894b 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -771,6 +771,8 @@ 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-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
 
+libqgraph-pci-obj-y = $(libqos-pc-obj-y)
+
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
 
diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c
index 644f45d8b0..93cbfbce6b 100644
--- a/tests/libqos/pci-pc.c
+++ b/tests/libqos/pci-pc.c
@@ -18,15 +18,9 @@
 
 #include "qemu-common.h"
 
-
 #define ACPI_PCIHP_ADDR 0xae00
 #define PCI_EJ_BASE 0x0008
 
-typedef struct QPCIBusPC
-{
-QPCIBus bus;
-} QPCIBusPC;
-
 static uint8_t qpci_pc_pio_readb(QPCIBus *bus, uint32_t addr)
 {
 return inb(addr);
@@ -115,44 +109,65 @@ static void qpci_pc_config_writel(QPCIBus *bus, int 
devfn, uint8_t offset, uint3
 outl(0xcfc, value);
 }
 
-QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc)
+static void *qpci_pc_get_driver(void *obj, const char *interface)
 {
-QPCIBusPC *ret = g_new0(QPCIBusPC, 1);
+QPCIBusPC *qpci = obj;
+if (!g_strcmp0(interface, "pci-bus")) {
+return &qpci->bus;
+}
+fprintf(stderr, "%s not present in pci-bus-pc\n", interface);
+g_assert_not_reached();
+}
 
+void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, QGuestAllocator *alloc)
+{
 assert(qts);
 
-ret->bus.pio_readb = qpci_pc_pio_readb;
-ret->bus.pio_readw = qpci_pc_pio_readw;
-ret->bus.pio_readl = qpci_pc_pio_readl;
-ret->bus.pio_readq = qpci_pc_pio_readq;
+qpci->bus.pio_readb = qpci_pc_pio_readb;
+qpci->bus.pio_readw = qpci_pc_pio_readw;
+qpci->bus.pio_readl = qpci_pc_pio_readl;
+qpci->bus.pio_readq = qpci_pc_pio_readq;
+
+qpci->bus.pio_writeb = qpci_pc_pio_writeb;
+qpci->bus.pio_writew = qpci_pc_pio_writew;
+qpci->bus.pio_writel = qpci_pc_pio_writel;
+qpci->bus.pio_writeq = qpci_pc_pio_writeq;
+
+qpci->bus.memread = qpci_pc_memread;
+qpci->bus.memwrite = qpci_pc_memwrite;
 
-ret->bus.pio_writeb = qpci_pc_pio_writeb;
-ret->bus.pio_writew = qpci_pc_pio_writew;
-ret->bus.pio_writel = qpci_pc_pio_writel;
-ret->bus.pio_writeq = qpci_pc_pio_writeq;
+qpci->bus.config_readb = qpci_pc_config_readb;
+qpci->bus.config_readw = qpci_pc_config_readw;
+qpci->bus.config_readl = qpci_pc_config_readl;
 
-ret->bus.memread = qpci_pc_memread;
-ret->bus.memwrite = qpci_pc_memwrite;
+qpci->bus.config_writeb = qpci_pc_config_writeb;
+qpci->bus.config_writew = qpci_pc_config_writew;
+qpci->bus.config_writel = qpci_pc_config_writel;
 
-ret->bus.config_readb = qpci_pc_config_readb;
-ret->bus.config_readw = qpci_pc_config_readw;
-ret->bus.config_readl = qpci_pc_config_readl;
+qpci->bus.qts = qts;
+qpci->bus.pio_alloc_ptr = 0xc000;
+qpci->bus.mmio_alloc_ptr = 0xE000;
+qpci->bus.mmio_limit = 0x1ULL;
 
-ret->bus.config_writeb = qpci_pc_config_writeb;
-ret->bus.config_writew = qpci_pc_config_writew;
-ret->bus.config_writel = qpci_pc_config_writel;
+qpci->obj.get_driver = qpci_pc_get_driver;
+}
 
-ret->bus.qts = qts;
-ret->bus.pio_alloc_ptr = 0xc000;
-ret->bus.mmio_alloc_ptr = 0xE000;
-ret->bus.mmio_limit = 0x1ULL;
+QPCIBus *qpci_new_pc(QTestState *qts, QGuestAllocator *alloc)
+{
+QPCIBusPC *qpci = g_new0(QPCIBusPC, 1);
+qpci_init_pc(qpci, qts, alloc);
 
-return &ret->bus;
+return &qpci->bus;
 }
 
 void qpci_free_pc(QPCIBus *bus)
 {
-QPCIBusPC *s = container_of(bus, QPCIBusPC, bus);
+QPCIBusPC *s;
+
+if (!bus) {
+return;
+}
+s = container_of(bus, QPCIBusPC, bus);
 
 g_free(s);
 }
@@ -176,3 +191,11 @@ void qpci_unplug_acpi_device_test(const char *id, uint8_t 
slot)
 
 qmp_eventwait("DEVICE_DELETED");
 }
+
+static void qpci_pc_register_nodes(void)
+{
+qos_node_create_driver("pci-bus-pc", NULL);
+qos_node_produces("pci-bus-pc", "pci-bus");
+}
+
+libqos_init(qpci_pc_register_nodes);
diff --git a/tests/libqos/pci-pc.h b/tests/libqos/pci-pc.h
index 84cc300735..7b0751d1ef 100644
--- a/tests/l

[Qemu-devel] [PATCH 13/33] tests/qgraph: virtio_start_device function

2018-08-13 Thread Emanuele Giuseppe Esposito
This function is intended to group all the qvirtio_* functions that
start the qvirtio devices.
Applied in all tests using this combination of functions.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/libqos/virtio.c|  7 +++
 tests/libqos/virtio.h|  1 +
 tests/vhost-user-test.c  |  4 +---
 tests/virtio-9p-test.c   |  4 +---
 tests/virtio-blk-test.c  | 10 +++---
 tests/virtio-net-test.c  |  4 +---
 tests/virtio-scsi-test.c |  4 +---
 7 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index 0dad5c19ac..c1ff0206d5 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -365,3 +365,10 @@ const char *qvirtio_get_dev_type(void)
 return "pci";
 }
 }
+
+void qvirtio_start_device(QVirtioDevice *vdev)
+{
+qvirtio_reset(vdev);
+qvirtio_set_acknowledge(vdev);
+qvirtio_set_driver(vdev);
+}
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 69b5b13840..2c68668de0 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -146,5 +146,6 @@ bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, 
uint32_t *len);
 void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx);
 
 const char *qvirtio_get_dev_type(void);
+void qvirtio_start_device(QVirtioDevice *vdev);
 
 #endif
diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
index a976808eba..d43d09a013 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -198,9 +198,7 @@ static void init_virtio_dev(TestServer *s, uint32_t 
features_mask)
 g_assert_nonnull(s->dev);
 
 qvirtio_pci_device_enable(s->dev);
-qvirtio_reset(&s->dev->vdev);
-qvirtio_set_acknowledge(&s->dev->vdev);
-qvirtio_set_driver(&s->dev->vdev);
+qvirtio_start_device(&s->dev->vdev);
 
 s->alloc = pc_alloc_init(global_qtest);
 
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index a2b31085f6..d275c74106 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -65,9 +65,7 @@ static QVirtIO9P *qvirtio_9p_pci_start(void)
 v9p->dev = (QVirtioDevice *) dev;
 
 qvirtio_pci_device_enable(dev);
-qvirtio_reset(v9p->dev);
-qvirtio_set_acknowledge(v9p->dev);
-qvirtio_set_driver(v9p->dev);
+qvirtio_start_device(v9p->dev);
 
 v9p->vq = qvirtqueue_setup(v9p->dev, v9p->qs->alloc, 0);
 
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 9be9ffb378..66797d0348 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -112,10 +112,7 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, 
int slot)
 g_assert_cmphex(dev->pdev->devfn, ==, ((slot << 3) | PCI_FN));
 
 qvirtio_pci_device_enable(dev);
-qvirtio_reset(&dev->vdev);
-qvirtio_set_acknowledge(&dev->vdev);
-qvirtio_set_driver(&dev->vdev);
-
+qvirtio_start_device(&dev->vdev);
 return dev;
 }
 
@@ -329,6 +326,7 @@ static void pci_indirect(void)
 qvirtio_set_features(&dev->vdev, features);
 
 vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
+
 qvirtio_set_driver_ok(&dev->vdev);
 
 /* Write request */
@@ -715,9 +713,7 @@ static void mmio_basic(void)
 g_assert(dev != NULL);
 g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK);
 
-qvirtio_reset(&dev->vdev);
-qvirtio_set_acknowledge(&dev->vdev);
-qvirtio_set_driver(&dev->vdev);
+qvirtio_start_device(&dev->vdev);
 
 alloc = generic_alloc_init(MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE_SIZE);
 vq = qvirtqueue_setup(&dev->vdev, alloc, 0);
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index b285a262e9..72728acf66 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -45,9 +45,7 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, 
int slot)
 g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET);
 
 qvirtio_pci_device_enable(dev);
-qvirtio_reset(&dev->vdev);
-qvirtio_set_acknowledge(&dev->vdev);
-qvirtio_set_driver(&dev->vdev);
+qvirtio_start_device(&dev->vdev);
 
 return dev;
 }
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 037872bb98..1581b6926c 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -159,9 +159,7 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot)
 g_assert_cmphex(vs->dev->device_type, ==, VIRTIO_ID_SCSI);
 
 qvirtio_pci_device_enable(dev);
-qvirtio_reset(vs->dev);
-qvirtio_set_acknowledge(vs->dev);
-qvirtio_set_driver(vs->dev);
+qvirtio_start_device(vs->dev);
 
 vs->num_queues = qvirtio_config_readl(vs->dev, 0);
 
-- 
2.17.1




[Qemu-devel] [PATCH 16/33] tests/qgraph: arm/virt machine node

2018-08-13 Thread Emanuele Giuseppe Esposito
Add arm/virt machine to the graph. This machine contains virtio-mmio, so
its constructor must take care of setting it properly when called.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include  |  1 +
 tests/libqos/virt-machine.c | 90 +
 2 files changed, 91 insertions(+)
 create mode 100644 tests/libqos/virt-machine.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 5220136473..20cb983ed0 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -770,6 +770,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) 
$(libqos-pc-obj-y) tests/libqos/virt
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
+libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virt-machine.c b/tests/libqos/virt-machine.c
new file mode 100644
index 00..c8910a58f4
--- /dev/null
+++ b/tests/libqos/virt-machine.c
@@ -0,0 +1,90 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/malloc.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-mmio.h"
+#include "libqos/malloc-generic.h"
+
+#define ARM_PAGE_SIZE   4096
+#define VIRTIO_MMIO_BASE_ADDR   0x0A003E00
+#define ARM_VIRT_RAM_ADDR   0x4000
+#define ARM_VIRT_RAM_SIZE   0x2000
+#define VIRTIO_MMIO_SIZE0x0200
+
+typedef struct QVirtioMachine QVirtioMachine;
+
+struct QVirtioMachine {
+QOSGraphObject obj;
+QGuestAllocator *alloc;
+QVirtioMMIODevice virtio_mmio;
+};
+
+static void virtio_destructor(QOSGraphObject *obj)
+{
+QVirtioMachine *machine = (QVirtioMachine *) obj;
+generic_alloc_uninit(machine->alloc);
+g_free(obj);
+}
+
+static void *virtio_get_driver(void *object, const char *interface)
+{
+QVirtioMachine *machine = object;
+if (!g_strcmp0(interface, "memory")) {
+return machine->alloc;
+}
+
+fprintf(stderr, "%s not present in arm/virtio\n", interface);
+g_assert_not_reached();
+}
+
+static QOSGraphObject *virtio_get_device(void *obj, const char *device)
+{
+QVirtioMachine *machine = obj;
+if (!g_strcmp0(device, "virtio-mmio")) {
+return &machine->virtio_mmio.obj;
+}
+
+fprintf(stderr, "%s not present in arm/virtio\n", device);
+g_assert_not_reached();
+}
+
+static void *qos_create_machine_arm_virt(void)
+{
+QVirtioMachine *machine = g_new0(QVirtioMachine, 1);
+
+machine->alloc = generic_alloc_init(ARM_VIRT_RAM_ADDR, ARM_VIRT_RAM_SIZE,
+ARM_PAGE_SIZE);
+qvirtio_mmio_init_device(&machine->virtio_mmio, VIRTIO_MMIO_BASE_ADDR,
+ VIRTIO_MMIO_SIZE);
+
+machine->obj.get_device = virtio_get_device;
+machine->obj.get_driver = virtio_get_driver;
+machine->obj.destructor = virtio_destructor;
+return machine;
+}
+
+static void virtio_mmio_register_nodes(void)
+{
+qos_node_create_machine("arm/virt", qos_create_machine_arm_virt);
+qos_node_contains("arm/virt", "virtio-mmio", NULL);
+}
+
+libqos_init(virtio_mmio_register_nodes);
-- 
2.17.1




[Qemu-devel] [PATCH 01/33] tests: qgraph API for the qtest driver framework

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph API that allows to add/remove nodes and edges from the graph,
implementation of Depth First Search to discover the paths and basic unit
test to check correctness of the API.
Included also a main executable that takes care of starting the framework,
create the nodes, set the available drivers/machines, discover the path and
run tests.

graph.h provides the public API to manage the graph nodes/edges
graph_extra.h provides a more private API used successively by the gtest 
integration part
qos-test.c provides the main executable

Signed-off-by: Emanuele Giuseppe Esposito 
---
 configure   |   2 +-
 include/qemu/module.h   |   2 +
 tests/Makefile.include  |  12 +-
 tests/libqos/qgraph.c   | 721 
 tests/libqos/qgraph.h   | 515 ++
 tests/libqos/qgraph_extra.h | 263 +
 tests/libqtest.h|   3 +
 tests/qos-test.c| 481 
 tests/test-qgraph.c | 446 ++
 9 files changed, 2442 insertions(+), 3 deletions(-)
 create mode 100644 tests/libqos/qgraph.c
 create mode 100644 tests/libqos/qgraph.h
 create mode 100644 tests/libqos/qgraph_extra.h
 create mode 100644 tests/qos-test.c
 create mode 100644 tests/test-qgraph.c

diff --git a/configure b/configure
index 2a7796ea80..85a108506a 100755
--- a/configure
+++ b/configure
@@ -7352,7 +7352,7 @@ if test "$ccache_cpp2" = "yes"; then
 fi
 
 # build tree in object directory in case the source is not in the current 
directory
-DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos 
tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm"
+DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos 
tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm tests/qgraph"
 DIRS="$DIRS docs docs/interop fsdev scsi"
 DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw"
 DIRS="$DIRS roms/seabios roms/vgabios"
diff --git a/include/qemu/module.h b/include/qemu/module.h
index 54300ab6e5..1fcdca084d 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -44,6 +44,7 @@ typedef enum {
 MODULE_INIT_OPTS,
 MODULE_INIT_QOM,
 MODULE_INIT_TRACE,
+MODULE_INIT_LIBQOS,
 MODULE_INIT_MAX
 } module_init_type;
 
@@ -51,6 +52,7 @@ typedef enum {
 #define opts_init(function) module_init(function, MODULE_INIT_OPTS)
 #define type_init(function) module_init(function, MODULE_INIT_QOM)
 #define trace_init(function) module_init(function, MODULE_INIT_TRACE)
+#define libqos_init(function) module_init(function, MODULE_INIT_LIBQOS)
 
 #define block_module_load_one(lib) module_load_one("block-", lib)
 #define ui_module_load_one(lib) module_load_one("ui-", lib)
diff --git a/tests/Makefile.include b/tests/Makefile.include
index a49282704e..d3ac711db2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -755,8 +755,10 @@ tests/test-crypto-ivgen$(EXESUF): 
tests/test-crypto-ivgen.o $(test-crypto-obj-y)
 tests/test-crypto-afsplit$(EXESUF): tests/test-crypto-afsplit.o 
$(test-crypto-obj-y)
 tests/test-crypto-block$(EXESUF): tests/test-crypto-block.o 
$(test-crypto-obj-y)
 
-libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
-libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
+libqgraph-obj-y = tests/libqos/qgraph.o
+
+libqos-obj-y = $(libqgraph-obj-y) tests/libqos/pci.o tests/libqos/fw_cfg.o
+libqos-obj-y += tests/libqos/malloc.o tests/libqos/i2c.o tests/libqos/libqos.o
 libqos-spapr-obj-y = $(libqos-obj-y) tests/libqos/malloc-spapr.o
 libqos-spapr-obj-y += tests/libqos/libqos-spapr.o
 libqos-spapr-obj-y += tests/libqos/rtas.o
@@ -769,6 +771,12 @@ 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-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
 
+check-unit-y += tests/test-qgraph$(EXESUF)
+tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
+
+check-qtest-generic-y += tests/qos-test$(EXESUF)
+tests/qos-test$(EXESUF): tests/qos-test.o $(libqgraph-obj-y)
+
 tests/qmp-test$(EXESUF): tests/qmp-test.o
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
 tests/rtc-test$(EXESUF): tests/rtc-test.o
diff --git a/tests/libqos/qgraph.c b/tests/libqos/qgraph.c
new file mode 100644
index 00..786a1fdb45
--- /dev/null
+++ b/tests/libqos/qgraph.c
@@ -0,0 +1,721 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCH

[Qemu-devel] [PATCH 08/33] tests/qgraph: pci-spapr driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add pci-bus-spapr node, that produces pci-bus. Move QPCIBusSPAPR struct
declaration in its header (since it will be needed by other drivers)
and introduce a setter method for drivers that do not need to allocate
but have to initialize QPCIBusSPAPR.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include   |   2 +-
 tests/libqos/pci-spapr.c | 116 +--
 tests/libqos/pci-spapr.h |  24 
 3 files changed, 88 insertions(+), 54 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 67dbec0d35..5713be3ec4 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -771,7 +771,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) 
$(libqos-pc-obj-y) tests/libqos/virt
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 
-libqgraph-pci-obj-y = $(libqos-pc-obj-y)
+libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 
diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c
index f306cb746d..24f2c2c60d 100644
--- a/tests/libqos/pci-spapr.c
+++ b/tests/libqos/pci-spapr.c
@@ -9,33 +9,13 @@
 #include "libqtest.h"
 #include "libqos/pci-spapr.h"
 #include "libqos/rtas.h"
+#include "libqos/qgraph.h"
 
 #include "hw/pci/pci_regs.h"
 
 #include "qemu-common.h"
 #include "qemu/host-utils.h"
 
-
-/* From include/hw/pci-host/spapr.h */
-
-typedef struct QPCIWindow {
-uint64_t pci_base;/* window address in PCI space */
-uint64_t size;/* window size */
-} QPCIWindow;
-
-typedef struct QPCIBusSPAPR {
-QPCIBus bus;
-QGuestAllocator *alloc;
-
-uint64_t buid;
-
-uint64_t pio_cpu_base;
-QPCIWindow pio;
-
-uint64_t mmio32_cpu_base;
-QPCIWindow mmio32;
-} QPCIBusSPAPR;
-
 /*
  * PCI devices are always little-endian
  * SPAPR by default is big-endian
@@ -160,60 +140,90 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int 
devfn, uint8_t offset,
 #define SPAPR_PCI_MMIO32_WIN_SIZE0x8000 /* 2 GiB */
 #define SPAPR_PCI_IO_WIN_SIZE0x1
 
-QPCIBus *qpci_new_spapr(QTestState *qts, QGuestAllocator *alloc)
+static void *qpci_spapr_get_driver(void *obj, const char *interface)
 {
-QPCIBusSPAPR *ret = g_new0(QPCIBusSPAPR, 1);
+QPCIBusSPAPR *qpci = obj;
+if (!g_strcmp0(interface, "pci-bus")) {
+return &qpci->bus;
+}
+fprintf(stderr, "%s not present in pci-bus-spapr", interface);
+g_assert_not_reached();
+}
 
+void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qts,
+ QGuestAllocator *alloc)
+{
 assert(qts);
 
-ret->alloc = alloc;
+qpci->alloc = alloc;
 
-ret->bus.pio_readb = qpci_spapr_pio_readb;
-ret->bus.pio_readw = qpci_spapr_pio_readw;
-ret->bus.pio_readl = qpci_spapr_pio_readl;
-ret->bus.pio_readq = qpci_spapr_pio_readq;
+qpci->bus.pio_readb = qpci_spapr_pio_readb;
+qpci->bus.pio_readw = qpci_spapr_pio_readw;
+qpci->bus.pio_readl = qpci_spapr_pio_readl;
+qpci->bus.pio_readq = qpci_spapr_pio_readq;
 
-ret->bus.pio_writeb = qpci_spapr_pio_writeb;
-ret->bus.pio_writew = qpci_spapr_pio_writew;
-ret->bus.pio_writel = qpci_spapr_pio_writel;
-ret->bus.pio_writeq = qpci_spapr_pio_writeq;
+qpci->bus.pio_writeb = qpci_spapr_pio_writeb;
+qpci->bus.pio_writew = qpci_spapr_pio_writew;
+qpci->bus.pio_writel = qpci_spapr_pio_writel;
+qpci->bus.pio_writeq = qpci_spapr_pio_writeq;
 
-ret->bus.memread = qpci_spapr_memread;
-ret->bus.memwrite = qpci_spapr_memwrite;
+qpci->bus.memread = qpci_spapr_memread;
+qpci->bus.memwrite = qpci_spapr_memwrite;
 
-ret->bus.config_readb = qpci_spapr_config_readb;
-ret->bus.config_readw = qpci_spapr_config_readw;
-ret->bus.config_readl = qpci_spapr_config_readl;
+qpci->bus.config_readb = qpci_spapr_config_readb;
+qpci->bus.config_readw = qpci_spapr_config_readw;
+qpci->bus.config_readl = qpci_spapr_config_readl;
 
-ret->bus.config_writeb = qpci_spapr_config_writeb;
-ret->bus.config_writew = qpci_spapr_config_writew;
-ret->bus.config_writel = qpci_spapr_config_writel;
+qpci->bus.config_writeb = qpci_spapr_config_writeb;
+qpci->bus.config_writew = qpci_spapr_config_writew;
+qpci->bus.config_writel = qpci_spapr_config_writel;
 
 /* FIXME: We assume the default location of the PHB for now.
  * Ideally we'd parse the device tree deposited in the guest to
  * get the window locations */
-ret->buid = 0x8002000ULL;
+qpci->buid = 0x8002000ULL;
 
-ret->pio_cpu_base = SPAPR_PCI_BASE;
-ret->pio.pci_base = 0;
-ret->pio.size = SPAPR_PCI_IO_WIN_SIZE;
+qpci->pio_cpu_base = SPAPR_PCI_BASE;
+qpci->pio.pci_base = 0;
+qpci->pio.size = SPAPR_PCI_IO_WIN_SIZE;
 
 /* 32-bit portion of the MMIO window is at PCI address 2..4 GiB */
-ret->mmio32_cpu_base = SPAPR_P

[Qemu-devel] [PATCH 18/33] tests/qgraph: virtio-serial driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-serial-pci and virtio-serial-device.
Both nodes produce virtio-serial, but virtio-serial-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and functions,
while virtio-serial-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include   |   3 +
 tests/libqos/virtio-serial.c | 109 +++
 tests/libqos/virtio-serial.h |  39 +
 3 files changed, 151 insertions(+)
 create mode 100644 tests/libqos/virtio-serial.c
 create mode 100644 tests/libqos/virtio-serial.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 0e0bebf783..409475eafd 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -770,8 +770,11 @@ libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
+libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
+
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-obj-y += $(libqgraph-virtio-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 libqgraph-pci-obj-y += tests/libqos/e1000e.o
 
diff --git a/tests/libqos/virtio-serial.c b/tests/libqos/virtio-serial.c
new file mode 100644
index 00..83e1f90708
--- /dev/null
+++ b/tests/libqos/virtio-serial.c
@@ -0,0 +1,109 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-serial.h"
+
+/* virtio-serial-device */
+static void qvirtio_serial_device_destructor(QOSGraphObject *obj)
+{
+QVirtioSerialDevice *v_serial = (QVirtioSerialDevice *) obj;
+
+g_free(v_serial);
+}
+
+static void *qvirtio_serial_device_get_driver(void *object,
+  const char *interface)
+{
+QVirtioSerialDevice *v_serial = object;
+if (!g_strcmp0(interface, "virtio-serial")) {
+return &v_serial->serial;
+}
+
+fprintf(stderr, "%s not present in virtio-serial-device\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_serial_device_create(void *virtio_dev,
+ QGuestAllocator *t_alloc,
+ void *addr)
+{
+QVirtioSerialDevice *virtio_device = g_new0(QVirtioSerialDevice, 1);
+QVirtioSerial *interface = &virtio_device->serial;
+
+interface->vdev = virtio_dev;
+
+virtio_device->obj.destructor = qvirtio_serial_device_destructor;
+virtio_device->obj.get_driver = qvirtio_serial_device_get_driver;
+
+return &virtio_device->obj;
+}
+
+/* virtio-serial-pci */
+static void *qvirtio_serial_pci_get_driver(void *object, const char *interface)
+{
+QVirtioSerialPCI *v_serial = object;
+if (!g_strcmp0(interface, "virtio-serial")) {
+return &v_serial->serial;
+}
+
+fprintf(stderr, "%s not present in virtio-serial-pci\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_serial_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioSerialPCI *virtio_spci = g_new0(QVirtioSerialPCI, 1);
+QVirtioSerial *interface = &virtio_spci->serial;
+QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
+
+virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
+interface->vdev = &virtio_spci->pci_vdev.vdev;
+
+obj->get_driver = qvirtio_serial_pci_get_driver;
+
+return obj;
+}
+
+static void virtio_serial_register_nodes(void)
+{
+   QPCIAddress addr = {
+.devfn = QPCI_DEVFN(4, 0),
+};
+
+QOSGraphEdgeOptions edge_opts = { };
+
+/* virtio-serial-device */
+edge_opts.extra_device_opts = "id=vser0";
+qos_node_create_driver("virtio-serial-device",
+virtio_serial_device_create);
+qos_node_consumes("virtio-serial-device", "virtio", &edge_opts);
+qos_node_produces("virtio-serial-device", "virtio-serial");
+
+/* virtio-serial-pci */
+edge_opts.extra_device_opts = "id=vser0,addr=04.0";
+add_qpci_address(&edge_opts, &addr);
+qos_node_create_driver("virtio-serial-pci", virtio_serial_pci_create);
+qos_node_consumes("virtio-serial-pci", "pci-

[Qemu-devel] [PATCH 19/33] tests/qgraph: virtio-console test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/virtio-console-test in qgraph test node,
virtio-console-test. This test consumes a virtio-serial interface
and checks that its function return the expected values.

Note that this test does not allocate any virtio-console structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include  |  5 +++--
 tests/libqos/virtio.c   |  1 +
 tests/virtio-console-test.c | 30 +++---
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 409475eafd..a160059758 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -187,7 +187,6 @@ gcov-files-ipack-y += hw/ipack/ipack.c
 check-qtest-ipack-y += tests/ipoctal232-test$(EXESUF)
 gcov-files-ipack-y += hw/char/ipoctal232.c
 
-check-qtest-virtioserial-y += tests/virtio-console-test$(EXESUF)
 gcov-files-virtioserial-y += hw/char/virtio-console.c
 
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
@@ -398,6 +397,8 @@ check-qtest-s390x-$(CONFIG_POSIX) += 
tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
 check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF)
+check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF)
+check-qtest-s390x-y += tests/virtio-serial-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
@@ -781,6 +782,7 @@ libqgraph-pci-obj-y += tests/libqos/e1000e.o
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
 libqgraph-tests-obj-y += tests/e1000e-test.o
+libqgraph-tests-obj-y += tests/virtio-console-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -831,7 +833,6 @@ tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o 
$(libqos-pc-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
 tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o $(libqos-virtio-obj-y)
 tests/virtio-serial-test$(EXESUF): tests/virtio-serial-test.o 
$(libqos-virtio-obj-y)
-tests/virtio-console-test$(EXESUF): tests/virtio-console-test.o 
$(libqos-virtio-obj-y)
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
 tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index c1ff0206d5..6c2124523e 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -352,6 +352,7 @@ void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx)
 /*
  * qvirtio_get_dev_type:
  * Returns: the preferred virtio bus/device type for the current architecture.
+ * TODO: delete this
  */
 const char *qvirtio_get_dev_type(void)
 {
diff --git a/tests/virtio-console-test.c b/tests/virtio-console-test.c
index 945bae5a15..336078f1c0 100644
--- a/tests/virtio-console-test.c
+++ b/tests/virtio-console-test.c
@@ -10,29 +10,29 @@
 #include "qemu/osdep.h"
 #include "libqtest.h"
 #include "libqos/virtio.h"
+#include "libqos/qgraph.h"
 
 /* Tests only initialization so far. TODO: Replace with functional tests */
-static void console_nop(void)
+static void console_nop(void *obj, void *data, QGuestAllocator *alloc)
 {
-global_qtest = qtest_startf("-device virtio-serial-%s,id=vser0 "
-"-device virtconsole,bus=vser0.0",
-qvirtio_get_dev_type());
-qtest_end();
+/* no operation */
 }
 
-static void serialport_nop(void)
+static void serialport_nop(void *obj, void *data, QGuestAllocator *alloc)
 {
-global_qtest = qtest_startf("-device virtio-serial-%s,id=vser0 "
-"-device virtserialport,bus=vser0.0",
-qvirtio_get_dev_type());
-qtest_end();
+/* no operation */
 }
 
-int main(int argc, char **argv)
+static void register_virtio_console_test(void)
 {
-g_test_init(&argc, &argv, NULL);
-qtest_add_func("/virtio/console/nop", console_nop);
-qtest_add_func("/virtio/serialport/nop", serialport_nop);
+QOSGraphTestOptions opts = { };
+QOSGraphEdgeOptions *edge_opts = &opts.edge;
 
-return g_test_run();
+edge_opts->before_cmd_line = "-device virtconsole,bus=vser0.0";
+qos_add_test("console-nop", "virtio-serial", console_nop, &opts);
+
+edge_opts->before_cmd_line = "-device virtserialport,bus=vser0.0";
+qos_add_test("serialport-nop", "virtio-serial", serialport_nop, &opts);
 }
+
+libqos_init(register_virtio_console_test);
-- 
2.17.1




[Qemu-devel] [PATCH 09/33] tests/qgraph: ppc64/pseries machine node

2018-08-13 Thread Emanuele Giuseppe Esposito
Add pseries  machine for the ppc64 QEMU binary. This machine contains a
spapr-pci-host-bridge driver, that contains itself a pci-bus-spapr
that produces the pci-bus interface.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include   |   1 +
 tests/libqos/ppc64_pseries-machine.c | 111 +++
 2 files changed, 112 insertions(+)
 create mode 100644 tests/libqos/ppc64_pseries-machine.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 5713be3ec4..7c712406e1 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -770,6 +770,7 @@ libqos-virtio-obj-y = $(libqos-spapr-obj-y) 
$(libqos-pc-obj-y) tests/libqos/virt
 
 libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
+libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 
 libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/ppc64_pseries-machine.c 
b/tests/libqos/ppc64_pseries-machine.c
new file mode 100644
index 00..c860e9bc5b
--- /dev/null
+++ b/tests/libqos/ppc64_pseries-machine.c
@@ -0,0 +1,111 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/qgraph.h"
+#include "pci-spapr.h"
+#include "libqos/malloc-spapr.h"
+
+typedef struct QSPAPR_pci_host QSPAPR_pci_host;
+typedef struct Qppc64_pseriesMachine Qppc64_pseriesMachine;
+
+struct QSPAPR_pci_host {
+QOSGraphObject obj;
+QPCIBusSPAPR pci;
+};
+
+struct Qppc64_pseriesMachine {
+QOSGraphObject obj;
+QGuestAllocator *alloc;
+QSPAPR_pci_host bridge;
+};
+
+/* QSPAPR_pci_host */
+
+static QOSGraphObject *QSPAPR_host_get_device(void *obj, const char *device)
+{
+QSPAPR_pci_host *host = obj;
+if (!g_strcmp0(device, "pci-bus-spapr")) {
+return &host->pci.obj;
+}
+fprintf(stderr, "%s not present in QSPAPR_pci_host\n", device);
+g_assert_not_reached();
+}
+
+static void qos_create_QSPAPR_host(QSPAPR_pci_host *host,
+   QGuestAllocator *alloc)
+{
+host->obj.get_device = QSPAPR_host_get_device;
+qpci_init_spapr(&host->pci, global_qtest, alloc);
+}
+
+/* ppc64/pseries machine */
+
+static void spapr_destructor(QOSGraphObject *obj)
+{
+Qppc64_pseriesMachine *machine = (Qppc64_pseriesMachine *) obj;
+spapr_alloc_uninit(machine->alloc);
+g_free(obj);
+}
+
+static void *spapr_get_driver(void *object, const char *interface)
+{
+Qppc64_pseriesMachine *machine = object;
+if (!g_strcmp0(interface, "memory")) {
+return machine->alloc;
+}
+
+fprintf(stderr, "%s not present in ppc64/pseries\n", interface);
+g_assert_not_reached();
+}
+
+static QOSGraphObject *spapr_get_device(void *obj, const char *device)
+{
+Qppc64_pseriesMachine *machine = obj;
+if (!g_strcmp0(device, "spapr-pci-host-bridge")) {
+return &machine->bridge.obj;
+}
+
+fprintf(stderr, "%s not present in ppc64/pseries\n", device);
+g_assert_not_reached();
+}
+
+static void *qos_create_machine_spapr(void)
+{
+Qppc64_pseriesMachine *machine = g_new0(Qppc64_pseriesMachine, 1);
+machine->obj.get_device = spapr_get_device;
+machine->obj.get_driver = spapr_get_driver;
+machine->obj.destructor = spapr_destructor;
+machine->alloc =  spapr_alloc_init_flags(global_qtest,
+ ALLOC_NO_FLAGS);
+qos_create_QSPAPR_host(&machine->bridge, machine->alloc);
+
+return &machine->obj;
+}
+
+static void spapr_machine_register_nodes(void)
+{
+qos_node_create_machine("ppc64/pseries", qos_create_machine_spapr);
+qos_node_create_driver("spapr-pci-host-bridge", NULL);
+qos_node_contains("ppc64/pseries", "spapr-pci-host-bridge", NULL);
+qos_node_contains("spapr-pci-host-bridge", "pci-bus-spapr", NULL);
+}
+
+libqos_init(spapr_machine_register_nodes);
+
-- 
2.17.1




[Qemu-devel] [PATCH 14/33] tests/qgraph: virtio-pci driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add QOSGraphObject to QVirtioPCIDevice structure, with a basic
constructor. virtio-pci is not present in qgraph, since it
will be used as starting point by its subclasses (virtio-*-pci)

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include|  2 +-
 tests/libqos/virtio-pci.c | 80 +++
 tests/libqos/virtio-pci.h | 12 ++
 3 files changed, 77 insertions(+), 17 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index e18796d8d8..5220136473 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -771,7 +771,7 @@ libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
 libqgraph-machines-obj-y += tests/libqos/raspi2-machine.o
 libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
 
-libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
+libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
 libqgraph-pci-obj-y += tests/libqos/e1000e.o
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index 550dede0a2..86860c47c8 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -15,12 +15,26 @@
 #include "libqos/pci-pc.h"
 #include "libqos/malloc.h"
 #include "libqos/malloc-pc.h"
+#include "libqos/qgraph.h"
 #include "standard-headers/linux/virtio_ring.h"
 #include "standard-headers/linux/virtio_pci.h"
 
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_regs.h"
 
+/* virtio-pci is a superclass of all virtio-xxx-pci devices;
+ * the relation between virtio-pci and virtio-xxx-pci is implicit,
+ * and therefore virtio-pci does not produce virtio and is not
+ * reached by any edge, not even as a "contains" edge.
+ * In facts, every device is a QVirtioPCIDevice with
+ * additional fields, since every one has its own
+ * number of queues and various attributes.
+ * Virtio-pci provides default functions to start the
+ * hw and destroy the object, and nodes that want to
+ * override them should always remember to call the
+ * original qvirtio_pci_destructor and qvirtio_pci_start_hw.
+ */
+
 typedef struct QVirtioPCIForeachData {
 void (*func)(QVirtioDevice *d, void *data);
 uint16_t device_type;
@@ -32,7 +46,6 @@ typedef struct QVirtioPCIForeachData {
 void qvirtio_pci_device_free(QVirtioPCIDevice *dev)
 {
 g_free(dev->pdev);
-g_free(dev);
 }
 
 static QVirtioPCIDevice *qpcidevice_to_qvirtiodevice(QPCIDevice *pdev)
@@ -76,7 +89,7 @@ static void qvirtio_pci_assign_device(QVirtioDevice *d, void 
*data)
 
 static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t off)
 {
-QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
+QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
 return qpci_io_readb(dev->pdev, dev->bar, CONFIG_BASE(dev) + off);
 }
 
@@ -90,7 +103,7 @@ static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, 
uint64_t off)
 
 static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t off)
 {
-QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
+QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
 uint16_t value;
 
 value = qpci_io_readw(dev->pdev, dev->bar, CONFIG_BASE(dev) + off);
@@ -102,7 +115,7 @@ static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, 
uint64_t off)
 
 static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t off)
 {
-QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
+QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
 uint32_t value;
 
 value = qpci_io_readl(dev->pdev, dev->bar, CONFIG_BASE(dev) + off);
@@ -114,7 +127,7 @@ static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, 
uint64_t off)
 
 static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t off)
 {
-QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
+QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
 uint64_t val;
 
 val = qpci_io_readq(dev->pdev, dev->bar, CONFIG_BASE(dev) + off);
@@ -127,37 +140,37 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice 
*d, uint64_t off)
 
 static uint32_t qvirtio_pci_get_features(QVirtioDevice *d)
 {
-QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
+QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
 return qpci_io_readl(dev->pdev, dev->bar, VIRTIO_PCI_HOST_FEATURES);
 }
 
 static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features)
 {
-QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
+QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
 qpci_io_writel(dev->pdev, dev->bar, VIRTIO_PCI_GUEST_FEATURES, features);
 }
 
 static uint32_t qvirtio_pci_get_guest_features(QVirtioDevice *d)
 {
-QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
+QVirtioPCIDevice *dev = container_of(d, QVirtioPCIDevice, vdev);
 return qpci_io_readl(dev->pdev, dev->bar, VIRTIO_PCI_GUEST_FEATURES);
 }
 
 static uint8_t qvirtio_pci_get_status(QVirtioDevice *d)
 {
-Q

[Qemu-devel] [PATCH 24/33] tests/qgraph: virtio-balloon test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/virtio-balloon-test in qgraph test node,
virtio-balloon-test. This test consumes a virtio-balloon interface
and checks that its function return the expected values.

Note that this test does not allocate any virtio-balloon structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include  |  4 +---
 tests/virtio-balloon-test.c | 22 +++---
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 362d9ec4b2..b23597972d 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -192,7 +192,6 @@ gcov-files-virtioserial-y += hw/char/virtio-console.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
 check-qtest-virtio-y += tests/virtio-net-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
-check-qtest-virtio-y += tests/virtio-balloon-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
@@ -395,7 +394,6 @@ check-qtest-s390x-$(CONFIG_POSIX) += 
tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
 check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
@@ -784,6 +782,7 @@ libqgraph-tests-obj-y += tests/e1000e-test.o
 libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
 libqgraph-tests-obj-y += tests/virtio-9p-test.o
+libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -826,7 +825,6 @@ tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o
 tests/ne2000-test$(EXESUF): tests/ne2000-test.o
 tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
 tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
-tests/virtio-balloon-test$(EXESUF): tests/virtio-balloon-test.o 
$(libqos-virtio-obj-y)
 tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y)
 tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) 
$(libqos-virtio-obj-y)
diff --git a/tests/virtio-balloon-test.c b/tests/virtio-balloon-test.c
index 0a07e036bb..8499a2349d 100644
--- a/tests/virtio-balloon-test.c
+++ b/tests/virtio-balloon-test.c
@@ -9,25 +9,17 @@
 
 #include "qemu/osdep.h"
 #include "libqtest.h"
-#include "libqos/virtio.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-balloon.h"
 
 /* Tests only initialization so far. TODO: Replace with functional tests */
-static void balloon_nop(void)
+static void balloon_nop(void *obj, void *data, QGuestAllocator *alloc)
 {
 }
 
-int main(int argc, char **argv)
+static void register_virtio_balloon_test(void)
 {
-int ret;
-
-g_test_init(&argc, &argv, NULL);
-qtest_add_func("/virtio/balloon/nop", balloon_nop);
-
-global_qtest = qtest_startf("-device virtio-balloon-%s",
-qvirtio_get_dev_type());
-ret = g_test_run();
-
-qtest_end();
-
-return ret;
+qos_add_test("balloon-nop", "virtio-balloon", balloon_nop, NULL);
 }
+
+libqos_init(register_virtio_balloon_test);
-- 
2.17.1




[Qemu-devel] [PATCH 11/33] tests/qgraph: e1000e driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-e1000e.
It consumes a pci-bus, and it's directly used by tests
(e1000e is pci based).

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |   1 +
 tests/libqos/e1000e.c  | 262 +
 tests/libqos/e1000e.h  |  53 +
 3 files changed, 316 insertions(+)
 create mode 100644 tests/libqos/e1000e.c
 create mode 100644 tests/libqos/e1000e.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 7c712406e1..9f0d64f4ae 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -775,6 +775,7 @@ libqgraph-machines-obj-y += 
tests/libqos/ppc64_pseries-machine.o
 libqgraph-pci-obj-y = $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
 libqgraph-pci-obj-y += tests/libqos/sdhci.o
+libqgraph-pci-obj-y += tests/libqos/e1000e.o
 
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
diff --git a/tests/libqos/e1000e.c b/tests/libqos/e1000e.c
new file mode 100644
index 00..33dac5a88b
--- /dev/null
+++ b/tests/libqos/e1000e.c
@@ -0,0 +1,262 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "qemu-common.h"
+#include "libqos/pci-pc.h"
+#include "qemu/sockets.h"
+#include "qemu/iov.h"
+#include "qemu/bitops.h"
+#include "libqos/malloc.h"
+#include "libqos/malloc-pc.h"
+#include "libqos/malloc-generic.h"
+#include "libqos/qgraph.h"
+#include "e1000e.h"
+
+#define E1000E_IMS  (0x00d0)
+
+#define E1000E_STATUS   (0x0008)
+#define E1000E_STATUS_LU BIT(1)
+#define E1000E_STATUS_ASDV1000 BIT(9)
+
+#define E1000E_CTRL (0x)
+#define E1000E_CTRL_RESET BIT(26)
+
+#define E1000E_RCTL (0x0100)
+#define E1000E_RCTL_EN  BIT(1)
+#define E1000E_RCTL_UPE BIT(3)
+#define E1000E_RCTL_MPE BIT(4)
+
+#define E1000E_RFCTL (0x5008)
+#define E1000E_RFCTL_EXTEN  BIT(15)
+
+#define E1000E_TCTL (0x0400)
+#define E1000E_TCTL_EN  BIT(1)
+
+#define E1000E_CTRL_EXT (0x0018)
+#define E1000E_CTRL_EXT_DRV_LOADBIT(28)
+#define E1000E_CTRL_EXT_TXLSFLOWBIT(22)
+
+#define E1000E_IVAR (0x00E4)
+#define E1000E_IVAR_TEST_CFG((E1000E_RX0_MSG_ID << 0)| BIT(3)  | \
+ (E1000E_TX0_MSG_ID << 8)| BIT(11) | \
+ (E1000E_OTHER_MSG_ID << 16) | BIT(19) | \
+ BIT(31))
+
+#define E1000E_RING_LEN (0x1000)
+
+#define E1000E_TDBAL(0x3800)
+
+#define E1000E_TDBAH(0x3804)
+#define E1000E_TDH  (0x3810)
+
+#define E1000E_RDBAL(0x2800)
+#define E1000E_RDBAH(0x2804)
+#define E1000E_RDH  (0x2810)
+
+#define E1000E_TXD_LEN  (16)
+#define E1000E_RXD_LEN  (16)
+
+static void e1000e_macreg_write(QE1000E *d, uint32_t reg, uint32_t val)
+{
+QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e);
+qpci_io_writel(&d_pci->pci_dev, d_pci->mac_regs, reg, val);
+}
+
+static uint32_t e1000e_macreg_read(QE1000E *d, uint32_t reg)
+{
+QE1000E_PCI *d_pci = container_of(d, QE1000E_PCI, e1000e);
+return qpci_io_readl(&d_pci->pci_dev, d_pci->mac_regs, reg);
+}
+
+void e1000e_tx_ring_push(QE1000E *d, void *descr)
+{
+uint32_t tail = e1000e_macreg_read(d, E1000E_TDT);
+uint32_t len = e1000e_macreg_read(d, E1000E_TDLEN) / E1000E_TXD_LEN;
+
+memwrite(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN);
+e1000e_macreg_write(d, E1000E_TDT, (tail + 1) % len);
+
+/* Read WB data for the packet transmitted */
+memread(d->tx_ring + tail * E1000E_TXD_LEN, descr, E1000E_TXD_LEN);
+}
+
+void e1000e_rx_ring_push(QE1000E *d, void *descr)
+{
+uint32_t tail = e1000e_macreg_read(d, E1000E_RDT);
+uint32_t len = e1000e_macreg_read(d, E1000E_RDLEN) / E1000E_RXD_LEN;
+
+memwrite(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN);
+e1000e_macreg_write(d, E1000E_RDT, (tail + 1) % len);
+
+/* Read WB data for the packet received */
+memread(d->rx_ring + tail * E1000E_RXD_LEN, descr, E1000E_RXD_LEN);
+}
+
+static void e1000e_foreach_callback(QPCIDevice *dev, int devfn, void *data)
+{
+QPCIDevice *res = data;
+memcpy(res, dev, sizeof(QPCIDevice));
+}
+
+void e1000e_wait_isr(QE1000E *d, uint16_t msg_id)
+{
+  

[Qemu-devel] [PATCH 25/33] tests/qgraph: virtio-rng driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-rng-pci and virtio-rng-device.
Both nodes produce virtio-rng, but virtio-rng-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and functions,
while virtio-rng-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include|   1 +
 tests/libqos/virtio-rng.c | 108 ++
 tests/libqos/virtio-rng.h |  39 ++
 3 files changed, 148 insertions(+)
 create mode 100644 tests/libqos/virtio-rng.c
 create mode 100644 tests/libqos/virtio-rng.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index b23597972d..162187d15b 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -769,6 +769,7 @@ libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virtio-rng.c b/tests/libqos/virtio-rng.c
new file mode 100644
index 00..508af62c8d
--- /dev/null
+++ b/tests/libqos/virtio-rng.c
@@ -0,0 +1,108 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-rng.h"
+
+/* virtio-rng-device */
+static void qvirtio_rng_device_destructor(QOSGraphObject *obj)
+{
+QVirtioRngDevice *v_rng = (QVirtioRngDevice *) obj;
+
+g_free(v_rng);
+}
+
+static void *qvirtio_rng_device_get_driver(void *object,
+  const char *interface)
+{
+QVirtioRngDevice *v_rng = object;
+if (!g_strcmp0(interface, "virtio-rng")) {
+return &v_rng->rng;
+}
+
+fprintf(stderr, "%s not present in virtio-rng-device\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_rng_device_create(void *virtio_dev,
+  QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioRngDevice *virtio_rdevice = g_new0(QVirtioRngDevice, 1);
+QVirtioRng *interface = &virtio_rdevice->rng;
+
+interface->vdev = virtio_dev;
+
+virtio_rdevice->obj.destructor = qvirtio_rng_device_destructor;
+virtio_rdevice->obj.get_driver = qvirtio_rng_device_get_driver;
+
+return &virtio_rdevice->obj;
+}
+
+/* virtio-rng-pci */
+static void *qvirtio_rng_pci_get_driver(void *object, const char *interface)
+{
+QVirtioRngPCI *v_rng = object;
+if (!g_strcmp0(interface, "virtio-rng")) {
+return &v_rng->rng;
+}
+
+fprintf(stderr, "%s not present in virtio-rng-pci\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_rng_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+   void *addr)
+{
+QVirtioRngPCI *virtio_rpci = g_new0(QVirtioRngPCI, 1);
+QVirtioRng *interface = &virtio_rpci->rng;
+QOSGraphObject *obj = &virtio_rpci->pci_vdev.obj;
+
+virtio_pci_init(&virtio_rpci->pci_vdev, pci_bus, addr);
+interface->vdev = &virtio_rpci->pci_vdev.vdev;
+
+obj->get_driver = qvirtio_rng_pci_get_driver;
+
+return obj;
+}
+
+static void virtio_rng_register_nodes(void)
+{
+QPCIAddress addr = {
+.devfn = QPCI_DEVFN(4, 0),
+};
+
+QOSGraphEdgeOptions opts = {
+.extra_device_opts = "addr=04.0",
+};
+
+/* virtio-rng-device */
+qos_node_create_driver("virtio-rng-device", virtio_rng_device_create);
+qos_node_consumes("virtio-rng-device", "virtio", NULL);
+qos_node_produces("virtio-rng-device", "virtio-rng");
+
+/* virtio-rng-pci */
+add_qpci_address(&opts, &addr);
+qos_node_create_driver("virtio-rng-pci", virtio_rng_pci_create);
+qos_node_consumes("virtio-rng-pci", "pci-bus", &opts);
+qos_node_produces("virtio-rng-pci", "virtio-rng");
+}
+
+libqos_init(virtio_rng_register_nodes);
diff --git a/tests/libqos/virtio-rng.h b/tests/libqos/virtio-rng.h
new file mode 100644
index 00..fbba988875
--- /dev/null
+++ b/tests/libqos/virtio-rng.h
@@ -0,0 +1,39 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *

[Qemu-devel] [PATCH 20/33] tests/qgraph: virtio-serial test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/virtio-serial-test in qgraph test node,
virtio-serial-test. This test consumes a virtio-serial interface
and checks that its function return the expected values.

Note that this test does not allocate any virtio-serial structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |  4 +---
 tests/virtio-serial-test.c | 27 +--
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index a160059758..eafceefc12 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -205,7 +205,6 @@ check-qtest-virtio-y += tests/virtio-9p-test$(EXESUF)
 gcov-files-virtio-y += hw/9pfs/virtio-9p.c
 gcov-files-virtio-y += i386-softmmu/hw/9pfs/virtio-9p-device.c
 endif
-check-qtest-virtio-y += tests/virtio-serial-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/char/virtio-serial-bus.c
 check-qtest-virtio-y += $(check-qtest-virtioserial-y)
 gcov-files-virtio-y += $(gcov-files-virtioserial-y)
@@ -398,7 +397,6 @@ check-qtest-s390x-$(CONFIG_POSIX) += 
tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
 check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF)
 check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-serial-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
@@ -782,6 +780,7 @@ libqgraph-pci-obj-y += tests/libqos/e1000e.o
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
 libqgraph-tests-obj-y += tests/e1000e-test.o
+libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
@@ -832,7 +831,6 @@ tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o 
$(libqos-pc-obj-y) $(lib
 tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
 tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o $(libqos-virtio-obj-y)
-tests/virtio-serial-test$(EXESUF): tests/virtio-serial-test.o 
$(libqos-virtio-obj-y)
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
 tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o
diff --git a/tests/virtio-serial-test.c b/tests/virtio-serial-test.c
index 7cc7060264..3dcac93011 100644
--- a/tests/virtio-serial-test.c
+++ b/tests/virtio-serial-test.c
@@ -9,33 +9,24 @@
 
 #include "qemu/osdep.h"
 #include "libqtest.h"
-#include "libqos/virtio.h"
+#include "libqos/virtio-serial.h"
 
 /* Tests only initialization so far. TODO: Replace with functional tests */
-static void virtio_serial_nop(void)
+static void virtio_serial_nop(void *obj, void *data, QGuestAllocator *alloc)
 {
+/* no operation */
 }
 
-static void hotplug(void)
+static void serial_hotplug(void *obj, void *data, QGuestAllocator *alloc)
 {
 qtest_qmp_device_add("virtserialport", "hp-port", NULL);
-
 qtest_qmp_device_del("hp-port");
 }
 
-int main(int argc, char **argv)
+static void register_virtio_serial_test(void)
 {
-int ret;
-
-g_test_init(&argc, &argv, NULL);
-qtest_add_func("/virtio/serial/nop", virtio_serial_nop);
-qtest_add_func("/virtio/serial/hotplug", hotplug);
-
-global_qtest = qtest_startf("-device virtio-serial-%s",
-qvirtio_get_dev_type());
-ret = g_test_run();
-
-qtest_end();
-
-return ret;
+qos_add_test("serial-nop", "virtio-serial", virtio_serial_nop, NULL);
+qos_add_test("serial-hotplug", "virtio-serial", serial_hotplug, NULL);
 }
+
+libqos_init(register_virtio_serial_test);
-- 
2.17.1




[Qemu-devel] [PATCH 29/33] tests/qgraph: virtio-net driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-net-pci and virtio-net-device.
Both nodes produce virtio-net, but virtio-net-pci receives
a pci-bus and overrides virtio-pci QOSGraphObject and its functions,
while virtio-net-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include|   1 +
 tests/libqos/virtio-net.c | 179 ++
 tests/libqos/virtio-net.h |  41 +
 3 files changed, 221 insertions(+)
 create mode 100644 tests/libqos/virtio-net.c
 create mode 100644 tests/libqos/virtio-net.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 814cef85c7..c105c0902c 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -768,6 +768,7 @@ libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-blk.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-net.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virtio-net.c b/tests/libqos/virtio-net.c
new file mode 100644
index 00..332d121486
--- /dev/null
+++ b/tests/libqos/virtio-net.c
@@ -0,0 +1,179 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-net.h"
+#include "hw/virtio/virtio-net.h"
+
+
+static QGuestAllocator *alloc;
+
+static void driver_init(QVirtioDevice *dev)
+{
+uint32_t features;
+
+features = qvirtio_get_features(dev);
+features = features & ~(QVIRTIO_F_BAD_FEATURE |
+(1u << VIRTIO_RING_F_INDIRECT_DESC) |
+(1u << VIRTIO_RING_F_EVENT_IDX));
+qvirtio_set_features(dev, features);
+
+qvirtio_set_driver_ok(dev);
+}
+
+static void virtio_net_cleanup(QVirtioNet *interface)
+{
+qvirtqueue_cleanup(interface->vdev->bus, interface->rx, alloc);
+qvirtqueue_cleanup(interface->vdev->bus, interface->tx, alloc);
+}
+
+static void virtio_net_setup(QVirtioNet *interface)
+{
+interface->rx = qvirtqueue_setup(interface->vdev, alloc, 0);
+interface->tx = qvirtqueue_setup(interface->vdev, alloc, 1);
+driver_init(interface->vdev);
+}
+
+/* virtio-net-device */
+static void qvirtio_net_device_destructor(QOSGraphObject *obj)
+{
+QVirtioNetDevice *v_net = (QVirtioNetDevice *) obj;
+virtio_net_cleanup(&v_net->net);
+g_free(v_net);
+}
+
+static void qvirtio_net_device_start_hw(QOSGraphObject *obj)
+{
+QVirtioNetDevice *v_net = (QVirtioNetDevice *) obj;
+QVirtioNet *interface = &v_net->net;
+
+virtio_net_setup(interface);
+}
+
+static void *qvirtio_net_device_get_driver(void *object,
+   const char *interface)
+{
+QVirtioNetDevice *v_net = object;
+if (!g_strcmp0(interface, "virtio-net")) {
+return &v_net->net;
+}
+
+fprintf(stderr, "%s not present in virtio-net-device\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_net_device_create(void *virtio_dev,
+  QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioNetDevice *virtio_ndevice = g_new0(QVirtioNetDevice, 1);
+QVirtioNet *interface = &virtio_ndevice->net;
+
+interface->vdev = virtio_dev;
+alloc = t_alloc;
+
+virtio_ndevice->obj.destructor = qvirtio_net_device_destructor;
+virtio_ndevice->obj.get_driver = qvirtio_net_device_get_driver;
+virtio_ndevice->obj.start_hw = qvirtio_net_device_start_hw;
+
+return &virtio_ndevice->obj;
+}
+
+/* virtio-net-pci */
+static void qvirtio_net_pci_destructor(QOSGraphObject *obj)
+{
+QVirtioNetPCI *v_net = (QVirtioNetPCI *) obj;
+QVirtioNet *interface = &v_net->net;
+QOSGraphObject *pci_vobj =  &v_net->pci_vdev.obj;
+
+virtio_net_cleanup(interface);
+qvirtio_pci_destructor(pci_vobj);
+g_free(v_net);
+}
+
+static void qvirtio_net_pci_start_hw(QOSGraphObject *obj)
+{
+QVirtioNetPCI *v_net = (QVirtioNetPCI *) obj;
+QVirtioNet *interface = &v_net->net;
+QOSGraphObject *pci_vobj =  &v_net->pci_vdev.obj;
+
+qvirtio_pci_start_hw(pci_vobj);
+virti

[Qemu-devel] [PATCH 12/33] tests/qgraph: e1000e-test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/e1000e-test in qgraph test node, e1000e-test. This test
consumes an e1000e interface and checks that its function return the
expected values.

Note that this test does not allocate any e1000e structure, it's all done by the
qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |   3 +-
 tests/e1000e-test.c| 354 +
 2 files changed, 78 insertions(+), 279 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 9f0d64f4ae..e18796d8d8 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -213,7 +213,6 @@ gcov-files-virtio-y += $(gcov-files-virtioserial-y)
 
 check-qtest-pci-y += tests/e1000-test$(EXESUF)
 gcov-files-pci-y += hw/net/e1000.c
-check-qtest-pci-y += tests/e1000e-test$(EXESUF)
 gcov-files-pci-y += hw/net/e1000e.c hw/net/e1000e_core.c
 check-qtest-pci-y += tests/rtl8139-test$(EXESUF)
 gcov-files-pci-y += hw/net/rtl8139.c
@@ -779,6 +778,7 @@ libqgraph-pci-obj-y += tests/libqos/e1000e.o
 
 libqgraph-tests-obj-y = $(libqgraph-pci-obj-y)
 libqgraph-tests-obj-y += tests/sdhci-test.o
+libqgraph-tests-obj-y += tests/e1000e-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -813,7 +813,6 @@ tests/i440fx-test$(EXESUF): tests/i440fx-test.o 
$(libqos-pc-obj-y)
 tests/q35-test$(EXESUF): tests/q35-test.o $(libqos-pc-obj-y)
 tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y)
 tests/e1000-test$(EXESUF): tests/e1000-test.o
-tests/e1000e-test$(EXESUF): tests/e1000e-test.o $(libqos-pc-obj-y)
 tests/rtl8139-test$(EXESUF): tests/rtl8139-test.o $(libqos-pc-obj-y)
 tests/pcnet-test$(EXESUF): tests/pcnet-test.o
 tests/pnv-xscom-test$(EXESUF): tests/pnv-xscom-test.o
diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c
index 574801fd38..4c4f1e24ae 100644
--- a/tests/e1000e-test.c
+++ b/tests/e1000e-test.c
@@ -34,208 +34,11 @@
 #include "libqos/malloc.h"
 #include "libqos/malloc-pc.h"
 #include "libqos/malloc-generic.h"
-
-#define E1000E_IMS  (0x00d0)
-
-#define E1000E_STATUS   (0x0008)
-#define E1000E_STATUS_LU BIT(1)
-#define E1000E_STATUS_ASDV1000 BIT(9)
-
-#define E1000E_CTRL (0x)
-#define E1000E_CTRL_RESET BIT(26)
-
-#define E1000E_RCTL (0x0100)
-#define E1000E_RCTL_EN  BIT(1)
-#define E1000E_RCTL_UPE BIT(3)
-#define E1000E_RCTL_MPE BIT(4)
-
-#define E1000E_RFCTL (0x5008)
-#define E1000E_RFCTL_EXTEN  BIT(15)
-
-#define E1000E_TCTL (0x0400)
-#define E1000E_TCTL_EN  BIT(1)
-
-#define E1000E_CTRL_EXT (0x0018)
-#define E1000E_CTRL_EXT_DRV_LOADBIT(28)
-#define E1000E_CTRL_EXT_TXLSFLOWBIT(22)
-
-#define E1000E_RX0_MSG_ID   (0)
-#define E1000E_TX0_MSG_ID   (1)
-#define E1000E_OTHER_MSG_ID (2)
-
-#define E1000E_IVAR (0x00E4)
-#define E1000E_IVAR_TEST_CFG((E1000E_RX0_MSG_ID << 0)| BIT(3)  | \
- (E1000E_TX0_MSG_ID << 8)| BIT(11) | \
- (E1000E_OTHER_MSG_ID << 16) | BIT(19) | \
- BIT(31))
-
-#define E1000E_RING_LEN (0x1000)
-#define E1000E_TXD_LEN  (16)
-#define E1000E_RXD_LEN  (16)
-
-#define E1000E_TDBAL(0x3800)
-#define E1000E_TDBAH(0x3804)
-#define E1000E_TDLEN(0x3808)
-#define E1000E_TDH  (0x3810)
-#define E1000E_TDT  (0x3818)
-
-#define E1000E_RDBAL(0x2800)
-#define E1000E_RDBAH(0x2804)
-#define E1000E_RDLEN(0x2808)
-#define E1000E_RDH  (0x2810)
-#define E1000E_RDT  (0x2818)
-
-typedef struct e1000e_device {
-QPCIDevice *pci_dev;
-QPCIBar mac_regs;
-
-uint64_t tx_ring;
-uint64_t rx_ring;
-} e1000e_device;
+#include "libqos/e1000e.h"
 
 static int test_sockets[2];
-static QGuestAllocator *test_alloc;
-static QPCIBus *test_bus;
-
-static void e1000e_pci_foreach_callback(QPCIDevice *dev, int devfn, void *data)
-{
-QPCIDevice **res = data;
-
-g_assert_null(*res);
-*res = dev;
-}
-
-static QPCIDevice *e1000e_device_find(QPCIBus *bus)
-{
-static const int e1000e_vendor_id = 0x8086;
-static const int e1000e_dev_id = 0x10D3;
-
-QPCIDevice *e1000e_dev = NULL;
-
-qpci_device_foreach(bus, e1000e_vendor_id, e1000e_dev_id,
-e1000e_pci_foreach_callback, &e1000e_dev);
-
-g_assert_nonnull(e1000e_dev);
-
-return e1000e_dev;
-}
 
-static void e1000e_macreg_write(e1000e_device *d, uint32_t reg, uint32_t val)
-{
-qpci_io_writel(d->pci_dev, d->mac_regs, reg, val);
-}
-
-static uint32_t e1000e_macreg_read(e1000e_device *d, uint32_t reg)
-{
-return qpci_io_readl(d->pci_dev, d->mac_regs, reg);
-}
-
-static void e1000e_device_init(QPCIBus *bus, e1000e_device *d)
-{
-uint32_t val;
-
-d->pci_dev = e1000e_device_find(bus);
-
-/* Enable the device */
-qpci_device_enable(d->pci_dev);
-
-/* Map BAR0 (mac registers) */
-d->mac_regs = qpci_iomap(d->pci_dev, 0,

[Qemu-devel] [PATCH 28/33] tests/qgraph: virtio-blk test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/virtio-blk-test in qgraph test node,
virtio-blk-test. This test consumes a virtio-blk interface
and checks that its function return the expected values.

Some functions are implemented only for virtio-blk-pci, so they
don't consume virtio-blk, but virtio-blk-pci

Note that this test does not allocate any virtio-blk structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include  |   4 +-
 tests/virtio-blk-test.c | 468 
 2 files changed, 190 insertions(+), 282 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 340c2462d2..814cef85c7 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -193,7 +193,6 @@ gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
 check-qtest-virtio-y += tests/virtio-net-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
-check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
 gcov-files-virtio-y += hw/virtio/virtio-rng.c
 check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
@@ -373,7 +372,6 @@ check-qtest-arm-y += tests/pca9552-test$(EXESUF)
 check-qtest-arm-y += tests/ds1338-test$(EXESUF)
 check-qtest-arm-y += tests/m25p80-test$(EXESUF)
 gcov-files-arm-y += hw/misc/tmp105.c
-check-qtest-arm-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
@@ -785,6 +783,7 @@ libqgraph-tests-obj-y += tests/virtio-console-test.o
 libqgraph-tests-obj-y += tests/virtio-9p-test.o
 libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 libqgraph-tests-obj-y += tests/virtio-rng-test.o
+libqgraph-tests-obj-y += tests/virtio-blk-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -827,7 +826,6 @@ tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o
 tests/ne2000-test$(EXESUF): tests/ne2000-test.o
 tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
 tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
-tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y)
 tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) 
$(libqos-virtio-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index e60b33c38a..930e0b9e67 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -10,29 +10,17 @@
 
 #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"
-#include "libqos/malloc-generic.h"
-#include "qemu/bswap.h"
-#include "standard-headers/linux/virtio_ids.h"
-#include "standard-headers/linux/virtio_config.h"
-#include "standard-headers/linux/virtio_ring.h"
+ #include "qemu/bswap.h"
 #include "standard-headers/linux/virtio_blk.h"
 #include "standard-headers/linux/virtio_pci.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-blk.h"
 
 #define TEST_IMAGE_SIZE (64 * 1024 * 1024)
 #define QVIRTIO_BLK_TIMEOUT_US  (30 * 1000 * 1000)
 #define PCI_SLOT_HP 0x06
-#define PCI_SLOT0x04
-#define PCI_FN  0x00
 
-#define MMIO_PAGE_SIZE  4096
-#define MMIO_DEV_BASE_ADDR  0x0A003E00
-#define MMIO_RAM_ADDR   0x4000
-#define MMIO_RAM_SIZE   0x2000
+static char *tmp_path;
 
 typedef struct QVirtioBlkReq {
 uint32_t type;
@@ -45,75 +33,16 @@ typedef struct QVirtioBlkReq {
 static char *drive_create(void)
 {
 int fd, ret;
-char *tmp_path = g_strdup("/tmp/qtest.XX");
+char *t_path = g_strdup("/tmp/qtest.XX");
 
 /* Create a temporary raw image */
-fd = mkstemp(tmp_path);
+fd = mkstemp(t_path);
 g_assert_cmpint(fd, >=, 0);
 ret = ftruncate(fd, TEST_IMAGE_SIZE);
 g_assert_cmpint(ret, ==, 0);
 close(fd);
 
-return tmp_path;
-}
-
-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 "
-  "-drive if=none,id=drive1,file=null-co://,format=raw "
-  "-device virtio-blk-pci,id=drv0,drive=drive0,"
-  "addr=%x.%x";
-
-tmp_path = drive_create();
-
-if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-qs = qtest_pc_boot(cmd, tmp_path, PCI_SLOT, PCI_FN);
-} else if (strcmp(arch, "ppc64") == 0) {
-qs = qtest_spapr_boot(cmd, tmp_path, PCI_SLOT, PCI_FN);
-} else {
-g_printerr("virtio-blk t

[Qemu-devel] [PATCH 21/33] tests/qgraph: virtio-9p driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-9p-pci and virtio-9p-device.
Both nodes produce virtio-9p, but virtio-9p-pci receives
a pci-bus and overrides virtio-pci QOSGraphObject and its functions,
while virtio-9p-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include   |   1 +
 tests/libqos/virtio-9p.c | 165 +++
 tests/libqos/virtio-9p.h |  42 ++
 3 files changed, 208 insertions(+)
 create mode 100644 tests/libqos/virtio-9p.c
 create mode 100644 tests/libqos/virtio-9p.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index eafceefc12..48d3aab447 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -770,6 +770,7 @@ libqgraph-machines-obj-y += 
tests/libqos/ppc64_pseries-machine.o
 libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
 libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virtio-9p.c b/tests/libqos/virtio-9p.c
new file mode 100644
index 00..df60db8f39
--- /dev/null
+++ b/tests/libqos/virtio-9p.c
@@ -0,0 +1,165 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "standard-headers/linux/virtio_ids.h"
+#include "libqos/virtio-9p.h"
+#include "libqos/qgraph.h"
+
+static QGuestAllocator *alloc;
+
+static void virtio_9p_cleanup(QVirtio9P *interface)
+{
+qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc);
+}
+
+static void virtio_9p_setup(QVirtio9P *interface)
+{
+interface->vq = qvirtqueue_setup(interface->vdev, alloc, 0);
+qvirtio_set_driver_ok(interface->vdev);
+}
+
+/* virtio-9p-device */
+static void virtio_9p_device_destructor(QOSGraphObject *obj)
+{
+QVirtio9PDevice *v_9p = (QVirtio9PDevice *) obj;
+QVirtio9P *interface = &v_9p->v9p;
+virtio_9p_cleanup(interface);
+
+g_free(v_9p);
+}
+
+static void virtio_9p_device_start_hw(QOSGraphObject *obj)
+{
+QVirtio9PDevice *v_9p = (QVirtio9PDevice *) obj;
+QVirtio9P *interface = &v_9p->v9p;
+
+virtio_9p_setup(interface);
+}
+
+static void *virtio_9p_device_get_driver(void *object, const char *interface)
+{
+QVirtio9PDevice *v_9p = object;
+if (!g_strcmp0(interface, "virtio-9p")) {
+return &v_9p->v9p;
+}
+
+fprintf(stderr, "%s not present in virtio-9p-device\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_9p_device_create(void *virtio_dev,
+ QGuestAllocator *t_alloc,
+ void *addr)
+{
+QVirtio9PDevice *virtio_device = g_new0(QVirtio9PDevice, 1);
+QVirtio9P *interface = &virtio_device->v9p;
+
+interface->vdev = virtio_dev;
+alloc = t_alloc;
+
+virtio_device->obj.destructor = virtio_9p_device_destructor;
+virtio_device->obj.get_driver = virtio_9p_device_get_driver;
+virtio_device->obj.start_hw = virtio_9p_device_start_hw;
+
+return &virtio_device->obj;
+}
+
+/* virtio-9p-pci */
+static void virtio_9p_pci_destructor(QOSGraphObject *obj)
+{
+QVirtio9PPCI *v9_pci = (QVirtio9PPCI *) obj;
+QVirtio9P *interface = &v9_pci->v9p;
+QOSGraphObject *pci_vobj =  &v9_pci->pci_vdev.obj;
+
+virtio_9p_cleanup(interface);
+qvirtio_pci_destructor(pci_vobj);
+g_free(v9_pci);
+}
+
+static void virtio_9p_pci_start_hw(QOSGraphObject *obj)
+{
+QVirtio9PPCI *v9_pci = (QVirtio9PPCI *) obj;
+QVirtio9P *interface = &v9_pci->v9p;
+QOSGraphObject *pci_vobj =  &v9_pci->pci_vdev.obj;
+
+qvirtio_pci_start_hw(pci_vobj);
+virtio_9p_setup(interface);
+}
+
+static void *virtio_9p_pci_get_driver(void *object, const char *interface)
+{
+QVirtio9PPCI *v9p = object;
+if (!g_strcmp0(interface, "virtio-9p")) {
+return &v9p->v9p;
+}
+
+fprintf(stderr, "%s not present in virtio-9p-pci\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtio9PPCI *v9_pci = g_new0(QVirtio9PPCI, 1);
+QVirtio9P *interface = &v9_pci->v9p;
+QOSGraphObject *obj = &v9_pci->pci_vdev.obj;
+
+virt

[Qemu-devel] [PATCH 31/33] tests/qgraph: virtio-scsi driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-scsi-pci and virtio-scsi-device.
Both nodes produce virtio-scsi, but virtio-scsi-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and its functions,
while virtio-scsi-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |   1 +
 tests/libqos/virtio-scsi.c | 117 +
 tests/libqos/virtio-scsi.h |  39 +
 3 files changed, 157 insertions(+)
 create mode 100644 tests/libqos/virtio-scsi.c
 create mode 100644 tests/libqos/virtio-scsi.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 7a2b67c1ec..a839763505 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -768,6 +768,7 @@ libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-blk.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-net.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-scsi.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virtio-scsi.c b/tests/libqos/virtio-scsi.c
new file mode 100644
index 00..8f13c0bfaf
--- /dev/null
+++ b/tests/libqos/virtio-scsi.c
@@ -0,0 +1,117 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "standard-headers/linux/virtio_ids.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-scsi.h"
+
+/* virtio-scsi-device */
+static void qvirtio_scsi_device_destructor(QOSGraphObject *obj)
+{
+QVirtioSCSIDevice *v_scsi = (QVirtioSCSIDevice *) obj;
+
+g_free(v_scsi);
+}
+
+static void *qvirtio_scsi_device_get_driver(void *object,
+   const char *interface)
+{
+QVirtioSCSIDevice *v_scsi = object;
+if (!g_strcmp0(interface, "virtio-scsi")) {
+return &v_scsi->scsi;
+}
+
+fprintf(stderr, "%s not present in virtio-scsi-device\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_scsi_device_create(void *virtio_dev,
+  QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioSCSIDevice *virtio_bdevice = g_new0(QVirtioSCSIDevice, 1);
+QVirtioSCSI *interface = &virtio_bdevice->scsi;
+
+interface->vdev = virtio_dev;
+
+virtio_bdevice->obj.destructor = qvirtio_scsi_device_destructor;
+virtio_bdevice->obj.get_driver = qvirtio_scsi_device_get_driver;
+
+return &virtio_bdevice->obj;
+}
+
+/* virtio-scsi-pci */
+static void *qvirtio_scsi_pci_get_driver(void *object,
+const char *interface)
+{
+QVirtioSCSIPCI *v_scsi = object;
+if (!g_strcmp0(interface, "virtio-scsi")) {
+return &v_scsi->scsi;
+}
+
+fprintf(stderr, "%s not present in virtio-scsi-pci\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_scsi_pci_create(void *pci_bus,
+QGuestAllocator *t_alloc,
+void *addr)
+{
+QVirtioSCSIPCI *virtio_spci = g_new0(QVirtioSCSIPCI, 1);
+QVirtioSCSI *interface = &virtio_spci->scsi;
+QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
+
+virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
+interface->vdev = &virtio_spci->pci_vdev.vdev;
+
+g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_SCSI);
+
+obj->get_driver = qvirtio_scsi_pci_get_driver;
+
+return obj;
+}
+
+static void virtio_scsi_register_nodes(void)
+{
+QPCIAddress addr = {
+.devfn = QPCI_DEVFN(4, 0),
+};
+
+QOSGraphEdgeOptions opts = {
+.before_cmd_line = "-drive id=drv0,if=none,file=null-co://,format=raw",
+.after_cmd_line = "-device scsi-hd,bus=vs0.0,drive=drv0",
+};
+
+/* virtio-scsi-device */
+opts.extra_device_opts = "id=vs0";
+qos_node_create_driver("virtio-scsi-device",
+virtio_scsi_device_create);
+qos_node_consumes("virtio-scsi-device", "virtio", &opts);
+qos_node_produces("virtio-scsi-device", "virtio-scsi");
+
+/* virtio-scsi-pci */
+opts.extra_device_opts = "id=vs0,addr=04.0";
+add_qpci_address(&opts, &addr);
+qos_

[Qemu-devel] [PATCH 15/33] tests/qgraph: virtio-mmio driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add virtio-mmio node in qgraph framework.
virtio-mmio produces virtio, the interface consumed by all virtio-*-device
nodes.

Being a memory-mapped device, it doesn't have to provide a constructor
to qgraph, since it's always "contained" inside some other nodes.

Also rename qvirtio_mmio_init_device in qvirtio_mmio_device_new, since the 
function
actually allocates a new QVirtioMMIODevice and initialize it.

Signed-off-by: Emanuele Giuseppe Esposito 
Reviewed-by: Laurent Vivier 
---
 tests/libqos/virtio-mmio.c | 66 ++
 tests/libqos/virtio-mmio.h |  5 ++-
 tests/virtio-blk-test.c|  3 +-
 3 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c
index 7aa8383338..61ed0e549b 100644
--- a/tests/libqos/virtio-mmio.c
+++ b/tests/libqos/virtio-mmio.c
@@ -13,42 +13,43 @@
 #include "libqos/virtio-mmio.h"
 #include "libqos/malloc.h"
 #include "libqos/malloc-generic.h"
+#include "libqos/qgraph.h"
 #include "standard-headers/linux/virtio_ring.h"
 
 static uint8_t qvirtio_mmio_config_readb(QVirtioDevice *d, uint64_t off)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 return readb(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint16_t qvirtio_mmio_config_readw(QVirtioDevice *d, uint64_t off)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 return readw(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint32_t qvirtio_mmio_config_readl(QVirtioDevice *d, uint64_t off)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 return readl(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint64_t qvirtio_mmio_config_readq(QVirtioDevice *d, uint64_t off)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 return readq(dev->addr + QVIRTIO_MMIO_DEVICE_SPECIFIC + off);
 }
 
 static uint32_t qvirtio_mmio_get_features(QVirtioDevice *d)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 writel(dev->addr + QVIRTIO_MMIO_HOST_FEATURES_SEL, 0);
 return readl(dev->addr + QVIRTIO_MMIO_HOST_FEATURES);
 }
 
 static void qvirtio_mmio_set_features(QVirtioDevice *d, uint32_t features)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 dev->features = features;
 writel(dev->addr + QVIRTIO_MMIO_GUEST_FEATURES_SEL, 0);
 writel(dev->addr + QVIRTIO_MMIO_GUEST_FEATURES, features);
@@ -56,25 +57,25 @@ static void qvirtio_mmio_set_features(QVirtioDevice *d, 
uint32_t features)
 
 static uint32_t qvirtio_mmio_get_guest_features(QVirtioDevice *d)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 return dev->features;
 }
 
 static uint8_t qvirtio_mmio_get_status(QVirtioDevice *d)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 return (uint8_t)readl(dev->addr + QVIRTIO_MMIO_DEVICE_STATUS);
 }
 
 static void qvirtio_mmio_set_status(QVirtioDevice *d, uint8_t status)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 writel(dev->addr + QVIRTIO_MMIO_DEVICE_STATUS, (uint32_t)status);
 }
 
 static bool qvirtio_mmio_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 uint32_t isr;
 
 isr = readl(dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 1;
@@ -88,7 +89,7 @@ static bool qvirtio_mmio_get_queue_isr_status(QVirtioDevice 
*d, QVirtQueue *vq)
 
 static bool qvirtio_mmio_get_config_isr_status(QVirtioDevice *d)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 uint32_t isr;
 
 isr = readl(dev->addr + QVIRTIO_MMIO_INTERRUPT_STATUS) & 2;
@@ -102,7 +103,7 @@ static bool 
qvirtio_mmio_get_config_isr_status(QVirtioDevice *d)
 
 static void qvirtio_mmio_queue_select(QVirtioDevice *d, uint16_t index)
 {
-QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
+QVirtioMMIODevice *dev = container_of(d, QVirtioMMIODevice, vdev);
 writel(dev->addr + QVIRTIO_MMIO_QUEUE_SEL, (uint32_t)index);
 
 g_assert_cmphex(readl(dev->addr + QVIRTIO_MMIO_QUEUE_PFN), ==, 0);
@@ -110,20 +111,20 @@ static void qvirtio_mmio_queue_select(QVirtioDevice *d, 
uint16_t index)
 
 static uint16_t qvirtio_mmio_get_queue_size(QVirtioDevice *d)
 {
-QVirtioMMIODevice *dev = (QVirt

[Qemu-devel] [PATCH 22/33] tests/qgraph: virtio-9p test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-9p-pci and virtio-9p-device.
Both nodes produce virtio-9p, but virtio-9p-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and functions,
while virtio-9p-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include |   3 +-
 tests/virtio-9p-test.c | 219 +++--
 2 files changed, 82 insertions(+), 140 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 48d3aab447..495ff5ca9b 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -201,7 +201,6 @@ gcov-files-virtio-y += hw/virtio/virtio-rng.c
 check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
-check-qtest-virtio-y += tests/virtio-9p-test$(EXESUF)
 gcov-files-virtio-y += hw/9pfs/virtio-9p.c
 gcov-files-virtio-y += i386-softmmu/hw/9pfs/virtio-9p-device.c
 endif
@@ -783,6 +782,7 @@ libqgraph-tests-obj-y += tests/sdhci-test.o
 libqgraph-tests-obj-y += tests/e1000e-test.o
 libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
+libqgraph-tests-obj-y += tests/virtio-9p-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -831,7 +831,6 @@ tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) 
$(libqos-virtio-obj-y)
 tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
-tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o $(libqos-virtio-obj-y)
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
 tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index d275c74106..7a80c1d785 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -9,99 +9,36 @@
 
 #include "qemu/osdep.h"
 #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"
-#include "standard-headers/linux/virtio_pci.h"
 #include "hw/9pfs/9p.h"
 #include "hw/9pfs/9p-synth.h"
+#include "libqos/virtio-9p.h"
+#include "libqos/qgraph.h"
 
 #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
+static QGuestAllocator *alloc;
 
-static const char mount_tag[] = "qtest";
-
-typedef struct {
-QVirtioDevice *dev;
-QOSState *qs;
-QVirtQueue *vq;
-} QVirtIO9P;
-
-static QVirtIO9P *qvirtio_9p_start(const char *driver)
-{
-const char *arch = qtest_get_arch();
-const char *cmd = "-fsdev synth,id=fsdev0 "
-  "-device %s,fsdev=fsdev0,mount_tag=%s";
-QVirtIO9P *v9p = g_new0(QVirtIO9P, 1);
-
-if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-v9p->qs = qtest_pc_boot(cmd, driver, mount_tag);
-} else if (strcmp(arch, "ppc64") == 0) {
-v9p->qs = qtest_spapr_boot(cmd, driver, mount_tag);
-} else {
-g_printerr("virtio-9p tests are only available on x86 or ppc64\n");
-exit(EXIT_FAILURE);
-}
-global_qtest = v9p->qs->qts;
-
-return v9p;
-}
-
-static void qvirtio_9p_stop(QVirtIO9P *v9p)
-{
-qtest_shutdown(v9p->qs);
-g_free(v9p);
-}
-
-static QVirtIO9P *qvirtio_9p_pci_start(void)
-{
-QVirtIO9P *v9p = qvirtio_9p_start("virtio-9p-pci");
-QVirtioPCIDevice *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;
-
-qvirtio_pci_device_enable(dev);
-qvirtio_start_device(v9p->dev);
-
-v9p->vq = qvirtqueue_setup(v9p->dev, v9p->qs->alloc, 0);
-
-qvirtio_set_driver_ok(v9p->dev);
-
-return v9p;
-}
-
-static void qvirtio_9p_pci_stop(QVirtIO9P *v9p)
+static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
 {
-qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->qs->alloc);
-qvirtio_pci_device_disable(container_of(v9p->dev, QVirtioPCIDevice, vdev));
-qvirtio_pci_device_free((QVirtioPCIDevice *)v9p->dev);
-qvirtio_9p_stop(v9p);
-}
-
-static void pci_config(QVirtIO9P *v9p)
-{
-size_t tag_len = qvirtio_config_readw(v9p->dev, 0);
+QVirtio9P *v9p = obj;
+alloc = t_alloc;
+size_t tag_len = qvirtio_config_readw(v9p->vdev, 0);
 char *tag;
 int i;
 
-g_assert_cmpint(tag_len, ==, strlen(mount_tag));
+g_assert_cmpint(tag_len, ==, strlen(MOUNT_TAG));
 
 tag = g_malloc(tag_len);
 for (i = 0; i < tag_len; i++) {
-tag[i] = qvirtio_config_readb(v9p->dev, i + 2);
+tag[i

[Qemu-devel] [PATCH 32/33] tests/qgraph: virtio-scsi test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/virtio-scsi-test in qgraph test node,
virtio-scsi-test. This test consumes a virtio-scsi interface
and checks that its function return the expected values.

Some functions are implemented only for virtio-scsi-pci, so they
don't consume virtio-scsi, but virtio-scsi-pci

Note that this test does not allocate any virtio-scsi structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include   |   3 +-
 tests/virtio-scsi-test.c | 153 +++
 2 files changed, 75 insertions(+), 81 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index a839763505..15926cc95f 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -194,7 +194,6 @@ gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
 gcov-files-virtio-y += hw/virtio/virtio-rng.c
-check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c
 ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 gcov-files-virtio-y += hw/9pfs/virtio-9p.c
@@ -786,6 +785,7 @@ libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 libqgraph-tests-obj-y += tests/virtio-rng-test.o
 libqgraph-tests-obj-y += tests/virtio-blk-test.o
 libqgraph-tests-obj-y += tests/virtio-net-test.o
+libqgraph-tests-obj-y += tests/virtio-scsi-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -829,7 +829,6 @@ tests/ne2000-test$(EXESUF): tests/ne2000-test.o
 tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
 tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
 tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
-tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
 tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 1581b6926c..cc70cd1799 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -18,6 +18,8 @@
 #include "standard-headers/linux/virtio_ids.h"
 #include "standard-headers/linux/virtio_pci.h"
 #include "standard-headers/linux/virtio_scsi.h"
+#include "libqos/virtio-scsi.h"
+#include "libqos/qgraph.h"
 
 #define PCI_SLOT0x02
 #define PCI_FN  0x00
@@ -27,55 +29,28 @@
 
 typedef struct {
 QVirtioDevice *dev;
-QOSState *qs;
 int num_queues;
 QVirtQueue *vq[MAX_NUM_QUEUES + 2];
-} QVirtIOSCSI;
+} QVirtioSCSIQueues;
 
-static QOSState *qvirtio_scsi_start(const char *extra_opts)
-{
-QOSState *qs;
-const char *arch = qtest_get_arch();
-const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw "
-  "-device virtio-scsi-pci,id=vs0 "
-  "-device scsi-hd,bus=vs0.0,drive=drv0 %s";
-
-if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-qs = qtest_pc_boot(cmd, extra_opts ? : "");
-} else if (strcmp(arch, "ppc64") == 0) {
-qs = qtest_spapr_boot(cmd, extra_opts ? : "");
-} else {
-g_printerr("virtio-scsi tests are only available on x86 or ppc64\n");
-exit(EXIT_FAILURE);
-}
-global_qtest = qs->qts;
-return qs;
-}
+static QGuestAllocator *alloc;
 
-static void qvirtio_scsi_stop(QOSState *qs)
-{
-qtest_shutdown(qs);
-}
-
-static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
+static void qvirtio_scsi_pci_free(QVirtioSCSIQueues *vs)
 {
 int i;
 
 for (i = 0; i < vs->num_queues + 2; i++) {
-qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], vs->qs->alloc);
+qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], alloc);
 }
-qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
-qvirtio_pci_device_free((QVirtioPCIDevice *)vs->dev);
-qvirtio_scsi_stop(vs->qs);
 g_free(vs);
 }
 
-static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size,
+static uint64_t qvirtio_scsi_alloc(QVirtioSCSIQueues *vs, size_t alloc_size,
const void *data)
 {
 uint64_t addr;
 
-addr = guest_alloc(vs->qs->alloc, alloc_size);
+addr = guest_alloc(alloc, alloc_size);
 if (data) {
 memwrite(addr, data, alloc_size);
 }
@@ -83,7 +58,8 @@ static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t 
alloc_size,
 return addr;
 }
 
-static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
+static uint8_t virtio_scsi_do_command(QVirtioSCSIQueues *vs,
+  const uint8_t *cdb,
   const uint8_t *data_in,
   size_t data_in_len,
   uint8_t *data_out, size_t data_out

[Qemu-devel] [PATCH 17/33] tests: virtio: separate ccw tests from libqos

2018-08-13 Thread Emanuele Giuseppe Esposito
From: Paolo Bonzini 

Because qtest does not support s390 channel I/O, s390 only performs smoke tests 
on
those few devices that do not have any functional tests.  Therefore, every time 
we
add functional tests for a virtio device, the choice is between removing
those tests from the s390 suite (so that s390 actually _loses_ coverage)
or sprinkling the test with architecture checks.

This patch simply creates a ccw-specific test that only performs smoke tests on
all virtio-ccw devices.  If channel I/O support is ever added to qtest and 
libqos,
then this file can go away.  In the meanwhile, it simplifies maintenance and
makes sure that all virtio devices are tested.

Signed-off-by: Paolo Bonzini 
Acked-by: Cornelia Huck 
Reviewed-by: Thomas Huth 
---
 tests/Makefile.include  |   5 +-
 tests/virtio-ccw-test.c | 121 
 2 files changed, 123 insertions(+), 3 deletions(-)
 create mode 100644 tests/virtio-ccw-test.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 20cb983ed0..0e0bebf783 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -397,9 +397,7 @@ check-qtest-s390x-$(CONFIG_SLIRP) += 
tests/test-netfilter$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
 check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
 check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-balloon-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-console-test$(EXESUF)
-check-qtest-s390x-y += tests/virtio-serial-test$(EXESUF)
+check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
@@ -824,6 +822,7 @@ tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
 tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
 tests/virtio-balloon-test$(EXESUF): tests/virtio-balloon-test.o 
$(libqos-virtio-obj-y)
 tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y)
+tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) 
$(libqos-virtio-obj-y)
 tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
diff --git a/tests/virtio-ccw-test.c b/tests/virtio-ccw-test.c
new file mode 100644
index 00..88602f3235
--- /dev/null
+++ b/tests/virtio-ccw-test.c
@@ -0,0 +1,121 @@
+/*
+ * QTest testcase for VirtIO CCW
+ *
+ * Copyright (c) 2014 SUSE LINUX Products GmbH
+ * Copyright (c) 2018 Red Hat, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+/* Until we have a full libqos implementation of virtio-ccw (which requires
+ * also to add support for I/O channels to qtest), we can only do simple
+ * tests that initialize the devices.
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "libqos/virtio.h"
+
+static void virtio_balloon_nop(void)
+{
+global_qtest = qtest_startf("-device virtio-balloon-ccw");
+qtest_end();
+}
+
+static void virtconsole_nop(void)
+{
+global_qtest = qtest_startf("-device virtio-serial-ccw,id=vser0 "
+"-device virtconsole,bus=vser0.0");
+qtest_end();
+}
+
+static void virtserialport_nop(void)
+{
+global_qtest = qtest_startf("-device virtio-serial-ccw,id=vser0 "
+"-device virtserialport,bus=vser0.0");
+qtest_end();
+}
+
+static void virtio_serial_nop(void)
+{
+global_qtest = qtest_startf("-device virtio-serial-ccw");
+qtest_end();
+}
+
+static void virtio_serial_hotplug(void)
+{
+global_qtest = qtest_startf("-device virtio-serial-ccw");
+qtest_qmp_device_add("virtserialport", "hp-port", NULL);
+qtest_qmp_device_del("hp-port");
+qtest_end();
+}
+
+static void virtio_blk_nop(void)
+{
+global_qtest = qtest_startf("-drive if=none,id=drv0,"
+"file=null-co://,format=raw "
+"-device virtio-blk-ccw,drive=drv0");
+qtest_end();
+}
+
+static void virtio_net_nop(void)
+{
+global_qtest = qtest_startf("-device virtio-net-ccw");
+qtest_end();
+}
+
+static void virtio_9p_nop(void)
+{
+global_qtest = qtest_startf("-fsdev synth,id=fsdev0 "
+"-device 
virtio-9p-ccw,fsdev=fsdev0,mount_tag=qtest");
+qtest_end();
+}
+
+static void virtio_rng_nop(void)
+{
+global_qtest = qtest_startf("-device virtio-rng-ccw");
+qtest_end();
+}
+
+static void virtio_scsi_nop(void)
+{
+global_qtest = qtest_startf("-device virtio-scsi-ccw");
+qtest_end();
+}
+
+static void virtio_scsi_hotplug(void)
+{
+global_qtest = qtest_startf("-drive if=none,id=drv0,"
+"file=null-co://,format=raw "
+   

[Qemu-devel] [PATCH 23/33] tests/qgraph: virtio-balloon driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-balloon-pci and virtio-balloon-device.
Both nodes produce virtio-balloon, but virtio-balloon-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and functions,
while virtio-balloon-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include|   1 +
 tests/libqos/virtio-balloon.c | 111 ++
 tests/libqos/virtio-balloon.h |  39 
 3 files changed, 151 insertions(+)
 create mode 100644 tests/libqos/virtio-balloon.c
 create mode 100644 tests/libqos/virtio-balloon.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 495ff5ca9b..362d9ec4b2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -770,6 +770,7 @@ libqgraph-machines-obj-y += tests/libqos/virt-machine.o
 
 libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virtio-balloon.c b/tests/libqos/virtio-balloon.c
new file mode 100644
index 00..98d2548ffe
--- /dev/null
+++ b/tests/libqos/virtio-balloon.c
@@ -0,0 +1,111 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-balloon.h"
+
+/* virtio-balloon-device */
+static void qvirtio_balloon_device_destructor(QOSGraphObject *obj)
+{
+QVirtioBalloonDevice *v_balloon = (QVirtioBalloonDevice *) obj;
+
+g_free(v_balloon);
+}
+
+static void *qvirtio_balloon_device_get_driver(void *object,
+   const char *interface)
+{
+QVirtioBalloonDevice *v_balloon = object;
+if (!g_strcmp0(interface, "virtio-balloon")) {
+return &v_balloon->balloon;
+}
+
+fprintf(stderr, "%s not present in virtio-balloon-device\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_balloon_device_create(void *virtio_dev,
+  QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioBalloonDevice *virtio_bdevice = g_new0(QVirtioBalloonDevice, 1);
+QVirtioBalloon *interface = &virtio_bdevice->balloon;
+
+interface->vdev = virtio_dev;
+
+virtio_bdevice->obj.destructor = qvirtio_balloon_device_destructor;
+virtio_bdevice->obj.get_driver = qvirtio_balloon_device_get_driver;
+
+return &virtio_bdevice->obj;
+}
+
+/* virtio-balloon-pci */
+static void *qvirtio_balloon_pci_get_driver(void *object,
+const char *interface)
+{
+QVirtioBalloonPCI *v_balloon = object;
+if (!g_strcmp0(interface, "virtio-balloon")) {
+return &v_balloon->balloon;
+}
+
+fprintf(stderr, "%s not present in virtio-balloon-pci\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_balloon_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioBalloonPCI *virtio_bpci = g_new0(QVirtioBalloonPCI, 1);
+QVirtioBalloon *interface = &virtio_bpci->balloon;
+QOSGraphObject *obj = &virtio_bpci->pci_vdev.obj;
+
+
+virtio_pci_init(&virtio_bpci->pci_vdev, pci_bus, addr);
+interface->vdev = &virtio_bpci->pci_vdev.vdev;
+
+obj->get_driver = qvirtio_balloon_pci_get_driver;
+
+return obj;
+}
+
+static void virtio_balloon_register_nodes(void)
+{
+QPCIAddress addr = {
+.devfn = QPCI_DEVFN(4, 0),
+};
+
+QOSGraphEdgeOptions opts = {
+.extra_device_opts = "addr=04.0",
+};
+
+/* virtio-balloon-device */
+qos_node_create_driver("virtio-balloon-device",
+virtio_balloon_device_create);
+qos_node_consumes("virtio-balloon-device", "virtio", NULL);
+qos_node_produces("virtio-balloon-device", "virtio-balloon");
+
+/* virtio-balloon-pci */
+add_qpci_address(&opts, &addr);
+qos_node_create_driver("virtio-balloon-pci", virtio_balloon_pci_create);
+qos_node_consumes("virtio-balloon-pci", "pci-bus", &opts);
+qos_node_produces("virtio-balloon-pci", "virtio-balloon");
+}
+
+libqos_init(virtio_balloon_register_nod

[Qemu-devel] [PATCH 27/33] tests/qgraph: virtio-blk driver and interface nodes

2018-08-13 Thread Emanuele Giuseppe Esposito
Add qgraph nodes for virtio-blk-pci and virtio-blk-device.
Both nodes produce virtio-blk, but virtio-blk-pci receives
a pci-bus and uses virtio-pci QOSGraphObject and functions,
while virtio-blk-device receives a virtio and implements
its own functions

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include|   1 +
 tests/libqos/virtio-blk.c | 126 ++
 tests/libqos/virtio-blk.h |  40 
 3 files changed, 167 insertions(+)
 create mode 100644 tests/libqos/virtio-blk.c
 create mode 100644 tests/libqos/virtio-blk.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index cc1e1396f1..340c2462d2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -769,6 +769,7 @@ libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-balloon.o
 libqgraph-virtio-obj-y += tests/libqos/virtio-rng.o
+libqgraph-virtio-obj-y += tests/libqos/virtio-blk.o
 
 libqgraph-pci-obj-y = $(libqos-virtio-obj-y)
 libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
diff --git a/tests/libqos/virtio-blk.c b/tests/libqos/virtio-blk.c
new file mode 100644
index 00..a9dcee376c
--- /dev/null
+++ b/tests/libqos/virtio-blk.c
@@ -0,0 +1,126 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * 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 "libqtest.h"
+#include "standard-headers/linux/virtio_blk.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-blk.h"
+
+#define PCI_SLOT0x04
+#define PCI_FN  0x00
+
+/* virtio-blk-device */
+static void qvirtio_blk_device_destructor(QOSGraphObject *obj)
+{
+QVirtioBlkDevice *v_blk = (QVirtioBlkDevice *) obj;
+g_free(v_blk);
+}
+
+static void *qvirtio_blk_device_get_driver(void *object,
+   const char *interface)
+{
+QVirtioBlkDevice *v_blk = object;
+if (!g_strcmp0(interface, "virtio-blk")) {
+return &v_blk->blk;
+}
+
+fprintf(stderr, "%s not present in virtio-blk-device\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_blk_device_create(void *virtio_dev,
+  QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioBlkDevice *virtio_blk = g_new0(QVirtioBlkDevice, 1);
+QVirtioBlk *interface = &virtio_blk->blk;
+
+interface->vdev = virtio_dev;
+
+virtio_blk->obj.destructor = qvirtio_blk_device_destructor;
+virtio_blk->obj.get_driver = qvirtio_blk_device_get_driver;
+
+return &virtio_blk->obj;
+}
+
+/* virtio-blk-pci */
+static void *qvirtio_blk_pci_get_driver(void *object, const char *interface)
+{
+QVirtioBlkPCI *v_blk = object;
+if (!g_strcmp0(interface, "virtio-blk")) {
+return &v_blk->blk;
+}
+
+/* implicit contains */
+if (!g_strcmp0(interface, "pci-device")) {
+return v_blk->pci_vdev.pdev;
+}
+
+fprintf(stderr, "%s not present in virtio-blk-pci\n", interface);
+g_assert_not_reached();
+}
+
+static void *virtio_blk_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
+  void *addr)
+{
+QVirtioBlkPCI *virtio_blk = g_new0(QVirtioBlkPCI, 1);
+QVirtioBlk *interface = &virtio_blk->blk;
+QOSGraphObject *obj = &virtio_blk->pci_vdev.obj;
+
+virtio_pci_init(&virtio_blk->pci_vdev, pci_bus, addr);
+interface->vdev = &virtio_blk->pci_vdev.vdev;
+
+g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_BLOCK);
+
+obj->get_driver = qvirtio_blk_pci_get_driver;
+
+return obj;
+}
+
+static void virtio_blk_register_nodes(void)
+{
+/* FIXME: every test using these two nodes needs to setup a
+ * -drive,id=drive0 otherwise QEMU is not going to start */
+
+char *arg = g_strdup_printf("id=drv0,drive=drive0,addr=%x.%x",
+PCI_SLOT, PCI_FN);
+
+QPCIAddress addr = {
+.devfn = QPCI_DEVFN(PCI_SLOT, PCI_FN),
+};
+
+QOSGraphEdgeOptions opts = { };
+
+/* virtio-blk-device */
+opts.extra_device_opts = "drive=drive0";
+qos_node_create_driver("virtio-blk-device", virtio_blk_device_create);
+qos_node_consumes("virtio-blk-device", "virtio", &opts);
+qos_node_produces("virtio-blk-device", "virtio-blk");
+
+/* 

Re: [Qemu-devel] QEMU on Solaris

2018-08-13 Thread Peter Maydell
On 13 August 2018 at 11:08, Peter Tribble  wrote:
> You can certainly run illumos (such as OpenIndiana or Tribblix) in a VM
> easily,
> and freely. I can help with that.

A good start would be if we had a wiki page similar to
https://wiki.qemu.org/Hosts/BSD (linked to from the "Building
QEMU from source" subsection of https://wiki.qemu.org/Documentation)
that gave the instructions for how to set up a VM running on
x86 QEMU/KVM on Linux which can build QEMU.

Then we could look at adding it to the tests in tests/vm/

thanks
-- PMM



[Qemu-devel] [PATCH 26/33] tests/qgraph: virtio-rng test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/virtio-rng-test in qgraph test node,
virtio-rng-test. This test consumes a virtio-rng interface
and checks that its function return the expected values.

Some functions are implemented only for virtio-rng-pci, so they
don't consume virtio-rng, but virtio-rng-pci

Note that this test does not allocate any virtio-rng structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include  |  3 +--
 tests/virtio-rng-test.c | 25 +
 2 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 162187d15b..cc1e1396f1 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -195,7 +195,6 @@ gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 check-qtest-virtio-y += tests/virtio-blk-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
-check-qtest-virtio-y += tests/virtio-rng-test$(EXESUF)
 gcov-files-virtio-y += hw/virtio/virtio-rng.c
 check-qtest-virtio-y += tests/virtio-scsi-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/scsi/virtio-scsi.c
@@ -784,6 +783,7 @@ libqgraph-tests-obj-y += tests/virtio-serial-test.o
 libqgraph-tests-obj-y += tests/virtio-console-test.o
 libqgraph-tests-obj-y += tests/virtio-9p-test.o
 libqgraph-tests-obj-y += tests/virtio-balloon-test.o
+libqgraph-tests-obj-y += tests/virtio-rng-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -829,7 +829,6 @@ tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
 tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y)
 tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) 
$(libqos-virtio-obj-y)
-tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
diff --git a/tests/virtio-rng-test.c b/tests/virtio-rng-test.c
index dcecf77463..fd67922b66 100644
--- a/tests/virtio-rng-test.c
+++ b/tests/virtio-rng-test.c
@@ -9,16 +9,17 @@
 
 #include "qemu/osdep.h"
 #include "libqtest.h"
-#include "libqos/pci.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-rng.h"
 
 #define PCI_SLOT_HP 0x06
 
 /* Tests only initialization so far. TODO: Replace with functional tests */
-static void pci_nop(void)
+static void nop(void *obj, void *data, QGuestAllocator *alloc)
 {
 }
 
-static void hotplug(void)
+static void rng_hotplug(void *obj, void *data, QGuestAllocator *alloc)
 {
 const char *arch = qtest_get_arch();
 
@@ -29,18 +30,10 @@ static void hotplug(void)
 }
 }
 
-int main(int argc, char **argv)
+static void register_virtio_rng_test(void)
 {
-int ret;
-
-g_test_init(&argc, &argv, NULL);
-qtest_add_func("/virtio/rng/pci/nop", pci_nop);
-qtest_add_func("/virtio/rng/pci/hotplug", hotplug);
-
-qtest_start("-device virtio-rng-pci");
-ret = g_test_run();
-
-qtest_end();
-
-return ret;
+qos_add_test("rng-nop", "virtio-rng", nop, NULL);
+qos_add_test("rng-hotplug", "virtio-rng-pci", rng_hotplug, NULL);
 }
+
+libqos_init(register_virtio_rng_test);
-- 
2.17.1




[Qemu-devel] [PATCH] chardev: Add websocket support

2018-08-13 Thread Julia Suvorova via Qemu-devel
New option "websock" added to allow using websocket protocol for
chardev socket backend.
Example:
-chardev socket,websock,id=...

Signed-off-by: Julia Suvorova 
---
 chardev/char-socket.c | 75 ---
 chardev/char.c|  3 ++
 qapi/char.json|  3 ++
 3 files changed, 70 insertions(+), 11 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index efbad6ee7c..4464446511 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -26,6 +26,7 @@
 #include "chardev/char.h"
 #include "io/channel-socket.h"
 #include "io/channel-tls.h"
+#include "io/channel-websock.h"
 #include "io/net-listener.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
@@ -69,6 +70,8 @@ typedef struct {
 GSource *telnet_source;
 TCPChardevTelnetInit *telnet_init;
 
+bool is_websock;
+
 GSource *reconnect_timer;
 int64_t reconnect_time;
 bool connect_err_reported;
@@ -386,12 +389,14 @@ static void tcp_chr_free_connection(Chardev *chr)
 }
 
 static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr,
-  bool is_listen, bool is_telnet)
+  bool is_listen, bool is_telnet,
+  bool is_websock)
 {
 switch (addr->type) {
 case SOCKET_ADDRESS_TYPE_INET:
 return g_strdup_printf("%s%s:%s:%s%s", prefix,
-   is_telnet ? "telnet" : "tcp",
+   is_telnet ? "telnet"
+ : (is_websock ? "websock" : "tcp"),
addr->u.inet.host,
addr->u.inet.port,
is_listen ? ",server" : "");
@@ -420,7 +425,8 @@ static void update_disconnected_filename(SocketChardev *s)
 
 g_free(chr->filename);
 chr->filename = SocketAddress_to_str("disconnected:", s->addr,
- s->is_listen, s->is_telnet);
+ s->is_listen, s->is_telnet,
+ s->is_websock);
 }
 
 /* NB may be called even if tcp_chr_connect has not been
@@ -508,7 +514,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t 
*buf, int len)
 
 static char *sockaddr_to_str(struct sockaddr_storage *ss, socklen_t ss_len,
  struct sockaddr_storage *ps, socklen_t ps_len,
- bool is_listen, bool is_telnet)
+ bool is_listen, bool is_telnet, bool is_websock)
 {
 char shost[NI_MAXHOST], sserv[NI_MAXSERV];
 char phost[NI_MAXHOST], pserv[NI_MAXSERV];
@@ -531,7 +537,8 @@ static char *sockaddr_to_str(struct sockaddr_storage *ss, 
socklen_t ss_len,
 getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost),
 pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV);
 return g_strdup_printf("%s:%s%s%s:%s%s <-> %s%s%s:%s",
-   is_telnet ? "telnet" : "tcp",
+   is_telnet ? "telnet"
+ : (is_websock ? "websock" : "tcp"),
left, shost, right, sserv,
is_listen ? ",server" : "",
left, phost, right, pserv);
@@ -550,7 +557,7 @@ static void tcp_chr_connect(void *opaque)
 chr->filename = sockaddr_to_str(
 &s->sioc->localAddr, s->sioc->localAddrLen,
 &s->sioc->remoteAddr, s->sioc->remoteAddrLen,
-s->is_listen, s->is_telnet);
+s->is_listen, s->is_telnet, s->is_websock);
 
 s->connected = 1;
 chr->gsource = io_add_watch_poll(chr, s->ioc,
@@ -699,6 +706,45 @@ cont:
 }
 
 
+static void tcp_chr_websock_handshake(QIOTask *task, gpointer user_data)
+{
+Chardev *chr = user_data;
+
+if (qio_task_propagate_error(task, NULL)) {
+tcp_chr_disconnect(chr);
+} else {
+tcp_chr_connect(chr);
+}
+}
+
+
+static void tcp_chr_websock_init(Chardev *chr)
+{
+SocketChardev *s = SOCKET_CHARDEV(chr);
+QIOChannelWebsock *wioc;
+gchar *name;
+
+if (s->is_listen) {
+wioc = qio_channel_websock_new_server(s->ioc);
+} else {
+/* Websocket client is not yet implemented */
+return;
+}
+if (wioc == NULL) {
+tcp_chr_disconnect(chr);
+return;
+}
+
+name = g_strdup_printf("chardev-websock-server-%s", chr->label);
+qio_channel_set_name(QIO_CHANNEL(wioc), name);
+g_free(name);
+object_unref(OBJECT(s->ioc));
+s->ioc = QIO_CHANNEL(wioc);
+
+qio_channel_websock_handshake(wioc, tcp_chr_websock_handshake, chr, NULL);
+}
+
+
 static void tcp_chr_tls_handshake(QIOTask *task,
   gpointer user_data)
 {
@@ -710,6 +756,8 @@ static void tcp_chr_tls_handshake(QIOTask *task,
 } else {
 if (s->do_telnetopt) {
 tcp_chr_telne

[Qemu-devel] [PATCH 30/33] tests/qgraph: virtio-net test node

2018-08-13 Thread Emanuele Giuseppe Esposito
Convert tests/virtio-net-test in qgraph test node,
virtio-net-test. This test consumes a virtio-net interface
and checks that its function return the expected values.

Some functions are implemented only for virtio-net-pci, so they
don't consume virtio-net, but virtio-net-pci

Note that this test does not allocate any virtio-net structure,
it's all done by the qtest walking graph mechanism

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include  |   3 +-
 tests/virtio-net-test.c | 161 
 2 files changed, 49 insertions(+), 115 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index c105c0902c..7a2b67c1ec 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -190,7 +190,6 @@ gcov-files-ipack-y += hw/char/ipoctal232.c
 gcov-files-virtioserial-y += hw/char/virtio-console.c
 
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio.c
-check-qtest-virtio-y += tests/virtio-net-test$(EXESUF)
 gcov-files-virtio-y += i386-softmmu/hw/net/virtio-net.c
 gcov-files-virtio-y += i386-softmmu/hw/virtio/virtio-balloon.c
 gcov-files-virtio-y += i386-softmmu/hw/block/virtio-blk.c
@@ -785,6 +784,7 @@ libqgraph-tests-obj-y += tests/virtio-9p-test.o
 libqgraph-tests-obj-y += tests/virtio-balloon-test.o
 libqgraph-tests-obj-y += tests/virtio-rng-test.o
 libqgraph-tests-obj-y += tests/virtio-blk-test.o
+libqgraph-tests-obj-y += tests/virtio-net-test.o
 
 check-unit-y += tests/test-qgraph$(EXESUF)
 tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
@@ -828,7 +828,6 @@ tests/ne2000-test$(EXESUF): tests/ne2000-test.o
 tests/wdt_ib700-test$(EXESUF): tests/wdt_ib700-test.o
 tests/tco-test$(EXESUF): tests/tco-test.o $(libqos-pc-obj-y)
 tests/virtio-ccw-test$(EXESUF): tests/virtio-ccw-test.o
-tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y) 
$(libqos-virtio-obj-y)
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
 tests/tpci200-test$(EXESUF): tests/tpci200-test.o
 tests/display-vga-test$(EXESUF): tests/display-vga-test.o
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 72728acf66..38daeda18c 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -9,18 +9,11 @@
 
 #include "qemu/osdep.h"
 #include "libqtest.h"
-#include "qemu-common.h"
-#include "qemu/sockets.h"
 #include "qemu/iov.h"
-#include "libqos/libqos-pc.h"
-#include "libqos/libqos-spapr.h"
-#include "libqos/virtio.h"
-#include "libqos/virtio-pci.h"
 #include "qapi/qmp/qdict.h"
-#include "qemu/bswap.h"
 #include "hw/virtio/virtio-net.h"
-#include "standard-headers/linux/virtio_ids.h"
-#include "standard-headers/linux/virtio_ring.h"
+#include "libqos/qgraph.h"
+#include "libqos/virtio-net.h"
 
 #define PCI_SLOT_HP 0x06
 #define PCI_SLOT0x04
@@ -29,59 +22,10 @@
 #define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000)
 #define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf)
 
-static void test_end(void)
-{
-qtest_end();
-}
+static int sv[2];
 
 #ifndef _WIN32
 
-static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
-{
-QVirtioPCIDevice *dev;
-
-dev = qvirtio_pci_device_find(bus, VIRTIO_ID_NET);
-g_assert(dev != NULL);
-g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET);
-
-qvirtio_pci_device_enable(dev);
-qvirtio_start_device(&dev->vdev);
-
-return dev;
-}
-
-static QOSState *pci_test_start(int socket)
-{
-QOSState *qs;
-const char *arch = qtest_get_arch();
-const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
-  "virtio-net-pci,netdev=hs0";
-
-if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-qs = qtest_pc_boot(cmd, socket);
-} else if (strcmp(arch, "ppc64") == 0) {
-qs = qtest_spapr_boot(cmd, socket);
-} else {
-g_printerr("virtio-net tests are only available on x86 or ppc64\n");
-exit(EXIT_FAILURE);
-}
-global_qtest = qs->qts;
-return qs;
-}
-
-static void driver_init(QVirtioDevice *dev)
-{
-uint32_t features;
-
-features = qvirtio_get_features(dev);
-features = features & ~(QVIRTIO_F_BAD_FEATURE |
-(1u << VIRTIO_RING_F_INDIRECT_DESC) |
-(1u << VIRTIO_RING_F_EVENT_IDX));
-qvirtio_set_features(dev, features);
-
-qvirtio_set_driver_ok(dev);
-}
-
 static void rx_test(QVirtioDevice *dev,
 QGuestAllocator *alloc, QVirtQueue *vq,
 int socket)
@@ -191,80 +135,71 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
 guest_free(alloc, req_addr);
 }
 
-static void send_recv_test(QVirtioDevice *dev,
-   QGuestAllocator *alloc, QVirtQueue *rvq,
-   QVirtQueue *tvq, int socket)
+static void send_recv_test(void *obj, void *data, QGuestAllocator *t_alloc)
 {
-rx_test(dev, alloc, rvq, socket);
-tx_test(dev, alloc, tvq, socket);
+QVirtioN

Re: [Qemu-devel] [PATCH 26/29] vmsvga: Add basic support for display topology

2018-08-13 Thread Gerd Hoffmann
  Hi,

> These registers are suppose to indicate to guest the display monitor
> size (width & height).

> Thus, wiring up GraphicsHwOps->ui_info callback to return new info on
> SVGA_REG_DISPLAY_{WIDTH, HEIGHT} registers may be useful only for case
> that we want guest to respond to the fact that the host display have
> been resized.

Yes, that is the purpose of the ui_info callback.  virtio-vga is the
easiest way to play with this:  Resize the gtk window, and gnome should
adapt the guest desktop to the new size, so you don't have a scaled
guest desktop.

> However, I am not sure there is a mechanism to notify guest from
> vmware-svga device that this even has occurred for guest to reread
> these registers.  Both in Linux vmware-svga driver code and VMware
> SVGA development kit, the SVGA_IRQFLAG_* flags don’t indicate such an
> interrupt source. In addition, it seems that Linux vmware-svga driver
> code only reads these registers at vmw_kms_save_vga() which weirdly
> enough, seems to be unreachable code (not called from anywhere…).

Hmm, that is strange ...

> Therefore, I’m not sure it is important to do this change at this
> patch series.

It isn't important for the series anyway.  Was just meant as hint where
the vmware-svga emulation could possibly improved even more, now that
you are at it.  It can certainly go either later as separate series or
not at all if it turns out it doesn't work anyway because the guests
drivers don't check the registers.

cheers,
  Gerd




Re: [Qemu-devel] Question about dirty page statistics for live migration

2018-08-13 Thread Li Qiang
2018-08-13 17:35 GMT+08:00 Dr. David Alan Gilbert :

> * Li Qiang (liq...@gmail.com) wrote:
> > Hello Dave, Juan and all,
> >
> > It is useful to get the dirty page rates in guest to evaluate the guest
> > loads
> > so that we can make a decide to live migrate it or not. So I think we can
> > add a on-demand qmp for showing the dirty page rates.
> >
> > I found someone has done this work in here:
> > -->https://github.com/grivon/yabusame-qemu-dpt
> > and here:
> > https://github.com/btrplace/qemu-patch
> >
> > But seems not go to the upstream.
> >
> > I want to know your opinions about adding this qmp.
>
> Something like that could be good;

one easy idea we had was
> a 'migrate null:' uri and then you would use most of the existing
> migration code to do the measurement; you would only have to
> add a dummy file backend,


As far as I understand, here dummy file backend just means the file migrate
to, right?

Thanks,
Li Qiang



> and something to stop the migration ever
> terminating (maybe just set the downtime very low).
>
>
> Dave
>
>
> > Thanks,
> > Li Qiang
> --
> Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK
>


[Qemu-devel] [PATCH 33/33] tests/qgraph: temporarly commented vhost-user-test

2018-08-13 Thread Emanuele Giuseppe Esposito
vhost-user-test has not converted to qgraph yet, and since
it uses virtio interface, it won't work, causing make check
to fail.
Commented out until it does not get converted to graph node.

Signed-off-by: Emanuele Giuseppe Esposito 
---
 tests/Makefile.include | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 15926cc95f..30355058fc 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -287,10 +287,10 @@ check-qtest-i386-y += tests/cpu-plug-test$(EXESUF)
 check-qtest-i386-y += tests/q35-test$(EXESUF)
 check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
 gcov-files-i386-y += hw/pci-host/q35.c
-check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += 
tests/vhost-user-test$(EXESUF)
-ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
-check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += 
tests/vhost-user-test$(EXESUF)
-endif
+# check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += 
tests/vhost-user-test$(EXESUF)
+# ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
+# check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += 
tests/vhost-user-test$(EXESUF)
+# endif
 check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-swtpm-test$(EXESUF)
 check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-test$(EXESUF)
 check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-swtpm-test$(EXESUF)
-- 
2.17.1




Re: [Qemu-devel] [PATCH 00/29]: vmsvga: Various fixes and enhancements

2018-08-13 Thread Gerd Hoffmann
  Hi,

> > But gdm doesn't start, neither with X11 nor with wayland.  Which is a
> > regression, because the xorg vmware driver manages to handle the current
> > qemu emulation just fine so gnome @ X11 works.
> 
> Interesting. Thanks for finding this out. Will have a look.
> Can you give more exact details about how you reproduced this issue?

xorg is easiest, because Fedora 28 uses that by default for vmware svga:

  (1) download Fedora 28 workstation live iso.
  (2) boot in qemu with -vga vmware.

To try wayland you have to install fedora to disk (can be done using the
workstation live iso).

You can switch between xorg and wayland using /etc/gdm/custom.conf then,
by commenting/uncommenting the WaylandEnable line ...

   [daemon]
   # Uncoment the line below to force the login screen to use Xorg
   #WaylandEnable=false

... and rebooting.

> I prefer to have a similar setup to make sure we have fixed the
> regression in this series.

xorg regression needs fixing.

Having wayland working too would be nice, but wayland doesn't work with
the current emulation either.  So it isn't a regression and can be done
as separate patch series later on.

cheers,
  Gerd




Re: [Qemu-devel] [RFC PATCH 0/3] tweaks for QEMU's C standard

2018-08-13 Thread Daniel P . Berrangé
On Mon, Aug 13, 2018 at 11:25:49AM +0200, Thomas Huth wrote:
> On 08/13/2018 11:07 AM, Daniel P. Berrangé wrote:
> > On Fri, Aug 10, 2018 at 06:10:58PM +0100, Alex Bennée wrote:
> >> Hi,
> >>
> >> While I was reviewing Richard's SVE series I found Travis choking on
> >> some perfectly valid c99. It turns out that Travis default image is
> >> old enough that gcc defaults to -std=gnu89 hence the problem. However
> >> switching to c99 isn't enough as we use GNUisms and even gnu99 still
> >> trips up on qemu-secomp.
> >>
> >> Of course we could just jump to C11 already?
> > 
> > We've always required GCC or a compatible compiler (CLang is only viable
> > alternative option really). We use a number of GCC extensions to the C
> > standard and I don't see a compelling reason to stop using them.
> > 
> > From that POV I think we do *NOT* need to care about official C standards
> > (c89, c99, c11, etc), only the GNU C standards (gnu89, gnu99, gnu11, etc).
> > 
> >> This is an RFC because this could descend into a C standards
> >> bike-shedding exercise but I thought I'd at least put it out there on
> >> a Friday afternoon ;-)
> > 
> > I did some archeology to inform our plans...
> > 
> > The default GCC C standards across various versions are:
> > 
> >   8.2.1: gnu17
> >   7.3.1: gnu11
> >   6.4.1: gnu11
> >   5.3.1: gnu11
> >   4.9.1: gnu89
> >   4.4.7: gnu89
> > 
> > Interesting to note that no version of GCC ever defaulted to gnu99. It was
> > not fully implemented initially and by the time the standard was fully
> > implemented, gnu11 was already good enough to be the default. So GCC jumped
> > straight from gnu89 as default to gnu11 as default.
> > 
> > Across the various distros we aim to support we have:
> > 
> >   RHEL-7: 4.8.5
> >   Debian (Stretch): 6.3.0
> >   Debian (Jessie): 4.9.2
> >   OpenBSD (Ports): 4.9.4
> >   FreeBSD (Ports): 8.2.0
> >   OpenSUSE Leap 15: 7.3.1
> >   SLE12-SP2:
> >   Ubuntu (Xenial): 5.4.0
> >   macOS (Homebrew): 8.2.0
> > 
> > IOW plenty of our plaforms are still on 4.x which defaults to gnu89.
> 
> Thanks for the great summary!
> 
> > In GCC 4.x, gnu99 is said to be incomplete (but usable) and gnu11
> > are said to be incomplete and experimental (ie don't use it).
> > 
> > The lowest common denominator supported by all our platforms is thus
> > gnu89.
> > 
> > If we don't mind that gnu99 is not fully complete in 4.x, we could use
> > that standard.
> > 
> > We definitely can't use gnu11 any time soon.
> > 
> > Given that many modern platforms default to gnu11, I think we should
> > set an explicit -std=gnu89, or -std=gnu99, because otherwise we risk
> > accidentally introducing code that relies on gnu11 features.
> 
> Sounds good. What about trying -std=gnu99 first, and if we run into
> problems, switch back to -std=gnu89 later?

I don't have a strong opinion either way - both options would be better
than what we do today by relying on the variable gcc built-in defaults.

Using -std=gnu99 gives slightly weaker protection in that we might still
accidentally use features which are not supported in the limitd gnu99
impl of gcc 4.x. I think that's unlikely, however, hence I don't really
mind either of gnu89 or gnu99

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



Re: [Qemu-devel] [PATCH 00/29]: vmsvga: Various fixes and enhancements

2018-08-13 Thread Liran Alon


- kra...@redhat.com wrote:

> Hi,
> 
> > > But gdm doesn't start, neither with X11 nor with wayland.  Which
> is a
> > > regression, because the xorg vmware driver manages to handle the
> current
> > > qemu emulation just fine so gnome @ X11 works.
> > 
> > Interesting. Thanks for finding this out. Will have a look.
> > Can you give more exact details about how you reproduced this
> issue?
> 
> xorg is easiest, because Fedora 28 uses that by default for vmware
> svga:
> 
>   (1) download Fedora 28 workstation live iso.
>   (2) boot in qemu with -vga vmware.
> 
> To try wayland you have to install fedora to disk (can be done using
> the
> workstation live iso).
> 
> You can switch between xorg and wayland using /etc/gdm/custom.conf
> then,
> by commenting/uncommenting the WaylandEnable line ...
> 
>[daemon]
># Uncoment the line below to force the login screen to use Xorg
>#WaylandEnable=false
> 
> ... and rebooting.
> 
> > I prefer to have a similar setup to make sure we have fixed the
> > regression in this series.
> 
> xorg regression needs fixing.
> 
> Having wayland working too would be nice, but wayland doesn't work
> with
> the current emulation either.  So it isn't a regression and can be
> done
> as separate patch series later on.
> 
> cheers,
>   Gerd

Thanks for the info.
We will reproduce and attempt to fix them both.
Stay tuned.

Regards,
-Liran



Re: [Qemu-devel] [PATCH 33/33] tests/qgraph: temporarly commented vhost-user-test

2018-08-13 Thread Michael S. Tsirkin
On Mon, Aug 13, 2018 at 12:14:53PM +0200, Emanuele Giuseppe Esposito wrote:
> vhost-user-test has not converted to qgraph yet, and since
> it uses virtio interface, it won't work, causing make check
> to fail.
> Commented out until it does not get converted to graph node.
> 
> Signed-off-by: Emanuele Giuseppe Esposito 

Two problems with that
- we lose vhost user coverage
- bisecting to before patch 33 will leave us with
  a failing make check

Thoughts?

> ---
>  tests/Makefile.include | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 15926cc95f..30355058fc 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -287,10 +287,10 @@ check-qtest-i386-y += tests/cpu-plug-test$(EXESUF)
>  check-qtest-i386-y += tests/q35-test$(EXESUF)
>  check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
>  gcov-files-i386-y += hw/pci-host/q35.c
> -check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += 
> tests/vhost-user-test$(EXESUF)
> -ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
> -check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += 
> tests/vhost-user-test$(EXESUF)
> -endif
> +# check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += 
> tests/vhost-user-test$(EXESUF)
> +# ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
> +# check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += 
> tests/vhost-user-test$(EXESUF)
> +# endif
>  check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-swtpm-test$(EXESUF)
>  check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-test$(EXESUF)
>  check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-swtpm-test$(EXESUF)
> -- 
> 2.17.1



Re: [Qemu-devel] [PATCH 33/33] tests/qgraph: temporarly commented vhost-user-test

2018-08-13 Thread Paolo Bonzini
On 13/08/2018 13:15, Michael S. Tsirkin wrote:
> On Mon, Aug 13, 2018 at 12:14:53PM +0200, Emanuele Giuseppe Esposito wrote:
>> vhost-user-test has not converted to qgraph yet, and since
>> it uses virtio interface, it won't work, causing make check
>> to fail.
>> Commented out until it does not get converted to graph node.
>>
>> Signed-off-by: Emanuele Giuseppe Esposito 
> 
> Two problems with that
> - we lose vhost user coverage
> - bisecting to before patch 33 will leave us with
>   a failing make check

See $SUBJECT, "temporarily". :)

Paolo

> 
>> ---
>>  tests/Makefile.include | 8 
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> index 15926cc95f..30355058fc 100644
>> --- a/tests/Makefile.include
>> +++ b/tests/Makefile.include
>> @@ -287,10 +287,10 @@ check-qtest-i386-y += tests/cpu-plug-test$(EXESUF)
>>  check-qtest-i386-y += tests/q35-test$(EXESUF)
>>  check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
>>  gcov-files-i386-y += hw/pci-host/q35.c
>> -check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += 
>> tests/vhost-user-test$(EXESUF)
>> -ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
>> -check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += 
>> tests/vhost-user-test$(EXESUF)
>> -endif
>> +# check-qtest-i386-$(CONFIG_VHOST_USER_NET_TEST_i386) += 
>> tests/vhost-user-test$(EXESUF)
>> +# ifeq ($(CONFIG_VHOST_USER_NET_TEST_i386),)
>> +# check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += 
>> tests/vhost-user-test$(EXESUF)
>> +# endif
>>  check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-swtpm-test$(EXESUF)
>>  check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-test$(EXESUF)
>>  check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-swtpm-test$(EXESUF)
>> -- 
>> 2.17.1




Re: [Qemu-devel] [PATCH v7 6/9] qcow2: Increase the default upper limit on the L2 cache size

2018-08-13 Thread Kevin Wolf
Am 13.08.2018 um 03:39 hat Max Reitz geschrieben:
> On 2018-08-10 14:00, Alberto Garcia wrote:
> > On Fri 10 Aug 2018 08:26:44 AM CEST, Leonid Bloch wrote:
> >> The upper limit on the L2 cache size is increased from 1 MB to 32 MB.
> >> This is done in order to allow default full coverage with the L2 cache
> >> for images of up to 256 GB in size (was 8 GB). Note, that only the
> >> needed amount to cover the full image is allocated. The value which is
> >> changed here is just the upper limit on the L2 cache size, beyond which
> >> it will not grow, even if the size of the image will require it to.
> >>
> >> Signed-off-by: Leonid Bloch 
> > 
> > Reviewed-by: Alberto Garcia 
> > 
> >> -#define DEFAULT_L2_CACHE_MAX_SIZE (1 * MiB)
> >> +#define DEFAULT_L2_CACHE_MAX_SIZE (32 * MiB)
> > 
> > The patch looks perfect to me now and I'm fine with this change, but
> > this is quite an increase from the previous default value. If anyone
> > thinks that this is too aggressive (or too little :)) I'm all ears.
> 
> This is just noise from the sidelines (so nothing too serious), but
> anyway, I don't like it very much.
> 
> My first point is that the old limit doesn't mean you can only use 8 GB
> qcow2 images.  You can use more, you just can't access more than 8 GB
> randomly.  I know I'm naive, but I think that the number of use cases
> where you need random IOPS spread out over more than 8 GB of an image
> are limited.

I think I can see use cases for databases that are spead across more
than 8 GB. But you're right, it's a tradeoff and users can always
increase the cache size in theory if they need more performance. But
then, they can also decrease the cache size if they need more memory.

Let's be honest: While qcow2 does have some room for functional
improvements, it mostly has an image problem, which comes from the fact
that there are cases where performance drops drastically. Benchmarks are
a very important use case and they do random I/O over more than 8 GB.

Not properly supporting such cases out-of-the-box is the reason why
people are requesting that we add features to raw images even if they
require on-disk metadata. If we want to avoid this kind of nonsense, we
need to improve the out-of-the-box experience with qcow2.

> My second point is that qemu still allocated 128 MB of RAM by default.
> Using 1/4th of that for every qcow2 image you attach to the VM seems a
> bit much.

Well, that's more because 128 MB is ridiculously low today and you won't
be able to run any recent guest without overriding the default.

> Now it gets a bit complicated.  This series makes cache-clean-interval
> default to 10 minutes, so it shouldn't be an issue in practice.  But one
> thing to note is that this is a Linux-specific feature, so on every
> other system, this really means 32 MB per image.

That's a bit inaccurate in this generality: On non-Linux, it means 32 MB
per fully accessed image with a size >= 256 GB.

> (Also, 10 minutes means that whenever I boot up my VM with a couple of
> disks with random accesses all over the images during boot, I might
> end up using 32 MB per image again (for 10 min), even though I don't
> really need that performance.)

If your system files are fragmented in a way that a boot will access
every 512 MB chunk in a 256 GB disk, you should seriously think about
fixing that...

This is a pathological case that shouldn't define our defaults. Random
I/O over 256 GB is really a pathological case, too, but people are
likely to actually test it. They aren't going to systematically test a
horribly fragmented system that wouldn't happen in reality.

> Now if we really rely on that cache-clean-interval, why not make it
> always cover the whole image by default?  I don't really see why we
> should now say "256 GB seems reasonable, and 32 MB doesn't sound like
> too much, let's go there".  (Well, OK, I do see how you end up using 32
> MB as basically a safety margin, where you'd say that anything above it
> is just unreasonable.)
> 
> Do we update the limit in a couple of years again because people have
> more RAM and larger disks then?  (Maybe we do?)

Possibly. I see those defaults as values that we can adjust to reality
whenever we think the old values don't reflect the important cases well
enough any more.

> My personal opinion is this: Most users should be fine with 8 GB of
> randomly accessible image space (this may be wrong).  Whenever a user
> does have an application that uses more than 8 GB, they are probably in
> an area where they want to do some performance tuning anyway.  Requiring
> them to set l2-cache-full in that case seems reasonable to me.

In principle, I'd agree. I'd even say that management tools should
always explicitly set those options instead of relying on our defaults.
But management tools have been ignoring these options for a long time
and keep doing so.

And honestly, if you can't spend a few megabytes for the caches, it's
just as reasonable that you should set l2-cache to a lo

Re: [Qemu-devel] [PATCH v2 04/22] check: Only test isa-testdev when it is compiled in

2018-08-13 Thread Paolo Bonzini
On 10/08/2018 17:17, Juan Quintela wrote:
> Paolo Bonzini  wrote:
>> On 10/08/2018 13:08, Juan Quintela wrote:
 Emanuele's qos-test would do this automatically.  It would be nicer to
 convert the whole ISA subsystem to use libqos and qos-test...
>>> Can we get this in until we get some volunteer for that other work?
>>> /me full of things on his plate at the moment.
>>
>> Sure, but since this is RFC, I commented. :)
> 
> I didn't expect less of you O:-)
> 
>> With qos-test, all tests
>> end up in a single binary that is generic for all QEMU targets, and
>> there's no need to synchronize the configuration with the testing.
>>
>> The disadvantage of doing it at the Makefile level is that it relies on
>> the devices being either in all targets or none.  For example
>> CONFIG_ISA_TESTDEV cannot be removed from just
>> default-configs/ppc-softmmu.mak if you are building both a PPC and an
>> x86 target.

Anyway, I'm not opposed to merging this part, it's just that they may be
unnecessary in the future.  The virtio split is more interesting to me,
and I am very happy that you are doing it!

Paolo



Re: [Qemu-devel] Question about dirty page statistics for live migration

2018-08-13 Thread Dr. David Alan Gilbert
* Li Qiang (liq...@gmail.com) wrote:
> 2018-08-13 17:35 GMT+08:00 Dr. David Alan Gilbert :
> 
> > * Li Qiang (liq...@gmail.com) wrote:
> > > Hello Dave, Juan and all,
> > >
> > > It is useful to get the dirty page rates in guest to evaluate the guest
> > > loads
> > > so that we can make a decide to live migrate it or not. So I think we can
> > > add a on-demand qmp for showing the dirty page rates.
> > >
> > > I found someone has done this work in here:
> > > -->https://github.com/grivon/yabusame-qemu-dpt
> > > and here:
> > > https://github.com/btrplace/qemu-patch
> > >
> > > But seems not go to the upstream.
> > >
> > > I want to know your opinions about adding this qmp.
> >
> > Something like that could be good;
> 
> one easy idea we had was
> > a 'migrate null:' uri and then you would use most of the existing
> > migration code to do the measurement; you would only have to
> > add a dummy file backend,
> 
> 
> As far as I understand, here dummy file backend just means the file migrate
> to, right?

Yes; because then if you have a dummy migration destination, the rest of
the migration code will run, sync the bitmap and clear the bits, and
give you an approximation of the dirty rate.

It might still be worth having the separate code to measure it without
the overhead of the migration code; but then that's more complex - and
if you're trying to measure it to know how hard it is to migrate then
perhaps it's better to use the migration code anyway.

Dave

> Thanks,
> Li Qiang
> 
> 
> 
> > and something to stop the migration ever
> > terminating (maybe just set the downtime very low).
> >
> >
> > Dave
> >
> >
> > > Thanks,
> > > Li Qiang
> > --
> > Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK
> >
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [PATCH v7 5/9] qcow2: Assign the L2 cache relatively to the image size

2018-08-13 Thread Kevin Wolf
Am 11.08.2018 um 21:19 hat Leonid Bloch geschrieben:
> > >   @item refcount-cache-size
> > >   The maximum size of the refcount block cache in bytes
> > > diff --git a/tests/qemu-iotests/137 b/tests/qemu-iotests/137
> > > index 87965625d8..e3fb078588 100755
> > > --- a/tests/qemu-iotests/137
> > > +++ b/tests/qemu-iotests/137
> > > @@ -109,7 +109,6 @@ $QEMU_IO \
> > >   -c "reopen -o 
> > > cache-size=1M,l2-cache-size=64k,refcount-cache-size=64k" \
> > >   -c "reopen -o cache-size=1M,l2-cache-size=2M" \
> > >   -c "reopen -o cache-size=1M,refcount-cache-size=2M" \
> > > --c "reopen -o l2-cache-size=256T" \
> > 
> > The "L2 cache size too big" error can still be tested, but you will need
> > to create an image large enough to allow such a big cache.
> > 
> > $ qemu-img create -f qcow2 -o cluster_size=256k hd.qcow2 32P
> > $ $QEMU -drive file=hd.qcow2,l2-cache-entry-size=512,l2-cache-size=1T
> 
> * 32P qcow2 will take 33M - is it OK to create it just for a test?
> * Is it worth to create a special test scenario, with a separate image
> creation, just for that case?

We're creating larger images than that during tests, so I think this is
fine. You don't have to create a new separate test file or anything,
just increase the size of the used test image from 64M to 32P or
whatever is necessary.

Kevin



Re: [Qemu-devel] [PATCH 0/4] throttle: Race condition fixes and test cases

2018-08-13 Thread Alberto Garcia
ping

On Thu 02 Aug 2018 04:50:22 PM CEST, Alberto Garcia wrote:
> Hi all,
>
> here are the patches that I promised yesterday.
>
> I was originally thinking to propose this for the v3.0 release, but
> after debugging and fixing the problem I think that it's not
> essential (details below).
>
> The important patch is the second one. The first and the third are
> just test cases and the last is an alternative solution for the bug
> that Stefan fixed in 6fccbb475bc6effc313ee9481726a1748b6dae57.
>
> There are details in the patches themselves, but here's an explanation
> of the problem: consider a scenario with two drives A and B that are
> part of the same throttle group. Both of them have throttled requests
> and they're waiting for a timer that is set on drive A.
>
> (timer here) -->  [A]  ---  req1, req2
>   [B]  ---  req3
>
> If we drain drive [A] (e.g. by disabling its I/O limits) then its
> queue is restarted. req1 is processed immediately, and before
> finishing it calls schedule_next_request(). This follows the
> round-robin algorithm, selects req3 and puts a timer in [B].
>
> But we're still not done with draining [A], and now we have a
> BDRV_POLL_WHILE() loop at the end of bdrv_do_drained_begin() waiting
> for req2 to finish. That won't happen until the timer in [B] fires and
> req3 is done. If there are more drives in the group and more requests
> in the queue this can take a while. That's why disabling a drive's I/O
> limits can be noticeably slow: we disabled the I/O limits but they're
> still being enforced in practice.
>
> The QEMU I/O tests run in qtest mode (with QEMU_CLOCK_VIRTUAL). The
> clock must be advanced manually, which means that the scenario that I
> just described hangs QEMU because BDRV_POLL_WHILE() loops forever (you
> can reproduce this with patch 3). In a real world scenario this only
> results in the aforementioned slowdown (probably negligible in
> practice), which is not a critical thing, and that's why I think it's
> safe to keep the current code for QEMU 3.
>
> I think that's all. Questions and commend are welcome.
>
> Berto
>
> Alberto Garcia (4):
>   qemu-iotests: Test removing a throttle group member with a pending
> timer
>   throttle-groups: Skip the round-robin if a member is being drained
>   qemu-iotests: Update 093 to improve the draining test
>   throttle-groups: Don't allow timers without throttled requests
>
>  block/throttle-groups.c| 41 +-
>  tests/qemu-iotests/093 | 55 
> ++
>  tests/qemu-iotests/093.out |  4 ++--
>  3 files changed, 88 insertions(+), 12 deletions(-)
>
> -- 
> 2.11.0



Re: [Qemu-devel] [PATCH v7 5/9] qcow2: Assign the L2 cache relatively to the image size

2018-08-13 Thread Leonid Bloch

On 8/13/18 2:33 PM, Kevin Wolf wrote:

Am 11.08.2018 um 21:19 hat Leonid Bloch geschrieben:

   @item refcount-cache-size
   The maximum size of the refcount block cache in bytes
diff --git a/tests/qemu-iotests/137 b/tests/qemu-iotests/137
index 87965625d8..e3fb078588 100755
--- a/tests/qemu-iotests/137
+++ b/tests/qemu-iotests/137
@@ -109,7 +109,6 @@ $QEMU_IO \
   -c "reopen -o cache-size=1M,l2-cache-size=64k,refcount-cache-size=64k" \
   -c "reopen -o cache-size=1M,l2-cache-size=2M" \
   -c "reopen -o cache-size=1M,refcount-cache-size=2M" \
--c "reopen -o l2-cache-size=256T" \


The "L2 cache size too big" error can still be tested, but you will need
to create an image large enough to allow such a big cache.

$ qemu-img create -f qcow2 -o cluster_size=256k hd.qcow2 32P
$ $QEMU -drive file=hd.qcow2,l2-cache-entry-size=512,l2-cache-size=1T


* 32P qcow2 will take 33M - is it OK to create it just for a test?
* Is it worth to create a special test scenario, with a separate image
creation, just for that case?


We're creating larger images than that during tests, so I think this is
fine. You don't have to create a new separate test file or anything,
just increase the size of the used test image from 64M to 32P or
whatever is necessary.


OK, sure, will do in v9.

Leonid.



Kevin





[Qemu-devel] [PATCH] qemu-options: Fix bad "macaddr" property in the documentation

2018-08-13 Thread Thomas Huth
When using the "-device" option, the property is called "mac".
"macaddr" is only used for the legacy "-net nic" option.

Reported-by: Harald Hoyer 
Signed-off-by: Thomas Huth 
---
 qemu-options.hx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index b1bf0f4..3495531 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2345,7 +2345,7 @@ qemu-system-i386 linux.img \
  -netdev socket,id=n2,mcast=230.0.0.1:1234
 # launch yet another QEMU instance on same "bus"
 qemu-system-i386 linux.img \
- -device e1000,netdev=n3,macaddr=52:54:00:12:34:58 \
+ -device e1000,netdev=n3,mac=52:54:00:12:34:58 \
  -netdev socket,id=n3,mcast=230.0.0.1:1234
 @end example
 
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH] chardev: Add websocket support

2018-08-13 Thread Paolo Bonzini
Thanks Julia, just a few cleanups to simplify the prototypes of some
functions.

On 13/08/2018 12:20, Julia Suvorova wrote:
> New option "websock" added to allow using websocket protocol for
> chardev socket backend.
> Example:
> -chardev socket,websock,id=...
> 
> Signed-off-by: Julia Suvorova 
> ---
>  chardev/char-socket.c | 75 ---
>  chardev/char.c|  3 ++
>  qapi/char.json|  3 ++
>  3 files changed, 70 insertions(+), 11 deletions(-)
> 
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index efbad6ee7c..4464446511 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -26,6 +26,7 @@
>  #include "chardev/char.h"
>  #include "io/channel-socket.h"
>  #include "io/channel-tls.h"
> +#include "io/channel-websock.h"
>  #include "io/net-listener.h"
>  #include "qemu/error-report.h"
>  #include "qemu/option.h"
> @@ -69,6 +70,8 @@ typedef struct {
>  GSource *telnet_source;
>  TCPChardevTelnetInit *telnet_init;
>  
> +bool is_websock;
> +
>  GSource *reconnect_timer;
>  int64_t reconnect_time;
>  bool connect_err_reported;
> @@ -386,12 +389,14 @@ static void tcp_chr_free_connection(Chardev *chr)
>  }
>  
>  static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr,
> -  bool is_listen, bool is_telnet)
> +  bool is_listen, bool is_telnet,
> +  bool is_websock)

The only caller passes the four arguments as "s->addr, s->is_listen,
s->is_telner, s->is_websock".  Can you change the arguments to
"SocketChardev *s, const char *prefix" and rename to
qemu_chr_socket_address?  Or even remove "const char *prefix" and rename
to "qemu_chr_compute_disconnected_filename", as you prefer.

>  {
>  switch (addr->type) {
>  case SOCKET_ADDRESS_TYPE_INET:
>  return g_strdup_printf("%s%s:%s:%s%s", prefix,
> -   is_telnet ? "telnet" : "tcp",
> +   is_telnet ? "telnet"
> + : (is_websock ? "websock" : "tcp"),
> addr->u.inet.host,
> addr->u.inet.port,
> is_listen ? ",server" : "");
> @@ -420,7 +425,8 @@ static void update_disconnected_filename(SocketChardev *s)
>  
>  g_free(chr->filename);
>  chr->filename = SocketAddress_to_str("disconnected:", s->addr,
> - s->is_listen, s->is_telnet);
> + s->is_listen, s->is_telnet,
> + s->is_websock);
>  }
>  
>  /* NB may be called even if tcp_chr_connect has not been
> @@ -508,7 +514,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t 
> *buf, int len)
>  
>  static char *sockaddr_to_str(struct sockaddr_storage *ss, socklen_t ss_len,
>   struct sockaddr_storage *ps, socklen_t ps_len,
> - bool is_listen, bool is_telnet)
> + bool is_listen, bool is_telnet, bool is_websock)

Likewise here, the function only needs a single argument SocketChardev
*s and can be renamed to qemu_chr_compute_filename (since the result is
assigned to chr->filename).

>  {
>  char shost[NI_MAXHOST], sserv[NI_MAXSERV];
>  char phost[NI_MAXHOST], pserv[NI_MAXSERV];
> @@ -531,7 +537,8 @@ static char *sockaddr_to_str(struct sockaddr_storage *ss, 
> socklen_t ss_len,
>  getnameinfo((struct sockaddr *) ps, ps_len, phost, sizeof(phost),
>  pserv, sizeof(pserv), NI_NUMERICHOST | NI_NUMERICSERV);
>  return g_strdup_printf("%s:%s%s%s:%s%s <-> %s%s%s:%s",
> -   is_telnet ? "telnet" : "tcp",
> +   is_telnet ? "telnet"
> + : (is_websock ? "websock" : "tcp"),

... and finally add a new function
qemu_chr_socket_protocol(SocketChardev *s) that returns one of "telnet",
"websock" or "tcp".

> diff --git a/qapi/char.json b/qapi/char.json
> index b7b2a05766..135ccddaf7 100644
> --- a/qapi/char.json
> +++ b/qapi/char.json
> @@ -251,6 +251,8 @@
>  #  sockets (default: false)
>  # @tn3270: enable tn3270 protocol on server
>  #  sockets (default: false) (Since: 2.10)
> +# @websock: enable websocket protocol on server
> +#   sockets (default: false)

"(Since: 3.1)".

Thanks,

Paolo

>  # @reconnect: For a client socket, if a socket is disconnected,
>  #  then attempt a reconnect after the given number of seconds.
>  #  Setting this to zero disables this function. (default: 0)
> @@ -265,6 +267,7 @@
>   '*nodelay'   : 'bool',
>   '*telnet': 'bool',
>   '*tn3270': 'bool',
> + '*websoc

Re: [Qemu-devel] [PATCH 00/33] Qtest driver framework

2018-08-13 Thread Michael S. Tsirkin
On Mon, Aug 13, 2018 at 12:14:20PM +0200, Emanuele Giuseppe Esposito wrote:
> Qgraph API for the qtest driver framework
> 
> This series of patches introduce a different qtest driver
> organization, viewing machines, drivers and tests as node in a
> graph, each having one or multiple edges relations.
> 
> The idea is to have a framework where each test asks for a specific
> driver, and the framework takes care of allocating the proper devices
> required and passing the correct command line arguments to QEMU.
> 
> A node can be of four types:
> - MACHINE:   for example "arm/raspi2"
> - DRIVER:for example "generic-sdhci"
> - INTERFACE: for example "sdhci" (interface for all "-sdhci" drivers)
> - TEST:  for example "sdhci-test", consumes an interface and tests
>  the functions provided
> 
> An edge relation between two nodes (drivers or machines) X and Y can be:
> - X CONSUMES Y: Y can be plugged into X
> - X PRODUCES Y: X provides the interface Y
> - X CONTAINS Y: Y is part of X component
> 
> Basic framework steps are the following:
> - All nodes and edges are created in their respective machine/driver/test 
> files
> - The framework starts QEMU and asks for a list of available devices
>   and machines
> - The framework walks the graph starting from the available machines and
>   performs a Depth First Search for tests
> - Once a test is found, the path is walked again and all drivers are
>   allocated accordingly and the final interface is passed to the test
> - The test is executed
> - Unused objects are cleaned and the path discovery is continued
> 
> Depending on the QEMU binary used, only some drivers/machines will be 
> available
> and only test that are reached by them will be executed.
> 
> This work is being done as Google Summer of Code 2018 project for QEMU,
> my mentors are Paolo Bonzini and Laurent Vivier.
> Additional infos on the project can be found at:
> https://wiki.qemu.org/Features/qtest_driver_framework

Seems pretty clean to me. Except that patch 33
needs to be fixed and fix squashed:

Acked-by: Michael S. Tsirkin 


> v3:
> - Minor fixes regarding memory leaks and naming
> 
> Signed-off-by: Emanuele Giuseppe Esposito 
> 
> Emanuele Giuseppe Esposito (32):
>   tests: qgraph API for the qtest driver framework
>   tests/qgraph: rename qpci_init_pc and qpci_init_spapr functions
>   tests/qgraph: pci-pc driver and interface nodes
>   tests/qgraph: x86_64/pc machine node
>   tests/qgraph: sdhci driver and interface nodes
>   tests/qgraph: sdhci test node
>   tests/qgraph: arm/raspi2 machine node
>   tests/qgraph: pci-spapr driver and interface nodes
>   tests/qgraph: ppc64/pseries machine node
>   tests/qgraph: has_buggy_msi flag
>   tests/qgraph: e1000e driver and interface nodes
>   tests/qgraph: e1000e-test node
>   tests/qgraph: virtio_start_device function
>   tests/qgraph: virtio-pci driver and interface nodes
>   tests/qgraph: virtio-mmio driver and interface nodes
>   tests/qgraph: arm/virt machine node
>   tests/qgraph: virtio-serial driver and interface nodes
>   tests/qgraph: virtio-console test node
>   tests/qgraph: virtio-serial test node
>   tests/qgraph: virtio-9p driver and interface nodes
>   tests/qgraph: virtio-9p test node
>   tests/qgraph: virtio-balloon driver and interface nodes
>   tests/qgraph: virtio-balloon test node
>   tests/qgraph: virtio-rng driver and interface nodes
>   tests/qgraph: virtio-rng test node
>   tests/qgraph: virtio-blk driver and interface nodes
>   tests/qgraph: virtio-blk test node
>   tests/qgraph: virtio-net driver and interface nodes
>   tests/qgraph: virtio-net test node
>   tests/qgraph: virtio-scsi driver and interface nodes
>   tests/qgraph: virtio-scsi test node
>   tests/qgraph: temporarly commented vhost-user-test
> 
> Paolo Bonzini (1):
>   tests: virtio: separate ccw tests from libqos
> 
>  configure|   2 +-
>  include/qemu/module.h|   2 +
>  tests/Makefile.include   |  79 +--
>  tests/e1000e-test.c  | 354 +++--
>  tests/i440fx-test.c  |   2 +-
>  tests/ide-test.c |   2 +-
>  tests/libqos/ahci.c  |   2 +-
>  tests/libqos/e1000e.c| 262 ++
>  tests/libqos/e1000e.h|  53 ++
>  tests/libqos/libqos-pc.c |   2 +-
>  tests/libqos/libqos-spapr.c  |   2 +-
>  tests/libqos/libqos.c|   2 +-
>  tests/libqos/libqos.h|   2 +-
>  tests/libqos/pci-pc.c|  86 ++--
>  tests/libqos/pci-pc.h|  22 +-
>  tests/libqos/pci-spapr.c | 119 +++--
>  tests/libqos/pci-spapr.h |  26 +-
>  tests/libqos/pci.c   |  37 +-
>  tests/libqos/pci.h   |  15 +
>  tests/libqos/ppc64_pseries-machine.c | 111 +
>  tests/libqos/qgraph.c| 721 +++
>  tests/libqos/qgraph.h| 515 ++

Re: [Qemu-devel] [PATCH] acpi: SRAT: do not create reserved gap entries

2018-08-13 Thread Eduardo Habkost
On Mon, Aug 13, 2018 at 09:07:13AM +0200, Igor Mammedov wrote:
> On Fri, 10 Aug 2018 15:28:35 -0300
> Eduardo Habkost  wrote:
> 
> > On Fri, Aug 10, 2018 at 06:01:06PM +0200, Igor Mammedov wrote:
> > > On Fri, 10 Aug 2018 16:06:57 +0200
> > > Igor Mammedov  wrote:
> > >   
> > > > Commit 848a1cc1e8b04 while introducing SRAT entries for DIMM and NVDIMM
> > > > also introduced fake entries for gaps between memory devices, assuming
> > > > that we need all possible range covered with SRAT entries.
> > > > And it did it wrong since gap would overlap with preceeding entry.
> > > > Reproduced with following CLI:
> > > > 
> > > >  -m 1G,slots=4,maxmem=8 \
> > > >  -object memory-backend-ram,size=1G,id=m0 \
> > > >  -device pc-dimm,memdev=m0,addr=0x10100 \
> > > >  -object memory-backend-ram,size=1G,id=m1 \
> > > >  -device pc-dimm,memdev=m1
> > > > 
> > > > However recent development (10efd7e108) showed that gap entries might
> > > > be not need. And indeed testing with WS2008DC-WS2016DC guests range
> > > > shows that memory hotplug works just fine without gap entries.
> > > > 
> > > > So rather than fixing gap entry borders, just drop them altogether
> > > > and simplify code around it.
> > > > 
> > > > Spotted-by: Laszlo Ersek 
> > > > Signed-off-by: Igor Mammedov 
> > > > ---
> > > > There is no need to update reference blobs since gaps beween dimms
> > > > aren't generated by any exsting test case.
> > > > 
> > > > Considering issue is not visible by default lets just merge it into 3.1
> > > > and stable 3.0.1  
> > > Pls ignore it for now I'll need to do more extensive testing with old 
> > > kernels,
> > > we might need these holes for old kernels or even new ones.
> > > /me goes to read kernel code
> > > 
> > > /per spec possible to hotplug range could be in SRAT,
> > >  even though I don't like it bu we might end up with static
> > >  partitioning of hotplug area between nodes like on bare metal
> > >  to avoid chasing after unknown requirements from windows /  
> > 
> > Does that mean we might want to pair DIMM slots with NUMA nodes
> > in advance?  Do you have a suggestion on how the command-line
> > would look like, in this case?
> > 
> > Maybe "-numa mem-slot,slot=X,node=Y"?
> it's either, to make it per slot (it implies fixed maximum size per slot)
> or a bit more flexible maxmem per node, might be something like:
>   -numa memory,node=X,maxmem=Y

That could work, but maybe it's too much flexibility?  It would
be tricky to define what is supposed happen when a slot cross
multiple NUMA nodes.

-- 
Eduardo



Re: [Qemu-devel] [PATCH] chardev: Add websocket support

2018-08-13 Thread Daniel P . Berrangé
On Mon, Aug 13, 2018 at 01:20:37PM +0300, Julia Suvorova via Qemu-devel wrote:
> New option "websock" added to allow using websocket protocol for
> chardev socket backend.
> Example:
> -chardev socket,websock,id=...
> 
> Signed-off-by: Julia Suvorova 
> ---
>  chardev/char-socket.c | 75 ---
>  chardev/char.c|  3 ++
>  qapi/char.json|  3 ++
>  3 files changed, 70 insertions(+), 11 deletions(-)
> 


> @@ -699,6 +706,45 @@ cont:
>  }
>  
>  
> +static void tcp_chr_websock_handshake(QIOTask *task, gpointer user_data)
> +{
> +Chardev *chr = user_data;
> +
> +if (qio_task_propagate_error(task, NULL)) {
> +tcp_chr_disconnect(chr);
> +} else {
> +tcp_chr_connect(chr);
> +}
> +}
> +
> +
> +static void tcp_chr_websock_init(Chardev *chr)
> +{
> +SocketChardev *s = SOCKET_CHARDEV(chr);
> +QIOChannelWebsock *wioc;
> +gchar *name;
> +
> +if (s->is_listen) {
> +wioc = qio_channel_websock_new_server(s->ioc);
> +} else {
> +/* Websocket client is not yet implemented */
> +return;
> +}
> +if (wioc == NULL) {
> +tcp_chr_disconnect(chr);
> +return;
> +}
> +
> +name = g_strdup_printf("chardev-websock-server-%s", chr->label);
> +qio_channel_set_name(QIO_CHANNEL(wioc), name);
> +g_free(name);
> +object_unref(OBJECT(s->ioc));
> +s->ioc = QIO_CHANNEL(wioc);
> +
> +qio_channel_websock_handshake(wioc, tcp_chr_websock_handshake, chr, 
> NULL);
> +}
> +
> +
>  static void tcp_chr_tls_handshake(QIOTask *task,
>gpointer user_data)
>  {
> @@ -710,6 +756,8 @@ static void tcp_chr_tls_handshake(QIOTask *task,
>  } else {
>  if (s->do_telnetopt) {
>  tcp_chr_telnet_init(chr);
> +} else if (s->is_websock) {
> +tcp_chr_websock_init(chr);
>  } else {
>  tcp_chr_connect(chr);
>  }
> @@ -799,12 +847,12 @@ static int tcp_chr_new_client(Chardev *chr, 
> QIOChannelSocket *sioc)
>  
>  if (s->tls_creds) {
>  tcp_chr_tls_init(chr);
> +} else if (s->do_telnetopt) {
> +tcp_chr_telnet_init(chr);
> +} else if (s->is_websock) {
> +tcp_chr_websock_init(chr);
>  } else {
> -if (s->do_telnetopt) {
> -tcp_chr_telnet_init(chr);
> -} else {
> -tcp_chr_connect(chr);
> -}
> +tcp_chr_connect(chr);


I don't think the ordering of init calls is correct when we have multiple 
options
enabled.

With tls=y & telnet=y we initialize TLS, then initialize telnet.

With tls=y & telnet=y & websock=y, we  initialize TLS, then initialize telnet 
and
then websock.

This means we're setting up a telnet session, and then running websocket over 
the top
of it.  This is wrong because there's no telnet client that exists which would 
be
able to use that.

The purpose of TLS & websock options in combination with telnet is to allow a 
normal
telnet session to be tunnelled over a TLS+websocket proxy.

So we must initailize TLS, then websock, then telnet


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



Re: [Qemu-devel] [PATCH] qemu-options: Fix bad "macaddr" property in the documentation

2018-08-13 Thread Markus Armbruster
Thomas Huth  writes:

> When using the "-device" option, the property is called "mac".
> "macaddr" is only used for the legacy "-net nic" option.

Indeed:

#define DEFINE_NIC_PROPERTIES(_state, _conf)\
--->DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),\
DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)

> Reported-by: Harald Hoyer 
> Signed-off-by: Thomas Huth 
> ---
>  qemu-options.hx | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index b1bf0f4..3495531 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2345,7 +2345,7 @@ qemu-system-i386 linux.img \
>   -netdev socket,id=n2,mcast=230.0.0.1:1234
>  # launch yet another QEMU instance on same "bus"
>  qemu-system-i386 linux.img \
> - -device e1000,netdev=n3,macaddr=52:54:00:12:34:58 \
> + -device e1000,netdev=n3,mac=52:54:00:12:34:58 \
>   -netdev socket,id=n3,mcast=230.0.0.1:1234
>  @end example

Reviewed-by: Markus Armbruster 



Re: [Qemu-devel] [PATCH v0 0/7] Background snapshots

2018-08-13 Thread Denis Plotnikov




On 26.07.2018 12:23, Peter Xu wrote:

On Thu, Jul 26, 2018 at 10:51:33AM +0200, Paolo Bonzini wrote:

On 25/07/2018 22:04, Andrea Arcangeli wrote:


It may look like the uffd-wp model is wish-feature similar to an
optimization, but without the uffd-wp model when the WP fault is
triggered by kernel code, the sigsegv model falls apart and requires
all kind of ad-hoc changes just for this single feature. Plus uffd-wp
has other benefits: it makes it all reliable in terms of not
increasing the number of vmas in use during the snapshot. Finally it
makes it faster too with no mmap_sem for reading and no sigsegv
signals.

The non cooperative features got merged first because there was much
activity on the kernel side on that front, but this is just an ideal
time to nail down the remaining issues in uffd-wp I think. That I
believe is time better spent than trying to emulate it with sigsegv
and changing all drivers to send new events down to qemu specific to
the sigsegv handling. We considered this before doing uffd for
postcopy too but overall it's unreliable and more work (no single
change was then needed to KVM code with uffd to handle postcopy and
here it should be the same).


I totally agree.  The hard part in userfaultfd was the changes to the
kernel get_user_pages API, but the payback was huge because _all_ kernel
uses (KVM, vhost-net, syscalls, etc.) just work with userfaultfd.  Going
back to mprotect would be a huge mistake.


Thanks for explaining the bits.  I'd say I wasn't aware of the
difference before I started the investigation (and only until now I
noticed that major difference between mprotect and userfaultfd).  I'm
really glad that it's much clear (at least for me) on which way we
should choose.

Now I'm thinking whether we can move the userfault write protect work
forward.  The latest discussion I saw so far is in 2016, when someone
from Huawei tried to use the write protect feature for that old
version of live snapshot but reported issue:

   https://lists.gnu.org/archive/html/qemu-devel/2016-12/msg01127.html

Is that the latest status for userfaultfd wr-protect?

If so, I'm thinking whether I can try to re-verify the work (I tried
his QEMU repository but I failed to compile somehow, so I plan to
write some even simpler code to try) to see whether I can get the same
KVM error he encountered.

Thoughts?


Just to sum up all being said before.

Using mprotect is a bad idea because VM's memory can be accessed from 
the number of places (KVM, vhost, ...) which need their own special care
of tracking memory accesses and notifying QEMU which makes the mprotect 
using unacceptable.


Protected memory accesses tracking can be done via userfaultfd's WP mode 
which isn't available right now.


So, the reasonable conclusion is to wait until the WP mode is available 
and build the background snapshot on top of userfaultfd-wp.
But, works on adding the WP-mode is pending for a quite a long time 
already.


Is there any way to estimate when it could be available?


Regards,



--
Best,
Denis



Re: [Qemu-devel] [PATCH 02/17] mirror: Make wait_for_any_operation() coroutine_fn

2018-08-13 Thread Murilo Opsfelder Araujo
Hi, Max.

On Mon, Aug 13, 2018 at 04:19:51AM +0200, Max Reitz wrote:
> mirror_wait_for_any_operation() calls qemu_co_queue_wait(), which is a
> coroutine_fn (technically it is a macro which resolves to a
> coroutine_fn).  Therefore, this function needs to be a coroutine_fn as
> well.
>
> This patch makes it and all of its callers coroutine_fns.
>
> Signed-off-by: Max Reitz 
> ---
>  block/mirror.c | 30 --
>  1 file changed, 16 insertions(+), 14 deletions(-)
>
> diff --git a/block/mirror.c b/block/mirror.c
> index 85f5742eae..c28b6159d5 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -279,7 +279,8 @@ static int mirror_cow_align(MirrorBlockJob *s, int64_t 
> *offset,
>  return ret;
>  }
>
> -static inline void mirror_wait_for_any_operation(MirrorBlockJob *s, bool 
> active)
> +static inline void coroutine_fn
> +mirror_co_wait_for_any_operation(MirrorBlockJob *s, bool active)
>  {
>  MirrorOp *op;
>
> @@ -297,10 +298,11 @@ static inline void 
> mirror_wait_for_any_operation(MirrorBlockJob *s, bool active)
>  abort();
>  }
>
> -static inline void mirror_wait_for_free_in_flight_slot(MirrorBlockJob *s)
> +static inline void coroutine_fn
> +mirror_co_wait_for_free_in_flight_slot(MirrorBlockJob *s)
>  {
>  /* Only non-active operations use up in-flight slots */
> -mirror_wait_for_any_operation(s, false);
> +mirror_co_wait_for_any_operation(s, false);
>  }
>
>  /* Perform a mirror copy operation.
> @@ -343,7 +345,7 @@ static void coroutine_fn mirror_co_read(void *opaque)
>
>  while (s->buf_free_count < nb_chunks) {
>  trace_mirror_yield_in_flight(s, op->offset, s->in_flight);
> -mirror_wait_for_free_in_flight_slot(s);
> +mirror_co_wait_for_free_in_flight_slot(s);
>  }
>
>  /* Now make a QEMUIOVector taking enough granularity-sized chunks
> @@ -549,7 +551,7 @@ static uint64_t coroutine_fn 
> mirror_iteration(MirrorBlockJob *s)
>
>  while (s->in_flight >= MAX_IN_FLIGHT) {
>  trace_mirror_yield_in_flight(s, offset, s->in_flight);
> -mirror_wait_for_free_in_flight_slot(s);
> +mirror_co_wait_for_free_in_flight_slot(s);
>  }
>
>  if (s->ret < 0) {
> @@ -600,10 +602,10 @@ static void mirror_free_init(MirrorBlockJob *s)
>   * mirror_resume() because mirror_run() will begin iterating again
>   * when the job is resumed.
>   */
> -static void mirror_wait_for_all_io(MirrorBlockJob *s)
> +static void coroutine_fn mirror_co_wait_for_all_io(MirrorBlockJob *s)
>  {
>  while (s->in_flight > 0) {
> -mirror_wait_for_free_in_flight_slot(s);
> +mirror_co_wait_for_free_in_flight_slot(s);
>  }
>  }
>
> @@ -762,7 +764,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob 
> *s)
>  if (s->in_flight >= MAX_IN_FLIGHT) {
>  trace_mirror_yield(s, UINT64_MAX, s->buf_free_count,
> s->in_flight);
> -mirror_wait_for_free_in_flight_slot(s);
> +mirror_co_wait_for_free_in_flight_slot(s);
>  continue;
>  }
>
> @@ -770,7 +772,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob 
> *s)
>  offset += bytes;
>  }
>
> -mirror_wait_for_all_io(s);
> +mirror_co_wait_for_all_io(s);
>  s->initial_zeroing_ongoing = false;
>  }
>
> @@ -916,7 +918,7 @@ static void coroutine_fn mirror_run(void *opaque)
>  /* Do not start passive operations while there are active
>   * writes in progress */
>  while (s->in_active_write_counter) {
> -mirror_wait_for_any_operation(s, true);
> +mirror_co_wait_for_any_operation(s, true);
>  }
>
>  if (s->ret < 0) {
> @@ -942,7 +944,7 @@ static void coroutine_fn mirror_run(void *opaque)
>  if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 ||
>  (cnt == 0 && s->in_flight > 0)) {
>  trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight);
> -mirror_wait_for_free_in_flight_slot(s);
> +mirror_co_wait_for_free_in_flight_slot(s);
>  continue;
>  } else if (cnt != 0) {
>  delay_ns = mirror_iteration(s);
> @@ -1028,7 +1030,7 @@ immediate_exit:
>  assert(ret < 0 || ((s->common.job.force_cancel || !s->synced) &&
> job_is_cancelled(&s->common.job)));
>  assert(need_drain);
> -mirror_wait_for_all_io(s);
> +mirror_co_wait_for_all_io(s);
>  }
>
>  assert(s->in_flight == 0);
> @@ -1098,11 +1100,11 @@ static void mirror_complete(Job *job, Error **errp)
>  job_enter(job);
>  }
>
> -static void mirror_pause(Job *job)
> +static void coroutine_fn mirror_pause(Job *job)

Other functions in this patch were renamed to mirror_co_*.  I'm not sure if
mirror_pause() should follow that, i.e. be renamed to mirror_co_pause().

>  {
>  Mir

[Qemu-devel] [PATCH] block/qapi: Fix memory leak in qmp_query_blockstats()

2018-08-13 Thread Kevin Wolf
For BlockBackends that are skipped in query-blockstats, we would leak
info since commit 567dcb31. Allocate info only later to avoid the memory
leak.

Fixes: CID 1394727
Cc: qemu-sta...@nongnu.org
Signed-off-by: Kevin Wolf 
---
 block/qapi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/qapi.c b/block/qapi.c
index 339727f0f4..c66f949db8 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -594,7 +594,7 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
 }
 } else {
 for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
-BlockStatsList *info = g_malloc0(sizeof(*info));
+BlockStatsList *info;
 AioContext *ctx = blk_get_aio_context(blk);
 BlockStats *s;
 char *qdev;
@@ -619,6 +619,7 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
 bdrv_query_blk_stats(s->stats, blk);
 aio_context_release(ctx);
 
+info = g_malloc0(sizeof(*info));
 info->value = s;
 *p_next = info;
 p_next = &info->next;
-- 
2.13.6




Re: [Qemu-devel] [Qemu-block] [PATCH] block/qapi: Fix memory leak in qmp_query_blockstats()

2018-08-13 Thread Alberto Garcia
On Mon 13 Aug 2018 03:27:54 PM CEST, Kevin Wolf wrote:
> For BlockBackends that are skipped in query-blockstats, we would leak
> info since commit 567dcb31. Allocate info only later to avoid the memory
> leak.
>
> Fixes: CID 1394727
> Cc: qemu-sta...@nongnu.org
> Signed-off-by: Kevin Wolf 

Reviewed-by: Alberto Garcia 

Berto



Re: [Qemu-devel] [PATCH v2] file-posix: Skip effectiveless OFD lock operations

2018-08-13 Thread Kevin Wolf
Am 13.08.2018 um 04:39 hat Fam Zheng geschrieben:
> If we know we've already locked the bytes, don't do it again; similarly
> don't unlock a byte if we haven't locked it. This doesn't change the
> behavior, but fixes a corner case explained below.
> 
> Libvirt had an error handling bug that an image can get its (ownership,
> file mode, SELinux) permissions changed (RHBZ 1584982) by mistake behind
> QEMU. Specifically, an image in use by Libvirt VM has:
> 
> $ ls -lhZ b.img
> -rw-r--r--. qemu qemu system_u:object_r:svirt_image_t:s0:c600,c690 b.img
> 
> Trying to attach it a second time won't work because of image locking.
> And after the error, it becomes:
> 
> $ ls -lhZ b.img
> -rw-r--r--. root root system_u:object_r:virt_image_t:s0 b.img
> 
> Then, we won't be able to do OFD lock operations with the existing fd.
> In other words, the code such as in blk_detach_dev:
> 
> blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort);
> 
> can abort() QEMU, out of environmental changes.
> 
> This patch is an easy fix to this and the change is regardlessly
> reasonable, so do it.
> 
> Signed-off-by: Fam Zheng 

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH] i386: Disable TOPOEXT by default on "-cpu host"

2018-08-13 Thread Moger, Babu
Looks good. Did some basic testing.

Reviewed-by: Babu Moger 

> -Original Message-
> From: Richard W.M. Jones 
> Sent: Friday, August 10, 2018 2:41 AM
> To: Eduardo Habkost 
> Cc: qemu-devel@nongnu.org; Paolo Bonzini ;
> Richard Henderson ; Moger, Babu
> 
> Subject: Re: [PATCH] i386: Disable TOPOEXT by default on "-cpu host"
> 
> On Thu, Aug 09, 2018 at 07:18:52PM -0300, Eduardo Habkost wrote:
> > Enabling TOPOEXT is always allowed, but it can't be enabled
> > blindly by "-cpu host" because it may make guests crash if the
> > rest of the cache topology information isn't provided or isn't
> > consistent.
> >
> > This addresses the bug reported at:
> > https://bugzilla.redhat.com/show_bug.cgi?id=1613277
> >
> > Signed-off-by: Eduardo Habkost 
> > ---
> >  target/i386/cpu.c | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> > index 723e02221e..3ac627978f 100644
> > --- a/target/i386/cpu.c
> > +++ b/target/i386/cpu.c
> > @@ -849,6 +849,12 @@ static FeatureWordInfo
> feature_word_info[FEATURE_WORDS] = {
> >  },
> >  .cpuid_eax = 0x8001, .cpuid_reg = R_ECX,
> >  .tcg_features = TCG_EXT3_FEATURES,
> > +/*
> > + * TOPOEXT is always allowed but can't be enabled blindly by
> > + * "-cpu host", as it requires consistent cache topology info
> > + * to be provided so it doesn't confuse guests.
> > + */
> > +.no_autoenable_flags = CPUID_EXT3_TOPOEXT,
> >  },
> >  [FEAT_C000_0001_EDX] = {
> >  .feat_names = {
> 
> Can confirm that this fixes the problem observed on the original AMD
> Phenom machine, using qemu from git (@6ad908053) + your patch.
> Therefore:
> 
> Tested-by: Richard W.M. Jones 
> 
> Thanks,
> 
> Rich.
> 
> --
> Richard Jones, Virtualization Group, Red Hat
> http://people.redhat.com/~rjones
> Read my programming and virtualization blog: http://rwmj.wordpress.com
> virt-p2v converts physical machines to virtual machines.  Boot with a
> live CD or over the network (PXE) and turn machines into KVM guests.
> http://libguestfs.org/virt-v2v



Re: [Qemu-devel] [PATCH 1/4] block: adding lzfse decompressing support as a module.

2018-08-13 Thread Kevin Wolf
Am 10.08.2018 um 06:07 hat Julio Faracco geschrieben:
> QEMU dmg support includes zlib and bzip2, but it does not contains lzfse
> support. This commit adds the source file to extend compression support
> for new DMGs.
> 
> Signed-off-by: Julio Faracco 
> ---
>  block/dmg-lzfse.c | 54 +++
>  1 file changed, 54 insertions(+)
>  create mode 100644 block/dmg-lzfse.c
> 
> diff --git a/block/dmg-lzfse.c b/block/dmg-lzfse.c
> new file mode 100644
> index 00..d09b544a0a
> --- /dev/null
> +++ b/block/dmg-lzfse.c
> @@ -0,0 +1,54 @@
> +/*
> + * DMG lzfse uncompression
> + *
> + * Copyright (c) 2018 Julio Cesar Faracco
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "dmg.h"
> +#include 
> +
> +static int dmg_uncompress_lzfse_do(char *next_in, unsigned int avail_in,
> +   char *next_out, unsigned int avail_out)
> +{
> +void *aux;
> +size_t aux_allocated;
> +size_t out_size;
> +
> +aux_allocated = lzfse_decode_scratch_size();
> +aux = g_malloc(aux_allocated);
> +
> +if (aux_allocated != 0 && aux == 0) {
> +return -1;
> +}
> +
> +out_size = lzfse_decode_buffer((uint8_t *) next_out, avail_out,
> +   (uint8_t *) next_in, avail_in, aux);
> +
> +return out_size;
> +}

aux is leaked in this function.

Also, I don't think we actually need it. lzfse_decode_buffer() is
documented to just do the necessary allocation internally if NULL is
passed. Unless we do something more sophisticated, doing the memory
allocation ourselves is unnecessary complexity.

Kevin



Re: [Qemu-devel] [PATCH 2/4] configure: adding support to lzfse library.

2018-08-13 Thread Kevin Wolf
Am 10.08.2018 um 06:07 hat Julio Faracco geschrieben:
> This commit includes the support to lzfse opensource library. With this
> library dmg block driver can decompress images with this type of
> compression inside.
> 
> Signed-off-by: Julio Faracco 
> ---
>  block/Makefile.objs |  2 ++
>  configure   | 32 
>  2 files changed, 34 insertions(+)
> 
> diff --git a/block/Makefile.objs b/block/Makefile.objs
> index c8337bf186..f4ddbb9c7b 100644
> --- a/block/Makefile.objs
> +++ b/block/Makefile.objs
> @@ -47,6 +47,8 @@ ssh.o-cflags   := $(LIBSSH2_CFLAGS)
>  ssh.o-libs := $(LIBSSH2_LIBS)
>  block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o
>  dmg-bz2.o-libs := $(BZIP2_LIBS)
> +block-obj-$(if $(CONFIG_LZFSE),m,n) += dmg-lzfse.o
> +dmg-lzfse.o-libs   := $(LZFSE_LIBS)
>  qcow.o-libs:= -lz
>  linux-aio.o-libs   := -laio
>  parallels.o-cflags := $(LIBXML2_CFLAGS)
> diff --git a/configure b/configure
> index 2a7796ea80..b12a16f2bf 100755
> --- a/configure
> +++ b/configure
> @@ -432,6 +432,7 @@ capstone=""
>  lzo=""
>  snappy=""
>  bzip2=""
> +lzfse=""
>  guest_agent=""
>  guest_agent_with_vss="no"
>  guest_agent_ntddscsi="no"
> @@ -1300,6 +1301,10 @@ for opt do
>;;
>--enable-bzip2) bzip2="yes"
>;;
> +  --enable-lzfse) lzfse="yes"
> +  ;;
> +  --disable-lzfse) lzfse="no"
> +  ;;
>--enable-guest-agent) guest_agent="yes"
>;;
>--disable-guest-agent) guest_agent="no"
> @@ -1689,6 +1694,8 @@ disabled with --disable-FEATURE, default is enabled if 
> available:
>snappy  support of snappy compression library
>bzip2   support of bzip2 compression library
>(for reading bzip2-compressed dmg images)
> +  lzfse   support of lzfse compression library
> +  (for reading lzfse-compressed dmg images)
>seccomp seccomp support
>coroutine-pool  coroutine freelist (better performance)
>glusterfs   GlusterFS backend
> @@ -2213,6 +2220,25 @@ EOF
>  fi
>  fi
>  
> +##
> +# lzfse check
> +
> +if test "$lzfse" != "no" ; then
> +cat > $TMPC << EOF
> +#include 
> +int main(void) { lzfse_decode_scratch_size(); return 0; }
> +EOF
> +if compile_prog "" "-llzfse" ; then
> +libs_softmmu="$libs_softmmu -llzfse"

Are you sure about libs_softmmu? I think this is only for QEMU proper,
but not for tools like qemu-img or qemu-io, so if this were relevant,
we'd be missing lzfse support in some tools.

> +lzfse="yes"
> +else
> +if test "$lzfse" = "yes"; then
> +feature_not_found "lzfse" "Install lzfse devel"
> +fi
> +lzfse="no"
> +fi
> +fi
> +
>  ##
>  # libseccomp check
>  
> @@ -6001,6 +6027,7 @@ echo "Live block migration $live_block_migration"
>  echo "lzo support   $lzo"
>  echo "snappy support$snappy"
>  echo "bzip2 support $bzip2"
> +echo "lzfse support $lzfse"
>  echo "NUMA host support $numa"
>  echo "libxml2   $libxml2"
>  echo "tcmalloc support  $tcmalloc"
> @@ -6525,6 +6552,11 @@ if test "$bzip2" = "yes" ; then
>echo "BZIP2_LIBS=-lbz2" >> $config_host_mak
>  fi
>  
> +if test "$lzfse" = "yes" ; then
> +  echo "CONFIG_LZFSE=y" >> $config_host_mak
> +  echo "LZFSE_LIBS=-llzfse" >> $config_host_mak

But since we have LZFSE_LIBS here and this is referenced in
block/Makefile.objs, I suspect that the libs_softmmu addition is
actually redundant and could just go away above.

> +fi
> +
>  if test "$libiscsi" = "yes" ; then
>echo "CONFIG_LIBISCSI=m" >> $config_host_mak
>echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak

Kevin



Re: [Qemu-devel] [PATCH 3/4] dmg: including dmg-lzfse module inside dmg block driver.

2018-08-13 Thread Kevin Wolf
Am 10.08.2018 um 06:07 hat Julio Faracco geschrieben:
> This commit includes the support to new module dmg-lzfse into dmg block
> driver. It includes the support for block type ULFO (0x8007).
> 
> Signed-off-by: Julio Faracco 
> ---
>  block/dmg.c | 28 
>  block/dmg.h |  3 +++
>  2 files changed, 31 insertions(+)
> 
> diff --git a/block/dmg.c b/block/dmg.c
> index c9b3c519c4..390ab67e53 100644
> --- a/block/dmg.c
> +++ b/block/dmg.c
> @@ -33,6 +33,9 @@
>  int (*dmg_uncompress_bz2)(char *next_in, unsigned int avail_in,
>char *next_out, unsigned int avail_out);
>  
> +int (*dmg_uncompress_lzfse)(char *next_in, unsigned int avail_in,
> +char *next_out, unsigned int avail_out);
> +
>  enum {
>  /* Limit chunk sizes to prevent unreasonable amounts of memory being used
>   * or truncating when converting to 32-bit types
> @@ -107,6 +110,7 @@ static void update_max_chunk_size(BDRVDMGState *s, 
> uint32_t chunk,
>  switch (s->types[chunk]) {
>  case 0x8005: /* zlib compressed */
>  case 0x8006: /* bzip2 compressed */
> +case 0x8007: /* lzfse compressed */
>  compressed_size = s->lengths[chunk];
>  uncompressed_sectors = s->sectorcounts[chunk];
>  break;
> @@ -188,6 +192,8 @@ static bool dmg_is_known_block_type(uint32_t entry_type)
>  return true;
>  case 0x8006:/* bzip2 */
>  return !!dmg_uncompress_bz2;
> +case 0x8007:/* lzfse */
> + return !!dmg_uncompress_lzfse;

Indentation is off. I think you got a tab instead of spaces here.

>  default:
>  return false;
>  }
> @@ -431,6 +437,7 @@ static int dmg_open(BlockDriverState *bs, QDict *options, 
> int flags,
>  }
>  
>  block_module_load_one("dmg-bz2");
> +block_module_load_one("dmg-lzfse");
>  
>  s->n_chunks = 0;
>  s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;
> @@ -629,6 +636,27 @@ static inline int dmg_read_chunk(BlockDriverState *bs, 
> uint64_t sector_num)
>  return ret;
>  }
>  break;
> + case 0x8007:
> + if (!dmg_uncompress_lzfse) {

More tab damage in these two lines.

> +break;
> +}
> +/* we need to buffer, because only the chunk as whole can be
> + * inflated. */
> +ret = bdrv_pread(bs->file, s->offsets[chunk],
> + s->compressed_chunk, s->lengths[chunk]);
> +if (ret != s->lengths[chunk]) {
> +return -1;
> +}
> +
> +ret = dmg_uncompress_lzfse((char *)s->compressed_chunk,
> +   (unsigned int) s->lengths[chunk],
> +   (char *)s->uncompressed_chunk,
> +   (unsigned int)
> +   (512 * s->sectorcounts[chunk]));
> +if (ret < 0) {

lzfse_decode_buffer() returns 0 in error cases, and possibly a short
number of bytes. Should the condition compare ret with the expected full
byte count?

> +return ret;
> +}
> +break;
>  case 1: /* copy */
>  ret = bdrv_pread(bs->file, s->offsets[chunk],
>   s->uncompressed_chunk, s->lengths[chunk]);

Kevin



Re: [Qemu-devel] [PATCH 4/4] dmg: exchanging hardcoded dmg UDIF block types to enum.

2018-08-13 Thread Kevin Wolf
Am 10.08.2018 um 06:07 hat Julio Faracco geschrieben:
> This change is better to understand what kind of block type is being
> handled by the code. Using a syntax similar to the DMG documentation is
> easier than tracking all hex values assigned to a block type.
> 
> Signed-off-by: Julio Faracco 
> ---
>  block/dmg.c | 43 ---
>  1 file changed, 28 insertions(+), 15 deletions(-)
> 
> diff --git a/block/dmg.c b/block/dmg.c
> index 390ab67e53..ae379adb20 100644
> --- a/block/dmg.c
> +++ b/block/dmg.c
> @@ -44,6 +44,19 @@ enum {
>  DMG_SECTORCOUNTS_MAX = DMG_LENGTHS_MAX / 512,
>  };
>  
> +enum {
> +/* DMG Block Type */
> +UDZE=0, /* Zeroes */
> +UDRW,   /* RAW type */
> +UDIG,   /* Ignore */
> +UDCO=0x8004,

Note that 0x8004 didn't exist in the code previously, so UDCO
shouldn't occur anywhere else in this patch.

> +UDZO,
> +UDBZ,
> +ULFO,
> +UDCM=0x7ffe, /* Comments */
> +UDLE /* Last Entry */
> +};
> +
>  static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename)
>  {
>  int len;
> @@ -108,16 +121,16 @@ static void update_max_chunk_size(BDRVDMGState *s, 
> uint32_t chunk,
>  uint32_t uncompressed_sectors = 0;
>  
>  switch (s->types[chunk]) {
> -case 0x8005: /* zlib compressed */
> -case 0x8006: /* bzip2 compressed */
> -case 0x8007: /* lzfse compressed */
> +case UDCO: /* zlib compressed */

Oops, should this be UDZO?

> +case UDBZ: /* bzip2 compressed */
> +case ULFO: /* lzfse compressed */
>  compressed_size = s->lengths[chunk];
>  uncompressed_sectors = s->sectorcounts[chunk];
>  break;
> -case 1: /* copy */
> +case UDRW: /* copy */
>  uncompressed_sectors = DIV_ROUND_UP(s->lengths[chunk], 512);
>  break;
> -case 2: /* zero */
> +case UDIG: /* zero */
>  /* as the all-zeroes block may be large, it is treated specially: the
>   * sector is not copied from a large buffer, a simple memset is used
>   * instead. Therefore uncompressed_sectors does not need to be set. 
> */
> @@ -186,13 +199,13 @@ typedef struct DmgHeaderState {
>  static bool dmg_is_known_block_type(uint32_t entry_type)
>  {
>  switch (entry_type) {
> -case 0x0001:/* uncompressed */
> -case 0x0002:/* zeroes */
> -case 0x8005:/* zlib */
> +case UDRW:/* uncompressed */
> +case UDIG:/* zeroes */
> +case UDCO:/* zlib */

And this one, too?

>  return true;
> -case 0x8006:/* bzip2 */
> +case UDBZ:/* bzip2 */
>  return !!dmg_uncompress_bz2;
> -case 0x8007:/* lzfse */
> +case ULFO:/* lzfse */
>   return !!dmg_uncompress_lzfse;
>  default:
>  return false;

Kevin



Re: [Qemu-devel] [PATCH v8 3/8] qcow2: Avoid duplication in setting the refcount cache size

2018-08-13 Thread Alberto Garcia
On Mon 13 Aug 2018 03:07:24 AM CEST, Leonid Bloch wrote:
> The refcount cache size does not need to be set to its minimum value in
> read_cache_sizes(), as it is set to at least its minimum value in
> qcow2_update_options_prepare().
>
> Signed-off-by: Leonid Bloch 

Reviewed-by: Alberto Garcia 

Berto



  1   2   3   4   >