From: Dave Hansen <dave.hansen@intel.com>
To: Marco Elver <elver@google.com>,
Naresh Kamboju <naresh.kamboju@linaro.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: kasan-dev <kasan-dev@googlegroups.com>, X86 ML <x86@kernel.org>,
open list <linux-kernel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>,
regressions@lists.linux.dev, lkft-triage@lists.linaro.org,
Andrew Morton <akpm@linux-foundation.org>,
Alexander Potapenko <glider@google.com>
Subject: Re: WARNING: CPU: 0 PID: 0 at arch/x86/include/asm/kfence.h:46 kfence_protect
Date: Thu, 17 Nov 2022 06:34:15 -0800 [thread overview]
Message-ID: <4208866d-338f-4781-7ff9-023f016c5b07@intel.com> (raw)
In-Reply-To: <Y3Y+DQsWa79bNuKj@elver.google.com>
[-- Attachment #1: Type: text/plain, Size: 1659 bytes --]
On 11/17/22 05:58, Marco Elver wrote:
> [ 0.663761] WARNING: CPU: 0 PID: 0 at arch/x86/include/asm/kfence.h:46 kfence_protect+0x7b/0x120
> [ 0.664033] WARNING: CPU: 0 PID: 0 at mm/kfence/core.c:234 kfence_protect+0x7d/0x120
> [ 0.664465] kfence: kfence_init failed
Any chance you could add some debugging and figure out what actually
made kfence call over? Was it the pte or the level?
if (WARN_ON(!pte || level != PG_LEVEL_4K))
return false;
I can see how the thing you bisected to might lead to a page table not
being split, which could mess with the 'level' check.
Also, is there a reason this code is mucking with the page tables
directly? It seems, uh, rather wonky. This, for instance:
> if (protect)
> set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_PRESENT));
> else
> set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT));
>
> /*
> * Flush this CPU's TLB, assuming whoever did the allocation/free is
> * likely to continue running on this CPU.
> */
> preempt_disable();
> flush_tlb_one_kernel(addr);
> preempt_enable();
Seems rather broken. I assume the preempt_disable() is there to get rid
of some warnings. But, there is nothing I can see to *keep* the CPU
that did the free from being different from the one where the TLB flush
is performed until the preempt_disable(). That makes the
flush_tlb_one_kernel() mostly useless.
Is there a reason this code isn't using the existing page table
manipulation functions and tries to code its own? What prevents it from
using something like the attached patch?
[-- Attachment #2: kfence.patch --]
[-- Type: text/x-patch, Size: 1265 bytes --]
diff --git a/arch/x86/include/asm/kfence.h b/arch/x86/include/asm/kfence.h
index ff5c7134a37a..5cdb3a1f3995 100644
--- a/arch/x86/include/asm/kfence.h
+++ b/arch/x86/include/asm/kfence.h
@@ -37,34 +37,13 @@ static inline bool arch_kfence_init_pool(void)
return true;
}
-/* Protect the given page and flush TLB. */
static inline bool kfence_protect_page(unsigned long addr, bool protect)
{
- unsigned int level;
- pte_t *pte = lookup_address(addr, &level);
-
- if (WARN_ON(!pte || level != PG_LEVEL_4K))
- return false;
-
- /*
- * We need to avoid IPIs, as we may get KFENCE allocations or faults
- * with interrupts disabled. Therefore, the below is best-effort, and
- * does not flush TLBs on all CPUs. We can tolerate some inaccuracy;
- * lazy fault handling takes care of faults after the page is PRESENT.
- */
-
if (protect)
- set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_PRESENT));
+ set_memory_np(addr, addr + PAGE_SIZE);
else
- set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT));
+ set_memory_p(addr, addr + PAGE_SIZE);
- /*
- * Flush this CPU's TLB, assuming whoever did the allocation/free is
- * likely to continue running on this CPU.
- */
- preempt_disable();
- flush_tlb_one_kernel(addr);
- preempt_enable();
return true;
}
next prev parent reply other threads:[~2022-11-17 14:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 11:31 Naresh Kamboju
2022-11-17 13:58 ` Marco Elver
2022-11-17 14:34 ` Dave Hansen [this message]
2022-11-17 23:23 ` Marco Elver
2022-11-17 23:54 ` Dave Hansen
2022-11-18 9:19 ` Marco Elver
2022-11-18 10:32 ` Peter Zijlstra
2022-11-21 7:28 ` Naresh Kamboju
2022-11-21 8:43 ` Marco Elver
2022-11-21 5:40 ` Naresh Kamboju
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=4208866d-338f-4781-7ff9-023f016c5b07@intel.com \
--to=dave.hansen@intel.com \
--cc=akpm@linux-foundation.org \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkft-triage@lists.linaro.org \
--cc=naresh.kamboju@linaro.org \
--cc=peterz@infradead.org \
--cc=regressions@lists.linux.dev \
--cc=x86@kernel.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