From patchwork Fri Jul 3 16:53:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 231235 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2562371ilg; Fri, 3 Jul 2020 09:59:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKIaVmqSCHX1OtYu47Pj7bhHUJf0JSZyHAvpbL7XHymTQWV/Pu+7Ex0vFkpb9zXiJcwcBT X-Received: by 2002:a25:684a:: with SMTP id d71mr1528552ybc.68.1593795572705; Fri, 03 Jul 2020 09:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593795572; cv=none; d=google.com; s=arc-20160816; b=tlP0JAIQy1rIPNg0/AZoV3h4KHYD8z8u2wIt1gv7+eymZxSzODolNrXlDIu4fgCAP1 TAk7RWkP0d38AyT6Os2b2G9e9tbia3H4gMEyurhy7a61qANmBeYwLLDRWrNNvgTsryls 758JBqhe1a8rCJTvmpqJERAlQAG5h+l8yQq5gOD0ioRpFx+e7MO2Hhyq57G5W/f1yqMN fk/04f8K1Ab003JAre0yCxuda1xNFjjYGfIxzs4tIPZy2tlQ63a6oGxt5rjXPzY0uecH i6cbzcX1m5zyHnyoT16lYMPdYCUihPkAB/JPj69pbKPyaZH34S9VvnsggLkA9Zl6rljk ZKtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=BP6j/3HoxCBLJuDgMNnWxb3Xu4bxKE76bxnjKGSc4hg=; b=g8A6GY78rfANPm/JWMiXE9NoyDpo4PGSoNRc43GcYkX9u+cIUiTUXVyYKcc8Ve3nAe MTCOoZaEiX7mYv6jjI3N8SBbPsD5z8rJ5/07NPRN0IH1ditRgRhWMwiw0zSvozZKXKOG T0Uezh6iEcA9C1EAzfBoIfJrBnPrGiRERbvnF3moJiuleoRbHq799EBbH7YauNHHIiMw 6pOMtw0ztB0uNhIfSjoiuaZ8JQxG/+uQJfvLj1xh4wg26v0TOoqqbc2uKVLGRtXgDm5Z p9FrYkNZFH3oSLTAIDP2H2zbucVK3UFrxsJfw9pmKB3BJsPsjZBRicSXhzu1CjE4ataT ArvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kJut4Eo5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e1si12964933ybp.19.2020.07.03.09.59.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Jul 2020 09:59:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kJut4Eo5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrP2C-0005GB-4Z for patch@linaro.org; Fri, 03 Jul 2020 12:59:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrOxA-0004hH-OB for qemu-devel@nongnu.org; Fri, 03 Jul 2020 12:54:20 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:37257) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jrOx8-0005fP-SN for qemu-devel@nongnu.org; Fri, 03 Jul 2020 12:54:20 -0400 Received: by mail-wr1-x444.google.com with SMTP id a6so33423178wrm.4 for ; Fri, 03 Jul 2020 09:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BP6j/3HoxCBLJuDgMNnWxb3Xu4bxKE76bxnjKGSc4hg=; b=kJut4Eo5SHspIxgjriUq994rVvP3dM7w9x9sDGSehnrSs6GJ57odYtCKBIjLcMntCR SoDGx66UGDCT3K0E6G6uNfep+t+d/osNBDg6JQv6DLYWKEdjawR1ralR4y2BT4d7hNfV aj+NATFOG6knQExuN/V2AL41cwJ0Wy4wHceqecdjvTiH+b9X7v8VpdkVjkeYqg7eaUza Vg2WEv6Y0oRlKnHNR8bVx4bDCzm9vM7Ifl+kMgWXZ+26WsAcHFdsVQ00OAaIpo1Bsimf PNwV6o+nTNg28PL8APVZky4n3UevdMDc6/nQRReuwvT6wH3pj9FCImzb6VuoXO2z6v7B N2hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BP6j/3HoxCBLJuDgMNnWxb3Xu4bxKE76bxnjKGSc4hg=; b=QXESOhWpnbGKkgbu0kk3SHyQjOzsTi6uCLU2N/UjeU3eQvsfpndc0s+/LXIQiffP+5 uDRx03LvpBAqoWPwKH+/uQzsj0lAUGIbosfyqgfdRlTez/Btg+i8Dzb82TF40jwhA+hc f8fzQxOFQBGyahESieeccikc8qqTWQGzOuq6UvnUAAVtMmCGWbspXPJ5YQSpZOnX6tNp yVrZDdECdz+VL8pm/Y/pIIuW1eBJ7BEhvBE8z5rwovZg2+ZKFfkyM+FjX9gca/qkX5BH gdTtaUmyRoKhNSqm9FwnBYYyIGy6soJmYec7dFXSeBg9PojhW4iXkREXWNXwMUtwmDmX c0BQ== X-Gm-Message-State: AOAM530QmuTd7Bt8Fc1e/A9T4hpdw5+jEcQxUjqIpb8G0ezAVAynpFii Z/2zt1zlJKXp2zv2yJZs8a1dQoAUyN4HxQ== X-Received: by 2002:a5d:4b0f:: with SMTP id v15mr2685265wrq.216.1593795257154; Fri, 03 Jul 2020 09:54:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id j15sm5574224wrx.69.2020.07.03.09.54.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 09:54:16 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 09/34] target/arm: kvm: Handle DABT with no valid ISS Date: Fri, 3 Jul 2020 17:53:40 +0100 Message-Id: <20200703165405.17672-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200703165405.17672-1-peter.maydell@linaro.org> References: <20200703165405.17672-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Beata Michalska On ARMv7 & ARMv8 some load/store instructions might trigger a data abort exception with no valid ISS info to be decoded. The lack of decode info makes it at least tricky to emulate those instruction which is one of the (many) reasons why KVM will not even try to do so. Add support for handling those by requesting KVM to inject external dabt into the quest. Signed-off-by: Beata Michalska Reviewed-by: Andrew Jones Message-id: 20200629114110.30723-2-beata.michalska@linaro.org Signed-off-by: Peter Maydell --- target/arm/kvm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) -- 2.20.1 diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 7c672c78b88..3a46f54f1fd 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -39,6 +39,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { static bool cap_has_mp_state; static bool cap_has_inject_serror_esr; +static bool cap_has_inject_ext_dabt; static ARMHostCPUFeatures arm_host_cpu_features; @@ -245,6 +246,16 @@ int kvm_arch_init(MachineState *ms, KVMState *s) ret = -EINVAL; } + if (kvm_check_extension(s, KVM_CAP_ARM_NISV_TO_USER)) { + if (kvm_vm_enable_cap(s, KVM_CAP_ARM_NISV_TO_USER, 0)) { + error_report("Failed to enable KVM_CAP_ARM_NISV_TO_USER cap"); + } else { + /* Set status for supporting the external dabt injection */ + cap_has_inject_ext_dabt = kvm_check_extension(s, + KVM_CAP_ARM_INJECT_EXT_DABT); + } + } + return ret; } @@ -810,6 +821,42 @@ void kvm_arm_vm_state_change(void *opaque, int running, RunState state) } } +/** + * kvm_arm_handle_dabt_nisv: + * @cs: CPUState + * @esr_iss: ISS encoding (limited) for the exception from Data Abort + * ISV bit set to '0b0' -> no valid instruction syndrome + * @fault_ipa: faulting address for the synchronous data abort + * + * Returns: 0 if the exception has been handled, < 0 otherwise + */ +static int kvm_arm_handle_dabt_nisv(CPUState *cs, uint64_t esr_iss, + uint64_t fault_ipa) +{ + /* + * Request KVM to inject the external data abort into the guest + */ + if (cap_has_inject_ext_dabt) { + struct kvm_vcpu_events events = { }; + /* + * The external data abort event will be handled immediately by KVM + * using the address fault that triggered the exit on given VCPU. + * Requesting injection of the external data abort does not rely + * on any other VCPU state. Therefore, in this particular case, the VCPU + * synchronization can be exceptionally skipped. + */ + events.exception.ext_dabt_pending = 1; + /* KVM_CAP_ARM_INJECT_EXT_DABT implies KVM_CAP_VCPU_EVENTS */ + return kvm_vcpu_ioctl(cs, KVM_SET_VCPU_EVENTS, &events); + } else { + error_report("Data abort exception triggered by guest memory access " + "at physical address: 0x" TARGET_FMT_lx, + (target_ulong)fault_ipa); + error_printf("KVM unable to emulate faulting instruction.\n"); + } + return -1; +} + int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) { int ret = 0; @@ -820,6 +867,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret = EXCP_DEBUG; } /* otherwise return to guest */ break; + case KVM_EXIT_ARM_NISV: + /* External DABT with no valid iss to decode */ + ret = kvm_arm_handle_dabt_nisv(cs, run->arm_nisv.esr_iss, + run->arm_nisv.fault_ipa); + break; default: qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", __func__, run->exit_reason);