From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 484AC472F8C for ; Tue, 21 Jul 2026 17:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656154; cv=none; b=sqzqsIlRnOhybgeo04iP+5E0/ZK9bZ+vTqshc8Tb/cuoSCo4B/Nl2BKRjcX+IDArm5YfB8GkNloVDWz9Xhi7e0Q2rvOfqAqqULwMU2s5+b/LiRzWutz/Xv2Wvwp6J6tQsgwyw+M4ZUptazdY8DxJbw9+XSmYEUNg+LxUxNqTzA8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656154; c=relaxed/simple; bh=wtoP453vHl9jhsIHwdll81HsJdN1cePg3YyVulL6fXc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SoYJL3DH1VQlMbgnDVmEuGS+mbHRgswcX9YEZw4dYCWWjZe+aZ/4HrUDHOUJ0ANOqHxulAi2Ae8IDlxLZA13aoa899HmEPmm9D6JI1qdOG8eUTYHksdg+ZAFDFH2OKISChZc5ckAjwMwQpFtCxD+WR4O2MtyQxwDqEyJpg1lqOc= 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=ocB9Y7Si; arc=none smtp.client-ip=209.85.216.72 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.b="ocB9Y7Si" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38dd87656d3so11390184a91.2 for ; Tue, 21 Jul 2026 10:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784656153; x=1785260953; 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=1fjt8b0VZx808GggIVBxRHLGqfLzbT59D1LVyN4koO4=; b=ocB9Y7SiLHYzUUFtLYewqKvDHF35kW+50Me3BT3JzK35d9OaQPqq9ISLuWJrfgEn0R hOoTcaRxk6k2PNTBW147XPQLTxw1GJztQ5icPa/S1F9gKqSqFMShupB/rqmvfajsl0oS HPur727HZAhEVE0Gv/W3wuSGsU8A2q7HXNsBzHlGG5mfOnnbqdwoSr/2Vhvc2F5HskoV 2ByvTrnrr7qhTla7qpuNE/1wBMj7h3PeXKlTTQ7BfLKyYToVnJ5oniyy+P6NXLNPHma5 4t0E5VvrXZA0VpZWwo1HcG8zmjRA3XULRXC+KTv4xT56lE/mNWMweHiCh13RQikS//N0 OaYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784656153; x=1785260953; 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=1fjt8b0VZx808GggIVBxRHLGqfLzbT59D1LVyN4koO4=; b=dpOYRbKsI4sSHkijViSamFk1NkA9xG6OtcqJU+GfN+f6l2u+Ra2HqX7vSKdnwGiWrL 4S3FxpNojTdPm31DvfwBDXEsBcottVeD0YVuZ9Om7BQ9blxVn48J75D9bbyiA+6TkfDS f9JCvf59IKzat8sZl48HI//ecDLaVO5HpC2MzCjHEfMFPC9Th18Da1JpGZFgXYocOlsS IIuSO8OmN7FE3uviLXI7JW18YtSlNqLC0u0yNIiYSjYtAYOePMs4BovAlOwG+GwDxLg/ muZTEWKqKHSOhMwcm/fTOtiCO4kteD/G4dXwKkxwYQXrsOoOzb63cj7H0HRRW5wOvG7f xA5w== X-Forwarded-Encrypted: i=1; AHgh+RooPtf0Pjf3KJu8cXuNQkbVavFlmqmmuDXAPwXgbYK5eZiwKAAYGAW4w4kLDQCuWoGosmzORmR/HoVQqo0=@vger.kernel.org X-Gm-Message-State: AOJu0YxCGJK9Et6qwQsXRynwTdc//i3yz4F4aRLlTcS+usEH3YMiIyZW G4YA/2/Ki/zEqYmZ535TpSX92lZwvaypQilpMHCZUY9+AlNgcvIzjAtvpmE+HtP4SHx1d0eIClr fOqKYxw== X-Received: from pgjc9.prod.google.com ([2002:a63:d149:0:b0:c85:9c9a:ab5b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2583:b0:3c3:875d:c546 with SMTP id adf61e73a8af0-3c3ad792448mr20699995637.7.1784656152391; Tue, 21 Jul 2026 10:49:12 -0700 (PDT) Date: Tue, 21 Jul 2026 10:49:11 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260720192221.72912-1-absandze@amazon.de> Message-ID: Subject: Re: [RFC PATCH 0/2] KVM: x86/pmu: Let userspace disable SW accounting of emulated instructions From: Sean Christopherson To: Luka Absandze Cc: David Woodhouse , Paolo Bonzini , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-doc@vger.kernel.org" , "Graf (AWS), Alexander" Content-Type: text/plain; charset="us-ascii" On Tue, Jul 21, 2026, Luka Absandze wrote: > On 2026-07-21 09:47, Sean Christopherson wrote: > > Hmm, yeah, that'd be better than ignoring emulated instruction entirely, and > > would give userspace far better control over how shoddy KVM's emulation is. Off > > the cuff, the change would be fairly trivial too? E.g. > > > > diff --git arch/x86/kvm/pmu.c arch/x86/kvm/pmu.c > > index 7f777049d328..c5f436c6f83f 100644 > > --- arch/x86/kvm/pmu.c > > +++ arch/x86/kvm/pmu.c > > @@ -1084,7 +1084,8 @@ static void kvm_pmu_incr_counter(struct kvm_pmc *pmc) > > */ > > if (!kvm_vcpu_has_mediated_pmu(vcpu)) { > > pmc->emulated_counter++; > > - kvm_pmu_request_counter_reprogram(pmc); > > + if (pmc->emulated_counter > pmu_something_something_tolerance) > > + kvm_pmu_request_counter_reprogram(pmc); > > return; > > } > > I believe this is fine, but perhaps the tolerance itself could be a knob Ya, I was envisioning a knob. > with <0 meaning no reprogram? Eh, I don't see a need to assign special meaning to <0. Make it a u32 (or u64), and then a large value will provide the same behavior in practice, without needing special handling in KVM. > While the contention on this path will be much lower, we are still > introducing more steal time, and the added accuracy is probably not worth > even that for guests who really only care for the rate of change, rather than > exact instruction counts.