From: Vincent Donnefort <vdonnefort@google.com>
To: Fuad Tabba <tabba@google.com>
Cc: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Quentin Perret <qperret@google.com>,
Sebastian Ene <sebastianene@google.com>,
Hyunwoo Kim <imv4bel@gmail.com>
Subject: Re: [PATCH v2 4/8] KVM: arm64: Move PSCI helper functions to a shared header
Date: Fri, 19 Jun 2026 14:30:48 +0100 [thread overview]
Message-ID: <ajVEiM3QJfcEabbt@google.com> (raw)
In-Reply-To: <20260619070719.812227-5-tabba@google.com>
On Fri, Jun 19, 2026 at 08:07:15AM +0100, Fuad Tabba wrote:
> Move kvm_psci_valid_affinity() and kvm_psci_narrow_to_32bit() from
> psci.c to include/kvm/arm_psci.h, and move psci_affinity_mask() there
> too, renaming it kvm_psci_affinity_mask() now that it is no longer
> file-local. A follow-up series handles some protected-guest PSCI calls
> at EL2 using these helpers.
>
> No functional change intended.
>
> Signed-off-by: Fuad Tabba <tabba@google.com>
Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
> ---
> arch/arm64/kvm/psci.c | 30 +-----------------------------
> include/kvm/arm_psci.h | 27 +++++++++++++++++++++++++++
> 2 files changed, 28 insertions(+), 29 deletions(-)
>
> diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c
> index 3b5dbe9a0a0e..e3db84400d1f 100644
> --- a/arch/arm64/kvm/psci.c
> +++ b/arch/arm64/kvm/psci.c
> @@ -21,16 +21,6 @@
> * as described in ARM document number ARM DEN 0022A.
> */
>
> -#define AFFINITY_MASK(level) ~((0x1UL << ((level) * MPIDR_LEVEL_BITS)) - 1)
> -
> -static unsigned long psci_affinity_mask(unsigned long affinity_level)
> -{
> - if (affinity_level <= 3)
> - return MPIDR_HWID_BITMASK & AFFINITY_MASK(affinity_level);
> -
> - return 0;
> -}
> -
> static unsigned long kvm_psci_vcpu_suspend(struct kvm_vcpu *vcpu)
> {
> /*
> @@ -51,12 +41,6 @@ static unsigned long kvm_psci_vcpu_suspend(struct kvm_vcpu *vcpu)
> return PSCI_RET_SUCCESS;
> }
>
> -static inline bool kvm_psci_valid_affinity(struct kvm_vcpu *vcpu,
> - unsigned long affinity)
> -{
> - return !(affinity & ~MPIDR_HWID_BITMASK);
> -}
> -
> static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
> {
> struct vcpu_reset_state *reset_state;
> @@ -135,7 +119,7 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
> return PSCI_RET_INVALID_PARAMS;
>
> /* Determine target affinity mask */
> - target_affinity_mask = psci_affinity_mask(lowest_affinity_level);
> + target_affinity_mask = kvm_psci_affinity_mask(lowest_affinity_level);
> if (!target_affinity_mask)
> return PSCI_RET_INVALID_PARAMS;
>
> @@ -220,18 +204,6 @@ static void kvm_psci_system_suspend(struct kvm_vcpu *vcpu)
> run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
> }
>
> -static void kvm_psci_narrow_to_32bit(struct kvm_vcpu *vcpu)
> -{
> - int i;
> -
> - /*
> - * Zero the input registers' upper 32 bits. They will be fully
> - * zeroed on exit, so we're fine changing them in place.
> - */
> - for (i = 1; i < 4; i++)
> - vcpu_set_reg(vcpu, i, lower_32_bits(vcpu_get_reg(vcpu, i)));
> -}
> -
> static unsigned long kvm_psci_check_allowed_function(struct kvm_vcpu *vcpu, u32 fn)
> {
> /*
> diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h
> index cbaec804eb83..f86a006d6713 100644
> --- a/include/kvm/arm_psci.h
> +++ b/include/kvm/arm_psci.h
> @@ -38,6 +38,33 @@ static inline int kvm_psci_version(struct kvm_vcpu *vcpu)
> return KVM_ARM_PSCI_0_1;
> }
>
> +/* Narrow the PSCI register arguments (r1 to r3) to 32 bits. */
> +static inline void kvm_psci_narrow_to_32bit(struct kvm_vcpu *vcpu)
> +{
> + int i;
> +
> + /*
> + * Zero the input registers' upper 32 bits. They will be fully
> + * zeroed on exit, so we're fine changing them in place.
> + */
> + for (i = 1; i < 4; i++)
> + vcpu_set_reg(vcpu, i, lower_32_bits(vcpu_get_reg(vcpu, i)));
> +}
> +
> +static inline bool kvm_psci_valid_affinity(struct kvm_vcpu *vcpu,
> + unsigned long affinity)
> +{
> + return !(affinity & ~MPIDR_HWID_BITMASK);
> +}
> +
> +static inline unsigned long kvm_psci_affinity_mask(unsigned long affinity_level)
> +{
> + if (affinity_level <= 3)
> + return MPIDR_HWID_BITMASK &
> + ~((0x1UL << (affinity_level * MPIDR_LEVEL_BITS)) - 1);
> +
> + return 0;
> +}
>
> int kvm_psci_call(struct kvm_vcpu *vcpu);
>
> --
> 2.55.0.rc0.738.g0c8ab3ebcc-goog
>
next prev parent reply other threads:[~2026-06-19 13:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-19 7:07 [PATCH v2 0/8] KVM: arm64: Rework pKVM vCPU state synchronisation Fuad Tabba
2026-06-19 7:07 ` [PATCH v2 1/8] KVM: arm64: Extract MPIDR computation into a shared header Fuad Tabba
2026-06-19 13:24 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 2/8] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code Fuad Tabba
2026-06-19 13:26 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 3/8] KVM: arm64: Factor out reusable vCPU reset helpers Fuad Tabba
2026-06-19 13:29 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 4/8] KVM: arm64: Move PSCI helper functions to a shared header Fuad Tabba
2026-06-19 13:30 ` Vincent Donnefort [this message]
2026-06-19 7:07 ` [PATCH v2 5/8] KVM: arm64: Add host and hypervisor vCPU lookup primitives Fuad Tabba
2026-06-19 13:31 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 6/8] KVM: arm64: Minimise EL2's exposure of host VGIC state during world switch Fuad Tabba
2026-06-19 7:07 ` [PATCH v2 7/8] KVM: arm64: Add primitives to flush/sync the VGIC state at EL2 Fuad Tabba
2026-06-19 7:07 ` [PATCH v2 8/8] KVM: arm64: Implement lazy vCPU state sync for non-protected guests Fuad Tabba
2026-06-19 13:12 ` Vincent Donnefort
2026-06-19 16:41 ` Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajVEiM3QJfcEabbt@google.com \
--to=vdonnefort@google.com \
--cc=catalin.marinas@arm.com \
--cc=imv4bel@gmail.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=qperret@google.com \
--cc=sebastianene@google.com \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox