Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1290874lqj; Mon, 3 Jun 2024 17:14:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXUHFs3XEjAxElnZe3cD1mgBIEgB9ia8zSNT2LDzULbQnB0pPIRkkULgcnmhGYLWghFJkH5EZllvH0TtUMuxvnvPEKbG0elwtnEp9IpeQ== X-Google-Smtp-Source: AGHT+IFnlecG9UiJbfk/WQvJlh9eWkI90RFSg68bGP1hQSVC6XwPqsC3FUTI4AROB5J8DSPN3xoD X-Received: by 2002:a19:5f1b:0:b0:51c:d6c9:e9a3 with SMTP id 2adb3069b0e04-52b89599d0bmr5911038e87.17.1717460068670; Mon, 03 Jun 2024 17:14:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717460068; cv=pass; d=google.com; s=arc-20160816; b=Pbf8hglyU1r9q3iNuFuTU9AcWQWxQLh5pOWqGRx+NhV+tXSee+nDLkmT0PUXNXUGB6 adkQvqAG/UW3CBr0xadvxsVkDJ7GJm5V+Ju85xaSK1uTl4M1XwaHCzVgwYsppu1V5zQg ImgrxWT8Y8CFEyfpfDjXOhoQCbLMCiMTzxm/zqtBdV4yh6Ynnfk1KqlBpNQiGCpxQpJ/ MWAFLTnM9784Z+6chmzJsKt5HBY50hgobQdXNUhPl/AekiLHHk2FZZD28eS2VkgasKyB wRJgc3vtQvZzoLoIPNpASb/zBdJvIRB/jhLGSyqu5Q59Qw++c6mS9TAeEIL03j6UI0ZI PMmw== 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=6ccoeN8AjVVO4XJ0biqZf4iXVDLjkh53CRVPkhtuV/k=; fh=U3w0DzvBu/RforHSv0gpHxYJnpvr3mhp1NfRkCuINxs=; b=e/llliP6hT3uAbMx9aF6tMlalG7jbXpvbp04GrPHL4PaAlZtdF3lGv33dWwRCujg8r GZLRYtMLsfvNDjQbrY6L4wrNftZjl/JqVnW6DtpkmhJSaSbTdrNd2eVTV6wN2Oq6mJ9B QanJgcwKiREIbsSBeD9lWoltWYxFp7RuOhonZZo6QKtefHdw9DiPS3nztjYscWeeq2ft p7tQkb8AZxiRopzZoS4h2+UuVp/RueSy0PucKS7tc0Einl6AxUXkCi5riPiSJBdMc1ZM 7FW7c+XBRyX8Qvq11Z7F9cA43D9pZzexLZJpL6CeUSbofoT7M52t6LSeh9kEtzkD8Xyo 70GQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=X9XptLrH; 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-199862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199862-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31c63077si4297570a12.282.2024.06.03.17.14.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 17:14:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=X9XptLrH; 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-199862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199862-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 3933D1F23E59 for ; Tue, 4 Jun 2024 00:14:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B28B3ECC; Tue, 4 Jun 2024 00:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X9XptLrH" 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 40A69633 for ; Tue, 4 Jun 2024 00:14:14 +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=1717460055; cv=none; b=WU40e9L6Tk4pSdeNz7dsZKfM2o7/Rt9e9bltXbSFma5ZBvB2TdRPjNyJ3ZZqDjyW9U2oSMHRcxYxCw9rzqgU1CJ51GQfZ6qXRnp2FdvQ12zPuCJPVDvpNHH5wy8LzixPtvQQg9nRBniY8FgJAIJWqOTCJq2pB5WcHQ+sAFbhECs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717460055; c=relaxed/simple; bh=O7IEydvJikvy1VRybXHIgo7DsDUOiB9JWN05ebOrWWE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IHP8cioBIyB5R+V7FFpJLJDHFmuLGMUHGmcQOXeE3UkFRHeYjT25Kc9CELt+x2C9HIcw1q4ehNC84ua3R29bZGv4wZacC/hSOETCumpxUBQH/fc9yo2rAXvLbtLXgAgPoaoin1FZUYHxkUl9B10Ef14GJuipbwGdDzyhOVTRkgk= 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=X9XptLrH; 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-62a080977a5so86451047b3.0 for ; Mon, 03 Jun 2024 17:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717460053; x=1718064853; 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=6ccoeN8AjVVO4XJ0biqZf4iXVDLjkh53CRVPkhtuV/k=; b=X9XptLrHrFkIYZlPmilaKLHsQBTqhE2zNUyKiRS7SGdFCM23kPCm4Uw5dXIpVPfCEZ fSN5hmksS1uFQjE7BuKMosCP4IjDp8C9+hgy7vNvgcOEgNmklLyQtwGUZVoqk+aZBS1M JGBQfj5fNkTZhI6aErI/y8ipLA2YIz+UfuZT0cmJUrHXwzB03JxwmKo4Co/BJE0f2Zd/ k2aw5y8QhU3NspXOJYBvkXiJMPIiEmMqJoaz368d+QqwNGB/fL6UF3d2Uu6o+fWSGWoN Xe1AC0KQtHElahdWpR2dvIRm4kk1jLlr60c52BLcM6xHl10zkTmH4inlq18dlgemGB4w Kw3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717460053; x=1718064853; 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=6ccoeN8AjVVO4XJ0biqZf4iXVDLjkh53CRVPkhtuV/k=; b=BI2k1A3cbrBvix41cWXhOJ5isy3edy7vM3jmZCt+fje2FukWOV6GQJKqap3I5Y82TU MmgqK3bgemzF9rR79d7MqBdNEhIVnGuAKaxiksPp28xHVazfYIHr8P2KOYL781lcUgTO qFsMY5NaM00cnUqFOYkHg20DlLJbbPnY3FdO9eitzKtlHPBdvLnygfnlOWSR9tScokVT FalAm+AjCESzVrIVDurba3bSqd9Uwg4dVrllqOcKI+7hgjhS19FoCHHkMbvegi1QeZCt h9L+KrX9Kq0M9FlQu/YeldbewIzuzYr4H8n3sr6ozi23BTI7NlkdpMvsm9Zd2EftfKxx 1yVw== X-Forwarded-Encrypted: i=1; AJvYcCX6wuKJtx8RsWzQV1sdiOWNiHu3ArRQWfyL/S3N/s3Ps8LTxOe1rGV4SoMV9791vZaiqHr9l/JyCoKQnlVR8ma4/iLO9zwcD9IhrJF4 X-Gm-Message-State: AOJu0Yx8PmrXWEGXv5fA9xmx80wJDhqZ2vXGWDMpQckZ4GxAqZgkI2ME 9Xnp8tT9jVJwmHKkUX6dGlPQFAjg9uD9nfLlEwlSIOFFTwDwXMzuEOsQ7+0DbjJHLDO+YzS+mwg xSg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:3506:b0:627:a962:4252 with SMTP id 00721157ae682-62c7983febcmr26991967b3.7.1717460053326; Mon, 03 Jun 2024 17:14:13 -0700 (PDT) Date: Mon, 3 Jun 2024 17:14:11 -0700 In-Reply-To: <20240429155738.990025-5-alejandro.j.jimenez@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> 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 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. And avic_unaccelerated_access_interception() and handle_apic_write() don't necessarily have anything to do with injection. On the flip side, the slow paths for {svm,vmx}_deliver_interrupt() are very explicitly unnaccelerated injection. It's not entirely clear from the changelog what the end goal of this stat is. A singular stat for all APICv/AVIC access VM-Exits seems uninteresting, as such a stat essentially just captures that the guest is active. Maaaybe someone could glean info from comparing two VMs, but even that is dubious. E.g. if a guest is doing something function and generating a lot of avic_incomplete_ipi_interception() exits, those will likely be in the noise due to the total volume of other AVIC exits. > }; > > struct x86_instruction_info; > diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c > index 4b74ea91f4e6..274041d3cf66 100644 > --- a/arch/x86/kvm/svm/avic.c > +++ b/arch/x86/kvm/svm/avic.c > @@ -517,6 +517,8 @@ int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu) > kvm_apic_write_nodecode(vcpu, APIC_ICR); > else > kvm_apic_send_ipi(apic, icrl, icrh); > + > + ++vcpu->stat.apicv_unaccelerated_inj; > break; > case AVIC_IPI_FAILURE_TARGET_NOT_RUNNING: > /* > @@ -525,6 +527,8 @@ int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu) > * vcpus. So, we just need to kick the appropriate vcpu. > */ > avic_kick_target_vcpus(vcpu->kvm, apic, icrl, icrh, index); > + > + ++vcpu->stat.apicv_unaccelerated_inj; > break; > case AVIC_IPI_FAILURE_INVALID_BACKING_PAGE: > WARN_ONCE(1, "Invalid backing page\n"); > @@ -704,6 +708,9 @@ int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu) > > trace_kvm_avic_unaccelerated_access(vcpu->vcpu_id, offset, > trap, write, vector); > + > + ++vcpu->stat.apicv_unaccelerated_inj; > + > if (trap) { > /* Handling Trap */ > WARN_ONCE(!write, "svm: Handling trap read.\n"); > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index f10b5f8f364b..a7487f12ded1 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -5657,6 +5657,8 @@ static int handle_apic_write(struct kvm_vcpu *vcpu) > { > unsigned long exit_qualification = vmx_get_exit_qual(vcpu); > > + ++vcpu->stat.apicv_unaccelerated_inj; > + > /* > * APIC-write VM-Exit is trap-like, KVM doesn't need to advance RIP and > * hardware has done any necessary aliasing, offset adjustments, etc... > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 03cb933920cb..c8730b0fac87 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -307,6 +307,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { > STATS_DESC_IBOOLEAN(VCPU, guest_mode), > STATS_DESC_COUNTER(VCPU, notify_window_exits), > STATS_DESC_IBOOLEAN(VCPU, apicv_active), > + STATS_DESC_COUNTER(VCPU, apicv_unaccelerated_inj), > }; > > const struct kvm_stats_header kvm_vcpu_stats_header = { > -- > 2.39.3 >