Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4067155pxb; Tue, 17 Nov 2020 10:21:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7wMPgJ98eyZ/Y4o846FqvbSWK86qN0aumrjEl4rWr/Yw0ExD/3jifw6AzqHfXhbVB5NXt X-Received: by 2002:a17:907:1112:: with SMTP id qu18mr20873456ejb.507.1605637273128; Tue, 17 Nov 2020 10:21:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605637273; cv=none; d=google.com; s=arc-20160816; b=y3PJTrkzymhCfMGnhchUTVvmSIU9rNdcC29zQ72bm9lu/DSqUx7vQ68uzD80+SJjtj onX/fYmcexbw6jFxop2OehgZDNHmMqJy42tnSk9jMafj8xZJMbHsHJnw6SSVGIBBeT/3 as2NUE75Y0Gj4FkXG+PlI61+6uGiWhRT5NkPDiJDqYB89DGnl2RNXbsSXhBy4gg1Q7m8 Vw7rKfFYODrBMS0co0y/DSkIiOycKnHWeR83IjEtwnfSU0ZdN1d3JVD9W5qI3eoGYpHq cd9JmeK2NVM64GeDfTIlRm6hVyLg40kF5n0CPsDHlbya05UGxJN5hFdvdzWl7Ls4lnNF AnoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=e9MvRELompdcQ9+x82O89Ri9iXp7qNvrmx/wGARfLl4=; b=0910XGguH/QXMNPBFVWJjotUu1mouUh6UBWPRw9nP9J69xaJ+AV+HLkz18kTgCl+0e pja5u+qNs6+pFSZe1aOVOkbPcac2m6CPNozBdRWCLd6PNnFut0tGx3Cu9kxEa0blw0z4 JITHoN2N7OgzyXiSYtlZyjVUdvk/EHZ9ZMxl0BMgZKPzoD+ArMIoXQo2+e8JlzG4AUko SkIyaMBscAzL1WTsNF1jEQ/ScigbTe1dS5je1o44mylABW5OO8vtUGBrX0xlhOxMXULz TzeFgx9mnHH15ccBjqwHlzPLk0MUIaXNgTJ5hmQUGNlHjl+El7JKQmSMmi2FqO4DY9X5 cmpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GrNemWJ5; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gg12si13875019ejb.395.2020.11.17.10.20.47; Tue, 17 Nov 2020 10:21:13 -0800 (PST) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=GrNemWJ5; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731082AbgKQSRR (ORCPT + 99 others); Tue, 17 Nov 2020 13:17:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731060AbgKQSRO (ORCPT ); Tue, 17 Nov 2020 13:17:14 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B9E2C0613CF for ; Tue, 17 Nov 2020 10:17:14 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id e15so1906612wme.4 for ; Tue, 17 Nov 2020 10:17:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=e9MvRELompdcQ9+x82O89Ri9iXp7qNvrmx/wGARfLl4=; b=GrNemWJ571s3IP05lzCIf+o9mQWG20WSzj1XWIbqs4BH51p4FibpD+1iIudjxdsldY VTOoE+KKuVVeeDxGnJBQ6qpGvS4olzVpA4h2kHUJdYePK03MTWF1sVNn29wYr8jCqsP1 zfnuBAtCdwfY4dVJuW13O2zHGn/wvP8TJd+7Gv88DeaAnl6Vr0lt8jupKQCVqBMY6LJu UuVkqgukfwDXxkwuFocX4twgxviyx3guAteMin0WGg+8TngA8wcruUWGUCFFyFlGLDAH GgrgZwJ5cpl+PeisJnHcFbNvplQ+JU+cK6fr/J2jY7HohI0LpW8XQQFBmZ0pMJ5mGWt9 sFyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=e9MvRELompdcQ9+x82O89Ri9iXp7qNvrmx/wGARfLl4=; b=NfR4YjalUf6TA53VAFH3kDUTA21PuS/xc2oCGWVUGaEwUfEPLTkoVI/htbIFBYEST7 cz0NaHaiLNB9EHh7IzZTdDVpY/E87mEJh4GzEmHfajGEt4HaPzLWa2oZ5JVSZ1D2hD8z WFfYvxi1rqpIQH5jhqrTnli/nY1ttfK07XzYN5BIVyJrrKyhfkRcJptA3B/oWW4N4yxd 27fAi7yD58+1Fv/FnesK3Xa9ApXvzuYuSClWZwb0iO/Fase48voQoX4oBy2l0qf9BCt+ jS4246o1BSdSOQH6wrlmOoDhjUab3eScyp/RJBjQT1mufR8/lBerC2thexAMVXGAeo+D 0IGg== X-Gm-Message-State: AOAM531xZGfogKrmPajMIV6tHeRgWfwWH7xkAFlmsL5mcvze9GrK2744 v4i3JoQkdmrtiSG/DePDbjF9IDEOm0k9 Sender: "qperret via sendgmr" X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) (user=qperret job=sendgmr) by 2002:a1c:6405:: with SMTP id y5mr376392wmb.150.1605637032528; Tue, 17 Nov 2020 10:17:12 -0800 (PST) Date: Tue, 17 Nov 2020 18:16:03 +0000 In-Reply-To: <20201117181607.1761516-1-qperret@google.com> Message-Id: <20201117181607.1761516-24-qperret@google.com> Mime-Version: 1.0 References: <20201117181607.1761516-1-qperret@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [RFC PATCH 23/27] KVM: arm64: Refactor __populate_fault_info() From: Quentin Perret To: Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand Cc: "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , open list , "open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" , kernel-team@android.com, android-kvm@google.com, Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor __populate_fault_info() to introduce __get_fault_info() which will be used once the host is wrapped in a stage 2. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/hyp/switch.h | 36 +++++++++++++++---------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index 84473574c2e7..e9005255d639 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -157,19 +157,9 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar) return true; } -static inline bool __populate_fault_info(struct kvm_vcpu *vcpu) +static inline bool __get_fault_info(u64 esr, u64 *far, u64 *hpfar) { - u8 ec; - u64 esr; - u64 hpfar, far; - - esr = vcpu->arch.fault.esr_el2; - ec = ESR_ELx_EC(esr); - - if (ec != ESR_ELx_EC_DABT_LOW && ec != ESR_ELx_EC_IABT_LOW) - return true; - - far = read_sysreg_el2(SYS_FAR); + *far = read_sysreg_el2(SYS_FAR); /* * The HPFAR can be invalid if the stage 2 fault did not @@ -185,12 +175,30 @@ static inline bool __populate_fault_info(struct kvm_vcpu *vcpu) 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)) + if (!__translate_far_to_hpfar(*far, hpfar)) return false; } else { - hpfar = read_sysreg(hpfar_el2); + *hpfar = read_sysreg(hpfar_el2); } + return true; +} + +static inline bool __populate_fault_info(struct kvm_vcpu *vcpu) +{ + u8 ec; + u64 esr; + u64 hpfar, far; + + esr = vcpu->arch.fault.esr_el2; + ec = ESR_ELx_EC(esr); + + if (ec != ESR_ELx_EC_DABT_LOW && ec != ESR_ELx_EC_IABT_LOW) + return true; + + if (!__get_fault_info(esr, &far, &hpfar)) + return false; + vcpu->arch.fault.far_el2 = far; vcpu->arch.fault.hpfar_el2 = hpfar; return true; -- 2.29.2.299.gdc1121823c-goog