Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1272920pxu; Fri, 27 Nov 2020 03:55:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0hQb1Ihjir4CylunT2z1STkR7mwZlPgO6KT5s1bJwNMmn9mbhNurOb/0N3D/vxtx/6ECO X-Received: by 2002:a17:907:3f9e:: with SMTP id hr30mr7083974ejc.258.1606478142857; Fri, 27 Nov 2020 03:55:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606478142; cv=none; d=google.com; s=arc-20160816; b=XPYV/GVyUf2hkHWuhYIbZfVevgz8tWdE2NKc/+gVCUfL+Pj94u1C9qpNS5gwch4QS2 2DCex+c06b686hV/NlOe+/VuwoB4rZR+qvx7HbZfQlR2vT2Zeaw0Dn4n1bfhGajsWurz FfSkXOmTmv/btzRJieYNph50MV2wgr8zQroPSxkEtgbkkBPf3GNbHJr924WyUa8TcLXC EZwEblbAQ3SMX5lYvALawBtvdOoRw3Q9UV5Try2eXteHrsxpkrfEVwYEZlublveZxC3b kEYrC905PHxnvJm0fjmdKm+7nw2nLkaxkLKQj2YLAVXe2bhcyWXc7+F8iW2CTzOR5qjK QBPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=XOvScesm6lVXOut46bCcf06c1tw5EGUWMOETCLoBoHA=; b=QHh7bbVFBeT59MWwwbBxRyylcXt5oFb7kyrnvRqVpIOJsm+6FWFT4Qrb5t19tGt7Eh YEksLvswfl1jUCU/zmHolnd1UqG6pFcw+Kzil1UYLcBvu0A3teTWPMkGC7jV1IO7DeVe iCq9qoAp8NwBykD4pyf5gqwAxYgU7pTScpy41IcNx1omiTzmA96DiXBO33llF10CFCRT NGflhgYy1XcEp5HSBFliCilFwSnslwNhwQ0ucKsR1DBT3PERVzzAYqmiwJ5UaaJOsRop +12qqe7ObI9Rs25yhPZlgGIwbsRZlW4OO4aLiKv/qzMrN/60NHUGIxSQ6ZcvsRDAE/WE oTmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fDqlxhg0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si2387896edr.514.2020.11.27.03.55.18; Fri, 27 Nov 2020 03:55:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fDqlxhg0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728404AbgK0LxO (ORCPT + 99 others); Fri, 27 Nov 2020 06:53:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:60654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbgK0LxN (ORCPT ); Fri, 27 Nov 2020 06:53:13 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D728821D46; Fri, 27 Nov 2020 11:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606477991; bh=iRowjQfwiQpVHUf5+VNrejatl3jHns8UFqG/fY0lA64=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fDqlxhg0s8I0lbubTcM0KCHwdQ5Jm6b4//0Z144munNg+uAsO9SfKes4f3FiFafg6 lAjcNtv7ZpDmchUtH/zWKAHaB1tPAac0SuUp2XQbWK/yruSh3QdkHZDTae0hZhU55t rH4IdTGP0Q4Y9DdwQ4WMRTRoLzqccezgT1m48lk8= Date: Fri, 27 Nov 2020 11:53:05 +0000 From: Will Deacon To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Catalin Marinas , Greg Kroah-Hartman , Peter Zijlstra , Morten Rasmussen , Qais Yousef , Suren Baghdasaryan , Quentin Perret , Tejun Heo , Li Zefan , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , kernel-team@android.com Subject: Re: [PATCH v4 03/14] KVM: arm64: Kill 32-bit vCPUs on systems with mismatched EL0 support Message-ID: <20201127115304.GB20564@willie-the-truck> References: <20201124155039.13804-1-will@kernel.org> <20201124155039.13804-4-will@kernel.org> <9bd06b193e7fb859a1207bb1302b7597@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9bd06b193e7fb859a1207bb1302b7597@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 27, 2020 at 10:26:47AM +0000, Marc Zyngier wrote: > On 2020-11-24 15:50, Will Deacon wrote: > > If a vCPU is caught running 32-bit code on a system with mismatched > > support at EL0, then we should kill it. > > > > Acked-by: Marc Zyngier > > Signed-off-by: Will Deacon > > --- > > arch/arm64/kvm/arm.c | 11 ++++++++++- > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > > index 5750ec34960e..d322ac0f4a8e 100644 > > --- a/arch/arm64/kvm/arm.c > > +++ b/arch/arm64/kvm/arm.c > > @@ -633,6 +633,15 @@ static void check_vcpu_requests(struct kvm_vcpu > > *vcpu) > > } > > } > > > > +static bool vcpu_mode_is_bad_32bit(struct kvm_vcpu *vcpu) > > +{ > > + if (likely(!vcpu_mode_is_32bit(vcpu))) > > + return false; > > + > > + return !system_supports_32bit_el0() || > > + static_branch_unlikely(&arm64_mismatched_32bit_el0); > > +} > > + > > /** > > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute > > guest code > > * @vcpu: The VCPU pointer > > @@ -816,7 +825,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > > * with the asymmetric AArch32 case), return to userspace with > > * a fatal error. > > */ > > - if (!system_supports_32bit_el0() && vcpu_mode_is_32bit(vcpu)) { > > + if (vcpu_mode_is_bad_32bit(vcpu)) { > > /* > > * As we have caught the guest red-handed, decide that > > * it isn't fit for purpose anymore by making the vcpu > > Given the new definition of system_supports_32bit_el0() in the previous > patch, > why do we need this patch at all? I think the check is still needed, as this is an unusual case where we want to reject the mismatched system. For example, imagine 'arm64_mismatched_32bit_el0' is true and we're on a mismatched system: in this case system_supports_32bit_el0() will return 'true' because we allow 32-bit applications to run, we support the 32-bit personality etc. However, we still want to terminate 32-bit vCPUs if we spot them in this situation, so we have to check for: !system_supports_32bit_el0() || static_branch_unlikely(&arm64_mismatched_32bit_el0) so that we only allow 32-bit vCPUs when all of the physical CPUs support it at EL0. I could make this clearer either by adding a comment, or avoiding system_supports_32bit_el0() entirely here and just checking the sanitised SYS_ID_AA64PFR0_EL1 register directly instead. What do you prefer? Will