Skip to content

Commit acda701

Browse files
committed
Merge tag 'riscv-for-linus-5.11-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: "There are a few more fixes than a normal rc4, largely due to the bubble introduced by the holiday break: - return -ENOSYS for syscall number -1, which previously returned an uninitialized value. - ensure of_clk_init() has been called in time_init(), without which clock drivers may not be initialized. - fix sifive,uart0 driver to properly display the baud rate. A fix to initialize MPIE that allows interrupts to be processed during system calls. - avoid erronously begin tracing IRQs when interrupts are disabled, which at least triggers suprious lockdep failures. - workaround for a warning related to calling smp_processor_id() while preemptible. The warning itself is suprious on currently availiable systems. - properly include the generic time VDSO calls. A fix to our kasan address mapping. A fix to the HiFive Unleashed device tree, which allows the Ethernet PHY to be properly initialized by Linux (as opposed to relying on the bootloader). - defconfig update to include SiFive's GPIO driver, which is present on the HiFive Unleashed and necessary to initialize the PHY. - avoid allocating memory while initializing reserved memory. - avoid allocating the last 4K of memory, as pointers there alias with syscall errors. There are also two cleanups that should have no functional effect but do fix build warnings: - drop a duplicated definition of PAGE_KERNEL_EXEC. - properly declare the asm register SP shim. - cleanup the rv32 memory size Kconfig entry, to reflect the actual size of memory availiable" * tag 'riscv-for-linus-5.11-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: RISC-V: Fix maximum allowed phsyical memory for RV32 RISC-V: Set current memblock limit RISC-V: Do not allocate memblock while iterating reserved memblocks riscv: stacktrace: Move register keyword to beginning of declaration riscv: defconfig: enable gpio support for HiFive Unleashed dts: phy: add GPIO number and active state used for phy reset dts: phy: fix missing mdio device and probe failure of vsc8541-01 device riscv: Fix KASAN memory mapping. riscv: Fixup CONFIG_GENERIC_TIME_VSYSCALL riscv: cacheinfo: Fix using smp_processor_id() in preemptible riscv: Trace irq on only interrupt is enabled riscv: Drop a duplicated PAGE_KERNEL_EXEC riscv: Enable interrupts during syscalls with M-Mode riscv: Fix sifive serial driver riscv: Fix kernel time_init() riscv: return -ENOSYS for syscall -1
2 parents 9348b73 + e557793 commit acda701

14 files changed

Lines changed: 68 additions & 35 deletions

File tree

arch/riscv/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ config PA_BITS
137137

138138
config PAGE_OFFSET
139139
hex
140-
default 0xC0000000 if 32BIT && MAXPHYSMEM_2GB
140+
default 0xC0000000 if 32BIT && MAXPHYSMEM_1GB
141141
default 0x80000000 if 64BIT && !MMU
142142
default 0xffffffff80000000 if 64BIT && MAXPHYSMEM_2GB
143143
default 0xffffffe000000000 if 64BIT && MAXPHYSMEM_128GB
@@ -247,10 +247,12 @@ config MODULE_SECTIONS
247247

248248
choice
249249
prompt "Maximum Physical Memory"
250-
default MAXPHYSMEM_2GB if 32BIT
250+
default MAXPHYSMEM_1GB if 32BIT
251251
default MAXPHYSMEM_2GB if 64BIT && CMODEL_MEDLOW
252252
default MAXPHYSMEM_128GB if 64BIT && CMODEL_MEDANY
253253

254+
config MAXPHYSMEM_1GB
255+
bool "1GiB"
254256
config MAXPHYSMEM_2GB
255257
bool "2GiB"
256258
config MAXPHYSMEM_128GB

arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@
8888
phy-mode = "gmii";
8989
phy-handle = <&phy0>;
9090
phy0: ethernet-phy@0 {
91+
compatible = "ethernet-phy-id0007.0771";
9192
reg = <0>;
93+
reset-gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
9294
};
9395
};
9496

arch/riscv/configs/defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ CONFIG_HW_RANDOM=y
6464
CONFIG_HW_RANDOM_VIRTIO=y
6565
CONFIG_SPI=y
6666
CONFIG_SPI_SIFIVE=y
67+
CONFIG_GPIOLIB=y
68+
CONFIG_GPIO_SIFIVE=y
6769
# CONFIG_PTP_1588_CLOCK is not set
6870
CONFIG_POWER_RESET=y
6971
CONFIG_DRM=y

arch/riscv/include/asm/pgtable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
| _PAGE_DIRTY)
100100

101101
#define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
102-
#define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL | _PAGE_EXEC)
103102
#define PAGE_KERNEL_READ __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
104103
#define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL | _PAGE_EXEC)
105104
#define PAGE_KERNEL_READ_EXEC __pgprot((_PAGE_KERNEL & ~_PAGE_WRITE) \

arch/riscv/include/asm/vdso.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <linux/types.h>
1212

13-
#ifndef GENERIC_TIME_VSYSCALL
13+
#ifndef CONFIG_GENERIC_TIME_VSYSCALL
1414
struct vdso_data {
1515
};
1616
#endif

arch/riscv/kernel/cacheinfo.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ cache_get_priv_group(struct cacheinfo *this_leaf)
2626

2727
static struct cacheinfo *get_cacheinfo(u32 level, enum cache_type type)
2828
{
29-
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(smp_processor_id());
29+
/*
30+
* Using raw_smp_processor_id() elides a preemptability check, but this
31+
* is really indicative of a larger problem: the cacheinfo UABI assumes
32+
* that cores have a homonogenous view of the cache hierarchy. That
33+
* happens to be the case for the current set of RISC-V systems, but
34+
* likely won't be true in general. Since there's no way to provide
35+
* correct information for these systems via the current UABI we're
36+
* just eliding the check for now.
37+
*/
38+
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(raw_smp_processor_id());
3039
struct cacheinfo *this_leaf;
3140
int index;
3241

arch/riscv/kernel/entry.S

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ skip_context_tracking:
124124
REG_L a1, (a1)
125125
jr a1
126126
1:
127-
#ifdef CONFIG_TRACE_IRQFLAGS
128-
call trace_hardirqs_on
129-
#endif
130127
/*
131128
* Exceptions run with interrupts enabled or disabled depending on the
132129
* state of SR_PIE in m/sstatus.
133130
*/
134131
andi t0, s1, SR_PIE
135132
beqz t0, 1f
133+
#ifdef CONFIG_TRACE_IRQFLAGS
134+
call trace_hardirqs_on
135+
#endif
136136
csrs CSR_STATUS, SR_IE
137137

138138
1:
@@ -155,6 +155,15 @@ skip_context_tracking:
155155
tail do_trap_unknown
156156

157157
handle_syscall:
158+
#ifdef CONFIG_RISCV_M_MODE
159+
/*
160+
* When running is M-Mode (no MMU config), MPIE does not get set.
161+
* As a result, we need to force enable interrupts here because
162+
* handle_exception did not do set SR_IE as it always sees SR_PIE
163+
* being cleared.
164+
*/
165+
csrs CSR_STATUS, SR_IE
166+
#endif
158167
#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
159168
/* Recover a0 - a7 for system calls */
160169
REG_L a0, PT_A0(sp)
@@ -186,14 +195,7 @@ check_syscall_nr:
186195
* Syscall number held in a7.
187196
* If syscall number is above allowed value, redirect to ni_syscall.
188197
*/
189-
bge a7, t0, 1f
190-
/*
191-
* Check if syscall is rejected by tracer, i.e., a7 == -1.
192-
* If yes, we pretend it was executed.
193-
*/
194-
li t1, -1
195-
beq a7, t1, ret_from_syscall_rejected
196-
blt a7, t1, 1f
198+
bgeu a7, t0, 1f
197199
/* Call syscall */
198200
la s0, sys_call_table
199201
slli t0, a7, RISCV_LGPTR

arch/riscv/kernel/setup.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ static void __init init_resources(void)
127127
{
128128
struct memblock_region *region = NULL;
129129
struct resource *res = NULL;
130-
int ret = 0;
130+
struct resource *mem_res = NULL;
131+
size_t mem_res_sz = 0;
132+
int ret = 0, i = 0;
131133

132134
code_res.start = __pa_symbol(_text);
133135
code_res.end = __pa_symbol(_etext) - 1;
@@ -145,16 +147,17 @@ static void __init init_resources(void)
145147
bss_res.end = __pa_symbol(__bss_stop) - 1;
146148
bss_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
147149

150+
mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt) * sizeof(*mem_res);
151+
mem_res = memblock_alloc(mem_res_sz, SMP_CACHE_BYTES);
152+
if (!mem_res)
153+
panic("%s: Failed to allocate %zu bytes\n", __func__, mem_res_sz);
148154
/*
149155
* Start by adding the reserved regions, if they overlap
150156
* with /memory regions, insert_resource later on will take
151157
* care of it.
152158
*/
153159
for_each_reserved_mem_region(region) {
154-
res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
155-
if (!res)
156-
panic("%s: Failed to allocate %zu bytes\n", __func__,
157-
sizeof(struct resource));
160+
res = &mem_res[i++];
158161

159162
res->name = "Reserved";
160163
res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
@@ -171,8 +174,10 @@ static void __init init_resources(void)
171174
* Ignore any other reserved regions within
172175
* system memory.
173176
*/
174-
if (memblock_is_memory(res->start))
177+
if (memblock_is_memory(res->start)) {
178+
memblock_free((phys_addr_t) res, sizeof(struct resource));
175179
continue;
180+
}
176181

177182
ret = add_resource(&iomem_resource, res);
178183
if (ret < 0)
@@ -181,10 +186,7 @@ static void __init init_resources(void)
181186

182187
/* Add /memory regions to the resource tree */
183188
for_each_mem_region(region) {
184-
res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
185-
if (!res)
186-
panic("%s: Failed to allocate %zu bytes\n", __func__,
187-
sizeof(struct resource));
189+
res = &mem_res[i++];
188190

189191
if (unlikely(memblock_is_nomap(region))) {
190192
res->name = "Reserved";
@@ -205,9 +207,9 @@ static void __init init_resources(void)
205207
return;
206208

207209
error:
208-
memblock_free((phys_addr_t) res, sizeof(struct resource));
209210
/* Better an empty resource tree than an inconsistent one */
210211
release_child_resources(&iomem_resource);
212+
memblock_free((phys_addr_t) mem_res, mem_res_sz);
211213
}
212214

213215

arch/riscv/kernel/stacktrace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <asm/stacktrace.h>
1616

17-
register unsigned long sp_in_global __asm__("sp");
17+
register const unsigned long sp_in_global __asm__("sp");
1818

1919
#ifdef CONFIG_FRAME_POINTER
2020

@@ -28,9 +28,8 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
2828
sp = user_stack_pointer(regs);
2929
pc = instruction_pointer(regs);
3030
} else if (task == NULL || task == current) {
31-
const register unsigned long current_sp = sp_in_global;
3231
fp = (unsigned long)__builtin_frame_address(0);
33-
sp = current_sp;
32+
sp = sp_in_global;
3433
pc = (unsigned long)walk_stackframe;
3534
} else {
3635
/* task blocked in __switch_to */

arch/riscv/kernel/time.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2017 SiFive
55
*/
66

7+
#include <linux/of_clk.h>
78
#include <linux/clocksource.h>
89
#include <linux/delay.h>
910
#include <asm/sbi.h>
@@ -24,6 +25,8 @@ void __init time_init(void)
2425
riscv_timebase = prop;
2526

2627
lpj_fine = riscv_timebase / HZ;
28+
29+
of_clk_init(NULL);
2730
timer_probe();
2831
}
2932

0 commit comments

Comments
 (0)