[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen, blkback: fix persistent grants negotiation


  • To: Maximilian Heyne <mheyne@xxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 11 Jan 2022 12:11:15 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4vbVjBIbKzztlAe9vCcCRtVaFrKaWxxjBst7/u1OVq4=; b=FijY9vWbTiWmmKqfl5e/6IYr+Hl5trJs/tCkF7he/+aqmDTJSD68SwBxUEarjmgZRSVSw2R6k4YXAgugCDF9Yp/+JGqF46M8wzTET9u8VIyl8HKI6oky2jrsyUV/cPLe1dIV/Mbx6qqWXGxCmOzQUYvg72I6Y9R4icjzbuwdFzGwkbeOYYEY32toPRLAkuSIzyirEklzM7nrkRyj/e9tQvUc36l3/kHaVad3a/HBGbiftinbhDbOufIx3HJHC1S8fH6rxgA7e+5Nxh8kh7/cEBw2jRrRUlX+2unVUlFymuL+MVcRIwx+o1stdH5BuNuu4pvbw6BMtYDoenCOXwlgew==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MtZlmloa5NjDpfBJQTxhye7c7JuLPtDAkvx1Q6hQ7VOdvm+PpSU2xvfbuYYAZIdIyo+hb+zndZOd/iMLaNHHdwBj09WhOIYQrsYXWux/d+n7E/sNhrKn1M8Rg3hfLOrGrDc4NrYfuNP0yHJFrJ/ctJNXgg9L/fPyasCT+1PYDfkaV28QVRzNlWMnWHdqljyeeB+8oxtkklauJT4ygpxvFOb13mXCAcoap/mEeLn5oUrxXsqynyj80tdYZ7dTt3MdfqVDT1OtFQua9cIt0EulN9rJj5CSeAO2WLRt6lGf9jIUp2DtgsPvqkrLwzd/VnPwr+XoSXIrv4rheQtf/DdAzA==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Jens Axboe <axboe@xxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Anthony Liguori <aliguori@xxxxxxxxxx>, SeongJae Park <sjpark@xxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <linux-block@xxxxxxxxxxxxxxx>, <linux-kernel@xxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 11 Jan 2022 11:11:47 +0000
  • Ironport-data: A9a23:zlVqz6p1B8lhTSNjk34AyjEBx0peBmJrYxIvgKrLsJaIsI4StFCzt garIBnQOvmJNGL3c90lPd7goBwDvpCHyNFjQQdo/iA9Hy0b9puZCYyVIHmrMnLJJKUvbq7GA +byyDXkBJppJpMJjk71atANlZT4vE2xbuKU5NTsY0idfic5Dndx4f5fs7Rh2NQw2IHgW1rlV e7a+KUzBnf0g1aYDUpMg06zgEsHUCPa4W5wUvQWPJinjXeG/5UnJMt3yZKZdhMUdrJ8DO+iL 9sv+Znilo/vE7XBPfv++lrzWhVirrc/pmFigFIOM0SpqkAqSiDfTs/XnRfTAKtao2zhojx/9 DlCnbHuViVuGYv2ouYyUCRJIxNDI6JsoZaSdBBTseTLp6HHW37lwvEoB0AqJ4wIvO1wBAmi9 9RBdmpLNErawbvrnvTrEYGAhex6RCXvFJkYtXx6iynQEN4tQIzZQrWM7thdtNs1rp4XQqyBN 5dAAdZpRFfdbzoSE1YqNL8Vob2q1l/CfSxW913A8MLb5ECMlVcsgdABKuH9atGMAMlYgEucj mbH5HjiRAEXMsSFzjiI+W7qgfXA9Qv5V5gVD6aQ7e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jJEDtR0Wnl8PI1OFxojMivMthUAD9D02SkJezwld0vI1M W9ubhUnKaKL9jZupc5CQ2HzRF0RWEzHohT8mwkTiWnUb0i0TWicfmQyNNGE8F0d728BLCNQ+ 6uVyTq9XDvnFC0rMvDehaKxRyTfcOFM
  • Ironport-hdrordr: A9a23:ankYLaziIgMQgF2FMda3KrPwIr1zdoMgy1knxilNoH1uHvBw8v rEoB1173DJYVoqNk3I++rhBEDwexLhHPdOiOF6UItKNzOW21dAQrsSiLfK8nnNHDD/6/4Y9Y oISdkbNDQoNykZsfrH
  • Ironport-sdr: +LNhzxgyQIwGFZ5VV6qDOzBvNMLcq5gBJ6Qly+qzJynxF/aJZ8v2GSXyhhTU1Qe/XUzsCWs9ZG zndvA2sFmWxFp/cdUOnSlAFe8dTD/Mf3c0uz/HvLaImKGJhuSGarQm6IjfZcBJ+gmA3j2jcOzG b4t3pmzFrSBoNCZwA4RVbkukkIWutLJw+BoYXWH/QZr40gryeOjqieLlAuzPt8hJ83lIF7nNCY 2FpP3TLXoE7KuPoI+dWwD3xmKs7PlgCOkJADSAkw17s7DrPgaM3dgpITfAoA/cijtipM9Lh/vJ MbcsE9njnUW6KClRkHINz1jF
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Jan 06, 2022 at 09:10:13AM +0000, Maximilian Heyne wrote:
> Given dom0 supports persistent grants but the guest does not.
> Then, when attaching a block device during runtime of the guest, dom0
> will enable persistent grants for this newly attached block device:
> 
>   $ xenstore-ls -f | grep 20674 | grep persistent
>   /local/domain/0/backend/vbd/20674/768/feature-persistent = "0"
>   /local/domain/0/backend/vbd/20674/51792/feature-persistent = "1"

The mechanism that we use to advertise persistent grants support is
wrong. 'feature-persistent' should always be set if the backend
supports persistent grant (like it's done for other features in
xen_blkbk_probe). The usage of the feature depends on whether both
parties support persistent grants, and the xenstore entry printed by
blkback shouldn't reflect whether persistent grants are in use, but
rather whether blkback supports the feature.

> 
> Here disk 768 was attached during guest creation while 51792 was
> attached at runtime. If the guest would have advertised the persistent
> grant feature, there would be a xenstore entry like:
> 
>   /local/domain/20674/device/vbd/51792/feature-persistent = "1"
> 
> Persistent grants are also used when the guest tries to access the disk
> which can be seen when enabling log stats:
> 
>   $ echo 1 > /sys/module/xen_blkback/parameters/log_stats
>   $ dmesg
>   xen-blkback: (20674.xvdf-0): oo   0  |  rd    0  |  wr    0  |  f    0 |  
> ds    0 | pg:    1/1056
> 
> The "pg: 1/1056" shows that one persistent grant is used.
> 
> Before commit aac8a70db24b ("xen-blkback: add a parameter for disabling
> of persistent grants") vbd->feature_gnt_persistent was set in
> connect_ring. After the commit it was intended to be initialized in
> xen_vbd_create and then set according to the guest feature availability
> in connect_ring. However, with a running guest, connect_ring might be
> called before xen_vbd_create and vbd->feature_gnt_persistent will be
> incorrectly initialized. xen_vbd_create will overwrite it with the value
> of feature_persistent regardless whether the guest actually supports
> persistent grants.
> 
> With this commit, vbd->feature_gnt_persistent is set only in
> connect_ring and this is the only use of the module parameter
> feature_persistent. This avoids races when the module parameter changes
> during the block attachment process.
> 
> Note that vbd->feature_gnt_persistent doesn't need to be initialized in
> xen_vbd_create. It's next use is in connect which can only be called
> once connect_ring has initialized the rings. xen_update_blkif_status is
> checking for this.
> 
> Fixes: aac8a70db24b ("xen-blkback: add a parameter for disabling of 
> persistent grants")
> Signed-off-by: Maximilian Heyne <mheyne@xxxxxxxxx>
> ---
>  drivers/block/xen-blkback/xenbus.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/block/xen-blkback/xenbus.c 
> b/drivers/block/xen-blkback/xenbus.c
> index 914587aabca0c..51b6ec0380ca4 100644
> --- a/drivers/block/xen-blkback/xenbus.c
> +++ b/drivers/block/xen-blkback/xenbus.c
> @@ -522,8 +522,6 @@ static int xen_vbd_create(struct xen_blkif *blkif, 
> blkif_vdev_t handle,
>       if (q && blk_queue_secure_erase(q))
>               vbd->discard_secure = true;
>  
> -     vbd->feature_gnt_persistent = feature_persistent;
> -
>       pr_debug("Successful creation of handle=%04x (dom=%u)\n",
>               handle, blkif->domid);
>       return 0;
> @@ -1090,10 +1088,9 @@ static int connect_ring(struct backend_info *be)
>               xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
>               return -ENOSYS;
>       }
> -     if (blkif->vbd.feature_gnt_persistent)
> -             blkif->vbd.feature_gnt_persistent =
> -                     xenbus_read_unsigned(dev->otherend,
> -                                     "feature-persistent", 0);
> +
> +     blkif->vbd.feature_gnt_persistent = feature_persistent &&
> +             xenbus_read_unsigned(dev->otherend, "feature-persistent", 0);

I'm not sure it's correct to potentially read feature_persistent
multiple times like it's done here.

A device can be disconnected and re-attached multiple times, and that
implies multiple calls to connect_ring which could make the state of
feature_gnt_persistent change across reconnections if the value of
feature_persistent is changed. I think that would be unexpected.

There are also similar issues with
xenblk_max_queues/xen_blkif_max_ring_order changing after
xen_blkbk_probe has been executed. We likely need to stash all those
parameters so what's on xenbus is consistent with the limits enforced
in blkback.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.