All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: "Roger Pau Monné" <roger.pau@citrix.com>, xen-devel@lists.xenproject.org
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Jenny Herbert <jennifer.herbert@citrix.com>
Subject: Re: [PATCH 12/14] xen-blkback: safely unmap grants in case they are still in use
Date: Fri, 23 Jan 2015 14:54:50 +0000	[thread overview]
Message-ID: <54C260BA.7060506@citrix.com> (raw)
In-Reply-To: <54C25B2F.9090205@citrix.com>

On 23/01/15 14:31, Roger Pau Monné wrote:
> El 19/01/15 a les 16.51, David Vrabel ha escrit:
>> From: Jenny Herbert <jennifer.herbert@citrix.com>
>>
>> +static void xen_blkbk_unmap(struct xen_blkif *blkif,
>> +                            struct grant_page *pages[],
>> +                            int num)
>> +{
>> +	struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
>> +	struct page *unmap_pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
>> +	unsigned int invcount = 0;
>> +	int ret;
>> +
>> +	while (num) {
>> +		unsigned int batch = min(num, BLKIF_MAX_SEGMENTS_PER_REQUEST);
>> +		
>> +		invcount = xen_blkbk_unmap_prepare(blkif, pages, batch,
>> +						   unmap, unmap_pages);
> 
> I would add:
> 
> BUG_ON(invcount != batch);

I'm confused.  Surely invcount < batch is valid if one or more pages
within this batch are persistently mapped?

>> +		if (invcount) {
>> +			ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount);
>>  			BUG_ON(ret);
>> -			put_free_pages(blkif, unmap_pages, invcount);
>> -			invcount = 0;
>> +			xen_blkbk_unmap_done(blkif, unmap_pages, invcount);
>>  		}
>> -	}
>> -	if (invcount) {
>> -		ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount);
>> -		BUG_ON(ret);
>> -		put_free_pages(blkif, unmap_pages, invcount);
>> +		pages += batch;
>> +		num -= batch;
> 
> This loop is sort of buggy, it should work, but it is sub-optimal.
> 
> The pages array can contain both persistent grants and normal grants
> (the ones that we should unmap). So blindly increasing the pages pointer
> with batch will mean that we could be iterating over grants that have
> already been freed. It is not really an issue because we set handle to
> BLKBACK_INVALID_HANDLE, but it's a waste.

Again, I don't follow you here.

David

  reply	other threads:[~2015-01-23 14:54 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-19 15:51 [PATCHv3 00/14] xen: fix many long-standing grant mapping bugs David Vrabel
2015-01-19 15:51 ` [PATCH 01/14] mm: provide a find_special_page vma operation David Vrabel
2015-01-19 15:51 ` [PATCH 02/14] mm: add 'foreign' alias for the 'pinned' page flag David Vrabel
2015-01-19 15:51 ` [PATCH 03/14] xen/grant-table: pre-populate kernel unmap ops for xen_gnttab_unmap_refs() David Vrabel
2015-01-19 15:51 ` [PATCH 04/14] xen: remove scratch frames for ballooned pages and m2p override David Vrabel
2015-01-19 15:51 ` [PATCH 05/14] x86/xen: require ballooned pages for grant maps David Vrabel
2015-01-19 15:51 ` [PATCH 06/14] xen/grant-table: add helpers for allocating pages David Vrabel
2015-01-19 15:51 ` [PATCH 07/14] xen: mark grant mapped pages as foreign David Vrabel
2015-01-19 15:51 ` [PATCH 08/14] xen-netback: use foreign page information from the pages themselves David Vrabel
2015-01-19 15:51 ` [PATCH 09/14] xen/grant-table: add a mechanism to safely unmap pages that are in use David Vrabel
2015-01-19 15:51 ` [PATCH 10/14] xen/gntdev: convert priv->lock to a mutex David Vrabel
2015-01-19 17:49   ` Stefano Stabellini
2015-01-19 17:53     ` David Vrabel
2015-01-19 18:38       ` Stefano Stabellini
2015-01-19 18:43         ` David Vrabel
2015-01-19 15:51 ` [PATCH 11/14] xen/gntdev: safely unmap grants in case they are still in use David Vrabel
2015-01-19 15:51 ` [PATCH 12/14] xen-blkback: " David Vrabel
2015-01-23 12:02   ` David Vrabel
2015-01-23 14:41     ` Roger Pau Monné
2015-01-23 14:31   ` Roger Pau Monné
2015-01-23 14:54     ` David Vrabel [this message]
2015-01-23 15:47       ` Roger Pau Monné
2015-01-23 16:00         ` David Vrabel
2015-01-26 15:00           ` David Vrabel
2015-01-24  8:57         ` Roger Pau Monné
2015-01-26 15:02   ` David Vrabel
2015-01-26 17:34     ` Jens Axboe
2015-01-19 15:51 ` [PATCH 13/14] xen/gntdev: mark userspace PTEs as special on x86 PV guests David Vrabel
2015-01-19 15:51 ` [PATCH 14/14] xen/gntdev: provide find_special_page VMA operation David Vrabel
  -- strict thread matches above, loose matches on Subject: below --
2015-01-12 15:43 [PATCHv2 00/14] xen: fix many long-standing grant mapping bugs David Vrabel
2015-01-12 15:43 ` [PATCH 12/14] xen-blkback: safely unmap grants in case they are still in use David Vrabel
2015-01-14 15:17   ` Boris Ostrovsky
2015-01-14 15:47   ` Boris Ostrovsky
2015-01-14 16:00     ` David Vrabel
2015-01-14 16:22       ` Boris Ostrovsky
2015-01-14 16:33         ` David Vrabel

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=54C260BA.7060506@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jennifer.herbert@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.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.