From patchwork Tue Apr 8 10:52:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 14043027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4FCA9C369AC for ; Tue, 8 Apr 2025 13:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Q19XYvU/Ro13/HumWF+ExDj9VyTsluFGq7J8txirQ+0=; b=Gs9Dtfg0t2HiirjKkpkyWFAqwx UlIZVFIpoWNTTfve4kGCy9QVAUCNRKLsFi34J6Ty2Fbl4EJJ1qXMnZpzXO0mcm8JRNTrL/64/xoID jvcDMRBvogmSXtbsdAY4Q4ChBES79jyNEMBB+psqg2UYNXa3I5hDXA9ckXKo5dKsGHvveGN3YgBGi 8EDL1LSr9y50DJtumGjJniykCe+vzAWYMi0MKUdvHYJfV/3iuK6586zfTIejJIUa7pSnxsJ8Jycu2 YbORjNmi9gY2kLLxsNVJxcMTullTs/hxkRA9bg/UNJTOvDgrcbCTwpbeDInnTqZjBivV3XwRmb83e RTmwXagg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u28lw-000000046D0-0lkD; Tue, 08 Apr 2025 13:13:48 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u26ZT-00000003kb7-0wko for linux-arm-kernel@bombadil.infradead.org; Tue, 08 Apr 2025 10:52:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Q19XYvU/Ro13/HumWF+ExDj9VyTsluFGq7J8txirQ+0=; b=ilqjHIeXwVMPlPfwF5OuubTvWv 2/lFhbgXb0EOdZbdMxil7fXdQ3J4Yfrsq0gEPsYvBmUBqMHduaaH7Rgb4Mrp3/w8j2XTryW7z/ygx g/AnE3BEy2NKmPTf8HRfUqh6T+EwXpoHkYffcQtliQTfPiuAyMVOKTKsyggK59KRA924kCO9V4M9h PMXffhiIZM36oWIm9umSpNs0I8hy2z+YfAqJnhN7IetWG4ErU93+B5dWUxs1/N4cFVbVQDvFQ2w1h ZU0L/G2/jNJTBHHe2kouQV0pUyRvIkbHycQwxCy87JvY1ylYY/YuHG1SmF/LmOVNuUU98rANMNsH+ I6khmpnA==; Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by desiato.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u26ZP-00000008GRf-0tJR for linux-arm-kernel@lists.infradead.org; Tue, 08 Apr 2025 10:52:46 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 7935BA4924C; Tue, 8 Apr 2025 10:47:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D12D2C4CEE7; Tue, 8 Apr 2025 10:52:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744109561; bh=AgOtMrlLPvb6zKXe+xDLaAQQQZ+/MSUpbXn+rAw0ohk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nOcyuml1+X8f0mV2QzBsgLSchi/ZAd3r7eB/IYB2Xkd1irysliiz3d5O9rurG2T4b RfQrmR+SILsV2Vas4U7dyOvFZaaLECrl7H1s7RB4jOMlKNF9xgd7g1T+CsV4BRzfzb HkOjLGQIwOMiy14692juo85qPC7mNvPvGzE3ycJaqczWKZVdBfD+NqGafqlIKxV+ME +Msj1zxZ4ip90fqqlek3NGv66I+xhLAb9vV0pjTj9Kgtin2m8Ti+7muh0eUxoQ+VlR jCL/BLL3ULFz7TEdEByLZhfYEAZyYL4r1H7Gm6/2FFZyLzID69ixG6ZSXBD7ipsB+3 dZSf1JY2PshLg== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1u26ZM-003QX2-4c; Tue, 08 Apr 2025 11:52:40 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Joey Gouly , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Eric Auger Subject: [PATCH v2 16/17] KVM: arm64: Allow userspace to request KVM_ARM_VCPU_EL2* Date: Tue, 8 Apr 2025 11:52:24 +0100 Message-Id: <20250408105225.4002637-17-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250408105225.4002637-1-maz@kernel.org> References: <20250408105225.4002637-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, joey.gouly@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, eric.auger@redhat.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250408_115243_510428_BBD3F8ED X-CRM114-Status: GOOD ( 13.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since we're (almost) feature complete, let's allow userspace to request KVM_ARM_VCPU_EL2* by bumping KVM_VCPU_MAX_FEATURES up. We also now advertise the features to userspace with new capabilities. It's going to be great... Reviewed-by: Oliver Upton Reviewed-by: Joey Gouly Signed-off-by: Marc Zyngier Reviewed-by: Ganapatrao Kulkarni --- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/kvm/arm.c | 6 ++++++ include/uapi/linux/kvm.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index b2c535036a06b..79e175a16d356 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -39,7 +39,7 @@ #define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS -#define KVM_VCPU_MAX_FEATURES 7 +#define KVM_VCPU_MAX_FEATURES 9 #define KVM_VCPU_VALID_FEATURES (BIT(KVM_VCPU_MAX_FEATURES) - 1) #define KVM_REQ_SLEEP \ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 5287435873609..b021ce1e42c5c 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -368,6 +368,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_ARM_EL1_32BIT: r = cpus_have_final_cap(ARM64_HAS_32BIT_EL1); break; + case KVM_CAP_ARM_EL2: + r = cpus_have_final_cap(ARM64_HAS_NESTED_VIRT); + break; + case KVM_CAP_ARM_EL2_E2H0: + r = cpus_have_final_cap(ARM64_HAS_HCR_NV1); + break; case KVM_CAP_GUEST_DEBUG_HW_BPS: r = get_num_brps(); break; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index b6ae8ad8934b5..c9d4a908976e8 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -930,6 +930,8 @@ struct kvm_enable_cap { #define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237 #define KVM_CAP_X86_GUEST_MODE 238 #define KVM_CAP_ARM_WRITABLE_IMP_ID_REGS 239 +#define KVM_CAP_ARM_EL2 240 +#define KVM_CAP_ARM_EL2_E2H0 241 struct kvm_irq_routing_irqchip { __u32 irqchip;