[lxc-devel] [lxd/master] Add IOMMU group information to resources API #7894
nzubair76 on Github
lxc-bot at linuxcontainers.org
Mon Nov 23 00:47:58 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 431 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201122/604397aa/attachment.bin>
-------------- next part --------------
From c0ce8e9f9adb2361d10e44d1c2eab9f1259ff7b6 Mon Sep 17 00:00:00 2001
From: Nabil Zubair <nzubair76 at utexas.edu>
Date: Sun, 22 Nov 2020 18:28:55 -0600
Subject: [PATCH 1/3] api: add resources_pci_iommu extension
Signed-off-by: Nabil Zubair <nzubair76 at utexas.edu>
---
doc/api-extensions.md | 3 +++
shared/version/api.go | 1 +
2 files changed, 4 insertions(+)
diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index b5ae1aa193..5fdc480d10 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -1226,3 +1226,6 @@ send/receive on top of that.
## gpu\_mdev
This adds support for virtual GPUs. It introduces the `mdev` config key for GPU devices which takes
a supported mdev type, e.g. i915-GVTg_V5_4.
+
+## resources\_pci\_iommu
+This adds the IOMMUGroup field for PCI entries in the resources API.
\ No newline at end of file
diff --git a/shared/version/api.go b/shared/version/api.go
index 55cabb5d27..12ae55eb2d 100644
--- a/shared/version/api.go
+++ b/shared/version/api.go
@@ -236,6 +236,7 @@ var APIExtensions = []string{
"tpm_device_type",
"storage_zfs_clone_copy_rebase",
"gpu_mdev",
+ "resources_pci_iommu",
}
// APIExtensionsCount returns the number of available API extensions.
From 31c3ecbc39c8a59b1afa413d5cf3cf9ecc06d3bb Mon Sep 17 00:00:00 2001
From: Nabil Zubair <nzubair76 at utexas.edu>
Date: Sun, 22 Nov 2020 18:33:03 -0600
Subject: [PATCH 2/3] shared/api: Add IOMMUGroup field to ResourcesPCIDevice
Signed-off-by: Nabil Zubair <nzubair76 at utexas.edu>
---
doc/api-extensions.md | 2 +-
shared/api/resource.go | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index 5fdc480d10..fa855624cd 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -1228,4 +1228,4 @@ This adds support for virtual GPUs. It introduces the `mdev` config key for GPU
a supported mdev type, e.g. i915-GVTg_V5_4.
## resources\_pci\_iommu
-This adds the IOMMUGroup field for PCI entries in the resources API.
\ No newline at end of file
+This adds the IOMMUGroup field for PCI entries in the resources API.
diff --git a/shared/api/resource.go b/shared/api/resource.go
index edb590b7aa..d9fd419542 100644
--- a/shared/api/resource.go
+++ b/shared/api/resource.go
@@ -371,6 +371,9 @@ type ResourcesPCIDevice struct {
ProductID string `json:"product_id" yaml:"product_id"`
Vendor string `json:"vendor" yaml:"vendor"`
VendorID string `json:"vendor_id" yaml:"vendor_id"`
+
+ // API extension: resources_pci_iommu
+ IOMMUGroup uint64 `json:"iommu_group" yaml:"iommu_group"`
}
// ResourcesSystem represents the system
From 7153df32ccd128510b2d74a373cfee70ec20e7cc Mon Sep 17 00:00:00 2001
From: Nabil Zubair <nzubair76 at utexas.edu>
Date: Sun, 22 Nov 2020 18:37:08 -0600
Subject: [PATCH 3/3] Add IOMMU group value to PCI devices
Signed-off-by: Nabil Zubair <nzubair76 at utexas.edu>
---
lxd/resources/pci.go | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lxd/resources/pci.go b/lxd/resources/pci.go
index 69c95e0bed..8f062d9f4f 100644
--- a/lxd/resources/pci.go
+++ b/lxd/resources/pci.go
@@ -2,7 +2,9 @@ package resources
import (
"io/ioutil"
+ "os"
"path/filepath"
+ "strconv"
"strings"
"github.com/jaypipes/pcidb"
@@ -116,6 +118,22 @@ func GetPCI() (*api.ResourcesPCI, error) {
}
}
+ //Get IOMMU Group
+ iommuGroupSymPath := filepath.Join(sysBusPci, device.PCIAddress, "iommu_group")
+ if sysfsExists(iommuGroupSymPath) {
+ iommuGroupPath, err := os.Readlink(iommuGroupSymPath)
+ if err != nil {
+ return nil, errors.Wrapf(err, "Failed to readlink %q", iommuGroupSymPath)
+ }
+ iommuGroup := filepath.Base(iommuGroupPath)
+ device.IOMMUGroup, err = strconv.ParseUint(iommuGroup, 10, 64)
+ if err != nil {
+ return nil, errors.Wrapf(err, "Failed to parse %q", iommuGroup)
+ }
+ } else {
+ device.IOMMUGroup = 0
+ }
+
pci.Devices = append(pci.Devices, device)
pci.Total++
}
More information about the lxc-devel
mailing list