[PATCH] KVM: arm64: Support PREL/PLT relocs in EL2 code

2021-03-31 Thread David Brazdil
arm64: Generate hyp relocation data") Cc: Reported-by: Will Deacon Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/gen-hyprel.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/gen-hyprel.c b/arch/arm64/kvm/hyp/nvhe/gen-hyprel.c index ea

[PATCH pre-5.10] selinux: vsock: Set SID for socket returned by accept()

2021-03-29 Thread David Brazdil
344051a ("VSOCK: Introduce VM Sockets") Signed-off-by: David Brazdil Signed-off-by: David S. Miller --- net/vmw_vsock/af_vsock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 5d323574d04f..c82e7b52ab1f 100644 --- a/net/vmw_v

Re: [PATCH v2] selinux: vsock: Set SID for socket returned by accept()

2021-03-19 Thread David Brazdil
On Fri, Mar 19, 2021 at 01:05:41PM +, David Brazdil wrote: > For AF_VSOCK, accept() currently returns sockets that are unlabelled. > Other socket families derive the child's SID from the SID of the parent > and the SID of the incoming packet. This is typically done as the > co

[PATCH v2] selinux: vsock: Set SID for socket returned by accept()

2021-03-19 Thread David Brazdil
sting 'security_sk_clone' hook to copy the SID from the parent (server) socket to the child. There is no packet SID in this case. Fixes: d021c344051a ("VSOCK: Introduce VM Sockets") Signed-off-by: David Brazdil --- Tested on Android AOSP and Fedora 33 with v5.12-rc3. Unit test i

Re: [PATCH] selinux: vsock: Set SID for socket returned by accept()

2021-03-19 Thread David Brazdil
Hi Paul, I'll post a v2 shortly but will address your comments here. > > include/linux/lsm_hooks.h | 7 +++ > > include/linux/security.h | 5 + > > net/vmw_vsock/af_vsock.c | 1 + > > security/security.c | 5 + > > security/selinux/hooks.c | 10 ++

[PATCH] selinux: vsock: Set SID for socket returned by accept()

2021-03-17 Thread David Brazdil
hook 'vsock_sk_clone' that takes the parent (server) and child (connection) struct socks, and assigns the parent SID to the child. There is no packet SID in this case. Signed-off-by: David Brazdil --- This is my first patch in this part of the kernel so please comment if I

Re: [PATCH v2 4/8] KVM: arm64: Generate hyp relocation data

2021-02-01 Thread David Brazdil
Thanks for writing the fix, Marc! There are no corner cases in this code so if it boots, that should be a good indicator that all BE inputs were converted. Just one little thing I noticed below, otherwise: Acked-by: David Brazdil > arch/arm64/kvm/hyp/nvhe/Makefile | 1 + > arch/arm

Re: [PATCH v3 2/9] KVM: arm64: Add a buffer that can pass UBSan data from hyp/nVHE to kernel

2021-01-18 Thread David Brazdil
On Fri, Jan 15, 2021 at 05:18:23PM +, Elena Petrova wrote: > From: George Popescu > > Share a buffer between the kernel and the hyp/nVHE code by using the > macros from kvm_debug_buffer.h. > The hyp/nVHE code requires a write index which counts how many elements > have been writtens inside th

Re: [PATCH v3 9/9] KVM: arm64: Add UBSan tests for PKVM.

2021-01-18 Thread David Brazdil
On Fri, Jan 15, 2021 at 05:18:30PM +, Elena Petrova wrote: > From: George-Aurelian Popescu > > Test the UBsan functionality inside hyp/nVHE. > Because modules are not supported inside of hyp/nVHE code, the default > testing module for UBSan can not be used. > New functions have to be defined

Re: [PATCH v4 00/21] arm64: Early CPU feature override, and applications to VHE, BTI and PAuth

2021-01-18 Thread David Brazdil
rg/r/20210104135011.2063104-1-...@kernel.org > [3] https://lore.kernel.org/r/2021032811.2455113-1-...@kernel.org Pretty cool! Left a few minor comments here and there, other than that: Acked-by: David Brazdil

Re: [PATCH v4 18/21] arm64: Move "nokaslr" over to the early cpufeature infrastructure

2021-01-18 Thread David Brazdil
On Mon, Jan 18, 2021 at 09:45:30AM +, Marc Zyngier wrote: > Given that the early cpufeature infrastructure has borrowed quite > a lot of code from the kaslr implementation, let's reimplement > the matching of the "nokaslr" option with it. > > Signed-off-by:

Re: [PATCH v4 17/21] KVM: arm64: Document HVC_VHE_RESTART stub hypercall

2021-01-18 Thread David Brazdil
On Mon, Jan 18, 2021 at 09:45:29AM +, Marc Zyngier wrote: > For completeness, let's document the HVC_VHE_RESTART stub. > > Signed-off-by: Marc Zyngier Acked-by: David Brazdil > --- > Documentation/virt/kvm/arm/hyp-abi.rst | 9 + > 1 file changed, 9 insertio

