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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28206C06510 for ; Tue, 2 Jul 2019 12:54:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id F0FAB208C4 for ; Tue, 2 Jul 2019 12:54:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ovYwgswu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0FAB208C4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rcpQ4vqSLCOQz5R4XKYUNxTrlOyIG1WgvxdmafcPxb0=; b=ovYwgswutSBiwp wPnpHGuTtU0vMEIaseAz8PmguPrWWwfw/LJgFCyzhd8ZAEoSgn8ldKa/uq1LsMGeNuKAaMe0zSvJv N+R74db5RShIDDLjha/QeBs0411djoY9OlvmP9RPIlRwWm3Ib86ltl6a/XyxugfP10qCacjrXfUJM xBtSXnPJAjF4f8bmWLeZFaDfYu7l6vORh8LmREkR4ZdTffePvcjsntYRf6AzjhD53Yoa8+0JVS62M s36B5evRuN5uJ+s3j1y2O0EeWngbqlmzwl1CdWDKn/LRFkPf7PsMOZpWCS89ajtYWOcAGHP2bQ2Zc Fgkn1Ck/0CeMqaUIXo8Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiIJ0-0007Vd-SX; Tue, 02 Jul 2019 12:54:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiIIx-0007Uu-LW for linux-arm-kernel@lists.infradead.org; Tue, 02 Jul 2019 12:54:41 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 86BF2344; Tue, 2 Jul 2019 05:54:38 -0700 (PDT) Received: from [10.1.31.185] (unknown [10.1.31.185]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5AB993F703; Tue, 2 Jul 2019 05:54:36 -0700 (PDT) Subject: Re: [PATCH 23/59] KVM: arm64: nv: Respect virtual HCR_EL2.TWX setting To: Julien Thierry , Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org References: <20190621093843.220980-1-marc.zyngier@arm.com> <20190621093843.220980-24-marc.zyngier@arm.com> <53793288-0d5d-4212-c1f4-ffa6a790d1c4@arm.com> From: Alexandru Elisei Message-ID: <1ba3a46e-d8cd-d6c9-c1dc-2fe9ad309497@arm.com> Date: Tue, 2 Jul 2019 13:54:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <53793288-0d5d-4212-c1f4-ffa6a790d1c4@arm.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_055439_801880_644493EE X-CRM114-Status: GOOD ( 21.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Suzuki K Poulose , Andre Przywara , Christoffer Dall , Dave Martin , James Morse , Jintack Lim Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 6/25/19 3:19 PM, Julien Thierry wrote: > > On 06/21/2019 10:38 AM, Marc Zyngier wrote: >> From: Jintack Lim >> >> 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 >> Signed-off-by: Marc Zyngier >> --- >> arch/arm64/include/asm/kvm_nested.h | 2 ++ >> arch/arm64/kvm/Makefile | 1 + >> arch/arm64/kvm/handle_exit.c | 13 +++++++++- >> arch/arm64/kvm/nested.c | 39 +++++++++++++++++++++++++++++ >> 4 files changed, 54 insertions(+), 1 deletion(-) >> create mode 100644 arch/arm64/kvm/nested.c >> >> diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h >> index 8a3d121a0b42..645e5e11b749 100644 >> --- a/arch/arm64/include/asm/kvm_nested.h >> +++ b/arch/arm64/include/asm/kvm_nested.h >> @@ -10,4 +10,6 @@ static inline bool nested_virt_in_use(const struct kvm_vcpu *vcpu) >> test_bit(KVM_ARM_VCPU_NESTED_VIRT, vcpu->arch.features); >> } >> >> +int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe); >> + >> #endif /* __ARM64_KVM_NESTED_H */ >> diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile >> index 9e450aea7db6..f11bd8b0d837 100644 >> --- a/arch/arm64/kvm/Makefile >> +++ b/arch/arm64/kvm/Makefile >> @@ -36,4 +36,5 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/irqchip.o >> kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o >> kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.o >> >> +kvm-$(CONFIG_KVM_ARM_HOST) += nested.o >> kvm-$(CONFIG_KVM_ARM_HOST) += emulate-nested.o >> diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c >> index e348c15c81bc..ddba212fd6ec 100644 >> --- a/arch/arm64/kvm/handle_exit.c >> +++ b/arch/arm64/kvm/handle_exit.c >> @@ -127,7 +127,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; > I think you can simplify this: > > if (ret != -EINVAL) > return ret; And handle_wfx_nested can only return -EINVAL or 1 (from kvm_inject_nested_sync), so the condition is not only complicated, but also misleading. Thanks, Alex > > Cheers, > > Julien > > >> + } >> + >> + if (is_wfe) { >> trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true); >> vcpu->stat.wfe_exit_stat++; >> kvm_vcpu_on_spin(vcpu, vcpu_mode_priv(vcpu)); >> diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c >> new file mode 100644 >> index 000000000000..3872e3cf1691 >> --- /dev/null >> +++ b/arch/arm64/kvm/nested.c >> @@ -0,0 +1,39 @@ >> +/* >> + * Copyright (C) 2017 - Columbia University and Linaro Ltd. >> + * Author: Jintack Lim >> + * >> + * This program is free software; you can redistribute it and/or modify >> + * it under the terms of the GNU General Public License version 2 as >> + * published by the Free Software Foundation. >> + * >> + * This program is distributed in the hope that it will be useful, >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> + * GNU General Public License for more details. >> + * >> + * You should have received a copy of the GNU General Public License >> + * along with this program. If not, see . >> + */ >> + >> +#include >> +#include >> + >> +#include >> + >> +/* >> + * 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; >> +} >> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel