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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 49803C2B9F8 for ; Tue, 25 May 2021 09:22:50 +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 15B0661421 for ; Tue, 25 May 2021 09:22:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15B0661421 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+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.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=01NEPOGc8uarXhiFgJVtlw192popycCF+UDQFrye+Oc=; b=a6+zn/M4TD4bzV U74i/+yh9W1tSKVsYJ2sV3lntHhW5KJURwDy49KL2wAjuxAv3SU5PNQ3vdRocLE8xTQuVXCPWZquS gaYsnAUbezcFa47xKRlrE2o2oxa7ECoDHgCW/LPqJfUFV0MaN4MF1meqDmpZQ5/lXp9+wKpHPNagS 3j5qnjTwf/IhO39B7EsD8Ivs2KCDWPQ9VN7UNQig4XngfsgvJWr7MYbQ8tt+LDxdUfjCxnuwNCMCK dIgVVYWHt0x/pD/rh0U+0Auz6LOO7RcKX2vUMrDv12yPeUMrDEHbMy8DYU1Fo+sesJ4iRkU5nsR5P JniehPJsBlrrjtHx/Fkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llTFN-004KfW-6c; Tue, 25 May 2021 09:21:09 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llTFJ-004Kel-Ql for linux-arm-kernel@lists.infradead.org; Tue, 25 May 2021 09:21:07 +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 592C56D; Tue, 25 May 2021 02:21:04 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.37.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F3913F73D; Tue, 25 May 2021 02:21:01 -0700 (PDT) Date: Tue, 25 May 2021 10:20:54 +0100 From: Mark Rutland To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com, Steven Price , stable@vger.kernel.org Subject: Re: [PATCH v2] KVM: arm64: Prevent mixed-width VM creation Message-ID: <20210525092054.GA31646@C02TD0UTHF1T.local> References: <20210524170752.1549797-1-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210524170752.1549797-1-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210525_022105_938026_9D373858 X-CRM114-Status: GOOD ( 22.51 ) 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 On Mon, May 24, 2021 at 06:07:52PM +0100, Marc Zyngier wrote: > It looks like we have tolerated creating mixed-width VMs since... > forever. However, that was never the intention, and we'd rather > not have to support that pointless complexity. > > Forbid such a setup by making sure all the vcpus have the same > register width. > > Reported-by: Steven Price > Signed-off-by: Marc Zyngier > Cc: stable@vger.kernel.org Looks good to me! Acked-by: Mark Rutland Mark. > --- > > Notes: > v2: Fix missing check against ARM64_HAS_32BIT_EL1 (Mark) > > arch/arm64/include/asm/kvm_emulate.h | 5 +++++ > arch/arm64/kvm/reset.c | 28 ++++++++++++++++++++++++---- > 2 files changed, 29 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index f612c090f2e4..01b9857757f2 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -463,4 +463,9 @@ static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu) > vcpu->arch.flags |= KVM_ARM64_INCREMENT_PC; > } > > +static inline bool vcpu_has_feature(struct kvm_vcpu *vcpu, int feature) > +{ > + return test_bit(feature, vcpu->arch.features); > +} > + > #endif /* __ARM64_KVM_EMULATE_H__ */ > diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c > index 956cdc240148..d37ebee085cf 100644 > --- a/arch/arm64/kvm/reset.c > +++ b/arch/arm64/kvm/reset.c > @@ -166,6 +166,25 @@ static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu) > return 0; > } > > +static bool vcpu_allowed_register_width(struct kvm_vcpu *vcpu) > +{ > + struct kvm_vcpu *tmp; > + bool is32bit; > + int i; > + > + is32bit = vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT); > + if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1) && is32bit) > + return false; > + > + /* Check that the vcpus are either all 32bit or all 64bit */ > + kvm_for_each_vcpu(i, tmp, vcpu->kvm) { > + if (vcpu_has_feature(tmp, KVM_ARM_VCPU_EL1_32BIT) != is32bit) > + return false; > + } > + > + return true; > +} > + > /** > * kvm_reset_vcpu - sets core registers and sys_regs to reset value > * @vcpu: The VCPU pointer > @@ -217,13 +236,14 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) > } > } > > + if (!vcpu_allowed_register_width(vcpu)) { > + ret = -EINVAL; > + goto out; > + } > + > switch (vcpu->arch.target) { > default: > if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) { > - if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1)) { > - ret = -EINVAL; > - goto out; > - } > pstate = VCPU_RESET_PSTATE_SVC; > } else { > pstate = VCPU_RESET_PSTATE_EL1; > -- > 2.30.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel