Skip to contentSkip to conversation

vfio/pci: Fix handling of pci use accessor return codes

PATCH Applied Heiner Kallweit 3 participants 4 messages Jan 24, 2021 – Feb 2, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/pci: Fix handling of pci use accessor return codes

The pci user accessors return negative errno's on error.

Fixes f572a960a15e ("vfio/pci: Intel IGD host and LCP bridge config space access")
---
 drivers/vfio/pci/vfio_pci_igd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +5 -5
index 53d97f459..e66dfb017 100644
@@ -127,7 +127,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_byte(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		if (copy_to_user(buf + count - size, &val, 1))
 			return -EFAULT;
@@ -141,7 +141,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_word(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		val = cpu_to_le16(val);
 		if (copy_to_user(buf + count - size, &val, 2))
@@ -156,7 +156,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_dword(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		val = cpu_to_le32(val);
 		if (copy_to_user(buf + count - size, &val, 4))
@@ -171,7 +171,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_word(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		val = cpu_to_le16(val);
 		if (copy_to_user(buf + count - size, &val, 2))
@@ -186,7 +186,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_byte(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		if (copy_to_user(buf + count - size, &val, 1))
 			return -EFAULT;
Signature · 1 line
2.30.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · On Sun, 24 Jan 2021 16:35:41 +0100 Heiner Kallweit <[email protected]> wrote:

The pci user accessors return negative errno's on error.

Fixes f572a960a15e ("vfio/pci: Intel IGD host and LCP bridge config space access")
---
 drivers/vfio/pci/vfio_pci_igd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +0 -0
index 53d97f459..e66dfb017 100644

drivers/vfio/pci/vfio_pci_igd.c static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev, · line 130

Quoted 5 lines
drivers/vfio/pci/vfio_pci_igd.c +1 -1
@@ -127,7 +127,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_byte(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;

This is actually not strictly needed, as pcibios_err_to_errno() already keeps errors <= 0 unchanged, so more a cleanup than a fix?

Anyway,

Quoted 3 lines
drivers/vfio/pci/vfio_pci_igd.c +0 -0
 		if (copy_to_user(buf + count - size, &val, 1))
 			return -EFAULT;
#2 lore raw
Quoted 17 lines · Cornelia Huck
Quoted 14 lines · On Sun, 24 Jan 2021 16:35:41 +0100 Heiner Kallweit <[email protected]> wrote:

The pci user accessors return negative errno's on error.

Fixes f572a960a15e ("vfio/pci: Intel IGD host and LCP bridge config space access")
---
 drivers/vfio/pci/vfio_pci_igd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +0 -0
index 53d97f459..e66dfb017 100644
@@ -127,7 +127,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
Quoted 8 lines

drivers/vfio/pci/vfio_pci_igd.c static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev, · line 130

Quoted 4 lines
drivers/vfio/pci/vfio_pci_igd.c +1 -1
 		ret = pci_user_read_config_byte(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;

This is actually not strictly needed, as pcibios_err_to_errno() already keeps errors <= 0 unchanged, so more a cleanup than a fix?

I agree. Although I'd argue that the author of the original commit missed the fact the the user accessors return errno's, and the code just works by chance, because of the "good will" of pcibios_err_to_errno(). So up to you whether it's worth it to apply this change also to stable.

Quoted 8 lines

Anyway,

Quoted 3 lines
drivers/vfio/pci/vfio_pci_igd.c +0 -0
 		if (copy_to_user(buf + count - size, &val, 1))
 			return -EFAULT;
#3 lore raw
In reply to Heiner Kallweit
Quoted 7 lines · On Sun, 24 Jan 2021 16:35:41 +0100 Heiner Kallweit <[email protected]> wrote:

The pci user accessors return negative errno's on error.

Fixes f572a960a15e ("vfio/pci: Intel IGD host and LCP bridge config space access")
---
 drivers/vfio/pci/vfio_pci_igd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Applied to vfio next branch for v5.12 w/ Connie's R-b. I did drop the fixes tag since pcibios_err_to_errno() has always handled -errno correctly to avoid the unnecessary churn. Thanks,

Alex

Quoted 50 lines
drivers/vfio/pci/vfio_pci_igd.c +5 -5
index 53d97f459..e66dfb017 100644
@@ -127,7 +127,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_byte(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		if (copy_to_user(buf + count - size, &val, 1))
 			return -EFAULT;
@@ -141,7 +141,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_word(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		val = cpu_to_le16(val);
 		if (copy_to_user(buf + count - size, &val, 2))
@@ -156,7 +156,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_dword(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		val = cpu_to_le32(val);
 		if (copy_to_user(buf + count - size, &val, 4))
@@ -171,7 +171,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_word(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		val = cpu_to_le16(val);
 		if (copy_to_user(buf + count - size, &val, 2))
@@ -186,7 +186,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev,
 
 		ret = pci_user_read_config_byte(pdev, pos, &val);
 		if (ret)
-			return pcibios_err_to_errno(ret);
+			return ret;
 
 		if (copy_to_user(buf + count - size, &val, 1))
 			return -EFAULT;