From patchwork Tue Jul 18 16:58:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 108164 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp6155627obm; Tue, 18 Jul 2017 10:05:52 -0700 (PDT) X-Received: by 10.99.145.67 with SMTP id l64mr2793267pge.184.1500397552911; Tue, 18 Jul 2017 10:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500397552; cv=none; d=google.com; s=arc-20160816; b=jbSrr52Fn12KJJWQHt+862EOQZfwXRjtmWkB6pXL4vp4q8B6BKthuvgUalfnI/3N00 ES3v3EUV79UK+mCbVw2UTM2icEbK5/fmnhgCEIaWQO9GxEPgzAXCrTGVEcggh2g1Q5Zf BKLEhN3yZgkdCZMgqhohfK3C4he/DGQ2kJfxmWHgzUaY0iy/OfnnV3A2QZhETIlPTjs1 /JxblY27YuTVHE9TRqq472s1Iuuvi71Dfpe+r0MqVfo6LJHw8emsMiGF9QfzYmvuoxc0 DizMMby3eUoVBaSuznybuKqbOXzpzz0BjbufQHeYcVxY6zGx09S/F2/prfrWyzh0HuSD e+tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=r0TbfSmYolF1B4i1TJyduZHKE3K6Ho915piO3zAsk4U=; b=CmR3yHsiarhRVPCMMNX3xCjyXtCMS6+hoTnVvnIsc5BuxAx7YV00qdcVSc0i9HBoRM AKbK1MFlFYNQTTiMqvcpdVF+nyndAs6m5EU66Wqi+DCacSHPmRNhKqyxhFz0puHffshA gukPPH5nIJ6nD06HgbY12Z7k0YefNoUyuYsrYGHAo+ruoriicMNqOiS+8jtI5bCeUi6Q qIMlpVtPDgmL4jrzj1BFV4M54yzDov9TE7e39tHwjA6aZgG1waey4oOwvRw4AUbkoy6X ZwHqnsTUwmYbxy0nP6t9x6e/oA/M1i49QCvA4M4MlQMrWtoI29ZDy9lQMz4CySRUO77G 11LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=UqW2AHGG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9si229805pfb.420.2017.07.18.10.05.52; Tue, 18 Jul 2017 10:05:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=UqW2AHGG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752496AbdGRRFW (ORCPT + 25 others); Tue, 18 Jul 2017 13:05:22 -0400 Received: from mail-io0-f175.google.com ([209.85.223.175]:36469 "EHLO mail-io0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752271AbdGRRAS (ORCPT ); Tue, 18 Jul 2017 13:00:18 -0400 Received: by mail-io0-f175.google.com with SMTP id z62so17074507ioi.3 for ; Tue, 18 Jul 2017 10:00:17 -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=r0TbfSmYolF1B4i1TJyduZHKE3K6Ho915piO3zAsk4U=; b=UqW2AHGGRcS6rePAkcbLlKlh0PP97sHbXKisbJo9y9K1HxGQTTRgcavcjg0K7pxu2F vG2aQbLj4CLR9Z0cRyvYkIXm6s/mZb2C0SjvHjs3OZMqB/B22jbAPFIJsaQw7d5Yez5/ 2GbptrxjIJX9q44TjTkCf3RJZcDyXl51gAqEs= 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=r0TbfSmYolF1B4i1TJyduZHKE3K6Ho915piO3zAsk4U=; b=H8zP//u5qfDp9UhjW6iSIV5X6d5hSYWWdaKH+Sp+oQYQPEMiZ4VKcw1Slg17bxt9oV Kz3TGuzbtXhnl8uByTI3SycJmOsg8jEXLaZ8cPV12VRqarv2/+5vuB1AGDQrSXBevVFM 6ltt7xPCXNTCdc1FsksqcmExer79CW7LC/SxQCCbRSUNTMSs01ATW/aBCbAh8Y7C7omx lmHZBiQUCCwFbCXnNgr+oLkIN5HWMFhHoY93FcefTXAU7EFLgoYv2qA7WgR0O3uUZpnN MijNU3Rw6S4bxQTA/V/1gYNv2XFZ5J9fKo+JVkowwT/1wRMPSONw7jEkeV+8JrVUJnma FpwQ== X-Gm-Message-State: AIVw112fClaJQ1nmJekX/QS9hs3e6od2ueEFUaffzmavy5xbrCItHBa/ +CbjwtkGha4S302P X-Received: by 10.107.160.132 with SMTP id j126mr2515157ioe.224.1500397216290; Tue, 18 Jul 2017 10:00:16 -0700 (PDT) Received: from node.jintackl-qv26972.kvmarm-pg0.wisc.cloudlab.us (c220g1-030822.wisc.cloudlab.us. [128.104.222.82]) by smtp.gmail.com with ESMTPSA id j96sm1413075ioo.49.2017.07.18.10.00.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:15 -0700 (PDT) From: Jintack Lim To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: corbet@lwn.net, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, mchehab@kernel.org, cov@codeaurora.org, daniel.lezcano@linaro.org, david.daney@cavium.com, mark.rutland@arm.com, suzuki.poulose@arm.com, stefan@hello-penguin.com, andy.gross@linaro.org, wcohen@redhat.com, ard.biesheuvel@linaro.org, shankerd@codeaurora.org, vladimir.murzin@arm.com, james.morse@arm.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jintack Lim Subject: [RFC PATCH v2 24/38] KVM: arm64: Respect virtual HCR_EL2.TWX setting Date: Tue, 18 Jul 2017 11:58:50 -0500 Message-Id: <1500397144-16232-25-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> References: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Forward exceptions due to WFI or WFE instructions to the virtual EL2 if they are not coming from the virtual EL2 and virtual HCR_EL2.TWX is set. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/handle_exit.c | 13 ++++++++++++- arch/arm64/kvm/nested.c | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 46880c3..53b0b33 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -442,5 +442,6 @@ static inline void __cpu_init_stage2(void) int __init kvmarm_nested_cfg(char *buf); int init_nested_virt(void); bool nested_virt_in_use(struct kvm_vcpu *vcpu); +int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe); #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 8b398b2..25ec824 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -107,7 +107,18 @@ static int handle_no_fpsimd(struct kvm_vcpu *vcpu, struct kvm_run *run) */ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run) { - if (kvm_vcpu_get_hsr(vcpu) & ESR_ELx_WFx_ISS_WFE) { + bool is_wfe = !!(kvm_vcpu_get_hsr(vcpu) & ESR_ELx_WFx_ISS_WFE); + + if (nested_virt_in_use(vcpu)) { + int ret = handle_wfx_nested(vcpu, is_wfe); + + if (ret < 0 && ret != -EINVAL) + return ret; + else if (ret >= 0) + return ret; + } + + if (is_wfe) { trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true); vcpu->stat.wfe_exit_stat++; kvm_vcpu_on_spin(vcpu); diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index 9a05c76..042d304 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -18,6 +18,8 @@ #include #include +#include + static bool nested_param; int __init kvmarm_nested_cfg(char *buf) @@ -41,3 +43,21 @@ bool nested_virt_in_use(struct kvm_vcpu *vcpu) return false; } + +/* + * Inject wfx to the virtual EL2 if this is not from the virtual EL2 and + * the virtual HCR_EL2.TWX is set. Otherwise, let the host hypervisor + * handle this. + */ +int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe) +{ + u64 hcr_el2 = vcpu_sys_reg(vcpu, HCR_EL2); + + if (vcpu_mode_el2(vcpu)) + return -EINVAL; + + if ((is_wfe && (hcr_el2 & HCR_TWE)) || (!is_wfe && (hcr_el2 & HCR_TWI))) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + + return -EINVAL; +}