From patchwork Sat Feb 11 03:14:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13136800 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 EBF6FC636D3 for ; Sat, 11 Feb 2023 03:17:20 +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=miDRGU6DoFDxDG9BJr9zcse7u/PpOnq74cx9Nm2gN78=; b=cP/VOCcCcfMZbBpC43vjKWPIMh ON5YNdteP3F+H5qqEgTZp0QaiA9WT0u+w3rrX0HnETlYlrb6XNVDEtpvw2D0CJo/jq8J7Md/xlpze somOaUEQY5CpH9EKKR+Rnn1hNlA9643HzA2npmWW8m0Xqwyn9B3O0uFYzU4jaoOkP9ArqLdNQWCig hmR56XA2Pm/KNH4+Vam9m3QyDHun9Xz1p2yq1gMXwljJLwVqISIYsLvHM5jk3prWoVVOnekVPr8Mc 6ZP1LsAkHL/pSTKel0VXUtLsM7GIfrEyLFrkQhBBKB4I0fRLawm4hxfDPSP6vYgPMJ+D7qSayJCKy UxH05ueA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQgN3-008Qed-CF; Sat, 11 Feb 2023 03:16:13 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQgN0-008QdD-Ms for linux-arm-kernel@lists.infradead.org; Sat, 11 Feb 2023 03:16:12 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-52ec8c88d75so41689467b3.12 for ; Fri, 10 Feb 2023 19:16:07 -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=hdq7XuQlIHPZE8pEPY3tLAAyJhRpgi42DVvI6D6fk3s=; b=olC4sly3/BCcNo299QFE6SXvV3g1wqVFUyVd0+8jO9Hz+c+XRPNbcos5NTEKH3hY/R jfuycnUuQWdEbOb5vp8hZcuI6GgGI1csCoVVklgaUsyPjklgOJsSaNyrhgKH1/VKpzK+ DEbm1g4/DWJK4TW/Eh5bcI6KwZzSjgu0qXrAlSd0ywkqwa3K1g1Z1Xg8ejeFhlI8X0ft PSqzgUEdb4r24scbLQiArayCSitWzKiUJUoS1d70rdvllcCjnqRUP+QgxJEutdunjA+C MRKdYitr/BDl6m6mcox9XP9p0gA1+a1PtClTHXxPnS8X4eygpDmpWl6uof8xHFyxNtkP UG/Q== 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=hdq7XuQlIHPZE8pEPY3tLAAyJhRpgi42DVvI6D6fk3s=; b=0vCAhZCuo0JJ/NtqXE3gq8nA4QwIA1rZRv87WFjsfZvSfYdSDYVm18BFZr8rkhVqz2 QB9Yujv2m/OSxgvZtZvRbBxTinkE6krcCBlM/3GETxKGoUnKZGQbB7bO3c9c0kz2RWKI fJHKTHb5n7mo8wso/LN95nCe2U6T6Rrt80uwj+txkIDKJSpDZCHBAjqdTEbC9SazI4VV G53ONPtpgxT67D9R50v9D1VKG7cVutVu3XU0JJb2ZmKyziynKozu0EBQlrfKzvsOb9Xd LyxdIqcuoRBhJAmDvI4JR3UZFJ2V14L2Y+gk5g6Yv4UiMi1H3sT9M6+x7byqsZhdvKVu F0cw== X-Gm-Message-State: AO0yUKW2GP36mFWvIaF95mfkN7SCtEud8HJRGOjJYfDZnAq2iyUMU/zK JWfMja8KYZigjXtq7ZIKvoVJGqpddtI= X-Google-Smtp-Source: AK7set9MyQkoUEk7Igu3MmgDiS0MvOBHtDAybXqTLmWHi6ARX9UQnTFnvNsgayrwWqtVeJ8XRvgwFvDqePE= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a81:bf48:0:b0:506:7242:1c7b with SMTP id s8-20020a81bf48000000b0050672421c7bmr2250183ywk.494.1676085366884; Fri, 10 Feb 2023 19:16:06 -0800 (PST) Date: Fri, 10 Feb 2023 19:14:53 -0800 In-Reply-To: <20230211031506.4159098-1-reijiw@google.com> Mime-Version: 1.0 References: <20230211031506.4159098-1-reijiw@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230211031506.4159098-2-reijiw@google.com> Subject: [PATCH v4 01/14] 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 , Shaoqin Huang , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230210_191610_770469_5FEA3C3A X-CRM114-Status: GOOD ( 14.57 ) 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);