Re: [RFC PATCH 2/5] scsi: ufs: Add UFS-feature layer

From: Daejun Park
Date: Thu Jun 11 2020 - 22:28:11 EST


Hi Bart,

On 2020-06-04 18:30, Daejun Park wrote:
> > +inline void ufsf_slave_configure(struct ufs_hba *hba,
> > + struct scsi_device *sdev)
> > +{
> > + /* skip well-known LU */
> > + if (sdev->lun >= UFS_UPIU_MAX_UNIT_NUM_ID)
> > + return;
> > +
> > + if (!(hba->dev_info.b_ufs_feature_sup & UFS_FEATURE_SUPPORT_HPB_BIT))
> > + return;
> > +
> > + atomic_inc(&hba->ufsf.slave_conf_cnt);
> > + smp_mb__after_atomic(); /* for slave_conf_cnt */
> > +
> > + /* waiting sdev init.*/
> > + if (waitqueue_active(&hba->ufsf.sdev_wait))
> > + wake_up(&hba->ufsf.sdev_wait);
> > +}

> Guarding a wake_up() call with a waitqueue_active() check is an
> anti-pattern. Please don't do that and call wake_up() directly.
> Additionally, wake_up() includes a barrier if it wakes up a kernel
> thread so the smp_mb__after_atomic() can be left out if the
> waitqueue_active() call is removed.
OK, I will change it.

> > +/**
> > + * struct ufsf_operation - UFS feature specific callbacks
> > + * @prep_fn: called after construct upiu structure
> > + * @reset: called after proving hba
^^^^^^^
> Is this a typo? Should "proving" perhaps be changed into "probing"?
Yes, I will change.

> > +struct ufshpb_driver {
> > + struct device_driver drv;
> > + struct list_head lh_hpb_lu;
> > +
> > + struct ufsf_operation ufshpb_ops;
> > +
> > + /* memory management */
> > + struct kmem_cache *ufshpb_mctx_cache;
> > + mempool_t *ufshpb_mctx_pool;
> > + mempool_t *ufshpb_page_pool;
> > +
> > + struct workqueue_struct *ufshpb_wq;
> > +};

> Why is a dedicated workqueue needed? Why are the standard workqueues not
> good enough?
The map_work handles map related operations, including IO operations. So, adding
this task to the standard WQ can interfere with other jobs and degrade HPB related performance.


> > @@ -2525,6 +2525,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
> >
> > ufshcd_comp_scsi_upiu(hba, lrbp);
> >
> > + ufsf_ops_prep_fn(hba, lrbp);
> > +
> > err = ufshcd_map_sg(hba, lrbp);
> > if (err) {
> > lrbp->cmd = NULL;

> What happens if a SCSI command is retried and hence ufsf_ops_prep_fn()
> is called multiple times for the same SCSI command?
Developers of UFS features should implement it so that prep_fn does not have
any problems even if it processes the same SCSI command multiple times.
In HPB feature, prep_fn modifies only upiu structure. So it is ok to call
it multiple times because the upiu is rebuilt from ufshcd_comp_scsi_upiu().

Thanks,

Daejun.