Re: [PATCH v4 15/21] arm64: Add an aliasing facility for the idreg override

2021-01-18 Thread David Brazdil
rc Zyngier Acked-by: David Brazdil > --- > arch/arm64/kernel/idreg-override.c | 20 > 1 file changed, 20 insertions(+) > > diff --git a/arch/arm64/kernel/idreg-override.c > b/arch/arm64/kernel/idreg-override.c > index 75d9845f489b..16bc8b3b93ae 100644 &

Re: [PATCH v4 14/21] arm64: Honor VHE being disabled from the command-line

2021-01-18 Thread David Brazdil
On Mon, Jan 18, 2021 at 09:45:26AM +, Marc Zyngier wrote: > Finally we can check whether VHE is disabled on the command line, > and not enable it if that's the user's wish. > > Signed-off-by: Marc Zyngier Acked-by: David Brazdil > --- > arch/

Re: [PATCH v4 12/21] arm64: cpufeature: Add an early command-line cpufeature override facility

2021-01-18 Thread David Brazdil
ride val/mask pair. > > No features are currently defined, so no expected change in > functionality. > > Signed-off-by: Marc Zyngier Acked-by: David Brazdil > --- > arch/arm64/kernel/Makefile | 2 +- > arch/arm64/kernel/head.S

Re: [PATCH v4 04/21] arm64: Provide an 'upgrade to VHE' stub hypercall

2021-01-18 Thread David Brazdil
On Mon, Jan 18, 2021 at 09:45:16AM +, Marc Zyngier wrote: > As we are about to change the way a VHE system boots, let's > provide the core helper, in the form of a stub hypercall that > enables VHE and replicates the full EL1 context at EL2, thanks > to EL1 and VHE-EL2 being extremely similar.

Re: [PATCH v4 01/21] arm64: Fix labels in el2_setup macros

2021-01-18 Thread David Brazdil
Zyngier > --- > arch/arm64/include/asm/el2_setup.h | 24 > 1 file changed, 12 insertions(+), 12 deletions(-) Acked-by: David Brazdil

Re: [PATCH v3 3/9] KVM: arm64: Enable UBSAN_BOUNDS for the both the kernel and hyp/nVHE

2021-01-18 Thread David Brazdil
On Fri, Jan 15, 2021 at 05:18:24PM +, Elena Petrova wrote: > From: George Popescu > > If an out of bounds happens inside the hyp/nVHE code, the ubsan_out_of_bounds > handler stores the logging data inside the kvm_ubsan_buffer. The one > responsible > for printing is the kernel ubsan_out_of_b

Re: [PATCH v3 1/9] KVM: arm64: Enable UBSan instrumentation in nVHE hyp code

2021-01-18 Thread David Brazdil
ones defined in kernel-proper lib/ubsan.c. > > In this way, enabling UBSAN_MISC won't cause a link error. The commit message needs to be updated - UBSAN_MISC does not exist any longer. Also "nVHe" is a typo. Other than that: Acked-by: David Brazdil > > Signed-off-by: Elena

Re: [PATCH] arm64: Remove unused variable in arch_show_interrupts

2021-01-05 Thread David Brazdil
On Tue, Jan 05, 2021 at 06:08:35PM +, Catalin Marinas wrote: > On Tue, Jan 05, 2021 at 06:03:14PM +0000, David Brazdil wrote: > > Commit 5089bc51f81f ("arm64/smp: Use irq_desc_kstat_cpu() in > > arch_show_interrupts()") removed the only user of variable `irq`. >

[PATCH v2 6/8] KVM: arm64: Fix constant-pool users in hyp

2021-01-05 Thread David Brazdil
accordingly. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_mmu.h | 42 -- arch/arm64/kvm/hyp/nvhe/host.S | 29 +++-- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 2 -- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/arch/arm64

[PATCH v2 8/8] KVM: arm64: Remove hyp_symbol_addr

2021-01-05 Thread David Brazdil
Hyp code used the hyp_symbol_addr helper to force PC-relative addressing because absolute addressing results in kernel VAs due to the way hyp code is linked. This is not true anymore, so remove the helper and update all of its users. Acked-by: Ard Biesheuvel Signed-off-by: David Brazdil

[PATCH v2 5/8] KVM: arm64: Apply hyp relocations at runtime

2021-01-05 Thread David Brazdil
: David Brazdil --- arch/arm64/include/asm/kvm_mmu.h | 1 + arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/smp.c | 4 +++- arch/arm64/kvm/va_layout.c| 28 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include

[PATCH v2 7/8] KVM: arm64: Remove patching of fn pointers in hyp

2021-01-05 Thread David Brazdil
Storing a function pointer in hyp now generates relocation information used at early boot to convert the address to hyp VA. The existing alternative-based conversion mechanism is therefore obsolete. Remove it and simplify its users. Acked-by: Ard Biesheuvel Signed-off-by: David Brazdil

