From patchwork Fri May 10 11:26:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= X-Patchwork-Id: 13661434 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 49DE3C25B5F for ; Fri, 10 May 2024 11:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=RZ3K0mrCZzDs9fI1bfJOqz/2snI9xPICImlrpNNCzBg=; b=IbX52ryxz6rzJkmubFojcjun4n nRYXNDMNOnlgz06p3gGrGLdpqecyJpL9ebXffnLPHGt3xoUEmStA/W7K2OqNWY0F0QQPI1kDAEENz PMXqIe4rbI2+rs5uEm1CI4aB8cE7Y8hkgKGKuvl1WkeGTw+hK0gyErdLnf8cfHBcTqkMnBmphTQAT iS4OGgKCz/ZT3hj+la5wJmFf6KEu88BdEguyk3gRTr65ik+Dnqgi/HxgCs6EZcYMNxl4eVUJ6a1Zo vqP4OoqdK/VFxedUF2APQRpbgHTuKJIA6t6Ep5r3kjr64Txi8e5jGm3ygUqN77mmbJdSGfBtmSNbt tgMZH9aA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s5OPZ-00000005364-0hBE; Fri, 10 May 2024 11:27:37 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s5OPQ-000000052zm-2oOJ for linux-arm-kernel@lists.infradead.org; Fri, 10 May 2024 11:27:29 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc693399655so3067850276.1 for ; Fri, 10 May 2024 04:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715340445; x=1715945245; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=1X74EzIbLgwkSZ3RCE9vimfqgbYyFErrsdDhyQP2Whk=; b=1nDz8HJrN6/q1oSu3Lxc7GTCsSdxnPd2Ky5l4BM9NVBi9TvLl5+Yzei39T9PAwC16C mmiDI1riG7mabzJTMJcoG5b3w8WtFMv6BMIWwNiQ+3mYBlqDht7Kpzd6yE+nks2g8die Uz7mQRAAItiqnDXO7PxesCz+Y8O0AIXC2RPOV1ykw2oVaxIUmjvTo8lq0Kq0q9+HxxjX 6PpoxpE0XuWvghBpzE+mtYvR+xxZTWBrIpt2LbPVnKGiaSVL3y0fJPudDb+DHUKD7Slz iySzWnb8ROyapBRL1Vmrjeump1GGLKbaiVpbK4iXvx2kyZYqjfeSwVU4bqfTOwj43ST1 fq+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715340445; x=1715945245; h=content-transfer-encoding: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=1X74EzIbLgwkSZ3RCE9vimfqgbYyFErrsdDhyQP2Whk=; b=to3dQOQdvNcP/ZiQ5EloeSY3uPgiQxYIgqkxhtIJyyOfoKkzZ/kBz6iks0x1Sv3TXn HXXkWmO8Y6r2G2b1leSxyjaXdA+wtFq0G3xStQRJ7H5tvQwCh0cX7KdXSRm9FlJ32Baf eXimIdE1IeYSbgWxtvabVAy1dSe4JQVmIePUOMqVr4D0+qRuvzQS0vvq0JZTRJ52mBnZ DqisxwfuR91xfes/vsOXxqee2yi16lvQ2WpojMIldROoaYeIb3uvo+tgOeefCxDpfzon Z5nReEPIsldwmgmz7uhe0+s0K/pKVMD0NlocNKs09I8Kqjn6JhonsQ48qefbTWPo1/z2 nicw== X-Forwarded-Encrypted: i=1; AJvYcCUKXusi6E4h9lDZ9TPrs8Vqq/rAhe/8PFjRoh4LpfZGoJMNPliQNe4/uNYHjwMrGmBCHHqv1cR6EQB37p0GDXnHNwxZeN6sI1C+AjfMOXQpdlCLi40= X-Gm-Message-State: AOJu0Yy88H/M9zawSmIuCtSYjzsErLcnDKINqnCN04QcNdjgJmR0PpYm R0WF9wT1DQ4XY+8Xrq0Cq4g1Gz+QfwT7ty3Baz8ex9I6/kIk7W6mssDHDoeoKffIEzBq3WxRfw= = X-Google-Smtp-Source: AGHT+IE2vI8V+31DiouhAYXxHwv2C3egPY5JlN+7fyVhlwS8yXv78dpY0cirHvo9+5p4Wx/GqO7X9Ryw0g== X-Received: from ptosi.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:11ec]) (user=ptosi job=sendgmr) by 2002:a05:6902:2b88:b0:dcd:3172:7265 with SMTP id 3f1490d57ef6-dee4f3036e5mr593281276.8.1715340445332; Fri, 10 May 2024 04:27:25 -0700 (PDT) Date: Fri, 10 May 2024 12:26:32 +0100 In-Reply-To: <20240510112645.3625702-1-ptosi@google.com> Mime-Version: 1.0 References: <20240510112645.3625702-1-ptosi@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510112645.3625702-4-ptosi@google.com> Subject: [PATCH v3 03/12] KVM: arm64: Pass pointer to __pkvm_init_switch_pgd From: " =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= " To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: " =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= " , Marc Zyngier , Oliver Upton , Suzuki K Poulose , Vincent Donnefort X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240510_042728_741129_D7965F1D X-CRM114-Status: GOOD ( 13.26 ) 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 Make the function take a VA pointer, instead of a phys_addr_t, to fully take advantage of the high-level C language and its type checker. Perform all accesses to the kvm_nvhe_init_params before disabling the MMU, removing the need to access it using physical addresses, which was the reason for taking a phys_addr_t. Signed-off-by: Pierre-Clément Tosi --- arch/arm64/include/asm/kvm_hyp.h | 3 ++- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 12 +++++++++--- arch/arm64/kvm/hyp/nvhe/setup.c | 4 +--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 96daf7cf6802..c195e71d0746 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -123,7 +123,8 @@ void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr, #endif #ifdef __KVM_NVHE_HYPERVISOR__ -void __pkvm_init_switch_pgd(phys_addr_t params, void (*finalize_fn)(void)); +void __pkvm_init_switch_pgd(struct kvm_nvhe_init_params *params, + void (*finalize_fn)(void)); int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus, unsigned long *per_cpu_base, u32 hyp_va_bits); void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 2994878d68ea..5a15737b4233 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -265,7 +265,15 @@ alternative_else_nop_endif SYM_CODE_END(__kvm_handle_stub_hvc) +/* + * void __pkvm_init_switch_pgd(struct kvm_nvhe_init_params *params, + * void (*finalize_fn)(void)); + */ SYM_FUNC_START(__pkvm_init_switch_pgd) + /* Load the inputs from the VA pointer before turning the MMU off */ + ldr x5, [x0, #NVHE_INIT_PGD_PA] + ldr x0, [x0, #NVHE_INIT_STACK_HYP_VA] + /* Turn the MMU off */ pre_disable_mmu_workaround mrs x2, sctlr_el2 @@ -276,15 +284,13 @@ SYM_FUNC_START(__pkvm_init_switch_pgd) tlbi alle2 /* Install the new pgtables */ - ldr x3, [x0, #NVHE_INIT_PGD_PA] - phys_to_ttbr x4, x3 + phys_to_ttbr x4, x5 alternative_if ARM64_HAS_CNP orr x4, x4, #TTBR_CNP_BIT alternative_else_nop_endif msr ttbr0_el2, x4 /* Set the new stack pointer */ - ldr x0, [x0, #NVHE_INIT_STACK_HYP_VA] mov sp, x0 /* And turn the MMU back on! */ diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index bcaeb0fafd2d..45b83f3ed012 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -314,7 +314,6 @@ void __noreturn __pkvm_init_finalise(void) int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus, unsigned long *per_cpu_base, u32 hyp_va_bits) { - struct kvm_nvhe_init_params *params; void *virt = hyp_phys_to_virt(phys); typeof(__pkvm_init_switch_pgd) *fn; int ret; @@ -338,9 +337,8 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus, update_nvhe_init_params(); /* Jump in the idmap page to switch to the new page-tables */ - params = this_cpu_ptr(&kvm_init_params); fn = (typeof(fn))__hyp_pa(__pkvm_init_switch_pgd); - fn(__hyp_pa(params), __pkvm_init_finalise); + fn(this_cpu_ptr(&kvm_init_params), __pkvm_init_finalise); unreachable(); }