From patchwork Tue Jul 28 08:22:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11688633 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44AE814DD for ; Tue, 28 Jul 2020 08:23:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CA1620FC3 for ; Tue, 28 Jul 2020 08:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595924606; bh=s+JcctlNG0hHX2xEwi6C3ENfXMCtVb68JpHdq0Skmw4=; h=From:To:Cc:Subject:Date:List-ID:From; b=dhJJT9KnbQvHlScvDwfUlszyBrSYHSPS6xMm1J2oZ3j0GqCVwVyVcGjGVS2kceepb Q2/36AP8hU14CZPe5eibmcHYT4DVZ3YSKIvdYPe12JGZ3RE4kp8nVb6gp4QtrXR+Iu w8DiWsr/F0SE7xa+SgM/RAeiegjKL58EGLB4bols= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727978AbgG1IXZ (ORCPT ); Tue, 28 Jul 2020 04:23:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:49312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727878AbgG1IXY (ORCPT ); Tue, 28 Jul 2020 04:23:24 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5E64A2075D; Tue, 28 Jul 2020 08:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595924604; bh=s+JcctlNG0hHX2xEwi6C3ENfXMCtVb68JpHdq0Skmw4=; h=From:To:Cc:Subject:Date:From; b=FhwUUQidy339zU5Wogz7l7ZnPOqzOczutbqIH2gK1BTX5z0NE9l7Ve489HTCVByJR 5FoMU64OWFU+Dy1nx65lqauBVZMUso+rxZB+85ve4BCguqOnD/Wqy9eerAg2rICaOl 8x8WSiJjUkToSjV+fWon8nmzf7GyS8B66OyclbPA= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k0KtO-00FaXh-S3; Tue, 28 Jul 2020 09:23:23 +0100 From: Marc Zyngier To: Paolo Bonzini Cc: Nathan Chancellor , Nick Desaulniers , Quentin Perret , Will Deacon , James Morse , Julien Thierry , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kernel-team@android.com Subject: [GIT PULL] KVM/arm64 fixes for 5.8, take #4 Date: Tue, 28 Jul 2020 09:22:53 +0100 Message-Id: <20200728082255.3864378-1-maz@kernel.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: pbonzini@redhat.com, natechancellor@gmail.com, ndesaulniers@google.com, qperret@google.com, will@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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(-) From patchwork Tue Jul 28 08:22:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11688637 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 659CC6C1 for ; Tue, 28 Jul 2020 08:23:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DB8C208E4 for ; Tue, 28 Jul 2020 08:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595924608; bh=7J4ifTf3z4A0dVzuF6o8Muc/dgb2Mqij10g2be4Y9DE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gLVqb3LIEJvPT8xfBePP0B1GSNaG4t7ksmvzzwE0/VCtMmdxxNR3fXwjF8p3CvIlP lXQpOVgqY3LXmi4iHdgb7yvS2p7E5CT7iCoBEaO9czCYU2EPWlgL2rDqvbJeokAHZ4 HEp+obk7lOLi1o8RzQb3jKq6vF/6nu3JEayczYs8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728059AbgG1IX1 (ORCPT ); Tue, 28 Jul 2020 04:23:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:49382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728017AbgG1IX0 (ORCPT ); Tue, 28 Jul 2020 04:23:26 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A523B20838; Tue, 28 Jul 2020 08:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595924605; bh=7J4ifTf3z4A0dVzuF6o8Muc/dgb2Mqij10g2be4Y9DE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=inLBOhOJkaD/rInFVr1UHi1jHUyuEcmkFu2RME7YqR8Z/cjTmNBcyc0T4SQKugqml Kd2psSirXcMv+m0Xz9GHST5fjl+MoyktTLW4hqNdAh7Ry3JB2jO0eQB7d2SQ250sSf TvEIhuEQxk5whTW4cm9PBhZrjnrSRKMQOtbRSX3U= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k0KtQ-00FaXh-7H; Tue, 28 Jul 2020 09:23:24 +0100 From: Marc Zyngier To: Paolo Bonzini Cc: Nathan Chancellor , Nick Desaulniers , Quentin Perret , Will Deacon , James Morse , Julien Thierry , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kernel-team@android.com, stable@vger.kernel.org Subject: [PATCH 2/2] KVM: arm64: Don't inherit exec permission across page-table levels Date: Tue, 28 Jul 2020 09:22:55 +0100 Message-Id: <20200728082255.3864378-3-maz@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728082255.3864378-1-maz@kernel.org> References: <20200728082255.3864378-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: pbonzini@redhat.com, natechancellor@gmail.com, ndesaulniers@google.com, qperret@google.com, will@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kernel-team@android.com, stable@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Will Deacon 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 Signed-off-by: Marc Zyngier Tested-by: Quentin Perret Reviewed-by: Quentin Perret Cc: Marc Zyngier Cc: 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);