From nobody Tue Feb 10 01:59:10 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC6F72ECE9D; Thu, 8 Jan 2026 17:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767895181; cv=none; b=mvfCd+0z6ya1W2pZeULoHHPMkQSNlP5C83UFK5yctu1s0PsbDFN2s1u2ZIa28rBAFWUu4YOTIwMNPRUtQ1tvgvmIQy/uTWc7SiIa5cPrO4HuluGL4GJCzkHtGoed8xMvLGu3xNK/C5N9mrXdUcb0Wi8HqL3r6ym4dlsFlIvGrZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767895181; c=relaxed/simple; bh=1qd9jKKkciPMBnCtIYoZky5yLvK/08oE+llkGM6J0zQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pCdz4jMexliHhHsxcMM1X/X6cpsEz1H+FegSaMoGdo/kwJB8OeVhBNzkMImmLz6Ep6zhZov/mp6ztJA+5J+Q4eXtwVr9f0acZ09JZAQwRStsOrG6Aosl4rkGq8Wrsaf0Hst5cE/hUSRWt9Z89VJhk2itVlpHewsVvRV/N2nwrG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 676351515; Thu, 8 Jan 2026 09:59:27 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5F7BF3F5A1; Thu, 8 Jan 2026 09:59:31 -0800 (PST) From: Suzuki K Poulose To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, maz@kernel.org, will@kernel.org, oupton@kernel.org, aneesh.kumar@kernel.org, steven.price@arm.com, linux-kernel@vger.kernel.org, alexandru.elisei@arm.com, tabba@google.com, Oliver Upton , Suzuki K Poulose Subject: [kvmtool PATCH v5 15/15] arm64: smccc: Start sending PSCI to userspace Date: Thu, 8 Jan 2026 17:57:53 +0000 Message-ID: <20260108175753.1292097-16-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260108175753.1292097-1-suzuki.poulose@arm.com> References: <20260108175753.1292097-1-suzuki.poulose@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Oliver Upton kvmtool now has a PSCI implementation that complies with v1.0 of the specification. Use the SMCCC filter to start sending these calls out to userspace for further handling. While at it, shut the door on the legacy, KVM-specific v0.1 functions. Reviewed-by: Marc Zyngier Signed-off-by: Oliver Upton Signed-off-by: Suzuki K Poulose --- Changes since v4: - Switch to default in-kernel PSCI --- arm64/include/kvm/kvm-config-arch.h | 8 +++++-- arm64/smccc.c | 37 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/arm64/include/kvm/kvm-config-arch.h b/arm64/include/kvm/kvm-co= nfig-arch.h index ee031f01..f8dd088d 100644 --- a/arm64/include/kvm/kvm-config-arch.h +++ b/arm64/include/kvm/kvm-config-arch.h @@ -15,6 +15,7 @@ struct kvm_config_arch { u64 fw_addr; unsigned int sve_max_vq; bool no_pvtime; + bool psci; }; =20 int irqchip_parser(const struct option *opt, const char *arg, int unset); @@ -52,11 +53,14 @@ int sve_vl_parser(const struct option *opt, const char = *arg, int unset); "Force virtio devices to use PCI as their default " \ "transport (Deprecated: Use --virtio-transport " \ "option instead)", virtio_transport_parser, kvm), \ - OPT_CALLBACK('\0', "irqchip", &(cfg)->irqchip, \ + OPT_CALLBACK('\0', "irqchip", &(cfg)->irqchip, \ "[gicv2|gicv2m|gicv3|gicv3-its]", \ "Type of interrupt controller to emulate in the guest", \ irqchip_parser, NULL), \ OPT_U64('\0', "firmware-address", &(cfg)->fw_addr, \ - "Address where firmware should be loaded"), + "Address where firmware should be loaded"), \ + OPT_BOOLEAN('\0', "psci", &(cfg)->psci, \ + "Request userspace handling of PSCI, instead of" \ + " relying on the in-kernel implementation"), =20 #endif /* ARM_COMMON__KVM_CONFIG_ARCH_H */ diff --git a/arm64/smccc.c b/arm64/smccc.c index ef986d8c..47310a04 100644 --- a/arm64/smccc.c +++ b/arm64/smccc.c @@ -38,7 +38,44 @@ out: return true; } =20 +static struct kvm_smccc_filter filter_ranges[] =3D { + { + .base =3D KVM_PSCI_FN_BASE, + .nr_functions =3D 4, + .action =3D KVM_SMCCC_FILTER_DENY, + }, + { + .base =3D PSCI_0_2_FN_BASE, + .nr_functions =3D 0x20, + .action =3D KVM_SMCCC_FILTER_FWD_TO_USER, + }, + { + .base =3D PSCI_0_2_FN64_BASE, + .nr_functions =3D 0x20, + .action =3D KVM_SMCCC_FILTER_FWD_TO_USER, + }, +}; + void kvm__setup_smccc(struct kvm *kvm) { + struct kvm_device_attr attr =3D { + .group =3D KVM_ARM_VM_SMCCC_CTRL, + .attr =3D KVM_ARM_VM_SMCCC_FILTER, + }; + unsigned int i; =20 + if (!kvm->cfg.arch.psci) + return; + + if (ioctl(kvm->vm_fd, KVM_HAS_DEVICE_ATTR, &attr)) { + pr_debug("KVM SMCCC filter not supported"); + return; + } + + for (i =3D 0; i < ARRAY_SIZE(filter_ranges); i++) { + attr.addr =3D (u64)&filter_ranges[i]; + + if (ioctl(kvm->vm_fd, KVM_SET_DEVICE_ATTR, &attr)) + die_perror("KVM_SET_DEVICE_ATTR failed"); + } } --=20 2.43.0