Skip to content

File I/O DMA region access mode#842

Open
mnissler-rivos wants to merge 2 commits intonutanix:masterfrom
mnissler-rivos:file_access_mode
Open

File I/O DMA region access mode#842
mnissler-rivos wants to merge 2 commits intonutanix:masterfrom
mnissler-rivos:file_access_mode

Conversation

@mnissler-rivos
Copy link
Copy Markdown
Contributor

This PR adds a new mode to perform DMA operations using file I/O system calls. This is useful in cases where the client can supply a file descriptor, but the file descriptor doesn't support mmap(). This is the case for /proc/<pid>/mem for example, which can be used to give the server access to the client's address space.

This adds an enum to convey how a DMA region is to be accessed. Previously,
this was implicit in the presence of a file descriptor in the DMA region
tracking information. With this change, a new file I/O access mode is added
that designates accesses should happen via file I/O syscalls, such as
`pread()`/`pwrite()`. This is useful for file descriptors that don't support
`mmap()`, such as `/proc/<pid>/mem`. The access mode to be used is determined
from new flag bits in the VFIO_USER_DMA_MAP message, and the message handler
makes sure the passed flags and file descriptor presence are consistent.
Existing code is updated to use the access mode in conditionals rather than
testing file descriptor presence.

Signed-off-by: Mattias Nissler <mnissler@meta.com>
When performing DMA from/to a caller-supplied buffer via `vfu_sgl_write`
and `vfu_sgl_read`, respectively, we can use file descriptor based
access modes as configured for the region, rather than servicing the DMA
operation via IPC unconditionally.

Signed-off-by: Mattias Nissler <mnissler@meta.com>
@mnissler-rivos mnissler-rivos marked this pull request as ready for review April 9, 2026 13:47
Copy link
Copy Markdown
Collaborator

@jlevon jlevon left a comment

Choose a reason for hiding this comment

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

Not sure I'm quite clear on the use case - when would I be sharing something like /proc files with the server?

return ERROR_INT(EPERM);
}

if (sg->region->access_mode == REGION_ACCESS_MODE_MMAP) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hmm, there may be good reasons to want the client to service dma read/write even in the case of MODE_FILE_IO or MODE_MMAP. I wonder if we want a flags param for vfu_dma/read_write() so users can request this if needed?

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.

That thought crossed my mind as well. Can you think of any plausible reasons though? If the client did provide a file descriptor at registration time, it seems only fair that we use it :-D

I'll be happy to add parameter (or make separate functions) though if you think that's the best way forward.

uint32_t argsz;
#define VFIO_USER_F_DMA_REGION_READ (1 << 0)
#define VFIO_USER_F_DMA_REGION_WRITE (1 << 1)
#define VFIO_USER_F_DMA_REGION_MMAP (1 << 2)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this will need a qemu update to the protocol definition please, as well as ideally updating the qemu headers.

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.

Yes, I'll be happy to send a patch for that, but wanted to align on the overall proposal here first.

@mnissler-rivos
Copy link
Copy Markdown
Contributor Author

Not sure I'm quite clear on the use case - when would I be sharing something like /proc files with the server?

This is for a case where a non-VMM client wants to expose buffers to the server, and it isn't feasible in practice to change all memory allocation code paths in the client to use memfd_create (or equivalent) rather than malloc.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants