From patchwork Sat Aug 28 00:35:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12462999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A45F1C41537 for ; Sat, 28 Aug 2021 00:36:48 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4FFB860ED5 for ; Sat, 28 Aug 2021 00:36:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4FFB860ED5 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.174038.317495 (Exim 4.92) (envelope-from ) id 1mJmKi-0003pq-UO; Sat, 28 Aug 2021 00:36:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 174038.317495; Sat, 28 Aug 2021 00:36:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mJmKi-0003pj-R1; Sat, 28 Aug 2021 00:36:28 +0000 Received: by outflank-mailman (input) for mailman id 174038; Sat, 28 Aug 2021 00:36:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mJmKg-0003pb-Rm for xen-devel@lists.xenproject.org; Sat, 28 Aug 2021 00:36:26 +0000 Received: from mail-qt1-x849.google.com (unknown [2607:f8b0:4864:20::849]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f479d730-3649-468b-9304-36bd369216fa; Sat, 28 Aug 2021 00:36:25 +0000 (UTC) Received: by mail-qt1-x849.google.com with SMTP id b15-20020a05622a020f00b0029e28300d94so802304qtx.16 for ; Fri, 27 Aug 2021 17:36:25 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f479d730-3649-468b-9304-36bd369216fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:message-id:mime-version:subject:from:to:cc; bh=xh3b83AHgc+X5acCCZf2iVRK+ee8SLHX2uHx4t+xrBY=; b=FsrBDBj81I24PUYsfqY9aNe2Br6Cge4C10V9fErKyzcL9jN9JzP/kqqqUHGaBFgQcQ 0U9g5lP31TKw2LT3YjTlFAgoG4AS3SMwwYaB+iZ9VL+rH1PuDacZvkVF5TZDPvt+SCVp hoVnB9YrhsLy30buyfkioR3VRr/U9QgKrM+qQnkI0aZ8yrDkdgGSixnrY69JIAMGRumH CIa10muamcOBBpjShGeSCvzY0V1rXxFeRJk/BexUgt5cyg06R0PXRjlCeTWZrE9Yduwb tvUde2o7UVIgOctvxLjj8VW7xpdvOez/m4ccG77zN+autZ2tCUck8ZbNdlcpaKwRcScv Xlrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:message-id:mime-version:subject :from:to:cc; bh=xh3b83AHgc+X5acCCZf2iVRK+ee8SLHX2uHx4t+xrBY=; b=RzHpgJk9tO9nuhzHtxmkf1eWQGA2GlLTOqmVoD96Bc8oXYShps4RrE7EG465XlR04r 31J0clLQWMQg9aqG3SE12cZOS1GPFVVEoS/URBUmaFXgZjA4q3PwQVO817NoZHLG/1SO sBSQrfIgYMdWBwifotwhXL8jMrQA0pdh4rR25KUlvkQKJCHYofrVEufta4WHHTW+OGes 9jFp9o4yA2KLe+FY+NbPtUbJMaSzVIHW+YNVkcxiQ/KyWdb/9Z+xK1ZqZwTnYPZCVozn TfFaMcBCOUNkZXaFLRYHPHjUBApIfhYUzLr69yNuuQi5czoFDUcLvQ5F0FopRIUNAw72 BN3Q== X-Gm-Message-State: AOAM533fwcQH1aBRlKclWcEb/5KQrOjtekaFYOPjpJ46063kdxlYDlOC QADlM9Evetf8J6uyg5keVpgu0sc/Ekw= X-Google-Smtp-Source: ABdhPJzkOydjwKSx1IUjIGSvBy+QMF11RiN4xe9UgjoUhzwRgFrcyVUOeAZyVTnBYwiNIqVlWoCONvUze1Q= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:f66c:b851:7e79:7ed4]) (user=seanjc job=sendgmr) by 2002:a05:6214:10c4:: with SMTP id r4mr12642407qvs.58.1630110985252; Fri, 27 Aug 2021 17:36:25 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 27 Aug 2021 17:35:45 -0700 Message-Id: <20210828003558.713983-1-seanjc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [PATCH v2 00/13] perf: KVM: Fix, optimize, and clean up callbacks From: Sean Christopherson To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Will Deacon , Mark Rutland , Catalin Marinas , Marc Zyngier , Guo Ren , Nick Hu , Greentime Hu , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , Thomas Gleixner , Borislav Petkov , x86@kernel.org, Paolo Bonzini , Boris Ostrovsky , Juergen Gross Cc: Alexander Shishkin , Jiri Olsa , Namhyung Kim , James Morse , Alexandru Elisei , Suzuki K Poulose , "H. Peter Anvin" , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Stefano Stabellini , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, Artem Kashkanov , Like Xu , Zhu Lingshan This is a combination of ~2 series to fix bugs in the perf+KVM callbacks, optimize the callbacks by employing static_call, and do a variety of cleanup in both perf and KVM. Patch 1 fixes a mostly-theoretical bug where perf can deref a NULL pointer if KVM unregisters its callbacks while they're being accessed. In practice, compilers tend to avoid problematic reloads of the pointer and the PMI handler doesn't lose the race against module unloading, i.e doesn't hit a use-after-free. Patches 2 and 3 fix an Intel PT handling bug where KVM incorrectly eats PT interrupts when PT is supposed to be owned entirely by the host. Patches 4-7 clean up perf's callback infrastructure and switch to static_call for arm64 and x86 (the only survivors). Patches 8-13 clean up related KVM code and unify the arm64/x86 callbacks. Based on "git://git.kernel.org/pub/scm/virt/kvm/kvm.git queue", commit 680c7e3be6a3 ("KVM: x86: Exit to userspace ..."). v2 (relatively to static_call v10) - Split the patch into the semantic change (multiplexed ->state) and introduction of static_call. - Don't use '0' for "not a guest RIP". - Handle unregister path. - Drop changes for architectures that can be culled entirely. v2 (relative to v1) - Drop per-cpu approach. [Peter] - Fix mostly-theoretical reload and use-after-free with READ_ONCE(), WRITE_ONCE(), and synchronize_rcu(). [Peter] - Avoid new exports like the plague. [Peter] v1: - https://lkml.kernel.org/r/20210827005718.585190-1-seanjc@google.com v10 static_call: - https://lkml.kernel.org/r/20210806133802.3528-2-lingshan.zhu@intel.com Like Xu (2): perf/core: Rework guest callbacks to prepare for static_call support perf/core: Use static_call to optimize perf_guest_info_callbacks Sean Christopherson (11): perf: Ensure perf_guest_cbs aren't reloaded between !NULL check and deref KVM: x86: Register perf callbacks after calling vendor's hardware_setup() KVM: x86: Register Processor Trace interrupt hook iff PT enabled in guest perf: Stop pretending that perf can handle multiple guest callbacks perf: Force architectures to opt-in to guest callbacks KVM: x86: Drop current_vcpu for kvm_running_vcpu + kvm_arch_vcpu variable KVM: x86: More precisely identify NMI from guest when handling PMI KVM: Move x86's perf guest info callbacks to generic KVM KVM: x86: Move Intel Processor Trace interrupt handler to vmx.c KVM: arm64: Convert to the generic perf callbacks KVM: arm64: Drop perf.c and fold its tiny bits of code into arm.c / pmu.c arch/arm/kernel/perf_callchain.c | 28 ++------------ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kvm_host.h | 13 ++++++- arch/arm64/kernel/perf_callchain.c | 28 +++++++++++--- arch/arm64/kvm/Makefile | 2 +- arch/arm64/kvm/arm.c | 11 +++++- arch/arm64/kvm/perf.c | 62 ------------------------------ arch/arm64/kvm/pmu.c | 8 ++++ arch/csky/kernel/perf_callchain.c | 10 ----- arch/nds32/kernel/perf_event_cpu.c | 29 ++------------ arch/riscv/kernel/perf_callchain.c | 10 ----- arch/x86/Kconfig | 1 + arch/x86/events/core.c | 36 ++++++++++++++--- arch/x86/events/intel/core.c | 7 ++-- arch/x86/include/asm/kvm_host.h | 8 +++- arch/x86/kvm/pmu.c | 2 +- arch/x86/kvm/svm/svm.c | 2 +- arch/x86/kvm/vmx/vmx.c | 25 +++++++++++- arch/x86/kvm/x86.c | 58 +++++----------------------- arch/x86/kvm/x86.h | 17 ++++++-- arch/x86/xen/pmu.c | 32 +++++++-------- include/kvm/arm_pmu.h | 1 + include/linux/kvm_host.h | 10 +++++ include/linux/perf_event.h | 26 ++++++++----- init/Kconfig | 3 ++ kernel/events/core.c | 24 ++++++------ virt/kvm/kvm_main.c | 40 +++++++++++++++++++ 27 files changed, 245 insertions(+), 249 deletions(-) delete mode 100644 arch/arm64/kvm/perf.c