Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add a method for binding shared virtual addressing #3014

Merged
merged 4 commits into from
Sep 22, 2023

Conversation

michael-adler
Copy link
Member

Description

Add fpgaBindSVA() to allocate and bind PASIDs to FPGA ports. Shared virtual addressing requires hardware support, both in the CPU and on the FPGA.

fpgaBindSVA() depends on /dev/dfl-pci-sva from the dfl-pci driver. IOVA-based pinned DMA remains available with older drivers and hardware that does not support PASID.

OPAE behavior is unchanged when fpgaBindSVA() is not called.

Collateral (docs, reports, design examples, case IDs):

  • Document Update Required? (Specify FIM/AFU/Scripts)

Tests added:

Tests run:

Add fpgaBindSVA() to allocate and bind PASIDs to FPGA ports. Shared
virtual addressing requires hardware support, both in the CPU and on
the FPGA.

fpgaBindSVA() depends on /dev/dfl-pci-sva from the dfl-pci driver.
IOVA-based pinned DMA remains available with older drivers and hardware
that does not support PASID.
@michael-adler michael-adler requested review from a team as code owners September 20, 2023 03:11
@coveralls
Copy link

Pull Request Test Coverage Report for Build 6243520861

  • 3 of 38 (7.89%) changed or added relevant lines in 3 files are covered.
  • 15 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.2%) to 71.808%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/libopae-c/api-shell.c 0 6 0.0%
libraries/plugins/vfio/opae_vfio.c 1 30 3.33%
Files with Coverage Reduction New Missed Lines %
libraries/plugins/xfpga/open.c 1 74.68%
libraries/plugins/uio/opae_uio.c 4 90.18%
libraries/plugins/vfio/opae_vfio.c 4 82.64%
libraries/plugins/xfpga/mmio.c 6 82.87%
Totals Coverage Status
Change from base Build 6238677251: -0.2%
Covered Lines: 15744
Relevant Lines: 21925

💛 - Coveralls

@michael-adler
Copy link
Member Author

@rweight and @matthew-gerlach - These are the user space changes that go along with the dfl-pci driver updates.

Note that the changes here will work with old drivers. They won't find /dev/dfl-pci-sva and will be fine with that.

Copy link
Contributor

@tswhison tswhison left a comment

Choose a reason for hiding this comment

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

We're adding a new top-level API, so to be complete we would also need to add C++ and Python bindings support. Just FYI, if you wanted to include the support here; else I can take it on. There are also doc updates that need to happen.

if (h->sva_fd) {
// Release PASID and shared virtual addressing
opae_close(h->sva_fd);
h->sva_fd = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

0 is actually a valid file descriptor. Could we use -1 as the closed sentinel for this?


h = handle_check_and_lock(handle);
ASSERT_NOT_NULL(h);
ASSERT_NOT_NULL(pasid);
Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to allow pasid to be NULL, this will prevent that. Better to add a NULL check at 1621 and 1642.

// then assume PASID is not supported, either by the host or the FPGA.
snprintf(path, sizeof(path), "/dev/dfl-pci-sva/%s", v->cont_pciaddr);
fd = opae_open(path, O_RDONLY);
if (fd > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (fd > 0) {
if (fd >= 0) {

0 is a valid file descriptor.

if (fd > 0) {
// Request a shared virtual addressing. On success, the PASID is
// returned.
int res = opae_ioctl(fd, DFL_PCI_SVA_BIND_DEV);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use a different name than res? res is also defined on 1607.

@michael-adler
Copy link
Member Author

@tswhison - Thanks for going through this. I'll come back to it once the low-level device mechanism is set with @rweight. The general framework here will remain, but the details down inside opae_vfio.c are in flux.

…ly if the

  module isn't available.
- Improvements to file descriptor and PASID range checks.
@michael-adler
Copy link
Member Author

@tswhison - I'm confused by the failed test at opae-sdk/tests/opae-v/test_opae_vfio_c.cpp:3246. I think I didn't change anything relevant.

I think the test causes vfio_fpgaDestroyEventHandle() to close fd 0. Seems like a bad idea.

@michael-adler
Copy link
Member Author

@tswhison - I still think that opae-sdk/tests/opae-v/test_opae_vfio_c.cpp:3246 is a broken test since it closes fd 0. I exposed that bug by causing another test to do the same thing. My case is fixed in the latest commit by adding flags for pasid so that when the handle is initialized to 0 it doesn't look like there's a file open.

@tswhison
Copy link
Contributor

Thanks for pointing this out. I will submit a fix.

@michael-adler michael-adler merged commit 90db43d into OFS:master Sep 22, 2023
@michael-adler michael-adler deleted the mcadler/bind_sva branch September 22, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants