Re: [PATCH v3] kcov: don't generate a warning on vm_insert_page()'s failure

From: Andrew Morton
Date: Mon Apr 04 2022 - 19:02:35 EST


On Fri, 1 Apr 2022 18:25:12 +0000 Aleksandr Nogikh <nogikh@xxxxxxxxxx> wrote:

> vm_insert_page()'s failure is not an unexpected condition, so don't do
> WARN_ONCE() in such a case.
>
> Instead, print a kernel message and just return an error code.
>
> ...
>
> --- a/kernel/kcov.c
> +++ b/kernel/kcov.c
> @@ -475,8 +475,11 @@ static int kcov_mmap(struct file *filep, struct vm_area_struct *vma)
> vma->vm_flags |= VM_DONTEXPAND;
> for (off = 0; off < size; off += PAGE_SIZE) {
> page = vmalloc_to_page(kcov->area + off);
> - if (vm_insert_page(vma, vma->vm_start + off, page))
> - WARN_ONCE(1, "vm_insert_page() failed");
> + res = vm_insert_page(vma, vma->vm_start + off, page);
> + if (res) {
> + pr_warn_once("kcov: vm_insert_page() failed\n");
> + return res;
> + }
> }
> return 0;
> exit:

Can you explain the rationale here? If vm_insert_page() failure is an
expected condition, why warn at all?

I'm struggling to understand why a condition is worth a printk, but not
a WARN.

Some explanation of what leads to the vm_insert_page() failure would
have been helpful.