Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1107562lqt; Fri, 7 Jun 2024 08:11:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpIfuXVPRF54uKKUiShvxba4AOc71OjDu1LtMLwApgfMr9v13aG9cKKH7XkvGJehdjLEwBYjTyHpUV08V7i8bMfC+HWDnmhNu1f5B01w== X-Google-Smtp-Source: AGHT+IEJOqmntI7XqnHayp8+uasxYux5LINpcXlShyNsk0ambhOI9UBQL+bdpYiYunQfllKSOjUS X-Received: by 2002:a19:7406:0:b0:529:b023:6b9d with SMTP id 2adb3069b0e04-52bb9f7a181mr2074707e87.16.1717773102778; Fri, 07 Jun 2024 08:11:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717773102; cv=pass; d=google.com; s=arc-20160816; b=fCAr6PXXTpBtg4OwwutTBB2G6tlQD0j1GGGBHdY/vHYoVgWpn9lhwvVIw4EIzdQFwo ULP69hR7FAtAnegJ4177/uiCxEqop3NK9yyTKV4Af2QkE/G/fj4G4cszwhvQ+4RkAUEc YA4J2DyRUYJ5mpdKb+Lu4GJdWxVQ3sd1EDwzE4pMlAKfIP4XZ5SirN2cW1DJ83411Vwf nXschtr5acecL8WSf90ArhXraDOxPCXatP2oPJwzEXuIFAgrgSY+GNRbUN4qrUWJtlTs nzik2aszbwPn3btxO6rM0e8MV1cOOhRJ9TniaFrHDeApYqW7bvkh8bglxTQfJgRHlCMb TjOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=ex2nZHRLv3gtg4nC8Gp/3+MSsGZYhmqvJ3bWYCD2SdY=; fh=OE0y72AZYAtd9VIT0YVZle2ZGjHnobc69UCnDjUrkB4=; b=oD9X1I6lmoQqLi5F0umxhmcYndcgYBbbEM38J1lfT4ql94L5nr4HgAAJx3Xoo/hbqw tMwqnJ31lBwC3dWEyfN1842ghffWiz7CtmIF2eS0yaBew7X7+Q1+a1rXv7Lj6cwwzffk 8AYYVDvjQnRm/J3zWD8nozWVU03yt8JimlpoWjkiCcfV6GBJNcUiM4LPB7++bjrDOJQL U+Qc6gSbAF9JnuLjr/bVFrMGV/Ke+776tf8K9YvmQAyPFMtqg/amnYsVLvQv+o/Qu8eT Oo4c58/9vvZmDj3aUtU2bFdiNA00GJXyrOyZjwKvzDJAM//Np4PK6I0oBEXOSYHA4lrK Mk5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SvCJ05FJ; 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-206355-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206355-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c806db5e5si196451466b.378.2024.06.07.08.11.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 08:11:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206355-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SvCJ05FJ; 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-206355-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206355-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 44B8C1F27CBF for ; Fri, 7 Jun 2024 15:11:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 204521940A5; Fri, 7 Jun 2024 15:11:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SvCJ05FJ" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 A6A2054660 for ; Fri, 7 Jun 2024 15:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773091; cv=none; b=uazboqiVjpGCTZGNczpmM5BNwao+Zn70XBnhUxfBMH5uDyhEAFdItZ8ICL+/72zcVxbjf2PiQGanFKCn22GnSHEa1vRtPVCgM24YS6lPs/XKPygkbxiZYxfwdl5OJpt3AVRYgZg1Y6INdqMrglaXNL5XL8VbZqfjrTRUqkcy728= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773091; c=relaxed/simple; bh=t9H8jpD3p11qwd7sytuCB98EQ9NueIlYwx4Tt8/psKA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qfg2wXNfyBLRI4dgmIlZAkCz2RRMYdE9v7081yE6fMws/T8+5wblmE0WcWi0WKnUDJvrhLtTXWjSFlFUIA50sqqyo7JZRLymjK1bHGx294FAubtoL2IKb/VnQjryOeOiQACjI7Nkc80kXeW41lx1aj0+OJBWJn8DgcPBFFusCXY= 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=SvCJ05FJ; arc=none smtp.client-ip=209.85.128.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-yw1-f202.google.com with SMTP id 00721157ae682-627e4afa326so35975327b3.2 for ; Fri, 07 Jun 2024 08:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717773089; x=1718377889; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ex2nZHRLv3gtg4nC8Gp/3+MSsGZYhmqvJ3bWYCD2SdY=; b=SvCJ05FJlC8gyIyJJNlEX750hi5r1vsRvgrDDw31bITazF6vK0fo7PjcaZ3ku3SwmA Yxd8rf/lBiYwO/p0p736gt/Csz7Xs5l/WKV6hTMR4yhpDgmihJCvuWxFNGdC45oQPK7Y LkGbrsmxpUSCD7yJlwMMuQE+4GPRKtUTnwLQM8PnbHty6LsFuE+r2c3BmxzY8lbQpxlc oBlVVefERlCzuVaEWYQRrzShud77IBPFjBiW3famyoCoC4kqIMz8C88IanotOeM6orqL ODeCekp2AHV17f4yp2HsBHJnynxVsK1ed7zR0TDYsTRQofzdfRVwYDPkODHw3i9Uc3e5 GdUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717773089; x=1718377889; h=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=ex2nZHRLv3gtg4nC8Gp/3+MSsGZYhmqvJ3bWYCD2SdY=; b=mt2m9FgDY6SmAwPyn1j/ECfcIBnmZeGiKKf+xbqo0zh0O45MtEQ6WoFehHh12A72N9 2VqHUfd+gqoPMNQcjDRQANDzuIHBKLkYhOxd3Wqq8KgG+i5zkeicm3QIx1RyinWq7x35 7cLmfsUJPEO+Vn1DBVQP++VjNb40zCcEeDZ7G9i69/kwiVNF8rYXcpX3TwL82h7Uf0rA AI5yfZJXHZCRCziT+Cz+EqrFHQHIIF76pFlXvuqfl+M5gQMmysQblmly7eY/B3Kotajx 9EDnWAQKR4Cus2IPLlBq24GUqWukVLalrhCaMvl/l5D61DVpDdj1FtaY1UpIfxu7tEzE rZfA== X-Forwarded-Encrypted: i=1; AJvYcCWLu9Qjh6sCDf0U+RTyJ3dZcyXHzMkb27Jq3DMt+R7bM2+FF4siQd/iPbjHfPuOd7rMcpm1pB8tjT9OdSfW/bWxW801N2R7rSfL7Jto X-Gm-Message-State: AOJu0Yyf1L6QMFFOsqxmoVE3ljRI9/wfAhb93NO665oBw+XIvDc1YgpZ yFSbhm7AjJcLuEUmKC2JYHkOI9CWCBASQj3zcbXSazhXO0KmEFuGksxAOnh7A6dahnmPSU2xCVC xtA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1248:b0:df4:a393:8769 with SMTP id 3f1490d57ef6-dfaf65ba959mr237734276.9.1717773088585; Fri, 07 Jun 2024 08:11:28 -0700 (PDT) Date: Fri, 7 Jun 2024 08:11:27 -0700 In-Reply-To: <06e6b7c6-ba5d-4fb0-9a77-30ac44f6935a@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240429155738.990025-1-alejandro.j.jimenez@oracle.com> <20240429155738.990025-5-alejandro.j.jimenez@oracle.com> <06e6b7c6-ba5d-4fb0-9a77-30ac44f6935a@oracle.com> Message-ID: Subject: Re: [PATCH 4/4] KVM: x86: Add vCPU stat for APICv interrupt injections causing #VMEXIT From: Sean Christopherson To: Alejandro Jimenez Cc: kvm@vger.kernel.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, suravee.suthikulpanit@amd.com, vashegde@amd.com, mlevitsk@redhat.com, joao.m.martins@oracle.com, boris.ostrovsky@oracle.com, mark.kanda@oracle.com Content-Type: text/plain; charset="us-ascii" On Thu, Jun 06, 2024, Alejandro Jimenez wrote: > On 6/3/24 20:14, Sean Christopherson wrote: > > On Mon, Apr 29, 2024, Alejandro Jimenez wrote: > > > Even when APICv/AVIC is active, certain guest accesses to its local APIC(s) > > > cannot be fully accelerated, and cause a #VMEXIT to allow the VMM to > > > emulate the behavior and side effects. Expose a counter stat for these > > > specific #VMEXIT types. > > > > > > Suggested-by: Paolo Bonzini > > > Signed-off-by: Alejandro Jimenez > > > --- > > > arch/x86/include/asm/kvm_host.h | 1 + > > > arch/x86/kvm/svm/avic.c | 7 +++++++ > > > arch/x86/kvm/vmx/vmx.c | 2 ++ > > > arch/x86/kvm/x86.c | 1 + > > > 4 files changed, 11 insertions(+) > > > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > > index e7e3213cefae..388979dfe9f3 100644 > > > --- a/arch/x86/include/asm/kvm_host.h > > > +++ b/arch/x86/include/asm/kvm_host.h > > > @@ -1576,6 +1576,7 @@ struct kvm_vcpu_stat { > > > u64 guest_mode; > > > u64 notify_window_exits; > > > u64 apicv_active; > > > + u64 apicv_unaccelerated_inj; > > > > The stat name doesn't match the changelog or the code. The AVIC updates in > > avic_incomplete_ipi_interception() are unaccelerated _injection_, they're > > unaccelarated _delivery_. And in those cases, the fact that delivery wasn't > > accelerated is relatively uninteresting in most cases. > > > > Yeah, this was my flawed attempt to interpret/implement Paolo's comment in > the RFC thread: > > "... for example I'd add an interrupt_injections stat for unaccelerated > injections causing a vmexit or otherwise hitting lapic.c" KVM essentially already has this stat, irq_injections. Sort of. The problem is that the stat isn't bumped when APICv is enabled because the IRQ isn't *directly* injected. KVM does "inject" the IRQ into the IRR (and RVI on Intel), but KVM doesn't go through .inject_irq(). For APICv, KVM could bump the stat when manually moving the IRQ from the IRR to RVI, but that'd be more than a bit misleading with respect to AVIC. With AVIC, the CPU itself processes the IRR on VMRUN, i.e. there's no software intervention needed to get the CPU to inject the IRQ. But practically speaking, there's no meaningful difference between the two flows; in both cases an IRQ arrived while the target vCPU wasn't actively running the guest. And that means KVM would need to parse the IRR on AMD just to bump a stat. It'd also be misleading to some extent in general, because when the target vCPU is in its inner run loop, but not actually post-VM-Enter, KVM doesn't kick the vCPU because either KVM or the CPU will automatically process the pending IRQ. I.e. KVM would bump the stat cases where the injection isn't fully accelerated, but that's somewhat disingenuous because KVM didn't need to slow down the vCPU in order to deliver the interrupt. And KVM already has an irq_exits stat, which can be used to get a rough feel for how often KVM is kicking a vCPU (though timer ticks likely dominate the stat). > > And avic_unaccelerated_access_interception() and handle_apic_write() don't > > necessarily have anything to do with injection. > > apicv_unaccelerated_acccess is perhaps a better name (assuming stat is > updated in handle_apic_access() as well)? This is again not super interesting. If we were to add this stat, I would lobby hard for turning "exits" into an array that accounts each individual VM-Exit, though with some massaging to reconcile differences between VMX and SVM. Unaccelerated APIC exits aren't completely uninteresting, but they suffer similar issues to the "exits" stat: a few flavors of APIC exits would dominate the stats, and _those_ exits aren't very interesting. > > On the flip side, the slow paths for {svm,vmx}_deliver_interrupt() are very > > explicitly unnaccelerated injection. > > Now that you highlight this, I think it might be closer to Paolo's idea. i.e. > a stat for the slow path on these can be contrasted/compared with the > kvm_apicv_accept_irq tracepoint that is hit on the fast path. My initial > reaction would be to update a stat for the fast path, as a confirmation that > apicv is active which is how/why I typically use the kvm_apicv_accept_irq > tracepoint, but that becomes redundant by having the apicv_active stat on > PATCH 1. > > So, if you don't think it is useful to have a general > apicv_unaccelerated_acccess counter, I can drop this patch. The one thing I can think of that might be somewhat interesting is when kvm_apic_send_ipi() is invoked to deliver an IPI. If KVM manually sends the IPI, and IPI virtualization is enabled (on-by-default in AVIC, and an add-on feature for APICv), then it means IPI virtualization isn't doing it's job for whatever reason. But even then, I'm doubt it's worth a stat, because it likely just means the guest is doing something weird, not that there's a problem in KVM.