lkml.org 
[lkml]   [2023]   [Jan]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [RFC PATCH 02/19] drivers/vhost: Convert to use vm_account
Date

"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Tue, Jan 24, 2023 at 04:42:31PM +1100, Alistair Popple wrote:
>> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
>> index ec32f78..a31dd53 100644
>> --- a/drivers/vhost/vdpa.c
>> +++ b/drivers/vhost/vdpa.c
>
> ...
>
>> @@ -780,6 +780,10 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
>> u32 asid = iotlb_to_asid(iotlb);
>> int r = 0;
>>
>> + if (!vdpa->use_va)
>> + if (vm_account_pinned(&dev->vm_account, PFN_DOWN(size)))
>> + return -ENOMEM;
>> +
>> r = vhost_iotlb_add_range_ctx(iotlb, iova, iova + size - 1,
>> pa, perm, opaque);
>> if (r)
>
> I suspect some error handling will have to be reworked then, no?

Thanks. I had meant to go back and double check some of these driver
conversions. Will add something like below:

@@ -787,7 +787,7 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
r = vhost_iotlb_add_range_ctx(iotlb, iova, iova + size - 1,
pa, perm, opaque);
if (r)
- return r;
+ goto out_unaccount;

if (ops->dma_map) {
r = ops->dma_map(vdpa, asid, iova, size, pa, perm, opaque);
@@ -798,12 +798,14 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
r = iommu_map(v->domain, iova, pa, size,
perm_to_iommu_flags(perm));
}
- if (r) {
+ if (r)
vhost_iotlb_del_range(iotlb, iova, iova + size - 1);
- return r;
- }

- return 0;
+out_unaccount:
+ if (!vdpa->use_va)
+ vm_unaccount_pinned(&dev->vm_account, PFN_DOWN(size));
+
+ return r;
}

static void vhost_vdpa_unmap(struct vhost_vdpa *v,
>> --
>> git-series 0.9.1

\
 
 \ /
  Last update: 2023-03-27 00:01    [W:0.381 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site