arm64:msr: Add MSR driver
cover arm64:msr: Add MSR driver
Hi
MSR ARM driver aims to provide interfacs for user to read or write data to all system registers. Its functions is same as MSR driver (x86 platform). It mainly depends on kprobe and undef exception to read or write system registers dynamicly.
In addition, this module create interfaces for each core. We have tested in the virtual machine using tree command:
$ tree /dev/cpu
/dev/cpu
|-- 0
| `-- msr
|-- 1
| `-- msr
|-- 2
| `-- msr
|-- 3
| `-- msr
|-- 4
| `-- msr
|-- 5
| `-- msr
|-- 6
| `-- msr
`-- 7
`-- msr8 directories, 8 files
The interfaces of this module is same as MSR module in user space, and to solve the problem that ARM platform has no similar MSR module. Using this interface, we did some pressure tests to test the stability and security of MSR driver. The test results show that the driver will not cause system panic if various illegal values and multithreading concurrent access are passed through the interface.
We also designed a user space tool: system-register-tools. We have open sourced this tool, which link as follows:
https://github.com/alibaba/system-register-tools
In this tools, we provide two command: rdasr and wrasr, the aboving MSR driver has been tested by:
$ rdasr -t 0: OSDTRRX_EL1 : UNDEFINED or unreadable! 1: DBGBVR0_EL1 : 0x0 2: DBGBCR0_EL1 : 0x1e0 3: DBGWVR0_EL1 : 0x0 4: DBGWCR0_EL1 : 0x0 5: DBGBVR1_EL1 : 0x0 6: DBGBCR1_EL1 : 0x1e0 7: DBGWVR1_EL1 : 0x0 8: DBGWCR1_EL1 : 0x0 9: MDCCINT_EL1 : 0x0 10: MDSCR_EL1 : 0x1000 11: DBGBVR2_EL1 : 0x0 ... ... 598: ICC_IGRPEN1_EL3 : UNDEFINED or unreadable! 599: TPIDR_EL3 : UNDEFINED or unreadable! 600: SCXTNUM_EL3 : UNDEFINED or unreadable! 601: CNTPS_TVAL_EL1 : UNDEFINED or unreadable! 602: CNTPS_CTL_EL1 : UNDEFINED or unreadable! 603: CNTPS_CVAL_EL1 : UNDEFINED or unreadable! 604: CNTPS_CVAL_EL1 : UNDEFINED or unreadable!
The test ended and no system exception occurred!
Undefined or unreadable registers: 409
Readable registers: 196
The above is a test of more than 600 system registers, and no system exception occurred
Rongwei Wang (3):
arm64:insn: Export the symbol to modify code text arm64:msr: Introduce MSR ARM driver arm64:msr: Enable MSR ARM driver
arch/arm64/Kconfig | 9 + arch/arm64/configs/defconfig | 1 + arch/arm64/include/asm/msr_arm.h | 80 ++++++++ arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/insn.c | 1 + arch/arm64/kernel/msr_arm.c | 406 +++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/msr_smp.c | 297 ++++++++++++++++++++++++++++ 7 files changed, 796 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/msr_arm.h create mode 100644 arch/arm64/kernel/msr_arm.c create mode 100644 arch/arm64/kernel/msr_smp.c
Signature · 1 line
1.8.3.1
PATCH 1/3 arm64:insn: Export symbols for MSR ARM driver
In order to use the MSR-ARM driver in module and built-in ways, we need export following symbols.
The MSR-ARM driver depends on function aarch64_insn_patch_text to modify the text at runtime, and function aarch64_insn_read to read one instruction in the specified address.
In addition, we need register_undef_hook and unregister_undef_hook to handle the low probability undefined exception which triggered only by MSR-ARM driver.
--- arch/arm64/kernel/insn.c | 2 ++ arch/arm64/kernel/traps.c | 2 ++ 2 files changed, 4 insertions(+)
arch/arm64/kernel/insn.c +2 -0
@@ -135,6 +135,7 @@ int __kprobes aarch64_insn_read(void *addr, u32 *insnp)return ret; } +EXPORT_SYMBOL (aarch64_insn_read);static int __kprobes __aarch64_insn_write (void *addr,__le32 insn) {
@@ -247,6 +248,7 @@ int __kprobes aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt)return stop_machine_cpuslocked (aarch64_insn_patch_text_cb, &patch, cpu_online_mask); } +EXPORT_SYMBOL (aarch64_insn_patch_text);static int __kprobes aarch64_get_imm_shift_mask (enum aarch64_insn_imm_type type,u32 *maskp,int *shiftp)
arch/arm64/kernel/traps.c +2 -0
@@ -292,6 +292,7 @@ void register_undef_hook(struct undef_hook *hook)list_add (&hook->node, &undef_hook);raw_spin_unlock_irqrestore (&undef_lock, flags); } +EXPORT_SYMBOL (register_undef_hook);void unregister_undef_hook (struct undef_hook *hook) {
@@ -301,6 +302,7 @@ void unregister_undef_hook(struct undef_hook *hook)list_del (&hook->node);raw_spin_unlock_irqrestore (&undef_lock, flags); } +EXPORT_SYMBOL (unregister_undef_hook);static int call_undef_hook (struct pt_regs *regs) {
Signature · 1 line
1.8.3.1
PATCH 2/3 arm64:msr: Introduce MSR ARM driver
In reply to Rongwei WangThe function of MSR-ARM driver is similar to that of MSR module under x86. It is used to read and write system registers in user mode, which is easy to debug.
In the implementation of MSR-ARM module, because the current aarch64 architecture lacks the support of rdmsr and wrmsr instructions, we have to modify the code segment at runtime to realize the reading and writing of arbitrary registers.
In terms of security, because modifying the code segment may generate undefined instruction exceptions, we use the existing undefined instruction exception hook function registration interface of the kernel to shield the exceptions only generated by MSR-ARM.
Meanwhile, we designed a user space tool: system-register-tools, which function similar to msr-tools under x86. We have open sourced this tool in Github, link as follows: https://github.com/alibaba/system-register-tools.
--- arch/arm64/Kconfig | 9 + arch/arm64/include/asm/msr_arm.h | 75 ++++++++ arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/msr_arm.c | 399 +++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/msr_smp.c | 249 ++++++++++++++++++++++++ 5 files changed, 734 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/msr_arm.h create mode 100644 arch/arm64/kernel/msr_arm.c create mode 100644 arch/arm64/kernel/msr_smp.c
arch/arm64/Kconfig +9 -0
@@ -1688,6 +1688,15 @@ config ARM64_MTE endmenu +config ARM64_MSR + tristate "/dev/cpu/*/msr - AARCH64 Model-specific register support" + help + This device gives privileged processes access to the arm64 + Model-Specific Registers (MSRs). It is a character device with + major 202 and minors 0 to <NR_CPUS-1> for /dev/cpu/0/msr to + /dev/cpu/<NR_CPUS-1>/msr. MSR accesses are directed to a specific CPU on + multi-processor systems. + config ARM64_SVE bool "ARM Scalable Vector Extension support" default y
arch/arm64/include/asm/msr_arm.h new file +75 -0
75 lines not on this page · raw message
arch/arm64/kernel/Makefile +2 -1
@@ -17,7 +17,7 @@ obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ return_address.o cpuinfo.o cpu_errata.o \ cpufeature.o alternative.o cacheinfo.o \ smp.o smp_spin_table.o topology.o smccc-call.o \ - syscall.o proton-pack.o + syscall.o proton-pack.o msr_smp.o targets += efi-entry.o
@@ -60,6 +60,7 @@ obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o obj-$(CONFIG_ARM64_MTE) += mte.o +obj-$(CONFIG_ARM64_MSR) += msr_arm.o obj-y += vdso/ probes/ obj-$(CONFIG_COMPAT_VDSO) += vdso32/
arch/arm64/kernel/msr_arm.c new file +399 -0
399 lines not on this page · raw message
arch/arm64/kernel/msr_smp.c new file +249 -0
249 lines not on this page · raw message
Signature · 1 line
1.8.3.1
kernel test robot
build botRe: [PATCH 2/3] arm64:msr: Introduce MSR ARM driver
Thank you for the patch! Perhaps something to improve:
Hi Rongwei,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on v5.10-rc6 next-20201130]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Rongwei-Wang/arm64-msr-Add-MSR-driver/20201201-015322 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: arm64-allyesconfig (attached as .config) compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/00ac9cd26a786bf9c061bc7e524f31484408f8c1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Rongwei-Wang/arm64-msr-Add-MSR-driver/20201201-015322 git checkout 00ac9cd26a786bf9c061bc7e524f31484408f8c1
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
arch/arm64/kernel/msr_arm.c: In function 'msr_open':
>> arch/arm64/kernel/msr_arm.c:292:24: warning: variable 'c' set but not used [-Wunused-but-set-variable]
292 | struct cpuinfo_arm64 *c;
| ^vim +/c +292 arch/arm64/kernel/msr_arm.c
287
288 static int msr_open(struct inode *inode, struct file *file)
289 {
290 unsigned int cpu = iminor(file_inode(file));
291 /* TODO */
> 292 struct cpuinfo_arm64 *c;
293
294 if (!capable(CAP_SYS_RAWIO))
295 return -EPERM;
296
297 if (cpu >= nr_cpu_ids || !cpu_online(cpu))
298 return -ENXIO; /* No such CPU */
299
300 c = &per_cpu(cpu_data, cpu);
301 return 0;
302 }
303
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 3/3 arm64:msr: Enable MSR ARM driver
In reply to Rongwei WangBy default, MSR-ARM is compiled as a module.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -1092,3 +1092,4 @@ CONFIG_DEBUG_KERNEL=y # CONFIG_DEBUG_PREEMPT is not set # CONFIG_FTRACE is not set CONFIG_MEMTEST=y +CONFIG_ARM64_MSR=m
Signature · 1 line
1.8.3.1
Will Deacon
maintainerQuoted 4 lines · Rongwei Wang
MSR ARM driver aims to provide interfacs for user to read or write data to all system registers. Its functions is same as MSR driver (x86 platform). It mainly depends on kprobe and undef exception to read or write system registers dynamicly.
... but why? These are privileged registers for a reason, and giving userspace access to them is bound to cause serious problems. Why can't we do whatever it is that userspace is trying to do by poking these things in the kernel instead? This interface is a bit like using /dev/mem instead of writing a proper device driver.
Thanks,
Will
Hi, Will
Thanks for your reply!
There are absolutely privileged registers, and seriously expose the interface directly!
However, these interfaces (/dev/cpu/<N>/msr) need permissions to access, so there should be few security issues. In addition, it may be due to my unclear description above. This driver is mainly a debugging tool. It make developers can easily get the values of some system registers without modifying the kernel. In fact, we first considered the /dev/mem solution, but it seems that /dev/mem can map peripheral or IO registers, but not system registers.
Quoted 17 lines
2020年12月1日 上午1:57,Will Deacon <[email protected]> 写道:
Quoted 4 lines · Rongwei Wang
MSR ARM driver aims to provide interfacs for user to read or write data to all system registers. Its functions is same as MSR driver (x86 platform). It mainly depends on kprobe and undef exception to read or write system registers dynamicly.
... but why? These are privileged registers for a reason, and giving userspace access to them is bound to cause serious problems. Why can't we do whatever it is that userspace is trying to do by poking these things in the kernel instead? This interface is a bit like using
/dev/meminstead of writing a proper device driver.Thanks,
Will
Hi, Will
Thanks for your reply!
There are absolutely privileged registers, and seriously expose the interface directly!
However, these interfaces (/dev/cpu/<N>/msr) need permissions to access, so there should be few security issues. In addition, it may be due to my unclear description above. This driver is mainly a debugging tool. It make developers can easily get the values of some system registers without modifying the kernel. In fact, we first considered the /dev/mem solution, but it seems that /dev/mem can map peripheral or IO registers, but not system registers.
Quoted 17 lines
2020年12月1日 上午1:57,Will Deacon <[email protected]> 写道:
Quoted 4 lines · Rongwei Wang
MSR ARM driver aims to provide interfacs for user to read or write data to all system registers. Its functions is same as MSR driver (x86 platform). It mainly depends on kprobe and undef exception to read or write system registers dynamicly.
... but why? These are privileged registers for a reason, and giving userspace access to them is bound to cause serious problems. Why can't we do whatever it is that userspace is trying to do by poking these things in the kernel instead? This interface is a bit like using
/dev/meminstead of writing a proper device driver.Thanks,
Will
Quoted 6 lines · Rongwei Wang
The interfaces of this module is same as MSR module in user space, and to solve the problem that ARM platform has no similar MSR module. Using this interface, we did some pressure tests to test the stability and security of MSR driver. The test results show that the driver will not cause system panic if various illegal values and multithreading concurrent access are passed through the interface.
It would certainly help if you described what problem you are trying to solve here. In general, giving userspace access to random system registers is a pretty bad idea.
Are you trying to validate a CPU? a hypervisor? Or is it just a fun way to check how many things you can poke before something catches fire?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 9 lines · Marc Zyngier
Quoted 6 lines · Rongwei Wang
The interfaces of this module is same as MSR module in user space, and to solve the problem that ARM platform has no similar MSR module. Using this interface, we did some pressure tests to test the stability and security of MSR driver. The test results show that the driver will not cause system panic if various illegal values and multithreading concurrent access are passed through the interface.
Quoted 6 lines
It would certainly help if you described what problem you are trying to solve here. In general, giving userspace access to random system registers is a pretty bad idea.
Are you trying to validate a CPU? a hypervisor? Or is it just a fun way to check how many things you can poke before something catches fire?
I agree with the requests for justification.
Rongwei mentions that this driver functions the same as the x86 platform MSR driver. This one uses /dev.
I thought that the x86 driver used /sys, but I could be wrong.
Do we (or not) want cross-platform compatabilities?
Regarding permissions, /dev or /sys files have permission settings. They don't have to be world-readable.
Signature · 1 line
~Randy
Hi
We have validate this driver in vm and physical machine, and works fine.
Actually, we used existing interfaces to realize this driver, likes aarch64_insn_read and aarch64_insn_patch_text. These existing intefaces had validated a CPU.
Quoted 23 lines
2020年12月1日 上午2:05,Marc Zyngier <[email protected]> 写道:
Quoted 6 lines · Rongwei Wang
The interfaces of this module is same as MSR module in user space, and to solve the problem that ARM platform has no similar MSR module. Using this interface, we did some pressure tests to test the stability and security of MSR driver. The test results show that the driver will not cause system panic if various illegal values and multithreading concurrent access are passed through the interface.
It would certainly help if you described what problem you are trying to solve here. In general, giving userspace access to random system registers is a pretty bad idea.
Are you trying to validate a CPU? a hypervisor? Or is it just a fun way to check how many things you can poke before something catches fire?
Thanks,
M.Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 2 lines · wangrongwei
Hi
We have validate this driver in vm and physical machine, and works fine.
But what does "work fine" mean? None of these system registers are supposed to be accessible from userspace, so please explain *what* you are trying to do with this, other that introducing security holes and general system instability?
Quoted 2 lines
Actually, we used existing interfaces to realize this driver, likes
aarch64_insn_readandaarch64_insn_patch_text.
Sure. At that stage, you could also directly expose the linear mapping to userspace and start writing to it, it would probably be a fitting addition...
Quoted 1 line
These existing intefaces had validated a CPU.
If CPU validation is your goal, I suggest this is kept out of tree, as the kernel is hardly a validation tool for the arm64 architecture.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 4 lines
2020年12月1日 下午4:12,Marc Zyngier <[email protected]> 写道:
Quoted 8 lines
Quoted 2 lines · wangrongwei
Hi
We have validate this driver in vm and physical machine, and works fine.But what does "work fine" mean? None of these system registers are supposed to be accessible from userspace, so please explain *what* you are trying to do with this, other that introducing security holes and general system instability?
I think I know what you mean. Do you want me to describe how we achieved it?
In x86, the different registers can be accessed directly using the rdmsr and wrmsr instructions, but in ARM, since these two instructions are missing, so we modify the code segment during runtime, similar to the principle of static_key.
Quoted 6 lines
Quoted 3 lines
Actually, we used existing interfaces to realize this driver, likes
aarch64_insn_readandaarch64_insn_patch_text.Sure. At that stage, you could also directly expose the linear mapping to userspace and start writing to it, it would probably be a fitting addition...
Yes, but accessing those system registers doesn't seem to have an address, just have a register number (I'm not sure about that)?
Quoted 5 lines
Quoted 2 lines
These existing intefaces had validated a CPU.
If CPU validation is your goal, I suggest this is kept out of tree, as the kernel is hardly a validation tool for the arm64 architecture.
Not really sure what you mean by CPU validation as you describe above? However, the biggest challenge we encountered during implementation was an undefined instruction exception that could occur after modifying a code segment, but this problem was also solved using the kernel's existing interface.
Quoted 6 lines
Thanks,
M.Signature · 1 line
Jazz is not dead. It just smells funny…
Regard,
Rongwei.
Quoted 10 lines · wangrongwei
Quoted 10 lines
2020年12月1日 下午4:12,Marc Zyngier <[email protected]> 写道:
Quoted 2 lines · wangrongwei
Hi
We have validate this driver in vm and physical machine, and works fine.But what does "work fine" mean? None of these system registers are supposed to be accessible from userspace, so please explain *what* you are trying to do with this, other that introducing security holes and general system instability?
Quoted 5 lines
I think I know what you mean. Do you want me to describe how we achieved it? In x86, the different registers can be accessed directly using the rdmsr and wrmsr instructions, but in ARM, since these two instructions are missing, so we modify the code segment during runtime, similar to the principle of
static_key.
[...]
These are implementation details, none of which answer my question:
What makes you think this is a good idea? I cannot see any legitimate reason for userspace to ever access privileged system registers, and the fact that x86 has such feature isn't a good justification.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 19 lines
2020年12月1日 下午11:37,Marc Zyngier <[email protected]> 写道:
Quoted 8 lines · wangrongwei
Quoted 8 lines
2020年12月1日 下午4:12,Marc Zyngier <[email protected]> 写道:
Quoted 2 lines · wangrongwei
Hi
We have validate this driver in vm and physical machine, and works fine.But what does "work fine" mean? None of these system registers are supposed to be accessible from userspace, so please explain *what* you are trying to do with this, other that introducing security holes and general system instability?
Quoted 5 lines
I think I know what you mean. Do you want me to describe how we achieved it? In x86, the different registers can be accessed directly using the rdmsr and wrmsr instructions, but in ARM, since these two instructions are missing, so we modify the code segment during runtime, similar to the principle of
static_key.
Quoted 5 lines
[...]
These are implementation details, none of which answer my question:
What makes you think this is a good idea? I cannot see any legitimate
In fact, I think this tool useful mainly in the following scenarios:
1. performance debug
2. Arm-core features test
3. Debug-tool for kernel developer
Also, for example, MSR-ARM is needed for chip verification and system-level functional verification.
A simple example, perf stat can test pmu, but the overflow interrupt function and forced overflow function of pmu is not covered.
In both cases, we need a special interface to configure it, which can be considered as testing requirements, so it can only be tested by configuring (access) registers, e.g., devmem command for memmap registers, MSR-ARM driver for system registers.
Quoted 6 lines
reason for userspace to ever access privileged system registers, and the fact that x86 has such feature isn't a good justification.
M.Signature · 1 line
Jazz is not dead. It just smells funny…
Sorry for the delayed response.
Regards,
Rongwei Wang.
Quoted 22 lines · Rongwei Wang
Quoted 17 lines
2020年12月1日 下午11:37,Marc Zyngier <[email protected]> 写道:
Quoted 8 lines · wangrongwei
Quoted 8 lines
2020年12月1日 下午4:12,Marc Zyngier <[email protected]> 写道:
Quoted 2 lines · wangrongwei
Hi
We have validate this driver in vm and physical machine, and works fine.But what does "work fine" mean? None of these system registers are supposed to be accessible from userspace, so please explain *what* you are trying to do with this, other that introducing security holes and general system instability?
Quoted 5 lines
I think I know what you mean. Do you want me to describe how we achieved it? In x86, the different registers can be accessed directly using the rdmsr and wrmsr instructions, but in ARM, since these two instructions are missing, so we modify the code segment during runtime, similar to the principle of
static_key.Quoted 5 lines
[...]
These are implementation details, none of which answer my question:
What makes you think this is a good idea? I cannot see any legitimate
Quoted 8 lines
In fact, I think this tool useful mainly in the following scenarios:
1. performance debug
2. Arm-core features test
3. Debug-tool for kernel developer
Also, for example, MSR-ARM is needed for chip verification and system-level functional verification.
A simple example, perf stat can test pmu, but the overflow interrupt function and forced overflow function of pmu is not covered.
But what does it mean to change random system registers while the kernel itself is using them in parallel? All you are introducing is a bunch of uncontrolled, unexpected, and possibly fatal side effects.
Introducing such an interface makes the kernel unsafe, insecure, and and violates all the possible guarantees that we are trying hard to provide. After all, why would we even try to mitigate side channel vulnerabilities if we were to introduce such a thing?
Quoted 4 lines
In both cases, we need a special interface to configure it, which can be considered as testing requirements, so it can only be tested by configuring (access) registers, e.g., devmem command for memmap registers, MSR-ARM driver for system registers.
devmem was a terrible mistake. Unprivileged sysreg access is another instance of the same mistake.
The kernel is not a validation tool. It is designed to operate safely, securely, and reliably. What you propose is the negation of these goals for dubious purposes, and I think I represent a large number of kernel developers when I say that we really do not want it.
This will (hopefully) be my last message on this subject.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 32 lines
2020年12月3日 下午4:35,Marc Zyngier <[email protected]> 写道:
Quoted 18 lines · Rongwei Wang
Quoted 10 lines
2020年12月1日 下午11:37,Marc Zyngier <[email protected]> 写道:
Quoted 8 lines · wangrongwei
Quoted 8 lines
2020年12月1日 下午4:12,Marc Zyngier <[email protected]> 写道:
Quoted 2 lines · wangrongwei
Hi
We have validate this driver in vm and physical machine, and works fine.But what does "work fine" mean? None of these system registers are supposed to be accessible from userspace, so please explain *what* you are trying to do with this, other that introducing security holes and general system instability?
Quoted 8 lines
Quoted 5 lines
I think I know what you mean. Do you want me to describe how we achieved it? In x86, the different registers can be accessed directly using the rdmsr and wrmsr instructions, but in ARM, since these two instructions are missing, so we modify the code segment during runtime, similar to the principle of
static_key.[...]
These are implementation details, none of which answer my question:
What makes you think this is a good idea? I cannot see any legitimateQuoted 8 lines
In fact, I think this tool useful mainly in the following scenarios:
1. performance debug
2. Arm-core features test
3. Debug-tool for kernel developer
Also, for example, MSR-ARM is needed for chip verification and system-level functional verification.
A simple example, perf stat can test pmu, but the overflow interrupt function and forced overflow function of pmu is not covered.
Quoted 3 lines
But what does it mean to change random system registers while the kernel itself is using them in parallel? All you are introducing is a bunch of uncontrolled, unexpected, and possibly fatal side effects.
This problem exists when writing to a register, but it does not exist when reading a register.
Quoted 19 lines
Introducing such an interface makes the kernel unsafe, insecure, and and violates all the possible guarantees that we are trying hard to provide. After all, why would we even try to mitigate side channel vulnerabilities if we were to introduce such a thing?
Quoted 4 lines
In both cases, we need a special interface to configure it, which can be considered as testing requirements, so it can only be tested by configuring (access) registers, e.g., devmem command for memmap registers, MSR-ARM driver for system registers.
devmem was a terrible mistake. Unprivileged sysreg access is another instance of the same mistake.
The kernel is not a validation tool. It is designed to operate safely, securely, and reliably. What you propose is the negation of these goals for dubious purposes, and I think I represent a large number of kernel developers when I say that we really do not want it.
Quoted 7 lines
This will (hopefully) be my last message on this subject.
Thanks,
M.Signature · 1 line
Jazz is not dead. It just smells funny…
Thanks,
Rongwei Wang.
Quoted 1 line · Rongwei Wang
Quoted 1 line
2020年12月3日 下午4:35,Marc Zyngier <[email protected]> 写道:
[...]
Quoted 5 lines
Quoted 3 lines
But what does it mean to change random system registers while the kernel itself is using them in parallel? All you are introducing is a bunch of uncontrolled, unexpected, and possibly fatal side effects.
This problem exists when writing to a register, but it does not exist when reading a register.
If you're not aware that the ARM architecture does have system registers with read side-effects, you really shouldn't be writing this code.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 9 lines · Marc Zyngier
Quoted 1 line · Rongwei Wang
Quoted 1 line
2020年12月3日 下午4:35,Marc Zyngier <[email protected]> 写道:
[...]
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
But what does it mean to change random system registers while the kernel itself is using them in parallel? All you are introducing is a bunch of uncontrolled, unexpected, and possibly fatal side effects.
This problem exists when writing to a register, but it does not exist when reading a register.
If you're not aware that the ARM architecture does have system registers with read side-effects, you really shouldn't be writing this code.
Thanks, Does it make sense to put this feature in the drivers/ directory, likes misc drivers? Whether it can exist as a debugging tool in kernel or not? When debugging, then enables CONFIG_ARM64_MSR or CONFIG_ARM64_MSR_DEBUG.
Quoted 4 lines
M.Signature · 1 line
Jazz is not dead. It just smells funny…
Thanks,
Rongwei Wang.
Mark Rutland
reviewerQuoted 32 lines · Rongwei Wang
Quoted 32 lines
2020年12月3日 下午4:35,Marc Zyngier <[email protected]> 写道:
Quoted 26 lines · Rongwei Wang
Quoted 10 lines
2020年12月1日 下午11:37,Marc Zyngier <[email protected]> 写道:
Quoted 8 lines · wangrongwei
Quoted 8 lines
2020年12月1日 下午4:12,Marc Zyngier <[email protected]> 写道:
Quoted 2 lines · wangrongwei
Hi
We have validate this driver in vm and physical machine, and works fine.But what does "work fine" mean? None of these system registers are supposed to be accessible from userspace, so please explain *what* you are trying to do with this, other that introducing security holes and general system instability?
Quoted 8 lines
Quoted 5 lines
I think I know what you mean. Do you want me to describe how we achieved it? In x86, the different registers can be accessed directly using the rdmsr and wrmsr instructions, but in ARM, since these two instructions are missing, so we modify the code segment during runtime, similar to the principle of
static_key.[...]
These are implementation details, none of which answer my question:
What makes you think this is a good idea? I cannot see any legitimateIn fact, I think this tool useful mainly in the following scenarios:
1. performance debug
2. Arm-core features test
3. Debug-tool for kernel developer
Also, for example, MSR-ARM is needed for chip verification and system-level functional verification.
A simple example, perf stat can test pmu, but the overflow interrupt function and forced overflow function of pmu is not covered.
Quoted 4 lines
Quoted 3 lines
But what does it mean to change random system registers while the kernel itself is using them in parallel? All you are introducing is a bunch of uncontrolled, unexpected, and possibly fatal side effects.
This problem exists when writing to a register, but it does not exist when reading a register.
Reading registers can also have side-effects. For example the ICC_IAR_* registers are read-sensitive, and reading those could cause the kernel to stop receiving timer interrupts or similar. The problem /does/ exist when reading registers.
I concur with Marc and others that this simply isn't safe, regardless of read or write, and not something we want upstream in Linux.
For debug and testing, I suggest looking at kvm-unit-tests. That has some PMU tests already, and is gaining the ability to run bare-metal around now (and so might be helpful for testing HW). Having improved tests there would benefit everyone.
Thanks,
Mark.
Quoted 2 lines · Rongwei Wang
MSR ARM driver aims to provide interfacs for user to read or write data to all system registers.
Just a warranty from x86 land: if I were an ARM arch maintainer, I would never never *ever* take such driver exposing naked hw registers to userspace.
We have been fighting with this on x86 for years:
a7e1f67ed29f ("x86/msr: Filter MSR writes")
with userspace tools poking at random MSRs. Read the commit message for what can happen. And taking that thing is like opening a huge can'o'worms that can't be closed anymore.
Currently, we're trying to move userspace tools to proper sysfs interfaces but it is a huuuge pain. It is a lot easier to have people define proper interfaces from the get-go where the kernel can control and synchronize access.
HTH.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteHi, Boris, Thank your advice very much!
Indeed, I have read the commit message, and it seems that writes data to a system register may cause many problems. Actually, we have taken this into account. In the current version, we have separated the read and write functions to the system registers into two commands, they (rdasr and wrasr) can be found in system-register-tools (https://github.com/alibaba/system-register-tools).
In providing the WRASR function, we consider that users should bear the consequences of rewriting registers during the debugging phase. In fact, most of the time we rarely use WRASR, and only use it when we are very confident.
Quoted 30 lines
2020年12月1日 上午3:03,Borislav Petkov <[email protected]> 写道:
Quoted 2 lines · Rongwei Wang
MSR ARM driver aims to provide interfacs for user to read or write data to all system registers.
Just a warranty from x86 land: if I were an ARM arch maintainer, I would never never *ever* take such driver exposing naked hw registers to userspace.
We have been fighting with this on x86 for years:
a7e1f67ed29f("x86/msr: Filter MSR writes")with userspace tools poking at random MSRs. Read the commit message for what can happen. And taking that thing is like opening a huge can'o'worms that can't be closed anymore.
Currently, we're trying to move userspace tools to proper sysfs interfaces but it is a huuuge pain. It is a lot easier to have people define proper interfaces from the get-go where the kernel can control and synchronize access.
HTH.
Signature · 4 lines
Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Quoted 4 lines · wangrongwei
Indeed, I have read the commit message, and it seems that writes data to a system register may cause many problems. Actually, we have taken this into account. In the current version, we have separated the read and write functions to the system registers into two commands,
There's rdmsr and wrmsr in msr-tools on x86 too.
Quoted 4 lines
In providing the WRASR function, we consider that users should bear the consequences of rewriting registers during the debugging phase. In fact, most of the time we rarely use WRASR, and only use it when we are very confident.
As I said, there should never never ever be a tool which allows writing of registers from userspace. If I could go back in time, I'd stop this on x86 but it is too late now. Not for ARM though.
Also, do you see how all the people who replied to your mail, put the text under the quoted text. Do that too, pls, from now on, and refrain from top-posting.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 11 lines
2020年12月1日 下午7:26,Borislav Petkov <[email protected]> 写道:
Quoted 4 lines · wangrongwei
Indeed, I have read the commit message, and it seems that writes data to a system register may cause many problems. Actually, we have taken this into account. In the current version, we have separated the read and write functions to the system registers into two commands,
There's rdmsr and wrmsr in msr-tools on x86 too.
Yes, and x86 also provides two instructions with the same name in the instruction set, but not in ARM.
Quoted 6 lines
Quoted 5 lines
In providing the WRASR function, we consider that users should bear the consequences of rewriting registers during the debugging phase. In fact, most of the time we rarely use WRASR, and only use it when we are very confident.
Quoted 7 lines
As I said, there should never never ever be a tool which allows writing of registers from userspace. If I could go back in time, I'd stop this on x86 but it is too late now. Not for ARM though.
Also, do you see how all the people who replied to your mail, put the text under the quoted text. Do that too, pls, from now on, and refrain from top-posting.
Thank you for the reminder, it has been corrected!
Quoted 8 lines
Thx.
Signature · 4 lines
Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Thanks,
Rongwei Wang.
Quoted 2 lines · wangrongwei
Yes, and x86 also provides two instructions with the same name in the instruction set, but not in ARM.
Sorry, I can't parse what you're trying to say here.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 9 lines
2020年12月1日 下午10:54,Borislav Petkov <[email protected]> 写道:
Quoted 2 lines · wangrongwei
Yes, and x86 also provides two instructions with the same name in the instruction set, but not in ARM.
Sorry, I can't parse what you're trying to say here.
In the ARM architecture, there are no rdmsr and wrmsr instructions.
In ARM, the system registers can only be accessed through msr and mrs, so the problem created by MSR driver (depend on rdmsr and wrmsr) in x86 is not necessarily present in ARM, which is very different from x86. In addition, we want cross-platform compatabilities, and fill these gaps in the ARM.
Quoted 6 lines
Signature · 5 lines
-- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Regards,
Rongwei Wang.
Quoted 4 lines · Rongwei Wang
In ARM, the system registers can only be accessed through msr and mrs, so the problem created by MSR driver (depend on rdmsr and wrmsr) in x86 is not necessarily present in ARM, which is very different from x86.
No, the point I'm making is that it doesn't matter what the architecture does or does not, register *writes* from userspace are a bad bad idea for the reasons I described.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 5 lines
2020年12月1日 下午11:25,Borislav Petkov <[email protected]> 写道:
On Tue, Dec 01, 2020 at 11:17:39PM +0800, Rongwei Wang wrote:
Quoted 8 lines
Quoted 4 lines
In ARM, the system registers can only be accessed through msr and mrs, so the problem created by MSR driver (depend on rdmsr and wrmsr) in x86 is not necessarily present in ARM, which is very different from x86.
No, the point I'm making is that it doesn't matter what the architecture does or does not, register *writes* from userspace are a bad bad idea for the reasons I described.
Sorry, I was away for two days and didn't reply in time.
In fact, we find MSR in the x86 architecture to be a particularly useful interface. It helped us a lot when we were doing some kernel debugging. So we consider implementing a similar feature in ARM. So as a debugging tool, could it exist, e.g. if I change CONFIG_ARM64_MSR to CONFIG_ARM64_MSR_DEBUG or others. Do you think this adjustment is possible?
Quoted 6 lines
Signature · 5 lines
-- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Regards,
Rongwei Wang.
Quoted 5 lines · Rongwei Wang
Quoted 5 lines
2020年12月1日 下午10:54,Borislav Petkov <[email protected]> 写道:
Quoted 8 lines
Quoted 5 lines · wangrongwei
Quoted 2 lines
Yes, and x86 also provides two instructions with the same name in the instruction set, but not in ARM.
Sorry, I can't parse what you're trying to say here.
In the ARM architecture, there are no rdmsr and wrmsr instructions.
In ARM, the system registers can only be accessed through msr and mrs, so the problem created by MSR driver (depend on rdmsr and wrmsr) in x86 is not necessarily present in ARM, which is very different from x86. In addition, we want cross-platform compatabilities, and fill these gaps in the ARM.
Apologies for being blunt, but this looks like another occurrence of the 'compatibility' disease, where everything has to work in the exact same way as it does on x86, even if it was a terrible idea to begin with.
One of the nice things of having a [relatively] new architecture is that we are not being held back by backward compatibility requirements, given that we cannot break existing use cases that predate the existence of the architecture.
In other words, there are things that the x86 maintainers would gladly remove (such as MSR access from userland, and I'm sure there are many examples), but they simply cannot because it is already being relied upon in the field. But that does not mean other architectures are required to provide a similar interface, and especially not ones that allow you to poke at undocumented, non-architected CPU registers.