Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4048959pxb; Mon, 4 Oct 2021 16:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU5f1t2xtr+U215K8xeJGrAgk6EiVVTzJZgqFV66FiUtkKlwZcnZO8SAmuj2Ux1CapVVZt X-Received: by 2002:a17:902:aa90:b0:13e:2256:52c with SMTP id d16-20020a170902aa9000b0013e2256052cmr2073169plr.57.1633388983366; Mon, 04 Oct 2021 16:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633388983; cv=none; d=google.com; s=arc-20160816; b=UwYRJ5ED7KVV+P57NhQ9LqdZZ3rgI9DDRZqdZ6FZwz24aWcH5IFoMYVtfJma5YUEM2 nkIyU7OkiUyuKAN8BHw+b54zmiEIPeeIBV8/zibv476OfkjzBmB4zCZ5EL+gxw2N4O/1 GdaZPgQBXloYErh5gtQwz7pROrb6hxL4l1fkOez2wtAxHr/94SKDo45l72O7bEOaxYAi h5c9ny0rqDvYxncVTb+sxp7WiDW7D+JSsR8Q//iph4gx0bIkuYwqQMpPUCy6nOH5RfmA IYbVBN400MTWuHfjty61kWBqbNfyX/pMY+m69skZGT9IEiSbcZbLTWTNx6/xss1yRga5 vRCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2YD4IL94ZMt8n0E1nwwjjVE/c9+TuPYNIYJTa/op9Q8=; b=vrKtZtMkE12y0b5eWTTbq/Tfv9PHalPDPOKC/eteNmZIt4Iiposhw15BmPiTq4De6Y WVARkkVo72pAvIAkq/EKAYrlujXSrkD4fQBCz/pEpM1V+5dLkrjUyNix0G6wakPIOc0M EXCWGcMz3EAnY+E2yXH5XH4cRQsP543mjahPvneQaO3Q5K/aoXJPNgTsgl6froRuqQZ8 5dzIDHaans5j6AWWSPw8c4p4UNM4Hxldg82mSqSYgdV4wJMbpyyUZeInqyXqjIUyCDAp 0UJr+jGaN5ln6nv++eVVJNQINN6hBAddkAzU1Nz7iSrCL1s0bCrW7RUtSlxWVWpknP9I VX3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c140si19664435pfb.379.2021.10.04.16.09.30; Mon, 04 Oct 2021 16:09:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236155AbhJDRvD (ORCPT + 99 others); Mon, 4 Oct 2021 13:51:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235305AbhJDRuu (ORCPT ); Mon, 4 Oct 2021 13:50:50 -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 4FEC061207; Mon, 4 Oct 2021 17:49:01 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mXS5D-00EhBv-Mm; Mon, 04 Oct 2021 18:48:59 +0100 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, qperret@google.com, dbrazdil@google.com, Steven Price , Andrew Jones , Fuad Tabba , Srivatsa Vaddagiri , Shanker R Donthineni , James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: [PATCH v2 02/16] KVM: arm64: Check for PTE valitity when checking for executable/cacheable Date: Mon, 4 Oct 2021 18:48:35 +0100 Message-Id: <20211004174849.2831548-3-maz@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211004174849.2831548-1-maz@kernel.org> References: <20211004174849.2831548-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, will@kernel.org, qperret@google.com, dbrazdil@google.com, steven.price@arm.com, drjones@redhat.com, tabba@google.com, vatsa@codeaurora.org, sdonthineni@nvidia.com, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Don't blindly assume that the PTE is valid when checking whether it describes an executable or cacheable mapping. This makes sure that we don't issue CMOs for invalid mappings. Suggested-by: Will Deacon Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/pgtable.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index f8ceebe4982e..6bbfd952f0c5 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -638,12 +638,12 @@ static void stage2_put_pte(kvm_pte_t *ptep, struct kvm_s2_mmu *mmu, u64 addr, static bool stage2_pte_cacheable(struct kvm_pgtable *pgt, kvm_pte_t pte) { u64 memattr = pte & KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR; - return memattr == KVM_S2_MEMATTR(pgt, NORMAL); + return kvm_pte_valid(pte) && memattr == KVM_S2_MEMATTR(pgt, NORMAL); } static bool stage2_pte_executable(kvm_pte_t pte) { - return !(pte & KVM_PTE_LEAF_ATTR_HI_S2_XN); + return kvm_pte_valid(pte) && !(pte & KVM_PTE_LEAF_ATTR_HI_S2_XN); } static bool stage2_leaf_mapping_allowed(u64 addr, u64 end, u32 level, @@ -688,8 +688,7 @@ static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level, /* Perform CMOs before installation of the guest stage-2 PTE */ if (mm_ops->dcache_clean_inval_poc && stage2_pte_cacheable(pgt, new)) mm_ops->dcache_clean_inval_poc(kvm_pte_follow(new, mm_ops), - granule); - + granule); if (mm_ops->icache_inval_pou && stage2_pte_executable(new)) mm_ops->icache_inval_pou(kvm_pte_follow(new, mm_ops), granule); @@ -1091,7 +1090,7 @@ static int stage2_flush_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, kvm_pte_t pte = *ptep; kvm_pte_t *pte_follow; - if (!kvm_pte_valid(pte) || !stage2_pte_cacheable(pgt, pte)) + if (!stage2_pte_cacheable(pgt, pte)) return 0; pte_follow = kvm_pte_follow(pte, mm_ops); -- 2.30.2