From patchwork Thu Aug 1 04:58:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13749550 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 058B414B97B for ; Thu, 1 Aug 2024 05:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722488403; cv=none; b=KdtY+DDWSspvRO7+l54vvyhlNiUlNtvaGGvf/3L4ysCnxJnQvRq4h1MZdTX5ShYSYbbHz1l+HX8k2oujzs4l/J3uu/X4qpowfMWznLwQhANXNEGqQgfwb/DlprieSbN1IF/sPtFVqre5HeN9JKKN22OSGMHtOH9i53Il3i7+6v4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722488403; c=relaxed/simple; bh=jVaOpdzGgUeZCcxUSgcRGcOgS5BCijhoj9k5blSwf0Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kxxJ2UTK3gwk9xUgHqf7bOM8q9Fi63GgoTt2MO97nS8QzNt7CFUSPU3I6drLsvefNgu1KIdRNVOmeOVIIM/p8wuKSxK6prowbYoC3JIXnV3i7Ny7QLNqpE1WCSTJ4scT8+safnlo/G3dO93ZfaKojqLqXDIIedWabdFMUH9xQms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mizhang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ONCBjSsO; arc=none smtp.client-ip=209.85.216.73 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--mizhang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ONCBjSsO" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2cb4d02f34cso6565431a91.3 for ; Wed, 31 Jul 2024 22:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722488401; x=1723093201; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=KYRCskJ7zvPTDOVf+/zrSTGljeKv/UQQeog2dK9opJ8=; b=ONCBjSsO39j+KcJ1+C/v+zc+55Rn0yfY7UOCXIdP7kw2OPP5JVG8ETel9pgN0Ap2yb y0uY7fER6HIWVt+wXZbxNQMX2ol/2cm9TH/nM0QhlyDSmcVJVYMkSlWl+jbz1Ul9heqC IRSXwWLqersa7G5NOTXZvn/CuPZlH7JQS19xNLFSGNSZbuYkdo8Br8QhARgtkCTYAlkB PTz1M67M845P495GsvaFabMPTZ1ae9EFLXrgGOw+cZwob8NL23qC+/P7+b6cJLxr4gdS IFpt6gZt5GrG9F2oYboEURwbHc4KMj710ypIIJ/F4Pt1YLV66iZpkjZ/uLdl7bOp62Rj s2PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722488401; x=1723093201; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KYRCskJ7zvPTDOVf+/zrSTGljeKv/UQQeog2dK9opJ8=; b=q6N7zHh1PXI5uGlw04og/AuoWF44wQb3SgY+Ha4PpBmJYAumvgmGmjaccjUeVl+TfS 1DqFkAaxsfOq8Lqheb65m+L/YhjQ53dx7wM/4st5PlYiSt/bKRJfoTZkTV9RxdKmsP2O LLqz/f7kw0LKqtI0y9Re7oZv8CjYKWZk1mwLhscfE+IE7zQhWjsAPU3hizNNu2Sab4oi qJI3KuLqxjfWImIMdoqDT3nFpf0OdspPQss3Z2Alcwn+Jk1insT99uDH9/Dm5QRIulBn ysOli6bm5ADNI9gt+PbOAXcXYFO/obh/eWCMjEM2OotDJuxy4v1w7P+yztEbrkZnqvwa Igvw== X-Forwarded-Encrypted: i=1; AJvYcCX7LrN/JyKfilbNsfhQR8zKWWm2yU9ia/QhtuBqIwBJNiR1GuGb6v7wjBTdzRolTkxJGxncFDxsL2oLZhgu8korrwr9 X-Gm-Message-State: AOJu0YwJsAqtjkwLdlhTmFHXvAMFXui5BFibF7vnpggrH48ylHZlDDb/ /0Yjsjbv/gMJWXLxGobgU9k7GvvyU2kdxa4/WQyd30KsgVCkhi5R8h+dx4OrMRIjvKJXLMgl/Rm Gs6DNMw== X-Google-Smtp-Source: AGHT+IH6c/VUOVw0ZnJ/ftVLFu6/gHn7JaI8qXMS2BuHKe/7URPK44Ba8bG8xQ88Gi3/jTv0r6E7od1qhri+ X-Received: from mizhang-super.c.googlers.com ([34.105.13.176]) (user=mizhang job=sendgmr) by 2002:a17:90a:9c3:b0:2c9:9208:ee66 with SMTP id 98e67ed59e1d1-2cfe7b656a4mr3116a91.7.1722488401129; Wed, 31 Jul 2024 22:00:01 -0700 (PDT) Reply-To: Mingwei Zhang Date: Thu, 1 Aug 2024 04:58:36 +0000 In-Reply-To: <20240801045907.4010984-1-mizhang@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240801045907.4010984-1-mizhang@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801045907.4010984-28-mizhang@google.com> Subject: [RFC PATCH v3 27/58] KVM: x86/pmu: Create a function prototype to disable MSR interception From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Xiong Zhang , Dapeng Mi , Kan Liang , Zhenyu Wang , Manali Shukla , Sandipan Das Cc: Jim Mattson , Stephane Eranian , Ian Rogers , Namhyung Kim , Mingwei Zhang , gce-passthrou-pmu-dev@google.com, Samantha Alt , Zhiyuan Lv , Yanfei Xu , Like Xu , Peter Zijlstra , Raghavendra Rao Ananta , kvm@vger.kernel.org, linux-perf-users@vger.kernel.org Add one extra pmu function prototype in kvm_pmu_ops to disable PMU MSR interception. Signed-off-by: Mingwei Zhang Signed-off-by: Dapeng Mi Tested-by: Yongwei Ma --- arch/x86/include/asm/kvm-x86-pmu-ops.h | 1 + arch/x86/kvm/cpuid.c | 4 ++++ arch/x86/kvm/pmu.c | 5 +++++ arch/x86/kvm/pmu.h | 2 ++ 4 files changed, 12 insertions(+) diff --git a/arch/x86/include/asm/kvm-x86-pmu-ops.h b/arch/x86/include/asm/kvm-x86-pmu-ops.h index fd986d5146e4..1b7876dcb3c3 100644 --- a/arch/x86/include/asm/kvm-x86-pmu-ops.h +++ b/arch/x86/include/asm/kvm-x86-pmu-ops.h @@ -24,6 +24,7 @@ KVM_X86_PMU_OP(is_rdpmc_passthru_allowed) KVM_X86_PMU_OP_OPTIONAL(reset) KVM_X86_PMU_OP_OPTIONAL(deliver_pmi) KVM_X86_PMU_OP_OPTIONAL(cleanup) +KVM_X86_PMU_OP_OPTIONAL(passthrough_pmu_msrs) #undef KVM_X86_PMU_OP #undef KVM_X86_PMU_OP_OPTIONAL diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index f2f2be5d1141..3deb79b39847 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -381,6 +381,10 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu); kvm_pmu_refresh(vcpu); + + if (is_passthrough_pmu_enabled(vcpu)) + kvm_pmu_passthrough_pmu_msrs(vcpu); + vcpu->arch.cr4_guest_rsvd_bits = __cr4_reserved_bits(guest_cpuid_has, vcpu); diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index 3afefe4cf6e2..bd94f2d67f5c 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -1059,3 +1059,8 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp) kfree(filter); return r; } + +void kvm_pmu_passthrough_pmu_msrs(struct kvm_vcpu *vcpu) +{ + static_call_cond(kvm_x86_pmu_passthrough_pmu_msrs)(vcpu); +} diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h index e1af6d07b191..63f876557716 100644 --- a/arch/x86/kvm/pmu.h +++ b/arch/x86/kvm/pmu.h @@ -41,6 +41,7 @@ struct kvm_pmu_ops { void (*deliver_pmi)(struct kvm_vcpu *vcpu); void (*cleanup)(struct kvm_vcpu *vcpu); bool (*is_rdpmc_passthru_allowed)(struct kvm_vcpu *vcpu); + void (*passthrough_pmu_msrs)(struct kvm_vcpu *vcpu); const u64 EVENTSEL_EVENT; const int MAX_NR_GP_COUNTERS; @@ -292,6 +293,7 @@ void kvm_pmu_destroy(struct kvm_vcpu *vcpu); int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp); void kvm_pmu_trigger_event(struct kvm_vcpu *vcpu, u64 eventsel); bool kvm_pmu_check_rdpmc_passthrough(struct kvm_vcpu *vcpu); +void kvm_pmu_passthrough_pmu_msrs(struct kvm_vcpu *vcpu); bool is_vmware_backdoor_pmc(u32 pmc_idx);