Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp286987lqb; Tue, 16 Apr 2024 16:17:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXLNgizPlQxcsCxA5VsqAnO1DmNBmii5v+hMMm8woxvB26ekd0NTNxxXVB2iRCi36u6xm3uP13oj6zkP7IjSUHtQS0swXu87aiy2I639A== X-Google-Smtp-Source: AGHT+IHeYIZs1lM7cPKsWp40Kxx5XuBKCGmHXHW6E5zkywEw4WlnIfvKIUJHqpjbEN39SN1ogMxK X-Received: by 2002:a05:6808:1455:b0:3c5:f919:4267 with SMTP id x21-20020a056808145500b003c5f9194267mr18196754oiv.47.1713309445546; Tue, 16 Apr 2024 16:17:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713309445; cv=pass; d=google.com; s=arc-20160816; b=fjeNEH2CaeZpF+hOAbknCnG7x5FojFVg5uW+sHp1MJdS7NOhaKMEMPa4eLM7wA8UFi OSVEJNiJFUfbHk7F+48ahLaETxFP4c/M9cK9bbPsCJ99wLWpWIxmknqvOk7BmiUwETco yPFl15XQ28JxmwNDfwu37UeZMDWmpYZdzUfjs9TAVmofBThr4m75b6cYposWMv2DvDUp M3VZI1SbouOHMYr8I6+/V1CkHioML/HiXgLAGDs8Eynp8h7vvi13Lo4cLSUdiySFESHR JWADaXifoCvYSFinLZEONIbMCaLs3vMVPbXLoC6x/R9kh5bdu5iQwFr7LLYcrhPTAPWl S/8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=NJZOibadvs2OEsulzI9JxEoFHhlL05LvXGfr+CJAFIQ=; fh=3cXhJDbRvw2IKb8Cc4+/wybdEEBdVwcdRruHkrxtsQE=; b=FDA4wVx/fVNeSqrgqc6I5ghixJ88bwtUB5a9vXx+LyvDdxSBlbPYJDrX2C5jpUXmZg oSgNxpjPIGFHj+fJiWiaBAbL6y26MV919jhyf/e9pnXU5qTuVDa0nC0IbeLnTrGQnfUQ O4MfAsg16TOwlUhb23iN7eZUTISwRps3vfaAm65EkwTXqRqeAr9lA7PaIbQEl618EojI A6v7qiT2TOMPqcnzEuc0fbsXcJTLKPJZS5x8bOxaVJtDqFjJ47yg1dYM/SZIxfHzUtoE y6cOQWm/IsZwFhhfo7yzaqneeh/kcwdWgXm3chG5QIKk6vQ13rq8iyuyIJAzszuxlWpA uHeQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=H7YFFHmc; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-147746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f9-20020ac85d09000000b004370dc3ed83si5776543qtx.581.2024.04.16.16.17.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 16:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=H7YFFHmc; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-147746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E361C1C212EB for ; Tue, 16 Apr 2024 23:17:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0EE4A13A86E; Tue, 16 Apr 2024 23:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="H7YFFHmc" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E324F2375B for ; Tue, 16 Apr 2024 23:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713309436; cv=none; b=BGWWJoNMPiWANi6qFnZItl9MudZ9LWfzi/Oa6zANy4xNMrOpXq+DRD54HtKZhJjvYUhb6bg1l6zzs7hzotbnH9kqsJYBA26T1rbf3Vfjr7u+Pzs1FVCfD1arLKMohII0mDcoIe3E+p8TFbQ1VEKB91tRTljeNNdT9Sms+t0rxS4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713309436; c=relaxed/simple; bh=Q0XMbJFBVMCnlF4miLF84NAlOU5Vi7ZAToMbckKuqFc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=svU2jHLkedc8MeV4xWSyuAEdNUWpcyaaefEAB/FEVqpasapEQDNGQUlrUb3g1WywggAxe6QZs7l17rJ4JRkTyk409XocTHSQxDNWpg8jjxejShHH0GZWCUEAGBvQhKvRlZthvHO3oFeqKZiaZKr4e4k4Aham9frgJPN8wrl8t8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=H7YFFHmc; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5dcab65d604so4013119a12.3 for ; Tue, 16 Apr 2024 16:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713309434; x=1713914234; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=NJZOibadvs2OEsulzI9JxEoFHhlL05LvXGfr+CJAFIQ=; b=H7YFFHmcKUuPAG+g2jRRLm/H1fV3zeqHG7sG+dUaiZdQK7AxxnoQUY17jFlhHk+SYo vSekPHvCB5FLGsETCOtRv9pIvo0leUwukxnoMw9kAyVpwySWUtFLWxMBvOeaW909qds7 ANqyFS8nqZ6LrFOHAyQxv42mbYd713QY9yy9aHuXtvEpMe67o+XbNFMCacjS1gVS0RcB 7Bafwj/5qFPJfgAFcaANe5dJmmmL3duvdYZf1Kd9anAV42rkz0uZSmADTW86fkWaEAXG bsNW6F5QsHWrGmo9JyEsh3Plc5/1POog5+T7c1SN2Tcv0Blj++5iYM3+MU1dhsMhcfKg Y0Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713309434; x=1713914234; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=NJZOibadvs2OEsulzI9JxEoFHhlL05LvXGfr+CJAFIQ=; b=UVKzGE/jkybgNX38GbAdMksZdCA0OgTRZ6h6xBjcztEQ2AzbGAcjGc8qxY63umvhSc /xQFgeKxLEnPMsAohSrPRzueq0TDZxJwrp4m7HgzghQuyPd8q0BBcTKeEtbN7aqqX8jz eiJeQYhXzmA4zbK5FF1yjnHPPSSYNMmr/fD4b8z39HBiNnwiN8bL9VMHNUpPueXGTfGA AFfQ0Tu1uq8XzZZRa53D0eTipQOLpgV09hG8Eu1XgVn8MTUm19mrytfZqg/XR0AiK8Gh j26oQ4DmI7U1W3/J1ssFcYPRvwgFpgK7Sj16tuluIkyGvMWcBeAdCIMI6bj1zHC2rKdm 7ZQQ== X-Forwarded-Encrypted: i=1; AJvYcCUIaR60K2yOE+h/XnJ72eRNMRcGIPDydnN4xnGEZrsKeoMk4JNrvbl1n+oAf8HVw05tku/OrIa82jw0SE/V/4zzlt870POqUdnXD70G X-Gm-Message-State: AOJu0YyfFAgYjpwrg3IIodDgyV/ToKdnT80rRvJgN22UPcidxjixu99N Bpk2zKZVrZ14s3Jh+kCGnbVQXgQkpvJ8VjgfXAR0mxVRQDOEUWae/2IIZd1IvZpJwW90YGAWKEG Wxw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:62c2:0:b0:5f7:536a:234b with SMTP id m2-20020a6562c2000000b005f7536a234bmr28060pgv.4.1713309434222; Tue, 16 Apr 2024 16:17:14 -0700 (PDT) Date: Tue, 16 Apr 2024 16:17:12 -0700 In-Reply-To: <77fe7722-cbe9-4880-8096-e2c197c5b757@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240416204729.2541743-1-boris.ostrovsky@oracle.com> <66cc2113-3417-42d0-bf47-d707816cbb53@oracle.com> <77fe7722-cbe9-4880-8096-e2c197c5b757@oracle.com> Message-ID: Subject: Re: [PATCH] KVM/x86: Do not clear SIPI while in SMM From: Sean Christopherson To: boris.ostrovsky@oracle.com Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 16, 2024, boris.ostrovsky@oracle.com wrote: > (Sorry, need to resend) >=20 > On 4/16/24 6:03 PM, Paolo Bonzini wrote: > > On Tue, Apr 16, 2024 at 10:57=E2=80=AFPM w= rote: > > > On 4/16/24 4:53 PM, Paolo Bonzini wrote: > > > > On 4/16/24 22:47, Boris Ostrovsky wrote: > > > > > Keeping the SIPI pending avoids this scenario. > > > >=20 > > > > This is incorrect - it's yet another ugly legacy facet of x86, but = we > > > > have to live with it. SIPI is discarded because the code is suppos= ed > > > > to retry it if needed ("INIT-SIPI-SIPI"). > > >=20 > > > I couldn't find in the SDM/APM a definitive statement about whether S= IPI > > > is supposed to be dropped. > >=20 > > I think the manual is pretty consistent that SIPIs are never latched, > > they're only ever used in wait-for-SIPI state. > >=20 > > > > The sender should set a flag as early as possible in the SIPI code = so > > > > that it's clear that it was not received; and an extra SIPI is not = a > > > > problem, it will be ignored anyway and will not cause trouble if > > > > there's a race. > > > >=20 > > > > What is the reproducer for this? > > >=20 > > > Hotplugging/unplugging cpus in a loop, especially if you oversubscrib= e > > > the guest, will get you there in 10-15 minutes. > > >=20 > > > Typically (although I think not always) this is happening when OVMF i= f > > > trying to rendezvous and a processor is missing and is sent an extra = SMI. > >=20 > > Can you go into more detail? I wasn't even aware that OVMF's SMM > > supported hotplug - on real hardware I think there's extra work from > > the BMC to coordinate all SMIs across both existing and hotplugged > > packages(*) >=20 >=20 > It's been supported by OVMF for a couple of years (in fact, IIRC you were > part of at least initial conversations about this, at least for the unplu= g > part). >=20 > During hotplug QEMU gathers all cpus in OVMF from (I think) > ich9_apm_ctrl_changed() and they are all waited for in > SmmCpuRendezvous()->SmmWaitForApArrival(). Occasionally it may so happen > that the SMI from QEMU is not delivered to a processor that was *just* > successfully hotplugged and so it is pinged again (https://github.com/tia= nocore/edk2/blob/fcfdbe29874320e9f876baa7afebc3fca8f4a7df/UefiCpuPkg/PiSmmC= puDxeSmm/MpService.c#L304). >=20 >=20 > At the same time this processor is now being brought up by kernel and is > being sent INIT-SIPI-SIPI. If these (or at least the SIPIs) arrive after = the > SMI reaches the processor then that processor is not going to have a good > day. It's specifically SIPI that's problematic. INIT is blocked by SMM, but lat= ched, and SMIs are blocked by WFS, but latched. And AFAICT, KVM emulates all of = those combinations correctly. Why is the SMI from QEMU not delivered? That seems like the smoking gun.