From patchwork Sat May 27 04:02:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13257541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CBE70C77B7E for ; Sat, 27 May 2023 04:04:56 +0000 (UTC) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=uk2eM44Z0M/KhKja8zcws5Colx/8n68OCrvFcLVhl8c=; b=LOs5NhB6My4/58skbehleK+8Cl QkQhnVBhTDgjNvZ4yJKHN4LWt6kO13zNCMgS/mGoKWs5ZiukSPK7elrFK451lceXEhmSkVEXl9fQh GqeBCBi2YeZrN8G5/jtUfwIncpAwor8c2UgelmRudRIaeoM67p3BVWgySvcvdYuks65DwEHA15zOU 4WFj6/GXorJnBhFli41M3qlnN0zUifg/y3ACxBL1HwsdJI9uqP7vg6g9CZgDb/aqyOJPjXFRIbtkn wN/M/ayAfkUCh6Ff7i1IwfxRj15Zf5ftLrGiQqM4tUQsgWkU2LtM3EYYGKDc2hn8fq1dYm63zjf+X tkca+nHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2lAR-004nyW-1z; Sat, 27 May 2023 04:04:35 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2lAO-004nxK-0e for linux-arm-kernel@lists.infradead.org; Sat, 27 May 2023 04:04:33 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56536dd5f79so35521617b3.3 for ; Fri, 26 May 2023 21:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685160270; x=1687752270; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YHzsFiaji3R6LFuYZV3olh4p0y72F3S93sl+y+EJDgg=; b=tXRV7/8vaXCBmNvtRzMV0UTHrROqViarCwmmvALY8aLcpKOu4xRm91QNaRI34zQ8v8 yvLYZ1GU58l5FB/cjDoO40R/Z9cSiIJqqRZNSNv4nT8eeNOM9sC/MTkqBlahXlSb6FOb YEz1zKPvzwS09qQoUfpVwwChYweXdNma7oX+Su9R3sb4Apr9TGtS1UBKzdIVs4NTCGyY efKwRDyUP4EN4C9cvir8Cel8fAQPgCtt3xAF7dx0txEhPQARq6ttu0gHmWMud3io/OYo NtwEmzBt55fsPBQMr0neMCUGj7Kuyq78I2B4S7IX5XU/3LtYh0XQ4L7d7gXjDRmn9kz5 teGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685160270; x=1687752270; 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=YHzsFiaji3R6LFuYZV3olh4p0y72F3S93sl+y+EJDgg=; b=gDZ5wrVcg1F3L+3qDkPe9hZIOsgXCZ/Jl1+eHUcACTYcmXrhdB7xvWrQE0Mr7KqrdE dk2odtbtIn4GMGbji7k+93qyFhs7LH+k4DLSEMGFBg/9Dd/xJQKHEiWa9bcbwoEC92H7 4zYvWnY2WAB9mpnu12cWmbX+We1nGZgMWnuvPuB+OR0fIb+Z8XJb1M7d3uHlG4eFNH2L 2xmOq+8B2N5U4iRiP8rcaSIlKprkEEIKXxyqbZrDp6gKZPbEsRoUDDhLcD6t4wcvrwag Oanz4KaG5BTEqAKSGOcMznX/GL7ai3ETEpBZECvfVIQmZNT0kjsKq1oEkEfFhRbiJFVT XAsQ== X-Gm-Message-State: AC+VfDxTN5768VRPn3MbheUH570t2RuHaA7HYNP+Q1o5NgG7OlGMuUJM pyv+zZVIYINJOlPU0CFToKF3teS3W+w= X-Google-Smtp-Source: ACHHUZ4VFYAdIHLqeJ14za1MxIqkvJrkGV6Yf1oNFWGOG8pJc58iQwSXrcfI0IoqFC+oVQuwesnB8fXEw+Y= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a81:b71d:0:b0:55a:3133:86fa with SMTP id v29-20020a81b71d000000b0055a313386famr2380185ywh.3.1685160270657; Fri, 26 May 2023 21:04:30 -0700 (PDT) Date: Fri, 26 May 2023 21:02:33 -0700 In-Reply-To: <20230527040236.1875860-1-reijiw@google.com> Mime-Version: 1.0 References: <20230527040236.1875860-1-reijiw@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230527040236.1875860-2-reijiw@google.com> Subject: [PATCH 1/4] KVM: arm64: PMU: Introduce a helper to set the guest's PMU From: Reiji Watanabe To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_210432_240178_C720840A X-CRM114-Status: GOOD ( 14.38 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce a new helper function to set the guest's PMU (kvm->arch.arm_pmu), and use it when the guest's PMU needs to be set. This helper will make it easier for the following patches to modify the relevant code. No functional change intended. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/pmu-emul.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 45727d50d18d..d50c8f7a2410 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -869,6 +869,21 @@ static bool pmu_irq_is_valid(struct kvm *kvm, int irq) return true; } +static int kvm_arm_set_vm_pmu(struct kvm *kvm, struct arm_pmu *arm_pmu) +{ + lockdep_assert_held(&kvm->arch.config_lock); + + if (!arm_pmu) { + arm_pmu = kvm_pmu_probe_armpmu(); + if (!arm_pmu) + return -ENODEV; + } + + kvm->arch.arm_pmu = arm_pmu; + + return 0; +} + static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id) { struct kvm *kvm = vcpu->kvm; @@ -888,7 +903,7 @@ static int kvm_arm_pmu_v3_set_pmu(struct kvm_vcpu *vcpu, int pmu_id) break; } - kvm->arch.arm_pmu = arm_pmu; + WARN_ON_ONCE(kvm_arm_set_vm_pmu(kvm, arm_pmu)); cpumask_copy(kvm->arch.supported_cpus, &arm_pmu->supported_cpus); ret = 0; break; @@ -913,9 +928,10 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) if (!kvm->arch.arm_pmu) { /* No PMU set, get the default one */ - kvm->arch.arm_pmu = kvm_pmu_probe_armpmu(); - if (!kvm->arch.arm_pmu) - return -ENODEV; + int ret = kvm_arm_set_vm_pmu(kvm, NULL); + + if (ret) + return ret; } switch (attr->attr) {