Skip to contentSkip to conversation

ioreq: Support 32-bit default_ioport_* accesses

PATCH In review Boris Ostrovsky 4 participants 16 messages May 20, 2016 – May 26, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ioreq: Support 32-bit default_ioport_* accesses

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

QEMU needs to be able to handle them.

---
 vl.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
vl.c +8 -7
index c864e7d..79d3ab5 100644
@@ -350,17 +350,18 @@ static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
 
 static uint32_t default_ioport_readl(void *opaque, uint32_t address)
 {
-#ifdef DEBUG_UNUSED_IOPORT
-    fprintf(stderr, "unused inl: port=0x%04x\n", address);
-#endif
-    return 0xffffffff;
+    uint32_t data;
+    data = default_ioport_readw(opaque, address) & 0xffff;
+    address = (address + 2) & (MAX_IOPORTS - 1);
+    data |= default_ioport_readw(opaque, address) << 16;
+    return data;
 }
 
 static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data)
 {
-#ifdef DEBUG_UNUSED_IOPORT
-    fprintf(stderr, "unused outl: port=0x%04x data=0x%02x\n", address, data);
-#endif
+    default_ioport_writew(opaque, address, data & 0xffff);
+    address = (address + 2) & (MAX_IOPORTS - 1);
+    default_ioport_writew(opaque, address, data >> 16);
 }
 
 /* size is the word size in byte */
Signature · 7 lines
1.8.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw
Quoted 16 lines · Boris Ostrovsky

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

QEMU needs to be able to handle them.

---
 vl.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
vl.c +0 -0
index c864e7d..79d3ab5 100644

vl.c static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) · line 355

Quoted 10 lines
vl.c +3 -4
@@ -350,17 +350,18 @@ static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
 
 static uint32_t default_ioport_readl(void *opaque, uint32_t address)
 {
-#ifdef DEBUG_UNUSED_IOPORT
-    fprintf(stderr, "unused inl: port=0x%04x\n", address);
-#endif
-    return 0xffffffff;
+    uint32_t data;
+    data = default_ioport_readw(opaque, address) & 0xffff;
+    address = (address + 2) & (MAX_IOPORTS - 1);

I'm not very familiar with how hardware behaves, but shouldn't we return some sort of invalid result (~0) and log when the port wraps?

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 18 lines · Wei Liu
Quoted 17 lines · Boris Ostrovsky

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

QEMU needs to be able to handle them.

---
 vl.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
vl.c +0 -0
index c864e7d..79d3ab5 100644
@@ -350,17 +350,18 @@ static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
 
Quoted 11 lines

vl.c static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) · line 355

