Skip to content

Commit 5de6b46

Browse files
committed
Merge tag 'loongarch-fixes-6.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
Pull LoongArch fixes from Huacai Chen: - make {virt, phys, page, pfn} translation work with KFENCE for LoongArch (otherwise NVMe and virtio-blk cannot work with KFENCE enabled) - update dts files for Loongson-2K series to make devices work correctly - fix a build error * tag 'loongarch-fixes-6.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson: LoongArch: Include linux/sizes.h in addrspace.h to prevent build errors LoongArch: Update dts for Loongson-2K2000 to support GMAC/GNET LoongArch: Update dts for Loongson-2K2000 to support PCI-MSI LoongArch: Update dts for Loongson-2K2000 to support ISA/LPC LoongArch: Update dts for Loongson-2K1000 to support ISA/LPC LoongArch: Make virt_addr_valid()/__virt_addr_valid() work with KFENCE LoongArch: Make {virt, phys, page, pfn} translation work with KFENCE mm: Move lowmem_page_address() a little later
2 parents e1dc191 + a07c772 commit 5de6b46

File tree

10 files changed

+121
-17
lines changed

10 files changed

+121
-17
lines changed

arch/loongarch/boot/dts/loongson-2k1000.dtsi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@
100100
#size-cells = <2>;
101101
dma-coherent;
102102

