Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp10449596pxu; Wed, 30 Dec 2020 03:04:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyp6nb4PFSawwIcxPJ5UnS3e6uOMO98BlknCIqEa70ZCVU6HvCRIhfijL+XVMokEeZXrr4G X-Received: by 2002:aa7:c652:: with SMTP id z18mr48204237edr.60.1609326291805; Wed, 30 Dec 2020 03:04:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609326291; cv=none; d=google.com; s=arc-20160816; b=M1I7Am80r9FQH/ikRmNbNosXeCfsynixVQuS1lvXMd3GY44Bjjci3sDoeIoLLVr9GT bSJFb9pC9dHn/8IGsMMGe2eCSAYu88WLiAW/tfSoJR4GjtwWNZCs7UbNh2W9dEUfSIMG 2768uqW6yvr0Cv7EPch2y5fA+z0W6LzJUze+y3/bt2SkZqQ9Ili2EWDBTr2Vrtkh/zO2 IuY0XxVQRwDlcgegCUVbNCC/jv3bBU/IoaFcZdZ8PW8l1zMJespSgrkneGxCmnVuMHH6 qprSD2r8/kVJlogKQNuWq55/G/Cm7E9Qmgj18HJWD/XnDMMGYuXROEy7+QjvfxH1xehn v3MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WS30afWY3GKACZJXCkkdeuRXpGLieFQFBc+EFWHXZ8I=; b=iNxxA++5HxDHdOU4ZGwjZBM6uNvibsGu4LQGRhAehW5c93+H32mb2NzHrs14ftg9yW XFob4PiVKOoDmTZ1fH8oqKAub/Iq8COJ2pAgLYySkBlU6Fx4uwlmsq5GRvcuxyBtPCci 01R5KHQqTXcOI4UN2bJfPb1SXFlsjDCF5lwG5WSWZRelu4vIxSlJJoSXq55THXJqa9gg F8G1yxJpkcdqr3WOjdjCBb6CSMq4se/wM9uaC1jidCKVevDv3qS/pMkileeS6z6fw4zT Yid1+Xzvmry4tH+Cx5XB4gOc+JGmWfiq/j3ufYvqy4ncLlckuzhA1LN2ucij3UglRtlH 18OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mcpxu45J; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gq1si18968997ejb.675.2020.12.30.03.04.29; Wed, 30 Dec 2020 03:04:51 -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=@google.com header.s=20161025 header.b=mcpxu45J; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726477AbgL3LDp (ORCPT + 99 others); Wed, 30 Dec 2020 06:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbgL3LDo (ORCPT ); Wed, 30 Dec 2020 06:03:44 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 250FEC061799 for ; Wed, 30 Dec 2020 03:03:04 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 3so4446766wmg.4 for ; Wed, 30 Dec 2020 03:03:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WS30afWY3GKACZJXCkkdeuRXpGLieFQFBc+EFWHXZ8I=; b=mcpxu45JEAPmoccMikSFXPzTHkYmNC9Cr2PxZF40ApQKLEt8ZByo+t4Jg+RtvlgioZ KPFZPvQog2EMXmEuRxbQyh1m8Tgk0umqTlpZKvxJUo2DJucEj9nfKymKPAPUqWFAD9cO VYzGwqDMiJn+rq4wPNXnI3mmw0MGIG408+6RDbnHSbM81z7fptRzXUanxDddqvV6JwKw 4P6vsMKVg5ADZEBJVnbIoINXwH3okfS0SYIXIG1pW9wX36MQ5b/4XwpAYWA6Mc6UXq5Z SGY8fG+SjE0UUOIQdOSxaWjRr8S/Xouoc3xoINaMgpjvsBwb3pXklmthHBqXNoVcw2gD O+Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WS30afWY3GKACZJXCkkdeuRXpGLieFQFBc+EFWHXZ8I=; b=IJL3Kfx49RMQ01Z18mVK3sfNgN9Hw8oypfe3Qly9awxQU2foWsNdnnDtYNGuN3MMS/ T8/PJYg/CaUYmEdxANd/G0POHadub8vClDYUaPCFt201R2zfkOQCDthnbF3vrx4Wgx7m hruCh75zYZCOqNdMP46RWBuYifqSp938gKie3xjRlPhruShqoS+GCNk7I5n+Wsy+i+Ch 4xloqMh+C4ZLoBf6LTle+ylXCGYwCM8GMkVatp3EpT5uyjgSrE9ZV02WndHdle61FFEx SXdY5gpdwe262MYyROa2728qYwVpljM1qvYY1RLOKj/fwy/FaLcW3ljwAmFk7kafoGqc CMug== X-Gm-Message-State: AOAM532kuEYN/GAAAWWFmdgq0nHX+ESTE1KjsMX3STSylPFzVvnVopRq S2/Tg/zXjD+Zw7mcPmgaH+esTA== X-Received: by 2002:a1c:4156:: with SMTP id o83mr7146093wma.178.1609326182577; Wed, 30 Dec 2020 03:03:02 -0800 (PST) Received: from google.com ([2a01:4b00:8523:2d03:b0e4:997:fb3:e517]) by smtp.gmail.com with ESMTPSA id y130sm7256253wmc.22.2020.12.30.03.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 03:03:01 -0800 (PST) Date: Wed, 30 Dec 2020 11:03:00 +0000 From: David Brazdil To: Marc Zyngier Cc: kvmarm@lists.cs.columbia.edu, James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH] KVM: arm64: Allow PSCI SYSTEM_OFF/RESET to return Message-ID: <20201230110300.a2wei7ojhjkqfkgk@google.com> References: <20201229160059.64135-1-dbrazdil@google.com> <229d84b8d7818a170adf489535ea2d43@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <229d84b8d7818a170adf489535ea2d43@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 29, 2020 at 05:16:41PM +0000, Marc Zyngier wrote: > Hi David, > > On 2020-12-29 16:00, David Brazdil wrote: > > The KVM/arm64 PSCI relay assumes that SYSTEM_OFF and SYSTEM_RESET should > > not return, as dictated by the PSCI spec. However, there is firmware out > > there which breaks this assumption, leading to a hyp panic. Make KVM > > more robust to broken firmware by allowing these to return. > > > > Signed-off-by: David Brazdil > > --- > > arch/arm64/kvm/hyp/nvhe/psci-relay.c | 13 +++++-------- > > 1 file changed, 5 insertions(+), 8 deletions(-) > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c > > b/arch/arm64/kvm/hyp/nvhe/psci-relay.c > > index e3947846ffcb..8e7128cb7667 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c > > +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c > > @@ -77,12 +77,6 @@ static unsigned long psci_forward(struct > > kvm_cpu_context *host_ctxt) > > cpu_reg(host_ctxt, 2), cpu_reg(host_ctxt, 3)); > > } > > > > -static __noreturn unsigned long psci_forward_noreturn(struct > > kvm_cpu_context *host_ctxt) > > -{ > > - psci_forward(host_ctxt); > > - hyp_panic(); /* unreachable */ > > -} > > - > > static unsigned int find_cpu_id(u64 mpidr) > > { > > unsigned int i; > > @@ -251,10 +245,13 @@ static unsigned long psci_0_2_handler(u64 > > func_id, struct kvm_cpu_context *host_ > > case PSCI_0_2_FN_MIGRATE_INFO_TYPE: > > case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU: > > return psci_forward(host_ctxt); > > + /* > > + * SYSTEM_OFF/RESET should not return according to the spec. > > + * Allow it so as to stay robust to broken firmware. > > + */ > > case PSCI_0_2_FN_SYSTEM_OFF: > > case PSCI_0_2_FN_SYSTEM_RESET: > > - psci_forward_noreturn(host_ctxt); > > - unreachable(); > > + return psci_forward(host_ctxt); > > case PSCI_0_2_FN64_CPU_SUSPEND: > > return psci_cpu_suspend(func_id, host_ctxt); > > case PSCI_0_2_FN64_CPU_ON: > > Thanks for having tracked this. > > I wonder whether we should also taint the kernel in this case, > because this is completely unexpected, and a major spec violation. > > Ideally, we'd be able to detect this case and prevent pKVM from > getting initialised at all, but I guess there is no way to detect > the sucker without ... calling SYSTEM_RESET? Yeah, there are no bits to check, unfortunately. :( David