[Qemu-devel] [Bug 1556044] Re: Redox GUI hangs with 100% CPU on ARM

2019-04-27 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

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

Title:
  Redox GUI hangs with 100% CPU on ARM

Status in QEMU:
  Expired

Bug description:
  Booting into Redox OS cli on ARM with qemu-system-i386 works fine.
  However, starting the Redox GUI (orbital) brings up the graphical
  interface and then starts using 100% CPU. I'd guess it's related to
  mouse detection and handling.

  The OS image is fully usable on x86.

  
  https://www.dropbox.com/s/u6v2k9wzcuiycfo/redox-disk.img.xz?dl=0

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



[Qemu-devel] [Bug 1520730] Re: 32-bit editors vim/rhide broken keyboard handling in freedos 1.1 and ms-dos 6.22

2019-04-27 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

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

Title:
  32-bit editors vim/rhide broken keyboard handling in freedos 1.1 and
  ms-dos 6.22

Status in QEMU:
  Expired

Bug description:
  This bug is present as of the latest commit:
  714487515dbe0c65d5904251e796cd3a5b3579fb

  I also saw it in 2.4.1, but that was a distro package.

  You can see the bug simply using the following line: qemu-system-i386
  -hda freedos.disk

  Simply type vim (or rhide) and start entering in some text. You'll
  notice repeating characters, and also eventually the key mode will
  change as if you're holding down the shift button. Not capslock. "a"
  will become "A", but "\" will also become "|".

  I don't think this is a bug in freedos because I get the same behavior
  with dos 6.22. Not dosbox, though.

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



[Qemu-devel] [PATCH RESEND 0/2] ui/cocoa: Fix absolute and relative input issues on Mojave

2019-04-27 Thread Chen Zhang via Qemu-devel
The following patches fixed absolute and relative input device issues on macOS 
Mojave.

Chen Zhang (2):
  ui/cocoa: Fix absolute input device grabbing issue on Mojave
  ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input
device

 ui/cocoa.m | 50 +++---
 1 file changed, 47 insertions(+), 3 deletions(-)

-- 
2.19.2

[Qemu-devel] [PATCH RESEND 1/2] ui/cocoa: Fix absolute input device grabbing issue on Mojave

2019-04-27 Thread Chen Zhang via Qemu-devel
This patches fixed boundary check methods for cursor in normal and
fullscreen modes with/without Zoom-to-Fit on Mojave.

On Mojave, absolute input device, i.e. tablet, had trouble re-grabbing
the cursor in re-entry into the virtual screen area. In some cases,
the `window` property of NSEvent object was nil after exit of cursor,
meaning that the `-locationInWindow` method would return value in screen
coordinates. The current implementation used raw locations frrom NSEvent
without considering whether the value was for the window coordinates or
the macOS screen coordinates, nor the zooming factor for Zoom-to-Fit in
fullscreen mode.

In fullscreen mode, the fullscreen cocoa window might not be the key
window, therefore the location of event in virtual coordinates should
suffice.

Note: CGRect, -convertRectToScreen: and -convertRectFromScreen: were
used in coordinates conversion for compatibility reason.

Signed-off-by: Chen Zhang mailto:tgfb...@me.com>>
---
ui/cocoa.m | 43 +--
1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 420b2411c1..474d44cb9f 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -405,6 +405,41 @@ QemuCocoaView *cocoaView;
return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height);
}