[PATCH v2 3/8] KVM: arm64: Add symbol at the beginning of each hyp section

2021-01-05 Thread David Brazdil
anchor. The linker of `vmlinux` will place the symbols together with the sections. Signed-off-by: David Brazdil --- arch/arm64/include/asm/hyp_image.h | 29 +++-- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 4 ++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/arch

[PATCH v2 2/8] KVM: arm64: Set up .hyp.rodata ELF section

2021-01-05 Thread David Brazdil
We will need to recognize pointers in .rodata specific to hyp, so establish a .hyp.rodata ELF section. Merge it with the existing .hyp.data..ro_after_init as they are treated the same at runtime. Signed-off-by: David Brazdil --- arch/arm64/include/asm/sections.h | 2 +- arch/arm64/kernel

[PATCH v2 0/8] arm64: Relocate absolute hyp VAs

2021-01-05 Thread David Brazdil
if missing * add generated files to .gitignore -David David Brazdil (8): KVM: arm64: Rename .idmap.text in hyp linker script KVM: arm64: Set up .hyp.rodata ELF section KVM: arm64: Add symbol at the beginning of each hyp section KVM: arm64: Generate hyp relocation data KVM: arm64: Apply

[PATCH v2 1/8] KVM: arm64: Rename .idmap.text in hyp linker script

2021-01-05 Thread David Brazdil
-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 2 +- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 31b060a44045..68fd64f2313e 100644 --- a/arch/arm64

[PATCH v2 4/8] KVM: arm64: Generate hyp relocation data

2021-01-05 Thread David Brazdil
with addend + . The linker of `vmlinux` will therefore fill the slot accordingly. This relocation data will be used at runtime to convert the kernel VAs at those positions to hyp VAs. Signed-off-by: David Brazdil --- arch/arm64/kernel/vmlinux.lds.S | 11 + arch/arm64/kvm/hyp/nvhe/.giti

[PATCH] arm64: Remove unused variable in arch_show_interrupts

2021-01-05 Thread David Brazdil
Commit 5089bc51f81f ("arm64/smp: Use irq_desc_kstat_cpu() in arch_show_interrupts()") removed the only user of variable `irq`. Remove the unused variable. Signed-off-by: David Brazdil --- arch/arm64/kernel/smp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm64/kernel/sm

Re: [PATCH] KVM: arm64: Allow PSCI SYSTEM_OFF/RESET to return

2020-12-30 Thread David Brazdil
On Tue, Dec 29, 2020 at 05:16:41PM +, Marc Zyngier wrote: > Hi David, > > On 2020-12-29 16:00, David Brazdil wrote: > > The KVM/arm64 PSCI relay assumes that SYSTEM_OFF and SYSTEM_RESET should > > not return, as dictated by the PSCI spec. However, there is firmware out &

[PATCH] KVM: arm64: Allow PSCI SYSTEM_OFF/RESET to return

2020-12-29 Thread David Brazdil
The KVM/arm64 PSCI relay assumes that SYSTEM_OFF and SYSTEM_RESET should not return, as dictated by the PSCI spec. However, there is firmware out there which breaks this assumption, leading to a hyp panic. Make KVM more robust to broken firmware by allowing these to return. Signed-off-by: David

[PATCH 6/9] KVM: arm64: Apply hyp relocations at runtime

2020-12-09 Thread David Brazdil
: David Brazdil --- arch/arm64/configs/defconfig | 1 + arch/arm64/include/asm/kvm_mmu.h | 1 + arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/smp.c | 4 +++- arch/arm64/kvm/va_layout.c| 28 5 files changed, 34 insertions(+), 1

[PATCH 9/9] KVM: arm64: Remove hyp_symbol_addr

2020-12-09 Thread David Brazdil
Hyp code used the hyp_symbol_addr helper to force PC-relative addressing because absolute addressing results in kernel VAs due to the way hyp code is linked. This is not true anymore, so remove the helper and update all of its users. Acked-by: Ard Biesheuvel Signed-off-by: David Brazdil

[PATCH 7/9] KVM: arm64: Fix constant-pool users in hyp

2020-12-09 Thread David Brazdil
accordingly. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_mmu.h | 42 -- arch/arm64/kvm/hyp/nvhe/host.S | 29 +++-- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 2 -- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/arch/arm64

[PATCH 8/9] KVM: arm64: Remove patching of fn pointers in hyp

2020-12-09 Thread David Brazdil
Storing a function pointer in hyp now generates relocation information used at early boot to convert the address to hyp VA. The existing alternative-based conversion mechanism is therefore obsolete. Remove it and simplify its users. Acked-by: Ard Biesheuvel Signed-off-by: David Brazdil

[PATCH 2/9] KVM: arm64: Rename .idmap.text in hyp linker script

2020-12-09 Thread David Brazdil
-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 2 +- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 31b060a44045..68fd64f2313e 100644 --- a/arch/arm64

