linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: arm64: Stub exports in nvhe code
@ 2021-02-03 14:19 Quentin Perret
  2021-02-03 14:19 ` [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS Quentin Perret
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Quentin Perret @ 2021-02-03 14:19 UTC (permalink / raw)
  To: arnd, maz, catalin.marinas, will
  Cc: james.morse, julien.thierry.kdev, suzuki.poulose, ardb,
	linux-arch, linux-kernel, linux-arm-kernel, kvmarm, kernel-team,
	qperret

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/20210108121524.656872-1-qperret@google.com/

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS
  2021-02-03 14:19 [PATCH 0/2] KVM: arm64: Stub exports in nvhe code Quentin Perret
@ 2021-02-03 14:19 ` Quentin Perret
  2021-02-03 15:24   ` Will Deacon
  2021-02-03 14:19 ` [PATCH 2/2] KVM: arm64: Stub EXPORT_SYMBOL for nVHE EL2 code Quentin Perret
  2021-02-03 16:43 ` [PATCH 0/2] KVM: arm64: Stub exports in nvhe code Marc Zyngier
  2 siblings, 1 reply; 5+ messages in thread
From: Quentin Perret @ 2021-02-03 14:19 UTC (permalink / raw)
  To: arnd, maz, catalin.marinas, will
  Cc: james.morse, julien.thierry.kdev, suzuki.poulose, ardb,
	linux-arch, linux-kernel, linux-arm-kernel, kvmarm, kernel-team,
	qperret

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 <qperret@google.com>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] KVM: arm64: Stub EXPORT_SYMBOL for nVHE EL2 code
  2021-02-03 14:19 [PATCH 0/2] KVM: arm64: Stub exports in nvhe code Quentin Perret
  2021-02-03 14:19 ` [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS Quentin Perret
@ 2021-02-03 14:19 ` Quentin Perret
  2021-02-03 16:43 ` [PATCH 0/2] KVM: arm64: Stub exports in nvhe code Marc Zyngier
  2 siblings, 0 replies; 5+ messages in thread
From: Quentin Perret @ 2021-02-03 14:19 UTC (permalink / raw)
  To: arnd, maz, catalin.marinas, will
  Cc: james.morse, julien.thierry.kdev, suzuki.poulose, ardb,
	linux-arch, linux-kernel, linux-arm-kernel, kvmarm, kernel-team,
	qperret

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 <ardb@kernel.org>
Signed-off-by: Quentin Perret <qperret@google.com>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS
  2021-02-03 14:19 ` [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS Quentin Perret
@ 2021-02-03 15:24   ` Will Deacon
  0 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2021-02-03 15:24 UTC (permalink / raw)
  To: Quentin Perret
  Cc: arnd, maz, catalin.marinas, james.morse, julien.thierry.kdev,
	suzuki.poulose, ardb, linux-arch, linux-kernel, linux-arm-kernel,
	kvmarm, kernel-team

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 <qperret@google.com>
> ---
>  include/asm-generic/export.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Will Deacon <will@kernel.org>

Will

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] KVM: arm64: Stub exports in nvhe code
  2021-02-03 14:19 [PATCH 0/2] KVM: arm64: Stub exports in nvhe code Quentin Perret
  2021-02-03 14:19 ` [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS Quentin Perret
  2021-02-03 14:19 ` [PATCH 2/2] KVM: arm64: Stub EXPORT_SYMBOL for nVHE EL2 code Quentin Perret
@ 2021-02-03 16:43 ` Marc Zyngier
  2 siblings, 0 replies; 5+ messages in thread
From: Marc Zyngier @ 2021-02-03 16:43 UTC (permalink / raw)
  To: arnd, Quentin Perret, catalin.marinas, will
  Cc: ardb, linux-arm-kernel, linux-arch, kernel-team, linux-kernel, kvmarm

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.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-03 16:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 14:19 [PATCH 0/2] KVM: arm64: Stub exports in nvhe code Quentin Perret
2021-02-03 14:19 ` [PATCH 1/2] asm-generic: export: Stub EXPORT_SYMBOL with __DISABLE_EXPORTS Quentin Perret
2021-02-03 15:24   ` Will Deacon
2021-02-03 14:19 ` [PATCH 2/2] KVM: arm64: Stub EXPORT_SYMBOL for nVHE EL2 code Quentin Perret
2021-02-03 16:43 ` [PATCH 0/2] KVM: arm64: Stub exports in nvhe code Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).