Skip to contentSkip to conversation

Xen Q35 Bringup patches + support for PCIe Extended Capabilities for passed through devices

RFC PATCH In review Alexey Gerasimenko 12 participants 159 messages Mar 12, 2018 – Jun 1, 2018 Page 2 of 2

lore
Share & tools
lore
author
#58 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Jan Beulich
Quoted 59 lines · On Thu, 22 Mar 2018 08:42:09 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 59 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 15:34, <[email protected]> wrote:
Quoted 23 lines · On Thu, 22 Mar 2018 07:20:00 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 14:05, <[email protected]> wrote:
Quoted 10 lines · On Thu, 22 Mar 2018 06:09:44 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 12:56, <[email protected]> wrote:

I really don't understand why some people have that fear of emulated MMCONFIG -- it's really the same thing as any other MMIO range QEMU already emulates via map_io_range_to_ioreq_server(). No sensitive information exposed. It is related only to emulated PCI conf space which QEMU already knows about and use, providing emulated PCI devices for it.

You continue to ignore the routing requirement multiple ioreq servers impose.

Quoted 7 lines

If the emulated MMCONFIG approach will be modified to become fully compatible with multiple ioreq servers (whatever they used for), I assume there will be no objections that emulated MMCONFIG can't be used?
I just want to clarify this moment -- why people think that a completely emulated MMIO range, not related in any way to host's MMCONFIG may compromise something.

Quoted 2 lines

Compromise? All that was said so far - afair - was that this is the wrong way round design wise.

I assume it's all about emulating some real system for HVM, for other goals PV/PVH are available. What is a proper, design-wise way to emulate the MMIO-based MMCONFIG range Q35 provides you think of?

Here is what I've heard so far in this thread:

1. Add a completely new dmop/hypercall so that QEMU can tell Xen where emulated MMCONFIG MMIO area is located and in the same time map it for MMIO trapping to intercept accesses. Latter action is the same what map_io_range_to_ioreq_server() does, but let's ignore it for now because there was opinion that we need to stick to a distinct hypercall.

2. Upon trapping accesses to this emulated range, Xen will pretend that QEMU didn't just told him about MMCONFIG location and size and instead convert MMIO access into PCI conf one and send the ioreq to QEMU or some other DM.

3. If there will be a PCIEXBAR relocation (OVMF does it currently for MMCONFIG usage, but we must later teach him non-QEMU manners), QEMU must immediately inform Xen about any changes in MMCONFIG location/status.

4. QEMU receives PCI conf access while expecting the MMIO address, so xen-hvm.c has to deal with it somehow, either obtaining MMCONFIG base and recreating emulated MMIO access from BDF/reg or doing the dirty work of finding PCIBus/PCIDevice target itself as it cannot use emulated CF8/CFC ports due to legacy PCI conf size limitation.

Quoted 7 lines
Quoted 2 lines

Please confirm that it is a preferable solution or if something missing.

I'm afraid this is only part of the picture, as you've been told by others before. We first of all need to settle on who emulates the core chipset registers. Depending on that will be how Xen would learn about the MCFG location inside the guest.

Few related thoughts:

1. MMCONFIG address is chipset-specific. On Q35 it's a PCIEXBAR, on other x86 systems it may be HECBASE or else. So we can assume it is bound to the emulated machine

2. We rely on QEMU to emulate different machines for us.

3. There are users which touch chipset-specific PCIEXBAR directly if they see a Q35 system (OVMF so far)

Seems like we're pretty limited in freedom of choice in this conditions, I'm afraid.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#80 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Roger Pau Monné
Quoted 21 lines · On Thu, 22 Mar 2018 12:44:02 +0000 Roger Pau Monné <[email protected]> wrote:
Quoted 15 lines · Alexey G

On Thu, 22 Mar 2018 09:57:16 +0000
Roger Pau Monné <[email protected]> wrote:
[...]

Quoted 11 lines
Quoted 5 lines

Yes, and it is still needed as we have two distinct (and not equal) interfaces to PCI conf space. Apart from 0..FFh range overlapping they can be considered very different interfaces. And whether it is a real system or emulated -- we can use either one of these two interfaces or both.

The legacy PCI config space accesses and the MCFG config space access are just different methods of accessing the PCI configuration space, but the data _must_ be exactly the same. I don't see how a device would care about where the access to the config space originated.

Quoted 4 lines

If they were different methods of accessing the same thing, they could've been used interchangeably. When we've got a PCI conf ioreq which has offset>100h we know we cannot just pass it to emulated CF8/CFC but have to emulate this specifically.

Quoted 8 lines

This is already not the best approach to dispatch PCI config space access in QEMU. I think the interface in QEMU should be:

pci_conf_space_{read/write}(sbdf, register, size , data)

And this would go directly into the device. But I assume this involves a non-trivial amount of work to be implemented. Hence xen-hvm.c usage of the IO port access replay.

Yes, it's a helpful shortcut. The only bad thing that we can't use it for PCI extended config accesses, a memory address within emulated MMCONFIG much more preferable in current architecture.

Quoted 27 lines
Quoted 20 lines
Quoted 5 lines

OK, so you don't want to reconstruct the access, fine.

Then just inject it using pcie_mmcfg_data_{read/write} or some similar wrapper. My suggestion was just to try to use the easier way to get this injected into QEMU.

QEMU knows its position, the problem it that xen-hvm.c (ioreq processor) is rather isolated from MMCONFIG emulation.

If you check the pcie_mmcfg_data_read/write MMCONFIG handlers in QEMU, you can see this:

