Skip to contentSkip to conversation

libxl: tooling expects wrong errno

PATCH In review Grzegorz Uriasz 5 participants 9 messages Jun 14, 2020 – Jun 26, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: tooling expects wrong errno

When iommu is not enabled for a given domain then pci passthrough hypercalls such as xc_test_assign_device return EOPNOTSUPP. The code responsible for this is in "iommu_do_domctl" inside xen/drivers/passthrough/iommu.c
This patch fixes the error message reported by libxl when assigning pci devices to domains without iommu.

---
 tools/libxl/libxl_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_pci.c +1 -1
index 957ff5c8e9..bc5843b137 100644
@@ -1561,7 +1561,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
             LOGD(ERROR, domid,
                  "PCI device %04x:%02x:%02x.%u %s?",
                  pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func,
-                 errno == ENOSYS ? "cannot be assigned - no IOMMU"
+                 errno == EOPNOTSUPP ? "cannot be assigned - no IOMMU"
                  : "already assigned to a different guest");
             goto out;
         }
Signature · 1 line
2.27.0
#1 lore raw

Grzegorz Uriasz writes ("[PATCH] libxl: tooling expects wrong errno"):

Quoted 18 lines

When iommu is not enabled for a given domain then pci passthrough hypercalls such as xc_test_assign_device return EOPNOTSUPP. The code responsible for this is in "iommu_do_domctl" inside xen/drivers/passthrough/iommu.c
This patch fixes the error message reported by libxl when assigning pci devices to domains without iommu.

---
 tools/libxl/libxl_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_pci.c +0 -0
index 957ff5c8e9..bc5843b137 100644

tools/libxl/libxl_pci.c void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, · line 1567

Quoted 8 lines
tools/libxl/libxl_pci.c +1 -1
@@ -1561,7 +1561,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
             LOGD(ERROR, domid,
                  "PCI device %04x:%02x:%02x.%u %s?",
                  pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func,
-                 errno == ENOSYS ? "cannot be assigned - no IOMMU"
+                 errno == EOPNOTSUPP ? "cannot be assigned - no IOMMU"
                  : "already assigned to a different guest");
             goto out;
         }

Thanks. I have addressed some Xen IOMMU maintainers. Can you confirm whether this is right ?

Regards,
Ian.

#2 lore raw
Quoted 14 lines · Ian Jackson

Grzegorz Uriasz writes ("[PATCH] libxl: tooling expects wrong errno"):

Quoted 13 lines

When iommu is not enabled for a given domain then pci passthrough hypercalls such as xc_test_assign_device return EOPNOTSUPP. The code responsible for this is in "iommu_do_domctl" inside xen/drivers/passthrough/iommu.c
This patch fixes the error message reported by libxl when assigning pci devices to domains without iommu.

---
 tools/libxl/libxl_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

tools/libxl/libxl_pci.c void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, · line 1567

Quoted 13 lines
tools/libxl/libxl_pci.c +1 -1
index 957ff5c8e9..bc5843b137 100644
@@ -1561,7 +1561,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
             LOGD(ERROR, domid,
                  "PCI device %04x:%02x:%02x.%u %s?",
                  pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func,
-                 errno == ENOSYS ? "cannot be assigned - no IOMMU"
+                 errno == EOPNOTSUPP ? "cannot be assigned - no IOMMU"
                  : "already assigned to a different guest");
             goto out;
         }

Thanks. I have addressed some Xen IOMMU maintainers. Can you confirm whether this is right ?

Not an IOMMU maintainer myself, but I've taken a look at the code and I think Grzegorz is right. iommu_do_domctl will return -EOPNOTSUPP if the IOMMU is not enabled for the domain. Another option would be to check for EBUSY (which will certainly be returned when the device is busy) and log the error code with a message when it's different than EBUSY?

There are many possible error here, for example the device itself might not be behind an IOMMU, in which case Xen will return -ENODEV at least on the Intel case.

Thanks, Roger.

#3 lore raw
Quoted 49 lines

-----Original Message-----
From: Roger Pau Monné <[email protected]>
Sent: 15 June 2020 16:57
To: Ian Jackson <[email protected]>
Cc: Grzegorz Uriasz <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Kevin Tian <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; [email protected]; Anthony Perard <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] libxl: tooling expects wrong errno

Quoted 14 lines · Ian Jackson

Grzegorz Uriasz writes ("[PATCH] libxl: tooling expects wrong errno"):

Quoted 13 lines

When iommu is not enabled for a given domain then pci passthrough hypercalls such as xc_test_assign_device return EOPNOTSUPP. The code responsible for this is in "iommu_do_domctl" inside xen/drivers/passthrough/iommu.c
This patch fixes the error message reported by libxl when assigning pci devices to domains without iommu.

---
 tools/libxl/libxl_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

tools/libxl/libxl_pci.c void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, · line 1567

