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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 82922C4338F for ; Thu, 12 Aug 2021 13:11:47 +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 3855D61059 for ; Thu, 12 Aug 2021 13:11:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3855D61059 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=agjuIajRjMwHd3ek8dHJKygd1wTnc4E+V3NZ/O0J+uE=; b=UHb1Ugz5wcfk/Y d1Y7Bj6ZE9Q1m16Lo8g5TcPWi3V6FzDz56QeLXTkbI5rvPFAu7oco7odPhSATajuJki7YPcp1UIpS NGBmKKGSSUSDOEZfOriHZgWWIU2cUssjkApNm3Xjo3aKfd8h0vzXMB084Zp2AVCJx8x7lpf/vt8w2 ecMsMAjJtLYubDQwajJ0BtbPS4RRjDDaUeTKfS48bma1hQ1JU7GuRV6PKtlDjhkqQpJDFUXC3N15M fqNwNmQnPBtE6j5rSVccd3MjQbe3e1ePivKLCwnwqvBy5N8yyRseDJO0kWEeODLbVMJqu+dkwpuKE Nejw5eeo60a2CrbPBzPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mEASW-00A71X-AL; Thu, 12 Aug 2021 13:09:20 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mEASP-00A70Z-WB for linux-arm-kernel@lists.infradead.org; Thu, 12 Aug 2021 13:09:18 +0000 Received: by mail-ot1-x333.google.com with SMTP id c23-20020a0568301af7b029050cd611fb72so7640911otd.3 for ; Thu, 12 Aug 2021 06:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WRqzbWQ5nIKrt8ACxqIhdjGTjjV3XNEnx9RLXFnLp9U=; b=af9F5gG94wT94ta0EmdCDZ8PMu/JYSODDydH43su3PYUH4Z+npHCVd+twnuabLyLNV AIRifFs11BXjl7YazhGbXPfY4lNp4+/FEqPxhzIGR0b3jyb4NHjP7kUl0QOJ/VbDYSCB zNvXzIbE8H6Z1AG4SI7PCxZR0ffFQ77Cz11R/oC77w/C3MuMlI+IVT+jryt6r3kbgt03 UeVzl+KGq4v/L8c0z7v3ETQ1rM0re5bwSmmKhOrdWFpgq+zjfmf0rwokthr5pRl130jX oLOOYQm4tbe896knjGw2NJTQSh1bNrKbUMtFmPczK4ih0DP8ZsNDXMkHcnAvjd5BYv8M 713Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WRqzbWQ5nIKrt8ACxqIhdjGTjjV3XNEnx9RLXFnLp9U=; b=jrG1m9L0DPl3Y3kDEWR1ZnsG7ZhsmAiW5tdr1v6TpyAV7k1hP6F9WXDBveTV63kS4t kTIeWS4yA+lFm51jX/J9ZsNRe6Xz3fM36excL0dh3W4vMeiQxL14/OTvoBskDTVD7plb inJgsMjYqBr+Rx3/HwkAlhJhBqp1Qa966jlFWOawdAs+tT3yOpBXagxT1Tha58JrN06n BUiBr4LyB/fwkYbEkHBoSu2kMplKP4qXkkGhieCWmch9SbCcAjtJwWVn4VfO9fPZp67m f9xvVQDT/dvfAq6esU5A8GTkr+qNtmGqVSKMYHKmM9fI92eGLXOgAcHXYblX/PaMcE9H LuoQ== X-Gm-Message-State: AOAM530uXgK8EuFk3uajj0i9MvVviJTAXcELkTUS7zTS/AMFE4sGOs16 5YOvWCG2nDmjfpCoW2lIDMvB0sIJIa3EosxFL76apA== X-Google-Smtp-Source: ABdhPJzOnqtXcXrXssuHj4ykZZNRW7+lUJI1VruW/y3wcegljhCDGPhQVqab0qVckurvGz4++zn4Vc5YQG/X0aDIIwE= X-Received: by 2002:a05:6830:1095:: with SMTP id y21mr3282853oto.144.1628773752727; Thu, 12 Aug 2021 06:09:12 -0700 (PDT) MIME-Version: 1.0 References: <20210719160346.609914-1-tabba@google.com> <20210719160346.609914-15-tabba@google.com> <20210812095743.GL5912@willie-the-truck> In-Reply-To: <20210812095743.GL5912@willie-the-truck> From: Fuad Tabba Date: Thu, 12 Aug 2021 15:08:36 +0200 Message-ID: Subject: Re: [PATCH v3 14/15] KVM: arm64: Handle protected guests at 32 bits To: Will Deacon Cc: kvmarm@lists.cs.columbia.edu, maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, pbonzini@redhat.com, drjones@redhat.com, qperret@google.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210812_060914_103669_4AB65030 X-CRM114-Status: GOOD ( 30.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Will, On Thu, Aug 12, 2021 at 11:57 AM Will Deacon wrote: > > On Mon, Jul 19, 2021 at 05:03:45PM +0100, Fuad Tabba wrote: > > Protected KVM does not support protected AArch32 guests. However, > > it is possible for the guest to force run AArch32, potentially > > causing problems. Add an extra check so that if the hypervisor > > catches the guest doing that, it can prevent the guest from > > running again by resetting vcpu->arch.target and returning > > ARM_EXCEPTION_IL. > > > > Adapted from commit 22f553842b14 ("KVM: arm64: Handle Asymmetric > > AArch32 systems") > > > > Signed-off-by: Fuad Tabba > > --- > > arch/arm64/kvm/hyp/include/hyp/switch.h | 24 ++++++++++++++++++++++++ > > 1 file changed, 24 insertions(+) > > > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > > index 8431f1514280..f09343e15a80 100644 > > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > > @@ -23,6 +23,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -477,6 +478,29 @@ static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) > > write_sysreg_el2(read_sysreg_el2(SYS_ELR) - 4, SYS_ELR); > > } > > > > + /* > > + * Protected VMs might not be allowed to run in AArch32. The check below > > + * is based on the one in kvm_arch_vcpu_ioctl_run(). > > + * The ARMv8 architecture doesn't give the hypervisor a mechanism to > > + * prevent a guest from dropping to AArch32 EL0 if implemented by the > > + * CPU. If the hypervisor spots a guest in such a state ensure it is > > + * handled, and don't trust the host to spot or fix it. > > + */ > > + if (unlikely(is_nvhe_hyp_code() && > > + kvm_vm_is_protected(kern_hyp_va(vcpu->kvm)) && > > + FIELD_GET(FEATURE(ID_AA64PFR0_EL0), > > + PVM_ID_AA64PFR0_ALLOW) < > > + ID_AA64PFR0_ELx_32BIT_64BIT && > > + vcpu_mode_is_32bit(vcpu))) { > > + /* > > + * As we have caught the guest red-handed, decide that it isn't > > + * fit for purpose anymore by making the vcpu invalid. > > + */ > > + vcpu->arch.target = -1; > > + *exit_code = ARM_EXCEPTION_IL; > > + goto exit; > > + } > > Would this be better off inside the nvhe-specific run loop? Seems like we > could elide fixup_guest_exit() altogether if we've detect that we're in > AArch32 state when we shouldn't be and it would keep the code off the shared > path. Yes, it makes more sense and would result in cleaner code to have it there, especially in the future where there's likely to be a separate run loop for protected VMs. I'll move it. Thanks, /fuad > Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel