vPCI: account for hidden devices in modify_bars()
RFC PATCH 1/1 vPCI: account for hidden devices in modify_bars()
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).
xen/drivers/vpci/header.c +5 -1
@@ -206,6 +206,7 @@ static int modify_bars(const struct pci_struct vpci_header *header = &pdev->vpci->header;struct rangeset *mem =rangeset_new (NULL ,NULL ,0 );struct pci_dev *tmp, *dev =NULL ; +const struct domain *d;const struct vpci_msix *msix = pdev->vpci->msix;unsigned int i;int rc;
@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_* Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ - for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todo + for_each_pdev ( d, tmp ) {if ( tmp == pdev ) {
@@ -282,6 +284,7 @@ static int modify_bars(const struct pci_*/ continue ; } +if ( !tmp->vpci ) {ASSERT (d == dom_xen && system_state < SYS_STATE_active);continue ; }//todo for ( i =0 ; i <ARRAY_SIZE (tmp->vpci->header.bars); i++ ) {
@@ -308,6 +311,7 @@ static int modify_bars(const struct pci_ } } } +if ( !is_hardware_domain (d) )break ; }//todo ASSERT (dev);
Hello, Jan!
Quoted 24 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).xen/drivers/vpci/header.c +1
-0@@ -206,6 +206,7 @@ static int modify_bars(const struct pci_struct vpci_header *header = &pdev->vpci->header;struct rangeset *mem =rangeset_new (NULL ,NULL ,0 );struct pci_dev *tmp, *dev =NULL ; +const struct domain *d;const struct vpci_msix *msix = pdev->vpci->msix;unsigned int i;int rc;
xen/drivers/vpci/header.c static int modify_bars(const struct pci_ · line 269
Quoted 5 lines
xen/drivers/vpci/header.c +1
-1@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_* Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ -for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todo
I am not quite sure this will be correct for the cases where pdev->domain != dom0,
e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases
we'll force running the loop for dom_xen which I am not sure is desirable.
Another question is why such a hidden device has its pdev->domain not set correctly,
so we need to work this around?
Thank you,
Oleksandr
Quoted 22 lines
xen/drivers/vpci/header.c +3
-0+ for_each_pdev ( d, tmp ) {if ( tmp == pdev ) {@@ -282,6 +284,7 @@ static int modify_bars(const struct pci_*/ continue ; } +if ( !tmp->vpci ) {ASSERT (d == dom_xen && system_state < SYS_STATE_active);continue ; }//todo for ( i =0 ; i <ARRAY_SIZE (tmp->vpci->header.bars); i++ ) {@@ -308,6 +311,7 @@ static int modify_bars(const struct pci_ } } } +if ( !is_hardware_domain (d) )break ; }//todo ASSERT (dev);
Quoted 28 lines · Oleksandr Andrushchenko
Hello, Jan!
Quoted 25 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).xen/drivers/vpci/header.c +1
-0@@ -206,6 +206,7 @@ static int modify_bars(const struct pci_struct vpci_header *header = &pdev->vpci->header;struct rangeset *mem =rangeset_new (NULL ,NULL ,0 );struct pci_dev *tmp, *dev =NULL ; +const struct domain *d;const struct vpci_msix *msix = pdev->vpci->msix;unsigned int i;int rc;@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_* Check for overlaps with other BARs. Note that only BARs that are
Quoted 8 lines
xen/drivers/vpci/header.c static int modify_bars(const struct pci_ · line 269
Quoted 4 lines
xen/drivers/vpci/header.c +1
-1* currently mapped (enabled) are checked for overlaps. */ -for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todo I am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.
It is surely not desirable, but it also doesn't happen - see the is_hardware_domain() check further down (keeping context below).
Quoted 2 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?
Please see _setup_hwdom_pci_devices() and commit e46ea4d44dc0 ("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering the ASSERT() in question).
Jan
Quoted 11 lines
Quoted 10 lines
xen/drivers/vpci/header.c +1
-0@@ -308,6 +311,7 @@ static int modify_bars(const struct pci_ } } } +if ( !is_hardware_domain (d) )break ; }//todo ASSERT (dev);
Quoted 36 lines · Jan Beulich
Quoted 27 lines · Oleksandr Andrushchenko
Hello, Jan!
Quoted 24 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).xen/drivers/vpci/header.c +1
-0@@ -206,6 +206,7 @@ static int modify_bars(const struct pci_struct vpci_header *header = &pdev->vpci->header;struct rangeset *mem =rangeset_new (NULL ,NULL ,0 );struct pci_dev *tmp, *dev =NULL ; +const struct domain *d;const struct vpci_msix *msix = pdev->vpci->msix;unsigned int i;int rc;@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_Quoted 8 lines
xen/drivers/vpci/header.c static int modify_bars(const struct pci_ · line 269
Quoted 5 lines
xen/drivers/vpci/header.c +1
-1* Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ -for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todo I am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.
Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).
Right
Quoted 10 lines
Quoted 3 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).
So, why don't we set pdev->domain = dom_xen for such devices and call
modify_bars or something from pci_hide_device for instance (I didn't get too
much into implementation details though)? If pci_hide_device already handles
such exceptions, so it should also take care of the correct BAR overlaps etc.
Otherwise it looks like we put some unrelated logic into vpci which is for hiding
the devices (on x86).
Thank you,
Oleksandr
Quoted 13 lines
Jan
Quoted 10 lines
Quoted 10 lines
xen/drivers/vpci/header.c +1
-0@@ -308,6 +311,7 @@ static int modify_bars(const struct pci_ } } } +if ( !is_hardware_domain (d) )break ; }//todo ASSERT (dev);
Quoted 52 lines · Oleksandr Andrushchenko
Quoted 36 lines · Jan Beulich
Quoted 27 lines · Oleksandr Andrushchenko
Hello, Jan!
Quoted 24 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).xen/drivers/vpci/header.c +1
-0@@ -206,6 +206,7 @@ static int modify_bars(const struct pci_struct vpci_header *header = &pdev->vpci->header;struct rangeset *mem =rangeset_new (NULL ,NULL ,0 );struct pci_dev *tmp, *dev =NULL ; +const struct domain *d;const struct vpci_msix *msix = pdev->vpci->msix;unsigned int i;int rc;@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_Quoted 8 lines
xen/drivers/vpci/header.c static int modify_bars(const struct pci_ · line 269
Quoted 5 lines
xen/drivers/vpci/header.c +1
-1* Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ -for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todo I am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).Right
Quoted 10 lines
Quoted 3 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).
Quoted 4 lines
So, why don't we set
pdev->domain=dom_xenfor such devices and callmodify_barsor something frompci_hide_devicefor instance (I didn't get too much into implementation details though)? Ifpci_hide_devicealready handles such exceptions, so it should also take care of the correct BAR overlaps etc.
How would it? It runs long before Dom0 gets created, let alone when Dom0 may make adjustments to the BAR arrangement.
The temporary overriding of pdev->domain is because other IOMMU code takes the domain to act upon from that field. This could have been solved without override, but then much heavier code churn would have resulted.
Quoted 2 lines
Otherwise it looks like we put some unrelated logic into vpci which is for hiding the devices (on x86).
Hiding devices is in no way x86-specific.
Jan
Quoted 50 lines · Jan Beulich
Quoted 49 lines · Oleksandr Andrushchenko
Quoted 36 lines · Jan Beulich
Quoted 27 lines · Oleksandr Andrushchenko
Hello, Jan!
Quoted 24 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).xen/drivers/vpci/header.c +1
-0@@ -206,6 +206,7 @@ static int modify_bars(const struct pci_struct vpci_header *header = &pdev->vpci->header;struct rangeset *mem =rangeset_new (NULL ,NULL ,0 );struct pci_dev *tmp, *dev =NULL ; +const struct domain *d;const struct vpci_msix *msix = pdev->vpci->msix;unsigned int i;int rc;@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_Quoted 8 lines
xen/drivers/vpci/header.c static int modify_bars(const struct pci_ · line 269
Quoted 5 lines
xen/drivers/vpci/header.c +1
-1* Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ -for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todo I am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).Right
Quoted 9 lines
Quoted 2 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).
Quoted 6 lines
Quoted 4 lines
So, why don't we set
pdev->domain=dom_xenfor such devices and callmodify_barsor something frompci_hide_devicefor instance (I didn't get too much into implementation details though)? Ifpci_hide_devicealready handles such exceptions, so it should also take care of the correct BAR overlaps etc.How would it? It runs long before Dom0 gets created, let alone when Dom0 may make adjustments to the BAR arrangement.
So, why don't we call "yet another hide function" while creating Dom0 for that
exactly reason, e.g. BAR overlap handling? E.g. make it 2-stage hide for special
devices such as console etc.
Quoted 3 lines
The temporary overriding of
pdev->domainis because other IOMMU code takes the domain to act upon from that field.
So, you mean pdev->domain in that case is pointing to what?
Quoted 7 lines
This could have been
solved without override, but then much heavier code churn would have resulted.Quoted 2 lines
Otherwise it looks like we put some unrelated logic into vpci which is for hiding the devices (on x86).
Hiding devices is in no way x86-specific.
I mean that the use-case you have, e.g. a *PCI* console you want to hide,
is definitely not something used on Arm at least.
Quoted 3 lines
Jan
Quoted 30 lines · Oleksandr Andrushchenko
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Oleksandr Andrushchenko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksandr Andrushchenko
xen/drivers/vpci/header.c static int modify_bars(const struct pci_ · line 269
Quoted 6 lines · Jan Beulich
xen/drivers/vpci/header.c +1
-1@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_* Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ -for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todo I am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).Right
Quoted 9 lines
Quoted 2 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).So, why don't we set
pdev->domain=dom_xenfor such devices and callmodify_barsor something frompci_hide_devicefor instance (I didn't get too much into implementation details though)? Ifpci_hide_devicealready handles such exceptions, so it should also take care of the correct BAR overlaps etc.
Quoted 6 lines
Quoted 2 lines
How would it? It runs long before Dom0 gets created, let alone when Dom0 may make adjustments to the BAR arrangement.
So, why don't we call "yet another hide function" while creating Dom0 for that exactly reason, e.g. BAR overlap handling? E.g. make it 2-stage hide for special devices such as console etc.
This might be an option, but is imo going to result not only in more code churn, but also in redundant code. After all what modify_bars() needs is the union of BARs from Dom0's and DomXEN's devices.
Quoted 4 lines
Quoted 2 lines
The temporary overriding of
pdev->domainis because other IOMMU code takes the domain to act upon from that field.So, you mean
pdev->domainin that case is pointing to what?
Did you look at the function I've pointed you at? DomXEN there gets temporarily overridden to Dom0.
Quoted 10 lines
Quoted 7 lines
This could have been
solved without override, but then much heavier code churn would have resulted.Quoted 2 lines
Otherwise it looks like we put some unrelated logic into vpci which is for hiding the devices (on x86).
Hiding devices is in no way x86-specific.
I mean that the use-case you have, e.g. a *PCI* console you want to hide, is definitely not something used on Arm at least.
Not yet, that is? Why would - in the long run - somebody not want to put in a PCI serial card in a system that supports PCI and has no (available) other serial port? And if you have looked at the commit I did point you at, you will also have found that it's more than just the serial device that we hide.
Jan
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Oleksandr Andrushchenko
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Oleksandr Andrushchenko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksandr Andrushchenko
Review static int modify_bars(const struct pci_ · line 269
Quoted 6 lines · Jan Beulich
(quoted diff) +1
-1@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_ * Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ - for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todoI am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).Right
Quoted 9 lines
Quoted 2 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).So, why don't we set
pdev->domain=dom_xenfor such devices and callmodify_barsor something frompci_hide_devicefor instance (I didn't get too much into implementation details though)? Ifpci_hide_devicealready handles such exceptions, so it should also take care of the correct BAR overlaps etc.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
How would it? It runs long before Dom0 gets created, let alone when Dom0 may make adjustments to the BAR arrangement.
So, why don't we call "yet another hide function" while creating Dom0 for that exactly reason, e.g. BAR overlap handling? E.g. make it 2-stage hide for special devices such as console etc.
This might be an option, but is imo going to result not only in more code churn, but also in redundant code. After all what
modify_bars()needs is the union of BARs from Dom0's and DomXEN's devices.
To me DomXEN here is yet another workaround as strictly speaking
vpci code didn't need and doesn't(?) need it at the moment. Yes, at least on Arm.
So, I do understand why you want it there, but this then does need a very
good description of what is happening and why...
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
The temporary overriding of
pdev->domainis because other IOMMU code takes the domain to act upon from that field.So, you mean
pdev->domainin that case is pointing to what?Did you look at the function I've pointed you at? DomXEN there gets temporarily overridden to Dom0.
This looks like yet another workaround to me which is not cute.
So, the overall solution is spread over multiple subsystems, each
introducing something which is hard to follow
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
This could have been
solved without override, but then much heavier code churn would have resulted.Quoted 2 lines
Otherwise it looks like we put some unrelated logic into vpci which is for hiding the devices (on x86).
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Hiding devices is in no way x86-specific.
I mean that the use-case you have, e.g. a *PCI* console you want to hide, is definitely not something used on Arm at least.
Not yet, that is? Why would - in the long run - somebody not want to put in a PCI serial card in a system that supports PCI and has no (available) other serial port? And if you have looked at the commit I did point you at
I did
Quoted 2 lines
, you will also have found that it's more than just the serial device that we hide.
Serial was just an example from the list
Quoted 3 lines
Jan
Quoted 49 lines · Oleksandr Andrushchenko
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Oleksandr Andrushchenko
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Oleksandr Andrushchenko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksandr Andrushchenko
Review static int modify_bars(const struct pci_ · line 269
Quoted 6 lines · Jan Beulich
(quoted diff) +1
-1@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_ * Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ - for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todoI am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).Right
Quoted 9 lines
Quoted 2 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).So, why don't we set
pdev->domain=dom_xenfor such devices and callmodify_barsor something frompci_hide_devicefor instance (I didn't get too much into implementation details though)? Ifpci_hide_devicealready handles such exceptions, so it should also take care of the correct BAR overlaps etc.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
How would it? It runs long before Dom0 gets created, let alone when Dom0 may make adjustments to the BAR arrangement.
So, why don't we call "yet another hide function" while creating Dom0 for that exactly reason, e.g. BAR overlap handling? E.g. make it 2-stage hide for special devices such as console etc.
This might be an option, but is imo going to result not only in more code churn, but also in redundant code. After all what
modify_bars()needs is the union of BARs from Dom0's and DomXEN's devices.To me DomXEN here is yet another workaround as strictly speaking vpci code didn't need and doesn't(?) need it at the moment. Yes, at least on Arm. So, I do understand why you want it there, but this then does need a very good description of what is happening and why...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The temporary overriding of
pdev->domainis because other IOMMU code takes the domain to act upon from that field.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
So, you mean
pdev->domainin that case is pointing to what?Did you look at the function I've pointed you at? DomXEN there gets temporarily overridden to Dom0.
This looks like yet another workaround to me which is not cute. So, the overall solution is spread over multiple subsystems, each introducing something which is hard to follow
If you have any better suggestions, I'm all ears. Or feel free to send patches.
Jan
Quoted 48 lines · Jan Beulich
Quoted 47 lines · Oleksandr Andrushchenko
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Oleksandr Andrushchenko
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Oleksandr Andrushchenko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksandr Andrushchenko
Review static int modify_bars(const struct pci_ · line 269
Quoted 6 lines · Jan Beulich
(quoted diff) +1
-1@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_ * Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ - for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todoI am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).Right
Quoted 9 lines
Quoted 2 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).So, why don't we set
pdev->domain=dom_xenfor such devices and callmodify_barsor something frompci_hide_devicefor instance (I didn't get too much into implementation details though)? Ifpci_hide_devicealready handles such exceptions, so it should also take care of the correct BAR overlaps etc.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
How would it? It runs long before Dom0 gets created, let alone when Dom0 may make adjustments to the BAR arrangement.
So, why don't we call "yet another hide function" while creating Dom0 for that exactly reason, e.g. BAR overlap handling? E.g. make it 2-stage hide for special devices such as console etc.
This might be an option, but is imo going to result not only in more code churn, but also in redundant code. After all what
modify_bars()needs is the union of BARs from Dom0's and DomXEN's devices.To me DomXEN here is yet another workaround as strictly speaking vpci code didn't need and doesn't(?) need it at the moment. Yes, at least on Arm. So, I do understand why you want it there, but this then does need a very good description of what is happening and why...
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
The temporary overriding of
pdev->domainis because other IOMMU code takes the domain to act upon from that field.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
So, you mean
pdev->domainin that case is pointing to what?Did you look at the function I've pointed you at? DomXEN there gets temporarily overridden to Dom0.
This looks like yet another workaround to me which is not cute. So, the overall solution is spread over multiple subsystems, each introducing something which is hard to follow
If you have any better suggestions, I'm all ears. Or feel free to send patches.
Unfortunately I don't have any. But, could you please at least document a bit
more what is happening here with DomXEN: either in the commit message or
in the code itself, so it is easier to understand why vpci has this code at all...
Thank you,
Oleksandr
Quoted 3 lines
Jan
Quoted 55 lines · Oleksandr Andrushchenko
Quoted 54 lines · Jan Beulich
Quoted 53 lines · Oleksandr Andrushchenko
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Oleksandr Andrushchenko
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Oleksandr Andrushchenko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksandr Andrushchenko
Review static int modify_bars(const struct pci_ · line 269
Quoted 6 lines · Jan Beulich
(quoted diff) +1
-1@@ -265,7 +266,8 @@ static int modify_bars(const struct pci_ * Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ - for_each_pdev ( pdev->domain, tmp ) +for ( d = pdev->domain; ; d = dom_xen ) {//todoI am not quite sure this will be correct for the cases where
pdev->domain!= dom0, e.g. in the series for PCI passthrough for Arm this can be any guest. For such cases we'll force running the loop fordom_xenwhich I am not sure is desirable.Quoted 2 lines
It is surely not desirable, but it also doesn't happen - see the
is_hardware_domain()check further down (keeping context below).Right
Quoted 9 lines
Quoted 2 lines
Another question is why such a hidden device has its
pdev->domainnot set correctly, so we need to work this around?Please see
_setup_hwdom_pci_devices()and commite46ea4d44dc0("PCI: don't allow guest assignment of devices used by Xen") introducing that temporary override. To permit limited visibility to Dom0, these devices still need setting up in the IOMMU for Dom0. Consequently BAR overlap detection also needs to take these into account (i.e. the goal here is not just to prevent triggering theASSERT()in question).So, why don't we set
pdev->domain=dom_xenfor such devices and callmodify_barsor something frompci_hide_devicefor instance (I didn't get too much into implementation details though)? Ifpci_hide_devicealready handles such exceptions, so it should also take care of the correct BAR overlaps etc.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
How would it? It runs long before Dom0 gets created, let alone when Dom0 may make adjustments to the BAR arrangement.
So, why don't we call "yet another hide function" while creating Dom0 for that exactly reason, e.g. BAR overlap handling? E.g. make it 2-stage hide for special devices such as console etc.
This might be an option, but is imo going to result not only in more code churn, but also in redundant code. After all what
modify_bars()needs is the union of BARs from Dom0's and DomXEN's devices.To me DomXEN here is yet another workaround as strictly speaking vpci code didn't need and doesn't(?) need it at the moment. Yes, at least on Arm. So, I do understand why you want it there, but this then does need a very good description of what is happening and why...
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
The temporary overriding of
pdev->domainis because other IOMMU code takes the domain to act upon from that field.So, you mean
pdev->domainin that case is pointing to what?Did you look at the function I've pointed you at? DomXEN there gets temporarily overridden to Dom0.
This looks like yet another workaround to me which is not cute. So, the overall solution is spread over multiple subsystems, each introducing something which is hard to follow
Quoted 6 lines
Quoted 2 lines
If you have any better suggestions, I'm all ears. Or feel free to send patches.
Unfortunately I don't have any. But, could you please at least document a bit more what is happening here with DomXEN: either in the commit message or in the code itself, so it is easier to understand why vpci has this code at all...
Well, the commit message imo already says what needs saying. I'll extend the pre-existing code comment, though. But of course the primary purpose of this RFC is to potentially have a better approach pointed out in the first place, which I guess will mean to wait with v1 until Roger's return.
Jan
Quoted 4 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Thanks for looking into this, I certainly didn't take hidden devices into account for vPCI dom0.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).
I have a couple of questions, AFAICT we currently hide the serial console and/or the VGA adapter if it's in use by Xen.
I wonder whether we need to add vPCI handlers for those:setup_one_hwdom_device will attempt to add vPCI handlers to the hidden device because of the temporary override of pdev->domain done in _setup_hwdom_pci_devices, but I think that for hidden devices we shouldn't add vPCI handlers. We should instead block PCI config space access from dom0 to the device so that it doesn't mess with Xen usage.
It's also not clear why does Xen want to have those hidden devices partly controlled by dom0, as it would seem to me that dom0 interfering with hidden devices in use by Xen can only lead to trouble.
Thanks, Roger.
Quoted 20 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Thanks for looking into this, I certainly didn't take hidden devices into account for vPCI dom0.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).I have a couple of questions, AFAICT we currently hide the serial console and/or the VGA adapter if it's in use by Xen.
Quoted 6 lines
I wonder whether we need to add vPCI handlers for those:
setup_one_hwdom_devicewill attempt to add vPCI handlers to the hidden device because of the temporary override ofpdev->domaindone in_setup_hwdom_pci_devices, but I think that for hidden devices we shouldn't add vPCI handlers. We should instead block PCI config space access from dom0 to the device so that it doesn't mess with Xen usage.
The answer to this follows (I think) from the one below.
Quoted 3 lines
It's also not clear why does Xen want to have those hidden devices partly controlled by dom0, as it would seem to me that dom0 interfering with hidden devices in use by Xen can only lead to trouble.
Dom0 can't interfere as long as it can only read from the device. Restricting accesses to reads is one of the purposes of "hiding" (the other is to make it impossible to assign these to a DomU). Not allowing Dom0 to read from such devices would lead to wrong PCI device discovery - some devices would be missing (which may or may not be merely a cosmetic issue). If the missing device is a multi- function one at function 0, other devices in the same slot may also not be found by Dom0 (depending on whether it looks at non-zero function numbers in this case).
Jan
Quoted 34 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Thanks for looking into this, I certainly didn't take hidden devices into account for vPCI dom0.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).I have a couple of questions, AFAICT we currently hide the serial console and/or the VGA adapter if it's in use by Xen.
Quoted 6 lines
I wonder whether we need to add vPCI handlers for those:
setup_one_hwdom_devicewill attempt to add vPCI handlers to the hidden device because of the temporary override ofpdev->domaindone in_setup_hwdom_pci_devices, but I think that for hidden devices we shouldn't add vPCI handlers. We should instead block PCI config space access from dom0 to the device so that it doesn't mess with Xen usage.The answer to this follows (I think) from the one below.
Quoted 3 lines
It's also not clear why does Xen want to have those hidden devices partly controlled by dom0, as it would seem to me that dom0 interfering with hidden devices in use by Xen can only lead to trouble.
Quoted 9 lines
Dom0 can't interfere as long as it can only read from the device. Restricting accesses to reads is one of the purposes of "hiding" (the other is to make it impossible to assign these to a DomU). Not allowing Dom0 to read from such devices would lead to wrong PCI device discovery - some devices would be missing (which may or may not be merely a cosmetic issue). If the missing device is a multi- function one at function 0, other devices in the same slot may also not be found by Dom0 (depending on whether it looks at non-zero function numbers in this case).
Hm, indeed seems possible that missing function 0 the whole device is skipped.
Maybe we need a special vPCI handling for those devices that just allows reads but not writes, and that doesn't maps the BARs into dom0 p2m? Or could the BARs potentially be shared between multiple functions on the same device?
This also makes me wonder why they have to be added to the IOMMU, is that related to device groups and the fact that Xen is not clever enough to figure whether devices belong to the same IOMMU group and thus must be assigned together?
Thanks Roger.
Quoted 45 lines · Roger Pau Monné
Quoted 34 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Thanks for looking into this, I certainly didn't take hidden devices into account for vPCI dom0.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).I have a couple of questions, AFAICT we currently hide the serial console and/or the VGA adapter if it's in use by Xen.
Quoted 6 lines
I wonder whether we need to add vPCI handlers for those:
setup_one_hwdom_devicewill attempt to add vPCI handlers to the hidden device because of the temporary override ofpdev->domaindone in_setup_hwdom_pci_devices, but I think that for hidden devices we shouldn't add vPCI handlers. We should instead block PCI config space access from dom0 to the device so that it doesn't mess with Xen usage.The answer to this follows (I think) from the one below.
Quoted 3 lines
It's also not clear why does Xen want to have those hidden devices partly controlled by dom0, as it would seem to me that dom0 interfering with hidden devices in use by Xen can only lead to trouble.
Quoted 9 lines
Dom0 can't interfere as long as it can only read from the device. Restricting accesses to reads is one of the purposes of "hiding" (the other is to make it impossible to assign these to a DomU). Not allowing Dom0 to read from such devices would lead to wrong PCI device discovery - some devices would be missing (which may or may not be merely a cosmetic issue). If the missing device is a multi- function one at function 0, other devices in the same slot may also not be found by Dom0 (depending on whether it looks at non-zero function numbers in this case).
Quoted 6 lines
Hm, indeed seems possible that missing function 0 the whole device is skipped.
Maybe we need a special vPCI handling for those devices that just allows reads but not writes, and that doesn't maps the BARs into dom0 p2m?
Not sure about mapping. They could be mapped r/o. And they may actually need mapping for multi-function devices, but I guess for such devices to actually function properly then there would be more work required.
Quoted 2 lines
Or could the BARs potentially be shared between multiple functions on the same device?
I don't think that's allowed (or would even work) - if anything (like in general) small BARs may share a page, but without overlaps.
Quoted 4 lines
This also makes me wonder why they have to be added to the IOMMU, is that related to device groups and the fact that Xen is not clever enough to figure whether devices belong to the same IOMMU group and thus must be assigned together?
I'm actually not sure whether they need to be added to the IOMMU. With multi-function devices in mind, back at the time I though it would make more sense that way. But I may have been wrong, and hence we may want to revisit this. Problem with such changes is that they may cause rare issues on very specific systems, which we may have no way noticing even during a full release cycle.
Jan
Quoted 49 lines · Jan Beulich
Quoted 48 lines · Roger Pau Monné
Quoted 34 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Thanks for looking into this, I certainly didn't take hidden devices into account for vPCI dom0.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).I have a couple of questions, AFAICT we currently hide the serial console and/or the VGA adapter if it's in use by Xen.
Quoted 6 lines
I wonder whether we need to add vPCI handlers for those:
setup_one_hwdom_devicewill attempt to add vPCI handlers to the hidden device because of the temporary override ofpdev->domaindone in_setup_hwdom_pci_devices, but I think that for hidden devices we shouldn't add vPCI handlers. We should instead block PCI config space access from dom0 to the device so that it doesn't mess with Xen usage.The answer to this follows (I think) from the one below.
Quoted 3 lines
It's also not clear why does Xen want to have those hidden devices partly controlled by dom0, as it would seem to me that dom0 interfering with hidden devices in use by Xen can only lead to trouble.
Quoted 9 lines
Dom0 can't interfere as long as it can only read from the device. Restricting accesses to reads is one of the purposes of "hiding" (the other is to make it impossible to assign these to a DomU). Not allowing Dom0 to read from such devices would lead to wrong PCI device discovery - some devices would be missing (which may or may not be merely a cosmetic issue). If the missing device is a multi- function one at function 0, other devices in the same slot may also not be found by Dom0 (depending on whether it looks at non-zero function numbers in this case).
Hm, indeed seems possible that missing function 0 the whole device is skipped.
Quoted 8 lines
Quoted 3 lines
Maybe we need a special vPCI handling for those devices that just allows reads but not writes, and that doesn't maps the BARs into dom0 p2m?
Not sure about mapping. They could be mapped r/o. And they may actually need mapping for multi-function devices, but I guess for such devices to actually function properly then there would be more work required.
I'm also slightly puzzled as to why ehci-dbgp uses pci_hide_device while ns16550 uses pci_ro_device instead.
Is this because the PCI device used by ehci-dbgp must be shared with dom0 for other USB ports to be usable, and hence dom0 will need read and write access to the device PCI config space and BARs?
Note that pci_hide_device is less restrictive than pci_ro_device, as it doesn't mark the device as RO.
That would seem quite risky, as it's likely that dom0 will perform some kind of reset of the USB device and thus the console will be lost.
Quoted 5 lines
Quoted 2 lines
Or could the BARs potentially be shared between multiple functions on the same device?
I don't think that's allowed (or would even work) - if anything (like in general) small BARs may share a page, but without overlaps.
BARs sharing a page should already be handled correctly by vPCI.
Quoted 11 lines
Quoted 4 lines
This also makes me wonder why they have to be added to the IOMMU, is that related to device groups and the fact that Xen is not clever enough to figure whether devices belong to the same IOMMU group and thus must be assigned together?
I'm actually not sure whether they need to be added to the IOMMU. With multi-function devices in mind, back at the time I though it would make more sense that way. But I may have been wrong, and hence we may want to revisit this. Problem with such changes is that they may cause rare issues on very specific systems, which we may have no way noticing even during a full release cycle.
I guess it depends on whether the device is to be used by dom0, see my question above about ehci-dbgp for example.
Thanks, Roger.
Quoted 66 lines · Roger Pau Monné
Quoted 49 lines · Jan Beulich
Quoted 48 lines · Roger Pau Monné
Quoted 34 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Thanks for looking into this, I certainly didn't take hidden devices into account for vPCI dom0.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).I have a couple of questions, AFAICT we currently hide the serial console and/or the VGA adapter if it's in use by Xen.
Quoted 6 lines
I wonder whether we need to add vPCI handlers for those:
setup_one_hwdom_devicewill attempt to add vPCI handlers to the hidden device because of the temporary override ofpdev->domaindone in_setup_hwdom_pci_devices, but I think that for hidden devices we shouldn't add vPCI handlers. We should instead block PCI config space access from dom0 to the device so that it doesn't mess with Xen usage.The answer to this follows (I think) from the one below.
Quoted 3 lines
It's also not clear why does Xen want to have those hidden devices partly controlled by dom0, as it would seem to me that dom0 interfering with hidden devices in use by Xen can only lead to trouble.
Quoted 9 lines
Dom0 can't interfere as long as it can only read from the device. Restricting accesses to reads is one of the purposes of "hiding" (the other is to make it impossible to assign these to a DomU). Not allowing Dom0 to read from such devices would lead to wrong PCI device discovery - some devices would be missing (which may or may not be merely a cosmetic issue). If the missing device is a multi- function one at function 0, other devices in the same slot may also not be found by Dom0 (depending on whether it looks at non-zero function numbers in this case).
Hm, indeed seems possible that missing function 0 the whole device is skipped.
Quoted 8 lines
Quoted 3 lines
Maybe we need a special vPCI handling for those devices that just allows reads but not writes, and that doesn't maps the BARs into dom0 p2m?
Not sure about mapping. They could be mapped r/o. And they may actually need mapping for multi-function devices, but I guess for such devices to actually function properly then there would be more work required.
I'm also slightly puzzled as to why ehci-dbgp uses
pci_hide_devicewhile ns16550 usespci_ro_deviceinstead.Is this because the PCI device used by ehci-dbgp must be shared with dom0 for other USB ports to be usable, and hence dom0 will need read and write access to the device PCI config space and BARs?
Quoted 6 lines
Note that
pci_hide_deviceis less restrictive thanpci_ro_device, as it doesn't mark the device as RO.That would seem quite risky, as it's likely that dom0 will perform some kind of reset of the USB device and thus the console will be lost.
There's actually a protocol to prevent exactly that: See PHYSDEVOP_dbgp_op.
Jan
Quoted 67 lines · Jan Beulich
Quoted 66 lines · Roger Pau Monné
Quoted 49 lines · Jan Beulich
Quoted 48 lines · Roger Pau Monné
Quoted 34 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Hidden devices (e.g. an add-in PCI serial card used for Xen's serial console) are associated with DomXEN, not Dom0. This means that while looking for overlapping BARs such devices cannot be found on Dom0's list of devices; DomXEN's list also needs to be scanned.
Thanks for looking into this, I certainly didn't take hidden devices into account for vPCI dom0.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
RFC: Patch intentionally mis-formatted, as the necessary re-indentation
would make the diff difficult to read. At this point I'd merely like to gather input towards possible better approaches to solve the issue (not the least because quite possibly there are further places needing changing).I have a couple of questions, AFAICT we currently hide the serial console and/or the VGA adapter if it's in use by Xen.
Quoted 6 lines
I wonder whether we need to add vPCI handlers for those:
setup_one_hwdom_devicewill attempt to add vPCI handlers to the hidden device because of the temporary override ofpdev->domaindone in_setup_hwdom_pci_devices, but I think that for hidden devices we shouldn't add vPCI handlers. We should instead block PCI config space access from dom0 to the device so that it doesn't mess with Xen usage.The answer to this follows (I think) from the one below.
Quoted 3 lines
It's also not clear why does Xen want to have those hidden devices partly controlled by dom0, as it would seem to me that dom0 interfering with hidden devices in use by Xen can only lead to trouble.
Quoted 9 lines
Dom0 can't interfere as long as it can only read from the device. Restricting accesses to reads is one of the purposes of "hiding" (the other is to make it impossible to assign these to a DomU). Not allowing Dom0 to read from such devices would lead to wrong PCI device discovery - some devices would be missing (which may or may not be merely a cosmetic issue). If the missing device is a multi- function one at function 0, other devices in the same slot may also not be found by Dom0 (depending on whether it looks at non-zero function numbers in this case).
Hm, indeed seems possible that missing function 0 the whole device is skipped.
Quoted 8 lines
Quoted 3 lines
Maybe we need a special vPCI handling for those devices that just allows reads but not writes, and that doesn't maps the BARs into dom0 p2m?
Not sure about mapping. They could be mapped r/o. And they may actually need mapping for multi-function devices, but I guess for such devices to actually function properly then there would be more work required.
I'm also slightly puzzled as to why ehci-dbgp uses
pci_hide_devicewhile ns16550 usespci_ro_deviceinstead.Is this because the PCI device used by ehci-dbgp must be shared with dom0 for other USB ports to be usable, and hence dom0 will need read and write access to the device PCI config space and BARs?
Quoted 8 lines
Quoted 6 lines
Note that
pci_hide_deviceis less restrictive thanpci_ro_device, as it doesn't mark the device as RO.That would seem quite risky, as it's likely that dom0 will perform some kind of reset of the USB device and thus the console will be lost.
There's actually a protocol to prevent exactly that: See
PHYSDEVOP_dbgp_op.
OK, so dom0 should be allowed write access to hidden devices config space and BARs, while RO devices don't. That means that for hidden devices we need to intercept PCI config space accesses and use vPCI for PVH.
For RO devices we already allow read-only access to it's config space when using vPCI, albeit it might be nice to also add BARs as RO to the guest physmap if they are enabled.
Will look into sorting this out.
Thanks, Roger.