Re: [PATCH 1/2] xen-blkback: Advertise feature-persistent as user requested

From: SeongJae Park
Date: Wed Aug 31 2022 - 12:18:00 EST


Hi Pratyush,

On Wed, 31 Aug 2022 15:47:50 +0000 Pratyush Yadav <ptyadav@xxxxxxxxx> wrote:

> Hi,
>
> On 25/08/22 04:15PM, SeongJae Park wrote:
> > Commit e94c6101e151 ("xen-blkback: Apply 'feature_persistent' parameter
> > when connect") made blkback to advertise its support of the persistent
> > grants feature only if the user sets the 'feature_persistent' parameter
> > of the driver and the frontend advertised its support of the feature.
> > However, following commit 402c43ea6b34 ("xen-blkfront: Apply
> > 'feature_persistent' parameter when connect") made the blkfront to work
> > in the same way. That is, blkfront also advertises its support of the
> > persistent grants feature only if the user sets the 'feature_persistent'
> > parameter of the driver and the backend advertised its support of the
> > feature.
> >
> > Hence blkback and blkfront will never advertise their support of the
> > feature but wait until the other advertises the support, even though
> > users set the 'feature_persistent' parameters of the drivers. As a
> > result, the persistent grants feature is disabled always regardless of
> > the 'feature_persistent' values[1].
> >
> > The problem comes from the misuse of the semantic of the advertisement
> > of the feature. The advertisement of the feature should means only
> > availability of the feature not the decision for using the feature.
> > However, current behavior is working in the wrong way.
> >
> > This commit fixes the issue by making the blkback advertises its support
> > of the feature as user requested via 'feature_persistent' parameter
> > regardless of the otherend's support of the feature.
> >
> > [1] https://lore.kernel.org/xen-devel/bd818aba-4857-bc07-dc8a-e9b2f8c5f7cd@xxxxxxxx/
> >
> > Fixes: e94c6101e151 ("xen-blkback: Apply 'feature_persistent' parameter when connect")
> > Cc: <stable@xxxxxxxxxxxxxxx> # 5.10.x
> > Reported-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
> > Suggested-by: Juergen Gross <jgross@xxxxxxxx>
> > Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
> > ---
> > drivers/block/xen-blkback/common.h | 3 +++
> > drivers/block/xen-blkback/xenbus.c | 6 ++++--
> > 2 files changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
> > index bda5c815e441..a28473470e66 100644
> > --- a/drivers/block/xen-blkback/common.h
> > +++ b/drivers/block/xen-blkback/common.h
> > @@ -226,6 +226,9 @@ struct xen_vbd {
> > sector_t size;
> > unsigned int flush_support:1;
> > unsigned int discard_secure:1;
> > + /* Connect-time cached feature_persistent parameter value */
> > + unsigned int feature_gnt_persistent_parm:1;
> > + /* Persistent grants feature negotiation result */
> > unsigned int feature_gnt_persistent:1;
> > unsigned int overflow_max_grants:1;
> > };
> > diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
> > index ee7ad2fb432d..c0227dfa4688 100644
> > --- a/drivers/block/xen-blkback/xenbus.c
> > +++ b/drivers/block/xen-blkback/xenbus.c
> > @@ -907,7 +907,7 @@ static void connect(struct backend_info *be)
> > xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
> >
> > err = xenbus_printf(xbt, dev->nodename, "feature-persistent", "%u",
> > - be->blkif->vbd.feature_gnt_persistent);
> > + be->blkif->vbd.feature_gnt_persistent_parm);
> > if (err) {
> > xenbus_dev_fatal(dev, err, "writing %s/feature-persistent",
> > dev->nodename);
> > @@ -1085,7 +1085,9 @@ static int connect_ring(struct backend_info *be)
> > return -ENOSYS;
> > }
> >
> > - blkif->vbd.feature_gnt_persistent = feature_persistent &&
> > + blkif->vbd.feature_gnt_persistent_parm = feature_persistent;
>
> If feature_gnt_persistent_parm is always going to be equal to
> feature_persistent, then why introduce it at all? Why not just use
> feature_persistent directly? This way you avoid adding an extra flag
> whose purpose is not immediately clear, and you also avoid all the mess
> with setting this flag at the right time.

Mainly because the parameter should read twice (once for advertisement, and
once later just before the negotitation, for checking if we advertised or not),
and the user might change the parameter value between the two reads.

For the detailed available sequence of the race, you could refer to the prior
conversation[1].

[1] https://lore.kernel.org/linux-block/20200922111259.GJ19254@Air-de-Roger/


Thanks,
SJ

>
> > + blkif->vbd.feature_gnt_persistent =
> > + blkif->vbd.feature_gnt_persistent_parm &&
> > xenbus_read_unsigned(dev->otherend, "feature-persistent", 0);
> >
> > blkif->vbd.overflow_max_grants = 0;
> > --
> > 2.25.1
> >
> >
>