static uint64_t pcie_mmcfg_data_read(void *opaque, <...>

{
    PCIExpressHost *e = opaque;

...

We know this 'opaque' when we do MMIO-style MMCONFIG handling as pcie_mmcfg_data_read/write are actual handlers.

Quoted 6 lines

But xen-hvm.c needs to gain access to PCIExpressHost out of nowhere, which is possible but considered a hack by QEMU. We can also insert some code to MMCONFIG emulation which will store info we need to some global variables to be used across wildly different and unrelated modules. It will work, but anyone who see it will have bad thoughts on his mind.

Quoted 7 lines

Since you need to notify Xen the MCFG area address, why not just store the MCFG address while doing this operation? You could do this with a helper in xen-hvm.c, and keep the variable locally to that file.

In any case, this is a QEMU implementation detail. IMO the IOREQ interface is clear and should not be bended like this just because 'this is easier to implement in QEMU'.

A bit of hack too, but might work. Anyway, it's an extra work we can avoid if we simply skip PCI conf translation for MMCONFIG MMIO ioreqs targeting QEMU. I completely agree that we need to translate these accesses into PCI conf ioreqs for device DMs, but for QEMU it is an unwanted and redundant step.

AFAIK (Paul might correct me here) the multiple device emulators feature already makes use of the primary (aka default) DM and device-specific DM distinction, so in theory it should be possible to provide that translation only for device-specific DMs (which function apart from the emulated machine and cannot use its facilities).

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#81 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 92 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Alexey G
Sent: 22 March 2018 15:31
To: Roger Pau Monne <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Anthony Perard <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 21 lines · On Thu, 22 Mar 2018 12:44:02 +0000 Roger Pau Monné <[email protected]> wrote:
Quoted 15 lines · Alexey G

On Thu, 22 Mar 2018 09:57:16 +0000
Roger Pau Monné <[email protected]> wrote:
[...]

Quoted 11 lines
Quoted 5 lines

Yes, and it is still needed as we have two distinct (and not equal) interfaces to PCI conf space. Apart from 0..FFh range overlapping they can be considered very different interfaces. And whether it is a real system or emulated -- we can use either one of these two interfaces or both.

The legacy PCI config space accesses and the MCFG config space access are just different methods of accessing the PCI configuration space, but the data _must_ be exactly the same. I don't see how a device would care about where the access to the config space originated.

Quoted 4 lines

If they were different methods of accessing the same thing, they could've been used interchangeably. When we've got a PCI conf ioreq which has offset>100h we know we cannot just pass it to emulated CF8/CFC but have to emulate this specifically.

Quoted 8 lines

This is already not the best approach to dispatch PCI config space access in QEMU. I think the interface in QEMU should be:

pci_conf_space_{read/write}(sbdf, register, size , data)

And this would go directly into the device. But I assume this involves a non-trivial amount of work to be implemented. Hence xen-hvm.c usage of the IO port access replay.

Yes, it's a helpful shortcut. The only bad thing that we can't use it for PCI extended config accesses, a memory address within emulated MMCONFIG much more preferable in current architecture.

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines

OK, so you don't want to reconstruct the access, fine.

Then just inject it using pcie_mmcfg_data_{read/write} or some similar wrapper. My suggestion was just to try to use the easier way to get this injected into QEMU.

QEMU knows its position, the problem it that xen-hvm.c (ioreq processor) is rather isolated from MMCONFIG emulation.

If you check the pcie_mmcfg_data_read/write MMCONFIG handlers in QEMU, you can see this:

static uint64_t pcie_mmcfg_data_read(void *opaque, <...>

{
    PCIExpressHost *e = opaque;

...

Quoted 6 lines
Quoted 6 lines

We know this 'opaque' when we do MMIO-style MMCONFIG handling as pcie_mmcfg_data_read/write are actual handlers.

But xen-hvm.c needs to gain access to PCIExpressHost out of nowhere, which is possible but considered a hack by QEMU. We can also insert some code to MMCONFIG emulation which will store info we need to

some

Quoted 11 lines
Quoted 3 lines

global variables to be used across wildly different and unrelated modules. It will work, but anyone who see it will have bad thoughts on his mind.

Since you need to notify Xen the MCFG area address, why not just store the MCFG address while doing this operation? You could do this with a helper in xen-hvm.c, and keep the variable locally to that file.

In any case, this is a QEMU implementation detail. IMO the IOREQ interface is clear and should not be bended like this just because 'this is easier to implement in QEMU'.

A bit of hack too, but might work. Anyway, it's an extra work we can avoid if we simply skip PCI conf translation for MMCONFIG MMIO ioreqs targeting QEMU. I completely agree that we need to translate these accesses into PCI conf ioreqs for device DMs, but for QEMU it is an unwanted and redundant step.

Quoted 6 lines

AFAIK (Paul might correct me here) the multiple device emulators feature already makes use of the primary (aka default) DM and device-specific DM distinction, so in theory it should be possible to provide that translation only for device-specific DMs (which function apart from the emulated machine and cannot use its facilities).

No, that's not quite right. Only qemu-trad (and stubdom) are 'default' ioreq servers. Upstream QEMU has registered individual PCI devices with Xen for some time now, and hence gets proper PCI config IOREQs. Also we really really want default ioreq servers as their interface to Xen is fragile and has only just narrowly avoided being a security issue.

Paul

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#82 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.03.18 at 11:29, <[email protected]> wrote:

No, that's not quite right. Only qemu-trad (and stubdom) are 'default' ioreq servers. Upstream QEMU has registered individual PCI devices with Xen for some time now, and hence gets proper PCI config IOREQs. Also we really really want default ioreq servers as their interface to Xen is fragile and has only just narrowly avoided being a security issue.

Did you miss some "don't" or "to go away"?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#83 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 14 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 23 March 2018 11:39
To: Paul Durrant <[email protected]>
Cc: Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; 'Alexey G' <[email protected]>; [email protected]; Anthony Perard <[email protected]>; Ian Jackson <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 1 line
Quoted 1 line
Quoted 1 line · On 23.03.18 at 11:29, <[email protected]> wrote:
Quoted 9 lines
Quoted 3 lines

No, that's not quite right. Only qemu-trad (and stubdom) are 'default' ioreq servers. Upstream QEMU has registered individual PCI devices with Xen for some time now, and hence gets proper PCI config IOREQs. Also we really

really

Quoted 2 lines

want default ioreq servers as their interface to Xen is fragile and has only just narrowly avoided being a security issue.

Did you miss some "don't" or "to go away"?

Oops, yes! "to go away" definitely.

Paul

Quoted 7 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#59 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Alexey G
Quoted 86 lines

-----Original Message-----
From: Alexey G [mailto:[email protected]]
Sent: 22 March 2018 15:09
To: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>; Anthony Perard <[email protected]>; Ian Jackson <[email protected]>; Paul Durrant <[email protected]>; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; StefanoStabellini <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 11 lines · On Thu, 22 Mar 2018 08:42:09 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 15:34, <[email protected]> wrote:
Quoted 7 lines · On Thu, 22 Mar 2018 07:20:00 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 14:05, <[email protected]> wrote:
Quoted 3 lines · On Thu, 22 Mar 2018 06:09:44 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 22.03.18 at 12:56, <[email protected]> wrote:

I really don't understand why some people have that fear of emulated MMCONFIG -- it's really the same thing as any other

MMIO

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

range QEMU already emulates via

map_io_range_to_ioreq_server().

Quoted 31 lines
Quoted 31 lines
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

No sensitive information exposed. It is related only to emulated PCI conf space which QEMU already knows about and use, providing emulated PCI devices for it.

You continue to ignore the routing requirement multiple ioreq servers impose.

Quoted 7 lines

If the emulated MMCONFIG approach will be modified to become fully compatible with multiple ioreq servers (whatever they used for), I assume there will be no objections that emulated MMCONFIG can't be used?
I just want to clarify this moment -- why people think that a completely emulated MMIO range, not related in any way to host's MMCONFIG may compromise something.

Quoted 2 lines

Compromise? All that was said so far - afair - was that this is the wrong way round design wise.

I assume it's all about emulating some real system for HVM, for other goals PV/PVH are available. What is a proper, design-wise way to emulate the MMIO-based MMCONFIG range Q35 provides you think of?

Here is what I've heard so far in this thread:

1. Add a completely new dmop/hypercall so that QEMU can tell Xen where emulated MMCONFIG MMIO area is located and in the same time map it for MMIO trapping to intercept accesses. Latter action is the same what map_io_range_to_ioreq_server() does, but let's ignore it for now because there was opinion that we need to stick to a distinct hypercall.

Quoted 7 lines
Quoted 7 lines

2. Upon trapping accesses to this emulated range, Xen will pretend that QEMU didn't just told him about MMCONFIG location and size and instead convert MMIO access into PCI conf one and send the ioreq to QEMU or some other DM.

3. If there will be a PCIEXBAR relocation (OVMF does it currently for MMCONFIG usage, but we must later teach him non-QEMU manners),

QEMU

Quoted 5 lines
Quoted 5 lines

must immediately inform Xen about any changes in MMCONFIG location/status.

4. QEMU receives PCI conf access while expecting the MMIO address, so xen-hvm.c has to deal with it somehow, either obtaining MMCONFIG

base

Quoted 11 lines
Quoted 6 lines

and recreating emulated MMIO access from BDF/reg or doing the dirty work of finding PCIBus/PCIDevice target itself as it cannot use emulated CF8/CFC ports due to legacy PCI conf size limitation.

Please confirm that it is a preferable solution or if something missing.

I'm afraid this is only part of the picture, as you've been told by others before. We first of all need to settle on who emulates the core chipset registers. Depending on that will be how Xen would learn about the MCFG location inside the guest.

Quoted 6 lines

Few related thoughts:

1. MMCONFIG address is chipset-specific. On Q35 it's a PCIEXBAR, on other x86 systems it may be HECBASE or else. So we can assume it is bound to the emulated machine

Xen emulates the machine so it should be emulating PCIEXBAR.

Quoted 2 lines

2. We rely on QEMU to emulate different machines for us.

We should not be. It's a historical artefact that we rely on QEMU for any part of machine emulation.

Quoted 3 lines

3. There are users which touch chipset-specific PCIEXBAR directly if they see a Q35 system (OVMF so far)

And we should squash such accesses. The toolstack should be sole control of the guest memory map. It should be the only building MCFG so it should decide where the MMCONFIG regions go, not the firmware running in guest context.

Quoted 2 lines

Seems like we're pretty limited in freedom of choice in this conditions, I'm afraid.

I don't think so. We're only limited if we use QEMU's Q35 emulation and what I'm saying is that we should not be doing that (nor should be we be using it to emulate any part of the PIIX today).

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#60 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

On Fri, 23 Mar 2018 13:57:11 +0000
Paul Durrant <[email protected]> wrote:
[...]

Quoted 7 lines
Quoted 5 lines

Few related thoughts:

1. MMCONFIG address is chipset-specific. On Q35 it's a PCIEXBAR, on other x86 systems it may be HECBASE or else. So we can assume it is bound to the emulated machine

Xen emulates the machine so it should be emulating PCIEXBAR.

Actually, Xen currently emulates only few devices. Others are provided by QEMU, that's the problem.

Quoted 3 lines
Quoted 1 line

2. We rely on QEMU to emulate different machines for us.

We should not be. It's a historical artefact that we rely on QEMU for any part of machine emulation.

HVM guests need to see something more or less close to real hardware to run. Even if we later install PV drivers for network/storage/etc usage, we still need to support system firmware (SeaBIOS/OVMF) and be able to install any (ideally) OS which expects to be installed only on some real x86 hw. We also need to be ready to fallback to the emulated hw if eg. user will boot OS in the safe mode.

It all depends on what you mean by not relying on QEMU for any part of machine emulation.

There is a number of mandatory devices which should be provided for a typical x86 system. Xen emulates some of them, but there is a number which he doesn't. Apart from "classic" devices like RTC, PIT, KBC, etc we need to provide at least storage and network interfaces.

Windows installer won't be happy to boot from the PV storage device, he prefers to encounter something like AHCI (Windows 7+), ATA (for older OSes) or ATAPI if it is an iso cd.
Providing emulation for the AHCI+ATA+ATAPI trio alone is a non-trivial task. QEMU itself provides only partial implementation of these, many features are unsupported. Another very useful thing to emulate is USB. Depending on the controller version and device classes required, this may be far more complex to emulate than AHCI+ATA+ATAPI combined.

So, if you suggest to drop QEMU completely, it means that all this functionality must be replaced by own. Not that hard, but still a lot of effort.

OTOH, if you mean stripping QEMU of general PCI bus control and replacing his emulated NB/SB with Xen-owned -- well, it theory it should be possible, with patches on QEMU side.

In fact, the emulated chipset (NB+SB combo without supplemental devices) itself is a small part of required emulation. It's relatively easy to provide own analogs of for eg. 'mch' and 'ICH9-LPC' QEMU PCIDevice's, the problem is to glue all remaining parts together.

I assume the final goal in this case is to have only a set of necessary QEMU PCIDevice's for which we will be providing I/O, MMIO and PCI conf trapping facilities. Only devices such as rtl8139, ich9-ahci and few others.

Basically, this means a new, chipset-less QEMU machine type. Well, in theory it is possible with a bit of effort I think. The main question is where will be the NB/SB/PCIbus emulating part reside in this case. As this part must still have some priveleges, it's basically the same decision problem as with QEMU's dwelling place -- stubdomain, Dom0 or else.

Quoted 5 lines
Quoted 2 lines

3. There are users which touch chipset-specific PCIEXBAR directly if they see a Q35 system (OVMF so far)

And we should squash such accesses.

Yes, we have that privilege (i.e. allocating all IO/MMIO bases) for hvmloader. OVMF should not differ in this subject to SeaBIOS.

Quoted 4 lines

The toolstack should be sole
control of the guest memory map. It should be the only building MCFG so it should decide where the MMCONFIG regions go, not the firmware running in guest context.

HVM memory layout is another problem which needs solution BTW. I had to implement one for my PT goals, but it's very radical I'm afraid.

Right now there are wicked issues present in handling memory layout between hvmloader and QEMU. They may see a different memory map, even with overlaps in some (depending on MMIO hole size and content) cases -- like an attempt to place MMIO BAR over memory which is used for vram backing storage by QEMU, causing variety of issues like emulated I/O errors (with a storage device) during guest boot attempt.

Regarding control of the guest memory map in the toolstack only... The problem is, only firmware can see a final memory map at the moment. And only the device model knows about invisible "service" ranges for emulated devices, like the LFB content (aka "VRAM") when it is not mapped to a guest.

In order to calculate the final memory/MMIO hole split, we need to know:

1) all PCI devices on a PCI bus. At the moment Xen contributes only devices like PT to the final PCI bus (via QMP device_add). Others are QEMU ones. Even Xen platform PCI device relies on QEMU emulation. Non-QEMU device emulators are another source of virtual PCI devices I guess.

2) all chipset-specific emulated MMIO ranges. MMCONFIG is one of them and largest (up to 256Mb for a segment). There are few other smaller ranges, eg. Root Complex registers. All this ranges depend on the emulated chipset.

3) all reserved memory ranges (this one what toolstack already knows)

4) all "service" guest memory ranges like backing storage for VRAM in QEMU. Emulated Option ROMs should belong here too, but IIRC xen-hvm.c either intentionally or by mistate handles them as emulated ranges currently.

If we miss any of these (like what are the chipset-specific ranges and their size alignment requirements) -- we're in trouble. But, if we know *all* of these, we can pre-calculate the MMIO hole size. Although this is a bit fragile to do from the toolstack because both sizing algo in the toolstack and MMIO BAR allocation code in the firmware (hvmloader) must have their algorithms synchronized, because it is possible to sruff BARs to MMIO hole in different ways, especially when PCI-PCI bridges will appear on the scene. Both need to do it in a consistent way (resulting in similar set of gaps between allocated BARs), otherwise expected MMIO hole sizes won't match, which means we may need to relocate MMIO BARs to the high MMIO hole and this in turn may lead to those overlaps with QEMU memories.

Quoted 8 lines
Quoted 2 lines

Seems like we're pretty limited in freedom of choice in this conditions, I'm afraid.

I don't think so. We're only limited if we use QEMU's Q35 emulation and what I'm saying is that we should not be doing that (nor should be we be using it to emulate any part of the PIIX today).

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#61 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 18 lines · Alexey G

On Fri, 23 Mar 2018 13:57:11 +0000
Paul Durrant <[email protected]> wrote:
[...]

Quoted 7 lines
Quoted 5 lines

Few related thoughts:

1. MMCONFIG address is chipset-specific. On Q35 it's a PCIEXBAR, on other x86 systems it may be HECBASE or else. So we can assume it is bound to the emulated machine

Xen emulates the machine so it should be emulating PCIEXBAR.

Actually, Xen currently emulates only few devices. Others are provided by QEMU, that's the problem.

Quoted 3 lines
Quoted 1 line

2. We rely on QEMU to emulate different machines for us.

We should not be. It's a historical artefact that we rely on QEMU for any part of machine emulation.

Quoted 6 lines

HVM guests need to see something more or less close to real hardware to run. Even if we later install PV drivers for network/storage/etc usage, we still need to support system firmware (SeaBIOS/OVMF) and be able to install any (ideally) OS which expects to be installed only on some real x86 hw. We also need to be ready to fallback to the emulated hw if eg. user will boot OS in the safe mode.

I think Paul means that Xen should be emulating the platform devices and part of the southbridge/northbridge functionality, but not all the emulated devices provided to a guest.

Quoted 37 lines

It all depends on what you mean by not relying on QEMU for any part of machine emulation.

There is a number of mandatory devices which should be provided for a typical x86 system. Xen emulates some of them, but there is a number which he doesn't. Apart from "classic" devices like RTC, PIT, KBC, etc we need to provide at least storage and network interfaces.

Windows installer won't be happy to boot from the PV storage device, he prefers to encounter something like AHCI (Windows 7+), ATA (for older OSes) or ATAPI if it is an iso cd.
Providing emulation for the AHCI+ATA+ATAPI trio alone is a non-trivial task. QEMU itself provides only partial implementation of these, many features are unsupported. Another very useful thing to emulate is USB. Depending on the controller version and device classes required, this may be far more complex to emulate than AHCI+ATA+ATAPI combined.

So, if you suggest to drop QEMU completely, it means that all this functionality must be replaced by own. Not that hard, but still a lot of effort.

OTOH, if you mean stripping QEMU of general PCI bus control and replacing his emulated NB/SB with Xen-owned -- well, it theory it should be possible, with patches on QEMU side.

In fact, the emulated chipset (NB+SB combo without supplemental devices) itself is a small part of required emulation. It's relatively easy to provide own analogs of for eg. 'mch' and 'ICH9-LPC' QEMU PCIDevice's, the problem is to glue all remaining parts together.

I assume the final goal in this case is to have only a set of necessary QEMU PCIDevice's for which we will be providing I/O, MMIO and PCI conf trapping facilities. Only devices such as rtl8139, ich9-ahci and few others.

Quoted 4 lines

Basically, this means a new, chipset-less QEMU machine type. Well, in theory it is possible with a bit of effort I think. The main question is where will be the NB/SB/PCIbus emulating part reside in this case.

Mostly inside of Xen. Of course the IDE/SATA/USB/Ethernet... part of the southbrigde will be emulated by a device model (ie: QEMU).

As you mention above, I also took a look and it seems like the amount of registers that we should emulate for Q35 DRAM controller (D0:F0) is fairly minimal based on current QEMU implementation. We could even possibly get away by just emulating PCIEXBAR.

Quoted 54 lines

As this part must still have some priveleges, it's basically the same decision problem as with QEMU's dwelling place -- stubdomain, Dom0 or else.

Quoted 5 lines
Quoted 2 lines

3. There are users which touch chipset-specific PCIEXBAR directly if they see a Q35 system (OVMF so far)

And we should squash such accesses.

Yes, we have that privilege (i.e. allocating all IO/MMIO bases) for hvmloader. OVMF should not differ in this subject to SeaBIOS.

Quoted 4 lines

The toolstack should be sole
control of the guest memory map. It should be the only building MCFG so it should decide where the MMCONFIG regions go, not the firmware running in guest context.

HVM memory layout is another problem which needs solution BTW. I had to implement one for my PT goals, but it's very radical I'm afraid.

