2021-02-03 14:21:45

by Quentin Perret

[permalink] [raw]
Subject: [PATCH 0/2] KVM: arm64: Stub exports in nvhe code

Hi all,

In the context of the currently ongoing work to remove the host kernel
from the TCB under KVM/arm64, I have been trying to wrap the host kernel
with a stage 2 page-table -- see [1].

Using this infrastructure, I attempted to unmap the .hyp. sections from
the host stage 2 as it really shouldn't need to access them. But by
doing so, I realized quickly the module loader was getting very confused
by the usage of EXPORT_SYMBOL() macros in library functions that have
been pulled into the EL2 object, and that we end up linking modules
against the EL2 copy of e.g. memset. And so, this series essentially
tries to fix this.

- Patch 01 changes asm-generic/export.h to ensure we respect
__DISABLE_EXPORTS even for asm exports;

- and patch 02 makes use of it for all of the nVHE EL2 code.

This was tested on aml-s905x-cc, which now successfully loads kernel
modules with .hyp.text unmapped from the host.

Thanks,
Quentin

[1] https://lore.kernel.org/kvmarm/[email protected]/

Quentin Perret (2):
asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS
KVM: arm64: Stub EXPORT_SYMBOL for nVHE EL2 code

arch/arm64/kvm/hyp/nvhe/Makefile | 4 ++--
include/asm-generic/export.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

--
2.30.0.365.g02bc693789-goog


2021-02-03 14:23:48

by Quentin Perret

[permalink] [raw]
Subject: [PATCH 2/2] KVM: arm64: Stub EXPORT_SYMBOL for nVHE EL2 code

In order to ensure the module loader does not get confused if a symbol
is exported in EL2 nVHE code (as will be the case when we will compile
e.g. lib/memset.S into the EL2 object), make sure to stub all exports
using __DISABLE_EXPORTS in the nvhe folder.

Suggested-by: Ard Biesheuvel <[email protected]>
Signed-off-by: Quentin Perret <[email protected]>
---
arch/arm64/kvm/hyp/nvhe/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
index 1f1e351c5fe2..c9c121c8d5de 100644
--- a/arch/arm64/kvm/hyp/nvhe/Makefile
+++ b/arch/arm64/kvm/hyp/nvhe/Makefile
@@ -3,8 +3,8 @@
# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
#

-asflags-y := -D__KVM_NVHE_HYPERVISOR__
-ccflags-y := -D__KVM_NVHE_HYPERVISOR__
+asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
+ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS

obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
hyp-main.o hyp-smp.o psci-relay.o
--
2.30.0.365.g02bc693789-goog

2021-02-03 14:24:20

by Quentin Perret

[permalink] [raw]
Subject: [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS

It is currently possible to stub EXPORT_SYMBOL() macros in C code using
__DISABLE_EXPORTS, which is necessary to run in constrained environments
such as the EFI stub or the decompressor. But this currently doesn't
apply to exports from assembly, which can lead to somewhat confusing
situations.

Consolidate the __DISABLE_EXPORTS infrastructure by checking it from
asm-generic/export.h as well.

Signed-off-by: Quentin Perret <[email protected]>
---
include/asm-generic/export.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h
index 365345f9a9e3..07a36a874dca 100644
--- a/include/asm-generic/export.h
+++ b/include/asm-generic/export.h
@@ -33,7 +33,7 @@
*/

.macro ___EXPORT_SYMBOL name,val,sec
-#ifdef CONFIG_MODULES
+#if defined(CONFIG_MODULES) && !defined(__DISABLE_EXPORTS)
.section ___ksymtab\sec+\name,"a"
.balign KSYM_ALIGN
__ksymtab_\name:
--
2.30.0.365.g02bc693789-goog

2021-02-03 15:28:48

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS

On Wed, Feb 03, 2021 at 02:19:30PM +0000, Quentin Perret wrote:
> It is currently possible to stub EXPORT_SYMBOL() macros in C code using
> __DISABLE_EXPORTS, which is necessary to run in constrained environments
> such as the EFI stub or the decompressor. But this currently doesn't
> apply to exports from assembly, which can lead to somewhat confusing
> situations.
>
> Consolidate the __DISABLE_EXPORTS infrastructure by checking it from
> asm-generic/export.h as well.
>
> Signed-off-by: Quentin Perret <[email protected]>
> ---
> include/asm-generic/export.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Will Deacon <[email protected]>

Will

2021-02-03 16:46:41

by Marc Zyngier

[permalink] [raw]
Subject: Re: [PATCH 0/2] KVM: arm64: Stub exports in nvhe code

On Wed, 3 Feb 2021 14:19:29 +0000, Quentin Perret wrote:
> In the context of the currently ongoing work to remove the host kernel
> from the TCB under KVM/arm64, I have been trying to wrap the host kernel
> with a stage 2 page-table -- see [1].
>
> Using this infrastructure, I attempted to unmap the .hyp. sections from
> the host stage 2 as it really shouldn't need to access them. But by
> doing so, I realized quickly the module loader was getting very confused
> by the usage of EXPORT_SYMBOL() macros in library functions that have
> been pulled into the EL2 object, and that we end up linking modules
> against the EL2 copy of e.g. memset. And so, this series essentially
> tries to fix this.
>
> [...]

Applied to kvm-arm64/misc-5.12, thanks!

[1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS
commit: 54effa653246c35997f5e990e0134be5be09f9d1
[2/2] KVM: arm64: Stub EXPORT_SYMBOL for nVHE EL2 code
commit: bbc075e01ceac50e0a8353b520544f3089e94e44

Cheers,

M.
--
Without deviation from the norm, progress is not possible.