All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/6] vhost: mark dirty pages during map uninit
Date: Tue, 23 Jul 2019 21:19:33 +0800	[thread overview]
Message-ID: <a670cd0d-581d-1aba-41bd-c643c19f9604@redhat.com> (raw)
In-Reply-To: <20190723041702-mutt-send-email-mst@kernel.org>


On 2019/7/23 下午5:17, Michael S. Tsirkin wrote:
> On Tue, Jul 23, 2019 at 03:57:17AM -0400, Jason Wang wrote:
>> We don't mark dirty pages if the map was teared down outside MMU
>> notifier. This will lead untracked dirty pages. Fixing by marking
>> dirty pages during map uninit.
>>
>> Reported-by: Michael S. Tsirkin<mst@redhat.com>
>> Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address")
>> Signed-off-by: Jason Wang<jasowang@redhat.com>
>> ---
>>   drivers/vhost/vhost.c | 22 ++++++++++++++++------
>>   1 file changed, 16 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>> index 89c9f08b5146..5b8821d00fe4 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -306,6 +306,18 @@ static void vhost_map_unprefetch(struct vhost_map *map)
>>   	kfree(map);
>>   }
>>   
>> +static void vhost_set_map_dirty(struct vhost_virtqueue *vq,
>> +				struct vhost_map *map, int index)
>> +{
>> +	struct vhost_uaddr *uaddr = &vq->uaddrs[index];
>> +	int i;
>> +
>> +	if (uaddr->write) {
>> +		for (i = 0; i < map->npages; i++)
>> +			set_page_dirty(map->pages[i]);
>> +	}
>> +}
>> +
>>   static void vhost_uninit_vq_maps(struct vhost_virtqueue *vq)
>>   {
>>   	struct vhost_map *map[VHOST_NUM_ADDRS];
>> @@ -315,8 +327,10 @@ static void vhost_uninit_vq_maps(struct vhost_virtqueue *vq)
>>   	for (i = 0; i < VHOST_NUM_ADDRS; i++) {
>>   		map[i] = rcu_dereference_protected(vq->maps[i],
>>   				  lockdep_is_held(&vq->mmu_lock));
>> -		if (map[i])
>> +		if (map[i]) {
>> +			vhost_set_map_dirty(vq, map[i], i);
>>   			rcu_assign_pointer(vq->maps[i], NULL);
>> +		}
>>   	}
>>   	spin_unlock(&vq->mmu_lock);
>>   
>> @@ -354,7 +368,6 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq,
>>   {
>>   	struct vhost_uaddr *uaddr = &vq->uaddrs[index];
>>   	struct vhost_map *map;
>> -	int i;
>>   
>>   	if (!vhost_map_range_overlap(uaddr, start, end))
>>   		return;
>> @@ -365,10 +378,7 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq,
>>   	map = rcu_dereference_protected(vq->maps[index],
>>   					lockdep_is_held(&vq->mmu_lock));
>>   	if (map) {
>> -		if (uaddr->write) {
>> -			for (i = 0; i < map->npages; i++)
>> -				set_page_dirty(map->pages[i]);
>> -		}
>> +		vhost_set_map_dirty(vq, map, index);
>>   		rcu_assign_pointer(vq->maps[index], NULL);
>>   	}
>>   	spin_unlock(&vq->mmu_lock);
> OK and the reason it's safe is because the invalidate counter
> got incremented so we know page will not get mapped again.
>
> But we*do*  need to wait for page not to be mapped.
> And if that means waiting for VQ processing to finish,
> then I worry that is a very log time.
>

I'm not sure I get you here. If we don't have such map, we will fall 
back to normal uaccess helper. And in the memory accessor, the rcu 
critical section is pretty small.

Thanks




  parent reply	other threads:[~2019-07-23 13:19 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23  7:57 [PATCH 0/6] Fixes for meta data acceleration Jason Wang
2019-07-23  7:57 ` [PATCH 1/6] vhost: don't set uaddr for invalid address Jason Wang
2019-07-23  7:57 ` Jason Wang
2019-07-23  7:57 ` [PATCH 2/6] vhost: validate MMU notifier registration Jason Wang
2019-07-23  7:57 ` Jason Wang
2019-07-23  9:17   ` Michael S. Tsirkin
2019-07-23 13:30     ` Jason Wang
2019-07-23 13:30     ` Jason Wang
2019-07-23  9:17   ` Michael S. Tsirkin
2019-07-23  7:57 ` [PATCH 3/6] vhost: fix vhost map leak Jason Wang
2019-07-23  7:57 ` Jason Wang
2019-07-23  7:57 ` [PATCH 4/6] vhost: reset invalidate_count in vhost_set_vring_num_addr() Jason Wang
2019-07-23  7:57 ` Jason Wang
2019-07-23  9:17   ` Michael S. Tsirkin
2019-07-23 13:25     ` Jason Wang
2019-07-23 13:25     ` Jason Wang
2019-07-23  9:17   ` Michael S. Tsirkin
2019-07-23  7:57 ` [PATCH 5/6] vhost: mark dirty pages during map uninit Jason Wang
2019-07-23  9:17   ` Michael S. Tsirkin
2019-07-23 13:19     ` Jason Wang
2019-07-23 13:19     ` Jason Wang [this message]
2019-07-25  5:21       ` Michael S. Tsirkin
2019-07-25  5:21       ` Michael S. Tsirkin
2019-07-23  9:17   ` Michael S. Tsirkin
2019-07-23  7:57 ` Jason Wang
2019-07-23  7:57 ` [PATCH 6/6] vhost: don't do synchronize_rcu() in vhost_uninit_vq_maps() Jason Wang
2019-07-23  9:16   ` Michael S. Tsirkin
2019-07-23  9:16   ` Michael S. Tsirkin
2019-07-23 13:16     ` Jason Wang
2019-07-23 13:16     ` Jason Wang
2019-07-23  7:57 ` Jason Wang

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=a670cd0d-581d-1aba-41bd-c643c19f9604@redhat.com \
    --to=jasowang@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.