Right now there are wicked issues present in handling memory layout between hvmloader and QEMU. They may see a different memory map, even with overlaps in some (depending on MMIO hole size and content) cases -- like an attempt to place MMIO BAR over memory which is used for vram backing storage by QEMU, causing variety of issues like emulated I/O errors (with a storage device) during guest boot attempt.

Regarding control of the guest memory map in the toolstack only... The problem is, only firmware can see a final memory map at the moment. And only the device model knows about invisible "service" ranges for emulated devices, like the LFB content (aka "VRAM") when it is not mapped to a guest.

In order to calculate the final memory/MMIO hole split, we need to know:

1) all PCI devices on a PCI bus. At the moment Xen contributes only devices like PT to the final PCI bus (via QMP device_add). Others are QEMU ones. Even Xen platform PCI device relies on QEMU emulation. Non-QEMU device emulators are another source of virtual PCI devices I guess.

2) all chipset-specific emulated MMIO ranges. MMCONFIG is one of them and largest (up to 256Mb for a segment). There are few other smaller ranges, eg. Root Complex registers. All this ranges depend on the emulated chipset.

3) all reserved memory ranges (this one what toolstack already knows)

4) all "service" guest memory ranges like backing storage for VRAM in QEMU. Emulated Option ROMs should belong here too, but IIRC xen-hvm.c either intentionally or by mistate handles them as emulated ranges currently.

Quoted 12 lines

If we miss any of these (like what are the chipset-specific ranges and their size alignment requirements) -- we're in trouble. But, if we know *all* of these, we can pre-calculate the MMIO hole size. Although this is a bit fragile to do from the toolstack because both sizing algo in the toolstack and MMIO BAR allocation code in the firmware (hvmloader) must have their algorithms synchronized, because it is possible to sruff BARs to MMIO hole in different ways, especially when PCI-PCI bridges will appear on the scene. Both need to do it in a consistent way (resulting in similar set of gaps between allocated BARs), otherwise expected MMIO hole sizes won't match, which means we may need to relocate MMIO BARs to the high MMIO hole and this in turn may lead to those overlaps with QEMU memories.

I agree that the current memory layout management (or the lack of it) is concerning. Although related, I think this should be tackled as a different issue from the chipset one IMHO.

Since you already posted the Q35 series I would attempt to get that done first before jumping into the memory layout one.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#62 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 1 line · On Mon, 26 Mar 2018 10:24:38 +0100 Roger Pau Monné <[email protected]> wrote:

On Sat, Mar 24, 2018 at 08:32:44AM +1000, Alexey G wrote:

[...]

Quoted 16 lines
Quoted 11 lines

In fact, the emulated chipset (NB+SB combo without supplemental devices) itself is a small part of required emulation. It's relatively easy to provide own analogs of for eg. 'mch' and 'ICH9-LPC' QEMU PCIDevice's, the problem is to glue all remaining parts together.

I assume the final goal in this case is to have only a set of necessary QEMU PCIDevice's for which we will be providing I/O, MMIO and PCI conf trapping facilities. Only devices such as rtl8139, ich9-ahci and few others.

Quoted 4 lines

Basically, this means a new, chipset-less QEMU machine type. Well, in theory it is possible with a bit of effort I think. The main question is where will be the NB/SB/PCIbus emulating part reside in this case.

Quoted 7 lines

Mostly inside of Xen. Of course the IDE/SATA/USB/Ethernet... part of the southbrigde will be emulated by a device model (ie: QEMU).

As you mention above, I also took a look and it seems like the amount of registers that we should emulate for Q35 DRAM controller (D0:F0) is fairly minimal based on current QEMU implementation. We could even possibly get away by just emulating PCIEXBAR.

MCH emulation alone might be not an option. Besides, some southbridge-specific features like emulating ACPI PM facilities for domain power management (basically, anything at PMBASE) will be preferable to implement on Xen side, especially considering the fact that ACPI tables are already provided by Xen's libacpi/hvmloader, not the device model.
I think the feature may require to cover at least the NB+SB combination, at least Q35 MCH + ICH9 for start, ideally 82441FX+PIIX4 as well. Also, Xen should control emulated/PT PCI device placement.

Before going this way, it would be good to measure all risks. Looks like there are two main directions currently:

I. (conservative) Let the main device model (QEMU) to inform Xen about the current chipset-specific MMCONFIG location, to allow Xen to know that some MMIO accesses to this area must be forwarded to other ioreq servers (device emulators) in a form of PCI config read/write ioreqs, if BDF corresponding to a MMCONFIG offset will point to the PCI device owned by a device emulator.
In case of device emulators the conversion of MMIO accesses to PCI config ones is a mandatory step, while the owner of the MMCONFIG MMIO range may receive MMIO accesses in a native form without conversion (a strongly preferable option for QEMU).

This approach assumes introducing of the new dmop/hypercall (something like XEN_DMOP_mmcfg_location_change) to pass to Xen basic MMCONFIG information -- address, enabled/disabled status (or simply address=0 instead) and size of the MMCONFIG area, eg. as a number of buses. This information is enough to select a proper ioreq server in Xen and allow multiple device emulators to function properly.
For future compatibility we can also provide the segment and start/end bus range as arguments.

What this approach will require:
--------------------------------

- new notification-style dmop/hypercall to tell Xen about the current emulated MMCONFIG location

- trivial changes in QEMU to use this dmop in Q35 PCIEXBAR handling code

- relatively simple Xen changes in ioreq.c to use the provided range for ioreq server selection. Also, to provide MMIO -> PCI config ioreq translation for supplemental ioreq servers which don't know anything about the emulated system

Risks:
------

Risk to break anything is minimal in this case.

If QEMU will not provide this information (eg. due to an outdated version installed), only basic PCI config space accesses via CF8/CFC will be forwarded to a distinct ioreq server. This means the extended PCI config space accesses won't be forwarded to specific device emulators. Other than these device emulators, anything else will continue to work properly in this case. No differences will be for guest OSes without PCIe ECAM support in either case.

In general, no breakthrough improvements, no negative side-effects. Just PCIe ECAM working as expected and compatibility with multiple ioreq servers is retained.

II. (a new feature) Move chipset emulation to Xen directly.

In this case no separate notification necessary as Xen will be emulating the chosen chipset itself. MMCONFIG location will be known from own PCIEXBAR emulation.

QEMU will be used only to emulate a minimal set of unrelated devices (eg. storage/network/vga). Less dependency on QEMU overall.

More freedom to implement some specific features in the future like smram support for EFI firmware needs. Chipset remapping (aka reclaim) functionality for memory relocation may be implemented under complete Xen control, avoiding usage of unsafe add_to_physmap hypercalls.

In future this will allow to move passthrough-supporting code from QEMU (hw/xen/xen-pt*.c) to Xen, merging it with Roger's vpci series. This will improve eg. the PT + stubdomain situation a lot -- PCI config space accesses for PT devices will be handled in a uniform way without Dom0 interaction.
This particular feature can be implemented for the previous approach as well, still it is easier to do when Xen controls the emulated machine

In general, this is a good long-term direction.

What this approach will require:
--------------------------------

- Changes in QEMU code to support a new chipset-less machine(s). In theory might be possible to implement on top of the "null" machine concept

- Major changes in Xen code to implement the actual chipset emulation there

- Changes on the toolstack side as the emulated machine will be selected and used differently

- Moving passthrough support from QEMU to Xen will likely require to re-divide areas of responsibility for PCI device passthrough between xen-pciback and the hypervisor. It might be more convenient to perform some tasks of xen-pciback in Xen directly

- strong dependency between Xen/libxl/QEMU/etc versions -- any outdated component will be a major problem. Can be resolved by providing some compatibility code

- longer implementation time

Risks:
------

- A major architecture change with possible issues encountered during the implementation

- Moving the emulation of the machine to Xen creates a non-zero risk of introducing a security issue while extending the emulation support further. As all emulation will take place on a most trusted level, any exploitable bug in the chipset emulation code may compromise the whole system

- there is a risk to encounter some dependency on missing chipset devices in QEMU. Some of QEMU devices (which depend on QEMU chipset devices/properties) might not work without extra patches. In theory this may be addressed by leaving the dummy MCH/LPC/pci-host devices in place while not forwarding any IO/MMIO/PCI conf accesses to them (using simply as compat placeholders)

- risk of incompatibility with future QEMU versions

In both cases, for security concerns PCIEXBAR and other MCH registers can be made write-once (RO on all further accesses, similar to a TXT-locked system).

[...]

Quoted 41 lines
Quoted 27 lines

Regarding control of the guest memory map in the toolstack only... The problem is, only firmware can see a final memory map at the moment. And only the device model knows about invisible "service" ranges for emulated devices, like the LFB content (aka "VRAM") when it is not mapped to a guest.

In order to calculate the final memory/MMIO hole split, we need to know:

1) all PCI devices on a PCI bus. At the moment Xen contributes only devices like PT to the final PCI bus (via QMP device_add). Others are QEMU ones. Even Xen platform PCI device relies on QEMU emulation. Non-QEMU device emulators are another source of virtual PCI devices I guess.

2) all chipset-specific emulated MMIO ranges. MMCONFIG is one of them and largest (up to 256Mb for a segment). There are few other smaller ranges, eg. Root Complex registers. All this ranges depend on the emulated chipset.

3) all reserved memory ranges (this one what toolstack already knows)

4) all "service" guest memory ranges like backing storage for VRAM in QEMU. Emulated Option ROMs should belong here too, but IIRC xen-hvm.c either intentionally or by mistate handles them as emulated ranges currently.

Quoted 13 lines

If we miss any of these (like what are the chipset-specific ranges and their size alignment requirements) -- we're in trouble. But, if we know *all* of these, we can pre-calculate the MMIO hole size. Although this is a bit fragile to do from the toolstack because both sizing algo in the toolstack and MMIO BAR allocation code in the firmware (hvmloader) must have their algorithms synchronized, because it is possible to sruff BARs to MMIO hole in different ways, especially when PCI-PCI bridges will appear on the scene. Both need to do it in a consistent way (resulting in similar set of gaps between allocated BARs), otherwise expected MMIO hole sizes won't match, which means we may need to relocate MMIO BARs to the high MMIO hole and this in turn may lead to those overlaps with QEMU memories.

Quoted 6 lines

I agree that the current memory layout management (or the lack of it) is concerning. Although related, I think this should be tackled as a different issue from the chipset one IMHO.

Since you already posted the Q35 series I would attempt to get that done first before jumping into the memory layout one.

It is somewhat related to the chipset because memory/MMIO layout inconsistency can be solved more, well, naturally on Q35.

Basically, we have a non-standard MMIO hole layout where the start of the high MMIO hole do not match the top of addressable RAM (due to invisible ranges of the device model).

Q35 initially have facilities to allow firmware to modify (via emulation) or discover such MMIO hole setup which can be used for safe MMIO BAR allocation to avoid overlaps with QEMU-owned invisible ranges.

It doesn't really matter which registers to pick for this task, but for Q35 this approach is at least consistent with what a real system does (PV/PVH people will find this peculiarity pointless I suppose :) ).

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#63 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 29 lines · Alexey G
Quoted 1 line · On Mon, 26 Mar 2018 10:24:38 +0100 Roger Pau Monné <[email protected]> wrote:

On Sat, Mar 24, 2018 at 08:32:44AM +1000, Alexey G wrote:

[...]

Quoted 16 lines
Quoted 11 lines

In fact, the emulated chipset (NB+SB combo without supplemental devices) itself is a small part of required emulation. It's relatively easy to provide own analogs of for eg. 'mch' and 'ICH9-LPC' QEMU PCIDevice's, the problem is to glue all remaining parts together.

I assume the final goal in this case is to have only a set of necessary QEMU PCIDevice's for which we will be providing I/O, MMIO and PCI conf trapping facilities. Only devices such as rtl8139, ich9-ahci and few others.

Quoted 4 lines

Basically, this means a new, chipset-less QEMU machine type. Well, in theory it is possible with a bit of effort I think. The main question is where will be the NB/SB/PCIbus emulating part reside in this case.

Quoted 7 lines

Mostly inside of Xen. Of course the IDE/SATA/USB/Ethernet... part of the southbrigde will be emulated by a device model (ie: QEMU).

As you mention above, I also took a look and it seems like the amount of registers that we should emulate for Q35 DRAM controller (D0:F0) is fairly minimal based on current QEMU implementation. We could even possibly get away by just emulating PCIEXBAR.

Quoted 6 lines

MCH emulation alone might be not an option. Besides, some southbridge-specific features like emulating ACPI PM facilities for domain power management (basically, anything at PMBASE) will be preferable to implement on Xen side, especially considering the fact that ACPI tables are already provided by Xen's libacpi/hvmloader, not the device model.

Likely, but AFAICT this is kind of already broken, because PM1a and TMR is already emulated by Xen at hardcoded values. See xen/arch/x86/hvm/pmtimer.c.

Quoted 3 lines

