From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69F9D33F8D6 for ; Fri, 19 Jun 2026 07:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781852849; cv=none; b=IGtM98NEw0UJBzj8FlX8bQBZhzdVtC9bGq22Y3vJ5pBN9Zu+biuSuoVVDZbo6P1dgHPdZo6r4wXXVv2//p5woyvErrlhBbGfdLmrpQMJ1y7VxjRuPOg9R2OWOgbKwGPg9zivbOb1uOvMcwHP6j5mavctGLUBC7AoDAKnqo6tzLo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781852849; c=relaxed/simple; bh=9JDMmHjB8wIpJAXXialivP1h3vqF/BPRvofAJksL8RU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jWzqo5QHpO9i/JU6gKfzeLG4jGJ+LQCqyUmoCgg3YP90A2pjGQSm8F7LSiwdE95T7I1s4b7NAh6WAEwDrLbZo+NEbUkNZLmhtfkKxj3jsH7KdDBHUao/ltyKP6EaamJOgksXqN0GIx+TVsbkHp/pf9Z0QOiA9sqNPO8A/QkLJ6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d5rlNx4I; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d5rlNx4I" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-45eec2ba533so1489230f8f.3 for ; Fri, 19 Jun 2026 00:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781852846; x=1782457646; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S1QUYcee151+QuSJM7wM7vpmF/sftjcL7x2ymejauNs=; b=d5rlNx4IJghKjykqT9uWLOX0otsXz1y7zvnV7d8g0H++E4YPcCOAlm+n4pHeJ6ANzu XkNTkEEe9VKv+ffggqyt+JoB4GuMX5RXZUGqMns2R/IQGg1yq7mJngtF0eLCybgofFyy 46HjoOE77HTpSiQi3Bb+OFFLghdLHZX/DAcZzZCPv+egvJNUHGAdc37iA4dZbKKybc8Q khaGtsaKgvME9VSUkmXjNFKJgwHgyDfowLyyhtI910zTCCL/8Aq12iGmx+KZszAvhUo6 r51r1oqpWjqvsFk/qBLl1B2iNZknw4Wqe8o6rMI6+1xkP70uQK856+VxNzN1ss7XnuJd 7LFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781852846; x=1782457646; 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=S1QUYcee151+QuSJM7wM7vpmF/sftjcL7x2ymejauNs=; b=T2d+/PdNFg+cGK9fjgf8u6rZuEeIpWQg7oNwPvVsEoE+hhykNxL6kR/GlkUdAFC/Gs 9/D6kxUbayogtxq/kwUtn8wem/oTZ+BfVVA2e+PShLc923kd4tBTagUsdoOlRKM/zHH7 RZ21sfD8ks/WiaDk2pUO6MeQ6fVvX0pZDbm8LoBDn8Zis9WhJ+jO6FMe1wns/MzYhvZZ MxbhhendK+so3DMxu3t/WXgZoPmzTLQ4AUHWqHyLPPmvuxRfWnqpGYHrXptVgWZRdhVM 7vQxr9sbT0IhrpqGGcVSaBELfld/kXCpTjlYsRfCWq7eBNizrEi9nxyQeyQeUu4Sa+0m V5sA== X-Forwarded-Encrypted: i=1; AFNElJ+O4xKn51415rIc7wsaheP7G13rOhbr1ZvguhE+4TGG8xV+xqcllxwWiV62lT41FiOd8PpnycbwsQQ5v2Q=@vger.kernel.org X-Gm-Message-State: AOJu0YwtRdbgwSRWsi+bWmkGL5WRITWpZnD1v0/r3kcLzhjB6lgvylaA k6JiWHhJYxAviwvDKEwY79cmgWmuHc4JvvFvfob/2009nj6YXgx7ncm3XTUgDktohQLlGT2SeVG spA== X-Received: from wrmd14.prod.google.com ([2002:adf:e88e:0:b0:44b:7bd5:1b9f]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:adf:e891:0:b0:45e:ea68:523b with SMTP id ffacd0b85a97d-465004395ccmr3242226f8f.10.1781852845441; Fri, 19 Jun 2026 00:07:25 -0700 (PDT) Date: Fri, 19 Jun 2026 08:07:15 +0100 In-Reply-To: <20260619070719.812227-1-tabba@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260619070719.812227-1-tabba@google.com> X-Mailer: git-send-email 2.55.0.rc0.738.g0c8ab3ebcc-goog Message-ID: <20260619070719.812227-5-tabba@google.com> Subject: [PATCH v2 4/8] KVM: arm64: Move PSCI helper functions to a shared header From: Fuad Tabba To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Vincent Donnefort , Quentin Perret , Sebastian Ene , Hyunwoo Kim , Fuad Tabba Content-Type: text/plain; charset="UTF-8" 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 --- 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