linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>, linux-mm@kvack.org
Subject: Re: [bug report] mm: avoid leaving partial pfn mappings around in error case
Date: Sun, 15 Sep 2024 13:01:43 +0100	[thread overview]
Message-ID: <68590155-fd3c-4ce4-9a1f-d314efada198@lucifer.local> (raw)
In-Reply-To: <8e3ffaf2-358f-479c-8de6-46e1b0bb0c5f@stanley.mountain>

On Sun, Sep 15, 2024 at 01:08:27PM GMT, Dan Carpenter wrote:
> Hi Linus,
>
> Commit 79a61cc3fc04 ("mm: avoid leaving partial pfn mappings around in
> error case") from Sep 11, 2024 (linux-next), leads to the following
> Smatch static checker warning:
>
> 	mm/memory.c:2709 remap_pfn_range_notrack()
> 	warn: sleeping in atomic context
>
> mm/memory.c
>     2696 int remap_pfn_range_notrack(struct vm_area_struct *vma, unsigned long addr,
>     2697                 unsigned long pfn, unsigned long size, pgprot_t prot)
>     2698 {
>     2699         int error = remap_pfn_range_internal(vma, addr, pfn, size, prot);
>     2700
>     2701         if (!error)
>     2702                 return 0;
>     2703
>     2704         /*
>     2705          * A partial pfn range mapping is dangerous: it does not
>     2706          * maintain page reference counts, and callers may free
>     2707          * pages due to the error. So zap it early.
>     2708          */
> --> 2709         zap_page_range_single(vma, addr, size, NULL);
>
> The lru_add_drain() function at the start of zap_page_range_single() takes a
> mutext.

Hm does it? I see a local lock, and some folio batch locking which are
local locks too?

Unless this is hugetlb, I see:

-> hugetlb_zap_begin()
   -> __hugetlb_zap_begin()
      -> hugetlb_vma_lock_write()
         -> down_write()
            -> might_sleep()

(Also __hugetlb_zap_begin() -> i_mmap_lock_write() -> down_write())

I see only spin locks in the page table allocation paths (unless I'm
missing something).

I may be missing something, however!

>
>     2710         return error;
>     2711 }
>
> It's the preempt_disable() in gru_fault() which is the issue.  The call tree
> is:
>
> gru_fault() <- disables preempt
> -> remap_pfn_range()
>    -> remap_pfn_range_notrack()
>
> regards,
> dan carpenter
>


  parent reply	other threads:[~2024-09-15 12:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-15 10:08 Dan Carpenter
2024-09-15 10:23 ` Linus Torvalds
2024-09-15 12:05   ` Dan Carpenter
2024-09-15 13:14     ` Linus Torvalds
2024-09-18 21:08       ` Dimitri Sivanich
2024-09-15 12:01 ` Lorenzo Stoakes [this message]
2024-09-15 12:09   ` Dan Carpenter
2024-09-15 12:38     ` Lorenzo Stoakes
2024-09-15 13:14       ` Dan Carpenter
2024-09-15 13:26         ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=68590155-fd3c-4ce4-9a1f-d314efada198@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-mm@kvack.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox