Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9950488pxu; Tue, 29 Dec 2020 09:20:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOVP+WMcfl93C3QaqMW5crnHOXoRnNzyqSYPuwmIEv52xXKjSgvPVmJJIHr9y9zkgaqNnf X-Received: by 2002:aa7:da03:: with SMTP id r3mr46524848eds.155.1609262407492; Tue, 29 Dec 2020 09:20:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609262407; cv=none; d=google.com; s=arc-20160816; b=e1iAMDFl/MbHmR9hcvxAt21tCJIn6FHM+660JD5nP1lfwLqyhvjbTlppXgCxooblPh 7fV1yJ+zBBz2zK26l1jp6WW8nBrqq4E6eOIcoRLRe7haC+aKRr87NIdo8MoTgyEDacVQ BrZY2kVlsRjGhmpBPhqKDQ3Zd/RhrsNkEih50LbIbsQ9QOAggHq8tWJY5+XjfxuAIpfi Ir8fQPWyxTV2uH7LJ1i2ZOu+DPPVZvQTtC7/99S2YoLRE6+o3iwmT81injlTRqu9BTb6 DgIxgLH3Bi7+Z/q531vRNe9WQYgkt23jwPU8y4mWq+ZG+sODfSoHY8x4DTsZLnBlyIP0 erHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version; bh=mWw9x8Shy83YumdYA42NiDiJDj33dRuYCFM1WEB/0WY=; b=uvveeBcRl8KgtzisJERD+0t22nblJkVIVfOeUOPg5RoBLB+dC8AULFndbd78dcmb/A 3AO76J75PxjxWBBAV6Jrd3jcZaYBp74K48JhFiOZGOVqx+1SKp2RaJjTpCzj56J3dZhY I9COlq29hrvaftpnVNE7yzHM+BbNlBQgx3ijJMjUWvm76LihBG+WMhpmiT60fkIRJpOR enQnuCB86JJMjkibIFpkvcMUK6pXMzsOan/d1iPpFkf0/+2XSftVonjlx5k645cDuGud K9Q3FsCFYi7Gyi0hl1/zQw/Co8f3rj+G8o3p40uRgh1VB86yBW3BwlwQ0fEGgi5u+kz8 57hw== ARC-Authentication-Results: i=1; mx.google.com; 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 uz9si20078808ejb.386.2020.12.29.09.19.43; Tue, 29 Dec 2020 09:20:07 -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; 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 S1726261AbgL2RRZ (ORCPT + 99 others); Tue, 29 Dec 2020 12:17:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:45404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726258AbgL2RRY (ORCPT ); Tue, 29 Dec 2020 12:17:24 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (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 CC47A21D94; Tue, 29 Dec 2020 17:16:43 +0000 (UTC) Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1kuIbx-004Ri2-Kb; Tue, 29 Dec 2020 17:16:41 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 29 Dec 2020 17:16:41 +0000 From: Marc Zyngier To: David Brazdil 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 In-Reply-To: <20201229160059.64135-1-dbrazdil@google.com> References: <20201229160059.64135-1-dbrazdil@google.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: <229d84b8d7818a170adf489535ea2d43@kernel.org> X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: dbrazdil@google.com, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? M. -- Jazz is not dead. It just smells funny...