103+
isa@18000000 {
104+
compatible = "isa";
105+
#size-cells = <1>;
106+
#address-cells = <2>;
107+
ranges = <1 0x0 0x0 0x18000000 0x4000>;
108+
};
109+
103110
liointc0: interrupt-controller@1fe01400 {
104111
compatible = "loongson,liointc-2.0";
105112
reg = <0x0 0x1fe01400 0x0 0x40>,

arch/loongarch/boot/dts/loongson-2k2000-ref.dts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,45 @@
6161

6262
&gmac0 {
6363
status = "okay";
64+
65+
phy-mode = "gmii";
66+
phy-handle = <&phy0>;
67+
mdio {
68+
compatible = "snps,dwmac-mdio";
69+
#address-cells = <1>;
70+
#size-cells = <0>;
71+
phy0: ethernet-phy@0 {
72+
reg = <2>;
73+
};
74+
};
6475
};
6576

6677
&gmac1 {
6778
status = "okay";
79+
80+
phy-mode = "gmii";
81+
phy-handle = <&phy1>;
82+
mdio {
83+
compatible = "snps,dwmac-mdio";
84+
#address-cells = <1>;
85+
#size-cells = <0>;
86+
phy1: ethernet-phy@1 {
87+
reg = <2>;
88+
};
89+
};
6890
};
6991

7092
&gmac2 {
7193
status = "okay";
94+
95+
phy-mode = "rgmii";
96+
phy-handle = <&phy2>;
97+
mdio {
98+
compatible = "snps,dwmac-mdio";
99+
#address-cells = <1>;
100+
#size-cells = <0>;
101+
phy2: ethernet-phy@2 {
102+
reg = <0>;
103+
};
104+
};
72105
};

arch/loongarch/boot/dts/loongson-2k2000.dtsi

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
#address-cells = <2>;
5252
#size-cells = <2>;
5353

54+
isa@18400000 {
55+
compatible = "isa";
56+
#size-cells = <1>;
57+
#address-cells = <2>;
58+
ranges = <1 0x0 0x0 0x18400000 0x4000>;
59+
};
60+
5461
pmc: power-management@100d0000 {
5562
compatible = "loongson,ls2k2000-pmc", "loongson,ls2k0500-pmc", "syscon";
5663
reg = <0x0 0x100d0000 0x0 0x58>;
@@ -109,6 +116,8 @@
109116
msi: msi-controller@1fe01140 {
110117
compatible = "loongson,pch-msi-1.0";
111118
reg = <0x0 0x1fe01140 0x0 0x8>;
119+
interrupt-controller;
120+
#interrupt-cells = <1>;
112121
msi-controller;
113122
loongson,msi-base-vec = <64>;
114123
loongson,msi-num-vecs = <192>;
@@ -140,27 +149,34 @@
140149
#address-cells = <3>;
141150
#size-cells = <2>;
142151
device_type = "pci";
152+
msi-parent = <&msi>;
143153
bus-range = <0x0 0xff>;
144-
ranges = <0x01000000 0x0 0x00008000 0x0 0x18400000 0x0 0x00008000>,
154+
ranges = <0x01000000 0x0 0x00008000 0x0 0x18408000 0x0 0x00008000>,
145155
<0x02000000 0x0 0x60000000 0x0 0x60000000 0x0 0x20000000>;
146156

147157
gmac0: ethernet@3,0 {
148158
reg = <0x1800 0x0 0x0 0x0 0x0>;
149-
interrupts = <12 IRQ_TYPE_LEVEL_HIGH>;
159+
interrupts = <12 IRQ_TYPE_LEVEL_HIGH>,
160+
<13 IRQ_TYPE_LEVEL_HIGH>;
161+
interrupt-names = "macirq", "eth_lpi";
150162
interrupt-parent = <&pic>;
151163
status = "disabled";
152164
};
153165

154166
gmac1: ethernet@3,1 {
155167
reg = <0x1900 0x0 0x0 0x0 0x0>;
156-
interrupts = <14 IRQ_TYPE_LEVEL_HIGH>;
168+
interrupts = <14 IRQ_TYPE_LEVEL_HIGH>,
169+
<15 IRQ_TYPE_LEVEL_HIGH>;
170+
interrupt-names = "macirq", "eth_lpi";
157171
interrupt-parent = <&pic>;
158172
status = "disabled";
159173
};
160174

161175
gmac2: ethernet@3,2 {
162176
reg = <0x1a00 0x0 0x0 0x0 0x0>;
163-
interrupts = <17 IRQ_TYPE_LEVEL_HIGH>;
177+
interrupts = <17 IRQ_TYPE_LEVEL_HIGH>,
178+
<18 IRQ_TYPE_LEVEL_HIGH>;
179+
interrupt-names = "macirq", "eth_lpi";
164180
interrupt-parent = <&pic>;
165181
status = "disabled";
166182
};

arch/loongarch/include/asm/addrspace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define _ASM_ADDRSPACE_H
1212

1313
#include <linux/const.h>
14+
#include <linux/sizes.h>
1415

1516
#include <asm/loongarch.h>
1617

arch/loongarch/include/asm/io.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
#include <asm/pgtable-bits.h>
1515
#include <asm/string.h>
1616

17-
/*
18-
* Change "struct page" to physical address.
19-
*/
20-
#define page_to_phys(page) ((phys_addr_t)page_to_pfn(page) << PAGE_SHIFT)
21-
2217
extern void __init __iomem *early_ioremap(u64 phys_addr, unsigned long size);
2318
extern void __init early_iounmap(void __iomem *addr, unsigned long size);
2419

@@ -73,6 +68,21 @@ extern void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t
7368

7469
#define __io_aw() mmiowb()
7570

71+
#ifdef CONFIG_KFENCE
72+
#define virt_to_phys(kaddr) \
73+
({ \
74+
(likely((unsigned long)kaddr < vm_map_base)) ? __pa((unsigned long)kaddr) : \
75+
page_to_phys(tlb_virt_to_page((unsigned long)kaddr)) + offset_in_page((unsigned long)kaddr);\
76+
})
77+
78+
#define phys_to_virt(paddr) \
79+
({ \
80+
extern char *__kfence_pool; \
81+
(unlikely(__kfence_pool == NULL)) ? __va((unsigned long)paddr) : \
82+
page_address(phys_to_page((unsigned long)paddr)) + offset_in_page((unsigned long)paddr);\
83+
})
84+
#endif
85+
7686
#include <asm-generic/io.h>
7787

7888
#define ARCH_HAS_VALID_PHYS_ADDR_RANGE

arch/loongarch/include/asm/kfence.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
static inline bool arch_kfence_init_pool(void)
1717
{
1818
int err;
19+
char *kaddr, *vaddr;
1920
char *kfence_pool = __kfence_pool;
2021
struct vm_struct *area;
2122

@@ -35,6 +36,14 @@ static inline bool arch_kfence_init_pool(void)
3536
return false;
3637
}
3738

39+
kaddr = kfence_pool;
40+
vaddr = __kfence_pool;
41+
while (kaddr < kfence_pool + KFENCE_POOL_SIZE) {
42+
set_page_address(virt_to_page(kaddr), vaddr);
43+
kaddr += PAGE_SIZE;
44+
vaddr += PAGE_SIZE;
45+
}
46+
3847
return true;
3948
}
4049

arch/loongarch/include/asm/page.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,38 @@ typedef struct { unsigned long pgprot; } pgprot_t;
7878
struct page *dmw_virt_to_page(unsigned long kaddr);
7979
struct page *tlb_virt_to_page(unsigned long kaddr);
8080

81-
#define virt_to_pfn(kaddr) PFN_DOWN(PHYSADDR(kaddr))
81+
#define pfn_to_phys(pfn) __pfn_to_phys(pfn)
82+
#define phys_to_pfn(paddr) __phys_to_pfn(paddr)
83+
84+
#define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
85+
#define phys_to_page(paddr) pfn_to_page(phys_to_pfn(paddr))
86+
87+
#ifndef CONFIG_KFENCE
88+
89+
#define page_to_virt(page) __va(page_to_phys(page))
90+
#define virt_to_page(kaddr) phys_to_page(__pa(kaddr))
91+
92+
#else
93+
94+
#define WANT_PAGE_VIRTUAL
95+
96+
#define page_to_virt(page) \
97+
({ \
98+
extern char *__kfence_pool; \
99+
(__kfence_pool == NULL) ? __va(page_to_phys(page)) : page_address(page); \
100+
})
82101

83102
#define virt_to_page(kaddr) \
84103
({ \
85104
(likely((unsigned long)kaddr < vm_map_base)) ? \
86105
dmw_virt_to_page((unsigned long)kaddr) : tlb_virt_to_page((unsigned long)kaddr);\
87106
})
88107

108+
#endif
109+
110+
#define pfn_to_virt(pfn) page_to_virt(pfn_to_page(pfn))
111+
#define virt_to_pfn(kaddr) page_to_pfn(virt_to_page(kaddr))
112+
89113
extern int __virt_addr_valid(volatile void *kaddr);
90114
#define virt_addr_valid(kaddr) __virt_addr_valid((volatile void *)(kaddr))
91115

arch/loongarch/mm/mmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
#include <linux/export.h>
66
#include <linux/io.h>
7+
#include <linux/kfence.h>
78
#include <linux/memblock.h>
89
#include <linux/mm.h>
910
#include <linux/mman.h>
@@ -111,6 +112,9 @@ int __virt_addr_valid(volatile void *kaddr)
111112
{
112113
unsigned long vaddr = (unsigned long)kaddr;
113114

115+
if (is_kfence_address((void *)kaddr))
116+
return 1;
117+
114118
if ((vaddr < PAGE_OFFSET) || (vaddr >= vm_map_base))
115119
return 0;
116120

arch/loongarch/mm/pgtable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
struct page *dmw_virt_to_page(unsigned long kaddr)
1313
{
14-
return pfn_to_page(virt_to_pfn(kaddr));
14+
return phys_to_page(__pa(kaddr));
1515
}
1616
EXPORT_SYMBOL(dmw_virt_to_page);
1717

1818
struct page *tlb_virt_to_page(unsigned long kaddr)
1919
{
20-
return pfn_to_page(pte_pfn(*virt_to_kpte(kaddr)));
20+
return phys_to_page(pfn_to_phys(pte_pfn(*virt_to_kpte(kaddr))));
2121
}
2222
EXPORT_SYMBOL(tlb_virt_to_page);
2323

include/linux/mm.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,11 +2207,6 @@ static inline int arch_make_folio_accessible(struct folio *folio)
22072207
*/
22082208
#include <linux/vmstat.h>
22092209

2210-
static __always_inline void *lowmem_page_address(const struct page *page)
2211-
{
2212-
return page_to_virt(page);
2213-
}
2214-
22152210
#if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)
22162211
#define HASHED_PAGE_VIRTUAL
22172212
#endif
@@ -2234,6 +2229,11 @@ void set_page_address(struct page *page, void *virtual);
22342229
void page_address_init(void);
22352230
#endif
22362231

2232+
static __always_inline void *lowmem_page_address(const struct page *page)
2233+
{
2234+
return page_to_virt(page);
2235+
}
2236+
22372237
#if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL)
22382238
#define page_address(page) lowmem_page_address(page)
22392239
#define set_page_address(page, address) do { } while(0)

0 commit comments

Comments
 (0)