[PATCH 1/9] KVM: arm64: Correctly align nVHE percpu data

2020-12-09 Thread David Brazdil
g kvm-unit-tests or starting any VM and subsequent soft lockup on a Cortex A72 device. Fixes: 30c953911c43 ("kvm: arm64: Set up hyp percpu data for nVHE") Signed-off-by: Jamie Iles Signed-off-by: Marc Zyngier Acked-by: David Brazdil Cc: David Brazdil Cc: Marc Zyngier Cc: Will Deac

[PATCH 5/9] KVM: arm64: Generate hyp relocation data

2020-12-09 Thread David Brazdil
with addend + . The linker of `vmlinux` will therefore fill the slot accordingly. This relocation data will be used at runtime to convert the kernel VAs at those positions to hyp VAs. Signed-off-by: David Brazdil --- arch/arm64/kernel/vmlinux.lds.S | 11 + arch/arm64/kvm/hyp/nvhe/Mak

[PATCH 0/9] KVM: arm64: Relocate absolute hyp VAs

2020-12-09 Thread David Brazdil
topic/hyp-reloc_v1 -David David Brazdil (8): KVM: arm64: Rename .idmap.text in hyp linker script KVM: arm64: Set up .hyp.rodata ELF section KVM: arm64: Add symbol at the beginning of each hyp section KVM: arm64: Generate hyp relocation data KVM: arm64: Apply hyp relocations at runtime

[PATCH 3/9] KVM: arm64: Set up .hyp.rodata ELF section

2020-12-09 Thread David Brazdil
We will need to recognize pointers in .rodata specific to hyp, so establish a .hyp.rodata ELF section. Merge it with the existing .hyp.data..ro_after_init as they are treated the same at runtime. Signed-off-by: David Brazdil --- arch/arm64/include/asm/sections.h | 2 +- arch/arm64/kernel

[PATCH 4/9] KVM: arm64: Add symbol at the beginning of each hyp section

2020-12-09 Thread David Brazdil
anchor. The linker of `vmlinux` will place the symbols together with the sections. Signed-off-by: David Brazdil --- arch/arm64/include/asm/hyp_image.h | 29 +++-- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 4 ++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/arch

Re: [RFC PATCH 5/6] kvm: arm64: Fix constant-pool users in hyp

2020-12-09 Thread David Brazdil
Hey, relized I never replied to this... On Tue, Nov 24, 2020 at 03:08:20PM +0100, Ard Biesheuvel wrote: > On Thu, 19 Nov 2020 at 17:26, David Brazdil wrote: > > > > Hyp code used to use absolute addressing via a constant pool to obtain > > the kernel VA of 3 symbols - pani

Re: [PATCH v4 00/26] Opt-in always-on nVHE hypervisor

2020-12-08 Thread David Brazdil
Hey Marc, On Thu, Dec 03, 2020 at 07:23:19PM +, Marc Zyngier wrote: > On Wed, 2 Dec 2020 18:40:56 +0000, David Brazdil wrote: > > As we progress towards being able to keep guest state private to the > > host running nVHE hypervisor, this series allows the hypervisor to > &

[PATCH 6/6] kvm: arm64: Move skip_host_instruction to adjust_pc.h

2020-12-08 Thread David Brazdil
Move function for skipping host instruction in the host trap handler to a header file containing analogical helpers for guests. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 9 + arch/arm64/kvm/hyp/nvhe/hyp-main.c | 12 ++-- 2 files

[PATCH 5/6] kvm: arm64: Remove unused includes in psci-relay.c

2020-12-08 Thread David Brazdil
Minor cleanup removing unused includes. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index 0d6f4aa39621..1f7237e45148 100644 --- a/arch

[PATCH 3/6] kvm: arm64: Skip computing hyp VA layout for VHE

2020-12-08 Thread David Brazdil
Computing the hyp VA layout is redundant when the kernel runs in EL2 and hyp shares its VA mappings. Make calling kvm_compute_layout() conditional on not just CONFIG_KVM but also !is_kernel_in_hyp_mode(). Signed-off-by: David Brazdil --- arch/arm64/kernel/smp.c | 2 +- 1 file changed, 1

[PATCH 2/6] kvm: arm64: Use lm_alias in nVHE-only VA conversion

2020-12-08 Thread David Brazdil
init_hyp_physvirt_offset() computes PA from a kernel VA. Conversion to kernel linear-map is required first but the code used kvm_ksym_ref() for this purpose. Under VHE that is a NOP and resulted in a runtime warning. Replace kvm_ksym_ref with lm_alias. Reported-by: Qian Cai Signed-off-by: David

[PATCH 1/6] kvm: arm64: Prevent use of invalid PSCI v0.1 function IDs

2020-12-08 Thread David Brazdil
. Reported-by: Mark Rutland Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_host.h| 20 +++ arch/arm64/kvm/arm.c | 14 +--- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 53 +--- 3 files changed, 70 insertions(+), 17 deletions(-) diff

[PATCH 4/6] kvm: arm64: Minor cleanup of hyp variables used in host

2020-12-08 Thread David Brazdil
Small cleanup moving declarations of hyp-exported variables to kvm_host.h and using macros to avoid having to refer to them with kvm_nvhe_sym() in host. No functional change intended. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_host.h | 6 ++ arch/arm64/kvm/arm.c

[PATCH 0/6] Fixes and cleanups of PSCI relay for kvmarm/next

2020-12-08 Thread David Brazdil
be dropped if any concerns arise. The remaining patches are minor cleanups from review. -David David Brazdil (6): kvm: arm64: Prevent use of invalid PSCI v0.1 function IDs kvm: arm64: Use lm_alias in nVHE-only VA conversion kvm: arm64: Skip computing hyp VA layout for VHE kvm: arm64: Min

Re: [PATCH v4 17/26] kvm: arm64: Add offset for hyp VA <-> PA conversion

2020-12-08 Thread David Brazdil
Hi Qian, > > +/* > > + * Store a hyp VA <-> PA offset into a hyp-owned variable. > > + */ > > +static void init_hyp_physvirt_offset(void) > > +{ > > + extern s64 kvm_nvhe_sym(hyp_physvirt_offset); > > + u64 kern_va, hyp_va; > > + > > + /* Compute the offset from the hyp VA and PA of a random

Re: [PATCH v4 06/26] psci: Add accessor for psci_0_1_function_ids

2020-12-03 Thread David Brazdil
On Thu, Dec 03, 2020 at 10:47:12AM +, Mark Rutland wrote: > On Wed, Dec 02, 2020 at 06:41:02PM +0000, David Brazdil wrote: > > Make it possible to retrieve a copy of the psci_0_1_function_ids struct. > > This is useful for KVM if it is configured to intercept host's PSCI S

[PATCH v4 07/26] arm64: Make cpu_logical_map() take unsigned int

2020-12-02 Thread David Brazdil
d-off-by: David Brazdil --- arch/arm64/include/asm/smp.h | 4 ++-- arch/arm64/kernel/setup.c| 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h index 2e7f529ec5a6..bcb01ca15325 100644 --- a/arch/arm64/include/asm/

[PATCH v4 08/26] arm64: Extract parts of el2_setup into a macro

2020-12-02 Thread David Brazdil
functional change intended. Size of el2_setup increased by 148 bytes due to duplication. Signed-off-by: David Brazdil --- arch/arm64/include/asm/el2_setup.h | 182 + arch/arm64/kernel/head.S | 144 +++ 2 files changed, 198 insertions

[PATCH v4 25/26] kvm: arm64: Trap host SMCs in protected mode

2020-12-02 Thread David Brazdil
HCR flags to use while the nVHE vector is installed when the kernel was booted with the protected flag enabled. Switch back to the default HCR flags when switching back to the stub vector. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/kvm/hyp/nvhe/hyp

[PATCH v4 24/26] kvm: arm64: Keep nVHE EL2 vector installed

2020-12-02 Thread David Brazdil
KVM by default keeps the stub vector installed and installs the nVHE vector only briefly for init and later on demand. Change this policy to install the vector at init and then never uninstall it if the kernel was given the protected KVM command line parameter. Signed-off-by: David Brazdil

[PATCH v4 26/26] kvm: arm64: Fix EL2 mode availability checks

2020-12-02 Thread David Brazdil
; modes matched at the point of KVM init and KVM will not allow cores not present at init to boot. That said, the function is never used after KVM is initialized. Signed-off-by: David Brazdil --- arch/arm64/include/asm/virt.h | 18 ++ arch/arm64/kvm/arm.c | 9 ++---

[PATCH v4 22/26] kvm: arm64: Intercept host's CPU_SUSPEND PSCI SMCs

2020-12-02 Thread David Brazdil
struct psci_boot_args to store the state upon powerup, with each CPU having separate structs for CPU_ON and CPU_SUSPEND so that CPU_SUSPEND can operate locklessly and so that a CPU_ON call targeting a CPU cannot interfere with a concurrent CPU_SUSPEND call on that CPU. Signed-off-by: David Brazdil

[PATCH v4 23/26] kvm: arm64: Intercept host's SYSTEM_SUSPEND PSCI SMCs

2020-12-02 Thread David Brazdil
Add a handler of SYSTEM_SUSPEND host PSCI SMCs. The semantics are equivalent to CPU_SUSPEND, typically called on the last online CPU. Reuse the same entry point and boot args struct as CPU_SUSPEND. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 2 +- arch/arm64/kvm/hyp

[PATCH v4 13/26] kvm: arm64: Support per_cpu_ptr in nVHE hyp code

2020-12-02 Thread David Brazdil
only this_cpu_ptr() was supported by setting TPIDR_EL2. Signed-off-by: David Brazdil --- arch/arm64/include/asm/percpu.h | 6 ++ arch/arm64/kernel/image-vars.h| 3 +++ arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++- arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 24 4 files

[PATCH v4 15/26] kvm: arm64: Add SMC handler in nVHE EL2

2020-12-02 Thread David Brazdil
arguments and results, other GPRs are preserved. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/host.S | 38 ++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 35 --- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/arch/arm64

[PATCH v4 11/26] kvm: arm64: Init MAIR/TCR_EL2 from params struct

2020-12-02 Thread David Brazdil
and can be used when booting new cores. Take the opportunity to move copying the T0SZ value from idmap_t0sz in KVM init rather than in .hyp.idmap.text. This avoids the need for the idmap_t0sz symbol alias. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 2 ++ arch/arm64

[PATCH v4 21/26] kvm: arm64: Intercept host's CPU_ON SMCs

2020-12-02 Thread David Brazdil
returning ERET to the provided PC in EL1. There is a simple atomic lock around the boot args struct. If it is already locked, CPU_ON will return PENDING_ON error code. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 48 +++ arch/arm64/kvm/hyp/nvhe/psci-relay.c | 115

[PATCH v4 19/26] kvm: arm64: Extract __do_hyp_init into a helper function

2020-12-02 Thread David Brazdil
In preparation for adding a CPU entry point in nVHE hyp code, extract most of __do_hyp_init hypervisor initialization code into a common helper function. This will be invoked by the entry point to install KVM on the newly booted CPU. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp

[PATCH v4 20/26] kvm: arm64: Add function to enter host from KVM nVHE hyp code

2020-12-02 Thread David Brazdil
-restoring code after the trap handler would have returned. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/host.S | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index 2b56f0bdf874..a820dfdc9c25 100644 --- a/arch

[PATCH v4 18/26] kvm: arm64: Forward safe PSCI SMCs coming from host

2020-12-02 Thread David Brazdil
M_OFF * SYSTEM_RESET * SYSTEM_RESET2 Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 42 +++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index 70b42f4

[PATCH v4 17/26] kvm: arm64: Add offset for hyp VA <-> PA conversion

2020-12-02 Thread David Brazdil
Add a host-initialized constant to KVM nVHE hyp code for converting between EL2 linear map virtual addresses and physical addresses. Also add `__hyp_pa` macro that performs the conversion. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 +++ arch/arm64/kvm/va_layout.c

[PATCH v4 16/26] kvm: arm64: Bootstrap PSCI SMC handler in nVHE EL2

2020-12-02 Thread David Brazdil
, the SMC is handled by the PSCI handler. For now, all SMCs return PSCI_RET_NOT_SUPPORTED. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_hyp.h | 2 + arch/arm64/kvm/arm.c | 25 - .../arm64/kvm/hyp/include/nvhe/trap_handler.h | 18

[PATCH v4 09/26] kvm: arm64: Remove vector_ptr param of hyp-init

2020-12-02 Thread David Brazdil
. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 2 -- arch/arm64/include/asm/kvm_mmu.h | 24 arch/arm64/kvm/arm.c | 4 +--- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 9 ++--- 4 files changed, 31 insertions(+), 8 deletions(-) diff

[PATCH v4 10/26] kvm: arm64: Move hyp-init params to a per-CPU struct

2020-12-02 Thread David Brazdil
. Refactor __do_hyp_init to accept its parameters in a struct. This prepares the code for KVM booting cores as well as removes any limits on the number of __do_hyp_init arguments. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 6 ++ arch/arm64/include/asm/kvm_hyp.h | 2

[PATCH v4 12/26] kvm: arm64: Add .hyp.data..ro_after_init ELF section

2020-12-02 Thread David Brazdil
section and they are never changed by hyp afterwards. Signed-off-by: David Brazdil --- arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/vmlinux.lds.S | 10 ++ arch/arm64/kvm/arm.c | 8 arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + 4 files changed, 20 insertions

[PATCH v4 14/26] kvm: arm64: Create nVHE copy of cpu_logical_map

2020-12-02 Thread David Brazdil
whose features were not checked against the finalized capabilities. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 19 +++ arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 16 2 files changed, 35 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm6

[PATCH v4 06/26] psci: Add accessor for psci_0_1_function_ids

2020-12-02 Thread David Brazdil
Make it possible to retrieve a copy of the psci_0_1_function_ids struct. This is useful for KVM if it is configured to intercept host's PSCI SMCs. Signed-off-by: David Brazdil --- drivers/firmware/psci/psci.c | 12 +--- include/linux/psci.h | 9 + 2 files change

[PATCH v4 05/26] psci: Replace psci_function_id array with a struct

2020-12-02 Thread David Brazdil
s checking. Signed-off-by: David Brazdil --- drivers/firmware/psci/psci.c | 29 ++--- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 13b9ed71b446..593fdd0e09a2 100644 --- a/drivers/firmware/psci/ps

[PATCH v4 04/26] psci: Split functions to v0.1 and v0.2+ variants

2020-12-02 Thread David Brazdil
-off-by: David Brazdil --- drivers/firmware/psci/psci.c | 94 +++- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index ace5b9ac676c..13b9ed71b446 100644 --- a/drivers/firmware/psci/psci.c

[PATCH v4 03/26] psci: Support psci_ops.get_version for v0.1

2020-12-02 Thread David Brazdil
on is currently unused so this has no effect on existing functionality. Acked-by: Mark Rutland Signed-off-by: David Brazdil --- drivers/firmware/psci/psci.c | 13 ++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c

[PATCH v4 02/26] kvm: arm64: Add ARM64_KVM_PROTECTED_MODE CPU capability

2020-12-02 Thread David Brazdil
Expose the boolean value whether the system is running with KVM in protected mode (nVHE + kernel param). CPU capability was selected over a global variable to allow use in alternatives. Signed-off-by: David Brazdil --- arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm

[PATCH v4 01/26] kvm: arm64: Add kvm-arm.mode early kernel parameter

2020-12-02 Thread David Brazdil
ned-off-by: David Brazdil --- Documentation/admin-guide/kernel-parameters.txt | 10 ++ arch/arm64/include/asm/kvm_host.h | 9 + arch/arm64/kvm/arm.c| 16 3 files changed, 35 insertions(+) diff --git a/Documentation/admin-gu

[PATCH v4 00/26] Opt-in always-on nVHE hypervisor

2020-12-02 Thread David Brazdil
PEND implementation * replace spinlocks with CAS atomic * make cpu_logical_map ro_after_init David Brazdil (26): kvm: arm64: Add kvm-arm.mode early kernel parameter kvm: arm64: Add ARM64_KVM_PROTECTED_MODE CPU capability psci: Support psci_ops.get_version for v0.1 psci: Split fu

Re: [PATCH v3 16/23] kvm: arm64: Forward safe PSCI SMCs coming from host

2020-12-02 Thread David Brazdil
On Fri, Nov 27, 2020 at 10:14:33AM +, Lorenzo Pieralisi wrote: > On Thu, Nov 26, 2020 at 03:54:14PM +0000, David Brazdil wrote: > > Forward the following PSCI SMCs issued by host to EL3 as they do not > > require the hypervisor's intervention. This assumes that EL3 correctl

Re: [PATCH v3 03/23] arm64: Make cpu_logical_map() take unsigned int

2020-12-02 Thread David Brazdil
On Thu, Nov 26, 2020 at 05:28:38PM +, Mark Rutland wrote: > On Thu, Nov 26, 2020 at 03:54:01PM +0000, David Brazdil wrote: > > CPU index should never be negative. Change the signature of > > (set_)cpu_logical_map to take an unsigned int. > > > > Signed-off-by: Dav

Re: [PATCH v3 06/23] kvm: arm64: Add kvm-arm.protected early kernel parameter

2020-12-01 Thread David Brazdil
> > > be just me, but if you agree please update so that it doesn't give remote > > > idea that it is not valid on VHE enabled hardware. > > > > > > I was trying to run this on the hardware and was trying to understand the > > > details on how to do that. > > > > I see what you're saying, but !CO

Re: [PATCH v3 04/23] arm64: Move MAIR_EL1_SET to asm/memory.h

2020-12-01 Thread David Brazdil
Hey Mark, > > diff --git a/arch/arm64/include/asm/memory.h > > b/arch/arm64/include/asm/memory.h > > index cd61239bae8c..54a22cb5b17b 100644 > > --- a/arch/arm64/include/asm/memory.h > > +++ b/arch/arm64/include/asm/memory.h > > @@ -152,6 +152,19 @@ > > #define MT_S2_FWB_NORMAL 6 > > #define

Re: [PATCH v3 05/23] arm64: Extract parts of el2_setup into a macro

2020-12-01 Thread David Brazdil
Hey Mark, > In the head.S code, this was under an ifdef CONFIG_ARM_GIC_V3, but that > ifdef wasn't carried into the macro here, or into its use below. I'm not > sure of the impact, but that does seem to be a functional change. > > > + > > +.macro __init_el2_hstr > > + msr hstr_el2, xzr

Re: [PATCH v3 19/23] kvm: arm64: Intercept host's CPU_ON SMCs

2020-12-01 Thread David Brazdil
Hey Sudeep, > > +static unsigned int find_cpu_id(u64 mpidr) > > +{ > > + unsigned int i; > > + > > + /* Reject invalid MPIDRs */ > > + if (mpidr & ~MPIDR_HWID_BITMASK) > > + return INVALID_CPU_ID; > > + > > + for (i = 0; i < NR_CPUS; i++) { > > I may not have understood the flow

Re: [PATCH v3 16/23] kvm: arm64: Forward safe PSCI SMCs coming from host

2020-12-01 Thread David Brazdil
On Fri, Nov 27, 2020 at 04:51:59PM +, Sudeep Holla wrote: > On Thu, Nov 26, 2020 at 03:54:14PM +0000, David Brazdil wrote: > > Forward the following PSCI SMCs issued by host to EL3 as they do not > > require the hypervisor's intervention. This assumes that EL3 correctly >

Re: [PATCH v3 06/23] kvm: arm64: Add kvm-arm.protected early kernel parameter

2020-12-01 Thread David Brazdil
Hey Sudeep, > > diff --git a/Documentation/admin-guide/kernel-parameters.txt > > b/Documentation/admin-guide/kernel-parameters.txt > > index 526d65d8573a..06c89975c29c 100644 > > --- a/Documentation/admin-guide/kernel-parameters.txt > > +++ b/Documentation/admin-guide/kernel-parameters.txt > > @@

Re: [PATCH v3 02/23] psci: Accessor for configured PSCI function IDs

2020-11-26 Thread David Brazdil
Hey Mark, On Thu, Nov 26, 2020 at 05:24:50PM +, Mark Rutland wrote: > On Thu, Nov 26, 2020 at 03:54:00PM +0000, David Brazdil wrote: > > Function IDs used by PSCI are configurable for v0.1 via DT/APCI. If the > > host is using PSCI v0.1, KVM's host PSCI proxy needs

[PATCH v3 12/23] kvm: arm64: Create nVHE copy of cpu_logical_map

2020-11-26 Thread David Brazdil
whose features were not checked against the finalized capabilities. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 19 +++ arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 16 2 files changed, 35 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm6

[PATCH v3 23/23] kvm: arm64: Fix EL2 mode availability checks

2020-11-26 Thread David Brazdil
all cores' modes matched at the point of KVM init and KVM will not allow cores not present at init to boot. That said, the function is never used after KVM is initialized. Signed-off-by: David Brazdil --- arch/arm64/include/asm/virt.h | 18 ++ arch/arm64/kvm/arm.

[PATCH v3 21/23] kvm: arm64: Keep nVHE EL2 vector installed

2020-11-26 Thread David Brazdil
KVM by default keeps the stub vector installed and installs the nVHE vector only briefly for init and later on demand. Change this policy to install the vector at init and then never uninstall it if the kernel was given the protected KVM command line parameter. Signed-off-by: David Brazdil

[PATCH v3 20/23] kvm: arm64: Intercept host's CPU_SUSPEND PSCI SMCs

2020-11-26 Thread David Brazdil
racing them for the same boot args struct, CPU_SUSPEND uses a different struct instance and entry point. Each entry point selects the corresponding struct to restore host boot args from. This avoids the need for locking in CPU_SUSPEND. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp

[PATCH v3 22/23] kvm: arm64: Trap host SMCs in protected mode

2020-11-26 Thread David Brazdil
booted with the protected flag enabled. Switch back to the default HCR flags when switching back to the stub vector. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/kvm/hyp/nvhe/hyp-init.S | 10 ++ arch/arm64/kvm/hyp/nvhe/switch.c | 5 - 3 files

[PATCH v3 17/23] kvm: arm64: Extract __do_hyp_init into a helper function

2020-11-26 Thread David Brazdil
In preparation for adding a CPU entry point in nVHE hyp code, extract most of __do_hyp_init hypervisor initialization code into a common helper function. This will be invoked by the entry point to install KVM on the newly booted CPU. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp

[PATCH v3 18/23] kvm: arm64: Add function to enter host from KVM nVHE hyp code

2020-11-26 Thread David Brazdil
-restoring code after the trap handler would have returned. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/host.S | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index 2b56f0bdf874..a820dfdc9c25 100644 --- a/arch

[PATCH v3 15/23] kvm: arm64: Add offset for hyp VA <-> PA conversion

2020-11-26 Thread David Brazdil
Add a host-initialized constant to KVM nVHE hyp code for converting between EL2 linear map virtual addresses and physical addresses. Also add `__hyp_pa` macro that performs the conversion. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 +++ arch/arm64/kvm/va_layout.c

[PATCH v3 19/23] kvm: arm64: Intercept host's CPU_ON SMCs

2020-11-26 Thread David Brazdil
returning ERET to the provided PC in EL1. There is a simple atomic lock around the boot args struct. If it is already locked, CPU_ON will return PENDING_ON error code. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 30 arch/arm64/kvm/hyp/nvhe/psci-relay.c | 109

[PATCH v3 16/23] kvm: arm64: Forward safe PSCI SMCs coming from host

2020-11-26 Thread David Brazdil
M_OFF * SYSTEM_RESET * SYSTEM_RESET2 Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 43 +++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index e7091d8

[PATCH v3 13/23] kvm: arm64: Add SMC handler in nVHE EL2

2020-11-26 Thread David Brazdil
for arguments and results, other GPRs are preserved. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/host.S | 38 ++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 35 --- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/arch

  1   2   3   4   >