I think the feature may require to cover at least the NB+SB combination, at least Q35 MCH + ICH9 for start, ideally 82441FX+PIIX4 as well. Also, Xen should control emulated/PT PCI device placement.

Q35 MCH (D0:F0) it's required in order to trap access to PCIEXBAR.

Could you be more concise about ICH9?

The ICH9 spec contains multiple devices, for example it includes an ethernet controller and a SATA controller, which we should not emulate inside of Xen.

Quoted 22 lines

II. (a new feature) Move chipset emulation to Xen directly.

In this case no separate notification necessary as Xen will be emulating the chosen chipset itself. MMCONFIG location will be known from own PCIEXBAR emulation.

QEMU will be used only to emulate a minimal set of unrelated devices (eg. storage/network/vga). Less dependency on QEMU overall.

More freedom to implement some specific features in the future like smram support for EFI firmware needs. Chipset remapping (aka reclaim) functionality for memory relocation may be implemented under complete Xen control, avoiding usage of unsafe add_to_physmap hypercalls.

In future this will allow to move passthrough-supporting code from QEMU (hw/xen/xen-pt*.c) to Xen, merging it with Roger's vpci series. This will improve eg. the PT + stubdomain situation a lot -- PCI config space accesses for PT devices will be handled in a uniform way without Dom0 interaction.
This particular feature can be implemented for the previous approach as well, still it is easier to do when Xen controls the emulated machine

Quoted 8 lines

In general, this is a good long-term direction.

What this approach will require:
--------------------------------

- Changes in QEMU code to support a new chipset-less machine(s). In theory might be possible to implement on top of the "null" machine concept

Not all parts of the chipset should go inside of Xen, ATM I only foresee Q35 MCH being implemented inside of Xen. So I'm not sure calling this a chipset-less machine is correct from QEMU PoV.

Quoted 10 lines

- Major changes in Xen code to implement the actual chipset emulation there

- Changes on the toolstack side as the emulated machine will be selected and used differently

- Moving passthrough support from QEMU to Xen will likely require to re-divide areas of responsibility for PCI device passthrough between xen-pciback and the hypervisor. It might be more convenient to perform some tasks of xen-pciback in Xen directly

Moving pci-passthough from QEMU to Xen is IMO a separate project, and by the text you provide I'm not sure how is that related to the Q35 chipset implementation.

Quoted 3 lines

- strong dependency between Xen/libxl/QEMU/etc versions -- any outdated component will be a major problem. Can be resolved by providing some compatibility code

Well, you would only be able to use the Q35 feature with the right version of the components.

Quoted 21 lines

- longer implementation time

Risks:
------

- A major architecture change with possible issues encountered during the implementation

- Moving the emulation of the machine to Xen creates a non-zero risk of introducing a security issue while extending the emulation support further. As all emulation will take place on a most trusted level, any exploitable bug in the chipset emulation code may compromise the whole system

- there is a risk to encounter some dependency on missing chipset devices in QEMU. Some of QEMU devices (which depend on QEMU chipset devices/properties) might not work without extra patches. In theory this may be addressed by leaving the dummy MCH/LPC/pci-host devices in place while not forwarding any IO/MMIO/PCI conf accesses to them (using simply as compat placeholders)

Quoted 5 lines

- risk of incompatibility with future QEMU versions

In both cases, for security concerns PCIEXBAR and other MCH registers can be made write-once (RO on all further accesses, similar to a TXT-locked system).

I think option II is the right way to move forward.

Quoted 6 lines

It is somewhat related to the chipset because memory/MMIO layout inconsistency can be solved more, well, naturally on Q35.

Basically, we have a non-standard MMIO hole layout where the start of the high MMIO hole do not match the top of addressable RAM (due to invisible ranges of the device model).

But that's a device model issue then? I'm not sure I'm getting what you mean here.

Quoted 3 lines

Q35 initially have facilities to allow firmware to modify (via emulation) or discover such MMIO hole setup which can be used for safe MMIO BAR allocation to avoid overlaps with QEMU-owned invisible ranges.

IMO a single entity should be in control of the memory layout, and that's the toolstack.

Ideally we should not allow the firmware to change the layout at all. What are specifically the registers that you mention?

Quoted 3 lines

It doesn't really matter which registers to pick for this task, but for Q35 this approach is at least consistent with what a real system does (PV/PVH people will find this peculiarity pointless I suppose :) ).

Right, but I don't think we aim to emulate a fully complete Q35 MCH or ICH9 for example, which has tons of registers, not even QEMU is trying to do that. The main goal is to emulate the registers we know are required for OSes to work.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#64 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 37 lines · On Tue, 27 Mar 2018 09:45:30 +0100 Roger Pau Monné <[email protected]> wrote:
Quoted 29 lines · Alexey G
Quoted 1 line · On Mon, 26 Mar 2018 10:24:38 +0100 Roger Pau Monné <[email protected]> wrote:

On Sat, Mar 24, 2018 at 08:32:44AM +1000, Alexey G wrote:

[...]

Quoted 16 lines
Quoted 11 lines

In fact, the emulated chipset (NB+SB combo without supplemental devices) itself is a small part of required emulation. It's relatively easy to provide own analogs of for eg. 'mch' and 'ICH9-LPC' QEMU PCIDevice's, the problem is to glue all remaining parts together.

I assume the final goal in this case is to have only a set of necessary QEMU PCIDevice's for which we will be providing I/O, MMIO and PCI conf trapping facilities. Only devices such as rtl8139, ich9-ahci and few others.

Quoted 4 lines

Basically, this means a new, chipset-less QEMU machine type. Well, in theory it is possible with a bit of effort I think. The main question is where will be the NB/SB/PCIbus emulating part reside in this case.

Quoted 7 lines

Mostly inside of Xen. Of course the IDE/SATA/USB/Ethernet... part of the southbrigde will be emulated by a device model (ie: QEMU).

As you mention above, I also took a look and it seems like the amount of registers that we should emulate for Q35 DRAM controller (D0:F0) is fairly minimal based on current QEMU implementation. We could even possibly get away by just emulating PCIEXBAR.

Quoted 6 lines

MCH emulation alone might be not an option. Besides, some southbridge-specific features like emulating ACPI PM facilities for domain power management (basically, anything at PMBASE) will be preferable to implement on Xen side, especially considering the fact that ACPI tables are already provided by Xen's libacpi/hvmloader, not the device model.

Quoted 3 lines

Likely, but AFAICT this is kind of already broken, because PM1a and TMR is already emulated by Xen at hardcoded values. See xen/arch/x86/hvm/pmtimer.c.

Yes, that should be an argument to try to implement PMBASE emulation in Xen too. Although this needs to be checked against dependencies in QEMU first, especially with ACPI-related code.

This way we can have a better flexibility to use an arbitrary PMBASE value, not just having to hardcode it to ACPI_PM1A_EVT_BLK_ADDRESS_V1 in all related components.

Quoted 5 lines
Quoted 3 lines

I think the feature may require to cover at least the NB+SB combination, at least Q35 MCH + ICH9 for start, ideally 82441FX+PIIX4 as well. Also, Xen should control emulated/PT PCI device placement.

Q35 MCH (D0:F0) it's required in order to trap access to PCIEXBAR.

Absolutely.

BTW, another somewhat related problem at the moment is that Xen knows nothing about a chipset-specific MMIO hole(s). Due to this, it is possible for a guest to map PT BARs outside the MMIO hole, leading to errors like this:

(XEN) memory_map:remove: dom4 gfn=c8000 mfn=c8000 nr=2000 (XEN) memory_map:add: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1121:d0v5 p2m_set_entry: 0xffffffffc8000:9 -> -22 (0xc8000) (XEN) memory_map:fail: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 ret:-22 (XEN) memory_map:remove: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1228:d0v5 gfn_to_mfn failed! gfn=ffffffffc8000 type:4 (XEN) memory_map: error -22 removing dom4 access to [c8000,c9fff] (XEN) memory_map:remove: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1228:d0v5 gfn_to_mfn failed! gfn=ffffffffc8000 type:4 (XEN) memory_map: error -22 removing dom4 access to [c8000,c9fff] (XEN) memory_map:add: dom4 gfn=c8000 mfn=c8000 nr=2000

Note that it was merely a lame BAR sizing attempt from the guest-side SW (a PCI config space viewing tool) -- writing F's to the high part of the MMIO BAR first.

If we will know the guest's MMIO hole bounds, we can adapt to this behavior, avoiding erroneous mapping attempts to a wrong address outside the MMIO hole. Only the MMIO hole designated range can be used to map PT device BARs.

So, if we will be actually emulating MCH's MMIO hole related registers in Xen as well -- we can use them as scratchpad registers (write-once of course) to pass this kind of information between Xen and other involved parties as an alternative to eg. a dedicated hypercall.

Quoted 5 lines

Could you be more concise about ICH9?

The ICH9 spec contains multiple devices, for example it includes an ethernet controller and a SATA controller, which we should not emulate inside of Xen.

