Skip to content

Commit dd02c99

Browse files
committed
fix deadlock in processDVSEC
addresses one of the issue in #590 Change-Id: I71b6fee77fb5eae2694f75ee28bfb88b37142b3e
1 parent 8656a39 commit dd02c99

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/pci.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ inline void forAllIntelDevices(F f, int requestedDevice = -1, int requestedFunct
178178

179179
auto probe = [&f](const uint32 group, const uint32 bus, const uint32 device, const uint32 function)
180180
{
181+
// std::cerr << "Probing " << std::hex << group << ":" << bus << ":" << device << ":" << function << " " << std::dec << "\n";
181182
uint32 value = 0;
182183
try
183184
{
@@ -191,6 +192,7 @@ inline void forAllIntelDevices(F f, int requestedDevice = -1, int requestedFunct
191192
}
192193
const uint32 vendor_id = value & 0xffff;
193194
const uint32 device_id = (value >> 16) & 0xffff;
195+
// std::cerr << "Found dev " << std::hex << vendor_id << ":" << device_id << std::dec << "\n";
194196
if (vendor_id != PCM_INTEL_PCI_VENDOR_ID)
195197
{
196198
return;
@@ -256,12 +258,13 @@ void processDVSEC(MatchFunc matchFunc, ProcessFunc processFunc)
256258
{
257259
forAllIntelDevices([&](const uint32 group, const uint32 bus, const uint32 device, const uint32 function, const uint32 /* device_id */)
258260
{
261+
// std::cerr << "Intel device scan. found " << std::hex << group << ":" << bus << ":" << device << ":" << function << " " << device_id << std::dec;
259262
uint32 status{0};
260263
PciHandleType h(group, bus, device, function);
261264
h.read32(6, &status); // read status
262265
if (status & 0x10) // has capability list
263266
{
264-
// std::cout << "Intel device scan. found "<< std::hex << group << ":" << bus << ":" << device << ":" << function << " " << device_id << " with capability list\n" << std::dec;
267+
// std::cerr << "Intel device scan. found "<< std::hex << group << ":" << bus << ":" << device << ":" << function << " " << device_id << " with capability list\n" << std::dec;
265268
VSEC header;
266269
uint64 offset = 0x100;
267270
do
@@ -274,11 +277,11 @@ void processDVSEC(MatchFunc matchFunc, ProcessFunc processFunc)
274277
{
275278
return;
276279
}
277-
// std::cout << "offset 0x" << std::hex << offset << " header.fields.cap_id: 0x" << header.fields.cap_id << std::dec << "\n";
278-
// std::cout << ".. found entryID: 0x" << std::hex << header.fields.entryID << std::dec << "\n";
279-
if (matchFunc(header)) // UNCORE_DISCOVERY_DVSEC_ID_PMON
280+
// std::cerr << "offset 0x" << std::hex << offset << " header.fields.cap_id: 0x" << header.fields.cap_id << std::dec << "\n";
281+
// std::cerr << ".. found entryID: 0x" << std::hex << header.fields.entryID << std::dec << "\n";
282+
if (matchFunc(header))
280283
{
281-
// std::cout << ".... found UNCORE_DISCOVERY_DVSEC_ID_PMON\n";
284+
// std::cerr << ".... found match\n";
282285
auto barOffset = 0x10 + header.fields.tBIR * 4;
283286
uint32 bar = 0;
284287
if (h.read32(barOffset, &bar) == sizeof(uint32) && bar != 0) // read bar
@@ -291,7 +294,12 @@ void processDVSEC(MatchFunc matchFunc, ProcessFunc processFunc)
291294
std::cerr << "Error: can't read bar from offset " << barOffset << " \n";
292295
}
293296
}
297+
const uint64 lastOffset = offset;
294298
offset = header.fields.cap_next & ~3;
299+
if (lastOffset == offset) // the offset did not change
300+
{
301+
return; // deadlock protection
302+
}
295303
} while (1);
296304
}
297305
});

0 commit comments

Comments
 (0)