From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 17FB910F0 for ; Fri, 19 Jun 2026 13:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781875857; cv=none; b=FWqRn+VLnp9rxQZPmksN8O9tPrrrtkwmYh2ikoE7nf1fQyl6sWl1JbF/j8oSsnJH/NkTBWSYRMSDIVYOK2f1vt/Gl9n9YlG1TOGxc9N1LnnLqOtsWcpIZ+doq79YpgILGwMcNlEJnQo4APB6Lkw1+ABYX+fmvdGAhhs4LAuJ1v8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781875857; c=relaxed/simple; bh=liIbQvJAKQSTMKQlJX/BN70PZg+kVCxw1ywqeFHjGUw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Kh9rV4DtBkjwXquzshQsvjsPnNqO7/G5QOdOgJeWFY6KXynV82qSeDCta7QpiKPWJvk75zGnzFsVA2jYsanHE0RD58zBgw8WFbY7U/8eDcu4xXPtfScLsgl3Jley74CYn3n6GbRX8y2h0JR8zdmGotBaaIHEpQU4cj85qx9GAJQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FsQSNrd2; arc=none smtp.client-ip=209.85.218.52 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FsQSNrd2" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-bec49f7e35eso303745966b.2 for ; Fri, 19 Jun 2026 06:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781875854; x=1782480654; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=3TpHNc6do1SKJbtgxSVn8RTCsd27hNGE1sd8vLk5+cE=; b=FsQSNrd2bbil4Njjw26KYhz07Dvet9PCdJHOx7lRPIPYSyIcYy0gp67TjcyJQxRd3K O3648KSckTlMqKe/xYx5gjyd8TKay1IlxxH682Enh/X2Lv1EWv8iv6S1dwLthEsXLyeF AIgQ57D+Jo1aSf46lZhd10bNoL6IMa3xg8lEj5ryVY38Uiew3BSy5Bi6p9VajV4fK8qC jj6BJslIZ7s5U31m2T4TGpuH/AvXTEfgDiG1XPql+/68tris5Ca64m9RqJaAFzARJP89 rHxjKsEGBjpwm6q/ocFCvb4wG3K3vkyoN0xEegk5KWUMAPHrmRkCzTM7/jDGI4Kh9qgn GYBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781875854; x=1782480654; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3TpHNc6do1SKJbtgxSVn8RTCsd27hNGE1sd8vLk5+cE=; b=fNo54HZtfHyxE84Rx2wrI07C+DTOwnIYbtSMi1EXXRwzqzOsWcYbyaINWsE6oeEejQ IymUOWiXuK6gP2jxOLGEzGWsKx8ymkMF8YWQYlc/PIHq1XCXrJfoEfVzSkIqOzTaprvW u9R0qFc1ZAREvxZZ0b765tKAsrflfr7rYN7LzRvNAhU4rOXHXhquxE+/7GlCdWMnBzKr tzY9Q5k/c1NWEEzYW3tyuHsKIp3zf2HGUypqFGKSxLxVN6d0epRBWBuiaEPZ4nSJwakU W/LMHcGNhKDdZ39KWFWM43DX4kh20qoQByBkClbqQcSGBGzNK/v7XDf0H8Bhs8UNkVfF S7gA== X-Forwarded-Encrypted: i=1; AFNElJ8IGzjaDKE3as82b4OFP9SC0fW+OIgChbzUy1/ZrSsnofODaTpt2MPKN9g0K9PevZPUhjbG6R7JvCMP+no=@vger.kernel.org X-Gm-Message-State: AOJu0YwOVpcVXni0oG7r+2ucG1TZBkJQg3q7LOvNwpP2e3gOEqGwsEa6 xF8O0wMDHWWj0dAHZd5sEyE8qPHW4LKBS7OBcgBOTEvcVtYZNGMoVWAPtKPst+gPsw== X-Gm-Gg: AfdE7cmdxPOezydQPu4TJV2iPY1UAgQvUcsQLTLHs8+onUxWWK2Mx5NWtPI3drhEAun CNVanwD7DiQ0VqcsiRA7FZGRhkGHS1xTo0lTwSDt7adGXtj/xFOEvrJilQ134UmgGgNy1ysNcUC h17KO5GDrHSlf0OAr84+dKZht4UulT/r9YdhnGlLgpWOhRJHEAbgfMGs2gzK5A9qSVkJyQ0KZYc NIcEn6Y8T8EVgXpTgPXu5nqiipdNSxl++uKR5OBa2eBaQ82FKAEedyXoW4tvIT2Q/MsQShQDjuK bwucHOXW3DW/pJw4WR6QW7CMY5o/jzQa/yB5neHGKGSolhxzo+YqTKF0fAMtSEvkab0KZZT6/ES HJgxvvV9gisbtyxJ3xJgrPGZnNDV9+1sa/e5NAxQ1HUo6QyU9vb2+ki7HvvwhriF7P1HZPGhgQf 5MWssFgC9KXOLKzMYSRD+TbHVFkJ/QtoBheWIy9Nxzc/7SyMUMuTX2lVtq X-Received: by 2002:a17:907:c1b:b0:bab:e742:aba with SMTP id a640c23a62f3a-c097ccbfcaamr195069766b.42.1781875853661; Fri, 19 Jun 2026 06:30:53 -0700 (PDT) Received: from google.com (135.91.155.104.bc.googleusercontent.com. [104.155.91.135]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650c115fd8sm8260734f8f.35.2026.06.19.06.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:30:52 -0700 (PDT) Date: Fri, 19 Jun 2026 14:30:48 +0100 From: Vincent Donnefort To: Fuad Tabba Cc: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Quentin Perret , Sebastian Ene , Hyunwoo Kim Subject: Re: [PATCH v2 4/8] KVM: arm64: Move PSCI helper functions to a shared header Message-ID: References: <20260619070719.812227-1-tabba@google.com> <20260619070719.812227-5-tabba@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Reviewed-by: Vincent Donnefort > --- > 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 >