Quoted 13 lines
tools/libxl/libxl_pci.c +1 -1
index 957ff5c8e9..bc5843b137 100644
@@ -1561,7 +1561,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
             LOGD(ERROR, domid,
                  "PCI device %04x:%02x:%02x.%u %s?",
                  pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func,
-                 errno == ENOSYS ? "cannot be assigned - no IOMMU"
+                 errno == EOPNOTSUPP ? "cannot be assigned - no IOMMU"
                  : "already assigned to a different guest");
             goto out;
         }

Thanks. I have addressed some Xen IOMMU maintainers. Can you confirm whether this is right ?

Not an IOMMU maintainer myself, but I've taken a look at the code and I think Grzegorz is right. iommu_do_domctl will return -EOPNOTSUPP if the IOMMU is not enabled for the domain. Another option would be to check for EBUSY (which will certainly be returned when the device is busy) and log the error code with a message when it's different than EBUSY?

Quoted 3 lines

There are many possible error here, for example the device itself might not be behind an IOMMU, in which case Xen will return -ENODEV at least on the Intel case.

ENOSYS is certainly wrong; it should only be used to indicate an unimplemented hypercall. I think Roger's suggestion of avoiding EBUSY and use LOGED would be better though.

Paul

Quoted 2 lines

Thanks, Roger.

Acked-by
#4 lore raw
In reply to Roger Pau Monné

Roger Pau Monne writes ("Re: [PATCH] libxl: tooling expects wrong errno"):

Quoted 39 lines · Ian Jackson
Quoted 14 lines

Grzegorz Uriasz writes ("[PATCH] libxl: tooling expects wrong errno"):

Quoted 13 lines

When iommu is not enabled for a given domain then pci passthrough hypercalls such as xc_test_assign_device return EOPNOTSUPP. The code responsible for this is in "iommu_do_domctl" inside xen/drivers/passthrough/iommu.c
This patch fixes the error message reported by libxl when assigning pci devices to domains without iommu.

---
 tools/libxl/libxl_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

tools/libxl/libxl_pci.c void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, · line 1567

Quoted 13 lines
tools/libxl/libxl_pci.c +1 -1
index 957ff5c8e9..bc5843b137 100644
@@ -1561,7 +1561,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
             LOGD(ERROR, domid,
                  "PCI device %04x:%02x:%02x.%u %s?",
                  pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func,
-                 errno == ENOSYS ? "cannot be assigned - no IOMMU"
+                 errno == EOPNOTSUPP ? "cannot be assigned - no IOMMU"
                  : "already assigned to a different guest");
             goto out;
         }

Thanks. I have addressed some Xen IOMMU maintainers. Can you confirm whether this is right ?

Not an IOMMU maintainer myself, but I've taken a look at the code and I think Grzegorz is right. iommu_do_domctl will return -EOPNOTSUPP if the IOMMU is not enabled for the domain. Another option would be to check for EBUSY (which will certainly be returned when the device is busy) and log the error code with a message when it's different than EBUSY?

Quoted 3 lines

There are many possible error here, for example the device itself might not be behind an IOMMU, in which case Xen will return -ENODEV at least on the Intel case.

Thanks for the analysis. So:

This would seem to be a backport candidate. AFAICT check has been there, looking for ENOSYS, since this code was introduced in
826eb17271d3c647516d9944c47b0779afedea25
libxl: suppress device assignment to HVM guest when there is no IOMMU
?

But that commit has a Tested-by. Maybe Xen changed its error return at some point ?

Ian.

#5 lore raw
Quoted 58 lines

-----Original Message-----
From: Ian Jackson <[email protected]>
Sent: 15 June 2020 17:38
To: Roger Pau Monne <[email protected]>
Cc: Grzegorz Uriasz <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Kevin Tian <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; [email protected]; [email protected]; [email protected]; Anthony Perard <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] libxl: tooling expects wrong errno

Roger Pau Monne writes ("Re: [PATCH] libxl: tooling expects wrong errno"):

Quoted 39 lines · Ian Jackson
Quoted 14 lines

Grzegorz Uriasz writes ("[PATCH] libxl: tooling expects wrong errno"):

Quoted 13 lines

When iommu is not enabled for a given domain then pci passthrough hypercalls such as xc_test_assign_device return EOPNOTSUPP. The code responsible for this is in "iommu_do_domctl" inside xen/drivers/passthrough/iommu.c
This patch fixes the error message reported by libxl when assigning pci devices to domains without iommu.

---
 tools/libxl/libxl_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

tools/libxl/libxl_pci.c void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, · line 1567

Quoted 13 lines
tools/libxl/libxl_pci.c +1 -1
index 957ff5c8e9..bc5843b137 100644
@@ -1561,7 +1561,7 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,
             LOGD(ERROR, domid,
                  "PCI device %04x:%02x:%02x.%u %s?",
                  pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func,
-                 errno == ENOSYS ? "cannot be assigned - no IOMMU"
+                 errno == EOPNOTSUPP ? "cannot be assigned - no IOMMU"
                  : "already assigned to a different guest");
             goto out;
         }