ICH built-in devices from out PoV can be considered as distinct PCI devices (as long as they're actually distinct devices in PCI config space).
It's a QEMU's approach for them -- these devices can be added to a q35 machine optionally. Only a minimal set of devices provided initially, like MCH/LPC/AHCI. SMBus controller (0:1F.3) added by default too, but it's not useful much at the moment.

So mostly we can consider the LPC bridge (0:1F.0) for emulation of all devices provided by a real ICH SB.

Quoted 28 lines
Quoted 28 lines

II. (a new feature) Move chipset emulation to Xen directly.

In this case no separate notification necessary as Xen will be emulating the chosen chipset itself. MMCONFIG location will be known from own PCIEXBAR emulation.

QEMU will be used only to emulate a minimal set of unrelated devices (eg. storage/network/vga). Less dependency on QEMU overall.

More freedom to implement some specific features in the future like smram support for EFI firmware needs. Chipset remapping (aka reclaim) functionality for memory relocation may be implemented under complete Xen control, avoiding usage of unsafe add_to_physmap hypercalls.

In future this will allow to move passthrough-supporting code from QEMU (hw/xen/xen-pt*.c) to Xen, merging it with Roger's vpci series. This will improve eg. the PT + stubdomain situation a lot -- PCI config space accesses for PT devices will be handled in a uniform way without Dom0 interaction.
This particular feature can be implemented for the previous approach as well, still it is easier to do when Xen controls the emulated machine

In general, this is a good long-term direction.

What this approach will require:
--------------------------------

Quoted 7 lines
Quoted 3 lines

- Changes in QEMU code to support a new chipset-less machine(s). In theory might be possible to implement on top of the "null" machine concept

Not all parts of the chipset should go inside of Xen, ATM I only foresee Q35 MCH being implemented inside of Xen. So I'm not sure calling this a chipset-less machine is correct from QEMU PoV.

Emulating only MCH in Xen will still require lot of changes but overall benefit will become unclear -- basically, we just move PCIEXBAR emulation to Xen from QEMU.

Quoted 6 lines
Quoted 6 lines

- Major changes in Xen code to implement the actual chipset emulation there

- Changes on the toolstack side as the emulated machine will be selected and used differently

Quoted 8 lines
Quoted 4 lines

- Moving passthrough support from QEMU to Xen will likely require to re-divide areas of responsibility for PCI device passthrough
between xen-pciback and the hypervisor. It might be more convenient to perform some tasks of xen-pciback in Xen directly

Moving pci-passthough from QEMU to Xen is IMO a separate project, and by the text you provide I'm not sure how is that related to the Q35 chipset implementation.

Yes, it's more a separate feature on top of that approach.

Quoted 28 lines
Quoted 3 lines

- strong dependency between Xen/libxl/QEMU/etc versions -- any outdated component will be a major problem. Can be resolved by providing some compatibility code

Well, you would only be able to use the Q35 feature with the right version of the components.

Quoted 21 lines

- longer implementation time

Risks:
------

- A major architecture change with possible issues encountered during the implementation

- Moving the emulation of the machine to Xen creates a non-zero risk of introducing a security issue while extending the emulation support further. As all emulation will take place on a most trusted level,
any exploitable bug in the chipset emulation code may compromise the
whole system

- there is a risk to encounter some dependency on missing chipset devices in QEMU. Some of QEMU devices (which depend on QEMU chipset devices/properties) might not work without extra patches. In theory this may be addressed by leaving the dummy MCH/LPC/pci-host devices in place while not forwarding any IO/MMIO/PCI conf accesses to them (using simply as compat placeholders)

Quoted 7 lines
Quoted 5 lines

- risk of incompatibility with future QEMU versions

In both cases, for security concerns PCIEXBAR and other MCH registers can be made write-once (RO on all further accesses, similar to a TXT-locked system).

I think option II is the right way to move forward.

Agree, it's a good long-term direction.
Well, the problem is, option 1 can be implemented in a matter of 1-3 days. It will allow MMCONFIG to work with multiple device emulators while being very light on requirements -- no big code changes necessary, easy to test/review, etc.

OTOH, option 2 will require some research first as the change is non-trivial and may possibly produce any kind of incompatibility issues with QEMU.

Emulating just MCH in Xen while still leaving anything else to QEMU does not show an obvious advantage. Without extending the chipset emulation in Xen further, it will be just an overcomplicated emulation of PCIEXBAR register. If this will be the only first objective for the feature, then we need some strong justification why moving the emulation of guest's PCIEXBAR from QEMU to Xen is a mandatory thing.

We need to be extra sure that having MCH emulated in Xen while ICH9 and all the rest will remain to be emulated by QEMU is a good solution for PCIEXBAR emulation. Otherwise, having a split-type chipset emulation between Xen/QEMU just to handle the Q35' PCIEXBAR register is an overkill.

I would personally prefer to implement the option 1 first, while researching and implementing the option 2 in the near perspective.

There is nothing special in PCIEXBAR, it's just one of the emulated chipset registers, holding the address of the emulated MMIO area. This register doesn't differ much with eg. AHCI ABAR. In fact, it's actually more harmless -- for MMCONFIG MMIO we merely forward accesses for PCI config read/write emulation (same thing as for emulated CF8/CFC I/O), while handling AHCI ABAR MMIO means that we do serious things like initiating real block I/O with the host. For PT devices MMCONFIG accesses still go thru hw/xen-pt*.c for filtering or emulation.

Quoted 9 lines
Quoted 6 lines

It is somewhat related to the chipset because memory/MMIO layout inconsistency can be solved more, well, naturally on Q35.

Basically, we have a non-standard MMIO hole layout where the start of the high MMIO hole do not match the top of addressable RAM (due to invisible ranges of the device model).

But that's a device model issue then? I'm not sure I'm getting what you mean here.

We depend on the device model in the question where we can place the start of the high MMIO hole currently. This also badly affects memory relocation support, which is required for MMIO hole auto-sizing. There are multiple options how to resolve this problem, eg. placing VRAM to some addresses far beyond >4Gb but this approach is not ideal too as the device model cannot know where 64-bit BARs will be allocated. Although this is a simplest approach to avoid overlaps and to have the high MMIO hole base equal to the max guest RAM address.

Quoted 9 lines
Quoted 4 lines

Q35 initially have facilities to allow firmware to modify (via emulation) or discover such MMIO hole setup which can be used for safe MMIO BAR allocation to avoid overlaps with QEMU-owned invisible ranges.

IMO a single entity should be in control of the memory layout, and that's the toolstack.

Ideally we should not allow the firmware to change the layout at all.

This approach is terribly wrong, I don't know why opinions like this so common at Citrix. The toolstack is a least informed side. If MMIO/memory layout should be immutable, it must be calculated considering all factors, like chipset-specific MMIO ranges or ranges which cannot be used for the MMIO hole.

We need to know all resource requirements of device-model's and PT PCI devices, all chipset-specific MMIO ranges (which belong to a device model), all RMRRs (host's property) and all device-model invisible ranges like VRAM backing store (another device model's property). And we need to know in which manner hvmloader will be allocating BARs to the MMIO hole -- eg. either in a forward direction starting from some base or moving backwards from the end of 4Gb (minus hardcoded ranges). Basically this means that we have to depend on hvmloader code/version too in the toolstack, which is wrong on its own -- we should have a freedom to modify the BAR allocation algo in hvmloader at any time.

At the moment all this information can be discovered only from the firmware side. Lot of changes needed to gather all required information from the toolstack.

Quoted 1 line

What are specifically the registers that you mention?

Write-once emulation of TOLUD/TOUUD/REMAPBASE/REMAPLIMIT registers for hvmloader to use. That's the approach I'm actually using to make 'hvmloader/allow-memory-relocate=1' to work. Memory relocation without relying on add_to_physmap hypercall for hvmloader (which it does currently) while having MMIO/memory layout synchronized between all parties. There are multiple benefits (mostly for PT needs), including the MMIO hole auto-sizing support but this approach won't be accepted well with "toolstack should do everything" attitude I'm afraid.

Quoted 9 lines
Quoted 4 lines

It doesn't really matter which registers to pick for this task, but for Q35 this approach is at least consistent with what a real system does (PV/PVH people will find this peculiarity pointless I suppose :) ).

Right, but I don't think we aim to emulate a fully complete Q35 MCH or ICH9 for example, which has tons of registers, not even QEMU is trying to do that. The main goal is to emulate the registers we know are required for OSes to work.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#65 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 26 lines · Alexey G
Quoted 5 lines · On Tue, 27 Mar 2018 09:45:30 +0100 Roger Pau Monné <[email protected]> wrote:
Quoted 4 lines · Alexey G
Quoted 1 line · On Mon, 26 Mar 2018 10:24:38 +0100 Roger Pau Monné <[email protected]> wrote:

On Sat, Mar 24, 2018 at 08:32:44AM +1000, Alexey G wrote:

BTW, another somewhat related problem at the moment is that Xen knows nothing about a chipset-specific MMIO hole(s). Due to this, it is possible for a guest to map PT BARs outside the MMIO hole, leading to errors like this:

(XEN) memory_map:remove: dom4 gfn=c8000 mfn=c8000 nr=2000 (XEN) memory_map:add: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1121:d0v5 p2m_set_entry: 0xffffffffc8000:9 -> -22 (0xc8000) (XEN) memory_map:fail: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 ret:-22 (XEN) memory_map:remove: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1228:d0v5 gfn_to_mfn failed! gfn=ffffffffc8000 type:4 (XEN) memory_map: error -22 removing dom4 access to [c8000,c9fff] (XEN) memory_map:remove: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1228:d0v5 gfn_to_mfn failed! gfn=ffffffffc8000 type:4 (XEN) memory_map: error -22 removing dom4 access to [c8000,c9fff] (XEN) memory_map:add: dom4 gfn=c8000 mfn=c8000 nr=2000

Quoted 3 lines

Note that it was merely a lame BAR sizing attempt from the guest-side SW (a PCI config space viewing tool) -- writing F's to the high part of the MMIO BAR first.

You should disable memory decoding before attempting to size a BAR.

This error has nothing to do with trying to move a BAR outside of the MMIO hole, this error is caused by the gfn being bigger than the guest physical address width AFAICT.

Quoted 9 lines

If we will know the guest's MMIO hole bounds, we can adapt to this behavior, avoiding erroneous mapping attempts to a wrong address outside the MMIO hole. Only the MMIO hole designated range can be used to map PT device BARs.

So, if we will be actually emulating MCH's MMIO hole related registers in Xen as well -- we can use them as scratchpad registers (write-once of course) to pass this kind of information between Xen and other involved parties as an alternative to eg. a dedicated hypercall.

I'm not sure where this information is stored in MCH, guest OSes tend to fetch this from the ACPI _CRS method of the host-pci bridge device.

I also don't see QEMU emulating such registers, but yes, I won't be opposed to storing/reporting this in some registers if that's indeed supported. Note that I don't think this should be mandatory for adding Q35 support though.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

What this approach will require:
--------------------------------

- Changes in QEMU code to support a new chipset-less machine(s). In theory might be possible to implement on top of the "null" machine concept

Quoted 7 lines
Quoted 3 lines

Not all parts of the chipset should go inside of Xen, ATM I only foresee Q35 MCH being implemented inside of Xen. So I'm not sure calling this a chipset-less machine is correct from QEMU PoV.

Emulating only MCH in Xen will still require lot of changes but overall benefit will become unclear -- basically, we just move PCIEXBAR emulation to Xen from QEMU.

At least it would make Xen the one controlling the MCFG area, which is important. It would also be the first step into moving other chipset functionality into Xen.

Not doing it just perpetuates the bad precedent that we already have with the previous chipset.

Quoted 10 lines
Quoted 1 line

What are specifically the registers that you mention?

Write-once emulation of TOLUD/TOUUD/REMAPBASE/REMAPLIMIT registers for hvmloader to use. That's the approach I'm actually using to make 'hvmloader/allow-memory-relocate=1' to work. Memory relocation without relying on add_to_physmap hypercall for hvmloader (which it does currently) while having MMIO/memory layout synchronized between all parties. There are multiple benefits (mostly for PT needs), including the MMIO hole auto-sizing support but this approach won't be accepted well with "toolstack should do everything" attitude I'm afraid.

You seem to be trying to fix several issues at the same time, which just makes this much more complex than needed. The initial aim of this series was to allow HVM guests to use the Q35 chipset. I think that's what we should focus on.

As you have listed above (and in other emails) there are many limitations with the current HVM approach, which I would be more than happy for you to solve. But IMO not all of them must be solved in order to add Q35 support.

Since this series and email thread has already gone quite far, would you mind writing a design document with the approach that we discussed?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#68 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Alexey G
Quoted 4 lines

-----Original Message-----

Quoted 3 lines

IMO a single entity should be in control of the memory layout, and that's the toolstack.

Quoted 8 lines
Quoted 1 line

Ideally we should not allow the firmware to change the layout at all.

This approach is terribly wrong, I don't know why opinions like this so common at Citrix. The toolstack is a least informed side. If MMIO/memory layout should be immutable, it must be calculated considering all factors, like chipset-specific MMIO ranges or ranges which cannot be used for the MMIO hole.

Why is this approach wrong? Code running in the guest is non-privileged and we really don't want it messing around with memory layout. We really want to be in a position to e.g. build ACPI tables in the toolstack and we cannot do this until the layout becomes immutable.

Quoted 4 lines

We need to know all resource requirements of device-model's and PT PCI devices, all chipset-specific MMIO ranges (which belong to a device model), all RMRRs (host's property) and all device-model invisible ranges like VRAM backing store (another device model's property).

Yes, indeed we do.

Quoted 3 lines

And we need to know in which manner hvmloader will be allocating BARs to the MMIO hole -- eg. either in a forward direction starting from some base or moving backwards from the end of 4Gb (minus hardcoded ranges).

Eventually we want to get rid of hvmloader. Why do we need to know anything about its enumeration of BARs? After all they could be completely re-enumerated by the guest OS during or after boot (and indeed Windows does precisely that).

Quoted 4 lines

Basically this means that we have to depend on hvmloader code/version too in the toolstack, which is wrong on its own -- we should have a freedom to modify the BAR allocation algo in hvmloader at any time.

It should be irrelevant. The toolstack should decide on the sizes and locations of the MMIO holes and they should remain fixed, and be enforced by Xen. This avoids issues that we currently have such as guests populating RAM inside MMIO holes.

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#66 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Roger Pau Monné
Quoted 28 lines · On Wed, 28 Mar 2018 10:30:32 +0100 Roger Pau Monné <[email protected]> wrote:
Quoted 27 lines · Alexey G
Quoted 5 lines · On Tue, 27 Mar 2018 09:45:30 +0100 Roger Pau Monné <[email protected]> wrote:
Quoted 4 lines · Alexey G
Quoted 1 line · On Mon, 26 Mar 2018 10:24:38 +0100 Roger Pau Monné <[email protected]> wrote:

On Sat, Mar 24, 2018 at 08:32:44AM +1000, Alexey G wrote:

BTW, another somewhat related problem at the moment is that Xen knows nothing about a chipset-specific MMIO hole(s). Due to this, it is possible for a guest to map PT BARs outside the MMIO hole, leading to errors like this:

(XEN) memory_map:remove: dom4 gfn=c8000 mfn=c8000 nr=2000 (XEN) memory_map:add: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1121:d0v5 p2m_set_entry: 0xffffffffc8000:9 -> -22 (0xc8000) (XEN) memory_map:fail: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 ret:-22 (XEN) memory_map:remove: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1228:d0v5 gfn_to_mfn failed! gfn=ffffffffc8000 type:4 (XEN) memory_map: error -22 removing dom4 access to [c8000,c9fff] (XEN) memory_map:remove: dom4 gfn=ffffffffc8000 mfn=c8000 nr=2000 (XEN) p2m.c:1228:d0v5 gfn_to_mfn failed! gfn=ffffffffc8000 type:4 (XEN) memory_map: error -22 removing dom4 access to [c8000,c9fff] (XEN) memory_map:add: dom4 gfn=c8000 mfn=c8000 nr=2000

Quoted 5 lines
Quoted 3 lines

Note that it was merely a lame BAR sizing attempt from the guest-side SW (a PCI config space viewing tool) -- writing F's to the high part of the MMIO BAR first.

You should disable memory decoding before attempting to size a BAR.

The problem is, that PCI config space viewer is not mine. :) It should disable the decoding first normally, yes, but it doesn't. Yet there are no problems on the real system and these errors while being run in a VM. IIRC powercycling the guest and triggering these errors multiple times even had negative impact on host's stability, so it's a good test case.

Quoted 3 lines

This error has nothing to do with trying to move a BAR outside of the MMIO hole, this error is caused by the gfn being bigger than the guest physical address width AFAICT.

In fact, it's the essence of the error -- an attempt to map the range where it shouldn't be attempted to map at all.
p2m_set_entry is too deep to encounter this error, it should be avoided much earlier. If we knew the limits where we can (and cannot) map the PT device BARs, we can check if we really need to proceed with the mapping. This way we can handle that "mid-sizing/mid-change" condition when only half of the 64-bit mem BAR has been written.

