2024-01-07 04:31:00

by Yukai Wu

[permalink] [raw]
Subject: [PATCH] x86/mm: Remove unnecessary casts in init_64.c

Some pointers in init_64.c do not need to cast the type.

Signed-off-by: Yukai Wu <[email protected]>
---
arch/x86/mm/init_64.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index a190aae8c..f5bbac54b 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -150,7 +150,7 @@ static void sync_global_pgds_l5(unsigned long start, unsigned long end)
pgd_t *pgd;
spinlock_t *pgt_lock;

- pgd = (pgd_t *)page_address(page) + pgd_index(addr);
+ pgd = page_address(page) + pgd_index(addr);
/* the pgt_lock only for Xen */
pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
spin_lock(pgt_lock);
@@ -192,7 +192,7 @@ static void sync_global_pgds_l4(unsigned long start, unsigned long end)
p4d_t *p4d;
spinlock_t *pgt_lock;

- pgd = (pgd_t *)page_address(page) + pgd_index(addr);
+ pgd = page_address(page) + pgd_index(addr);
p4d = p4d_offset(pgd, addr);
/* the pgt_lock only for Xen */
pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
@@ -249,7 +249,7 @@ static __ref void *spp_getpage(void)
static p4d_t *fill_p4d(pgd_t *pgd, unsigned long vaddr)
{
if (pgd_none(*pgd)) {
- p4d_t *p4d = (p4d_t *)spp_getpage();
+ p4d_t *p4d = spp_getpage();
pgd_populate(&init_mm, pgd, p4d);
if (p4d != p4d_offset(pgd, 0))
printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
@@ -261,7 +261,7 @@ static p4d_t *fill_p4d(pgd_t *pgd, unsigned long vaddr)
static pud_t *fill_pud(p4d_t *p4d, unsigned long vaddr)
{
if (p4d_none(*p4d)) {
- pud_t *pud = (pud_t *)spp_getpage();
+ pud_t *pud = spp_getpage();
p4d_populate(&init_mm, p4d, pud);
if (pud != pud_offset(p4d, 0))
printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
@@ -273,7 +273,7 @@ static pud_t *fill_pud(p4d_t *p4d, unsigned long vaddr)
static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
{
if (pud_none(*pud)) {
- pmd_t *pmd = (pmd_t *) spp_getpage();
+ pmd_t *pmd = spp_getpage();
pud_populate(&init_mm, pud, pmd);
if (pmd != pmd_offset(pud, 0))
printk(KERN_ERR "PAGETABLE BUG #02! %p <-> %p\n",
@@ -285,7 +285,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
static pte_t *fill_pte(pmd_t *pmd, unsigned long vaddr)
{
if (pmd_none(*pmd)) {
- pte_t *pte = (pte_t *) spp_getpage();
+ pte_t *pte = spp_getpage();
pmd_populate_kernel(&init_mm, pmd, pte);
if (pte != pte_offset_kernel(pmd, 0))
printk(KERN_ERR "PAGETABLE BUG #03!\n");
@@ -378,19 +378,19 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
for (; size; phys += PMD_SIZE, size -= PMD_SIZE) {
pgd = pgd_offset_k((unsigned long)__va(phys));
if (pgd_none(*pgd)) {
- p4d = (p4d_t *) spp_getpage();
+ p4d = spp_getpage();
set_pgd(pgd, __pgd(__pa(p4d) | _KERNPG_TABLE |
_PAGE_USER));
}
p4d = p4d_offset(pgd, (unsigned long)__va(phys));
if (p4d_none(*p4d)) {
- pud = (pud_t *) spp_getpage();
+ pud = spp_getpage();
set_p4d(p4d, __p4d(__pa(pud) | _KERNPG_TABLE |
_PAGE_USER));
}
pud = pud_offset(p4d, (unsigned long)__va(phys));
if (pud_none(*pud)) {
- pmd = (pmd_t *) spp_getpage();
+ pmd = spp_getpage();
set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
_PAGE_USER));
}
--
2.34.1



2024-01-07 16:46:25

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH] x86/mm: Remove unnecessary casts in init_64.c

> - pgd = (pgd_t *)page_address(page) + pgd_index(addr);
> + pgd = page_address(page) + pgd_index(addr);

Please learn C operator precedence rules before touching this code.

> - pgd = (pgd_t *)page_address(page) + pgd_index(addr);
> + pgd = page_address(page) + pgd_index(addr);

2024-01-09 21:35:40

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH] x86/mm: Remove unnecessary casts in init_64.c

On Sun, Jan 07 2024 at 12:24, Yukai Wu wrote:
> @@ -150,7 +150,7 @@ static void sync_global_pgds_l5(unsigned long start, unsigned long end)
> pgd_t *pgd;
> spinlock_t *pgt_lock;
>
> - pgd = (pgd_t *)page_address(page) + pgd_index(addr);
> + pgd = page_address(page) + pgd_index(addr);

This is not equivalent.

Thanks,

tglx

2024-01-12 13:20:45

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] x86/mm: Remove unnecessary casts in init_64.c



Hello,

kernel test robot noticed "kernel_BUG_at_arch/x86/mm/init_64.c" on:

commit: b4f7cb0d6fbedcc9946304f02513f97ae2d3ef0c ("[PATCH] x86/mm: Remove unnecessary casts in init_64.c")
url: https://github.com/intel-lab-lkp/linux/commits/Yukai-Wu/x86-mm-Remove-unnecessary-casts-in-init_64-c/20240107-123342
base: https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git 91c17d7b04498ffb52939a18eb7e28fd23c9b654
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH] x86/mm: Remove unnecessary casts in init_64.c

in testcase: filebench
version: filebench-x86_64-22620e6-1_20221010
with following parameters:

disk: 1HDD
fs: btrfs
fs2: cifs
test: filemicro_create.f
cpufreq_governor: performance



compiler: gcc-12
test machine: 96 threads 2 sockets Intel(R) Xeon(R) Platinum 8260L CPU @ 2.40GHz (Cascade Lake) with 128G memory

(please refer to attached dmesg/kmsg for entire log/backtrace)



If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]


[ 31.641127][ T1120] ------------[ cut here ]------------
[ 31.646457][ T1120] kernel BUG at arch/x86/mm/init_64.c:202!
[ 31.652129][ T1120] invalid opcode: 0000 [#1] SMP NOPTI
[ 31.657362][ T1120] CPU: 12 PID: 1120 Comm: systemd-udevd Not tainted 6.7.0-rc2-00003-gb4f7cb0d6fbe #1
[ 31.666670][ T1120] Hardware name: Intel Corporation S2600WFD/S2600WFD, BIOS SE5C620.86B.0D.01.0286.011120190816 01/11/2019
[ 31.677790][ T1120] RIP: 0010:sync_global_pgds_l4 (arch/x86/mm/init_64.c:202 (discriminator 1))
[ 31.683541][ T1120] Code: e8 97 ea 00 00 48 89 c6 49 89 36 e9 2a ff ff ff 48 c7 c7 48 90 bb 83 c6 07 00 0f 1f 00 8b 0d 8d d1 94 01 e9 84 fe ff ff 0f 0b <0f> 0b 66 66 2e 0f 1f 84 00 00 00 00 00 66 66 2e 0f 1f 84 00 00 00
All code
========
0: e8 97 ea 00 00 callq 0xea9c
5: 48 89 c6 mov %rax,%rsi
8: 49 89 36 mov %rsi,(%r14)
b: e9 2a ff ff ff jmpq 0xffffffffffffff3a
10: 48 c7 c7 48 90 bb 83 mov $0xffffffff83bb9048,%rdi
17: c6 07 00 movb $0x0,(%rdi)
1a: 0f 1f 00 nopl (%rax)
1d: 8b 0d 8d d1 94 01 mov 0x194d18d(%rip),%ecx # 0x194d1b0
23: e9 84 fe ff ff jmpq 0xfffffffffffffeac
28: 0f 0b ud2
2a:* 0f 0b ud2 <-- trapping instruction
2c: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1)
33: 00 00 00 00
37: 66 data16
38: 66 data16
39: 2e cs
3a: 0f .byte 0xf
3b: 1f (bad)
3c: 84 00 test %al,(%rax)
...

Code starting with the faulting instruction
===========================================
0: 0f 0b ud2
2: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1)
9: 00 00 00 00
d: 66 data16
e: 66 data16
f: 2e cs
10: 0f .byte 0xf
11: 1f (bad)
12: 84 00 test %al,(%rax)
...
[ 31.702992][ T1120] RSP: 0018:ffffc9000aa8b9b8 EFLAGS: 00010206
[ 31.708918][ T1120] RAX: ffff88805f7f4000 RBX: ffff88df7f20d4ac RCX: ffff888000000000
[ 31.716743][ T1120] RDX: 000ffffffffff000 RSI: ffff8881bdc72000 RDI: ffff88df7f20d4ac
[ 31.724566][ T1120] RBP: ffff890000000000 R08: 8000000000000163 R09: 0000000000000001
[ 31.732395][ T1120] R10: ffff890000000000 R11: 0000000000000001 R12: ffffffff82c1c890
[ 31.740218][ T1120] R13: 0000000001ffff12 R14: ffff88df65642112 R15: ffffea017d959080
[ 31.748045][ T1120] FS: 00007f916a9ae8c0(0000) GS:ffff88903f900000(0000) knlGS:0000000000000000
[ 31.756822][ T1120] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 31.761388][ T8] EDID block 0 (tag 0x00) checksum is invalid, remainder is 125
[ 31.763260][ T1120] CR2: 00007f9169f4f56c CR3: 0000005f6511a006 CR4: 00000000007706f0
[ 31.763261][ T1120] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 31.763262][ T1120] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 31.763263][ T1120] PKRU: 55555554
[ 31.770744][ T8] [00] BAD 00 ff ff ff ff ff ff 00 ff ff ff ff ff ff ff ff
[ 31.778566][ T1120] Call Trace:
[ 31.778568][ T1120] <TASK>
[ 31.778569][ T1120] ? die (arch/x86/kernel/dumpstack.c:421 arch/x86/kernel/dumpstack.c:434 arch/x86/kernel/dumpstack.c:447)
[ 31.786396][ T8] [00] BAD ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 31.794218][ T1120] ? do_trap (arch/x86/kernel/traps.c:112 arch/x86/kernel/traps.c:153)
[ 31.794221][ T1120] ? sync_global_pgds_l4 (arch/x86/mm/init_64.c:202 (discriminator 1))
[ 31.794222][ T1120] ? do_error_trap (arch/x86/include/asm/traps.h:59 arch/x86/kernel/traps.c:174)
[ 31.797627][ T8] [00] BAD ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 31.804843][ T1120] ? sync_global_pgds_l4 (arch/x86/mm/init_64.c:202 (discriminator 1))
[ 31.804844][ T1120] ? exc_invalid_op (arch/x86/kernel/traps.c:265)
[ 31.807991][ T8] [00] BAD ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 31.810789][ T1120] ? sync_global_pgds_l4 (arch/x86/mm/init_64.c:202 (discriminator 1))
[ 31.810791][ T1120] ? asm_exc_invalid_op (arch/x86/include/asm/idtentry.h:568)
[ 31.814368][ T8] [00] BAD ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 31.821589][ T1120] ? sync_global_pgds_l4 (arch/x86/mm/init_64.c:202 (discriminator 1))
[ 31.821590][ T1120] ? sync_global_pgds_l4 (arch/x86/mm/init_64.c:201)
[ 31.821591][ T1120] __kernel_physical_mapping_init (arch/x86/mm/init_64.c:773)
[ 31.825611][ T8] [00] BAD ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 31.830749][ T1120] init_memory_mapping (arch/x86/mm/init.c:548 (discriminator 3))
[ 31.830753][ T1120] arch_add_memory (arch/x86/mm/init_64.c:969)
[ 31.830755][ T1120] pagemap_range (mm/memremap.c:246)
[ 31.835203][ T8] [00] BAD ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 31.842420][ T1120] memremap_pages (mm/memremap.c:367)
[ 31.842422][ T1120] ? devres_add (drivers/base/devres.c:70 drivers/base/devres.c:134 drivers/base/devres.c:249)
[ 31.847568][ T8] [00] BAD ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 31.852100][ T1120] devm_memremap_pages (mm/memremap.c:407)
[ 31.852114][ T1120] dev_dax_probe (drivers/dax/device.c:449) device_dax
[ 31.859677][ T777] scsi host5: ahci
[ 31.864475][ T1120] dax_bus_probe (drivers/dax/bus.c:201)
[ 31.869394][ T777] ata1: DUMMY
[ 31.876575][ T1120] really_probe (drivers/base/dd.c:579 drivers/base/dd.c:658)
[ 31.881714][ T777] ata2: DUMMY
[ 31.886852][ T1120] ? __pfx___driver_attach (drivers/base/dd.c:1157)
[ 31.886854][ T1120] __driver_probe_device (drivers/base/dd.c:800)
[ 31.886856][ T1120] driver_probe_device (drivers/base/dd.c:830)
[ 31.892773][ T777] ata3: DUMMY
[ 31.899989][ T1120] __driver_attach (drivers/base/dd.c:1217)
[ 31.899992][ T1120] bus_for_each_dev (drivers/base/bus.c:368)
[ 31.899994][ T1120] bus_add_driver (drivers/base/bus.c:673)
[ 31.904873][ T777] ata4: DUMMY
[ 31.909318][ T1120] driver_register (drivers/base/driver.c:246)
[ 31.909320][ T1120] ? __pfx_dax_init (drivers/dax/device.c:263) device_dax
[ 31.913776][ T777] ata5: SATA max UDMA/133 abar m524288@0x92180000 port 0x92180300 irq 358 lpm-pol 0
[ 31.920990][ T1120] do_one_initcall (init/main.c:1236)
[ 31.925525][ T777] ata6: SATA max UDMA/133 abar m524288@0x92180000 port 0x92180380 irq 358 lpm-pol 0
[ 31.929709][ T1120] do_init_module (kernel/module/main.c:2530)
[ 31.937992][ T777] ahci 0000:00:17.0: AHCI 0001.0301 32 slots 8 ports 6 Gbps 0xff impl SATA mode
[ 31.941722][ T1120] init_module_from_file (kernel/module/main.c:3148)
[ 31.941725][ T1120] idempotent_init_module (include/linux/spinlock.h:351 kernel/module/main.c:3111 kernel/module/main.c:3165)
[ 31.947303][ T777] ahci 0000:00:17.0: flags: 64bit ncq sntf led clo only pio slum part ems deso sadm sds apst
[ 31.950878][ T1120] __x64_sys_finit_module (include/linux/file.h:45 kernel/module/main.c:3187 kernel/module/main.c:3169 kernel/module/main.c:3169)
[ 31.950880][ T1120] do_syscall_64 (arch/x86/entry/common.c:51 arch/x86/entry/common.c:82)
[ 31.977632][ T777] scsi host6: ahci
[ 31.980789][ T1120] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:129)
[ 31.984225][ T777] scsi host7: ahci
[ 31.988473][ T1120] RIP: 0033:0x7f916ae63f29
[ 31.988475][ T1120] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 37 8f 0d 00 f7 d8 64 89 01 48
All code
========
0: 00 c3 add %al,%bl
2: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
9: 00 00 00
c: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
11: 48 89 f8 mov %rdi,%rax
14: 48 89 f7 mov %rsi,%rdi
17: 48 89 d6 mov %rdx,%rsi
1a: 48 89 ca mov %rcx,%rdx
1d: 4d 89 c2 mov %r8,%r10
20: 4d 89 c8 mov %r9,%r8
23: 4c 8b 4c 24 08 mov 0x8(%rsp),%r9
28: 0f 05 syscall
2a:* 48 3d 01 f0 ff ff cmp $0xfffffffffffff001,%rax <-- trapping instruction
30: 73 01 jae 0x33
32: c3 retq
33: 48 8b 0d 37 8f 0d 00 mov 0xd8f37(%rip),%rcx # 0xd8f71
3a: f7 d8 neg %eax
3c: 64 89 01 mov %eax,%fs:(%rcx)
3f: 48 rex.W

Code starting with the faulting instruction
===========================================
0: 48 3d 01 f0 ff ff cmp $0xfffffffffffff001,%rax
6: 73 01 jae 0x9
8: c3 retq
9: 48 8b 0d 37 8f 0d 00 mov 0xd8f37(%rip),%rcx # 0xd8f47
10: f7 d8 neg %eax
12: 64 89 01 mov %eax,%fs:(%rcx)
15: 48 rex.W


The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20240112/[email protected]



--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki