Re: pci_resource_to_user exports wrong region size on mips

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

 



Hi Rui,

On Wed, Jul 11, 2018 at 11:25:06AM +0800, Rui Wang wrote:
> static inline resource_size_t resource_size(const struct resource *res)
> {
>     return res->end - res->start + 1;
> }
> 
> static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
>         const struct resource *rsrc, resource_size_t *start,
>         resource_size_t *end)
> {
>     phys_addr_t size = resource_size(rsrc);
> 
>     *start = fixup_bigphys_addr(rsrc->start, size);
>     *end = rsrc->start + size;
> }
> 
> ----------------------------------------------------------------------------------
> 
> In that function, the "size" is set to "end - start + 1", this is all right.
> And "start" is actually set to "rsrc->start".
> 
> What confused me is that the "end" is set to "start + size".
> 
> If we replace the "size" to "end - start + 1", then the "end" is actually
> set to "start + end - start + 1", which is "end + 1".
> 
> I think this is the reason why the region size is 33 rather then 32.
> 
> I have checked the latest kernel, but the code is still like that. Is this a
> feature I don not understand or just a bug.

This looks like a bug introduced along with the MIPS implementation of
pci_resource_to_user() in Linux v3.12.

The "end" of a resource is the last byte it covers, but what this
function is incorrectly reporting to userland is the first byte after
the end of the resource.

The fix is simply to subtract one from what we assign to *end here. I've
submitted a fix for this just now, if I could have your Tested-by that
would be great:

    https://marc.info/?l=linux-mips&m=153141325813771&w=2

    https://patchwork.linux-mips.org/patch/19829/

Thanks,
    Paul




[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux