From: Steve Sistare <steven.sistare@oracle.com>
To: kvm@vger.kernel.org
Cc: Alex Williamson <alex.williamson@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
Kirti Wankhede <kwankhede@nvidia.com>,
Steve Sistare <steven.sistare@oracle.com>
Subject: [PATCH V3 3/9] vfio/type1: implement unmap all
Date: Fri, 29 Jan 2021 08:54:06 -0800 [thread overview]
Message-ID: <1611939252-7240-4-git-send-email-steven.sistare@oracle.com> (raw)
In-Reply-To: <1611939252-7240-1-git-send-email-steven.sistare@oracle.com>
Implement VFIO_DMA_UNMAP_FLAG_ALL.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
drivers/vfio/vfio_iommu_type1.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 6bf33c2..407f0f7 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1077,6 +1077,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
unsigned long pgshift;
dma_addr_t iova = unmap->iova;
unsigned long size = unmap->size;
+ bool unmap_all = !!(unmap->flags & VFIO_DMA_UNMAP_FLAG_ALL);
mutex_lock(&iommu->lock);
@@ -1086,8 +1087,13 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
if (iova & (pgsize - 1))
goto unlock;
- if (!size || size & (pgsize - 1))
+ if (unmap_all) {
+ if (iova || size)
+ goto unlock;
+ size = SIZE_MAX;
+ } else if (!size || size & (pgsize - 1)) {
goto unlock;
+ }
if (iova + size - 1 < iova || size > SIZE_MAX)
goto unlock;
@@ -1131,7 +1137,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
* will only return success and a size of zero if there were no
* mappings within the range.
*/
- if (iommu->v2) {
+ if (iommu->v2 && !unmap_all) {
dma = vfio_find_dma(iommu, iova, 1);
if (dma && dma->iova != iova)
goto unlock;
@@ -2515,6 +2521,7 @@ static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu,
case VFIO_TYPE1_IOMMU:
case VFIO_TYPE1v2_IOMMU:
case VFIO_TYPE1_NESTING_IOMMU:
+ case VFIO_UNMAP_ALL:
return 1;
case VFIO_DMA_CC_IOMMU:
if (!iommu)
@@ -2687,6 +2694,8 @@ static int vfio_iommu_type1_unmap_dma(struct vfio_iommu *iommu,
{
struct vfio_iommu_type1_dma_unmap unmap;
struct vfio_bitmap bitmap = { 0 };
+ uint32_t mask = VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP |
+ VFIO_DMA_UNMAP_FLAG_ALL;
unsigned long minsz;
int ret;
@@ -2695,8 +2704,11 @@ static int vfio_iommu_type1_unmap_dma(struct vfio_iommu *iommu,
if (copy_from_user(&unmap, (void __user *)arg, minsz))
return -EFAULT;
- if (unmap.argsz < minsz ||
- unmap.flags & ~VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP)
+ if (unmap.argsz < minsz || unmap.flags & ~mask)
+ return -EINVAL;
+
+ if ((unmap.flags & VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) &&
+ (unmap.flags & VFIO_DMA_UNMAP_FLAG_ALL))
return -EINVAL;
if (unmap.flags & VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) {
--
1.8.3.1
next prev parent reply other threads:[~2021-01-29 17:23 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 16:54 [PATCH V3 0/9] vfio virtual address update Steve Sistare
2021-01-29 16:54 ` [PATCH V3 1/9] vfio: option to unmap all Steve Sistare
2021-02-01 11:42 ` Cornelia Huck
2021-02-01 12:52 ` Steven Sistare
2021-02-01 13:13 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 2/9] vfio/type1: unmap cleanup Steve Sistare
2021-02-01 11:50 ` Cornelia Huck
2021-01-29 16:54 ` Steve Sistare [this message]
2021-02-01 11:59 ` [PATCH V3 3/9] vfio/type1: implement unmap all Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 4/9] vfio: interfaces to update vaddr Steve Sistare
2021-02-01 13:13 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 5/9] vfio/type1: massage unmap iteration Steve Sistare
2021-01-29 21:56 ` Alex Williamson
2021-01-30 16:51 ` Steven Sistare
2021-02-01 12:11 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 6/9] vfio/type1: implement interfaces to update vaddr Steve Sistare
2021-01-29 21:56 ` Alex Williamson
2021-01-30 16:51 ` Steven Sistare
2021-02-01 12:27 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 7/9] vfio: iommu driver notify callback Steve Sistare
2021-01-29 21:57 ` Alex Williamson
2021-01-30 16:51 ` Steven Sistare
2021-02-01 12:34 ` Cornelia Huck
2021-02-01 12:52 ` Steven Sistare
2021-02-01 13:17 ` Cornelia Huck
2021-02-01 13:17 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 8/9] vfio/type1: implement " Steve Sistare
2021-02-01 12:40 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 9/9] vfio/type1: block on invalid vaddr Steve Sistare
2021-02-01 12:47 ` Cornelia Huck
2021-01-29 21:55 ` [PATCH V3 0/9] vfio virtual address update Alex Williamson
2021-01-29 22:14 ` Steven Sistare
2021-01-30 16:54 ` Steven Sistare
2021-02-01 20:23 ` Alex Williamson
2021-02-01 21:13 ` Steven Sistare
2021-02-02 7:54 ` Cornelia Huck
2021-02-02 17:21 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1611939252-7240-4-git-send-email-steven.sistare@oracle.com \
--to=steven.sistare@oracle.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).