Skip to content

Commit 8904976

Browse files
petalogixmichalsimek
authored andcommitted
microblaze: Unprivileged stream instruction awareness
Add cpuinfo support for the new MicroBlaze option permitting userspace (unprivileged) access to the streaming instructions (FSL / AXI-stream). Emit a noisy warning at bootup if this is enabled, because bad user code can potentially lockup the CPU. Signed-off-by: John A. Williams <john.williams@petalogix.com> Signed-off-by: Michal Simek <monstr@monstr.eu>
1 parent 5db34eb commit 8904976

6 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎arch/microblaze/include/asm/cpuinfo.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct cpuinfo {
3838
u32 use_exc;
3939
u32 ver_code;
4040
u32 mmu;
41+
u32 mmu_privins;
4142
u32 endian;
4243

4344
/* CPU caches */

‎arch/microblaze/include/asm/pvr.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ struct pvr_s {
117117
#define PVR11_MMU_DTLB_SIZE 0x07000000
118118
#define PVR11_MMU_TLB_ACCESS 0x00C00000
119119
#define PVR11_MMU_ZONES 0x003C0000
120+
#define PVR11_MMU_PRIVINS 0x00010000
120121
/* MSR Reset value PVR mask */
121122
#define PVR11_MSR_RESET_VALUE_MASK 0x000007FF
122123

123-
124124
/* PVR access macros */
125125
#define PVR_IS_FULL(_pvr) (_pvr.pvr[0] & PVR0_PVR_FULL_MASK)
126126
#define PVR_USE_BARREL(_pvr) (_pvr.pvr[0] & PVR0_USE_BARREL_MASK)
@@ -216,6 +216,7 @@ struct pvr_s {
216216
#define PVR_MMU_DTLB_SIZE(_pvr) (_pvr.pvr[11] & PVR11_MMU_DTLB_SIZE)
217217
#define PVR_MMU_TLB_ACCESS(_pvr) (_pvr.pvr[11] & PVR11_MMU_TLB_ACCESS)
218218
#define PVR_MMU_ZONES(_pvr) (_pvr.pvr[11] & PVR11_MMU_ZONES)
219+
#define PVR_MMU_PRIVINS(pvr) (pvr.pvr[11] & PVR11_MMU_PRIVINS)
219220

220221
/* endian */
221222
#define PVR_ENDIAN(_pvr) (_pvr.pvr[0] & PVR0_ENDI)

‎arch/microblaze/kernel/cpu/cpuinfo-pvr-full.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void set_cpuinfo_pvr_full(struct cpuinfo *ci, struct device_node *cpu)
7272
CI(pvr_user2, USER2);
7373

7474
CI(mmu, USE_MMU);
75+
CI(mmu_privins, MMU_PRIVINS);
7576
CI(endian, ENDIAN);
7677

7778
CI(use_icache, USE_ICACHE);

‎arch/microblaze/kernel/cpu/cpuinfo-static.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ void __init set_cpuinfo_static(struct cpuinfo *ci, struct device_node *cpu)
119119
ci->pvr_user2 = fcpu(cpu, "xlnx,pvr-user2");
120120

121121
ci->mmu = fcpu(cpu, "xlnx,use-mmu");
122+
ci->mmu_privins = fcpu(cpu, "xlnx,mmu-privileged-instr");
122123
ci->endian = fcpu(cpu, "xlnx,endianness");
123124

124125
ci->ver_code = 0;

‎arch/microblaze/kernel/cpu/cpuinfo.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,8 @@ void __init setup_cpuinfo(void)
8888
printk(KERN_WARNING "%s: Unsupported PVR setting\n", __func__);
8989
set_cpuinfo_static(&cpuinfo, cpu);
9090
}
91+
92+
if (cpuinfo.mmu_privins)
93+
printk(KERN_WARNING "%s: Stream instructions enabled"
94+
" - USERSPACE CAN LOCK THIS KERNEL!\n", __func__);
9195
}

‎arch/microblaze/kernel/cpu/mb.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ static int show_cpuinfo(struct seq_file *m, void *v)
9797
(cpuinfo.use_exc & PVR2_FPU_EXC_MASK) ? "fpu " : "",
9898
(cpuinfo.use_exc & PVR2_USE_FSL_EXC) ? "fsl " : "");
9999

100+
count += seq_printf(m,
101+
"Stream-insns:\t%sprivileged\n",
102+
cpuinfo.mmu_privins ? "un" : "");
103+
100104
if (cpuinfo.use_icache)
101105
count += seq_printf(m,
102106
"Icache:\t\t%ukB\tline length:\t%dB\n",

0 commit comments

Comments
 (0)