Skip to content

Commit 156970a

Browse files
author
Dmitry Rozhkov
authored
Merge pull request #185 from mythi/iommu
qat_plugin: kerneldrv: register VF devices when IOMMU is on
2 parents b54161f + 4ba6af1 commit 156970a

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

cmd/qat_plugin/kerneldrv/kerneldrv.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func newDevicePlugin(configDir string, execer utilsexec.Interface) *DevicePlugin
134134
}
135135
}
136136

137-
func (dp *DevicePlugin) getOnlineDevices() ([]device, error) {
137+
func (dp *DevicePlugin) getOnlineDevices(iommuOn bool) ([]device, error) {
138138
outputBytes, err := dp.execer.Command("adf_ctl", "status").CombinedOutput()
139139
if err != nil {
140140
return nil, errors.Wrapf(err, "Can't get driver status")
@@ -152,6 +152,11 @@ func (dp *DevicePlugin) getOnlineDevices() ([]device, error) {
152152
continue
153153
}
154154

155+
// "Cannot use PF with IOMMU enabled"
156+
if iommuOn != strings.HasSuffix(matches[1], "vf") {
157+
continue
158+
}
159+
155160
devices = append(devices, device{
156161
id: fmt.Sprintf("dev%s", matches[2]),
157162
devtype: matches[1],
@@ -281,10 +286,28 @@ func (drvConfig driverConfig) update(devID string, iniSection *ini.Section) erro
281286
return nil
282287
}
283288

289+
func getIOMMUStatus() (bool, error) {
290+
iommus, err := ioutil.ReadDir("/sys/class/iommu/")
291+
if err != nil {
292+
return false, errors.Wrapf(err, "Unable to read IOMMU status")
293+
}
294+
295+
if len(iommus) > 0 {
296+
return true, nil
297+
}
298+
299+
return false, nil
300+
}
301+
284302
// Scan implements Scanner interface for kernel based QAT plugin.
285303
func (dp *DevicePlugin) Scan(notifier dpapi.Notifier) error {
286304
for {
287-
devices, err := dp.getOnlineDevices()
305+
iommuOn, err := getIOMMUStatus()
306+
if err != nil {
307+
return err
308+
}
309+
310+
devices, err := dp.getOnlineDevices(iommuOn)
288311
if err != nil {
289312
return err
290313
}

cmd/qat_plugin/kerneldrv/kerneldrv_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ There is 3 QAT acceleration device(s) in the system:
4444
qat_dev0 - type: c6xx, inst_id: 0, node_id: 0, bsf: 3b:00.0, #accel: 5 #engines: 10 state: up
4545
qat_dev1 - type: c6xx, inst_id: 1, node_id: 0, bsf: 3d:00.0, #accel: 5 #engines: 10 state: down
4646
qat_dev2 - type: c6xx, inst_id: 2, node_id: 3, bsf: d8:00.0, #accel: 5 #engines: 10 state: up
47+
`
48+
adfCtlOutputVf = `Checking status of all devices.
49+
There is 7 QAT acceleration device(s) in the system:
50+
qat_dev0 - type: c6xx, inst_id: 0, node_id: 0, bsf: 0000:3b:00.0, #accel: 5 #engines: 10 state: up
51+
qat_dev1 - type: c6xx, inst_id: 1, node_id: 0, bsf: 0000:3b:00.0, #accel: 5 #engines: 10 state: up
52+
qat_dev2 - type: c6xx, inst_id: 2, node_id: 3, bsf: 0000:3b:00.0, #accel: 5 #engines: 10 state: up
53+
qat_dev3 - type: c6xxvf, inst_id: 0, node_id: 0, bsf: 0000:3b:01.0, #accel: 1 #engines: 1 state: up
54+
qat_dev4 - type: c6xxvf, inst_id: 1, node_id: 0, bsf: 0000:3b:01.1, #accel: 1 #engines: 1 state: up
55+
qat_dev5 - type: c6xxvf, inst_id: 2, node_id: 0, bsf: 0000:3b:01.2, #accel: 1 #engines: 1 state: up
56+
qat_dev6 - type: c6xxvf, inst_id: 3, node_id: 0, bsf: 0000:3b:01.3, #accel: 1 #engines: 1 state: up
4757
`
4858
)
4959

@@ -58,16 +68,25 @@ func TestGetOnlineDevices(t *testing.T) {
5868
adfCtlError error
5969
expectedDevNum int
6070
expectedErr bool
71+
iommuOn bool
6172
}{
6273
{
6374
name: "all is good",
6475
adfCtlOutput: adfCtlOutput,
6576
expectedDevNum: 3,
77+
iommuOn: false,
6678
},
6779
{
6880
name: "one device is down",
6981
adfCtlOutput: adfCtlOutputOneDown,
7082
expectedDevNum: 2,
83+
iommuOn: false,
84+
},
85+
{
86+
name: "virtual functions enabled",
87+
adfCtlOutput: adfCtlOutputVf,
88+
expectedDevNum: 4,
89+
iommuOn: true,
7190
},
7291
{
7392
name: "adf_ctl fails to run",
@@ -94,7 +113,7 @@ func TestGetOnlineDevices(t *testing.T) {
94113
dp := &DevicePlugin{
95114
execer: &execer,
96115
}
97-
devices, err := dp.getOnlineDevices()
116+
devices, err := dp.getOnlineDevices(tt.iommuOn)
98117
if tt.expectedErr && err == nil {
99118
t.Error("Expected error hasn't been triggered")
100119
}

0 commit comments

Comments
 (0)