From patchwork Mon Mar 23 11:32:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beata Michalska X-Patchwork-Id: 184733 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3974680ile; Mon, 23 Mar 2020 04:33:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsgjSpaEpl1lP8Cuj2kHtcw4N7ufmJwgZafeDUVeHbLHbXzphZl3auzI16Youv8OEz1ns9g X-Received: by 2002:aed:2535:: with SMTP id v50mr21002289qtc.354.1584963198593; Mon, 23 Mar 2020 04:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584963198; cv=none; d=google.com; s=arc-20160816; b=jFOoeetWlgjjjQy0/lpup34cIsTgyWL3UfPzUvc7sKSt9+x9HtnjEH0wLmnX3822Kw Alpac3s9y7majVcm0v9xkY8rmmknmHevcrN0/Upu6nOOThfrtC0i2KyZkswxXeM8CDOb JQhq8WPfScSe0ucFZTFJdpb2TjZTCSwdzs8QO+dEh3ZmU4tyBBFJ+hPnQ1sIdcI6r3vw P+Wzv7FH/3a85c5qe3lvtIVhrDF/am3qPEnhxe2D4zlKF1DBFhVyj1RBKDPeWW2tvRyK 5fKtCuoe3FBW2rtPzwCFd+VhEZN3wHQM3aL6asxvDBQeV7JrHJtATonj28EE3nCAlPue aoZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=scdgVshz7sU0Fzpv5iTWYPRCzh314P+7l5wAJHlPMsk=; b=Kgn4wZGbDtXSMOqKucpap5CR4SBXzmRxJHbFgV7q1ynQkzEA/RjY1BmevAfb5uFpPT EHT6UBDzTMg8o32Fy4Q4hEeyGjiz43U/58aHgOUH6forGUWlAXwPETZF4s1eNGpq+v2b tMPPrsywPrRoG4bR3wq+kgtQ4Lm+0hLslOAX4+Ta+6jTpe0X02YevNg9o2SOy9R2tBag iFXK0+9vtXnArVE2mBPV7r8jferEwxOLT2dpGTcpi9ie9+KI4MjqN/bYj+eM7O0Pqk8X QlriAD3BWYbH37qRfsdqTYwQTaWf2NBwCiIhG8APbdQ3PI7cLpf74Bv2MVITDsY12+Kc RkXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="JLvAr/BL"; 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=fail (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 p12si8525249qtj.116.2020.03.23.04.33.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Mar 2020 04:33:18 -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=fail header.i=@linaro.org header.s=google header.b="JLvAr/BL"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGLKY-0001vv-0t for patch@linaro.org; Mon, 23 Mar 2020 07:33:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43021) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGLK4-0001RY-MO for qemu-devel@nongnu.org; Mon, 23 Mar 2020 07:32:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGLK3-0006wf-7S for qemu-devel@nongnu.org; Mon, 23 Mar 2020 07:32:48 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:51229) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGLK3-0006vp-0C for qemu-devel@nongnu.org; Mon, 23 Mar 2020 07:32:47 -0400 Received: by mail-wm1-x344.google.com with SMTP id c187so14236016wme.1 for ; Mon, 23 Mar 2020 04:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=scdgVshz7sU0Fzpv5iTWYPRCzh314P+7l5wAJHlPMsk=; b=JLvAr/BLfGkIUYDk0CdrGwqORp808GVmj/9LS6QzDIqOCdntGOzADShWL7NqnBoHmE y9D0qohsyh6Lh+QOYcEnJP3JfSmaRTaN3SaQKQ8JC/gzGza3aRvQFHayw+VQFVUNG8Be DEA2UA5WtVgEpMM8/pbvYq7H6tbTUwceliW4g4yGuPWddc/m1NfJ+GR8ih8Nl+Ff044y d1SANkvsxWEmBCPwcKwe4BFeDppIKLTOkzKtFtOvibWEscR7KVZmBNCuIfci0XYwK+9A WP32f6nfoIvNoxsxfhdYSqelcnl9nPhH/cHbCUPNCn2vLRCMdvRREZQF5JcW6FvhhVUa 071Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=scdgVshz7sU0Fzpv5iTWYPRCzh314P+7l5wAJHlPMsk=; b=D3jLwVTk3WcivgIypD1Hl/+gcctliOC8FEoSSFzUl5dcsjPUZTwirZ3otIfyn0AnHn Wk5SAB84i3u4JD0joDsJyzVV/4mfd+QNQVCQQSe8KhdfTRDbT+RQpUGfLyp62tFK6aP3 EAGVsAp25ZgAZZDk4mYj9LBdNmCrZscVIC109nhHlaMDdVlZNDQ41ZL/eo/pKpV3z2lu VOd8evWFSC+3pz167xx2CFLik3qRwh8JAZLtnS2MFqecIZKB358PCJ4Hz4ontTNWwNyo xh3i3aRJaZ5p9uzq03cU9u8POvmNG52gzf42u8J8SqYIefVNPppQRX2TtNjcbybaVOHw gRxA== X-Gm-Message-State: ANhLgQ3uBhqd0drusuopd/1gXuDEs+FVrmS4KDpjVyA+TV/HzUcJga1c oASA+NEmq5qVmk6kJmnXp6s1H2COko2C9g== X-Received: by 2002:a05:600c:1405:: with SMTP id g5mr12270544wmi.90.1584963165596; Mon, 23 Mar 2020 04:32:45 -0700 (PDT) Received: from moi-limbo-9350.home (host86-177-220-180.range86-177.btcentralplus.com. [86.177.220.180]) by smtp.gmail.com with ESMTPSA id 98sm23288473wrk.52.2020.03.23.04.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 04:32:45 -0700 (PDT) From: Beata Michalska To: qemu-devel@nongnu.org Subject: [PATCH v4 1/2] target/arm: kvm: Handle DABT with no valid ISS Date: Mon, 23 Mar 2020 11:32:26 +0000 Message-Id: <20200323113227.3169-2-beata.michalska@linaro.org> In-Reply-To: <20200323113227.3169-1-beata.michalska@linaro.org> References: <20200323113227.3169-1-beata.michalska@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 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: , Cc: peter.maydell@linaro.org, drjones@redhat.com, Christoffer.Dall@arm.com, qemu-arm@nongnu.org, pbonzini@redhat.com, kvmarm@lists.cs.columbia.edu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- target/arm/cpu.h | 2 ++ target/arm/kvm.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ target/arm/kvm_arm.h | 11 +++++++++++ 3 files changed, 67 insertions(+) -- 2.7.4 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 4ffd991..4f834c1 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -560,6 +560,8 @@ typedef struct CPUARMState { uint64_t esr; } serror; + uint8_t ext_dabt_pending; /* Request for injecting ext DABT */ + /* State of our input IRQ/FIQ/VIRQ/VFIQ lines */ uint32_t irq_line_state; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 85860e6..c088589 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; @@ -244,6 +245,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)) { + warn_report("Failed to enable DABT NISV 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; } @@ -703,9 +714,16 @@ int kvm_put_vcpu_events(ARMCPU *cpu) events.exception.serror_esr = env->serror.esr; } + if (cap_has_inject_ext_dabt) { + events.exception.ext_dabt_pending = env->ext_dabt_pending; + } + ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, &events); if (ret) { error_report("failed to put vcpu events"); + } else { + /* Clear instantly if the call was successful */ + env->ext_dabt_pending = 0; } return ret; @@ -819,6 +837,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); @@ -953,3 +976,34 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { return (data - 32) & 0xffff; } + +int kvm_arm_handle_dabt_nisv(CPUState *cs, uint64_t esr_iss, + uint64_t fault_ipa) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + + /* + * ISS [23:14] is invalid so there is a limited info + * on what has just happened so the only *useful* thing that can + * be retrieved from ISS is WnR & DFSC (though in some cases WnR + * might be less of a value as well) + */ + + /* + * Set pending ext dabt and trigger SET_EVENTS so that + * KVM can inject the abort + */ + if (cap_has_inject_ext_dabt) { + kvm_cpu_synchronize_state(cs); + env->ext_dabt_pending = 1; + } 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; + } + + return 0; +} diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index ae9e075..39472d5 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -450,6 +450,17 @@ struct kvm_guest_debug_arch; void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr); /** + * 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 synch data abort + * + * Returns: 0 if the exception has been handled, < 0 otherwise + */ +int kvm_arm_handle_dabt_nisv(CPUState *cs, uint64_t esr_iss, + uint64_t fault_ipa); +/** * its_class_name: * * Return the ITS class name to use depending on whether KVM acceleration