Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Correct isPCIeDevice logic#2889

Merged
amshinde merged 1 commit into
kata-containers:masterfrom
dgibson:correct-is-pcie
Aug 24, 2020
Merged

Correct isPCIeDevice logic#2889
amshinde merged 1 commit into
kata-containers:masterfrom
dgibson:correct-is-pcie

Conversation

@dgibson
Copy link
Copy Markdown
Contributor

@dgibson dgibson commented Aug 19, 2020

Currently, isPCIeDevice() attempts to determine if a (host) device is
PCI-Express capable by looking up its link speed via the PCI slots
information in sysfs. This is a) complicated and b) wrong. PCI-e devices
don't have to have slots information, so this frequently fails.

Instead determine if devices are PCI-e by checking for the presence of
PCIe extended configuration space by looking at the size of the "config"
file in sysfs.

Fixes: #2678

Signed-off-by: David Gibson david@gibson.dropbear.id.au

@dgibson
Copy link
Copy Markdown
Contributor Author

dgibson commented Aug 19, 2020

Corrected commit message format error.

Copy link
Copy Markdown

@devimc devimc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dgibson - one nit

Comment thread virtcontainers/device/drivers/utils.go Outdated

// Plain PCI devices hav 256 bytes of configuration space,
// PCI-Express devices have 4096 bytes
return fi.Size() > 256
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't hard code this value, instead declare a const

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Currently, isPCIeDevice() attempts to determine if a (host) device is
PCI-Express capable by looking up its link speed via the PCI slots
information in sysfs.  This is a) complicated and b) wrong.  PCI-e devices
don't have to have slots information, so this frequently fails.

Instead determine if devices are PCI-e by checking for the presence of
PCIe extended configuration space by looking at the size of the "config"
file in sysfs.

Fixes: #2678

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
@dgibson
Copy link
Copy Markdown
Contributor Author

dgibson commented Aug 24, 2020

@devimc, I've addressed your most recent comments. Can we get this fix merged?

@fidencio
Copy link
Copy Markdown
Member

/test

Copy link
Copy Markdown
Member

@fidencio fidencio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgibson, thanks for the contribution!

I've started CI and made one comment inline, which is just a nitpick.

For now, let's wait till CI finishes its job before addressing that (or not). :-)

return true
}
}
deviceLogger().WithField("dev-bdf", bdf).WithField("error", err).Warning("Couldn't stat() configuration space file")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use WithError(err), instead of WithField("error", err), but that's a nitpick.

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 24, 2020

Codecov Report

Merging #2889 into master will increase coverage by 0.06%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #2889      +/-   ##
==========================================
+ Coverage   51.40%   51.46%   +0.06%     
==========================================
  Files         118      118              
  Lines       17441    17435       -6     
==========================================
+ Hits         8965     8973       +8     
+ Misses       7393     7379      -14     
  Partials     1083     1083              

Copy link
Copy Markdown

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising @dgibson !

Please could you consider raising an equivalent PR for the 2.0 branch here too: https://github.com/kata-containers/kata-containers/tree/2.0-dev/src/runtime


// Plain PCI devices hav 256 bytes of configuration space,
// PCI-Express devices have 4096 bytes
return fi.Size() > PCIConfigSpaceSize
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say it might be safer to check if the size is exactly 4096. But presumably if another PCI standard is released that would be a superset of PCI-e (as PCI-e is to PCI) so I guess this is "safe" as-is 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and my guess would be that that hypothetical extension will probably behave closer to PCI express than classic PCI.

@jodh-intel jodh-intel added the port-to-2.0 PRs that need to be ported to kata 2.0-dev branch label Aug 24, 2020
Copy link
Copy Markdown

@devimc devimc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - thanks @dgibson - please don't forget to port this to 2.0-dev

Copy link
Copy Markdown
Member

@fidencio fidencio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Feel free to adapt the code with the nitpick I mentioned or just to ignore that, as it's nothing else than a nitpick.

@amshinde amshinde merged commit 149e012 into kata-containers:master Aug 24, 2020
@amshinde
Copy link
Copy Markdown
Member

@dgibson Thanks for the fix. Can you please backport this fix to 1.10 and 1.11 branches as well along with 2.x repo.

@dgibson dgibson deleted the correct-is-pcie branch August 25, 2020 06:00
@dgibson
Copy link
Copy Markdown
Contributor Author

dgibson commented Aug 25, 2020

@dgibson Thanks for the fix. Can you please backport this fix to 1.10 and 1.11 branches as well along with 2.x repo.

I've sent a backport for 1.11 here: #2898
Backporting for 1.10 doesn't make sense, the isPCIeDevice() function doesn't exist at all there.

I'll look at 2.x later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

port-to-2.0 PRs that need to be ported to kata 2.0-dev branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PcieDevice detection fails

5 participants