Re: [PATCH 3/4] cxl: add a firmware update mechanism using the sysfs firmware loader

From: Verma, Vishal L
Date: Wed May 31 2023 - 17:21:01 EST


On Mon, 2023-05-22 at 20:21 -0700, Dan Williams wrote:
> Vishal Verma wrote:

<snip>
Everything else not addressed here sounds good and I've made those
changes.

> >
> > +       remaining = size - cur_size;
> > +       size_in = cur_size + sizeof(*transfer);
> > +
> > +       mutex_lock(&cxlds->fw.fw_mutex);
>
> What is this lock protecting? I.e. will the fw_loader really try to send
> multiple overlapping firmware update attempts?

The lock is just to provide predictable points at which a cancel
request may be intercepted. The loader won't try overlapping firmware
transfer requests, but the ->cancel request comes from user space, and
could happen while there is a transfer in progress. With the lock, the
cancel will only be 'processed' after the current chunk's transfer is
done.

>
> > +       if (!cxlds->fw.clear_to_send) {
>
> I tend to prefer atomic bitops for state flags, especially if that lets
> you get away without a lock.

I can look into that - and this was really just a sanity check, not for
any type of atomicity or locking, rather just to ensure the ->prepare
step has been run before we get to the ->write stage.

If it hadn't been run, it would be a bug in the firmware uploader core,
so I suspect we can just remove this and assume that the fw uploader
will always do the different steps in the right order.

>
> >

<snip>

>
> > +
> > +       fw_name = dev_name(&cxlmd->dev);
> > +       truncate = strstr(fw_name, ".auto");
> > +       len = (truncate) ? truncate - fw_name : strlen(fw_name);
>
> What is this doing? The device name of a cxl_memdev will never have the
> string ".auto", looks like unnecessary copy/pasta.
>
> > +       cxlmd->fw_name = kmemdup_nul(fw_name, len, GFP_KERNEL);
>
> Not sure this is needed either. AFAICS just pass dev_name(&cxlmd->dev)
> and skip a separate string.
>
>
Yep it was copy/pasta I'd meant to clean up but missed. Done now.