Quoted 9 lines
vl.c +3 -4
 static uint32_t default_ioport_readl(void *opaque, uint32_t address)
 {
-#ifdef DEBUG_UNUSED_IOPORT
-    fprintf(stderr, "unused inl: port=0x%04x\n", address);
-#endif
-    return 0xffffffff;
+    uint32_t data;
+    data = default_ioport_readw(opaque, address) & 0xffff;
+    address = (address + 2) & (MAX_IOPORTS - 1);

I'm not very familiar with how hardware behaves, but shouldn't we return some sort of invalid result (~0) and log when the port wraps?

Intel SDM says that trying to access ports beyond 0xffff is implementation-specific. So wrapping them I guess is valid (it's how qemu implements it for default_ioport_readw/writew, which is what I am following here).

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 31 lines · Boris Ostrovsky
Quoted 18 lines · Wei Liu
Quoted 17 lines · Boris Ostrovsky

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

QEMU needs to be able to handle them.

---
 vl.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
vl.c +0 -0
index c864e7d..79d3ab5 100644
@@ -350,17 +350,18 @@ static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
 
Quoted 11 lines

vl.c static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) · line 355

Quoted 9 lines
vl.c +3 -4
 static uint32_t default_ioport_readl(void *opaque, uint32_t address)
 {
-#ifdef DEBUG_UNUSED_IOPORT
-    fprintf(stderr, "unused inl: port=0x%04x\n", address);
-#endif
-    return 0xffffffff;
+    uint32_t data;
+    data = default_ioport_readw(opaque, address) & 0xffff;
+    address = (address + 2) & (MAX_IOPORTS - 1);

I'm not very familiar with how hardware behaves, but shouldn't we return some sort of invalid result (~0) and log when the port wraps?

Quoted 5 lines

Intel SDM says that trying to access ports beyond 0xffff is implementation-specific. So wrapping them I guess is valid (it's how qemu implements it for default_ioport_readw/writew, which is what I am following here).

Fair enough.

Wei.

Quoted 3 lines

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#4 lore raw
In reply to Boris Ostrovsky
Quoted 7 lines · Boris Ostrovsky

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

QEMU needs to be able to handle them.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
In reply to Boris Ostrovsky

Boris Ostrovsky writes ("[PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 5 lines

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

QEMU needs to be able to handle them.

I'm kind of missing something here. If the specification has recently been updated to permit this, why should old hardware support it ?

(I tried to find the Linux upstream git commit you're referring to but my linux.git is up to date and it seems not to be fetching within a reasonable time, so I thought I would reply now.)

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw

Ian Jackson writes ("Re: [PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 5 lines

Boris Ostrovsky writes ("[PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 4 lines

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

Quoted 8 lines
Quoted 1 line

QEMU needs to be able to handle them.

I'm kind of missing something here. If the specification has recently been updated to permit this, why should old hardware support it ?

(I tried to find the Linux upstream git commit you're referring to but my linux.git is up to date and it seems not to be fetching within a reasonable time, so I thought I would reply now.)

I have looked at this commit now and I am none the wiser.

It says just "This patch adds access_width/bit_offset support in acpi_hw_write()". I also looked at the two linked messages:
https://github.com/acpica/acpica/commit/48eea5e7
https://bugs.acpica.org/show_bug.cgi?id=1240
and none of this explains why this supported is needed in a our deep-frozen ancient branch.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw
Quoted 13 lines · Ian Jackson

Ian Jackson writes ("Re: [PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 5 lines

Boris Ostrovsky writes ("[PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 4 lines

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

Quoted 7 lines
Quoted 1 line

QEMU needs to be able to handle them.

I'm kind of missing something here. If the specification has recently been updated to permit this, why should old hardware support it ?

(I tried to find the Linux upstream git commit you're referring to but my linux.git is up to date and it seems not to be fetching within a reasonable time, so I thought I would reply now.)

Quoted 8 lines

I have looked at this commit now and I am none the wiser.

It says just "This patch adds access_width/bit_offset support in acpi_hw_write()". I also looked at the two linked messages:
https://github.com/acpica/acpica/commit/48eea5e7
https://bugs.acpica.org/show_bug.cgi?id=1240
and none of this explains why this supported is needed in a our deep-frozen ancient branch.

IIUIC, the Linux/ACPICA patch makes ACPICA use correct field in ACPI's Generic Address Structure (section 5.2.3.2 in the 6.0 spec). Before the patch it used register's bit_width and now it will use access_size. According to the spec access_size 0 means undefined/legacy access.

I just looked at what hvmloader provides and at least for FADT address_size is 0. And I wonder whether ACPICA uses 4-byte-access for these cases.

So maybe instead of trying to patch qemu-trad I should see if I can make hvmloader provide proper access size. Let me poke at that.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw

Boris Ostrovsky writes ("Re: [PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 4 lines

IIUIC, the Linux/ACPICA patch makes ACPICA use correct field in ACPI's Generic Address Structure (section 5.2.3.2 in the 6.0 spec). Before the patch it used register's bit_width and now it will use access_size. According to the spec access_size 0 means undefined/legacy access.

I see. (Well, sort of.)

Quoted 3 lines

I just looked at what hvmloader provides and at least for FADT address_size is 0. And I wonder whether ACPICA uses 4-byte-access for these cases.

If 0 is "undefined/legacy access", shouldn't it be using the register's bit width ? Ie, isn't this then a bug in ACPICA ?

Quoted 2 lines

So maybe instead of trying to patch qemu-trad I should see if I can make hvmloader provide proper access size. Let me poke at that.

If this "access size" attribute is new, things should work without it, surely ?

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw
Quoted 10 lines · Ian Jackson

Boris Ostrovsky writes ("Re: [PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 4 lines

IIUIC, the Linux/ACPICA patch makes ACPICA use correct field in ACPI's Generic Address Structure (section 5.2.3.2 in the 6.0 spec). Before the patch it used register's bit_width and now it will use access_size. According to the spec access_size 0 means undefined/legacy access.

I see. (Well, sort of.)

Quoted 3 lines

I just looked at what hvmloader provides and at least for FADT address_size is 0. And I wonder whether ACPICA uses 4-byte-access for these cases.

Quoted 7 lines

If 0 is "undefined/legacy access", shouldn't it be using the register's bit width ? Ie, isn't this then a bug in ACPICA ?

Quoted 2 lines

So maybe instead of trying to patch qemu-trad I should see if I can make hvmloader provide proper access size. Let me poke at that.

If this "access size" attribute is new, things should work without it, surely ?

This is what the spec says:

AccessSize evaluates to an 8-bit integer that specifies the size of data values used when accessing the
address space as follows:
0 - Undefined (legacy)
1 - Byte access
2 - Word access
3 - DWord access
4 - QWord access
The 8-bit field DescriptorName . _ASZ is automatically created in order to refer to this portion of the
resource descriptor. See _ASZ (page 368) for more information. For backwards compatibility, the
AccesSize parameter is optional when invoking the Register macro. If the AccessSize parameter is
not supplied then the AccessSize field will be set to zero. In this case, OSPM will assume the access
size.

I don't think I understand what the last sentence means. Does it imply that SW can do whatever it thinks is appropriate?

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 25.05.16 at 17:36, <[email protected]> wrote:

This is what the spec says:

AccessSize evaluates to an 8-bit integer that specifies the size of data values used when accessing the
address space as follows:
0 - Undefined (legacy)
1 - Byte access
2 - Word access
3 - DWord access
4 - QWord access
The 8-bit field DescriptorName . _ASZ is automatically created in order to refer to this portion of the
resource descriptor. See _ASZ (page 368) for more information. For backwards compatibility, the
AccesSize parameter is optional when invoking the Register macro. If the AccessSize parameter is
not supplied then the AccessSize field will be set to zero. In this case, OSPM will assume the access
size.

Quoted 2 lines

I don't think I understand what the last sentence means. Does it imply that SW can do whatever it thinks is appropriate?

I think so, yes.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#11 lore raw

Jan Beulich writes ("Re: [Xen-devel] [PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 11 lines · On 25.05.16 at 17:36, <[email protected]> wrote:
Quoted 8 lines

AccesSize parameter is optional when invoking the Register macro. If the AccessSize parameter is
not supplied then the AccessSize field will be set to zero. In this case, OSPM will assume the access
size.

I don't think I understand what the last sentence means. Does it imply that SW can do whatever it thinks is appropriate?

I think so, yes.

I think this question can only be resolved de jure by looking at what previous ACPI specifications (before this AccessSize field) said.

But, I think: de facto, what is going on here is that ACPICA and hence Linux have changed their behaviour in a way that is not compatible with at least some existing "hardware". Is this not arguably a compatibility defect Linux ?

It would surely be better to make Linux do whatever it did before, when AccessSize is not supplied. That will avoid breaking any other things (whether or not those other things are de jure broken according to previous specs). It will also avoid us having to make changes our ACPI tables which themselves come with a risk of compatibility problems.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw
Quoted 8 lines · Ian Jackson

Jan Beulich writes ("Re: [Xen-devel] [PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 7 lines · On 25.05.16 at 17:36, <[email protected]> wrote:
Quoted 6 lines

AccesSize parameter is optional when invoking the Register macro. If the AccessSize parameter is
not supplied then the AccessSize field will be set to zero. In this case, OSPM will assume the access
size.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

I don't think I understand what the last sentence means. Does it imply that SW can do whatever it thinks is appropriate?

I think so, yes.

I think this question can only be resolved de jure by looking at what previous ACPI specifications (before this AccessSize field) said.

It's been around since 3.0 (which is 2004). Prior to that --- my cursory read of 2.0 suggests that accesses were 8-bit.

Quoted 6 lines

But, I think: de facto, what is going on here is that ACPICA and hence Linux have changed their behaviour in a way that is not compatible with at least some existing "hardware". Is this not arguably a compatibility defect Linux ?

Quoted 6 lines

It would surely be better to make Linux do whatever it did before, when AccessSize is not supplied. That will avoid breaking any other things (whether or not those other things are de jure broken according to previous specs). It will also avoid us having to make changes our ACPI tables which themselves come with a risk of compatibility problems.

ACPICA will use 32-bit accesses for access_size=0:

    https://github.com/acpica/acpica/commit/c49a751b

However, Linux appears to have some sort of workaround for FreeBSD, which *appears* as it should be applicable to hvmloader's tables as well. But it clearly does not as we are failing on Linux.

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/acpi/acpica/hwregs.c?id=b314a172ee968d45f72dffea68ab8af38aa80ded

Let me see whether which path we take.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw
In reply to Boris Ostrovsky

Boris Ostrovsky writes ("Re: [Xen-devel] [PATCH qemu-traditional] ioreq: Support 32-bit default_ioport_* accesses"):

Quoted 6 lines · Ian Jackson
Quoted 2 lines

I think this question can only be resolved de jure by looking at what previous ACPI specifications (before this AccessSize field) said.

It's been around since 3.0 (which is 2004). Prior to that --- my cursory read of 2.0 suggests that accesses were 8-bit.

That would mean that in the absence of indication that the new standard is supported, accesses should be 8-bit.

Quoted 12 lines
Quoted 11 lines

But, I think: de facto, what is going on here is that ACPICA and hence Linux have changed their behaviour in a way that is not compatible with at least some existing "hardware". Is this not arguably a compatibility defect Linux ?

It would surely be better to make Linux do whatever it did before, when AccessSize is not supplied. That will avoid breaking any other things (whether or not those other things are de jure broken according to previous specs). It will also avoid us having to make changes our ACPI tables which themselves come with a risk of compatibility problems.

Quoted 2 lines

ACPICA will use 32-bit accesses for access_size=0:

    https://github.com/acpica/acpica/commit/c49a751b

That commit message does not justify the decision other than as an optimisation. Backward-incompatible `optimisations' are a bad idea both de jure and de facto.

Quoted 7 lines

However, Linux appears to have some sort of workaround for FreeBSD, which *appears* as it should be applicable to hvmloader's tables as well. But it clearly does not as we are failing on Linux.

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/acpi/acpica/hwregs.c?id=b314a172ee968d45f72dffea68ab8af38aa80ded

Let me see whether which path we take.

I confess I don't understand that patch, but it does seem to be an attempt to provide backward-compatible behaviour.

Overall, all this new information tends to reinforce my initial supposition that the bug is in ACPICA and that qemu-xen-traditional ought not to be changed.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#15 lore raw
In reply to Boris Ostrovsky
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 25.05.16 at 17:08, <[email protected]> wrote:
Quoted 1 line · Ian Jackson

Ian Jackson writes ("Re: [PATCH qemu-traditional] ioreq: Support 32-bit

default_ioport_* accesses"):

Quoted 1 line
Quoted 1 line

Boris Ostrovsky writes ("[PATCH qemu-traditional] ioreq: Support 32-bit

default_ioport_* accesses"):

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

Recent changes in ACPICA (specifically, Linux commit 66b1ed5aa8dd ("ACPICA:
ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write()") result in guests issuing 32-bit accesses to IO space.

QEMU needs to be able to handle them.

I'm kind of missing something here. If the specification has recently been updated to permit this, why should old hardware support it ?

(I tried to find the Linux upstream git commit you're referring to but my linux.git is up to date and it seems not to be fetching within a reasonable time, so I thought I would reply now.)

Quoted 8 lines

I have looked at this commit now and I am none the wiser.

It says just "This patch adds access_width/bit_offset support in acpi_hw_write()". I also looked at the two linked messages:
https://github.com/acpica/acpica/commit/48eea5e7
https://bugs.acpica.org/show_bug.cgi?id=1240
and none of this explains why this supported is needed in a our deep-frozen ancient branch.

IIUIC, the Linux/ACPICA patch makes ACPICA use correct field in ACPI's Generic Address Structure (section 5.2.3.2 in the 6.0 spec). Before the patch it used register's bit_width and now it will use access_size. According to the spec access_size 0 means undefined/legacy access.

Quoted 6 lines

I just looked at what hvmloader provides and at least for FADT address_size is 0. And I wonder whether ACPICA uses 4-byte-access for these cases.

So maybe instead of trying to patch qemu-trad I should see if I can make hvmloader provide proper access size. Let me poke at that.

But don't forget about the risk of breaking other OSes with any kind of change like this one.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel