From patchwork Fri Aug 27 00:57:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12461055 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 0E9E1C432BE for ; Fri, 27 Aug 2021 01:05:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 BE87460FD9 for ; Fri, 27 Aug 2021 01:05:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BE87460FD9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References :Mime-Version:Message-Id:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ih0bKZFUBk53X9lzDPZaaJe+nBVVbhh+YWA7NkV1sQM=; b=ds9R97Jk90wM8z G+09/OoU1d0JeJrGa+CjMQ3hkRTLNQ5k+5shiISC2g6xONeTpb8qKTSLt7R0RpOhPnLsK6k1p6k7/ oVluJHKykTriKaqf/ybuOdO/GBKp7CToY/PprJGUc/43MkD48OWhk4pI5BiVX8/x7rcTnSXI5QlXL Cp6LqsaiLQegMVGb0tchv8X4ZzGc2qKrPNWSc4SvpNfzwiBfMvXHbre917Zo7G7QyFFf1eGE9/Jcm W9OKppDY+t/ysoUnpZsMeBblk2ZfIy3mXvWeaWpmMqHnEDMq1EhqwzkFG/bbHNm4047A81BBF1QxY bvzpdurmckNAmJBLoOHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJQH1-00BDed-Oc; Fri, 27 Aug 2021 01:03:12 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJQBp-00BAxO-39 for linux-arm-kernel@lists.infradead.org; Fri, 27 Aug 2021 00:57:53 +0000 Received: by mail-yb1-xb49.google.com with SMTP id v126-20020a254884000000b005991fd2f912so4926039yba.20 for ; Thu, 26 Aug 2021 17:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=AFHcFLQ8Zudn3D234yQQ371MlX0hPffSTnop5clNbU4=; b=ehODs2sAzX4fmqGdkUXhOCuacyAsZ5WG5XMN79bjP+xq4RU4v9fT+sBLKRTlQqGWyX q30luLe7UbUT+k5DL/N9U4aU2TEa+qPeGqAJxEBE/FVgE0CuiF3raXC1RXOK3ImBGaQ4 XbKMz4w/DkAC9W9hss3rUtWCAWdzbERpB661AM+dQQmPgaw7Ftx+tH6bG8AYsTaZ9CDU e02FAinIj3+x9EA64fOdiwehQIAyNOzTqpYk8MnCh+cFqm78JcgPcKiioGpdAXvwto5l kIPH0qjJWMM4k2bYrS2zDHxLCqBbRaCfrumPTD8MLrYqYErmy2b3iS7uHQauGeKAtamE EuYw== 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:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=AFHcFLQ8Zudn3D234yQQ371MlX0hPffSTnop5clNbU4=; b=TO/u3DkSCWxD6bXBLXFxvhD7cXGIN/2B25SYbCOdnOmZcK6X2tGN71ZPlaKutFilb2 EvEtFFyo2LigPDB4nvMs3oTPGGiBc76QNXdDEELaf1KXbg2qcbg2x986lvbmc4LEVSt8 LfIQ7tdnnMN3+9DFNprH7m9v1rc8N3/ZBxCPqYP/EOwaKWR3g3VGpJvCPk13ZRNDr7yz 6cqiHCBoDhAYidGtX5FSTaxQ0R9W2L+ND754nb09fqEH1uPILg09sENFqVyEJaawpisk XuXC8XC2yaHLp4yjmIS255BYhPGGln+swYwA3+OBtZI569OPG5lkoqx8/dnP+Z0ejWCE olNw== X-Gm-Message-State: AOAM531tJrSNaOj7oWvsCz3r7ojQEN5p7MuwfG4eZXilBvKvvlK9UQml bWnSgo+3WzYEUBRQfSZx/EVPSw97Y70= X-Google-Smtp-Source: ABdhPJxdtTMoWPCFq9FJTrWuwV5L/MyoyJcLiUL8JKOdEyDnebSuapnzs9qVktMCvhy616hB+yWZoBPXnlo= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:90:200:c16c:db05:96b2:1475]) (user=seanjc job=sendgmr) by 2002:a25:7a03:: with SMTP id v3mr2037918ybc.202.1630025867497; Thu, 26 Aug 2021 17:57:47 -0700 (PDT) Date: Thu, 26 Aug 2021 17:57:11 -0700 In-Reply-To: <20210827005718.585190-1-seanjc@google.com> Message-Id: <20210827005718.585190-9-seanjc@google.com> Mime-Version: 1.0 References: <20210827005718.585190-1-seanjc@google.com> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [PATCH 08/15] KVM: x86: Drop current_vcpu in favor of kvm_running_vcpu From: Sean Christopherson To: Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210826_175749_201864_59FBC608 X-CRM114-Status: GOOD ( 15.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now that KVM registers perf callbacks only when the CPU is "in guest", use kvm_running_vcpu instead of current_vcpu to retrieve the associated vCPU and drop current_vcpu. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 12 +++++------- arch/x86/kvm/x86.h | 4 ---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d4d91944fde7..e337aef60793 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8264,17 +8264,15 @@ static void kvm_timer_init(void) kvmclock_cpu_online, kvmclock_cpu_down_prep); } -DEFINE_PER_CPU(struct kvm_vcpu *, current_vcpu); -EXPORT_PER_CPU_SYMBOL_GPL(current_vcpu); - static int kvm_is_in_guest(void) { - return __this_cpu_read(current_vcpu) != NULL; + /* x86's callbacks are registered only when handling a guest NMI. */ + return true; } static int kvm_is_user_mode(void) { - struct kvm_vcpu *vcpu = __this_cpu_read(current_vcpu); + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); if (WARN_ON_ONCE(!vcpu)) return 0; @@ -8284,7 +8282,7 @@ static int kvm_is_user_mode(void) static unsigned long kvm_get_guest_ip(void) { - struct kvm_vcpu *vcpu = __this_cpu_read(current_vcpu); + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); if (WARN_ON_ONCE(!vcpu)) return 0; @@ -8294,7 +8292,7 @@ static unsigned long kvm_get_guest_ip(void) static void kvm_handle_intel_pt_intr(void) { - struct kvm_vcpu *vcpu = __this_cpu_read(current_vcpu); + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); if (WARN_ON_ONCE(!vcpu)) return; diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 4c5ba4128b38..f13f15d2fab8 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -393,11 +393,8 @@ static inline void kvm_unregister_perf_callbacks(void) __perf_unregister_guest_info_callbacks(); } -DECLARE_PER_CPU(struct kvm_vcpu *, current_vcpu); - static inline void kvm_before_interrupt(struct kvm_vcpu *vcpu, bool is_nmi) { - __this_cpu_write(current_vcpu, vcpu); WRITE_ONCE(vcpu->arch.handling_nmi_from_guest, is_nmi); kvm_register_perf_callbacks(); @@ -408,7 +405,6 @@ static inline void kvm_after_interrupt(struct kvm_vcpu *vcpu) kvm_unregister_perf_callbacks(); WRITE_ONCE(vcpu->arch.handling_nmi_from_guest, false); - __this_cpu_write(current_vcpu, NULL); }