Re: [GIT PULL] Char/Misc driver changes for 6.9-rc1

From: Linus Torvalds
Date: Wed Mar 27 2024 - 16:27:10 EST


On Wed, 27 Mar 2024 at 09:56, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> I also *suspect* that using 'physaddr_t' is in itself pointless,
> because I *think* the physical addresses are always page-aligned
> anyway, and it would be better if the uio_mem thing just contained the
> pfn instead. Which could just be 'unsigned long pfn'.

Oddly, the uio code seems to be written to allow unaligned page buffers,

actual_pages = ((idev->info->mem[mi].addr & ~PAGE_MASK)
+ idev->info->mem[mi].size + PAGE_SIZE -1) >>
PAGE_SHIFT;

but none of the mmap routines than actually allow such a mapping, and
they all have alignment checks.

Which sounds wonderful, until you find code like this duplicated in
various uio drivers:

uiomem->memtype = UIO_MEM_PHYS;
uiomem->addr = r->start & PAGE_MASK;
uiomem->offs = r->start & ~PAGE_MASK;
uiomem->size = (uiomem->offs + resource_size(r)
+ PAGE_SIZE - 1) & PAGE_MASK;

IOW, it explicitly aligns the resources to pages, so now mmap works
again. Oh the horror.

But yes, that physical part of 'addr' should be a pfn. Sadly, all of
this code is such a mess that it's a horrible job to try to fix it all
up.

So we may be stuck with the horrendous confusion that is the current
uio_mem thing.

Linus