Quoted 11 lines
Quoted 10 lines

If we will know the guest's MMIO hole bounds, we can adapt to this behavior, avoiding erroneous mapping attempts to a wrong address outside the MMIO hole. Only the MMIO hole designated range can be used to map PT device BARs.

So, if we will be actually emulating MCH's MMIO hole related registers in Xen as well -- we can use them as scratchpad registers (write-once of course) to pass this kind of information between Xen and other involved parties as an alternative to eg. a dedicated hypercall.

Quoted 7 lines

I'm not sure where this information is stored in MCH, guest OSes tend to fetch this from the ACPI _CRS method of the host-pci bridge device.

I also don't see QEMU emulating such registers, but yes, I won't be opposed to storing/reporting this in some registers if that's indeed supported. Note that I don't think this should be mandatory for adding Q35 support though.

This info needed for Xen, not guest OSes -- in order to avoid errors like described above. If we will be emulating MCH in Xen internally, we can emulate this registers as well. It will be simpler than introducing a new hypercall to inform Xen about the established MMIO hole range.

Anyway, you're right, it's a side issue. Just an example for what else the built-in MCH emulation may be useful.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

What this approach will require:
--------------------------------

- Changes in QEMU code to support a new chipset-less machine(s). In theory might be possible to implement on top of the "null" machine concept

Quoted 7 lines
Quoted 3 lines

Not all parts of the chipset should go inside of Xen, ATM I only foresee Q35 MCH being implemented inside of Xen. So I'm not sure calling this a chipset-less machine is correct from QEMU PoV.

Emulating only MCH in Xen will still require lot of changes but overall benefit will become unclear -- basically, we just move PCIEXBAR emulation to Xen from QEMU.

Quoted 6 lines

At least it would make Xen the one controlling the MCFG area, which is important. It would also be the first step into moving other chipset functionality into Xen.

Not doing it just perpetuates the bad precedent that we already have with the previous chipset.

I think it will be kinda ugly if we will be emulating just MCH in Xen and ICH9 (+ all the rest) in QEMU at the same time. It looks more like some temporary solution. It would be good to know if such approach will be approved by maintainers.

Quoted 12 lines
Quoted 11 lines
Quoted 1 line

What are specifically the registers that you mention?

Write-once emulation of TOLUD/TOUUD/REMAPBASE/REMAPLIMIT registers for hvmloader to use. That's the approach I'm actually using to make 'hvmloader/allow-memory-relocate=1' to work. Memory relocation without relying on add_to_physmap hypercall for hvmloader (which it does currently) while having MMIO/memory layout synchronized between all parties. There are multiple benefits (mostly for PT needs), including the MMIO hole auto-sizing support but this approach won't be accepted well with "toolstack should do everything" attitude I'm afraid.

Quoted 4 lines

You seem to be trying to fix several issues at the same time, which just makes this much more complex than needed. The initial aim of this series was to allow HVM guests to use the Q35 chipset. I think that's what we should focus on.

Agree. Initially, the main goal was to allow the PCIe extended config space usage for PT devices. Even this particular feature is not in its final state, there are other patches for hw/xen/xen-pt*.c pending (dynamic fields support), but these are more common, not bound to just Q35.

Quoted 8 lines

As you have listed above (and in other emails) there are many limitations with the current HVM approach, which I would be more than happy for you to solve. But IMO not all of them must be solved in order to add Q35 support.

Since this series and email thread has already gone quite far, would you mind writing a design document with the approach that we discussed?

I think we must all agree which approach to implement next. Basically, whether we need to completely discard the option #1 for this series and move on with #2. That lengthy requirements/risks email was an attempt to provide some ground for comparison.

Leaving only required devices like vga/usb/network/storage to QEMU while emulating everything else in Xen is a good milestone, but, as I understood we currently targeting less ambitious goals for option #2 -- emulating only MCH in Xen while emulating ICH9 etc in QEMU.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#67 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 11 lines

-----Original Message-----

I think we must all agree which approach to implement next. Basically, whether we need to completely discard the option #1 for this series and move on with #2. That lengthy requirements/risks email was an attempt to provide some ground for comparison.

Leaving only required devices like vga/usb/network/storage to QEMU while emulating everything else in Xen is a good milestone, but, as I understood we currently targeting less ambitious goals for option #2 -- emulating only MCH in Xen while emulating ICH9 etc in QEMU.

Option #2 is right direction architecturally; the trick is figuring out how to get there in stages.

I think the fact that Xen emulation obscures QEMU emulation means that we can start to do this without needing too much, if any, change in QEMU. It looks like handling MMCONFIG inside Xen would be a reasonable first stage. Stage two could be explanding Roger's vpci work to handle PCI pass-through to guests. Not sure what would come next.

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#69 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Paul Durrant
Quoted 13 lines · On Wed, 28 Mar 2018 10:03:29 +0000 Paul Durrant <[email protected]> wrote:
Quoted 12 lines
Quoted 5 lines

IMO a single entity should be in control of the memory layout, and that's the toolstack.

Ideally we should not allow the firmware to change the layout at all.

This approach is terribly wrong, I don't know why opinions like this so common at Citrix. The toolstack is a least informed side. If MMIO/memory layout should be immutable, it must be calculated considering all factors, like chipset-specific MMIO ranges or ranges which cannot be used for the MMIO hole.

Quoted 5 lines

Why is this approach wrong? Code running in the guest is non-privileged and we really don't want it messing around with memory layout. We really want to be in a position to e.g. build ACPI tables in the toolstack and we cannot do this until the layout becomes immutable.

Only firmware code in the guest can correctly determine guest's MMIO hole requirements (BIOS typically, but hvmloader in our case).

It is impossible to do in the toolstack at the moment, because it doesn't know at least
- MMIO BAR sizes of device-model's PCI devices
- chipset-specific MMIO ranges the DM emulates for a chosen machine
- the way these ranges are allocated to the MMIO hole by guest firmware

Even providing some interface to query all related information from a device model won't cover the problem how firmware will be allocating these ranges to the MMIO hole. Any code (or version) change can make the toolstack's expectations wrong ->

Quoted 6 lines
Quoted 5 lines

We need to know all resource requirements of device-model's and PT PCI devices, all chipset-specific MMIO ranges (which belong to a device model), all RMRRs (host's property) and all device-model invisible ranges like VRAM backing store (another device model's property).

Quoted 8 lines

Yes, indeed we do.

Quoted 4 lines

And we need to know in which manner hvmloader will be allocating BARs to the MMIO hole -- eg. either in a forward direction starting from some base or moving backwards from the end of 4Gb (minus hardcoded ranges).

Eventually we want to get rid of hvmloader.

...especially if BAR allocation will be delegated from hvmloader to other firmware like SeaBIOS/OVMF.

Quoted 4 lines

Why do we need to know
anything about its enumeration of BARs? After all they could be completely re-enumerated by the guest OS during or after boot (and indeed Windows does precisely that).

You probably confuse BAR assignment with BAR values enumeration.

Windows reallocates all PCI BARs in specific conditions only, they call this feature 'PCI resources rebalancing'. Normally it sticks to the PCI BAR allocation setup provided by firmware (hvmloader in our case). BAR reallocation doesn't really matter as long as we have a correct MMIO hole size.

The very last thing a user needs to do is guessing the correct value of the mmio_hole_size parameter, which value will be ok for all his PT devices while being not too large at the same time to leave more RAM for 32-bit guests.

Those 32-bit guests are most problematic for MMIO hole sizing. We should try to keep the MMIO hole size as small as possible to reduce RAM losses while at the same time we are not permitted to allocate any BARs to the high MMIO hole -- moving 64-bit BARs above 4Gb will automatically make such devices non-functional for 32-bit guests.

This means we need to calculate the precise MMIO hole size, according to all factors. And only firmware code in the guest can do it right.

Quoted 9 lines
Quoted 4 lines

Basically this means that we have to depend on hvmloader code/version too in the toolstack, which is wrong on its own -- we should have a freedom to modify the BAR allocation algo in hvmloader at any time.

It should be irrelevant. The toolstack should decide on the sizes and locations of the MMIO holes and they should remain fixed, and be enforced by Xen. This avoids issues that we currently have such as guests populating RAM inside MMIO holes.

The toolstack can't do it. There should be some one-time way to communicate the MMIO hole setup between Xen and hvmloader. And after that we can make it immutable.

Write-once interface via emulated platform registers (either designated for this purpose or any arbitrarily chosen) is a safe approach. We have full control of what can be provided or allowed to guest firmware via this interface. A dedicated hypercall should be ok too, but it's a bit overkill.

What is definitely not safe is to allow hvmloader to use the add_to_physmap hypercall.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#84 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Alexey Gerasimenko

tools/firmware/hvmloader/config.h extern uint8_t ioapic_version; · line 56

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/config.h +1 -0
@@ -53,10 +53,14 @@ extern uint8_t ioapic_version;
 #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
 #define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
 #define PCI_ICH9_LPC_DEVFN  0xf8    /* dev 31, fn 0 */
+#define PCI_MCH_DEVFN       0       /* bus 0, dev 0, func 0 */

Just MCH is liable to become ambiguous in the future. Perhaps PCI_Q35_MCH_DEVFN?

tools/firmware/hvmloader/config.h void pci_setup(void) · line 180

Quoted 10 lines
tools/firmware/hvmloader/config.h +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */

Why 32 bits? You only use the low few ones afaics. Also please avoid fixed width types unless you really need them.

tools/firmware/hvmloader/config.h void pci_setup(void) · line 270

Quoted 8 lines
tools/firmware/hvmloader/config.h +4 -0
@@ -259,13 +264,21 @@ void pci_setup(void)
                 bar_reg = PCI_ROM_ADDRESS;
 
             bar_data = pci_readl(devfn, bar_reg);
+
+            is_mem = !!(((bar_data & PCI_BASE_ADDRESS_SPACE) ==
+                       PCI_BASE_ADDRESS_SPACE_MEMORY) ||
+                       (bar_reg == PCI_ROM_ADDRESS));

Once you make is_mem properly bool, !! won't be needed anymore.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#111 lore raw

Re: [RFC PATCH 10/12] libacpi: build ACPI MCFG table if requested

In reply to Alexey Gerasimenko
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/libacpi/acpi2_0.h +7 -0
@@ -422,6 +422,25 @@ struct acpi_20_slit {
 };
 
 /*
+ * PCI Express Memory Mapped Configuration Description Table
+ */
+struct mcfg_range_entry {
+    uint64_t base_address;
+    uint16_t pci_segment;
+    uint8_t  start_pci_bus_num;
+    uint8_t  end_pci_bus_num;

tools/libacpi/acpi2_0.h struct acpi_20_slit { · line 441

Quoted 10 lines
tools/libacpi/acpi2_0.h +10 -0
+    uint32_t reserved;
+};
+
+struct acpi_mcfg {
+    struct acpi_header header;
+    uint8_t reserved[8];
+    struct mcfg_range_entry entries[1];
+};
+
+#define MCFG_SIZE_TO_NUM_BUSES(size)  ((size) >> 20)

In a response to a comment from Roger you suggested to move this to pci_regs.h. I don't see why it would belong there. I think if ACPI spells out such a formula somewhere, it's fine to liver here. Otherwise, since you need it in a single file only, please put it into the .c file.

Quoted 24 lines
tools/libacpi/build.c +17 -0
@@ -303,6 +303,37 @@ static struct acpi_20_slit *construct_slit(struct 
 acpi_ctxt *ctxt,
     return slit;
 }
 
+static struct acpi_mcfg *construct_mcfg(struct acpi_ctxt *ctxt,
+                                        const struct acpi_config *config)
+{
+    struct acpi_mcfg *mcfg;
+
+    /* Warning: this code expects that we have only one PCI segment */
+    mcfg = ctxt->mem_ops.alloc(ctxt, sizeof(*mcfg), 16);
+    if (!mcfg)
+        return NULL;
+
+    memset(mcfg, 0, sizeof(*mcfg));
+    mcfg->header.signature    = ACPI_MCFG_SIGNATURE;
+    mcfg->header.revision     = ACPI_1_0_MCFG_REVISION;
+    fixed_strcpy(mcfg->header.oem_id, ACPI_OEM_ID);
+    fixed_strcpy(mcfg->header.oem_table_id, ACPI_OEM_TABLE_ID);
+    mcfg->header.oem_revision = ACPI_OEM_REVISION;
+    mcfg->header.creator_id   = ACPI_CREATOR_ID;

tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct · line 333

Quoted 10 lines
tools/libacpi/build.c +10 -0
+    mcfg->header.creator_revision = ACPI_CREATOR_REVISION;
+    mcfg->header.length = sizeof(*mcfg);
+
+    mcfg->entries[0].base_address = config->mmconfig_addr;
+    mcfg->entries[0].pci_segment = 0;
+    mcfg->entries[0].start_pci_bus_num = 0;
+    mcfg->entries[0].end_pci_bus_num =
+        MCFG_SIZE_TO_NUM_BUSES(config->mmconfig_len) - 1;
+
+    set_checksum(mcfg, offsetof(struct acpi_header, checksum), sizeof(*mcfg));

Despite the numerous pre-existing examples this isn't really correct. What you mean is something like

    set_checksum(mcfg, offsetof(typeof(*mcfg), header.checksum), sizeof(*mcfg));

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#121 lore raw

Re: [RFC PATCH 11/12] hvmloader: use libacpi to build MCFG table

In reply to Alexey Gerasimenko

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 787

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/util.c +3 -0
@@ -782,6 +782,69 @@ int get_pc_machine_type(void)
     return machine_type;
 }
 
+#define PCIEXBAR_ADDR_MASK_64MB     (~((1ULL << 26) - 1))
+#define PCIEXBAR_ADDR_MASK_128MB    (~((1ULL << 27) - 1))
+#define PCIEXBAR_ADDR_MASK_256MB    (~((1ULL << 28) - 1))

I don't see the value of these constants, the more that they're generic 64/128/256 Mb masks rather than being PCIEXBAR specific. They also have no business living in pci_regs.h imo, including any of ...

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 789

Quoted 2 lines
tools/firmware/hvmloader/util.c +2 -0
+#define PCIEXBAR_LENGTH_BITS(reg)   (((reg) >> 1) & 3)
+#define PCIEXBAREN                  1

... these: Only generic fields should be described there. If you want to collect Q35 definitions in a central place, add q35.h. But if you do, please properly prefix all of them such that there won't be any risk collisions with possible future additions.

Quoted 11 lines
tools/firmware/hvmloader/util.c +11 -0
+static uint64_t mmconfig_get_base(void)
+{
+    uint64_t base;
+    uint32_t reg = pci_readl(PCI_MCH_DEVFN, PCI_MCH_PCIEXBAR);
+
+    base = reg | (uint64_t) pci_readl(PCI_MCH_DEVFN, PCI_MCH_PCIEXBAR+4) << 32;
+
+    switch (PCIEXBAR_LENGTH_BITS(reg))
+    {
+    case 0:
+        base &= PCIEXBAR_ADDR_MASK_256MB;

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 811

Quoted 10 lines
tools/firmware/hvmloader/util.c +10 -0
+        break;
+    case 1:
+        base &= PCIEXBAR_ADDR_MASK_128MB;
+        break;
+    case 2:
+        base &= PCIEXBAR_ADDR_MASK_64MB;
+        break;
+    case 3:
+        BUG();  /* a reserved value encountered */
+    }

Instead of this switch, why can't you ...

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 813

Quoted 1 line
tools/firmware/hvmloader/util.c +1 -0
+    return base;
    return base & ~(mmconfig_get_size() - 1);

here, eliminating (afaics) the need for the constants above?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#122 lore raw

Re: [RFC PATCH 11/12] hvmloader: use libacpi to build MCFG table

Quoted 15 lines · On Tue, 29 May 2018 08:46:13 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 787

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/util.c +3 -0
@@ -782,6 +782,69 @@ int get_pc_machine_type(void)
     return machine_type;
 }
 
+#define PCIEXBAR_ADDR_MASK_64MB     (~((1ULL << 26) - 1))
+#define PCIEXBAR_ADDR_MASK_128MB    (~((1ULL << 27) - 1))
+#define PCIEXBAR_ADDR_MASK_256MB    (~((1ULL << 28) - 1))  

I don't see the value of these constants, the more that they're generic 64/128/256 Mb masks rather than being PCIEXBAR specific. They also have no business living in pci_regs.h imo, including any of ...

Quoted 7 lines

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 789

Quoted 2 lines
tools/firmware/hvmloader/util.c +2 -0
+#define PCIEXBAR_LENGTH_BITS(reg)   (((reg) >> 1) & 3)
+#define PCIEXBAREN                  1  

... these: Only generic fields should be described there. If you want to collect Q35 definitions in a central place, add q35.h. But if you do, please properly prefix all of them such that there won't be any risk collisions with possible future additions.

OK, sure.

Quoted 24 lines
Quoted 11 lines
tools/firmware/hvmloader/util.c +11 -0
+static uint64_t mmconfig_get_base(void)
+{
+    uint64_t base;
+    uint32_t reg = pci_readl(PCI_MCH_DEVFN, PCI_MCH_PCIEXBAR);
+
+    base = reg | (uint64_t) pci_readl(PCI_MCH_DEVFN, PCI_MCH_PCIEXBAR+4) << 32;
+
+    switch (PCIEXBAR_LENGTH_BITS(reg))
+    {
+    case 0:
+        base &= PCIEXBAR_ADDR_MASK_256MB;

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 811

Quoted 10 lines
tools/firmware/hvmloader/util.c +10 -0
+        break;
+    case 1:
+        base &= PCIEXBAR_ADDR_MASK_128MB;
+        break;
+    case 2:
+        base &= PCIEXBAR_ADDR_MASK_64MB;
+        break;
+    case 3:
+        BUG();  /* a reserved value encountered */
+    }  

Instead of this switch, why can't you ...

Quoted 5 lines

tools/firmware/hvmloader/util.c int get_pc_machine_type(void) · line 813

Quoted 1 line
tools/firmware/hvmloader/util.c +1 -0
+    return base;  
   return base & ~(mmconfig_get_size() - 1);

here, eliminating (afaics) the need for the constants above?

I remember some MMCONFIG implementations using base alignment smaller than a possible MMCONFIG size, the code style was probably influenced by that fact. But as we deal with Q35 only, the mmconfig_get_size() for the base address mask is absolutely valid (and shorter).

In this case it will be nicer, agree. And we still have an assert for the unimplemented value (3) via the mmconfig_get_size() call to catch errors like an emulator returning 0xFF's on register reads.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#85 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Jan Beulich
Quoted 10 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/config.h extern uint8_t ioapic_version; · line 56

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/config.h +1 -0
@@ -53,10 +53,14 @@ extern uint8_t ioapic_version;
 #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
 #define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
 #define PCI_ICH9_LPC_DEVFN  0xf8    /* dev 31, fn 0 */
+#define PCI_MCH_DEVFN       0       /* bus 0, dev 0, func 0 */  

Just MCH is liable to become ambiguous in the future. Perhaps PCI_Q35_MCH_DEVFN?

Agree, PCI_Q35_MCH_DEVFN is more explicit.

Quoted 13 lines

tools/firmware/hvmloader/config.h void pci_setup(void) · line 180

Quoted 10 lines
tools/firmware/hvmloader/config.h +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */  

Why 32 bits? You only use the low few ones afaics. Also please avoid fixed width types unless you really need them.

bar_data is supposed to hold only BAR's kludge bits like 'enabled' bit values or MMCONFIG width bits. All of them occupy the low dword only while BAR's high dword is just a part of the address which will be replaced by allocated one (for mem64 BARs), thus no need to keep the high half.

So this is a sort of minor optimization -- avoiding using 64-bit operand size when 32 bit is enough.

Quoted 10 lines

tools/firmware/hvmloader/config.h void pci_setup(void) · line 270

Quoted 8 lines
tools/firmware/hvmloader/config.h +4 -0
@@ -259,13 +264,21 @@ void pci_setup(void)
                 bar_reg = PCI_ROM_ADDRESS;
 
             bar_data = pci_readl(devfn, bar_reg);
+
+            is_mem = !!(((bar_data & PCI_BASE_ADDRESS_SPACE) ==
+                       PCI_BASE_ADDRESS_SPACE_MEMORY) ||
+                       (bar_reg == PCI_ROM_ADDRESS));  

Once you make is_mem properly bool, !! won't be needed anymore.

OK, will switch to bool.

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#112 lore raw

Re: [RFC PATCH 10/12] libacpi: build ACPI MCFG table if requested

In reply to Jan Beulich
Quoted 21 lines · On Tue, 29 May 2018 08:36:49 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/libacpi/acpi2_0.h +14 -0
@@ -422,6 +422,25 @@ struct acpi_20_slit {
 };
 
 /*
+ * PCI Express Memory Mapped Configuration Description Table
+ */
+struct mcfg_range_entry {
+    uint64_t base_address;
+    uint16_t pci_segment;
+    uint8_t  start_pci_bus_num;
+    uint8_t  end_pci_bus_num;
+    uint32_t reserved;
+};
+
+struct acpi_mcfg {
+    struct acpi_header header;
+    uint8_t reserved[8];
+    struct mcfg_range_entry entries[1];
Quoted 8 lines

tools/libacpi/acpi2_0.h struct acpi_20_slit { · line 441

Quoted 3 lines
tools/libacpi/acpi2_0.h +3 -0
+};
+
+#define MCFG_SIZE_TO_NUM_BUSES(size)  ((size) >> 20)  

In a response to a comment from Roger you suggested to move this to pci_regs.h. I don't see why it would belong there. I think if ACPI spells out such a formula somewhere, it's fine to liver here. Otherwise, since you need it in a single file only, please put it into the .c file.

Agree, it is currently used in one place only, no need for .h

Quoted 38 lines
Quoted 24 lines
tools/libacpi/build.c +17 -0
@@ -303,6 +303,37 @@ static struct acpi_20_slit *construct_slit(struct 
 acpi_ctxt *ctxt,
     return slit;
 }
 
+static struct acpi_mcfg *construct_mcfg(struct acpi_ctxt *ctxt,
+                                        const struct acpi_config *config)
+{
+    struct acpi_mcfg *mcfg;
+
+    /* Warning: this code expects that we have only one PCI segment */
+    mcfg = ctxt->mem_ops.alloc(ctxt, sizeof(*mcfg), 16);
+    if (!mcfg)
+        return NULL;
+
+    memset(mcfg, 0, sizeof(*mcfg));
+    mcfg->header.signature    = ACPI_MCFG_SIGNATURE;
+    mcfg->header.revision     = ACPI_1_0_MCFG_REVISION;
+    fixed_strcpy(mcfg->header.oem_id, ACPI_OEM_ID);
+    fixed_strcpy(mcfg->header.oem_table_id, ACPI_OEM_TABLE_ID);
+    mcfg->header.oem_revision = ACPI_OEM_REVISION;
+    mcfg->header.creator_id   = ACPI_CREATOR_ID;

tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct · line 333

Quoted 10 lines
tools/libacpi/build.c +10 -0
+    mcfg->header.creator_revision = ACPI_CREATOR_REVISION;
+    mcfg->header.length = sizeof(*mcfg);
+
+    mcfg->entries[0].base_address = config->mmconfig_addr;
+    mcfg->entries[0].pci_segment = 0;
+    mcfg->entries[0].start_pci_bus_num = 0;
+    mcfg->entries[0].end_pci_bus_num =
+        MCFG_SIZE_TO_NUM_BUSES(config->mmconfig_len) - 1;
+
+    set_checksum(mcfg, offsetof(struct acpi_header, checksum), sizeof(*mcfg));  

Despite the numerous pre-existing examples this isn't really correct. What you mean is something like

Quoted 1 line
   set_checksum(mcfg, offsetof(typeof(*mcfg), header.checksum), sizeof(*mcfg));

Yes, all those set_checksum calls rely on the fact the acpi_header structure will always be the first field. It will be, but the code is technically wrong anyway.

I'll update all such set_checksum(...checksum)...) instances in the file for the next version, this is a trivial change.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#86 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Alexey G
Quoted 30 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 10 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/config.h extern uint8_t ioapic_version; · line 56

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/config.h +1 -0
@@ -53,10 +53,14 @@ extern uint8_t ioapic_version;
 #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
 #define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
 #define PCI_ICH9_LPC_DEVFN  0xf8    /* dev 31, fn 0 */
+#define PCI_MCH_DEVFN       0       /* bus 0, dev 0, func 0 */    

Just MCH is liable to become ambiguous in the future. Perhaps PCI_Q35_MCH_DEVFN?

Agree, PCI_Q35_MCH_DEVFN is more explicit.

Quoted 13 lines

tools/firmware/hvmloader/config.h void pci_setup(void) · line 180

Quoted 10 lines
tools/firmware/hvmloader/config.h +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */    

Why 32 bits? You only use the low few ones afaics. Also please avoid fixed width types unless you really need them.

Quoted 8 lines

bar_data is supposed to hold only BAR's kludge bits like 'enabled' bit values or MMCONFIG width bits. All of them occupy the low dword only while BAR's high dword is just a part of the address which will be replaced by allocated one (for mem64 BARs), thus no need to keep the high half.

So this is a sort of minor optimization -- avoiding using 64-bit operand size when 32 bit is enough.

Sorry, looks like I've misread the question. You were actually suggesting to make bar_data shorter. 8 bits is enough at the moment, so bar_data can be changed to uint8_t, yes.

Regarding avoiding using bool here -- the only reason was adapting to the existing code style. For some reason the existing hvmloader code prefers to use uint-types for bool values.

Quoted 11 lines
Quoted 10 lines

tools/firmware/hvmloader/config.h void pci_setup(void) · line 270

Quoted 8 lines
tools/firmware/hvmloader/config.h +4 -0
@@ -259,13 +264,21 @@ void pci_setup(void)
                 bar_reg = PCI_ROM_ADDRESS;
 
             bar_data = pci_readl(devfn, bar_reg);
+
+            is_mem = !!(((bar_data & PCI_BASE_ADDRESS_SPACE) ==
+                       PCI_BASE_ADDRESS_SPACE_MEMORY) ||
+                       (bar_reg == PCI_ROM_ADDRESS));    

Once you make is_mem properly bool, !! won't be needed anymore.

Quoted 6 lines

OK, will switch to bool.

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#87 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 17 lines
Quoted 14 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 10 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/config.h extern uint8_t ioapic_version; · line 56

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/config.h +1 -0
@@ -53,10 +53,14 @@ extern uint8_t ioapic_version;
 #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
 #define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
 #define PCI_ICH9_LPC_DEVFN  0xf8    /* dev 31, fn 0 */
+#define PCI_MCH_DEVFN       0       /* bus 0, dev 0, func 0 */      

Just MCH is liable to become ambiguous in the future. Perhaps PCI_Q35_MCH_DEVFN?

Quoted 1 line
Quoted 1 line

Agree, PCI_Q35_MCH_DEVFN is more explicit.

On the other thought, we can reuse one MCH BDF #define for multiple emulated chipsets, not just for something completely distinct to Q35 but even for those which mostly require merely changing PCI DIDs (like P35 etc.) So in this case producing multiple #defines like PCI_{Q|P|G}35_MCH_DEVFN for the same BDF 0:0.0 might be excessive.

PCI_ICH9_LPC_DEVFN can be actually reused too, its BDF location survived many chipset generations so its #define can be shared as well (though renamed to something like PCI_LPC_BRIDGE_DEVFN).

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

tools/firmware/hvmloader/config.h void pci_setup(void) · line 180

Quoted 10 lines
tools/firmware/hvmloader/config.h +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */      

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#88 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 26 lines
Quoted 18 lines
Quoted 1 line · On 30.05.18 at 06:32, <[email protected]> wrote:
Quoted 14 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 10 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/config.h extern uint8_t ioapic_version; · line 56

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/config.h +1 -0
@@ -53,10 +53,14 @@ extern uint8_t ioapic_version;
 #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
 #define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
 #define PCI_ICH9_LPC_DEVFN  0xf8    /* dev 31, fn 0 */
+#define PCI_MCH_DEVFN       0       /* bus 0, dev 0, func 0 */      

Just MCH is liable to become ambiguous in the future. Perhaps PCI_Q35_MCH_DEVFN?

Quoted 1 line
Quoted 1 line

Agree, PCI_Q35_MCH_DEVFN is more explicit.

On the other thought, we can reuse one MCH BDF #define for multiple emulated chipsets, not just for something completely distinct to Q35 but even for those which mostly require merely changing PCI DIDs (like P35 etc.) So in this case producing multiple #defines like PCI_{Q|P|G}35_MCH_DEVFN for the same BDF 0:0.0 might be excessive.

Quoted 3 lines

PCI_ICH9_LPC_DEVFN can be actually reused too, its BDF location survived many chipset generations so its #define can be shared as well (though renamed to something like PCI_LPC_BRIDGE_DEVFN).

PCI_x35_MCH_DEVFN then, with a brief comment explaining the x?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#90 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Alexey G
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 29.05.18 at 20:47, <[email protected]> wrote:
Quoted 23 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 14 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/pci.c void pci_setup(void) · line 180

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/pci.c +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */    

Why 32 bits? You only use the low few ones afaics. Also please avoid fixed width types unless you really need them.

bar_data is supposed to hold only BAR's kludge bits like 'enabled' bit values or MMCONFIG width bits. All of them occupy the low dword only while BAR's high dword is just a part of the address which will be replaced by allocated one (for mem64 BARs), thus no need to keep the high half.

Quoted 6 lines
Quoted 2 lines

So this is a sort of minor optimization -- avoiding using 64-bit operand size when 32 bit is enough.

Sorry, looks like I've misread the question. You were actually suggesting to make bar_data shorter. 8 bits is enough at the moment, so bar_data can be changed to uint8_t, yes.

Right.

Quoted 3 lines

Regarding avoiding using bool here -- the only reason was adapting to the existing code style. For some reason the existing hvmloader code prefers to use uint-types for bool values.

And wrongly so. We're slowly moving over, and we'd prefer the issue to not be widened by new code.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#89 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Jan Beulich
Quoted 26 lines · On Wed, 30 May 2018 02:13:30 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 26 lines
Quoted 18 lines
Quoted 1 line · On 30.05.18 at 06:32, <[email protected]> wrote:
Quoted 14 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 10 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/config.h extern uint8_t ioapic_version; · line 56

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/config.h +1 -0
@@ -53,10 +53,14 @@ extern uint8_t ioapic_version;
 #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
 #define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
 #define PCI_ICH9_LPC_DEVFN  0xf8    /* dev 31, fn 0 */
+#define PCI_MCH_DEVFN       0       /* bus 0, dev 0, func 0 */        

Just MCH is liable to become ambiguous in the future. Perhaps PCI_Q35_MCH_DEVFN?

Quoted 1 line
Quoted 1 line

Agree, PCI_Q35_MCH_DEVFN is more explicit.

On the other thought, we can reuse one MCH BDF #define for multiple emulated chipsets, not just for something completely distinct to Q35 but even for those which mostly require merely changing PCI DIDs (like P35 etc.) So in this case producing multiple #defines like PCI_{Q|P|G}35_MCH_DEVFN for the same BDF 0:0.0 might be excessive.

Quoted 5 lines
Quoted 3 lines

PCI_ICH9_LPC_DEVFN can be actually reused too, its BDF location survived many chipset generations so its #define can be shared as well (though renamed to something like PCI_LPC_BRIDGE_DEVFN).

PCI_x35_MCH_DEVFN then, with a brief comment explaining the x?

Hmm, I'm afraid there are too many chipsets sharing similarity with Q35, including x31 and x33 series. Also, it might be confusing due to existence of X-series chipsets like Intel X38.

I think it's better to rename this #define to PCI_Q35_MCH_DEVFN for now as you suggested and leave the choice of unified names for anyone (if any) who will be actually adding P35/G35/etc emulation on top of Q35's. So far we're limited to Q35 after all.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#91 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

In reply to Jan Beulich
Quoted 26 lines · On Wed, 30 May 2018 02:12:37 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 29.05.18 at 20:47, <[email protected]> wrote:
Quoted 23 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 14 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/pci.c void pci_setup(void) · line 180

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/pci.c +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */      

Why 32 bits? You only use the low few ones afaics. Also please avoid fixed width types unless you really need them.

bar_data is supposed to hold only BAR's kludge bits like 'enabled' bit values or MMCONFIG width bits. All of them occupy the low dword only while BAR's high dword is just a part of the address which will be replaced by allocated one (for mem64 BARs), thus no need to keep the high half.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

So this is a sort of minor optimization -- avoiding using 64-bit operand size when 32 bit is enough.

Sorry, looks like I've misread the question. You were actually suggesting to make bar_data shorter. 8 bits is enough at the moment, so bar_data can be changed to uint8_t, yes.

Right.

Ok, I'll switch to smaller types though not sure if it will make any significant impact I'm afraid.

In particular, bar_data will be typically used in 32/64-bit arithmetics, using a 32-bit datatype means we avoiding explicit zero extension for both 32 and 64-bit operations while for an uint8_t field the compiler will have to provide extra MOVZX instructions to embed a 8-bit operand into 32/64-bit expressions. 32-bit bar_reg can be made 16-bit in the same way but any memory usage improvements will be similarly counteracted by a requirement to use 66h-prefixed instructions for it.

Anyway, as the BAR allocation code is not memory- or time-consuming/critical, I guess any option will be good.

Quoted 6 lines
Quoted 3 lines

Regarding avoiding using bool here -- the only reason was adapting to the existing code style. For some reason the existing hvmloader code prefers to use uint-types for bool values.

And wrongly so. We're slowly moving over, and we'd prefer the issue to not be widened by new code.

BTW, there are other changes pending for hvmloader/pci.c which will (hopefully :) ) replace its BAR allocation and RMRR handling code, so this patch can be considered as sort of intermediate one -- I'm using a heavily reworked version of hvmloader/pci.c which I'd like to upstream.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#92 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 40 lines
Quoted 1 line
Quoted 1 line

Alexey G <[email protected]> 05/31/18 7:15 AM >>>

Quoted 26 lines · On Wed, 30 May 2018 02:12:37 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 29.05.18 at 20:47, <[email protected]> wrote:
Quoted 23 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 14 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

tools/firmware/hvmloader/pci.c void pci_setup(void) · line 180

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
tools/firmware/hvmloader/pci.c +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */      

Why 32 bits? You only use the low few ones afaics. Also please avoid fixed width types unless you really need them.

bar_data is supposed to hold only BAR's kludge bits like 'enabled' bit values or MMCONFIG width bits. All of them occupy the low dword only while BAR's high dword is just a part of the address which will be replaced by allocated one (for mem64 BARs), thus no need to keep the high half.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

So this is a sort of minor optimization -- avoiding using 64-bit operand size when 32 bit is enough.

Sorry, looks like I've misread the question. You were actually suggesting to make bar_data shorter. 8 bits is enough at the moment, so bar_data can be changed to uint8_t, yes.

Right.

Ok, I'll switch to smaller types though not sure if it will make any significant impact I'm afraid.

Quoted 8 lines

In particular, bar_data will be typically used in 32/64-bit arithmetics, using a 32-bit datatype means we avoiding explicit zero extension for both 32 and 64-bit operations while for an uint8_t field the compiler will have to provide extra MOVZX instructions to embed a 8-bit operand into 32/64-bit expressions. 32-bit bar_reg can be made 16-bit in the same way but any memory usage improvements will be similarly counteracted by a requirement to use 66h-prefixed instructions for it.

Hmm, yes, the space saving from using less wide types are probably indeed not worth it. But then please switch to "unsigned int" instead of uint<N>_t whenever the exact size doesn't matter.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#93 lore raw

Re: [RFC PATCH 07/12] hvmloader: allocate MMCONFIG area in the MMIO hole + minor code refactoring

Quoted 49 lines · On Thu, 31 May 2018 23:30:35 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 40 lines
Quoted 1 line
Quoted 1 line

Alexey G <[email protected]> 05/31/18 7:15 AM >>>

Quoted 26 lines · On Wed, 30 May 2018 02:12:37 -0600 "Jan Beulich" <[email protected]> wrote:
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 29.05.18 at 20:47, <[email protected]> wrote:
Quoted 23 lines · On Wed, 30 May 2018 03:56:07 +1000 Alexey G <[email protected]> wrote:
Quoted 14 lines · On Tue, 29 May 2018 08:23:51 -0600 "Jan Beulich" <[email protected]> wrote:

Review void pci_setup(void) · line 180

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 12.03.18 at 19:33, <[email protected]> wrote:
(quoted diff) +2 -1
@@ -172,10 +173,14 @@ void pci_setup(void)
 
     /* Create a list of device BARs in descending order of size. */
     struct bars {
-        uint32_t is_64bar;
         uint32_t devfn;
         uint32_t bar_reg;
         uint64_t bar_sz;
+        uint64_t addr_mask; /* which bits of the base address can be written */
+        uint32_t bar_data;  /* initial value - BAR flags here */        

Why 32 bits? You only use the low few ones afaics. Also please avoid fixed width types unless you really need them.

bar_data is supposed to hold only BAR's kludge bits like 'enabled' bit values or MMCONFIG width bits. All of them occupy the low dword only while BAR's high dword is just a part of the address which will be replaced by allocated one (for mem64 BARs), thus no need to keep the high half.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

So this is a sort of minor optimization -- avoiding using 64-bit operand size when 32 bit is enough.

Sorry, looks like I've misread the question. You were actually suggesting to make bar_data shorter. 8 bits is enough at the moment, so bar_data can be changed to uint8_t, yes.

Right.

Ok, I'll switch to smaller types though not sure if it will make any significant impact I'm afraid.

Quoted 8 lines

In particular, bar_data will be typically used in 32/64-bit arithmetics, using a 32-bit datatype means we avoiding explicit zero extension for both 32 and 64-bit operations while for an uint8_t field the compiler will have to provide extra MOVZX instructions to embed a 8-bit operand into 32/64-bit expressions. 32-bit bar_reg can be made 16-bit in the same way but any memory usage improvements will be similarly counteracted by a requirement to use 66h-prefixed instructions for it.

Quoted 3 lines

Hmm, yes, the space saving from using less wide types are probably indeed not worth it. But then please switch to "unsigned int" instead of uint<N>_t whenever the exact size doesn't matter.

Ok, will do in v2.

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel