aboutsummaryrefslogtreecommitdiff
path: root/lib/dma.h
AgeCommit message (Collapse)AuthorFilesLines
2021-08-19dma: cleanup dma_{map,unmap}_sg (#591)Swapnil Ingle1-20/+28
* dma: cleanup dma_{map,unmap}_sg Instead of using index to traverse sg and iovec, better to use it as pointers. It's more readable and less prone from coding mistakes. Also adding unit tests for the same. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-08-17fix dma_{map,unmap}_sg() array handling (#586)John Levon1-6/+6
Multiple places in dma_map_sg() and dma_unmap_sg() were dereferencing sg[0] instead of the correct index. Take the opportunity to improve the doc comments at the same time. Reported-by: Changpeng Liu <changpeng.liu@intel.com> Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-06-09clear dirty pages bitmap after getting dirty pages but keep mapped segments ↵Thanos Makatos1-14/+26
dirty (#551) Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-06-01limit max DMA region size (#545)John Levon1-1/+2
Since the dirty bitmap in message replies is allocated based upon the maximum size of an individual region, add a limit (somewhat arbitrarily 8TiB, which is a bitmap size of 256MiB). Add a couple of basic tests on the two DMA limits. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-05-25don't treat DMA segment as absolute when determining dirty page bit (#519)Thanos Makatos1-28/+2
New DMA regions don't get their pages tracked if dirty page logging has already been started, this patch fixes this bug. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-05-14dma: Use correct len type (#479)Swapnil Ingle1-3/+4
* dma: Use correct len type vfio_iommu_type1_dirty_bitmap_get.size is of type __u64 dma_controller_dirty_page_get() receives it as int, instead it should be u64 Also added UT to test overflow of length passed to dma_controller_dirty_page_get Fixes: #477 Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
2021-05-10fix dma unregister callback during region removal (#464)John Levon1-1/+3
There are two issues with the unregister callback: - we were requiring the callback to be set when removing a region, but it's only required if a consumer wants to map regions - when we removed all regions (for example, on a reset), we weren't triggering the callback Signed-off-by: John Levon <john.levon@nutanix.com> swapnil code review add assert Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-04-14libvfio-user.c: use ERROR_INT() (#433)John Levon1-1/+1
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-13dma: use ERROR_INT()John Levon1-7/+6
The first in a series excising the use of the "return -errno" idiom. This is a non-standard usage, and in userspace, we have "errno" for delivering side-band error values. As there have been multiple bugs from not using standard error return methods like -1+errno or NULL+errno, let's do that. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-13correct DMA region add/remove returns (#427)John Levon1-3/+1
Code was expecting -errno style returns, but the DMA code didn't do this. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-07clean up newlines in logs (#423)John Levon1-2/+2
vfu_log() and err() should not take newlines. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-07mark vfu_log() with format attribute (#426)John Levon1-3/+4
Fix up all resulting fallout. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-04-06vfu_reset_ctx(): tear down DMA and IRQs (#418)John Levon1-0/+3
When we lose the client connection, the IRQ and DMA region state is no longer valid; clean them up. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-31rework DMA callbacks (#396)John Levon1-76/+32
This fixes a number of issues with how DMA is handled, based on some changes by Thanos Makatos: - rename callbacks to register/unregister, as there is not necessarily any mapping - provide the (large) page-aligned mapped start and size, the page size used, as well as the protection flags: some API users need these - for convenience, provide the virtual address separately that corresponds to the mapped region - we should only require a DMA controller to use vfu_addr_to_sg(), not an unregister callback - the callbacks should return errno not -errno - region removal was incorrectly updating the region array - various other cleanups and clarifications Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-25re-work unit test mocking (#400)John Levon1-9/+10
Instead of trying to use the linker's --wrap, which just led to more problems when we want to call the real function, we'll add two defines, MOCK_DEFINE() and MOCK_DECLARE(), that behave differently when building the unit tests, such that all wrapped functions are picked up from test/mocks.c instead, regardless of compilation unit. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-03-23add -Wmissing-declarations (#399)John Levon1-11/+10
This is used by SPDK, and it's generally useful. This also uncovered some issues in the test mocking. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2021-02-18use UNUSED consistently (#350)John Levon1-3/+0
Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-21Misc fixes for DMA_MAP region prot (#233)swapnili1-4/+18
* Misc fixes for DMA_MAP region prot 1. Validate prot passed in vfu_addr_to_sg() 2. Let user know region prot via vfu_unmap_dma_cb_t Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2021-01-08Use prot flags sent by client to map dma regions (#227)swapnili1-1/+4
* Use prot flags sent by client to map dma regions Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-17add mappable bit in DMA segment (#215)Thanos Makatos1-7/+16
remove duplicate code for initializing DMA segment, mark DMA segment whether it's mappable, plus basic unit test for dma_addr_to_sg Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-17fail to map segment if DMA region isn't backed by file descriptorThanos Makatos1-1/+4
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-17validate region is segmentThanos Makatos1-0/+8
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-12-02use log level defines from syslogThanos Makatos1-2/+2
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-11-27rename to libvfio-user (#128)John Levon1-10/+10
The muser name no longer reflects the implementation, and will just serve to confuse. Bite the bullet now, and rename ourselves to reflect the actual implementation. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2020-11-24Api refactoring (#115)swapnili1-1/+2
API refactoring
2020-11-24clean up headersJohn Levon1-3/+3
Introduce include/ dir for public headers, and clean up include guards etc.
2020-11-17Fix compiler errors for non-dbg buildSwapnil Ingle1-1/+3
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2020-10-29support for live migration region and dirty page loggingThanos Makatos1-6/+79
This patch adds support for the live migration region and dirty page logging following VFIO. Live migration is NOT yet functional as handling accesses to the migration region is not yet implemented. Currenty the live migration region is fixed at index 9 simply for simplifying the implementation. Dirty page logging is simplified by requiring IOVA ranges to match exactly the entire IOVA range. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-10-05dma: add api to validate dma regionSwapnil Ingle1-0/+4
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2020-07-08dma: notify device of DMA removal eventsThanos Makatos1-8/+35
This patch introduces a new device callback that is called when a DMA region is removed. The device must provide this callback and when the callback returns all references to the DMA regions must have been removed. This new functionality is necessary since a DMA region can be removed at any time, so the device must be given a chance to drop all references and perform the necessary cleanup. This patch also stores lm_ctx_t inside dma_controller_t so that we don't have to pass lm_ctx_t when calling dma_XXX functions. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-06-24don't blindly trust region_hintThanos Makatos1-1/+2
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-03-24don't use fd for matching DMA region for unmapThanos Makatos1-1/+1
The fd might come from another process so it doesn't make sense, the IOVA range alone is sufficient to determine the DMA region to unmap. Also, don't fail unmapping DMA regions that don't exist. Maybe we should revisit this and ignore the error at the client side? Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2020-02-28log error messages when failing to remove DMAThanos Makatos1-3/+3
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2019-11-21lib/dma: remove DMA_MAP_FAST_IMPLSwapnil Ingle1-46/+15
muser works only with DMA_MAP_FAST_IMPL, So no need to support !DMA_MAP_FAST_IMPL implementation. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
2019-11-07enable -Wall, -Wextra, and -Werror and fix all warningsThanos Makatos1-8/+13
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2019-11-04Standardise function signaturesFelipe Franciosi1-22/+29
This makes all function signatures consistent, using a line break after the return type. It also review the usage of const across the project and fixes some other minor alignment issues. Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2019-09-05Minor style fixesFelipe Franciosi1-1/+1
2019-09-05rename dma_scattergather_t to dma_sg_t to improve readabilityThanos Makatos1-7/+7
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
2019-09-05Initial commitFelipe Franciosi1-0/+241