From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 723A03D5247 for ; Fri, 12 Jun 2026 06:59:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781247579; cv=none; b=Eriaie9zbkD99YedTMgRB2AjrJI8vQ+xjZ6Vzc/omX6VHubrTgdCiU4f8zLVKLWFN/q7uNKJ1+HcaUhCroerIq0D5jpZZLFi4EJmUTPcWJFlHn8y2NiQbbh5ZTbyX728uuspfFmQEbYC87bB94w/At3S6XOTkWCAHNZCMHeK/0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781247579; c=relaxed/simple; bh=Q0Hnrqlxx3zQPWTPMSg7qMZl5yITEayf5Kj/T+48KP0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ifz0AJNsbNuCRUc1H/vp8nhDzvl3Ka24zcSML4wtWAa/h2M2sZr5Uix83Q2nrj3sjPWaxsarQMAgO8qc4Wh/QrOl8A+LrLkl4cD0sidgqzpjENPxiXbQp3xjwfWbZva8ARPdxPqFIUJfpgwoaNDf6ky7iH7EP/Rsd65s5BHYAV0= 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=tOj1oJnr; arc=none smtp.client-ip=209.85.221.74 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="tOj1oJnr" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-45ef616db45so460066f8f.2 for ; Thu, 11 Jun 2026 23:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781247574; x=1781852374; 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=1n7cJGRx/zTufLA+k8QJWETRRdEVZBs0mmRutVAhkNk=; b=tOj1oJnrMnpavelADrr3i1aXnV6hK2A5RA2wEDnNo0exGuajrGm7FFnBEEoGIE6hqz uz0ndXOS4lFeMamNElpjWP7ZqvYZIqgzm0hf8406ORXwsEkJhvdYUfNi5WO82E58Ty1H 2dCzpoQc7EUW5cREpRLRk4bqVu7MBRSkhbt7j6q1bXWqPOttONi/0aS3pFeC1347BuSX UGnu7AZNNEGORptUoAXA7VIqnGowXzVCXX/bEtaff/65wGbtbdWOvsHUw/JmnWW60cRT uvT8YlLee425oCqGKriHguDE5bWDrv9uMNKkCJE+YIJYalWh1o4b/C5tWgpYXM44XVY9 Cq3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781247574; x=1781852374; 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=1n7cJGRx/zTufLA+k8QJWETRRdEVZBs0mmRutVAhkNk=; b=QmCMrTpgy5/MmNm+dhVpMAlD6fNizf+HLscTE0RQyKZmkBx6bNmV3ESP3amriWaFgZ PY47fl7M+4mjHaKWhdr4g8jhn7Mno+ZKTQynNFnJPV3snlcQ7/xpVPqvJ9rTv5WXOjNz 4JdZlE2zk6b7f33UiV/bUq/hDVJGx1PCuiG7MPiXILtkLQT1XlYUOsP5rdPaYQtHIaqE 3+3GCQziHbhXgzjzWWdpzhIUWmGiGpkyhcMyUuaJyLgPcnN7jRlHTOtW7/lUwY1aITEy LgPMLmM6gPkXUGQKajmKBm+ArWkf/TPpz7s/yCMUraFp6VjX+kUEN/v9BhWajKNK2SmO EIeg== X-Forwarded-Encrypted: i=1; AFNElJ8auKVJopjkKIkCnNpyuiSyVP8+eKjwrGi1DieKu1N2ST4iA0JTkwdz8Vi1x/BoIxG+/5liPF7f7M4C9rw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/0YcKi02WxOLv668wUSJVLQ16EgVtuWln8OGFNKMMHB6fvVtL xladIknPKbDFMICxiYJH6ShUf3X24/QCMzTKdGxRoC3ieaRkR5AZd8CLh4ZA0F1mmv0aYTEHxBc 6ZQ== X-Received: from wmc19.prod.google.com ([2002:a05:600c:6013:b0:490:bdab:4cf6]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:c107:b0:48e:7854:1608 with SMTP id 5b1f17b1804b1-490ec508dbfmr16032775e9.25.1781247573832; Thu, 11 Jun 2026 23:59:33 -0700 (PDT) Date: Fri, 12 Jun 2026 07:59:21 +0100 In-Reply-To: <20260612065925.755562-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: <20260612065925.755562-1-tabba@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260612065925.755562-8-tabba@google.com> Subject: [PATCH v1 07/11] KVM: arm64: Move PSCI helper functions to a shared header From: tabba@google.com To: Marc Zyngier , Oliver Upton Cc: Fuad Tabba , Will Deacon , Catalin Marinas , Quentin Perret , Vincent Donnefort , Sebastian Ene , Per Larsen , Suzuki K Poulose , Zenghui Yu , Joey Gouly , Steffen Eiden , Mark Rutland , Jonathan Cameron , Hyunwoo Kim , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org 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 | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index e1389c525e9d..228e5040c379 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; @@ -131,7 +115,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; @@ -215,18 +199,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..f12b74a4b176 100644 --- a/include/kvm/arm_psci.h +++ b/include/kvm/arm_psci.h @@ -38,6 +38,34 @@ 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.54.0.1136.gdb2ca164c4-goog