All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Guo <dongtai.guo@linux.dev>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: kernel@xen0n.name, rppt@kernel.org, akpm@linux-foundation.org,
	dave.hansen@linux.intel.com, geert@linux-m68k.org,
	ptesarik@suse.com, guoweikang.kernel@gmail.com,
	maobibo@loongson.cn, loongarch@lists.linux.dev,
	George Guo <guodongtai@kylinos.cn>
Subject: Re: [PATCH 1/1] LoongArch: mm: remove redundant pte occupancy check in __set_fixmap()
Date: Tue, 13 May 2025 10:19:48 +0800	[thread overview]
Message-ID: <20250513101948.000036d6@linux.dev> (raw)
In-Reply-To: <CAAhV-H5eUtV6N=jt9sUyKXLAP2sX2kHA7rEbyKuSL1G-kRiXFg@mail.gmail.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=GB18030, Size: 4360 bytes --]

On Sat, 10 May 2025 15:34:01 +0800
Huacai Chen <chenhuacai@kernel.org> wrote:

> Hi, George,
> 
> On Thu, May 8, 2025 at 11:056§2AM george <dongtai.guo@linux.dev> wrote:
> >
> > From: George Guo <guodongtai@kylinos.cn>
> >
> > This check could falsely report errors when PTEs are remapped:
> > arch/loongarch/mm/init.c:204: bad pte 0000000107b601c3.
> >
> > The check was unnecessary because:
> > - Fixmap slots are designed to be reusable
> > - Other architectures (x86/arm64) allow PTE overwrites
> > - Callers are responsible for proper mapping management
> >
> > Signed-off-by: George Guo <guodongtai@kylinos.cn>
> > ---
> >  arch/loongarch/mm/init.c | 4 ----
> >  1 file changed, 4 deletions(-)
> >
> > diff --git a/arch/loongarch/mm/init.c b/arch/loongarch/mm/init.c
> > index 06f11d9e4ec1..7b7e3b1aa00d 100644
> > --- a/arch/loongarch/mm/init.c
> > +++ b/arch/loongarch/mm/init.c
> > @@ -200,10 +200,6 @@ void __init __set_fixmap(enum fixed_addresses
> > idx, BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
> >
> >         ptep = populate_kernel_pte(addr);
> > -       if (!pte_none(ptep_get(ptep))) {
> > -               pte_ERROR(*ptep);
> > -               return;
> > -       }
> Resolve what problems? If other patches need this change, please
> submit them as a series.
Here is a test case to show the bug:
#include <linux/module.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <asm/io.h>
#include <asm-generic/fixmap.h>

#define ALLOC_SIZE 8192  // 8KB

static char *vmalloc_mem = NULL;

static int __init fixmap_test_init(void)
{
	struct page *page;
	phys_addr_t phys;
	void *addr;
	char c;
	void __iomem *base;
	char *charp;

	pr_info("%s module loaded!\n", THIS_MODULE->name);

	addr = vmalloc_mem = vmalloc(ALLOC_SIZE);
	if (!vmalloc_mem) {
		pr_err("Failed to allocate memory with vmalloc\n");
		return -ENOMEM;
	}

	vmalloc_mem[4099] = 'a';
	vmalloc_mem[0] = 'g';
	pr_info("Allocated vmalloc memory at virtual address: %px,
	vmalloc_mem[0]=%c\n", vmalloc_mem, vmalloc_mem[0]);

	//vrit addr -> phys addr
	page = vmalloc_to_page(addr);
	phys = page_to_phys(page) + offset_in_page(addr);
	pr_info("phys = 0x%lx\n", phys);


	__set_fixmap(FIX_TEXT_POKE0, phys & PAGE_MASK, FIXMAP_PAGE_IO);
	base = (void __iomem *)__fix_to_virt(FIX_TEXT_POKE0);
	base += phys & ~PAGE_MASK;
	charp = (char *)base;
	pr_info("fixmap virt addr=0x%lx,charp[0] = %c\n",base,
	charp[0]);
	__set_fixmap(FIX_TEXT_POKE0, 0, FIXMAP_PAGE_CLEAR);

	return 0;
}

static void __exit fixmap_test_exit(void)
{
	if (vmalloc_mem) {
		vfree(vmalloc_mem);
		pr_info("Freed vmalloc memory\n");
	}

	pr_info("%s module unloaded!\n", THIS_MODULE->name);
}

module_init(fixmap_test_init);
module_exit(fixmap_test_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("George Guo <guodongtai@kylinos.cn>");
MODULE_DESCRIPTION("fixmap test");

And below is the log for test:

arm64:

first insmod:
[10476.162720] fixmap_test module loaded!
[10476.163390] Allocated vmalloc memory at virtual address:
ffff80008008f000, vmalloc_mem[0]=g
[10476.164497] phys = 0x10fab2000
[10476.165106] fixmap virt addr=0xffffffffff5fc000,charp[0] = g

rmmod then insmod again:
[10514.031689] Freed vmalloc memory
[10514.032268] fixmap_test module unloaded!
[10516.391483] fixmap_test module loaded!
[10516.392135] Allocated vmalloc memory at virtual address:
ffff800080097000, vmalloc_mem[0]=g
[10516.393205] phys = 0x10dc2c000
[10516.393663] fixmap virt addr=0xffffffffff5fc000,charp[0] = g


loongarch:

first insmod:
[   43.983300] [   T1399] fixmap test module loaded
[   43.983570] [   T1399] Allocated vmalloc memory at virtual address:
ffff80001b45c000, vmalloc_mem[0]=g
[   43.983973] [   T1399] phys = 0x107b60000
[   43.984535] [   T1399] fixmap virt addr=0xfffffffffffd8000,charp[0]
= g

rmmod then insmod again:
[   52.266230] [   T1417] Freed vmalloc memory
[   55.344169] [   T1421] fixmap test module loaded
[   55.344441] [   T1421] Allocated vmalloc memory at virtual address:
ffff80001b344000, vmalloc_mem[0]=g
[   55.344915] [   T1421] phys = 0x10ae04000
[   55.345503] [   T1421] arch/loongarch/mm/init.c:204: bad pte
0000000107b601c3.
[   55.346087] [   T1421] fixmap virt addr=0xfffffffffffd8000,charp[0]
= \x00

> 
> Huacai
> 
> >
> >         if (pgprot_val(flags))
> >                 set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, flags));
> > --
> > 2.34.1
> >
> >


  reply	other threads:[~2025-05-13  2:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08  3:05 [PATCH 1/1] LoongArch: mm: remove redundant pte occupancy check in __set_fixmap() george
2025-05-08  5:23 ` Yanteng Si
2025-05-08  5:42   ` Andrew Morton
2025-05-08  5:56     ` Yanteng Si
2025-05-10  7:34 ` Huacai Chen
2025-05-13  2:19   ` George Guo [this message]
2025-08-21  3:05     ` [PATCH v2] " george
2025-08-28  6:34       ` Huacai Chen

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=20250513101948.000036d6@linux.dev \
    --to=dongtai.guo@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=chenhuacai@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=geert@linux-m68k.org \
    --cc=guodongtai@kylinos.cn \
    --cc=guoweikang.kernel@gmail.com \
    --cc=kernel@xen0n.name \
    --cc=loongarch@lists.linux.dev \
    --cc=maobibo@loongson.cn \
    --cc=ptesarik@suse.com \
    --cc=rppt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.