From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796175272; b=5bdkbmGJdrRGdRMT16ha2XqfRNEUQhwAT1Eyd6PcuPwzs40YpwRaIMHUaQ+i4ek1bQ6F eL19hCn23U9n/vV0cDBtECjOBzXI9NzQQaYS0xjO5FuxuwbFsIdcTQuwBAlOSSRZY2o2y QoaIg1br4JXt8b0IVGvm9q6xo+l1DpT+PUqssjIg2UB1akUCT4HJyyUsSZ+JKWcq5WjK/ WGMFYeds6JJ57OmLLRSS18rf9hvKEORoqt49nev5OrfgtFJsj/eMehJj9DjgcaHzGkm7I lOq9KfFTFdEF2y7ns0p0sK9mnmPIJXoP23a98sO3gZo2T3d8uOwBMvmEWz3468OYqtA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796175272; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=OCp7M1o0WjugiX5WkkOxZp4tqMOmyUtv5DpaKIhKy2o=; b=jHKd3uG/KbR6r5h5N+UZPUG4bTiAN1mzNCloHFRQXEMB2PzV39o+vVyForeRceJR01Gc M05LkKRXbJ5saZK2NKY02oZ6D8KEHMxpjphOB9TDq7s3eJ2lPj8c3ZD2vJo4Yxq0kQiVp UYUej/k+6TfA15+Pzaw5EeJaNNVEmUJlJdR+RrRFoHmAvZVgOUiMoiyozzkt8p04zvXiP rFtz2MeizD8qTgDpCnXrewXVGYj7j1sDecJ6eh1IlwUlgaMG4XvDrovBRkVNyRE0gdFX8 O376Lsdp7GZnQP0iDIGuo28aF+Ic+VgmHmmoq7kxG+dkeOZHkdbGoa2RLsNGuae9DZg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="ACij/Ypp"; arc=none smtp.remote-ip=209.85.216.72 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51A8D606A322 for ; Wed, 2 Dec 2026 01:34:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51A8D606A322 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=ACij/Ypp Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-3b4b76a2b95so11298621a91.1 for ; Tue, 01 Dec 2026 17:34:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796175271; x=1796780071; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OCp7M1o0WjugiX5WkkOxZp4tqMOmyUtv5DpaKIhKy2o=; b=ACij/YppQmhB0EZ7w11DAdGN0QIwZpQlPbb7nx8ZJ//+90Rj55hEuguUuUwLnjb1tl jRKgZAP1qvX6mWq5ZZBL3zOgGeFqXb80KY6QSCyecwXCp90gl9w4TIkzsjoEn1djxGB+ I5F0Jp0AgtIixOTfGAby2Rkos7FHy6wj1pJuZANRRfb6SDJu6KvwzN+bVEjE3W7Pk1zI XZdstnZZlGJz9s13ESx6ULzDId1qhcA/o7xq/lH7KqDVxVuZ95kkk6RpVXKMKTX9w03E osYK6C+ocZbB99osyxbo8aBZ1JQrOPJtsWURgf+d0gemEJriR0uiR+kGC+R1iZAuwNs4 E53g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796175271; x=1796780071; h=content-type: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:content-type; bh=OCp7M1o0WjugiX5WkkOxZp4tqMOmyUtv5DpaKIhKy2o=; b=NxwuTjDCElVhUwiLnxN77sYGxeNhFA/EhMquH2f5bTe1eNuXuz91MWfgnbv0CI2dij mMsxvnrEoeRIHxyR7y9Sh4PBsqV/HTwMd5sAlqz/KLz3YZ2mML6Qc7i2VMmBL87onVza h6Eyk4OhCKqedr+NFTa5udFivAB3mrskpZfU1qo1e765tV4WnUMj7UyAxVN3NAJx0MTb nH7qlGx7YDcO34JpXpSgXOmiBxifUSK3a/MY2T0ZD3Yv5ymuphKExQgJDsfO/N9JFI+k v3YK9cQwWK99b7j9VPWL3F0UrpNJh76OwgKSsn+yD/YCUQTEV2+huJg6q1YuFXakOk87 a+EA== X-Forwarded-Encrypted: i=1; AL+hErH4TnUU86iKjWn3GTE+yYWrIAQAx7CrRiNci3lwI9bLCyOQCXdS/2QlYyU+ZcMkkLDoJptKBeKsZ84uhgY=@vger.kernel.org X-Gm-Message-State: APuU4Z9grsEZpDakyBTgYNsO+ME0AV3XuHjTc0X4fxjxT0myPwo4spFA tsk0LUa7GnQTc1muKGm9daxwiCGxzojOnAAZHWLuTbgxTwJ79RgIdcETM61H0bn1GLeQzwMQ9j4 xDz+lqg== X-Received: from pjxd18.prod.google.com ([2002:a17:90a:c252:b0:3b3:fc12:c57c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:da87:b0:3b0:9a2e:b494 with SMTP id 98e67ed59e1d1-3b41c95b089mr36563219a91.54.1796175271344; Tue, 01 Dec 2026 17:34:31 -0800 (PST) Date: Tue, 1 Dec 2026 17:34:30 -0800 In-Reply-To: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20231107183605.409588-1-seanjc@google.com> <20231117103236.GI3818@noisy.programming.kicks-ass.net> <20231129112019.GG30650@noisy.programming.kicks-ass.net> Message-ID: Subject: Re: [PATCH] perf/x86: Don't enforce minimum period for KVM guest-only events From: Sean Christopherson To: Yosry Ahmed Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu , Jim Mattson , Mingwei Zhang Content-Type: text/plain; charset="us-ascii" On Wed, Nov 25, 2026, Yosry Ahmed wrote: > On Wed, Nov 29, 2023 at 12:20:19PM +0100, Peter Zijlstra wrote: > > On Tue, Nov 28, 2023 at 05:33:16PM -0800, Sean Christopherson wrote: > > > > > If programming a "period" of 1 puts the host at risk in some way, then I agree > > > that this is unsafe and we need a different solution. > > > > IIRC if you put in -1 on a Nehalem, you end up with an NMI-storm which > > wasn't trivial to recover from if at all (it's too long ago and I don't > > have ancient hardware like that anymore :/) > > > > > But if the worst case > > > scenario is non-determinstic or odd behavior from the guest's perspective, then > > > that's the guest's problem (with the caveat that the guest might not have accurate > > > Family/Model/Stepping data to make informed decisions). > > > > Things like bdm_limit_period() will cause odd behaviour IIRC, it does > > daft things like generate extra PEBS records on overflow and gives > > otherwise daft results for PDIR. > > > > glc_limit_period() lacks a useful comment :/ > > Sorry for thread necromancy, but it seems like the discussion stopped > here and I'd like to get this fixed as I am observing the same failures > that Sean did. > > Basically, if KVM needs to program period=1 (guest counter is -1), perf > overwrites it to 2. After 1 event, the guest counter should overflow, > but the hardware counter doesn't, so there is no PMI. On the other hand, > KVM relies on the hardware PMIs to signal overflows while perf events > are counting. > > The overflow is then lost: when KVM pauses the event (e.g. to account > for an emulated instruction), it folds the perf count into its software > counter and restarts the event with a new period, so the late hardware > overflow never comes, and KVM only checks for wraps on its own emulated > counts. > > Sean's fix makes the problem go away on all CPU platforms, and Peter's > makes it go away on Skylake+ on Intel (with updated microcode) and all > AMD platforms. So I am mostly happy with both. It's worth noting that > the blast radius is smaller with Sean's fix as it only affects guest > events. > > A middle ground would be skipping the left < 2 clamp on exclude_host > events, but not the x86_pmu_limit_period() callback, which makes the > problem go away on slightly more CPUs than Peter's patch (I think > Sandy/Ivy Bridge, and Skylake on older microcode versions). This keeps > the *_limit_period() subtleties in place. > > All three versions seem to make the problem go away on AMD Turin. > > WDYT? If Peter's fix works, go with that. I'm largely at the "I don't care" stage when it comes to the emulated vPMU. The only reason I sent this patch is because of KVM's testcase for this exact edgecase. In practice, the emulated vPMU can't get anywhere near perfect, we can only make it suck less. > An alternative to all of this is a "fix" on the KVM side where KVM is > always responsible for signaling all PMC overflows, instead of signaling > some of them from the PMI code path. KVM would keep track of the guest > counter value as of the last pause or write, and on PMI it would just > pause the event, manually check for the counter wrapping, and deliver > the PMI to the guest. > > This would obviously be a more complex change. Yeah, no thanks :-)