kvmarm.lists.cs.columbia.edu archive mirror
 help / color / mirror / Atom feed
* [GIT PULL] KVM/arm64 fixes for 5.8, take #4
@ 2020-07-28  8:22 Marc Zyngier
  2020-07-28  8:22 ` [PATCH 1/2] KVM: arm64: Prevent vcpu_has_ptrauth from generating OOL functions Marc Zyngier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marc Zyngier @ 2020-07-28  8:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, kernel-team, Nick Desaulniers, linux-arm-kernel,
	Nathan Chancellor, Will Deacon, kvmarm

Hi Paolo,

This is the last batch of fixes for 5.8. One fixes a long standing MMU
issue, while the other addresses a more recent brekage with out-of-line
helpers in the nVHE code.

Please pull,

	M.

The following changes since commit b9e10d4a6c9f5cbe6369ce2c17ebc67d2e5a4be5:

  KVM: arm64: Stop clobbering x0 for HVC_SOFT_RESTART (2020-07-06 11:47:02 +0100)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-5.8-4

for you to fetch changes up to b757b47a2fcba584d4a32fd7ee68faca510ab96f:

  KVM: arm64: Don't inherit exec permission across page-table levels (2020-07-28 09:03:57 +0100)

----------------------------------------------------------------
KVM/arm64 fixes for Linux 5.8, take #3

- Fix a corner case of a new mapping inheriting exec permission without
  and yet bypassing invalidation of the I-cache
- Make sure PtrAuth predicates oinly generate inline code for the
  non-VHE hypervisor code

----------------------------------------------------------------
Marc Zyngier (1):
      KVM: arm64: Prevent vcpu_has_ptrauth from generating OOL functions

Will Deacon (1):
      KVM: arm64: Don't inherit exec permission across page-table levels

 arch/arm64/include/asm/kvm_host.h | 11 ++++++++---
 arch/arm64/kvm/mmu.c              | 11 ++++++-----
 2 files changed, 14 insertions(+), 8 deletions(-)
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* [PATCH 1/2] KVM: arm64: Prevent vcpu_has_ptrauth from generating OOL functions
  2020-07-28  8:22 [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Marc Zyngier
@ 2020-07-28  8:22 ` Marc Zyngier
  2020-07-28  8:22 ` [PATCH 2/2] KVM: arm64: Don't inherit exec permission across page-table levels Marc Zyngier
  2020-07-31 11:25 ` [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2020-07-28  8:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, kernel-team, Nick Desaulniers, linux-arm-kernel,
	Nathan Chancellor, Will Deacon, kvmarm

So far, vcpu_has_ptrauth() is implemented in terms of system_supports_*_auth()
calls, which are declared "inline". In some specific conditions (clang
and SCS), the "inline" very much turns into an "out of line", which
leads to a fireworks when this predicate is evaluated on a non-VHE
system (right at the beginning of __hyp_handle_ptrauth).

Instead, make sure vcpu_has_ptrauth gets expanded inline by directly
using the cpus_have_final_cap() helpers, which are __always_inline,
generate much better code, and are the only thing that make sense when
running at EL2 on a nVHE system.

Fixes: 29eb5a3c57f7 ("KVM: arm64: Handle PtrAuth traps early")
Reported-by: Nathan Chancellor <natechancellor@gmail.com>
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Link: https://lore.kernel.org/r/20200722162231.3689767-1-maz@kernel.org
---
 arch/arm64/include/asm/kvm_host.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index c3e6fcc664b1..e21d4a01372f 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -380,9 +380,14 @@ struct kvm_vcpu_arch {
 #define vcpu_has_sve(vcpu) (system_supports_sve() && \
 			    ((vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_SVE))
 
-#define vcpu_has_ptrauth(vcpu)	((system_supports_address_auth() || \
-				  system_supports_generic_auth()) && \
-				 ((vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_PTRAUTH))
+#ifdef CONFIG_ARM64_PTR_AUTH
+#define vcpu_has_ptrauth(vcpu)						\
+	((cpus_have_final_cap(ARM64_HAS_ADDRESS_AUTH) ||		\
+	  cpus_have_final_cap(ARM64_HAS_GENERIC_AUTH)) &&		\
+	 (vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_PTRAUTH)
+#else
+#define vcpu_has_ptrauth(vcpu)		false
+#endif
 
 #define vcpu_gp_regs(v)		(&(v)->arch.ctxt.gp_regs)
 
-- 
2.27.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* [PATCH 2/2] KVM: arm64: Don't inherit exec permission across page-table levels
  2020-07-28  8:22 [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Marc Zyngier
  2020-07-28  8:22 ` [PATCH 1/2] KVM: arm64: Prevent vcpu_has_ptrauth from generating OOL functions Marc Zyngier
@ 2020-07-28  8:22 ` Marc Zyngier
  2020-07-31 11:25 ` [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2020-07-28  8:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, kernel-team, Nick Desaulniers, stable, linux-arm-kernel,
	Nathan Chancellor, Will Deacon, kvmarm

From: Will Deacon <will@kernel.org>

If a stage-2 page-table contains an executable, read-only mapping at the
pte level (e.g. due to dirty logging being enabled), a subsequent write
fault to the same page which tries to install a larger block mapping
(e.g. due to dirty logging having been disabled) will erroneously inherit
the exec permission and consequently skip I-cache invalidation for the
rest of the block.

Ensure that exec permission is only inherited by write faults when the
new mapping is of the same size as the existing one. A subsequent
instruction abort will result in I-cache invalidation for the entire
block mapping.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Tested-by: Quentin Perret <qperret@google.com>
Reviewed-by: Quentin Perret <qperret@google.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200723101714.15873-1-will@kernel.org
---
 arch/arm64/kvm/mmu.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 8c0035cab6b6..31058e6e7c2a 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1326,7 +1326,7 @@ static bool stage2_get_leaf_entry(struct kvm *kvm, phys_addr_t addr,
 	return true;
 }
 
-static bool stage2_is_exec(struct kvm *kvm, phys_addr_t addr)
+static bool stage2_is_exec(struct kvm *kvm, phys_addr_t addr, unsigned long sz)
 {
 	pud_t *pudp;
 	pmd_t *pmdp;
@@ -1338,11 +1338,11 @@ static bool stage2_is_exec(struct kvm *kvm, phys_addr_t addr)
 		return false;
 
 	if (pudp)
-		return kvm_s2pud_exec(pudp);
+		return sz <= PUD_SIZE && kvm_s2pud_exec(pudp);
 	else if (pmdp)
-		return kvm_s2pmd_exec(pmdp);
+		return sz <= PMD_SIZE && kvm_s2pmd_exec(pmdp);
 	else
-		return kvm_s2pte_exec(ptep);
+		return sz == PAGE_SIZE && kvm_s2pte_exec(ptep);
 }
 
 static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache,
@@ -1958,7 +1958,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	 * execute permissions, and we preserve whatever we have.
 	 */
 	needs_exec = exec_fault ||
-		(fault_status == FSC_PERM && stage2_is_exec(kvm, fault_ipa));
+		(fault_status == FSC_PERM &&
+		 stage2_is_exec(kvm, fault_ipa, vma_pagesize));
 
 	if (vma_pagesize == PUD_SIZE) {
 		pud_t new_pud = kvm_pfn_pud(pfn, mem_type);
-- 
2.27.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: [GIT PULL] KVM/arm64 fixes for 5.8, take #4
  2020-07-28  8:22 [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Marc Zyngier
  2020-07-28  8:22 ` [PATCH 1/2] KVM: arm64: Prevent vcpu_has_ptrauth from generating OOL functions Marc Zyngier
  2020-07-28  8:22 ` [PATCH 2/2] KVM: arm64: Don't inherit exec permission across page-table levels Marc Zyngier
@ 2020-07-31 11:25 ` Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2020-07-31 11:25 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: kvm, kernel-team, Nick Desaulniers, linux-arm-kernel,
	Nathan Chancellor, Will Deacon, kvmarm

On 28/07/20 10:22, Marc Zyngier wrote:
> Hi Paolo,
> 
> This is the last batch of fixes for 5.8. One fixes a long standing MMU
> issue, while the other addresses a more recent brekage with out-of-line
> helpers in the nVHE code.
> 
> Please pull,
> 
> 	M.
> 
> The following changes since commit b9e10d4a6c9f5cbe6369ce2c17ebc67d2e5a4be5:
> 
>   KVM: arm64: Stop clobbering x0 for HVC_SOFT_RESTART (2020-07-06 11:47:02 +0100)
> 
> are available in the Git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-5.8-4
> 
> for you to fetch changes up to b757b47a2fcba584d4a32fd7ee68faca510ab96f:
> 
>   KVM: arm64: Don't inherit exec permission across page-table levels (2020-07-28 09:03:57 +0100)
> 
> ----------------------------------------------------------------
> KVM/arm64 fixes for Linux 5.8, take #3
> 
> - Fix a corner case of a new mapping inheriting exec permission without
>   and yet bypassing invalidation of the I-cache
> - Make sure PtrAuth predicates oinly generate inline code for the
>   non-VHE hypervisor code
> 
> ----------------------------------------------------------------
> Marc Zyngier (1):
>       KVM: arm64: Prevent vcpu_has_ptrauth from generating OOL functions
> 
> Will Deacon (1):
>       KVM: arm64: Don't inherit exec permission across page-table levels
> 
>  arch/arm64/include/asm/kvm_host.h | 11 ++++++++---
>  arch/arm64/kvm/mmu.c              | 11 ++++++-----
>  2 files changed, 14 insertions(+), 8 deletions(-)
> 

Pulled, thanks.

Paolo

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

end of thread, other threads:[~2020-07-31 11:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28  8:22 [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Marc Zyngier
2020-07-28  8:22 ` [PATCH 1/2] KVM: arm64: Prevent vcpu_has_ptrauth from generating OOL functions Marc Zyngier
2020-07-28  8:22 ` [PATCH 2/2] KVM: arm64: Don't inherit exec permission across page-table levels Marc Zyngier
2020-07-31 11:25 ` [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Paolo Bonzini

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).