From patchwork Thu Aug 1 04:58:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13749538 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 918EA149C4B for ; Thu, 1 Aug 2024 04:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722488381; cv=none; b=YIoySkQrNqEBz1OIdVDS1xkJ6hblgf6bwFqR/Byp84cQQuzLpsq+sPpI2XskuM7feLJsQyTcrokr3AieiBpLsYgvqiEmvW2F5n9S3/kAdKNNgRD5byjNrUlTftokZ9z89bLusZ47/c4tNgZiqE3z9M8j0WtbGd9ZPQwO8WjtNCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722488381; c=relaxed/simple; bh=EFtuBGgmb/ySfNg1lLBNQXQnQVSSdGAckiedsEFvN8M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IWdp9rFduksrSav6AN36aAbyX7XJ0wIb4dGMFnYBHYvvyqBhjUrp2114NTpa5c7LAdexwjX46YiYnm1vLKAkpkc/Cbij7XP1+pxw7JQ5e6miQpT3Fci0tkb94zzEo/9dv5FRKVjzN/7NLWr453v5ECm/JsD3RsnPHV5XwBmuar8= 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=FlxFcygg; arc=none smtp.client-ip=209.85.128.201 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="FlxFcygg" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-64b70c4a269so121799267b3.1 for ; Wed, 31 Jul 2024 21:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722488379; x=1723093179; 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=w7uRuuJLWNcIJX8XquVv1gmL4i5q3RaqambFEsShWAg=; b=FlxFcyggeevJ+sTlFpLPseM7g1KX1TG9XAAt2WTKvgwdcGd7MblmXZNqNb6YeFuwSJ 2DHbeSjKhVDQgzRwayvuV0eVqXOQLIw7lkI0bYjbPyWj8AJaGJQt8i/W+WKiLu7HjWUQ M8OrwQwDd7QQ2kdNlEJhDi9iatOuzLQdkhbi/Po8bhAWE1+jGOtvo25hiIouw+yOMnVy eaA4LL6uGIab9jSggmKawineORuMK9x3XbndKvNhujJz14y8LBWA0r3as4o7UFEOd6hv NCLOkC3GlHM5s3t4OiJ8vCQAANG5QQH81vVgic9HtMlB12aCLqbcHP5gypSWMUdBbnjv St3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722488379; x=1723093179; 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=w7uRuuJLWNcIJX8XquVv1gmL4i5q3RaqambFEsShWAg=; b=gpuV3JGVks/eY3UMT3DI0bHOdlq9AuVnvPYmij1v+7VOeN3S43Cszw0uWaymDrGYar JvC1pAZHm/GwvhsOlHKeRMDZvsWYr3xi6FfRq9eFtvPl5XpIrVZgsRlcyKs9qJkLRoiK XtBhY/OY7wyJBNu62YEUTczTc9QO24xp40MROnKbjDYZgGy14Lq8K0BI0U5ngoeXWvBP Trcr8j3pmw5myQ1/bLgQXL4VONMU1KB7BfMJs4o6/ipY/v3vFWOhz68JO1C+m1V9VW4g GE8XponUwbWPimx0cdXfEANwUopZ9EdYE6veYS8S8cKhUblay46FG7nfQADY687x8tnd ex3A== X-Forwarded-Encrypted: i=1; AJvYcCXdYMP3N1eWJcnfdhFQGeCso/CE5HuZBkSQzsXUO1QgsL4RnV5aslsb138mH9OZaFfNbNJMR0T8gSL9f4KN8HhFTYOg X-Gm-Message-State: AOJu0YxsVvYIiKaQ1bHogNgbW+9jx0uObrGAwsaBpGbqU/9f+Hf9dsLN xgUMtvS6PPAMgKxGeLg/MUNj4Dn0+RuBumxWqVDpJnFYKhCf6ucl51h+5weywMxB0Ddw/+qbmBZ iStykPA== X-Google-Smtp-Source: AGHT+IHOUzg+IUPvsg1EhMzy5wRuwEGHHgmUm7eoY+LS5vO9f74Mpw915QluvDl83oVdZltRnH9hWIucwB8U X-Received: from mizhang-super.c.googlers.com ([35.247.89.60]) (user=mizhang job=sendgmr) by 2002:a05:690c:ed2:b0:64b:5dc3:e4fe with SMTP id 00721157ae682-6874abdc89cmr263197b3.1.1722488378564; Wed, 31 Jul 2024 21:59:38 -0700 (PDT) Reply-To: Mingwei Zhang Date: Thu, 1 Aug 2024 04:58:24 +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-16-mizhang@google.com> Subject: [RFC PATCH v3 15/58] perf/x86: Support switch_interrupt interface 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 From: Kan Liang Implement switch_interrupt interface for x86 PMU, switch PMI to dedicated KVM_GUEST_PMI_VECTOR at perf guest enter, and switch PMI back to NMI at perf guest exit. Signed-off-by: Xiong Zhang Signed-off-by: Kan Liang Tested-by: Yongwei Ma Signed-off-by: Mingwei Zhang --- arch/x86/events/core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 5bf78cd619bf..b17ef8b6c1a6 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2673,6 +2673,15 @@ static bool x86_pmu_filter(struct pmu *pmu, int cpu) return ret; } +static void x86_pmu_switch_interrupt(bool enter, u32 guest_lvtpc) +{ + if (enter) + apic_write(APIC_LVTPC, APIC_DM_FIXED | KVM_GUEST_PMI_VECTOR | + (guest_lvtpc & APIC_LVT_MASKED)); + else + apic_write(APIC_LVTPC, APIC_DM_NMI); +} + static struct pmu pmu = { .pmu_enable = x86_pmu_enable, .pmu_disable = x86_pmu_disable, @@ -2702,6 +2711,8 @@ static struct pmu pmu = { .aux_output_match = x86_pmu_aux_output_match, .filter = x86_pmu_filter, + + .switch_interrupt = x86_pmu_switch_interrupt, }; void arch_perf_update_userpage(struct perf_event *event,