Thanks. I have addressed some Xen IOMMU maintainers. Can you confirm whether this is right ?

Not an IOMMU maintainer myself, but I've taken a look at the code and I think Grzegorz is right. iommu_do_domctl will return -EOPNOTSUPP if the IOMMU is not enabled for the domain. Another option would be to check for EBUSY (which will certainly be returned when the device is busy) and log the error code with a message when it's different than EBUSY?

Quoted 3 lines

There are many possible error here, for example the device itself might not be behind an IOMMU, in which case Xen will return -ENODEV at least on the Intel case.

Thanks for the analysis. So:

Quoted 9 lines

This would seem to be a backport candidate. AFAICT check has been there, looking for ENOSYS, since this code was introduced in
826eb17271d3c647516d9944c47b0779afedea25
libxl: suppress device assignment to HVM guest when there is no IOMMU
?

But that commit has a Tested-by. Maybe Xen changed its error return at some point ?

Yes, it happened in 71e617a6b8f69849c70eda1b3c58f1ff6b244e5a use is_iommu_enabled() where appropriate...

Paul

Quoted 1 line

Ian.

#6 lore raw

Paul Durrant writes ("RE: [PATCH] libxl: tooling expects wrong errno"):

Quoted 12 lines
Quoted 12 lines

-----Original Message-----
From: Ian Jackson <[email protected]>
Thanks for the analysis. So:

This would seem to be a backport candidate. AFAICT check has been there, looking for ENOSYS, since this code was introduced in
826eb17271d3c647516d9944c47b0779afedea25
libxl: suppress device assignment to HVM guest when there is no IOMMU
?

Quoted 6 lines
Quoted 3 lines

But that commit has a Tested-by. Maybe Xen changed its error return at some point ?

Yes, it happened in 71e617a6b8f69849c70eda1b3c58f1ff6b244e5a use is_iommu_enabled() where appropriate...

So,

Backport: 4.13

Thanks!

Ian.

#7 lore raw
Quoted 17 lines · Ian Jackson

Paul Durrant writes ("RE: [PATCH] libxl: tooling expects wrong errno"):

Quoted 16 lines
Quoted 15 lines

-----Original Message-----
From: Ian Jackson <[email protected]>
Thanks for the analysis. So:

This would seem to be a backport candidate. AFAICT check has been there, looking for ENOSYS, since this code was introduced in
826eb17271d3c647516d9944c47b0779afedea25
libxl: suppress device assignment to HVM guest when there is no IOMMU
?

But that commit has a Tested-by. Maybe Xen changed its error return at some point ?

Quoted 8 lines
Quoted 2 lines

Yes, it happened in 71e617a6b8f69849c70eda1b3c58f1ff6b244e5a use is_iommu_enabled() where appropriate...

So,

Backport: 4.13

Thanks!

This is not yet committed. Paul, can I get a release ack from you?

Wei.

Quoted 2 lines

Ian.

#8 lore raw
Quoted 34 lines

-----Original Message-----
From: Wei Liu <[email protected]>
Sent: 26 June 2020 12:25
To: Ian Jackson <[email protected]>
Cc: [email protected]; Roger Pau Monne <[email protected]>; 'Grzegorz Uriasz' <[email protected]>; 'Jan Beulich' <[email protected]>; Andrew Cooper <[email protected]>; Kevin Tian <[email protected]>; 'Wei Liu' <[email protected]>; [email protected]; [email protected]; [email protected]; Anthony Perard <[email protected]>; xen- [email protected]; [email protected]
Subject: Re: [PATCH] libxl: tooling expects wrong errno

Quoted 22 lines · Ian Jackson

Paul Durrant writes ("RE: [PATCH] libxl: tooling expects wrong errno"):

Quoted 12 lines
Quoted 12 lines

-----Original Message-----
From: Ian Jackson <[email protected]>
Thanks for the analysis. So:

This would seem to be a backport candidate. AFAICT check has been there, looking for ENOSYS, since this code was introduced in
826eb17271d3c647516d9944c47b0779afedea25
libxl: suppress device assignment to HVM guest when there is no IOMMU
?

Quoted 6 lines
Quoted 3 lines

But that commit has a Tested-by. Maybe Xen changed its error return at some point ?

Yes, it happened in 71e617a6b8f69849c70eda1b3c58f1ff6b244e5a use is_iommu_enabled() where appropriate...

So,

Quoted 7 lines
Quoted 3 lines

Backport: 4.13

Thanks!

This is not yet committed. Paul, can I get a release ack from you?

Wei.

Yes.

Quoted 3 lines
Quoted 3 lines

Ian.