From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E776EC32771 for ; Tue, 27 Sep 2022 00:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :Mime-Version:Date:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=31UfL8SMAiw+DHwb26rNUSNGstjOv0s7VE9CTfU657A=; b=BoTiN2iQGSpPQi B64ECS7Wma4Vc2XVoRCchMSjGMx8Fzbz4+BPYTC6hj9zH4B/UFhStDw5A/XOW83oMCNyjoYi4vAOX xdWEt6/pxtc4NS2mR76hFeJY2ABVrntSc0r0bnurAFxNWaOdA8tzh1dW0OAjJIFetPx8Pwz8l/hvQ DtdSOAtULoRJ330lE+SfDVPMvjac8wFpxGdgH8SdG5dUxa0DPGo6RalSvnPLpJuuyIF5/tiwTb7C7 Xv8+MrM7QHZdPxp9fPaVF1jOBN9n2/cu8KS6QXWpo3gZKuZt9BuU2wVRKlDC8fi0NcBL/9ZehZKfk fZtAnYwtfXAcvHPGW+mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocyRZ-007WOY-D4; Tue, 27 Sep 2022 00:27:25 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocyRW-007WNv-E0 for linux-arm-kernel@lists.infradead.org; Tue, 27 Sep 2022 00:27:23 +0000 Received: by mail-pj1-x104a.google.com with SMTP id b10-20020a17090a12ca00b002034af352d0so3737806pjg.3 for ; Mon, 26 Sep 2022 17:27:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date; bh=9LlUllMuSCCNuvy8nXr0WUw6cjOfzqrjmVjCju9k9xE=; b=ib28nrR8JpjsrppII6G9v/dkNoieDbqAEGPjxFDDXpZ6X2dzYHAQgGQAGNeZsoN0E+ QivbBd1z3z72bEgc4ZrqGDiqM5n8tCaBCejTC384XUmG+MXYCSNsPSCMPasXavv9I9ju 7UxNYQXgwEHcdbOixKGvEN8J1at2ARMARli6/3VS5Vquhqwyf0HYlB/5vJ784LvBoNBt r0Ue8vNvTZXN6cpds0UdPc0Wjh7tN2e6knqL4lQQjuPByoh94Hfrp/pylM5QAgzvOgMi uPw2vyCKgVaO1z0v7Ynf3hRhgS3OJcG5bElgEhT0Y4BPuktbEk4Rdt7sJcnwJBSLPTZl VxLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date; bh=9LlUllMuSCCNuvy8nXr0WUw6cjOfzqrjmVjCju9k9xE=; b=SUs5iVhI8q7JG2tzElcq0oQ91wsx5cjcDuGD7MDLKa8Pfljy0b//sNBM11gBMzUuiu PNe8JgcXo/xpGiDuGI1MSmB4/SkMJ2IqN+OEMT2bAMSUN5S3HPwCEKioe7HkfweeGR/c hrzvN4vTZ4ZszuhPGOeCW6h3c8Y9dbcHrqPlmEYgvx7BjpR08ShdHsrw0FmCuvyP9LSL BWvpJWSgW+KHWBRFm9PlguD41WhdnmF53aGAiGpPMfCDRAv6GdqtujZ5Y3Q4Fyg91vnJ Eg6Qyo7aGfeNMWAkS0uMy8QgHFpkO72TnAfWbWo/xO0Xc+o8OTkHYs82mpj7GMjZpyKI gdUQ== X-Gm-Message-State: ACrzQf0TVgQYYIkOvyMK8k5X8eYXwqz9F73PznKEDc6Q5Zd4EpSCfq6l 3lsLZO/YjeCdNOpqiBPtowAZo1wmvmAI X-Google-Smtp-Source: AMsMyM7beut503w2dGOmNLcBHb2fmbJhHsJKZpriWBWPTuRptWckWaynxJFBeEmIGXr7bX7q5SvnLReY33W1 X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a05:6a00:1342:b0:545:4d30:eecb with SMTP id k2-20020a056a00134200b005454d30eecbmr25908814pfu.69.1664238440461; Mon, 26 Sep 2022 17:27:20 -0700 (PDT) Date: Tue, 27 Sep 2022 00:27:15 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog Message-ID: <20220927002715.2142353-1-mizhang@google.com> Subject: [PATCH] KVM: arm64: Cleanup the __get_fault_info() to take out the code that validates HPFAR From: Mingwei Zhang To: Marc Zyngier , Catalin Marinas , Will Deacon Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, Oliver Upton , Mingwei Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220926_172722_489395_2F9DD4AF X-CRM114-Status: GOOD ( 14.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Mingwei Zhang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Cleanup __get_fault_info() to take out the code that checks HPFAR. The conditions in __get_fault_info() that checks if HPFAR contains a valid IPA is slightly messy in that several conditions are written within one IF statement acrossing multiple lines and are connected with different logical operators. Among them, some conditions come from ARM Spec, while others come from CPU erratum. This makes the code hard to read and difficult to extend. So, cleanup the function to improve the readability. In particular, explicitly specify each condition separately within a newly created inline function. No functional changes are intended. Suggested-by: Oliver Upton Signed-off-by: Mingwei Zhang --- arch/arm64/kvm/hyp/include/hyp/fault.h | 36 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/fault.h b/arch/arm64/kvm/hyp/include/hyp/fault.h index 1b8a2dcd712f..4575500d26ff 100644 --- a/arch/arm64/kvm/hyp/include/hyp/fault.h +++ b/arch/arm64/kvm/hyp/include/hyp/fault.h @@ -41,12 +41,6 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar) return true; } -static inline bool __get_fault_info(u64 esr, struct kvm_vcpu_fault_info *fault) -{ - u64 hpfar, far; - - far = read_sysreg_el2(SYS_FAR); - /* * The HPFAR can be invalid if the stage 2 fault did not * happen during a stage 1 page table walk (the ESR_EL2.S1PTW @@ -58,14 +52,30 @@ static inline bool __get_fault_info(u64 esr, struct kvm_vcpu_fault_info *fault) * permission fault or the errata workaround is enabled, we * resolve the IPA using the AT instruction. */ - if (!(esr & ESR_ELx_S1PTW) && - (cpus_have_final_cap(ARM64_WORKAROUND_834220) || - (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) { - if (!__translate_far_to_hpfar(far, &hpfar)) - return false; - } else { +static inline bool __hpfar_is_valid(u64 esr) +{ + if (esr & ESR_ELx_S1PTW) + return true; + + if ((esr & ESR_ELx_FSC_TYPE) == FSC_PERM) + return false; + + if (cpus_have_final_cap(ARM64_WORKAROUND_834220)) + return false; + + return true; +} + +static inline bool __get_fault_info(u64 esr, struct kvm_vcpu_fault_info *fault) +{ + u64 hpfar, far; + + far = read_sysreg_el2(SYS_FAR); + + if (!__hpfar_is_valid(esr) && !__translate_far_to_hpfar(far, &hpfar)) + return false; + else hpfar = read_sysreg(hpfar_el2); - } fault->far_el2 = far; fault->hpfar_el2 = hpfar; base-commit: c59fb127583869350256656b7ed848c398bef879 -- 2.37.3.998.g577e59143f-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel