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 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 EEEC0C43460 for ; Thu, 20 May 2021 14:08:34 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 7BBDE61057 for ; Thu, 20 May 2021 14:08:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BBDE61057 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=desiato.20200630; 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=VD0fhvcvTIUKWsBY6k2OXgaYvL/yke2+0RWqaUeEhes=; b=C8+8RSsHwlwmyjoFuZp6b2sCDb 3nA8T9B5n7MlbLZQDLMvDif0eYgWDqs9d6KmI5rlIQnTJoSO3/lXyvTkaUnOAsU56oRLmQe0niakM TuaEaTDcy8137ZKU1A1KFVg+3yy4Xv9AL3PNUKQArKgFzOHDJJa59hLHKZFbJyslmZIWYjaOwblDU stUPIT+r1MOrg53s07YBnbleRyYABLXWiXZYv+VIupOB4cKuFTvmn/oW57fjs0rG5b8CYUkbAv9Fe 8vxsjyvxF+6k2a0Lys1UfKMH2jeVvqt8cHbkNc5n4tCvh9C2etVzTdPi2+G2fXUlBjyh+TPfz8ODM T+xdcOfA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljjJm-001MG5-AY; Thu, 20 May 2021 14:06:30 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljjJg-001MF6-Ce for linux-arm-kernel@desiato.infradead.org; Thu, 20 May 2021 14:06:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=IYDOOYfckWDHhURo7nmkAgHAYututC5c+82uL7TcsT0=; b=ixJQzD5b1gg9ka7tYqwWqAt6FT NB6pgcSLqoZ+iJI6mLJfLdiLJUkjiafktaZNUT/B562UFgDeEHmu1GrzWTHjMD0xkiaxpx5mVPloJ FheHXKWDOVkuF3b/Ae2WNfUiHm+LEuNB+cLcrA+jx0g6H3XCQCbuuEIIhaIWc/coNtotp5+UZQZFC wtTh/+4JTjgZ1YMKuupmHDuDZuxI4T05QAdaTzh5evTiz7vi7VQkwIgdyYMHeZSbUMMTYk/ogyl0g 0YVG/p4HXCO0oRYGpcHxoGg5U2L8F2ZMnQ7KFN7dUT4ojOlszsl0VODDwr2Su7gLNt7Qx56Z2d+B2 b1FBCJSQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ljjJd-00GPCu-D2 for linux-arm-kernel@lists.infradead.org; Thu, 20 May 2021 14:06:23 +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 110E011D4; Thu, 20 May 2021 07:06:20 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.7.235]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 917B53F73B; Thu, 20 May 2021 07:06:18 -0700 (PDT) Date: Thu, 20 May 2021 15:06:15 +0100 From: Mark Rutland To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kernel-team@android.com, stable@vger.kernel.org, Steven Price Subject: Re: [PATCH] KVM: arm64: Prevent mixed-width VM creation Message-ID: <20210520140615.GH17233@C02TD0UTHF1T.local> References: <20210520122253.171545-1-maz@kernel.org> <20210520124434.GD17233@C02TD0UTHF1T.local> <87zgwptvcg.wl-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87zgwptvcg.wl-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210520_070621_561847_FE5865AC X-CRM114-Status: GOOD ( 33.18 ) 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 Thu, May 20, 2021 at 01:58:55PM +0100, Marc Zyngier wrote: > On Thu, 20 May 2021 13:44:34 +0100, > Mark Rutland wrote: > > > > On Thu, May 20, 2021 at 01:22:53PM +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 > > > --- > > > arch/arm64/kvm/reset.c | 28 ++++++++++++++++++++++++---- > > > 1 file changed, 24 insertions(+), 4 deletions(-) > > > > > > diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c > > > index 956cdc240148..1cf308be6ef3 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; > > > + int i; > > > + > > > + /* Check that the vcpus are either all 32bit or all 64bit */ > > > + kvm_for_each_vcpu(i, tmp, vcpu->kvm) { > > > + bool w; > > > + > > > + w = test_bit(KVM_ARM_VCPU_EL1_32BIT, tmp->arch.features); > > > + w ^= test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features); > > > + > > > + if (w) > > > + return false; > > > + } > > > > I think this is wrong for a single-cpu VM. In that case, the loop will > > have a single iteration, and tmp == vcpu, so w must be 0 regardless of > > the value of arch.features. > > I don't immediately see what is wrong with a single-cpu VM. 'w' will > be zero indeed, and we'll return that this is allowed. After all, each > VM starts by being a single-CPU VM. Sorry; I should have been clearer. I had assumed that this was trying to rely on a difference across vcpus implicitly providing an equivalent of the removed check for the KVM_ARM_VCPU_EL1_32BIT cap. I guess from the below that was not the case. :) Thanks, Mark. > But of course... > > > IIUC that doesn't prevent KVM_ARM_VCPU_EL1_32BIT being set when we don't > > have the ARM64_HAS_32BIT_EL1 cap, unless that's checked elsewhere? > > ... I mistakenly removed the check against ARM64_HAS_32BIT_EL1... > > > > > How about something like: > > > > | static bool vcpu_allowed_register_width(struct kvm_vcpu *vcpu) > > | { > > | bool is_32bit = vcpu_features_32bit(vcpu); > > | struct kvm_vcpu *tmp; > > | int i; > > | > > | if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1) && is_32bit) > > | return false; > > | > > | kvm_for_each_vcpu(i, tmp, vcpu->kvm) { > > | if (is_32bit != vcpu_features_32bit(tmp)) > > | return false; > > | } > > | > > | return true; > > | } > > > > ... with a helper in like: > > > > | static bool vcpu_features_32bit(struct kvm_vcpu *vcpu) > > | { > > | return test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features); > > | } > > > > ... or > > > > | static inline bool vcpu_has_feature(struct kvm_vcpu *vcpu, int feature) > > | { > > | return test_bit(feature, vcpu->arch.features); > > | } > > > > ... so that we can avoid the line splitting required by the length of > > the test_bit() expression? > > Yup, looks OK to me (with a preference for the latter). > > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel