Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6246490rwb; Mon, 14 Nov 2022 17:04:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf7fAfdc1g8SIm8BwSjGI09ZcZwpvu/1pFpOuQKqOgZhsUQ25aapFDepxv6KOLlBEXfvSKiP X-Received: by 2002:a05:6a00:4108:b0:56c:411f:b699 with SMTP id bu8-20020a056a00410800b0056c411fb699mr16098973pfb.48.1668474265844; Mon, 14 Nov 2022 17:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668474265; cv=none; d=google.com; s=arc-20160816; b=PvLDgLLRBQpRPa10CeKgI5RxWTOHM4O2syaQEH5ifi00EuWYjirK/HI0UVA4nRbKK+ TrdIxSwODNfLa+jk3kSHzgv+Sz56iGnxjOR0igZxsjayGnRdyf5VRkOL1Qf1/SMUPHdT u+lq0RfHzPu0LGSpc7Hct0AYPE8Hc8SVksae/ZxgKXPD1iWy2H189gp21LTBXly+X3x4 nNf1ShV9yj+tRrcui24iqtN+fMHn/7OdjqpICskAJJ2KyIj7ZQOgGjpi3gfDByN4WPRS TZSQIJkSt3WMgSwhiQLK3FGtysOn33M8j7f5oEnc7k04JNzOiopYx0RMkl2G0OVUaou/ 4MDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :reply-to:dkim-signature; bh=2C+mEdWGRF7/5Wann0NujnMardQrr8Pv4jnCYIOIfiI=; b=Vy3WW96GYTJ5b+9ofJwpbv1JV/bGvwB3JA7+yl3rWRv5zBj0SdIqmwOs7DwFm2kyNZ zWeAtTJ1yuai47tr1tvorykkIP5lEunpxfeQnYGj9aNkdS+J2Ys/+cnW/xUUrBIuLgya miPNDcXfphtpJe/O6qmuLhKS6+PMyyTSjlZ13DEq46TjQQjaLzO1f2Z4DXGs4rro+6Tf CAw7zLpf2lwpjybw7HULHi0dyDM0qOc5RPIpQxBj23JFZ2ZfqGEYBGk9hr9tNJGxHUx4 jnpBbnbkOUpxs+TRw8shY7WViBQje9orkD36HVuJA8ddqMbASmudwMS/oKLR2nY9Od9n HdKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KdNFTJ+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u133-20020a62798b000000b005718306bf3bsi10559235pfc.278.2022.11.14.17.04.13; Mon, 14 Nov 2022 17:04:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KdNFTJ+k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236124AbiKNXeq (ORCPT + 88 others); Mon, 14 Nov 2022 18:34:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230520AbiKNXep (ORCPT ); Mon, 14 Nov 2022 18:34:45 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1520AE6B for ; Mon, 14 Nov 2022 15:34:44 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id m6-20020aa79006000000b0056bc283f477so6777740pfo.19 for ; Mon, 14 Nov 2022 15:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=2C+mEdWGRF7/5Wann0NujnMardQrr8Pv4jnCYIOIfiI=; b=KdNFTJ+kuX5LRPdITAEfyeE5gXPE4KELlxqjIkj/2C8ZNoZ5iZfHOVNDOOfbCszRT2 EaHbD6iQ0CU8zAwaA6+iaPNkTOFNfl+7SI4hQ9w3qmWHphbSo8l+UcnrhrfcFxRUufWZ RC8hBKQGlGyoM+QDaYRdUAnHywNf8Z+239VTm1JOIFTx/M3ta+dz7FG9CH6TMiVV8fbQ 0HxyUg2OeZDkIqp4q1UwzLYaKEiLBWCY8GQ7HDVo4w93hiRbYNXdW9SI7bCb/MUzSnOS M0md+d9QDWIxVbQgKli/kpzDulxMjA83byuaklikp6IKAYHFDbU3PJ+0feaaGPCd4Zbt E3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2C+mEdWGRF7/5Wann0NujnMardQrr8Pv4jnCYIOIfiI=; b=fCYgZV1O5XUCfyGHOY2cXkO/RNsAsW+/xj6GurMLiapG0iEvv/inbOzNJc9nQFHLrX wkVFO/+SRoAs9vPsXoQCpnE4ugKqelsLpttkxVbamnvPpL6ePmWVvMcPQuIqXBO/ExgI U+s+ZkZh6Xiqd3dvcjDTgRZy2bgOtTPNVdceEIQNEfDbQbkgJDfm8oU06Kwptdeftmbw C0n27dFwExbQMTy1p064v/IJJHzEHedYcB8PrtUOHIfNIx8YeMsVopqlR/1I0wVF5I7T vIw+O6anLJSTAG1nkjSz4VGJvxFROsObDC++pnBQl3/MecJQjgUbuBLyaAcdx0bYgfNP wtqA== X-Gm-Message-State: ANoB5pnmWtx4vYklFH2JEYam5zPAyptIIpKSTPDPbOABfKAgfbxFkfXv PC9LruF5MhjS7GkXBsiQ8Ne4/p4JqvA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:1c86:b0:56b:d027:214 with SMTP id y6-20020a056a001c8600b0056bd0270214mr15823140pfw.79.1668468884170; Mon, 14 Nov 2022 15:34:44 -0800 (PST) Reply-To: Sean Christopherson Date: Mon, 14 Nov 2022 23:34:38 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221114233441.3895891-1-seanjc@google.com> Subject: [PATCH v3 0/3] x86/crash: Fix double NMI shootdown bug From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, "Guilherme G . Piccoli" , Vitaly Kuznetsov , Paolo Bonzini , Tom Lendacky , Sean Christopherson Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tom, I Cc'd you this time around because the APM doesn't explicitly state that GIF is set when EFER.SVME is disabled. KVM's nSVM emulation does set GIF in this case, but it's not clear whether or not KVM is making up behavior. If clearing EFER.SVME doesn't set GIF, then patch 1 needs to be modified to try STGI before clearing EFER.SVME, e.g. if a crash is initiated from KVM between CLGI and STGI. Responding CPUs are "safe" because GIF=0 also blocks NMIs, but the initiating CPU might leave GIF=0 when jumping into the new kernel. Fix a double NMI shootdown bug found and debugged by Guilherme, who did all the hard work. NMI shootdown is a one-time thing; the handler leaves NMIs blocked and enters halt. At best, a second (or third...) shootdown is an expensive nop, at worst it can hang the kernel and prevent kexec'ing into a new kernel, e.g. prior to the hardening of register_nmi_handler(), a double shootdown resulted in a double list_add(), which is fatal when running with CONFIG_BUG_ON_DATA_CORRUPTION=y. With the "right" kexec/kdump configuration, emergency_vmx_disable_all() can be reached after kdump_nmi_shootdown_cpus() (currently the only two users of nmi_shootdown_cpus()). To fix, move the disabling of virtualization into crash_nmi_callback(), remove emergency_vmx_disable_all()'s callback, and do a shootdown for emergency_vmx_disable_all() if and only if a shootdown hasn't yet occurred. The only thing emergency_vmx_disable_all() cares about is disabling VMX/SVM (obviously), and since I can't envision a use case for an NMI shootdown that doesn't want to disable virtualization, doing that in the core handler means emergency_vmx_disable_all() only needs to ensure _a_ shootdown occurs, it doesn't care when that shootdown happened or what callback may have run. Patch 2 is a related bug fix found while exploring ideas for patch 1. Patch 3 is a cleanup to try to prevent future "fixed VMX but not SVM" style bugs. v3: - Re-collect Guilherme's Tested-by. - Tweak comment in patch 1 to reference STGI instead of CLGI. - Celebrate this series' half-birthday. v2: - Use a NULL handler and crash_ipi_issued instead of a magic nop handler. [tglx] - Add comments to call out that modifying the existing handler once the NMI is sent may cause explosions. - Add a patch to cleanup cpu_emergency_vmxoff(). - https://lore.kernel.org/all/20220518001647.1291448-1-seanjc@google.com v1: https://lore.kernel.org/all/20220511234332.3654455-1-seanjc@google.com Sean Christopherson (3): x86/crash: Disable virt in core NMI crash handler to avoid double shootdown x86/reboot: Disable virtualization in an emergency if SVM is supported x86/virt: Fold __cpu_emergency_vmxoff() into its sole caller arch/x86/include/asm/reboot.h | 1 + arch/x86/include/asm/virtext.h | 14 +----- arch/x86/kernel/crash.c | 16 +----- arch/x86/kernel/reboot.c | 89 +++++++++++++++++++++++++--------- 4 files changed, 69 insertions(+), 51 deletions(-) base-commit: dacca1e5e75d7c1297f1334cdc10491dcdd1b2b8 -- 2.38.1.431.g37b22c650d-goog