Re: [PATCH v3 3/4] fpga: dfl: add basic support for DFHv1
From: Xu Yilun
Date: Thu Oct 06 2022 - 05:56:15 EST
On 2022-10-04 at 18:11:06 +0300, Andy Shevchenko wrote:
> On Tue, Oct 04, 2022 at 07:37:17AM -0700, matthew.gerlach@xxxxxxxxxxxxxxx wrote:
> > From: Matthew Gerlach <matthew.gerlach@xxxxxxxxxxxxxxx>
> >
> > Add generic support for MSIX interrupts for DFL devices.
>
...
>
> > +int dfhv1_find_param(void __iomem *base, resource_size_t max, int param)
> > +{
> > + int off = DFHv1_PARAM_HDR;
> > + u64 v, next;
> > +
> > + while (off < max) {
> > + v = readq(base + off);
> > + if (param == FIELD_GET(DFHv1_PARAM_HDR_ID, v))
>
> > + return (DFHv1_PARAM_DATA + off);
>
> Too many parentheses.
>
> > +
> > + next = FIELD_GET(DFHv1_PARAM_HDR_NEXT_OFFSET, v);
> > + if (!next)
> > + break;
> > +
> > + off += next;
> > + }
> > +
> > + return -ENOENT;
> > +}
>
> The entire function seems a bit dangerous to me. You can ask for any max which
> covers (up to) 64-bit address space and then do MMIO by basically arbitrary
> address. How do you protect against wrong MMIO window here? (This is FPGA, so
> anything can be read from HW, i.o.w. it's _untrusted_ source of the data.)
>
> Also, have you tested this with IOMMU enabled? How do they work together (if
> there is any collision at all between two?)
Yeah, again I don't think this API is good to be used across modules,
even if the parameters got checked. It requires too much details for
other domain developers.
How about:
dfl_find_param(struct dfl_device *ddev, int param_id)
Thanks,
Yilun