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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 0FE2FC433DB for ; Wed, 30 Dec 2020 11:03:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC3E1221F8 for ; Wed, 30 Dec 2020 11:03:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726502AbgL3LDp (ORCPT ); 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-Google-Smtp-Source: ABdhPJzRBv6eAt8+sGkPthVC4MF6WX/caLmzGEjiLKFuGvqf5bNuQxrUjMah5pk6tT2ykIwAJbZmTw== 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 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=-13.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 8CAADC433DB for ; Wed, 30 Dec 2020 11:03:09 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 028BE20789 for ; Wed, 30 Dec 2020 11:03:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 028BE20789 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 4E5AB4B185; Wed, 30 Dec 2020 06:03:08 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2a5ivqSTDAr4; Wed, 30 Dec 2020 06:03:07 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 2609F4B15B; Wed, 30 Dec 2020 06:03:07 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A977E4B163 for ; Wed, 30 Dec 2020 06:03:05 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hvzBiFG6sTF6 for ; Wed, 30 Dec 2020 06:03:03 -0500 (EST) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id B96094B15B for ; Wed, 30 Dec 2020 06:03:03 -0500 (EST) Received: by mail-wm1-f51.google.com with SMTP id q75so4454478wme.2 for ; Wed, 30 Dec 2020 03:03:03 -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=CBl5liwWVZXDvJmTq0u1NIXf/8uh4P3xE7ccfBfgZojUU1wF09+ixT7DYBEqBP/Lk7 JsarhS+ujnC+Bassu12ggYuzvjt9Eh37O8u/zmp0yd4hZPqsxKb9nJrUXFG6IG5Qifhg fPC4OTG2POEtDlHMAMzXykwdvUjAgvrXrzNmQcq455cGYqEGQgePD33h8XGEYRgb1pA5 +4njfHvse88Hi/36v62S1bfnrdlAHls9TmkEh2F/KcQ8Ti+Y5VNmjX4USjh/RVqx32A4 dyh16D84johIZJd/+nlOrzw1gHrZbKp/dMdgQU+OYftchyvc4x71TVKKEwv5+9bV//H8 n5Wg== X-Gm-Message-State: AOAM530BgJcoZoRLVb6BRF1qzBc2we2riiASmCe1MMAoem1wMYssOT2m /tDShdZOUzgl2ovRSypRYjl5Ew== X-Google-Smtp-Source: ABdhPJzRBv6eAt8+sGkPthVC4MF6WX/caLmzGEjiLKFuGvqf5bNuQxrUjMah5pk6tT2ykIwAJbZmTw== 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 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-Disposition: inline In-Reply-To: <229d84b8d7818a170adf489535ea2d43@kernel.org> Cc: Lorenzo Pieralisi , Catalin Marinas , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sudeep Holla , kernel-team@android.com, Will Deacon , kvmarm@lists.cs.columbia.edu X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu 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 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,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 45B2CC433E6 for ; Wed, 30 Dec 2020 11:04:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 EA4B3221F8 for ; Wed, 30 Dec 2020 11:04:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA4B3221F8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=OZ9NR74HJao4Ihptbdi3kpo/OaGYDJTtkic6fLX6xVo=; b=VDsVn8a9gNCQQ5x5n+QV2NKaV 2bO1+ItQad0CjVSSuCNwXEdM1l+5ASNCGKM3abB796PFXRwE0uhO2+kDOVHvIvXusSulxAaiKu0Rx 3iGwxH2J5rNWTxIAWZquAlx3ghqMsV9NHMvswh6+FOCuuwEfvlfnfaVDzPP9Fj3qfUsNufJdD5Z8s 8BYDneWskQfJp7PhqHE+PGpcH1hXAf8DWh8D8bYPvWxos1rw4qQsvcQTPOZSPiWWfrXO7CwuDy6bk frfbN+o0MDYrNPzvbLiqgsBbIOq7Z5CM/9kG3hRHL1NBaXg5276q10KSvVJexV8zWlraiK7bTZ7YE wljZ17/dQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kuZFz-0001Yh-3T; Wed, 30 Dec 2020 11:03:07 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kuZFw-0001Y9-6F for linux-arm-kernel@lists.infradead.org; Wed, 30 Dec 2020 11:03:05 +0000 Received: by mail-wm1-x32d.google.com with SMTP id g185so4451395wmf.3 for ; Wed, 30 Dec 2020 03:03:03 -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=Od1l6Z3YBl+1/1DPJvwjaNoUdIvjSBZWeKW1ITKgUqPwXWL0aRNT2HvTtjT5NQpr1a Wa4ZxwXQlU0x1+uqAa29ZqDZWPnpgb4tbSOBf5ccdaIC/vvYI3mQtKAw1Omud/q+1p+O shJ/rn+AppHdC9Wc3YPF2vk4iyBAS0+LDO4pS9ThYHVgnaVEprz9FqQsDW8V/RcI93ho cIzQ8g9jSO0D7Ot8347sj62AU/wpttEuBnxmTyDHs24SztZ3ulVymeA1NDPweVhybbS3 BSKskFyWCzJWm4l85fQd3LmgIiB5Ki5XvxPLyoq0XyvEZwVzzLjTuOZtBDZsokUucCDi T0aw== X-Gm-Message-State: AOAM5323gYoH3izUkf6pto76iOTtIpgZw9glOgmzpXc5vxV6AWqQAAzJ FPOTFV4HNKySjpRV4PQ4ngvq+Q== X-Google-Smtp-Source: ABdhPJzRBv6eAt8+sGkPthVC4MF6WX/caLmzGEjiLKFuGvqf5bNuQxrUjMah5pk6tT2ykIwAJbZmTw== 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 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-Disposition: inline In-Reply-To: <229d84b8d7818a170adf489535ea2d43@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201230_060304_281413_041EEF7F X-CRM114-Status: GOOD ( 27.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Lorenzo Pieralisi , Suzuki K Poulose , Catalin Marinas , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Sudeep Holla , kernel-team@android.com, Will Deacon , kvmarm@lists.cs.columbia.edu, Julien Thierry 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 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel