qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <george.dunlap@eu.citrix.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [Qemu-devel] [PATCH v2 for-xen-4.5] xen_disk: fix unmapping of persistent grants
Date: Thu, 13 Nov 2014 17:19:49 +0100	[thread overview]
Message-ID: <5464DA25.7050604@citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1411131513470.26318@kaball.uk.xensource.com>

El 13/11/14 a les 16.36, Stefano Stabellini ha escrit:
> On Thu, 13 Nov 2014, Roger Pau Monne wrote:
>> @@ -421,7 +451,17 @@ static int ioreq_map(struct ioreq *ioreq)
>>              }
>>          }
>>      }
>> -    if (ioreq->blkdev->feature_persistent) {
>> +    if (ioreq->blkdev->feature_persistent && new_maps &&
>> +        (!batch_maps || (ioreq->blkdev->persistent_gnt_count + new_maps <=
>> +        ioreq->blkdev->max_grants))) {
> 
> Do we really need this change? If so, could you please write something
> about it in the commit message?

Ack.

> 
>> +        /*
>> +         * If we are using persistent grants and batch mappings only
>> +         * add the new maps to the list of persistent grants if the whole
>> +         * area can be persistently mapped.
>> +         */
> 
> Is this the reason for the change above?

Yes, this is the reason. Maybe it's not clear enough. If we are using
batch maps we have to map all the region persistently, we cannot cherry
pick single grants and make them persistent.

> 
>> +        if (batch_maps && new_maps) {
>> +            add_persistent_region(ioreq->blkdev, ioreq->pages, new_maps);
>> +        }
>>
>>          while ((ioreq->blkdev->persistent_gnt_count < ioreq->blkdev->max_grants)
>>                && new_maps) {
>>              /* Go through the list of newly mapped grants and add as many
>> @@ -437,6 +477,7 @@ static int ioreq_map(struct ioreq *ioreq)
>>                  grant->page = ioreq->pages + (new_maps) * XC_PAGE_SIZE;
>>              } else {
>>                  grant->page = ioreq->page[new_maps];
>> +                add_persistent_region(ioreq->blkdev, ioreq->page[new_maps], 1);
> 
> Basically in the !batch_maps case we are duplicating persistent_gnts
> into persistent_regions. Couldn't we just avoid calling
> add_persistent_region at all in that case and rely on the old
> destroy_grant function? In fact I think we could just pass NULL as
> GDestroyNotify function when creating persistent_gnts if batch_maps and
> the old unmodified destroy_grant if !batch_maps.

Not exactly, we still need the GDestroyNotify function in the batch_maps
case, but I could just pass g_free directly. Let me send v3 with this
reworked.

> 
>>              }
>>              grant->blkdev = ioreq->blkdev;
>>              xen_be_printf(&ioreq->blkdev->xendev, 3,
>> @@ -447,6 +488,7 @@ static int ioreq_map(struct ioreq *ioreq)
>>                            grant);
>>              ioreq->blkdev->persistent_gnt_count++;
>>          }
>> +        assert(!batch_maps || new_maps == 0);
> 
> Shouldn't new_maps be == 0 even in the !batch_maps case?

In theory yes, because we can persistently map all the grants that can
be on the ring. But a malicious/badly coded blkfront could try to
exploit this by always passing different grants, in which case we would
not be able to map them all persistently.

Roger.

      reply	other threads:[~2014-11-13 16:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13 14:58 [Qemu-devel] [PATCH v2 for-xen-4.5] xen_disk: fix unmapping of persistent grants Roger Pau Monne
2014-11-13 15:36 ` Stefano Stabellini
2014-11-13 16:19   ` Roger Pau Monné [this message]

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=5464DA25.7050604@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=stefano.stabellini@eu.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 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).