Re: [PATCH v5 04/44] x86: asm: instrument usercopy in get_user() and put_user()

From: Yu Zhao
Date: Tue Aug 30 2022 - 18:28:22 EST


On Tue, Aug 30, 2022 at 4:05 PM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, 30 Aug 2022 16:23:44 +0200 Alexander Potapenko <glider@xxxxxxxxxx> wrote:
>
> > > from init/do_mounts.c:2:
> > > ./include/linux/page-flags.h: In function ‘page_fixed_fake_head’:
> > > ./include/linux/page-flags.h:226:36: error: invalid use of undefined type ‘const struct page’
> > > 226 | test_bit(PG_head, &page->flags)) {
> > > | ^~
> > > ./include/linux/bitops.h:50:44: note: in definition of macro ‘bitop’
> > > 50 | __builtin_constant_p((uintptr_t)(addr) != (uintptr_t)NULL) && \
> > > | ^~~~
> > > ./include/linux/page-flags.h:226:13: note: in expansion of macro ‘test_bit’
> > > 226 | test_bit(PG_head, &page->flags)) {
> > > | ^~~~~~~~
> > > ...
> >
> > Gotcha, this is a circular dependency: mm_types.h -> sched.h ->
> > kmsan.h -> gfp.h -> mmzone.h -> page-flags.h -> mm_types.h, where the
> > inclusion of sched.h into mm_types.h was only introduced in "mm:
> > multi-gen LRU: support page table walks" - that's why the problem was
> > missing in other trees.
>
> Ah, thanks for digging that out.
>
> Yu, that inclusion is regrettable.

Sorry for the trouble -- it's also superfluous because we don't call
lru_gen_use_mm() when switching to the kernel.

I've queued the following for now.

--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -3,7 +3,6 @@
#define _LINUX_MM_TYPES_H

#include <linux/mm_types_task.h>
-#include <linux/sched.h>

#include <linux/auxvec.h>
#include <linux/kref.h>
@@ -742,8 +741,7 @@ static inline void lru_gen_init_mm(struct mm_struct *mm)

static inline void lru_gen_use_mm(struct mm_struct *mm)
{
- if (!(current->flags & PF_KTHREAD))
- WRITE_ONCE(mm->lru_gen.bitmap, -1);
+ WRITE_ONCE(mm->lru_gen.bitmap, -1);
}

#else /* !CONFIG_LRU_GEN */