+/* Get location of event and convert to virtual screen coordinate */
+- (CGPoint) screenLocationOfEvent:(NSEvent *)ev
+{
+NSWindow *eventWindow = [ev window];
+// XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10
+CGRect r = CGRectZero;
+r.origin = [ev locationInWindow];
+if (!eventWindow) {
+if (!isFullscreen) {
+return [[self window] convertRectFromScreen:r].origin;
+} else {
+CGPoint locationInSelfWindow = [[self window] 
convertRectFromScreen:r].origin;
+CGPoint loc = [self convertPoint:locationInSelfWindow 
fromView:nil];
+if (stretch_video) {
+loc.x /= cdx;
+loc.y /= cdy;
+}
+return loc;
+}
+} else if ([[self window] isEqual:eventWindow]) {
+if (!isFullscreen) {
+return r.origin;
+} else {
+CGPoint loc = [self convertPoint:r.origin fromView:nil];
+if (stretch_video) {
+loc.x /= cdx;
+loc.y /= cdy;
+}
+return loc;
+}
+} else {
+return [[self window] convertRectFromScreen:[eventWindow 
convertRectToScreen:r]].origin;
+}
+}
+
- (void) hideCursor
{
if (!cursor_hide) {
@@ -704,7 +739,8 @@ QemuCocoaView *cocoaView;
int keycode = 0;
bool mouse_event = false;
static bool switched_to_fullscreen = false;
-NSPoint p = [event locationInWindow];
+// Location of event in virtual screen coordinates
+NSPoint p = [self screenLocationOfEvent:event];

switch ([event type]) {
case NSEventTypeFlagsChanged:
@@ -815,7 +851,10 @@ QemuCocoaView *cocoaView;
break;
case NSEventTypeMouseMoved:
if (isAbsoluteEnabled) {
-if (![self screenContainsPoint:p] || ![[self window] 
isKeyWindow]) {
+// Cursor re-entered into a window might generate events bound 
to screen coordinates
+// and `nil` window property, and in full screen mode, current 
window might not be
+// key window, where event location alone should suffice.
+if (![self screenContainsPoint:p] || !([[self window] 
isKeyWindow] || isFullscreen)) {
if (isMouseGrabbed) {
[self ungrabMouse];
}
-- 
2.19.2

[Qemu-devel] [PATCH RESEND 2/2] ui/cocoa: Fix mouse grabbing in fullscreen mode for relative input device

2019-04-27 Thread Chen Zhang via Qemu-devel
In fullscreen mode, the window property of cocoaView may not be the key
window, and the current implementation would not grab mouse in fullscreen
mode after user ungrabs cursor in fullscreen mode with hot-key, and left
clicks the relative input devices to re-grab it.

This patch used value of isFullscreen as a short-cirtuit condition for
relative input device grabbing.

Signed-off-by: Chen Zhang mailto:tgfb...@me.com>>
---
ui/cocoa.m | 7 ++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 474d44cb9f..aa7cf07368 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -901,7 +901,12 @@ QemuCocoaView *cocoaView;
case NSEventTypeLeftMouseUp:
mouse_event = true;
if (!isMouseGrabbed && [self screenContainsPoint:p]) {
-if([[self window] isKeyWindow]) {
+/*
+ * In fullscreen mode, the window of cocoaView may not be the
+ * key window, therefore the position relative to the virtual
+ * screen alone will be sufficient.
+ */
+if(isFullscreen || [[self window] isKeyWindow]) {
[self grabMouse];
}
}
-- 
2.19.2

Re: [Qemu-devel] [PATCH 5/6] tests: Run the iotests during "make check" again

2019-04-27 Thread Eric Blake
On 4/25/19 5:24 AM, Thomas Huth wrote:

>> Ok, thanks for the info. Looks like many tests are failing because qemu-io 
>> suddenly prints its program name in front of the error messages? E.g.:
>>
>> --- /tmp/qemu-test/src/tests/qemu-iotests/069.out2019-04-24 
>> 16:52:31.0 +
>> +++ /tmp/qemu-test/build/tests/qemu-iotests/069.out.bad  2019-04-24 
>> 16:59:13.310226424 +
>> @@ -4,5 +4,5 @@
>>  
>>  Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=131072
>>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072 
>> backing_file=TEST_DIR/t.IMGFMT.base
>> -can't open device TEST_DIR/t.IMGFMT: Could not open backing file: Could not 
>> open 'TEST_DIR/t.IMGFMT.base': No such file or directory
>> +qemu-io: can't open device TEST_DIR/t.IMGFMT: Could not open backing file: 
>> Could not open 'TEST_DIR/t.IMGFMT.base': No such file or directory
>>
>> Does anybody from the block folks has a clue what might be going wrong here?
> 
> It's a regression in the current master branch, not caused by my series.
> The iotests also fail with vanilla master, e.g. reproducible with:
> 
>  cd tests/qemu-iotests
>  ./check -qcow2 069
> 
> It's caused by Christophe's commit here:
> 
>  99e98d7c9fc1a1639fad2c638733b02f4b43aebe
>  qemu-io: Use error_[gs]et_progname()
> 
> Christophe, could you please have a look?

The change in output is desirable, but yes, it does mean that iotests
need to have .out files updated to match.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Failing qemu-iotest 005 with raw

2019-04-27 Thread Eric Blake
On 4/26/19 5:53 AM, Kevin Wolf wrote:

>>  creating large image
>> +qemu-img: TEST_DIR/t.IMGFMT: The image size is too large for file
>> format 'IMGFMT'
>>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=536870912
>> [...]
>>
>> Could this be fixed somehow, or should the test rather be skipped for
>> IMGFMT=raw?
> 
> The test passes for me on XFS. Looks like the raw driver can handle
> large image files, but your host filesystem can't.
> 
> We would have to check whether the host filesystem can support large
> files and skip the test if it can't. I'm not sure how to do that. But
> actually, this isn't testing anything interesting for raw, so just
> unconditionally disabling the test for raw could be reasonable enough.

iotest 220 in commit 3b94c343 can serve as such an example (it skips the
test on at least ext4, while passing on tmpfs which allows larger sparse
files).

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PULL 0/4] x86 queue, 2019-04-25

2019-04-27 Thread Peter Maydell
On Thu, 25 Apr 2019 at 19:13, Eduardo Habkost  wrote:
>
> The following changes since commit 3284aa128153750f14a61e8a96fd085e6f2999b6:
>
>   Merge remote-tracking branch 'remotes/lersek/tags/edk2-pull-2019-04-22' 
> into staging (2019-04-24 13:19:41 +0100)
>
> are available in the Git repository at:
>
>   git://github.com/ehabkost/qemu.git tags/x86-next-pull-request
>
> for you to fetch changes up to a4e0b436f44a4bb47ed4a75b0c05d2547cf12b1c:
>
>   Pass through cache information for TOPOEXT CPUs (2019-04-25 14:52:28 -0300)
>
> 
> x86 queue, 2019-04-25
>
> * Hygon Dhyana CPU model (Pu Wen)
> * Categorize a few devices in hw/i386 (Ernest Esene)
> * Support host-cache-info on TOPOEXT CPUID leaf (Stanislav Lanci)
>
> 


Applied, thanks.

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

-- PMM



[Qemu-devel] [PATCHv4 2/2] ui/curses: manipulate cchar_t with standard curses functions

2019-04-27 Thread Samuel Thibault
The chars/attr fields are curses internals, setcchar and getcchar have
to be used instead.

Signed-off-by: Samuel Thibault 
Tested-by: Kamil Rytarowski 
---
 ui/curses.c | 43 +--
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index 81d419879e..1f3fcabb00 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -66,20 +66,22 @@ static void curses_update(DisplayChangeListener *dcl,
 {
 console_ch_t *line;
 cchar_t curses_line[width];
+wchar_t wch[CCHARW_MAX];
+attr_t attrs;
+short colors;
+int ret;
 
 line = screen + y * width;
 for (h += y; y < h; y ++, line += width) {
 for (x = 0; x < width; x++) {
 chtype ch = line[x] & 0xff;
 chtype at = line[x] & ~0xff;
-if (vga_to_curses[ch].chars[0]) {
-curses_line[x] = vga_to_curses[ch];
-} else {
-curses_line[x] = (cchar_t) {
-.chars[0] = ch,
-};
+ret = getcchar(_to_curses[ch], wch, , , NULL);
+if (ret == ERR || wch[0] == 0) {
+wch[0] = ch;
+wch[1] = 0;
 }
-curses_line[x].attr |= at;
+setcchar(_line[x], wch, at, 0, NULL);
 }
 mvwadd_wchnstr(screenpad, y, 0, curses_line, width);
 }
@@ -412,7 +414,7 @@ static void curses_atexit(void)
 static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
 {
 char mbch[MB_LEN_MAX];
-wchar_t wch;
+wchar_t wch[2];
 char *puch, *pmbch;
 size_t such, smbch;
 mbstate_t ps;
@@ -430,20 +432,22 @@ static void convert_ucs(unsigned char fch, uint16_t uch, 
iconv_t conv)
 }
 
 memset(, 0, sizeof(ps));
-if (mbrtowc(, mbch, sizeof(mbch) - smbch, ) == -1) {
+if (mbrtowc([0], mbch, sizeof(mbch) - smbch, ) == -1) {
 fprintf(stderr, "Could not convert 0x%04x "
 "from a multibyte character to wchar_t: %s\n",
 uch, strerror(errno));
 return;
 }
-vga_to_curses[fch].chars[0] = wch;
+
+wch[1] = 0;
+setcchar(_to_curses[fch], wch, 0, 0, NULL);
 }
 
 /* Setup wchar glyph for one font character */
 static void convert_font(unsigned char fch, iconv_t conv)
 {
 char mbch[MB_LEN_MAX];
-wchar_t wch;
+wchar_t wch[2];
 char *pfch, *pmbch;
 size_t sfch, smbch;
 mbstate_t ps;
@@ -461,13 +465,15 @@ static void convert_font(unsigned char fch, iconv_t conv)
 }
 
 memset(, 0, sizeof(ps));
-if (mbrtowc(, mbch, sizeof(mbch) - smbch, ) == -1) {
+if (mbrtowc([0], mbch, sizeof(mbch) - smbch, ) == -1) {
 fprintf(stderr, "Could not convert font glyph 0x%02x "
 "from a multibyte character to wchar_t: %s\n",
 fch, strerror(errno));
 return;
 }
-vga_to_curses[fch].chars[0] = wch;
+
+wch[1] = 0;
+setcchar(_to_curses[fch], wch, 0, 0, NULL);
 }
 
 /* Convert one wchar to UCS-2 */
@@ -592,7 +598,16 @@ static void font_setup(void)
 if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
 /* Non-Unicode capable, use termcap equivalents for those available */
 for (i = 0; i <= 0xFF; i++) {
-switch (get_ucs(vga_to_curses[i].chars[0], nativecharset_to_ucs2)) 
{
+wchar_t wch[CCHARW_MAX];
+attr_t attr;
+short color;
+int ret;
+
+ret = getcchar(_to_curses[i], wch, , , NULL);
+if (ret == ERR)
+continue;
+
+switch (get_ucs(wch[0], nativecharset_to_ucs2)) {
 case 0x00a3:
 vga_to_curses[i] = *WACS_STERLING;
 break;
-- 
2.20.1




[Qemu-devel] [PATCHv4 0/2] ui/curses: BSD portability fixes

2019-04-27 Thread Samuel Thibault
BSD needs a few fixes for wide character manipulations.

Difference with v1:
- Fix unitialized value in error message

Difference with v2:
- Add cchar_t manipulation fix

Difference with v3:
- use mbrtowc/wcrtomb instead of mbtowc/wctomb
- use MB_LEN_MAX instead of MB_CUR_MAX to avoid using a VLA.

Samuel Thibault (2):
  ui/curses: do not assume wchar_t contains unicode
  ui/curses: manipulate cchar_t with standard curses functions

 ui/curses.c | 194 ++--
 1 file changed, 126 insertions(+), 68 deletions(-)

-- 
2.20.1




[Qemu-devel] [PATCHv4 1/2] ui/curses: do not assume wchar_t contains unicode

2019-04-27 Thread Samuel Thibault
E.g. BSD and Solaris even use locale-specific encoding there.

We thus have to go through the native multibyte representation and use
mbrtowc/wcrtomb to make a proper conversion.

Signed-off-by: Samuel Thibault 
Tested-by: Kamil Rytarowski 
---
 ui/curses.c | 157 +---
 1 file changed, 100 insertions(+), 57 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index fb63945188..81d419879e 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -400,65 +400,108 @@ static void curses_atexit(void)
 endwin();
 }
 
+/*
+ * In the following:
+ * - fch is the font glyph number
+ * - uch is the unicode value
+ * - wch is the wchar_t value (may not be unicode, e.g. on BSD/solaris)
+ * - mbch is the native local-dependent multibyte representation
+ */
+
 /* Setup wchar glyph for one UCS-2 char */
-static void convert_ucs(int glyph, uint16_t ch, iconv_t conv)
+static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
 {
+char mbch[MB_LEN_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *puch, *pmbch;
+size_t such, smbch;
+mbstate_t ps;
+
+puch = (char *) 
+pmbch = (char *) mbch;
+such = sizeof(uch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from UCS-2 to a multibyte character: %s\n",
+uch, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: %s\n",
-ch, strerror(errno));
-} else {
-vga_to_curses[glyph].chars[0] = wch;
+memset(, 0, sizeof(ps));
+if (mbrtowc(, mbch, sizeof(mbch) - smbch, ) == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to wchar_t: %s\n",
+uch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Setup wchar glyph for one font character */
-static void convert_font(unsigned char ch, iconv_t conv)
+static void convert_font(unsigned char fch, iconv_t conv)
 {
+char mbch[MB_LEN_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *pfch, *pmbch;
+size_t sfch, smbch;
+mbstate_t ps;
+
+pfch = (char *) 
+pmbch = (char *) 
+sfch = sizeof(fch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from %s to a multibyte character: %s\n",
+fch, font_charset, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02x from %s to WCHAR_T: %s\n",
-ch, font_charset, strerror(errno));
-} else {
-vga_to_curses[ch].chars[0] = wch;
+memset(, 0, sizeof(ps));
+if (mbrtowc(, mbch, sizeof(mbch) - smbch, ) == -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from a multibyte character to wchar_t: %s\n",
+fch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Convert one wchar to UCS-2 */
 static uint16_t get_ucs(wchar_t wch, iconv_t conv)
 {
-uint16_t ch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
-
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02lx from WCHAR_T to UCS-2: 
%s\n",
-(unsigned long)wch, strerror(errno));
+char mbch[MB_LEN_MAX];
+uint16_t uch;
+char *pmbch, *puch;
+size_t smbch, such;
+mbstate_t ps;
+int ret;
+
+memset(, 0, sizeof(ps));
+ret = wcrtomb(mbch, wch, );
+if (ret == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from wchar_t to a multibyte character: %s\n",
+wch, strerror(errno));
+return 0xFFFD;
+}
+
+pmbch = (char *) mbch;
+puch = (char *) 
+smbch = ret;
+such = sizeof(uch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to UCS-2 : %s\n",
+wch, strerror(errno));
 return 0xFFFD;
 }
 
-return ch;
+return uch;
 }
 
 /*
@@ -466,6 +509,11 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
  */
 static void font_setup(void)
 {
+iconv_t ucs2_to_nativecharset;
+iconv_t nativecharset_to_ucs2;
+iconv_t font_conv;
+int i;
+
 /*
  * 

Re: [Qemu-devel] [PATCH] Makefile: Let the 'clean' rule remove qemu-ga.exe on Windows hosts

2019-04-27 Thread Stefan Weil
On 27.04.19 18:13, Philippe Mathieu-Daudé wrote:
> Commit 48ff7a625b36 added the QEMU Guest Agent tool with the
> optional ".exe" suffix for Windows hosts, but forgot to use
> this suffix in the 'clean' rule. Calling this rule let a dangling
> executable in the build directory.
> Correct this by using the proper optional suffix.
> 
> Fixes: 48ff7a625b36
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 626a04d305c..07bfa26536a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -639,7 +639,7 @@ clean:
>   ! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll 
> \
>   -exec rm {} +
>   rm -f $(edk2-decompressed)
> - rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* 
> *.pod *~ */*~
> + rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga$(EXESUF) TAGS 
> cscope.* *.pod *~ */*~
>   rm -f fsdev/*.pod scsi/*.pod
>   rm -f qemu-img-cmds.h
>   rm -f ui/shader/*-vert.h ui/shader/*-frag.h
> 

Reviewed-by: Stefan Weil 

Thank you!

Stefan



Re: [Qemu-devel] [PATCHv3 1/2] ui/curses: Do not assume wchar_t contains unicode

2019-04-27 Thread Kamil Rytarowski
On 27.04.2019 19:57, Samuel Thibault wrote:
> Kamil Rytarowski, le sam. 27 avril 2019 19:36:40 +0200, a ecrit:
>> On 27.04.2019 18:30, Samuel Thibault wrote:
>>> E.g. BSD and Solaris even use locale-specific encoding there.
>>>
>>> We thus have to go through the native multibyte representation and use
>>> mbtowc/wctomb to make a proper conversion.
>>>
>>> Signed-off-by: Samuel Thibault 
>>
>> Both patches work for me on NetBSD/amd64 8.99.37 for qemu-system-x86_64.
>> Borders are printed correctly.
>>
>> Regarding the patch I'm not sure whether to use MB_LEN_MAX or MB_CUR_MAX?
> 
> I don't know if qemu can afford VLA?
> 

It's better to avoid VLA and pick MB_LEN_MAX.

>> I'm also unsure whether to reset conversion state between a multibyte
>> character and wide character, with: `mbtowc(NULL, 0, 0);`. It's
>> recommended to use in code examples examples. I think it doesn't make
>> any harm to use it.
> 
> Mmm, better yet, we should actually use mbrtowc and wcrtomb. I have
> fixed this in my tree.
> 

This is even better.

>> I'm not sure if this is related, but "qemu-system-hppa -curses" is
>> broken for me. I didn't use it in the past as it just recently acquired
>> NetBSD guest support.
>>
>> (lldb) bt
>> libcurses.so.7`mvwadd_wchnstr(win=0x, y=,
>> x=, wchstr=0x7f7fe020, n=0) at add_wchstr.c:123
>>   * frame #2: 0x0078629e
>> qemu-system-hppa`curses_update(dcl=0x7f7ff7bd8bc0, x=0, y=0, w=79,
>> h=24) at curses.c:86:9
>> frame #3: 0x00753dae
>> qemu-system-hppa`dpy_text_update(con=0x7f7ff7bae580, x=0, y=0, w=79,
> 
>> (lldb) p screenpad
>> (WINDOW *) $2 = 0x
> 
> I don't think this is related at all, screenpad management is another
> matter.
> 

OK! I will treat it as an independent issue and try to address it.

> Samuel
> 




signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 0/2] hw/acpi: Improve build modularity (targeting MIPS/PPC)

2019-04-27 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20190427165504.29846-1-phi...@redhat.com/



Hi,

This series failed the docker-mingw@fedora build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===




The full log is available at
http://patchew.org/logs/20190427165504.29846-1-phi...@redhat.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCHv3 1/2] ui/curses: Do not assume wchar_t contains unicode

2019-04-27 Thread Samuel Thibault
Kamil Rytarowski, le sam. 27 avril 2019 19:36:40 +0200, a ecrit:
> On 27.04.2019 18:30, Samuel Thibault wrote:
> > E.g. BSD and Solaris even use locale-specific encoding there.
> > 
> > We thus have to go through the native multibyte representation and use
> > mbtowc/wctomb to make a proper conversion.
> > 
> > Signed-off-by: Samuel Thibault 
> 
> Both patches work for me on NetBSD/amd64 8.99.37 for qemu-system-x86_64.
> Borders are printed correctly.
> 
> Regarding the patch I'm not sure whether to use MB_LEN_MAX or MB_CUR_MAX?

I don't know if qemu can afford VLA?

> I'm also unsure whether to reset conversion state between a multibyte
> character and wide character, with: `mbtowc(NULL, 0, 0);`. It's
> recommended to use in code examples examples. I think it doesn't make
> any harm to use it.

Mmm, better yet, we should actually use mbrtowc and wcrtomb. I have
fixed this in my tree.

> I'm not sure if this is related, but "qemu-system-hppa -curses" is
> broken for me. I didn't use it in the past as it just recently acquired
> NetBSD guest support.
> 
> (lldb) bt
> libcurses.so.7`mvwadd_wchnstr(win=0x, y=,
> x=, wchstr=0x7f7fe020, n=0) at add_wchstr.c:123
>   * frame #2: 0x0078629e
> qemu-system-hppa`curses_update(dcl=0x7f7ff7bd8bc0, x=0, y=0, w=79,
> h=24) at curses.c:86:9
> frame #3: 0x00753dae
> qemu-system-hppa`dpy_text_update(con=0x7f7ff7bae580, x=0, y=0, w=79,

> (lldb) p screenpad
> (WINDOW *) $2 = 0x

I don't think this is related at all, screenpad management is another
matter.

Samuel



Re: [Qemu-devel] [PATCHv3 1/2] ui/curses: Do not assume wchar_t contains unicode

2019-04-27 Thread Kamil Rytarowski
On 27.04.2019 18:30, Samuel Thibault wrote:
> E.g. BSD and Solaris even use locale-specific encoding there.
> 
> We thus have to go through the native multibyte representation and use
> mbtowc/wctomb to make a proper conversion.
> 
> Signed-off-by: Samuel Thibault 

Both patches work for me on NetBSD/amd64 8.99.37 for qemu-system-x86_64.
Borders are printed correctly.

Regarding the patch I'm not sure whether to use MB_LEN_MAX or MB_CUR_MAX?

I'm also unsure whether to reset conversion state between a multibyte
character and wide character, with: `mbtowc(NULL, 0, 0);`. It's
recommended to use in code examples examples. I think it doesn't make
any harm to use it.


I'm not sure if this is related, but "qemu-system-hppa -curses" is
broken for me. I didn't use it in the past as it just recently acquired
NetBSD guest support.

(lldb) bt
* thread #1, stop reason = signal SIGSEGV
frame #0: 0x7f7ff6c1fb98
libcurses.so.7`wmove(win=0x, y=0, x=0) at move.c:71
frame #1: 0x7f7ff6c0ca9b
libcurses.so.7`mvwadd_wchnstr(win=0x, y=,
x=, wchstr=0x7f7fe020, n=0) at add_wchstr.c:123
  * frame #2: 0x0078629e
qemu-system-hppa`curses_update(dcl=0x7f7ff7bd8bc0, x=0, y=0, w=79,
h=24) at curses.c:86:9
frame #3: 0x00753dae
qemu-system-hppa`dpy_text_update(con=0x7f7ff7bae580, x=0, y=0, w=79,
h=24) at console.c:1658:13
frame #4: 0x00758abe
qemu-system-hppa`text_console_update(opaque=0x7f7ff7bae580,
chardata=0x0118e490) at console.c:1264:9
frame #5: 0x00751ef8
qemu-system-hppa`graphic_hw_text_update(con=0x7f7ff7bae580,
chardata=0x0118c690) at console.c:389:9
frame #6: 0x00785bcb
qemu-system-hppa`curses_refresh(dcl=0x7f7ff7bd8bc0) at curses.c:273:5
frame #7: 0x00758248
qemu-system-hppa`dpy_refresh(s=0x7f7ff7bd8770) at console.c:1622:13
frame #8: 0x0075809d
qemu-system-hppa`gui_update(opaque=0x7f7ff7bd8770) at console.c:205:5
frame #9: 0x008d9f4d
qemu-system-hppa`timerlist_run_timers(timer_list=0x7f7ff7e57d20) at
qemu-timer.c:574:9
frame #10: 0x008da01d
qemu-system-hppa`qemu_clock_run_timers(type=QEMU_CLOCK_REALTIME) at
qemu-timer.c:588:12
frame #11: 0x008da4ea
qemu-system-hppa`qemu_clock_run_all_timers at qemu-timer.c:708:25
frame #12: 0x008da962
qemu-system-hppa`main_loop_wait(nonblocking=0) at main-loop.c:519:5
frame #13: 0x005570a4 qemu-system-hppa`main_loop at vl.c:1970:9
frame #14: 0x00551fa4 qemu-system-hppa`main(argc=2,
argv=0x7f7fe768, envp=0x7f7fe780) at vl.c:4604:5
frame #15: 0x0040e7ad qemu-system-hppa`___start + 280

(lldb) p screenpad
(WINDOW *) $2 = 0x

We pass NULL window argument to mvwadd_wchnstr(3) and crash. Can you
reproduce it locally?

I will try to investigate it.

> ---
>  ui/curses.c | 151 
>  1 file changed, 94 insertions(+), 57 deletions(-)
> 
> diff --git a/ui/curses.c b/ui/curses.c
> index fb63945188..395f9545e9 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -400,65 +400,102 @@ static void curses_atexit(void)
>  endwin();
>  }
>  
> +/*
> + * In the following:
> + * - fch is the font glyph number
> + * - uch is the unicode value
> + * - wch is the wchar_t value (may not be unicode, e.g. on BSD/solaris)
> + * - mbch is the native local-dependent multibyte representation
> + */
> +
>  /* Setup wchar glyph for one UCS-2 char */
> -static void convert_ucs(int glyph, uint16_t ch, iconv_t conv)
> +static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
>  {
> +char mbch[MB_CUR_MAX];
>  wchar_t wch;
> -char *pch, *pwch;
> -size_t sch, swch;
> -
> -pch = (char *) 
> -pwch = (char *) 
> -sch = sizeof(ch);
> -swch = sizeof(wch);
> +char *puch, *pmbch;
> +size_t such, smbch;
> +
> +puch = (char *) 
> +pmbch = (char *) mbch;
> +such = sizeof(uch);
> +smbch = sizeof(mbch);
> +
> +if (iconv(conv, , , , ) == (size_t) -1) {
> +fprintf(stderr, "Could not convert 0x%04x "
> +"from UCS-2 to a multibyte character: %s\n",
> +uch, strerror(errno));
> +return;
> +}
>  
> -if (iconv(conv, , , , ) == (size_t) -1) {
> -fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: 
> %s\n",
> -ch, strerror(errno));
> -} else {
> -vga_to_curses[glyph].chars[0] = wch;
> +if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
> +fprintf(stderr, "Could not convert 0x%04x "
> +"from a multibyte character to wchar_t: %s\n",
> +uch, strerror(errno));
> +return;
>  }
> +vga_to_curses[fch].chars[0] = wch;
>  }
>  
>  /* Setup wchar glyph for one font character */
> -static void convert_font(unsigned char ch, iconv_t conv)
> 

Re: [Qemu-devel] [PATCH] configure: Add -Wno-typedef-redefinition to CFLAGS (for Clang)

2019-04-27 Thread Richard Henderson
On 4/27/19 8:45 AM, Thomas Huth wrote:
> Without the -Wno-typedef-redefinition option, clang complains if a typedef
> gets redefined in gnu99 mode (since this is officially a C11 feature). This
> used to also happen with older versions of GCC, but since we've bumped our
> minimum GCC version to 4.8, all versions of GCC that we support do not seem
> to issue this warning in gnu99 mode anymore. So this has become a common
> problem for people who only test their code with GCC - they do not notice
> the issue until they submit their patches and suddenly patchew or a
> maintainer complains.
> 
> Now that we do not urgently need to keep the code clean from typedef
> redefintions anymore with recent versions of GCC, we can ease the
> situation with clang, too, and simply shut these warnings off for good.
> 
> Signed-off-by: Thomas Huth 
> ---
>  configure | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson 


r~



Re: [Qemu-devel] [PATCH] hw/i386: The i440fx is not a machine, remove it from the machine list

2019-04-27 Thread Philippe Mathieu-Daudé
On 4/27/19 4:49 PM, Thomas Huth wrote:
> On 27/04/2019 16.19, Philippe Mathieu-Daudé wrote:
>> When building with CONFIG_ISAPC=n and CONFIG_I440FX=y we get:
>>
>>   $ make subdir-x86_64-softmmu
>>   [...]
>>   /usr/bin/ld: hw/i386/pc_piix.o: in function `pc_init1':
>>   /source/qemu/hw/i386/pc_piix.c:261: undefined reference to `isa_ide_init'
>>   /usr/bin/ld: /source/qemu/hw/i386/pc_piix.c:261: undefined reference to 
>> `isa_ide_init'
>>   collect2: error: ld returned 1 exit status
>>   make[1]: *** [Makefile:204: qemu-system-x86_64] Error 1
>>
>> This is because the I440FX device is a North Bridge, not a machine.
> 
> Really? I thought CONFIG_I440FX was there to configure the
> "pc-i440fx-x.y" machine types?

Ah, I just found in hw/i386/pc_piix.c:

if (pcmc->pci_enabled) {
pci_bus = i440fx_init(host_type,
  pci_type,
  _state, _devfn,
  _bus, pcms->gsi,
  system_memory, system_io,
  machine->ram_size,
  pcms->below_4g_mem_size,
  pcms->above_4g_mem_size,
  pci_memory, ram_memory);
pcms->bus = pci_bus;
} else {
pci_bus = NULL;
i440fx_state = NULL;
isa_bus = isa_bus_new(NULL, get_system_memory(), system_io,
  _abort);
no_hpet = 1;
}

So I guess I'll have to figure it out from here ;)

Thanks,

Phil.



[Qemu-devel] [PATCH 1/2] hw/acpi: Simplify the Makefile logic

2019-04-27 Thread Philippe Mathieu-Daudé
Since we only require to link with acpi-stub.o when CONFIG_ACPI
is disabled, we can simplify the Makefile logic.

Suggested-by: Paolo Bonzini 
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/acpi/Makefile.objs | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 2d46e3789ae..c86edfbed90 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -1,4 +1,3 @@
-ifeq ($(CONFIG_ACPI),y)
 common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o
 common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
@@ -6,16 +5,11 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
 common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
 common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
-common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
-
 common-obj-y += acpi_interface.o
 common-obj-y += bios-linker-loader.o
 common-obj-y += aml-build.o
 common-obj-$(CONFIG_TPM) += tpm.o
-
 common-obj-$(CONFIG_IPMI) += ipmi.o
+
 common-obj-$(call lnot,$(CONFIG_IPMI)) += ipmi-stub.o
-else
-common-obj-y += acpi-stub.o
-endif
-common-obj-$(CONFIG_ALL) += acpi-stub.o ipmi-stub.o
+common-obj-$(call lnot,$(CONFIG_ACPI)) += acpi-stub.o
-- 
2.20.1




Re: [Qemu-devel] [PATCH 2/2] hw/acpi: Always build the acpi/core.o file

2019-04-27 Thread Philippe Mathieu-Daudé
On 4/27/19 6:55 PM, Philippe Mathieu-Daudé wrote:
> The 'core' ACPI functions are not X86-specific.
> Let this file be built unconditionally, this will allow
> us to use ACPI on non-X86 architectures.
> 
> Suggested-by: Paolo Bonzini 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/acpi/Makefile.objs | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> index c86edfbed90..09c810ac556 100644
> --- a/hw/acpi/Makefile.objs
> +++ b/hw/acpi/Makefile.objs
> @@ -1,4 +1,5 @@
> -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o
> +common-obj-$(CONFIG_ACPI) += core.o

Sorry, sent from wrong branch :S

Please consider reviewing with this snippet applied on top:

-- >8 --
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
@@ -1,4 +1,4 @@
-common-obj-$(CONFIG_ACPI) += core.o
+common-obj-y += core.o
---

I'll respin after getting some review comments.

> +common-obj-$(CONFIG_ACPI_X86) += piix4.o pcihp.o
>  common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o
>  common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
>  common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
> 



[Qemu-devel] [PATCH 2/2] hw/acpi: Always build the acpi/core.o file

2019-04-27 Thread Philippe Mathieu-Daudé
The 'core' ACPI functions are not X86-specific.
Let this file be built unconditionally, this will allow
us to use ACPI on non-X86 architectures.

Suggested-by: Paolo Bonzini 
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/acpi/Makefile.objs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index c86edfbed90..09c810ac556 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -1,4 +1,5 @@
-common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o
+common-obj-$(CONFIG_ACPI) += core.o
+common-obj-$(CONFIG_ACPI_X86) += piix4.o pcihp.o
 common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
 common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
-- 
2.20.1




[Qemu-devel] [PATCH 0/2] hw/acpi: Improve build modularity (targeting MIPS/PPC)

2019-04-27 Thread Philippe Mathieu-Daudé
Hi,

This series is not related to the previous one I just send:
hw/i386/acpi: Improve build modularity (isapc/q35/...)
https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg04678.html

While the first only concern X86 (changes within the architecture),
this one allow the core ACPI feature to be used by the MIPS and
PPC archs (specific series will follow).

Regards,

Phil.

Philippe Mathieu-Daudé (2):
  hw/acpi: Simplify the Makefile logic
  hw/acpi: Always build the acpi/core.o file

 hw/acpi/Makefile.objs | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

-- 
2.20.1




[Qemu-devel] [PATCH] hw/sparc/leon3: Allow load of uImage firmwares

2019-04-27 Thread Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé 

Currently the Leon3 machine doesn't allow to load legacy u-boot images:

  $ qemu-system-sparc -M leon3_generic -d in_asm \
  -kernel HelenOS-0.6.0-sparc32-leon3.bin
  qemu-system-sparc: could not load kernel 'HelenOS-0.6.0-sparc32-leon3.bin'

  $ file HelenOS-0.6.0-sparc32-leon3.bin
  HelenOS-0.6.0-sparc32-leon3.bin: u-boot legacy uImage, HelenOS-0.6.0,\
Linux/ARM, OS Kernel Image (Not compressed), 2424229 bytes,\
Sun Dec 21 19:18:09 2014,\
Load Address: 0x4000, Entry Point: 0x4000,\
Header CRC: 0x8BCFA236, Data CRC: 0x37AD87DF

Since QEMU can load uImages, add the necessary code,
so the Leon3 machine can load these images:

  $ qemu-system-sparc -M leon3_generic -d in_asm \
  -kernel HelenOS-0.6.0-sparc32-leon3.bin
  
  IN:
  0x4000:  b  0x47a8
  0x4004:  nop
  
  IN:
  0x47a8:  save  %sp, -136, %sp
  0x47ac:  call  0x4020
  0x47b0:  sethi  %hi(0x4000b800), %i1
  ...

Tested with the following firmware:
http://www.helenos.org/releases/HelenOS-0.6.0-sparc32-leon3.bin

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/sparc/leon3.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 774639af33..0383b17c29 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -193,6 +193,10 @@ static void leon3_generic_hw_init(MachineState *machine)
 kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
, NULL, NULL,
1 /* big endian */, EM_SPARC, 0, 0);
+if (kernel_size < 0) {
+kernel_size = load_uimage(kernel_filename, NULL, ,
+  NULL, NULL, NULL);
+}
 if (kernel_size < 0) {
 error_report("could not load kernel '%s'", kernel_filename);
 exit(1);
-- 
2.19.1




[Qemu-devel] [PATCHv3 0/2] ui/curses: BSD portability fixes

2019-04-27 Thread Samuel Thibault
BSD needs a few fixes for wide character manipulations.

Difference with v1:
- Fix unitialized value in error message

Difference with v2:
- Add cchar_t manipulation fix

Samuel Thibault (2):
  ui/curses: do not assume wchar_t contains unicode
  ui/curses: manipulate cchar_t with standard curses functions

 ui/curses.c | 188 +---
 1 file changed, 120 insertions(+), 68 deletions(-)

-- 
2.20.1




Re: [Qemu-devel] [PATCH] hw/sparc/leon3: Allow load of uImage firmwares

2019-04-27 Thread Philippe Mathieu-Daudé
On Sat, Apr 27, 2019 at 6:24 PM Philippe Mathieu-Daudé  wrote:
>
> From: Philippe Mathieu-Daudé 

Grrr sent from wrong computer.



[Qemu-devel] [PATCHv3 2/2] ui/curses: manipulate cchar_t with standard curses functions

2019-04-27 Thread Samuel Thibault
The chars/attr fields are curses internals, setcchar and getcchar have
to be used instead.

Signed-off-by: Samuel Thibault 
---
 ui/curses.c | 43 +--
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index 395f9545e9..bc0d77a2a8 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -66,20 +66,22 @@ static void curses_update(DisplayChangeListener *dcl,
 {
 console_ch_t *line;
 cchar_t curses_line[width];
+wchar_t wch[CCHARW_MAX];
+attr_t attrs;
+short colors;
+int ret;
 
 line = screen + y * width;
 for (h += y; y < h; y ++, line += width) {
 for (x = 0; x < width; x++) {
 chtype ch = line[x] & 0xff;
 chtype at = line[x] & ~0xff;
-if (vga_to_curses[ch].chars[0]) {
-curses_line[x] = vga_to_curses[ch];
-} else {
-curses_line[x] = (cchar_t) {
-.chars[0] = ch,
-};
+ret = getcchar(_to_curses[ch], wch, , , NULL);
+if (ret == ERR || wch[0] == 0) {
+wch[0] = ch;
+wch[1] = 0;
 }
-curses_line[x].attr |= at;
+setcchar(_line[x], wch, at, 0, NULL);
 }
 mvwadd_wchnstr(screenpad, y, 0, curses_line, width);
 }
@@ -412,7 +414,7 @@ static void curses_atexit(void)
 static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
 {
 char mbch[MB_CUR_MAX];
-wchar_t wch;
+wchar_t wch[2];
 char *puch, *pmbch;
 size_t such, smbch;
 
@@ -428,20 +430,22 @@ static void convert_ucs(unsigned char fch, uint16_t uch, 
iconv_t conv)
 return;
 }
 
-if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+if (mbtowc([0], mbch, sizeof(mbch) - smbch) == -1) {
 fprintf(stderr, "Could not convert 0x%04x "
 "from a multibyte character to wchar_t: %s\n",
 uch, strerror(errno));
 return;
 }
-vga_to_curses[fch].chars[0] = wch;
+
+wch[1] = 0;
+setcchar(_to_curses[fch], wch, 0, 0, NULL);
 }
 
 /* Setup wchar glyph for one font character */
 static void convert_font(unsigned char fch, iconv_t conv)
 {
 char mbch[MB_CUR_MAX];
-wchar_t wch;
+wchar_t wch[2];
 char *pfch, *pmbch;
 size_t sfch, smbch;
 
@@ -457,13 +461,15 @@ static void convert_font(unsigned char fch, iconv_t conv)
 return;
 }
 
-if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+if (mbtowc([0], mbch, sizeof(mbch) - smbch) == -1) {
 fprintf(stderr, "Could not convert font glyph 0x%02x "
 "from a multibyte character to wchar_t: %s\n",
 fch, strerror(errno));
 return;
 }
-vga_to_curses[fch].chars[0] = wch;
+
+wch[1] = 0;
+setcchar(_to_curses[fch], wch, 0, 0, NULL);
 }
 
 /* Convert one wchar to UCS-2 */
@@ -586,7 +592,16 @@ static void font_setup(void)
 if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
 /* Non-Unicode capable, use termcap equivalents for those available */
 for (i = 0; i <= 0xFF; i++) {
-switch (get_ucs(vga_to_curses[i].chars[0], nativecharset_to_ucs2)) 
{
+wchar_t wch[CCHARW_MAX];
+attr_t attr;
+short color;
+int ret;
+
+ret = getcchar(_to_curses[i], wch, , , NULL);
+if (ret == ERR)
+continue;
+
+switch (get_ucs(wch[0], nativecharset_to_ucs2)) {
 case 0x00a3:
 vga_to_curses[i] = *WACS_STERLING;
 break;
-- 
2.20.1




[Qemu-devel] [PATCH v2] hw/sparc/leon3: Allow load of uImage firmwares

2019-04-27 Thread Philippe Mathieu-Daudé
Currently the Leon3 machine doesn't allow to load legacy u-boot images:

  $ qemu-system-sparc -M leon3_generic -d in_asm \
  -kernel HelenOS-0.6.0-sparc32-leon3.bin
  qemu-system-sparc: could not load kernel 'HelenOS-0.6.0-sparc32-leon3.bin'

  $ file HelenOS-0.6.0-sparc32-leon3.bin
  HelenOS-0.6.0-sparc32-leon3.bin: u-boot legacy uImage, HelenOS-0.6.0,\
Linux/ARM, OS Kernel Image (Not compressed), 2424229 bytes,\
Sun Dec 21 19:18:09 2014,\
Load Address: 0x4000, Entry Point: 0x4000,\
Header CRC: 0x8BCFA236, Data CRC: 0x37AD87DF

Since QEMU can load uImages, add the necessary code,
so the Leon3 machine can load these images:

  $ qemu-system-sparc -M leon3_generic -d in_asm \
  -kernel HelenOS-0.6.0-sparc32-leon3.bin
  
  IN:
  0x4000:  b  0x47a8
  0x4004:  nop
  
  IN:
  0x47a8:  save  %sp, -136, %sp
  0x47ac:  call  0x4020
  0x47b0:  sethi  %hi(0x4000b800), %i1
  ...

Tested with the following firmware:
http://www.helenos.org/releases/HelenOS-0.6.0-sparc32-leon3.bin

Signed-off-by: Philippe Mathieu-Daudé 
---
v2: Fixed GIT_AUTHOR_EMAIL
---
 hw/sparc/leon3.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 774639af33..0383b17c29 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -193,6 +193,10 @@ static void leon3_generic_hw_init(MachineState *machine)
 kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
, NULL, NULL,
1 /* big endian */, EM_SPARC, 0, 0);
+if (kernel_size < 0) {
+kernel_size = load_uimage(kernel_filename, NULL, ,
+  NULL, NULL, NULL);
+}
 if (kernel_size < 0) {
 error_report("could not load kernel '%s'", kernel_filename);
 exit(1);
-- 
2.19.1




[Qemu-devel] [PATCHv3 1/2] ui/curses: Do not assume wchar_t contains unicode

2019-04-27 Thread Samuel Thibault
E.g. BSD and Solaris even use locale-specific encoding there.

We thus have to go through the native multibyte representation and use
mbtowc/wctomb to make a proper conversion.

Signed-off-by: Samuel Thibault 
---
 ui/curses.c | 151 
 1 file changed, 94 insertions(+), 57 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index fb63945188..395f9545e9 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -400,65 +400,102 @@ static void curses_atexit(void)
 endwin();
 }
 
+/*
+ * In the following:
+ * - fch is the font glyph number
+ * - uch is the unicode value
+ * - wch is the wchar_t value (may not be unicode, e.g. on BSD/solaris)
+ * - mbch is the native local-dependent multibyte representation
+ */
+
 /* Setup wchar glyph for one UCS-2 char */
-static void convert_ucs(int glyph, uint16_t ch, iconv_t conv)
+static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *puch, *pmbch;
+size_t such, smbch;
+
+puch = (char *) 
+pmbch = (char *) mbch;
+such = sizeof(uch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from UCS-2 to a multibyte character: %s\n",
+uch, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: %s\n",
-ch, strerror(errno));
-} else {
-vga_to_curses[glyph].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to wchar_t: %s\n",
+uch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Setup wchar glyph for one font character */
-static void convert_font(unsigned char ch, iconv_t conv)
+static void convert_font(unsigned char fch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *pfch, *pmbch;
+size_t sfch, smbch;
+
+pfch = (char *) 
+pmbch = (char *) 
+sfch = sizeof(fch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from %s to a multibyte character: %s\n",
+fch, font_charset, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02x from %s to WCHAR_T: %s\n",
-ch, font_charset, strerror(errno));
-} else {
-vga_to_curses[ch].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from a multibyte character to wchar_t: %s\n",
+fch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Convert one wchar to UCS-2 */
 static uint16_t get_ucs(wchar_t wch, iconv_t conv)
 {
-uint16_t ch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
-
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02lx from WCHAR_T to UCS-2: 
%s\n",
-(unsigned long)wch, strerror(errno));
+char mbch[MB_CUR_MAX];
+uint16_t uch;
+char *pmbch, *puch;
+size_t smbch, such;
+int ret;
+
+ret = wctomb(mbch, wch);
+if (ret == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from wchar_t to a multibyte character: %s\n",
+wch, strerror(errno));
+return 0xFFFD;
+}
+
+pmbch = (char *) mbch;
+puch = (char *) 
+smbch = ret;
+such = sizeof(uch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to UCS-2 : %s\n",
+wch, strerror(errno));
 return 0xFFFD;
 }
 
-return ch;
+return uch;
 }
 
 /*
@@ -466,6 +503,11 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
  */
 static void font_setup(void)
 {
+iconv_t ucs2_to_nativecharset;
+iconv_t nativecharset_to_ucs2;
+iconv_t font_conv;
+int i;
+
 /*
  * Control characters are normally non-printable, but VGA does have
  * well-known glyphs for them.
@@ -505,30 +547,25 @@ static void font_setup(void)
   0x25bc
 };
 
-

[Qemu-devel] [PATCH] curses: do not assume wchar_t contains unicode

2019-04-27 Thread Samuel Thibault
E.g. BSD and Solaris even use locale-specific encoding there.

We thus have to go through the native multibyte representation and use
mbtowc/wctomb to make a proper conversion.

Signed-off-by: Samuel Thibault 
---
 ui/curses.c | 151 
 1 file changed, 94 insertions(+), 57 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index fb63945188..395f9545e9 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -400,65 +400,102 @@ static void curses_atexit(void)
 endwin();
 }
 
+/*
+ * In the following:
+ * - fch is the font glyph number
+ * - uch is the unicode value
+ * - wch is the wchar_t value (may not be unicode, e.g. on BSD/solaris)
+ * - mbch is the native local-dependent multibyte representation
+ */
+
 /* Setup wchar glyph for one UCS-2 char */
-static void convert_ucs(int glyph, uint16_t ch, iconv_t conv)
+static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *puch, *pmbch;
+size_t such, smbch;
+
+puch = (char *) 
+pmbch = (char *) mbch;
+such = sizeof(uch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from UCS-2 to a multibyte character: %s\n",
+uch, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: %s\n",
-ch, strerror(errno));
-} else {
-vga_to_curses[glyph].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to wchar_t: %s\n",
+uch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Setup wchar glyph for one font character */
-static void convert_font(unsigned char ch, iconv_t conv)
+static void convert_font(unsigned char fch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *pfch, *pmbch;
+size_t sfch, smbch;
+
+pfch = (char *) 
+pmbch = (char *) 
+sfch = sizeof(fch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from %s to a multibyte character: %s\n",
+fch, font_charset, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02x from %s to WCHAR_T: %s\n",
-ch, font_charset, strerror(errno));
-} else {
-vga_to_curses[ch].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from a multibyte character to wchar_t: %s\n",
+fch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Convert one wchar to UCS-2 */
 static uint16_t get_ucs(wchar_t wch, iconv_t conv)
 {
-uint16_t ch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
-
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02lx from WCHAR_T to UCS-2: 
%s\n",
-(unsigned long)wch, strerror(errno));
+char mbch[MB_CUR_MAX];
+uint16_t uch;
+char *pmbch, *puch;
+size_t smbch, such;
+int ret;
+
+ret = wctomb(mbch, wch);
+if (ret == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from wchar_t to a multibyte character: %s\n",
+wch, strerror(errno));
+return 0xFFFD;
+}
+
+pmbch = (char *) mbch;
+puch = (char *) 
+smbch = ret;
+such = sizeof(uch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to UCS-2 : %s\n",
+wch, strerror(errno));
 return 0xFFFD;
 }
 
-return ch;
+return uch;
 }
 
 /*
@@ -466,6 +503,11 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
  */
 static void font_setup(void)
 {
+iconv_t ucs2_to_nativecharset;
+iconv_t nativecharset_to_ucs2;
+iconv_t font_conv;
+int i;
+
 /*
  * Control characters are normally non-printable, but VGA does have
  * well-known glyphs for them.
@@ -505,30 +547,25 @@ static void font_setup(void)
   0x25bc
 };
 
-

[Qemu-devel] [PATCH] Makefile: Let the 'clean' rule remove qemu-ga.exe on Windows hosts

2019-04-27 Thread Philippe Mathieu-Daudé
Commit 48ff7a625b36 added the QEMU Guest Agent tool with the
optional ".exe" suffix for Windows hosts, but forgot to use
this suffix in the 'clean' rule. Calling this rule let a dangling
executable in the build directory.
Correct this by using the proper optional suffix.

Fixes: 48ff7a625b36
Signed-off-by: Philippe Mathieu-Daudé 
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 626a04d305c..07bfa26536a 100644
--- a/Makefile
+++ b/Makefile
@@ -639,7 +639,7 @@ clean:
! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll 
\
-exec rm {} +
rm -f $(edk2-decompressed)
-   rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* 
*.pod *~ */*~
+   rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga$(EXESUF) TAGS 
cscope.* *.pod *~ */*~
rm -f fsdev/*.pod scsi/*.pod
rm -f qemu-img-cmds.h
rm -f ui/shader/*-vert.h ui/shader/*-frag.h
-- 
2.20.1




[Qemu-devel] [PATCH] curses: Do not assume wchar_t contains unicode

2019-04-27 Thread Samuel Thibault
E.g. BSD and Solaris even use locale-specific encoding there.

We thus have to go through the native multibyte representation and use
mbtowc/wctomb to make a proper conversion.

Signed-off-by: Samuel Thibault 
---
 ui/curses.c | 151 
 1 file changed, 94 insertions(+), 57 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index fb63945188..395f9545e9 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -400,65 +400,102 @@ static void curses_atexit(void)
 endwin();
 }
 
+/*
+ * In the following:
+ * - fch is the font glyph number
+ * - uch is the unicode value
+ * - wch is the wchar_t value (may not be unicode, e.g. on BSD/solaris)
+ * - mbch is the native local-dependent multibyte representation
+ */
+
 /* Setup wchar glyph for one UCS-2 char */
-static void convert_ucs(int glyph, uint16_t ch, iconv_t conv)
+static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *puch, *pmbch;
+size_t such, smbch;
+
+puch = (char *) 
+pmbch = (char *) mbch;
+such = sizeof(uch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from UCS-2 to a multibyte character: %s\n",
+uch, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: %s\n",
-ch, strerror(errno));
-} else {
-vga_to_curses[glyph].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to wchar_t: %s\n",
+uch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Setup wchar glyph for one font character */
-static void convert_font(unsigned char ch, iconv_t conv)
+static void convert_font(unsigned char fch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *pfch, *pmbch;
+size_t sfch, smbch;
+
+pfch = (char *) 
+pmbch = (char *) 
+sfch = sizeof(fch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from %s to a multibyte character: %s\n",
+fch, font_charset, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02x from %s to WCHAR_T: %s\n",
-ch, font_charset, strerror(errno));
-} else {
-vga_to_curses[ch].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from a multibyte character to wchar_t: %s\n",
+fch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Convert one wchar to UCS-2 */
 static uint16_t get_ucs(wchar_t wch, iconv_t conv)
 {
-uint16_t ch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
-
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02lx from WCHAR_T to UCS-2: 
%s\n",
-(unsigned long)wch, strerror(errno));
+char mbch[MB_CUR_MAX];
+uint16_t uch;
+char *pmbch, *puch;
+size_t smbch, such;
+int ret;
+
+ret = wctomb(mbch, wch);
+if (ret == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from wchar_t to a multibyte character: %s\n",
+wch, strerror(errno));
+return 0xFFFD;
+}
+
+pmbch = (char *) mbch;
+puch = (char *) 
+smbch = ret;
+such = sizeof(uch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to UCS-2 : %s\n",
+wch, strerror(errno));
 return 0xFFFD;
 }
 
-return ch;
+return uch;
 }
 
 /*
@@ -466,6 +503,11 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
  */
 static void font_setup(void)
 {
+iconv_t ucs2_to_nativecharset;
+iconv_t nativecharset_to_ucs2;
+iconv_t font_conv;
+int i;
+
 /*
  * Control characters are normally non-printable, but VGA does have
  * well-known glyphs for them.
@@ -505,30 +547,25 @@ static void font_setup(void)
   0x25bc
 };
 
-

Re: [Qemu-devel] [PATCH] curses: Do not assume wchar_t contains unicode

2019-04-27 Thread Samuel Thibault
Ah, sorry, I missed putting v2 above and the change summary: I fixed an
uninitalized value in an error message.

Samuel

Samuel Thibault, le sam. 27 avril 2019 17:58:07 +0200, a ecrit:
> E.g. BSD and Solaris even use locale-specific encoding there.
> 
> We thus have to go through the native multibyte representation and use
> mbtowc/wctomb to make a proper conversion.
> 
> Signed-off-by: Samuel Thibault 
> ---
>  ui/curses.c | 151 
>  1 file changed, 94 insertions(+), 57 deletions(-)
> 
> diff --git a/ui/curses.c b/ui/curses.c
> index fb63945188..395f9545e9 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -400,65 +400,102 @@ static void curses_atexit(void)
>  endwin();
>  }
>  
> +/*
> + * In the following:
> + * - fch is the font glyph number
> + * - uch is the unicode value
> + * - wch is the wchar_t value (may not be unicode, e.g. on BSD/solaris)
> + * - mbch is the native local-dependent multibyte representation
> + */
> +
>  /* Setup wchar glyph for one UCS-2 char */
> -static void convert_ucs(int glyph, uint16_t ch, iconv_t conv)
> +static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
>  {
> +char mbch[MB_CUR_MAX];
>  wchar_t wch;
> -char *pch, *pwch;
> -size_t sch, swch;
> -
> -pch = (char *) 
> -pwch = (char *) 
> -sch = sizeof(ch);
> -swch = sizeof(wch);
> +char *puch, *pmbch;
> +size_t such, smbch;
> +
> +puch = (char *) 
> +pmbch = (char *) mbch;
> +such = sizeof(uch);
> +smbch = sizeof(mbch);
> +
> +if (iconv(conv, , , , ) == (size_t) -1) {
> +fprintf(stderr, "Could not convert 0x%04x "
> +"from UCS-2 to a multibyte character: %s\n",
> +uch, strerror(errno));
> +return;
> +}
>  
> -if (iconv(conv, , , , ) == (size_t) -1) {
> -fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: 
> %s\n",
> -ch, strerror(errno));
> -} else {
> -vga_to_curses[glyph].chars[0] = wch;
> +if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
> +fprintf(stderr, "Could not convert 0x%04x "
> +"from a multibyte character to wchar_t: %s\n",
> +uch, strerror(errno));
> +return;
>  }
> +vga_to_curses[fch].chars[0] = wch;
>  }
>  
>  /* Setup wchar glyph for one font character */
> -static void convert_font(unsigned char ch, iconv_t conv)
> +static void convert_font(unsigned char fch, iconv_t conv)
>  {
> +char mbch[MB_CUR_MAX];
>  wchar_t wch;
> -char *pch, *pwch;
> -size_t sch, swch;
> -
> -pch = (char *) 
> -pwch = (char *) 
> -sch = sizeof(ch);
> -swch = sizeof(wch);
> +char *pfch, *pmbch;
> +size_t sfch, smbch;
> +
> +pfch = (char *) 
> +pmbch = (char *) 
> +sfch = sizeof(fch);
> +smbch = sizeof(mbch);
> +
> +if (iconv(conv, , , , ) == (size_t) -1) {
> +fprintf(stderr, "Could not convert font glyph 0x%02x "
> +"from %s to a multibyte character: %s\n",
> +fch, font_charset, strerror(errno));
> +return;
> +}
>  
> -if (iconv(conv, , , , ) == (size_t) -1) {
> -fprintf(stderr, "Could not convert 0x%02x from %s to WCHAR_T: %s\n",
> -ch, font_charset, strerror(errno));
> -} else {
> -vga_to_curses[ch].chars[0] = wch;
> +if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
> +fprintf(stderr, "Could not convert font glyph 0x%02x "
> +"from a multibyte character to wchar_t: %s\n",
> +fch, strerror(errno));
> +return;
>  }
> +vga_to_curses[fch].chars[0] = wch;
>  }
>  
>  /* Convert one wchar to UCS-2 */
>  static uint16_t get_ucs(wchar_t wch, iconv_t conv)
>  {
> -uint16_t ch;
> -char *pch, *pwch;
> -size_t sch, swch;
> -
> -pch = (char *) 
> -pwch = (char *) 
> -sch = sizeof(ch);
> -swch = sizeof(wch);
> -
> -if (iconv(conv, , , , ) == (size_t) -1) {
> -fprintf(stderr, "Could not convert 0x%02lx from WCHAR_T to UCS-2: 
> %s\n",
> -(unsigned long)wch, strerror(errno));
> +char mbch[MB_CUR_MAX];
> +uint16_t uch;
> +char *pmbch, *puch;
> +size_t smbch, such;
> +int ret;
> +
> +ret = wctomb(mbch, wch);
> +if (ret == -1) {
> +fprintf(stderr, "Could not convert 0x%04x "
> +"from wchar_t to a multibyte character: %s\n",
> +wch, strerror(errno));
> +return 0xFFFD;
> +}
> +
> +pmbch = (char *) mbch;
> +puch = (char *) 
> +smbch = ret;
> +such = sizeof(uch);
> +
> +if (iconv(conv, , , , ) == (size_t) -1) {
> +fprintf(stderr, "Could not convert 0x%04x "
> +"from a multibyte character to UCS-2 : %s\n",
> +wch, strerror(errno));
>  

Re: [Qemu-devel] [PATCH] curses: Do not assume wchar_t contains unicode

2019-04-27 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20190427153031.5119-1-samuel.thiba...@ens-lyon.org/



Hi,

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

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1
=== TEST SCRIPT END ===

  AS  optionrom/linuxboot.o
  AS  optionrom/kvmvapic.o
  AS  optionrom/pvh.o
/tmp/qemu-test/src/ui/curses.c:482:25: error: variable 'uch' is uninitialized 
when used here [-Werror,-Wuninitialized]
uch, strerror(errno));
^~~
/tmp/qemu-test/src/ui/curses.c:473:17: note: initialize the variable 'uch' to 
silence this warning


The full log is available at
http://patchew.org/logs/20190427153031.5119-1-samuel.thiba...@ens-lyon.org/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH] hw/tpm: Only build tpm_ppi.o if any of TPM_TIS/TPM_CRB is built

2019-04-27 Thread Marc-André Lureau
Hi

On Sat, Apr 27, 2019 at 3:19 PM Philippe Mathieu-Daudé
 wrote:
>
> The TPM Physical Presence Interface routines are only used
> by the CRB/TIS interfaces. Do not compile this file if any
> of them is built.
>
> Signed-off-by: Philippe Mathieu-Daudé 

Reviewed-by: Marc-André Lureau 

> ---
> Marc-André:
>   You might want to add yourself as reviewer/maintainer of TPM ;)

yes, I suppose Stefan wouldn't mind having me as R: :)

> ---
>  hw/tpm/Makefile.objs | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs
> index 700c8786228..de0b85d02ae 100644
> --- a/hw/tpm/Makefile.objs
> +++ b/hw/tpm/Makefile.objs
> @@ -1,5 +1,5 @@
> -common-obj-y += tpm_util.o
> -obj-y += tpm_ppi.o
> +common-obj-$(CONFIG_TPM) += tpm_util.o
> +obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) += tpm_ppi.o
>  common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o
>  common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o
>  common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o
> --
> 2.20.1
>



[Qemu-devel] [PATCH] configure: Add -Wno-typedef-redefinition to CFLAGS (for Clang)

2019-04-27 Thread Thomas Huth
Without the -Wno-typedef-redefinition option, clang complains if a typedef
gets redefined in gnu99 mode (since this is officially a C11 feature). This
used to also happen with older versions of GCC, but since we've bumped our
minimum GCC version to 4.8, all versions of GCC that we support do not seem
to issue this warning in gnu99 mode anymore. So this has become a common
problem for people who only test their code with GCC - they do not notice
the issue until they submit their patches and suddenly patchew or a
maintainer complains.

Now that we do not urgently need to keep the code clean from typedef
redefintions anymore with recent versions of GCC, we can ease the
situation with clang, too, and simply shut these warnings off for good.

Signed-off-by: Thomas Huth 
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 2cc365be51..8e15dc9870 100755
--- a/configure
+++ b/configure
@@ -1917,7 +1917,7 @@ gcc_flags="-Wformat-security -Wformat-y2k -Winit-self 
-Wignored-qualifiers $gcc_
 gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
-gcc_flags="-Wno-string-plus-int $gcc_flags"
+gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
-- 
2.21.0




[Qemu-devel] [PATCH] curses: Do not assume wchar_t contains unicode

2019-04-27 Thread Samuel Thibault
E.g. BSD and Solaris even use locale-specific encoding there.

We thus have to go through the native multibyte representation and use
mbtowc/wctomb to make a proper conversion.

Signed-off-by: Samuel Thibault 
---
 ui/curses.c | 151 
 1 file changed, 94 insertions(+), 57 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index fb63945188..4414399e73 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -400,65 +400,102 @@ static void curses_atexit(void)
 endwin();
 }
 
+/*
+ * In the following:
+ * - fch is the font glyph number
+ * - uch is the unicode value
+ * - wch is the wchar_t value (may not be unicode, e.g. on BSD/solaris)
+ * - mbch is the native local-dependent multibyte representation
+ */
+
 /* Setup wchar glyph for one UCS-2 char */
-static void convert_ucs(int glyph, uint16_t ch, iconv_t conv)
+static void convert_ucs(unsigned char fch, uint16_t uch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *puch, *pmbch;
+size_t such, smbch;
+
+puch = (char *) 
+pmbch = (char *) mbch;
+such = sizeof(uch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from UCS-2 to a multibyte character: %s\n",
+uch, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: %s\n",
-ch, strerror(errno));
-} else {
-vga_to_curses[glyph].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to wchar_t: %s\n",
+uch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Setup wchar glyph for one font character */
-static void convert_font(unsigned char ch, iconv_t conv)
+static void convert_font(unsigned char fch, iconv_t conv)
 {
+char mbch[MB_CUR_MAX];
 wchar_t wch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
+char *pfch, *pmbch;
+size_t sfch, smbch;
+
+pfch = (char *) 
+pmbch = (char *) 
+sfch = sizeof(fch);
+smbch = sizeof(mbch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from %s to a multibyte character: %s\n",
+fch, font_charset, strerror(errno));
+return;
+}
 
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02x from %s to WCHAR_T: %s\n",
-ch, font_charset, strerror(errno));
-} else {
-vga_to_curses[ch].chars[0] = wch;
+if (mbtowc(, mbch, sizeof(mbch) - smbch) == -1) {
+fprintf(stderr, "Could not convert font glyph 0x%02x "
+"from a multibyte character to wchar_t: %s\n",
+fch, strerror(errno));
+return;
 }
+vga_to_curses[fch].chars[0] = wch;
 }
 
 /* Convert one wchar to UCS-2 */
 static uint16_t get_ucs(wchar_t wch, iconv_t conv)
 {
-uint16_t ch;
-char *pch, *pwch;
-size_t sch, swch;
-
-pch = (char *) 
-pwch = (char *) 
-sch = sizeof(ch);
-swch = sizeof(wch);
-
-if (iconv(conv, , , , ) == (size_t) -1) {
-fprintf(stderr, "Could not convert 0x%02lx from WCHAR_T to UCS-2: 
%s\n",
-(unsigned long)wch, strerror(errno));
+char mbch[MB_CUR_MAX];
+uint16_t uch;
+char *pmbch, *puch;
+size_t smbch, such;
+int ret;
+
+ret = wctomb(mbch, wch);
+if (ret == -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from wchar_t to a multibyte character: %s\n",
+uch, strerror(errno));
+return 0xFFFD;
+}
+
+pmbch = (char *) mbch;
+puch = (char *) 
+smbch = ret;
+such = sizeof(uch);
+
+if (iconv(conv, , , , ) == (size_t) -1) {
+fprintf(stderr, "Could not convert 0x%04x "
+"from a multibyte character to UCS-2 : %s\n",
+uch, strerror(errno));
 return 0xFFFD;
 }
 
-return ch;
+return uch;
 }
 
 /*
@@ -466,6 +503,11 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
  */
 static void font_setup(void)
 {
+iconv_t ucs2_to_nativecharset;
+iconv_t nativecharset_to_ucs2;
+iconv_t font_conv;
+int i;
+
 /*
  * Control characters are normally non-printable, but VGA does have
  * well-known glyphs for them.
@@ -505,30 +547,25 @@ static void font_setup(void)
   0x25bc
 };
 
-

Re: [Qemu-devel] [PATCH 3/3] hw/dma: Do not build the xlnx_dpdma device for the MicroBlaze machines

2019-04-27 Thread Thomas Huth
On 27/04/2019 16.14, Philippe Mathieu-Daudé wrote:
> The xlnx_dpdma device is only used by the ZynqMP AArch64 machine
> (not the MicroBlaze PMU). Remove it from the ZynqMP generic objects.
> (Note, this entry was duplicated for the AArch64).
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/dma/Makefile.objs | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/hw/dma/Makefile.objs b/hw/dma/Makefile.objs
> index 79affecc390..a5b1276f52a 100644
> --- a/hw/dma/Makefile.objs
> +++ b/hw/dma/Makefile.objs
> @@ -8,7 +8,6 @@ common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o
>  common-obj-$(CONFIG_ZYNQ_DEVCFG) += xlnx-zynq-devcfg.o
>  common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o
>  common-obj-$(CONFIG_STP2000) += sparc32_dma.o
> -obj-$(CONFIG_XLNX_ZYNQMP) += xlnx_dpdma.o
>  obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx_dpdma.o
>  common-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zdma.o
>  
> 

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH] hw/i386: The i440fx is not a machine, remove it from the machine list

2019-04-27 Thread Thomas Huth
On 27/04/2019 16.19, Philippe Mathieu-Daudé wrote:
> When building with CONFIG_ISAPC=n and CONFIG_I440FX=y we get:
> 
>   $ make subdir-x86_64-softmmu
>   [...]
>   /usr/bin/ld: hw/i386/pc_piix.o: in function `pc_init1':
>   /source/qemu/hw/i386/pc_piix.c:261: undefined reference to `isa_ide_init'
>   /usr/bin/ld: /source/qemu/hw/i386/pc_piix.c:261: undefined reference to 
> `isa_ide_init'
>   collect2: error: ld returned 1 exit status
>   make[1]: *** [Makefile:204: qemu-system-x86_64] Error 1
> 
> This is because the I440FX device is a North Bridge, not a machine.

Really? I thought CONFIG_I440FX was there to configure the
"pc-i440fx-x.y" machine types?

 Thomas



[Qemu-devel] [PATCH 2/3] hw/i386/acpi: Add object_resolve_type_unambiguous to improve modularity

2019-04-27 Thread Philippe Mathieu-Daudé
When building with CONFIG_Q35=n, we get:

LINKx86_64-softmmu/qemu-system-x86_64
  /usr/bin/ld: hw/i386/acpi-build.o: in function `acpi_get_misc_info':
  /source/qemu/hw/i386/acpi-build.c:243: undefined reference to `ich9_lpc_find'
  collect2: error: ld returned 1 exit status
  make[1]: *** [Makefile:204: qemu-system-x86_64] Error 1

This is due to a dependency in acpi-build.c on the ICH9_LPC
(via ich9_lpc_find) and PIIX4_PM (via piix4_pm_find) devices.

To allow better modularity (compile acpi-build.c with only
Q35/ICH9 or ISAPC/PIIX4), refactor the similar helper as
object_resolve_type_unambiguous(). This way we relax the
linker dependencies and can build the x86 targets with a
selection of machines (instead of all of them).

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/acpi/piix4.c | 11 ---
 hw/i386/acpi-build.c| 20 
 hw/isa/lpc_ich9.c   | 11 ---
 include/hw/acpi/piix4.h |  2 --
 include/hw/i386/ich9.h  |  2 --
 5 files changed, 16 insertions(+), 30 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 160e7308c51..c903e651695 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -552,17 +552,6 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
 piix4_pm_add_propeties(s);
 }
 
-Object *piix4_pm_find(void)
-{
-bool ambig;
-Object *o = object_resolve_path_type("", TYPE_PIIX4_PM, );
-
-if (ambig || !o) {
-return NULL;
-}
-return o;
-}
-
 I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
   qemu_irq sci_irq, qemu_irq smi_irq,
   int smm_enabled, DeviceState **piix4_pm)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 416da318ae0..123ff2b8169 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -35,6 +35,7 @@
 #include "hw/acpi/acpi-defs.h"
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/cpu.h"
+#include "hw/acpi/piix4.h"
 #include "hw/nvram/fw_cfg.h"
 #include "hw/acpi/bios-linker-loader.h"
 #include "hw/loader.h"
@@ -164,10 +165,21 @@ static void init_common_fadt_data(Object *o, AcpiFadtData 
*data)
 *data = fadt;
 }
 
+static Object *object_resolve_type_unambiguous(const char *typename)
+{
+bool ambig;
+Object *o = object_resolve_path_type("", typename, );
+
+if (ambig || !o) {
+return NULL;
+}
+return o;
+}
+
 static void acpi_get_pm_info(AcpiPmInfo *pm)
 {
-Object *piix = piix4_pm_find();
-Object *lpc = ich9_lpc_find();
+Object *piix = object_resolve_type_unambiguous(TYPE_PIIX4_PM);
+Object *lpc = object_resolve_type_unambiguous(TYPE_ICH9_LPC_DEVICE);
 Object *obj = piix ? piix : lpc;
 QObject *o;
 pm->cpu_hp_io_base = 0;
@@ -228,8 +240,8 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 
 static void acpi_get_misc_info(AcpiMiscInfo *info)
 {
-Object *piix = piix4_pm_find();
-Object *lpc = ich9_lpc_find();
+Object *piix = object_resolve_type_unambiguous(TYPE_PIIX4_PM);
+Object *lpc = object_resolve_type_unambiguous(TYPE_ICH9_LPC_DEVICE);
 assert(!!piix != !!lpc);
 
 if (piix) {
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index ac44aa53bee..031ee9cd933 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -624,17 +624,6 @@ static const MemoryRegionOps ich9_rst_cnt_ops = {
 .endianness = DEVICE_LITTLE_ENDIAN
 };
 
-Object *ich9_lpc_find(void)
-{
-bool ambig;
-Object *o = object_resolve_path_type("", TYPE_ICH9_LPC_DEVICE, );
-
-if (ambig) {
-return NULL;
-}
-return o;
-}
-
 static void ich9_lpc_get_sci_int(Object *obj, Visitor *v, const char *name,
  void *opaque, Error **errp)
 {
diff --git a/include/hw/acpi/piix4.h b/include/hw/acpi/piix4.h
index 57d7e1cda20..028bb53e3df 100644
--- a/include/hw/acpi/piix4.h
+++ b/include/hw/acpi/piix4.h
@@ -3,6 +3,4 @@
 
 #define TYPE_PIIX4_PM "PIIX4_PM"
 
-Object *piix4_pm_find(void);
-
 #endif
diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h
index 673d13d28f2..046bcf33bed 100644
--- a/include/hw/i386/ich9.h
+++ b/include/hw/i386/ich9.h
@@ -81,8 +81,6 @@ typedef struct ICH9LPCState {
 qemu_irq gsi[GSI_NUM_PINS];
 } ICH9LPCState;
 
-Object *ich9_lpc_find(void);
-
 #define Q35_MASK(bit, ms_bit, ls_bit) \
 ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1)))
 
-- 
2.20.1




[Qemu-devel] [PATCH 3/3] hw/i386/acpi: Assert a pointer is not null BEFORE using it

2019-04-27 Thread Philippe Mathieu-Daudé
Commit 72c194f7e75c added a non-null check on the 'obj' pointer.
Later, commit 500b11ea5095 added code which uses the 'obj'
pointer _before_ the assertion check. Move the assertion
_before_ the pointer use.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/i386/acpi-build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 123ff2b8169..b4ec14e349f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -186,6 +186,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 pm->pcihp_io_base = 0;
 pm->pcihp_io_len = 0;
 
+assert(obj);
 init_common_fadt_data(obj, >fadt);
 if (piix) {
 /* w2k requires FADT(rev1) or it won't boot, keep PC compatible */
@@ -204,7 +205,6 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 pm->fadt.flags |= 1 << ACPI_FADT_F_RESET_REG_SUP;
 pm->cpu_hp_io_base = ICH9_CPU_HOTPLUG_IO_BASE;
 }
-assert(obj);
 
 /* The above need not be conditional on machine type because the reset port
  * happens to be the same on PIIX (pc) and ICH9 (q35). */
-- 
2.20.1




[Qemu-devel] [PATCH 1/3] hw/acpi/piix4: Move TYPE_PIIX4_PM to a public header

2019-04-27 Thread Philippe Mathieu-Daudé
Move the TYPE_PIIX4_PM definition to the corresponding header,
so other files can use it.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/acpi/piix4.c | 2 --
 include/hw/acpi/piix4.h | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 9c079d68341..160e7308c51 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -92,8 +92,6 @@ typedef struct PIIX4PMState {
 MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
 
-#define TYPE_PIIX4_PM "PIIX4_PM"
-
 #define PIIX4_PM(obj) \
 OBJECT_CHECK(PIIX4PMState, (obj), TYPE_PIIX4_PM)
 
diff --git a/include/hw/acpi/piix4.h b/include/hw/acpi/piix4.h
index 26c2370e308..57d7e1cda20 100644
--- a/include/hw/acpi/piix4.h
+++ b/include/hw/acpi/piix4.h
@@ -1,6 +1,8 @@
 #ifndef HW_ACPI_PIIX4_H
 #define HW_ACPI_PIIX4_H
 
+#define TYPE_PIIX4_PM "PIIX4_PM"
+
 Object *piix4_pm_find(void);
 
 #endif
-- 
2.20.1




Re: [Qemu-devel] [PATCH 0/3] hw/i386/acpi: Improve build modularity (isapc/q35/...)

2019-04-27 Thread Philippe Mathieu-Daudé
On 4/27/19 4:40 PM, Philippe Mathieu-Daudé wrote:
> This series allow to build the ISAPC/Q35 machines independently.

Oops I guess I forgot:
Based-on: 20190427141905.20393-1-phi...@redhat.com
(i440fx is not a machine)
https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg04673.html

> 
> Regards,
> 
> Phil.
> 
> Philippe Mathieu-Daudé (3):
>   hw/acpi/piix4: Move TYPE_PIIX4_PM to a public header
>   hw/i386/acpi: Add object_resolve_type_unambiguous to improve
> modularity
>   hw/i386/acpi: Assert a pointer is not null BEFORE using it
> 
>  hw/acpi/piix4.c | 13 -
>  hw/i386/acpi-build.c| 22 +-
>  hw/isa/lpc_ich9.c   | 11 ---
>  include/hw/acpi/piix4.h |  2 +-
>  include/hw/i386/ich9.h  |  2 --
>  5 files changed, 18 insertions(+), 32 deletions(-)
> 



Re: [Qemu-devel] [PATCH 2/3] hw/intc: Only build the xlnx-iomod-intc device for the MicroBlaze PMU

2019-04-27 Thread Thomas Huth
On 27/04/2019 16.14, Philippe Mathieu-Daudé wrote:
> The Xilinx I/O Module Interrupt Controller is only used by the
> MicroBlaze PMU, not by the AArch64 machine.
> Move it from the generic ZynqMP object list to the PMU specific.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/intc/Makefile.objs | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs
> index df712c3e6c9..247e8016cb8 100644
> --- a/hw/intc/Makefile.objs
> +++ b/hw/intc/Makefile.objs
> @@ -3,7 +3,7 @@ common-obj-$(CONFIG_I8259) += i8259_common.o i8259.o
>  common-obj-$(CONFIG_PL190) += pl190.o
>  common-obj-$(CONFIG_PUV3) += puv3_intc.o
>  common-obj-$(CONFIG_XILINX) += xilinx_intc.o
> -common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-pmu-iomod-intc.o
> +common-obj-$(CONFIG_XLNX_ZYNQMP_PMU) += xlnx-pmu-iomod-intc.o
>  common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-ipi.o
>  common-obj-$(CONFIG_ETRAXFS) += etraxfs_pic.o
>  common-obj-$(CONFIG_IMX) += imx_avic.o imx_gpcv2.o
> 

Reviewed-by: Thomas Huth 



[Qemu-devel] [PATCH 0/3] hw/i386/acpi: Improve build modularity (isapc/q35/...)

2019-04-27 Thread Philippe Mathieu-Daudé
This series allow to build the ISAPC/Q35 machines independently.

Regards,

Phil.

Philippe Mathieu-Daudé (3):
  hw/acpi/piix4: Move TYPE_PIIX4_PM to a public header
  hw/i386/acpi: Add object_resolve_type_unambiguous to improve
modularity
  hw/i386/acpi: Assert a pointer is not null BEFORE using it

 hw/acpi/piix4.c | 13 -
 hw/i386/acpi-build.c| 22 +-
 hw/isa/lpc_ich9.c   | 11 ---
 include/hw/acpi/piix4.h |  2 +-
 include/hw/i386/ich9.h  |  2 --
 5 files changed, 18 insertions(+), 32 deletions(-)

-- 
2.20.1




[Qemu-devel] [PATCH] hw/i386: The i440fx is not a machine, remove it from the machine list

2019-04-27 Thread Philippe Mathieu-Daudé
When building with CONFIG_ISAPC=n and CONFIG_I440FX=y we get:

  $ make subdir-x86_64-softmmu
  [...]
  /usr/bin/ld: hw/i386/pc_piix.o: in function `pc_init1':
  /source/qemu/hw/i386/pc_piix.c:261: undefined reference to `isa_ide_init'
  /usr/bin/ld: /source/qemu/hw/i386/pc_piix.c:261: undefined reference to 
`isa_ide_init'
  collect2: error: ld returned 1 exit status
  make[1]: *** [Makefile:204: qemu-system-x86_64] Error 1

This is because the I440FX device is a North Bridge, not a machine.
It is however used by the ISAPC machine.

Correct the dependency in the ISAPC Kconfig.

Signed-off-by: Philippe Mathieu-Daudé 
---
 default-configs/i386-softmmu.mak | 1 -
 hw/i386/Kconfig  | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index ba3fb3ff50a..b33f5952128 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -23,5 +23,4 @@
 # Boards:
 #
 CONFIG_ISAPC=y
-CONFIG_I440FX=y
 CONFIG_Q35=y
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index a6aed7c1313..9211adf2bb3 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -69,7 +69,7 @@ config ISAPC
 select VGA_ISA
 # FIXME: it is in the same file as i440fx, and does not compile
 # if separated
-depends on I440FX
+select I440FX
 
 config Q35
 bool
-- 
2.20.1




[Qemu-devel] [PATCH 2/3] hw/intc: Only build the xlnx-iomod-intc device for the MicroBlaze PMU

2019-04-27 Thread Philippe Mathieu-Daudé
The Xilinx I/O Module Interrupt Controller is only used by the
MicroBlaze PMU, not by the AArch64 machine.
Move it from the generic ZynqMP object list to the PMU specific.

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

diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs
index df712c3e6c9..247e8016cb8 100644
--- a/hw/intc/Makefile.objs
+++ b/hw/intc/Makefile.objs
@@ -3,7 +3,7 @@ common-obj-$(CONFIG_I8259) += i8259_common.o i8259.o
 common-obj-$(CONFIG_PL190) += pl190.o
 common-obj-$(CONFIG_PUV3) += puv3_intc.o
 common-obj-$(CONFIG_XILINX) += xilinx_intc.o
-common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-pmu-iomod-intc.o
+common-obj-$(CONFIG_XLNX_ZYNQMP_PMU) += xlnx-pmu-iomod-intc.o
 common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-ipi.o
 common-obj-$(CONFIG_ETRAXFS) += etraxfs_pic.o
 common-obj-$(CONFIG_IMX) += imx_avic.o imx_gpcv2.o
-- 
2.20.1




[Qemu-devel] [PATCH 1/3] hw/Kconfig: Move the generic XLNX_ZYNQMP to the root hw/Kconfig

2019-04-27 Thread Philippe Mathieu-Daudé
The XLNX_ZYNQMP config is used in multiple subdirectories
(timer, intc). Move it to the root hw/Kconfig.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/Kconfig   | 3 +++
 hw/timer/Kconfig | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/Kconfig b/hw/Kconfig
index 88b9f150070..c3c78f43eb5 100644
--- a/hw/Kconfig
+++ b/hw/Kconfig
@@ -72,3 +72,6 @@ config XILINX
 config XILINX_AXI
 bool
 select PTIMER # for hw/dma/xilinx_axidma.c
+
+config XLNX_ZYNQMP
+bool
diff --git a/hw/timer/Kconfig b/hw/timer/Kconfig
index 51921eb63f1..eefc95f35ec 100644
--- a/hw/timer/Kconfig
+++ b/hw/timer/Kconfig
@@ -34,9 +34,6 @@ config TWL92230
 bool
 depends on I2C
 
-config XLNX_ZYNQMP
-bool
-
 config ALTERA_TIMER
 bool
 select PTIMER
-- 
2.20.1




[Qemu-devel] [PATCH 0/3] hw/microblaze: Kconfig cleanup

2019-04-27 Thread Philippe Mathieu-Daudé
Hi Edgar, Peter,

Few fixes while cleaning Kconfig, trying to optimize builds.

Regards,

Phil.

Philippe Mathieu-Daudé (3):
  hw/Kconfig: Move the generic XLNX_ZYNQMP to the root hw/Kconfig
  hw/intc: Only build the xlnx-iomod-intc device for the MicroBlaze PMU
  hw/dma: Do not build the xlnx_dpdma device for the MicroBlaze machines

 hw/Kconfig| 3 +++
 hw/dma/Makefile.objs  | 1 -
 hw/intc/Makefile.objs | 2 +-
 hw/timer/Kconfig  | 3 ---
 4 files changed, 4 insertions(+), 5 deletions(-)

-- 
2.20.1




[Qemu-devel] [PATCH 3/3] hw/dma: Do not build the xlnx_dpdma device for the MicroBlaze machines

2019-04-27 Thread Philippe Mathieu-Daudé
The xlnx_dpdma device is only used by the ZynqMP AArch64 machine
(not the MicroBlaze PMU). Remove it from the ZynqMP generic objects.
(Note, this entry was duplicated for the AArch64).

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/dma/Makefile.objs | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/dma/Makefile.objs b/hw/dma/Makefile.objs
index 79affecc390..a5b1276f52a 100644
--- a/hw/dma/Makefile.objs
+++ b/hw/dma/Makefile.objs
@@ -8,7 +8,6 @@ common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o
 common-obj-$(CONFIG_ZYNQ_DEVCFG) += xlnx-zynq-devcfg.o
 common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o
 common-obj-$(CONFIG_STP2000) += sparc32_dma.o
-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx_dpdma.o
 obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx_dpdma.o
 common-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zdma.o
 
-- 
2.20.1




[Qemu-devel] [PATCH] qom/object: Display more helpful message when an object type is missing

2019-04-27 Thread Philippe Mathieu-Daudé
When writing a new board, adding device which uses other devices
(container) or simply refactoring, one can discover the hard way
his machine misses some devices. In the case of containers, the
error is not obvious:

  $ qemu-system-microblaze -M xlnx-zynqmp-pmu
  **
  ERROR:/source/qemu/qom/object.c:454:object_initialize_with_type: assertion 
failed: (type != NULL)
  Aborted (core dumped)

And we have to look at the coredump to figure the error:

  (gdb) bt
  #1  0x7f84773cf895 in abort () at /lib64/libc.so.6
  #2  0x7f847961fb53 in  () at /lib64/libglib-2.0.so.0
  #3  0x7f847967a4de in g_assertion_message_expr () at 
/lib64/libglib-2.0.so.0
  #4  0x55c4bcac6c11 in object_initialize_with_type 
(data=data@entry=0x55c4bdf239e0, size=size@entry=2464, type=) at 
/source/qemu/qom/object.c:454
  #5  0x55c4bcac6e6d in object_initialize (data=data@entry=0x55c4bdf239e0, 
size=size@entry=2464, typename=typename@entry=0x55c4bcc7c643 "xlnx.zynqmp_ipi") 
at /source/qemu/qom/object.c:474
  #6  0x55c4bc9ea474 in xlnx_zynqmp_pmu_init (machine=0x55c4bdd46000) at 
/source/qemu/hw/microblaze/xlnx-zynqmp-pmu.c:176
  #7  0x55c4bca3b6cb in machine_run_board_init (machine=0x55c4bdd46000) at 
/source/qemu/hw/core/machine.c:1030
  #8  0x55c4bc95f6d2 in main (argc=, argv=, 
envp=) at /source/qemu/vl.c:4479

Since the caller knows the type name requested, we can simply display it
to ease development.

With this patch applied we get:

  $ qemu-system-microblaze -M xlnx-zynqmp-pmu
  qemu-system-microblaze: missing object type 'xlnx.zynqmp_ipi'
  Aborted (core dumped)

Since the assert(type) check in object_initialize_with_type() is
now impossible, remove it.

Signed-off-by: Philippe Mathieu-Daudé 
---
 qom/object.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/qom/object.c b/qom/object.c
index e3206d6799e..b1ba62c5b9e 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -28,6 +28,7 @@
 #include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qnum.h"
 #include "qapi/qmp/qstring.h"
+#include "qemu/error-report.h"
 
 #define MAX_INTERFACES 32
 
@@ -451,7 +452,6 @@ static void object_initialize_with_type(void *data, size_t 
size, TypeImpl *type)
 {
 Object *obj = data;
 
-g_assert(type != NULL);
 type_initialize(type);
 
 g_assert(type->instance_size >= sizeof(Object));
@@ -471,6 +471,11 @@ void object_initialize(void *data, size_t size, const char 
*typename)
 {
 TypeImpl *type = type_get_by_name(typename);
 
+if (!type) {
+error_report("missing object type '%s'", typename);
+abort();
+}
+
 object_initialize_with_type(data, size, type);
 }
 
-- 
2.20.1




[Qemu-devel] [PATCH] hw/dma: Compile the bcm2835_dma device as common object

2019-04-27 Thread Philippe Mathieu-Daudé
This device is used by both ARM (BCM2836, for raspi2) and AArch64
(BCM2837, for raspi3) targets, and is not CPU-specific.
Move it to common object, so we build it once for all targets.

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

diff --git a/hw/dma/Makefile.objs b/hw/dma/Makefile.objs
index 79affecc390..8b39f9c6004 100644
--- a/hw/dma/Makefile.objs
+++ b/hw/dma/Makefile.objs
@@ -14,4 +14,4 @@ common-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zdma.o
 
 obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o
 obj-$(CONFIG_PXA2XX) += pxa2xx_dma.o
-obj-$(CONFIG_RASPI) += bcm2835_dma.o
+common-obj-$(CONFIG_RASPI) += bcm2835_dma.o
-- 
2.20.1




[Qemu-devel] [PATCH] hw/tpm: Only build tpm_ppi.o if any of TPM_TIS/TPM_CRB is built

2019-04-27 Thread Philippe Mathieu-Daudé
The TPM Physical Presence Interface routines are only used
by the CRB/TIS interfaces. Do not compile this file if any
of them is built.

Signed-off-by: Philippe Mathieu-Daudé 
---
Marc-André:
  You might want to add yourself as reviewer/maintainer of TPM ;)
---
 hw/tpm/Makefile.objs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs
index 700c8786228..de0b85d02ae 100644
--- a/hw/tpm/Makefile.objs
+++ b/hw/tpm/Makefile.objs
@@ -1,5 +1,5 @@
-common-obj-y += tpm_util.o
-obj-y += tpm_ppi.o
+common-obj-$(CONFIG_TPM) += tpm_util.o
+obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) += tpm_ppi.o
 common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o
 common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o
 common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o
-- 
2.20.1




Re: [Qemu-devel] [PATCH 1/2] target/alpha: Clean up alpha_cpu_dump_state

2019-04-27 Thread Philippe Mathieu-Daudé
On 4/27/19 2:51 AM, Richard Henderson wrote:
> Drop the "RI" and "FIR" prefixes; use only the normal linux names.
> Add the FPCR to the dump.
> 
> Signed-off-by: Richard Henderson 
> ---
>  target/alpha/helper.c | 19 ++-
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/target/alpha/helper.c b/target/alpha/helper.c
> index 7201576aae..31de9593b6 100644
> --- a/target/alpha/helper.c
> +++ b/target/alpha/helper.c
> @@ -429,32 +429,33 @@ bool alpha_cpu_exec_interrupt(CPUState *cs, int 
> interrupt_request)
>  
>  void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags)
>  {
> -static const char *linux_reg_names[] = {
> -"v0 ", "t0 ", "t1 ", "t2 ", "t3 ", "t4 ", "t5 ", "t6 ",
> -"t7 ", "s0 ", "s1 ", "s2 ", "s3 ", "s4 ", "s5 ", "fp ",
> -"a0 ", "a1 ", "a2 ", "a3 ", "a4 ", "a5 ", "t8 ", "t9 ",
> -"t10", "t11", "ra ", "t12", "at ", "gp ", "sp ", "zero",
> +static const char linux_reg_names[31][4] = {
> +"v0",  "t0",  "t1", "t2",  "t3", "t4", "t5", "t6",
> +"t7",  "s0",  "s1", "s2",  "s3", "s4", "s5", "fp",
> +"a0",  "a1",  "a2", "a3",  "a4", "a5", "t8", "t9",
> +"t10", "t11", "ra", "t12", "at", "gp", "sp"
>  };
>  AlphaCPU *cpu = ALPHA_CPU(cs);
>  CPUAlphaState *env = >env;
>  int i;
>  
> -qemu_fprintf(f, " PC  " TARGET_FMT_lx "  PS  %02x\n",
> +qemu_fprintf(f, "PC  " TARGET_FMT_lx " PS  %02x\n",
>   env->pc, extract32(env->flags, ENV_FLAG_PS_SHIFT, 8));
>  for (i = 0; i < 31; i++) {
> -qemu_fprintf(f, "IR%02d %s " TARGET_FMT_lx "%c", i,
> +qemu_fprintf(f, "%-8s" TARGET_FMT_lx "%c",

I often wondered was this useful for (I mean, one would focus on one or
another, but having both displayed was not helpful IMO). Now the output
looks clearer, thanks!

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

>   linux_reg_names[i], cpu_alpha_load_gr(env, i),
>   (i % 3) == 2 ? '\n' : ' ');
>  }
>  
> -qemu_fprintf(f, "lock_a   " TARGET_FMT_lx " lock_v   " TARGET_FMT_lx 
> "\n",
> +qemu_fprintf(f, "lock_a  " TARGET_FMT_lx " lock_v  " TARGET_FMT_lx "\n",
>   env->lock_addr, env->lock_value);
>  
>  if (flags & CPU_DUMP_FPU) {
>  for (i = 0; i < 31; i++) {
> -qemu_fprintf(f, "FIR%02d%016" PRIx64 "%c", i, env->fir[i],
> +qemu_fprintf(f, "f%-7d%016" PRIx64 "%c", i, env->fir[i],
>   (i % 3) == 2 ? '\n' : ' ');
>  }
> +qemu_fprintf(f, "fpcr%016" PRIx64 "\n", 
> cpu_alpha_load_fpcr(env));
>  }
>  qemu_fprintf(f, "\n");
>  }
> 



Re: [Qemu-devel] [Qemu-block] [PATCH] block/rbd: add preallocation support

2019-04-27 Thread Jason Dillaman
On Sat, Apr 27, 2019 at 7:37 AM Stefano Garzarella  wrote:
>
> This patch adds the support of preallocation (off/full) for the RBD
> block driver.
> If available, we use rbd_writesame() to quickly fill the image when
> full preallocation is required.
>
> Signed-off-by: Stefano Garzarella 
> ---
>  block/rbd.c  | 149 ++-
>  qapi/block-core.json |   4 +-
>  2 files changed, 136 insertions(+), 17 deletions(-)
>
> diff --git a/block/rbd.c b/block/rbd.c
> index 0c549c9935..29dd1bb040 100644
> --- a/block/rbd.c
> +++ b/block/rbd.c
> @@ -13,6 +13,7 @@
>
>  #include "qemu/osdep.h"
>
> +#include "qemu/units.h"
>  #include 
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
> @@ -331,6 +332,110 @@ static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs)
>  }
>  }
>
> +static int qemu_rbd_do_truncate(rbd_image_t image, int64_t offset,
> +PreallocMode prealloc, Error **errp)
> +{
> +uint64_t current_length;
> +char *buf = NULL;
> +int ret;
> +
> +ret = rbd_get_size(image, _length);
> +if (ret < 0) {
> +error_setg_errno(errp, -ret, "Failed to get file length");
> +goto out;
> +}
> +
> +if (current_length > offset && prealloc != PREALLOC_MODE_OFF) {
> +error_setg(errp, "Cannot use preallocation for shrinking files");
> +ret = -ENOTSUP;
> +goto out;
> +}
> +
> +switch (prealloc) {
> +case PREALLOC_MODE_FULL: {
> +uint64_t current_offset = current_length;
> +int buf_size = 64 * KiB;

This should probably be 512B or 4KiB (which is the smallest striped
unit size). Not only will this avoid sending unnecessary zeroes to the
backing cluster, writesame silently turns into a standard write if
your buffer isn't properly aligned with the min(object size, stripe
unit size).

> +ssize_t bytes;
> +
> +buf = g_malloc(buf_size);
> +/*
> + * Some versions of rbd_writesame() discards writes of buffers with
> + * all zeroes. In order to avoid this behaviour, we set the first 
> byte
> + * to one.
> + */
> +buf[0] = 1;

You could also use "rados_conf_set(cluster,
"rbd_discard_on_zeroed_write_same", "false").

> +ret = rbd_resize(image, offset);
> +if (ret < 0) {
> +error_setg_errno(errp, -ret, "Failed to resize file");
> +goto out;
> +}
> +
> +#ifdef LIBRBD_SUPPORTS_WRITESAME
> +while (offset - current_offset > buf_size) {
> +/*
> + * rbd_writesame() supports only request where the size of the
> + * operation is multiple of buffer size and it must be less or
> + * equal to INT_MAX.
> + */
> +bytes = MIN(offset - current_offset, INT_MAX);
> +bytes -= bytes % buf_size;

Using the default object size of 4MiB, this write size would result in
up to 512 concurrent ops to the backing cluster. Perhaps the size
should be bounded such that only a dozen or so concurrent requests are
issued per write, always rounded next largest object / stripe period
size. librbd and the rbd CLI usually try to bound themselves to the
value in the "rbd_concurrent_management_ops" configuration setting
(currently defaults to 10).

> +bytes = rbd_writesame(image, current_offset, bytes, buf, 
> buf_size,
> +  0);
> +if (bytes < 0) {
> +ret = bytes;
> +error_setg_errno(errp, -ret,
> + "Failed to write for preallocation");
> +goto out;
> +}
> +
> +current_offset += bytes;
> +}
> +#endif /* LIBRBD_SUPPORTS_WRITESAME */
> +
> +while (current_offset < offset) {
> +bytes = rbd_write(image, current_offset,
> +  MIN(offset - current_offset, buf_size), buf);
> +if (bytes < 0) {
> +ret = bytes;
> +error_setg_errno(errp, -ret,
> + "Failed to write for preallocation");
> +goto out;
> +}
> +
> +current_offset += bytes;
> +}
> +
> +ret = rbd_flush(image);
> +if (ret < 0) {
> +error_setg_errno(errp, -ret, "Failed to flush the file");
> +goto out;
> +}
> +
> +break;
> +}
> +case PREALLOC_MODE_OFF:
> +ret = rbd_resize(image, offset);
> +if (ret < 0) {
> +error_setg_errno(errp, -ret, "Failed to resize file");
> +goto out;
> +}
> +break;
> +default:
> +error_setg(errp, "Unsupported preallocation mode: %s",
> +   PreallocMode_str(prealloc));
> +ret = -ENOTSUP;
> +goto out;
> +}
> +
> +ret = 0;
> +
> +out:
> +g_free(buf);
> +return ret;
> +}
> +
>  static QemuOptsList runtime_opts = {
>  

[Qemu-devel] [PATCH] block/rbd: add preallocation support

2019-04-27 Thread Stefano Garzarella
This patch adds the support of preallocation (off/full) for the RBD
block driver.
If available, we use rbd_writesame() to quickly fill the image when
full preallocation is required.

Signed-off-by: Stefano Garzarella 
---
 block/rbd.c  | 149 ++-
 qapi/block-core.json |   4 +-
 2 files changed, 136 insertions(+), 17 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index 0c549c9935..29dd1bb040 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 
+#include "qemu/units.h"
 #include 
 #include "qapi/error.h"
 #include "qemu/error-report.h"
@@ -331,6 +332,110 @@ static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs)
 }
 }
 
+static int qemu_rbd_do_truncate(rbd_image_t image, int64_t offset,
+PreallocMode prealloc, Error **errp)
+{
+uint64_t current_length;
+char *buf = NULL;
+int ret;
+
+ret = rbd_get_size(image, _length);
+if (ret < 0) {
+error_setg_errno(errp, -ret, "Failed to get file length");
+goto out;
+}
+
+if (current_length > offset && prealloc != PREALLOC_MODE_OFF) {
+error_setg(errp, "Cannot use preallocation for shrinking files");
+ret = -ENOTSUP;
+goto out;
+}
+
+switch (prealloc) {
+case PREALLOC_MODE_FULL: {
+uint64_t current_offset = current_length;
+int buf_size = 64 * KiB;
+ssize_t bytes;
+
+buf = g_malloc(buf_size);
+/*
+ * Some versions of rbd_writesame() discards writes of buffers with
+ * all zeroes. In order to avoid this behaviour, we set the first byte
+ * to one.
+ */
+buf[0] = 1;
+
+ret = rbd_resize(image, offset);
+if (ret < 0) {
+error_setg_errno(errp, -ret, "Failed to resize file");
+goto out;
+}
+
+#ifdef LIBRBD_SUPPORTS_WRITESAME
+while (offset - current_offset > buf_size) {
+/*
+ * rbd_writesame() supports only request where the size of the
+ * operation is multiple of buffer size and it must be less or
+ * equal to INT_MAX.
+ */
+bytes = MIN(offset - current_offset, INT_MAX);
+bytes -= bytes % buf_size;
+
+bytes = rbd_writesame(image, current_offset, bytes, buf, buf_size,
+  0);
+if (bytes < 0) {
+ret = bytes;
+error_setg_errno(errp, -ret,
+ "Failed to write for preallocation");
+goto out;
+}
+
+current_offset += bytes;
+}
+#endif /* LIBRBD_SUPPORTS_WRITESAME */
+
+while (current_offset < offset) {
+bytes = rbd_write(image, current_offset,
+  MIN(offset - current_offset, buf_size), buf);
+if (bytes < 0) {
+ret = bytes;
+error_setg_errno(errp, -ret,
+ "Failed to write for preallocation");
+goto out;
+}
+
+current_offset += bytes;
+}
+
+ret = rbd_flush(image);
+if (ret < 0) {
+error_setg_errno(errp, -ret, "Failed to flush the file");
+goto out;
+}
+
+break;
+}
+case PREALLOC_MODE_OFF:
+ret = rbd_resize(image, offset);
+if (ret < 0) {
+error_setg_errno(errp, -ret, "Failed to resize file");
+goto out;
+}
+break;
+default:
+error_setg(errp, "Unsupported preallocation mode: %s",
+   PreallocMode_str(prealloc));
+ret = -ENOTSUP;
+goto out;
+}
+
+ret = 0;
+
+out:
+g_free(buf);
+return ret;
+}
+
 static QemuOptsList runtime_opts = {
 .name = "rbd",
 .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
@@ -376,6 +481,7 @@ static int qemu_rbd_do_create(BlockdevCreateOptions 
*options,
 BlockdevCreateOptionsRbd *opts = >u.rbd;
 rados_t cluster;
 rados_ioctx_t io_ctx;
+rbd_image_t image;
 int obj_order = 0;
 int ret;
 
@@ -404,13 +510,21 @@ static int qemu_rbd_do_create(BlockdevCreateOptions 
*options,
 return ret;
 }
 
-ret = rbd_create(io_ctx, opts->location->image, opts->size, _order);
+ret = rbd_create(io_ctx, opts->location->image, 0, _order);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "error rbd create");
 goto out;
 }
 
-ret = 0;
+ret = rbd_open(io_ctx, opts->location->image, , NULL);
+if (ret < 0) {
+error_setg_errno(errp, -ret, "error rbd open");
+goto out;
+}
+
+ret = qemu_rbd_do_truncate(image, opts->size, opts->preallocation, errp);
+
+rbd_close(image);
 out:
 rados_ioctx_destroy(io_ctx);
 rados_shutdown(cluster);
@@ -431,6 +545,7 @@ static int coroutine_fn qemu_rbd_co_create_opts(const char 
*filename,
 BlockdevOptionsRbd 

Re: [Qemu-devel] [PATCH v2 1/3] q35: set split kernel irqchip as default

2019-04-27 Thread Paolo Bonzini
On 27/04/19 07:29, Paolo Bonzini wrote:
> 
>>> In my testing it looks like KVM advertises supporting the KVM_IRQFD
>>> resample feature, but vfio never gets the unmask notification, so the
>>> device remains with DisINTx set and no further interrupts are
>>> generated.  Do we expect KVM's IRQFD with resampler to work in the
>>> split IRQ mode?  We can certainly hope that "high performance" devices
>>> use MSI or MSI/X, but this would be quite a performance regression with
>>> split mode if our userspace bypass for INTx goes away.  Thanks,
>>
>> arch/x86/kvm/lapic.c:kvm_ioapic_send_eoi() dumps to userspace before
>> kvm_ioapic_update_eoi() can handle the irq_ack_notifier_list via
>> kvm_notify_acked_gsi(),
> 
> That wouldn't help because kvm_ioapic_update_eoi would not even be
> able to access vcpu->kvm->arch.vioapic (it's NULL).
> 
> The following untested patch would signal the resamplefd in 
> kvm_ioapic_send_eoi,
> before requesting the exit to userspace.  However I am not sure how QEMU
> sets up the VFIO eventfds: if I understand correctly, when VFIO writes again 
> to
> the irq eventfd, the interrupt request would not reach the userspace IOAPIC, 
> but
> only the in-kernel LAPIC.  That would be incorrect, and if my understanding is
> correct we need to trigger resampling from hw/intc/ioapic.c.

Actually it's worse: because you're bypassing IOAPIC when raising the
irq, the IOAPIC's remote_irr for example will not be set.  So split
irqchip currently must disable the intx fast path completely.

I guess we could also reimplement irqfd and resamplefd in the userspace
IOAPIC, and run the listener in a separate thread (using "-object
iothread" on the command line and AioContext in the code).

Paolo

> 
> Something like:
> 
> 1) VFIO uses kvm_irqchip_add_irqfd_notifier_gsi instead of KVM_IRQFD directly
> 
> 2) add a NotifierList in kvm_irqchip_assign_irqfd
> 
> 3) if kvm_irqchip_is_split(), register a corresponding Notifier in ioapic.c 
> which
> stores the resamplefd as an EventNotifier*
> 
> 4) ioapic_eoi_broadcast writes to the resamplefd
> 
> BTW, how do non-x86 platforms handle intx resampling?
> 
> Paolo
> 
>  8< -
> From: Paolo Bonzini 
> Subject: [PATCH WIP] kvm: lapic: run ack notifiers for userspace IOAPIC routes
> 
> diff --git a/arch/x86/kvm/ioapic.h b/arch/x86/kvm/ioapic.h
> index ea1a4e0297da..be337e06e3fd 100644
> --- a/arch/x86/kvm/ioapic.h
> +++ b/arch/x86/kvm/ioapic.h
> @@ -135,4 +135,6 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu,
>  ulong *ioapic_handled_vectors);
>  void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu,
>   ulong *ioapic_handled_vectors);
> +void kvm_notify_userspace_ioapic_routes(struct kvm *kvm, int vector);
> +
>  #endif
> diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
> index 3cc3b2d130a0..46ea79a0dd8a 100644
> --- a/arch/x86/kvm/irq_comm.c
> +++ b/arch/x86/kvm/irq_comm.c
> @@ -435,6 +435,34 @@ void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu,
>   srcu_read_unlock(>irq_srcu, idx);
>  }
>  
> +void kvm_notify_userspace_ioapic_routes(struct kvm *kvm, int vector)
> +{
> +struct kvm_kernel_irq_routing_entry *entry;
> +struct kvm_irq_routing_table *table;
> +u32 i, nr_ioapic_pins;
> +int idx;
> +
> +idx = srcu_read_lock(>irq_srcu);
> +table = srcu_dereference(kvm->irq_routing, >irq_srcu);
> +nr_ioapic_pins = min_t(u32, table->nr_rt_entries,
> +   kvm->arch.nr_reserved_ioapic_pins);
> +
> + for (i = 0; i < nr_ioapic_pins; i++) {
> +hlist_for_each_entry(entry, >map[i], link) {
> +struct kvm_lapic_irq irq;
> +
> +if (entry->type != KVM_IRQ_ROUTING_MSI)
> +continue;
> +
> + kvm_set_msi_irq(kvm, entry, );
> + if (irq.level && irq.vector == vector)
> + kvm_notify_acked_gsi(kvm, i);
> + }
> + }
> +
> + srcu_read_unlock(>irq_srcu, idx);
> +}
> +
>  void kvm_arch_irq_routing_update(struct kvm *kvm)
>  {
>   kvm_hv_irq_routing_update(kvm);
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 9f089e2e09d0..8f8e76d77925 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1142,6 +1142,7 @@ static bool kvm_ioapic_handles_vector(struct kvm_lapic 
> *apic, int vector)
>  
>  static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)
>  {
> + struct kvm_vcpu *vcpu = apic->vcpu;
>   int trigger_mode;
>  
>   /* Eoi the ioapic only if the ioapic doesn't own the vector. */
> @@ -1149,9 +1150,10 @@ static void kvm_ioapic_send_eoi(struct kvm_lapic 
> *apic, int vector)
>   return;
>  
>   /* Request a KVM exit to inform the userspace IOAPIC. */
> - if (irqchip_split(apic->vcpu->kvm)) {
> - apic->vcpu->arch.pending_ioapic_eoi = vector;
> -