On Wed, Sep 10, 2025 at 09:22:11PM +0100, Lorenzo Stoakes wrote:
> +static int kcov_mmap_prepare(struct vm_area_desc *desc)
>  {
>       int res = 0;
> -     struct kcov *kcov = vma->vm_file->private_data;
> -     unsigned long size, off;
> -     struct page *page;
> +     struct kcov *kcov = desc->file->private_data;
> +     unsigned long size, nr_pages, i;
> +     struct page **pages;
>       unsigned long flags;
>  
>       spin_lock_irqsave(&kcov->lock, flags);
>       size = kcov->size * sizeof(unsigned long);
> -     if (kcov->area == NULL || vma->vm_pgoff != 0 ||
> -         vma->vm_end - vma->vm_start != size) {
> +     if (kcov->area == NULL || desc->pgoff != 0 ||
> +         vma_desc_size(desc) != size) {

IMHO these range checks should be cleaned up into a helper:

/* Returns true if the VMA falls within starting_pgoff to
     starting_pgoff + ROUND_DOWN(length_bytes, PAGE_SIZE))
   Is careful to avoid any arithmetic overflow.
 */
vma_desc_check_range(desc, starting_pgoff=0, length_bytes=size);

> +     desc->vm_flags |= VM_DONTEXPAND;
> +     nr_pages = size >> PAGE_SHIFT;
> +
> +     pages = mmap_action_mixedmap_pages(&desc->action, desc->start,
> +                                        nr_pages);
> +     if (!pages)
> +             return -ENOMEM;
> +
> +     for (i = 0; i < nr_pages; i++)
> +             pages[i] = vmalloc_to_page(kcov->area + i * PAGE_SIZE);

This is not a mixed map.

All the memory comes from vmalloc_user() which makes them normal
struct pages with refcounts.

If anything the action should be called mmap_action_vmalloc_user() to
match how the memory was allocated instead of open coding something.

Jason

Reply via email to