From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 49A73472F8F for ; Tue, 21 Jul 2026 17:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656154; cv=none; b=IaQM9MYSekajmPzS6JKMzOEixaDXE64iaCJe7GLODS6H11nevzckrn0F/QPy31Lf9ofbeH+WTQmzSXBW9cDmFG94j7Bwg5DtA3/v3eawE8KOhv48LnRfNYXN8RL/i0zpPLb6qvbL7iqdqPiIWnbWUpeEnSw3a1kJ5EK2tmyOi9I= 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.71 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-f71.google.com with SMTP id 98e67ed59e1d1-38e1118e4abso12838766a91.0 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=eVpVONs5y7LN1QPpwmXqY9IeQbu5t7P4xTz1dsiJw6nlkgWhbxBOzr1Rt2pNOTASXp +uWR5+ryRRLvn6aF4oQD39TPGo2vR7E9RxqehT7imNCK3uZ2eejPOMi11Z0m2CcYV7NL SYP22sKnhiIXxvlEKDvtp3CUbgzMFL3tsv5aZiX0YlR/y7DAMIjOjWdisIaRA1ukIRFf oRngQgd3Q005Q2S/1fxrt7lZldzfoJPy3sxqAiooLqprbnEdcoFkV/pNkxKYPFrC8PwK oL1YCzOZ1qUQWcaJHnyZOnODvkgobSN0fqhK+ec8SNU6p4lnwL1i/d4/9q0FP2zGvSga hJAA== X-Forwarded-Encrypted: i=1; AHgh+RrFkQdNAkb0MQbC9hP9GDplYX97gyOClDCvzCfXldNZr3kVmAN0llTOHTWziKDxgN6pn6CWxF8E/38=@vger.kernel.org X-Gm-Message-State: AOJu0YxoXbxrwiBLeqqU6AZ5r1eTICvfXxjZfwj9cR0nrSN+9wGu1rDb IWFFZVbrDnb2XVq8GB81bDCKNyuykIF2/gZWlPB32MYjMRqD8BB3xdb5Z0MkWfSEmTd83UFw0Q6 eKcoI5Q== 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-doc@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.