From patchwork Fri Feb 3 04:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13126979 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 4A08AC636CC for ; Fri, 3 Feb 2023 04:06:38 +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=JKMd1EFmDAe7EzeHMWi/B7zoQiuYiSphnFzWRR7SPFU=; b=wPL7BG9YZDG7ohg6GS3DM1uPA9 ZSj76D6TEwEkHzwSu/KOxbRbTebxol25DdB1GmlgjiRLPerw2bs6LNJFilUjlj0dPcAHeJk20Bp/t mSETDKEFTrMlYN5nPpEWh6ujHiFo071D7C3rlzA/xq8KjChuEeV7ON1kmTwBtckPlXhB50vRs9CHQ K9j/Dpvup9Nq4IjCyxR41LS7cx/tFxWtXF5WMVdWJEb+/3W0yrj3jY58NxPO4ej8LSuNw82vsRTID YadFivu96GKwNOLyy2wcxJ36UJDan3DWnVlqp7wF44p/Cq/L1rE06KBy7NvuQkw3KYEu69YCl2x6w v2eheIIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNnKd-000GyI-C6; Fri, 03 Feb 2023 04:05:47 +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 1pNnKa-000Gxb-Rn for linux-arm-kernel@lists.infradead.org; Fri, 03 Feb 2023 04:05:46 +0000 Received: by mail-yb1-xb49.google.com with SMTP id y125-20020a25c883000000b0086349255277so2047131ybf.8 for ; Thu, 02 Feb 2023 20:05:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ipr4xhXjsZ3xlHgWCFzXNIu5kTM+BU4HEjtM53FIJC8=; b=c/d6PHNBqDvTeLHEKZO2QuLxxu4Dw58XcVsbS9TqYVD79JfHoLbKk5m+MlHoePbKvZ m+RiHImDM2atdcUtTq5p/p8ZKHwuJd0SnifljBbJaRr/xGiJOzWYhvkowagdjqZtMJRa ykLSRR6cNJ0zBMjRG6h6BR3ebZrbrlzZXuPZQ7TfzIPwZ8L7qTHTiolQAWapRGHaiNUj FAsvVziElhXi20ioCU8YNcHjKZwgyMOFIcWFZxuG9F/C/plHhQM317I3Zd0F09qlUS+d kGva4rNxavCSAw189iTIgHWJ6FmmRcmyhko0spN052hlBYOUey3NTCi7JFmr/nGCwkCP QCmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Ipr4xhXjsZ3xlHgWCFzXNIu5kTM+BU4HEjtM53FIJC8=; b=TuVAZ/4jstDa++SwsqCADY3TVqk17aZkv2wlez1PeN4lMlrNtbfXt535bI4mn85Ow0 aMyc1bISA/4JnjOg6En/+jEMtVcVbiW71f1lgOMMecx9R660AsvhSDcgBDOZoGqu7G6C b+6cmcKsHoVXH1h8xiEEdjV7OL6dPtP88kKqd8cFchxuLszlWK7iYllMTflUUdQ7PlX1 R/saVqcXtx+uVij7rIXN/4ooxsY8/Rz1c1fb49Kre7t3UG5G4mMN9riVmLI32rrTQRWs uFoeF2BWVqD0BfgoDiamRApAd2OvnjhNlzVmVU4BHVolZj2N9DVxyNzIyRBk3g0ORUqY KfmQ== X-Gm-Message-State: AO0yUKWca275XTEiy+DiRkk0BixP60ysdIqyShRAMbB2NTfwR34FawoP IJHXyEH6DooHvb0pbbOtURZGAQDwlOU= X-Google-Smtp-Source: AK7set9hXHYpsfeEyNZjmKuwBd86TPK7rc/HyFmmnFFTRFa6jkP13qBYeAs3sOwd8+uNbKkJ6PM4+ACIplY= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a81:af02:0:b0:4d7:50a4:630d with SMTP id n2-20020a81af02000000b004d750a4630dmr1108788ywh.518.1675397143239; Thu, 02 Feb 2023 20:05:43 -0800 (PST) Date: Thu, 2 Feb 2023 20:02:29 -0800 In-Reply-To: <20230203040242.1792453-1-reijiw@google.com> Mime-Version: 1.0 References: <20230203040242.1792453-1-reijiw@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230203040242.1792453-2-reijiw@google.com> Subject: [PATCH v3 01/14] KVM: arm64: PMU: Introduce a helper to set the guest's PMU From: Reiji Watanabe To: Marc Zyngier , 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 , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Shaoqin@google.com, Huang@google.com, shahuang@redhat.com, Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230202_200544_921304_04152540 X-CRM114-Status: GOOD ( 14.72 ) 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 24908400e190..f2a89f414297 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -867,6 +867,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->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; @@ -886,7 +901,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; @@ -911,10 +926,11 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) mutex_lock(&kvm->lock); 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) { + int ret = kvm_arm_set_vm_pmu(kvm, NULL); + + if (ret) { mutex_unlock(&kvm->lock); - return -ENODEV; + return ret; } } mutex_unlock(&kvm->lock);