Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4245517pxj; Wed, 12 May 2021 00:57:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuSSu22Wa2p7BOoZ1eGMZQIh9m8nQV8nqLT0QC15rt2w50LJ0qqAxO6s2LW2w3OVdt96Tv X-Received: by 2002:a5d:8516:: with SMTP id q22mr25868720ion.173.1620806275224; Wed, 12 May 2021 00:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620806275; cv=none; d=google.com; s=arc-20160816; b=aYnwyw0H54136XW7EpXeYeK8F3Cpokn1cekYKOLhC1I9UkxdArgYAxyI5nqIyrFxCD y0/kSoITSiaW/aVdaCZhU4Da7RI69ZouE+S0TA4UW5NXrFPj2QnFPJj85pr0GVCEIm/G 0vKbFWMzkoqcKmJEVjnUiJPRuevkUGPlT8qFdaKD9jXaxjxDXUAklPYqs1Zl//WlYZCB Gg/sYO9smZnUBAr0tZCwZhCrFXkd60zqqZpPIGT2KckXh8kkZXJxd1a6MKJ3/7AoE8hD lTd3YKPy695kEbhkajI1zrYAdD2zHfnPwC5SR392vnA21hvCp2pgofOP6/UEizZuf1Ug pA1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6NYLCM8naaJPRc/wrekqvOHSQVq1sGC/cHZp9EGoSOc=; b=W5J5jWtG8A7j+ZJ/wL+rFMN7EEtAvchn8KN7oUgFNqwy0yYbtegFgevdF59V3FCTWx dP05rxoLu/2gl+hvvTx5PU7ANHfWygqewOmeMwa6wm2eo8PXiLJyFeLOJ/qaZtI1/68L kRihAr14mZ3lub9C8iSaKisicTRrCwrVdC9CdHkQ1548N7doKk6gztaMoVZlqe/qbqAe WPqUzn7+4Xv8/AhvI61+t1baPTkaU2PbqbYxztgnZbgAS9o1NtTwkWxqTAY1nNOAbxuE Wr8pWGjJHI+XR8424RblNyNXSul1iiOIyZNS7vDiN6WgBwcZTrjD92fZ3G8uy9ycGYPH QCPA== 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q14si22837312ilg.14.2021.05.12.00.57.42; Wed, 12 May 2021 00:57:55 -0700 (PDT) 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbhELH4e (ORCPT + 99 others); Wed, 12 May 2021 03:56:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbhELH4U (ORCPT ); Wed, 12 May 2021 03:56:20 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DF0AC061761; Wed, 12 May 2021 00:55:13 -0700 (PDT) Received: from cap.home.8bytes.org (p549ad305.dip0.t-ipconnect.de [84.154.211.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id D19EA4B4; Wed, 12 May 2021 09:55:10 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org, Hyunwook Baek Cc: Joerg Roedel , Joerg Roedel , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 6/6] x86/sev-es: Leave NMI-mode before sending signals Date: Wed, 12 May 2021 09:54:45 +0200 Message-Id: <20210512075445.18935-7-joro@8bytes.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512075445.18935-1-joro@8bytes.org> References: <20210512075445.18935-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel The error path in the runtime #VC handler sends a signal to kill the current task if the exception was raised from user-space. Some parts of the #VC handler run in NMI mode, because it is critical that it is not interrupted (except from an NMI) while the GHCB is in use. But sending signals in NMI-mode is actually broken and triggers lockdep warnings. On the other side, when the signal is sent, there is no reason for the handler to still be in NMI-mode, as the GHCB is not used anymore. Leave NMI-mode before entering the error path to get rid of the lockdep warnings. Fixes: 62441a1fb532 ("x86/sev-es: Correctly track IRQ states in runtime #VC handler") Signed-off-by: Joerg Roedel --- arch/x86/kernel/sev.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 77155c4f07f5..79cbed2f28de 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1300,9 +1300,10 @@ DEFINE_IDTENTRY_VC_SAFE_STACK(exc_vmm_communication) return; } + instrumentation_begin(); + irq_state = irqentry_nmi_enter(regs); lockdep_assert_irqs_disabled(); - instrumentation_begin(); /* * This is invoked through an interrupt gate, so IRQs are disabled. The @@ -1352,13 +1353,19 @@ DEFINE_IDTENTRY_VC_SAFE_STACK(exc_vmm_communication) BUG(); } -out: - instrumentation_end(); irqentry_nmi_exit(regs, irq_state); + instrumentation_end(); return; fail: + /* + * Leave NMI mode - the GHCB is not busy anymore and depending on where + * the #VC came from this code is about to either kill the task (when in + * task context) or kill the machine. + */ + irqentry_nmi_exit(regs, irq_state); + if (user_mode(regs)) { /* * Do not kill the machine if user-space triggered the @@ -1380,7 +1387,9 @@ DEFINE_IDTENTRY_VC_SAFE_STACK(exc_vmm_communication) panic("Returned from Terminate-Request to Hypervisor\n"); } - goto out; + instrumentation_end(); + + return; } /* This handler runs on the #VC fall-back stack. It can cause further #VC exceptions */ -- 2.31.1