From patchwork Wed May 29 12:12:08 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: 13678765 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 9D04AC27C43 for ; Wed, 29 May 2024 12:14:58 +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=ZeVEyarowWOAWYFaLR9rNrg/saH3fb20K0t4f2AGQ0Q=; b=pdDSFYwnqyIeZiuWtPvQ8h+txX Aq3zd9T15WdAdHYXyHjM1E8OvSIF0gOMz2hBJcd33jY7h02tpz0MzCuOoXqgQAmWK0O3bh5g4oSPY sYBF/YU/orPWkAAhvpZYXAwL7JBHQYvRQUGB4hTIg2mCpsbnjGGjBuZbvLBJWRtX5gZ65Hh/8NEfW O766pk2rh6hbL0tZkhTaJyi8bp2iqrpWkZFya183hUDUk8HzoykkeZIUqiSdxAv36zeK8pRs+xKKF 2/vTfcL/j3FxQnghGfeF3ovzfY0bYDHGb+H9X9y6GwsgYIent6rZ/MVRxceIZXlPnHrfEQM4WOn4K Z/yiFg0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCICf-0000000437D-1CxG; Wed, 29 May 2024 12:14:49 +0000 Received: from mail-ed1-x549.google.com ([2a00:1450:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCICR-000000042za-3fZR for linux-arm-kernel@lists.infradead.org; Wed, 29 May 2024 12:14:37 +0000 Received: by mail-ed1-x549.google.com with SMTP id 4fb4d7f45d1cf-5785ea015dbso863249a12.2 for ; Wed, 29 May 2024 05:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716984873; x=1717589673; 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=tLmL1So5x4FnLH0kyn2ty29vEdym4EM/KIgVNMwbuEQ=; b=Uf8K4d0E5rBFMdvECN+fLyYWR+wpp2fuK67vVbFYnjKT9yR/XKFiiU7yFaSOcMoomQ Osv7OQRPHYbwbeq2xrV0I0U8hWl55ik94wtiDR1VtMHtrTYeUAXGDMwgUVK+rt/XwGES FVBIrAXKUthPgbLAFRlhOMOkdHw4Eud06W/q3Gcdeyt7gYG1T6Bq6j5TQk3/eDHV6cDj o77dMEgqXTmyOGZqwhpwwFcWSkbqYVVTeHsC0FaMyIfBeRm3vzQG+hqej8pJ7A7olm// DLMLWeJ/sFlp953vAuZ7XtE5tQrIppxfLrZaXFxRm5Skj8QGP/H9v741hJJ3hpJbZJOH VWdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716984873; x=1717589673; 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=tLmL1So5x4FnLH0kyn2ty29vEdym4EM/KIgVNMwbuEQ=; b=QPT++5+lZITAlN+sn8ShcmG6CW7iqMk7oomJ1j4VLUASfVQb1H9lCBsUW4zc3Pfq4M +VYOKeja4vZKh2plX3AznTxyutPr9i5zRyaK6v9WQDq38Cg5TUr2nD1ywGt1QyQ3ZgDu 60Ei8uODA7SLga5KKOVjPKVC3+q6eZvSz2CU5zD7zgOYBkHUnw+FmIXq1NYbfMi1gLHr 6C1x7GFkbyjUCuZaS5mcDPd3YF9ocMXmZUiMneqDXx7vwhmjjehQj1gNvmq8LPo1Cv8u HAQmhQAmigE1DlkJQJbEWauZ9Np9HPp/usRuUFqj0v4WCWAdDZrT/cNEuGAgPrryb9K9 oguw== X-Forwarded-Encrypted: i=1; AJvYcCWDiKQSC4AkJqpDTw/GB9DePnkJGrBbGaghv1ZX3sLXCyqQVPEP33++2+piQg6gi6YePStwjxNyzPLT1+YV5kuGKs4peWlmHZWJJwkHkqQG4Tv9cvc= X-Gm-Message-State: AOJu0YwX3wA2Ip4V9NzQ9cnePn6w2AIWMNSX1WS0I8sG6lleIRJ59PQO agGzi3kO0VBOVbMd5Jw4/KtJvul5HMprl1iJ+VlCfDykN0a+202CyCVckQ6h0ZdUTzb9o99IZA= = X-Google-Smtp-Source: AGHT+IFoWb2krclv9TkDbcARu8wLLSDlMlxLJgD2KUqfjrU7i3St1EL1/OV74yeBjy7fXa7WBSwaGQ6E2A== X-Received: from ptosi.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:11ec]) (user=ptosi job=sendgmr) by 2002:a05:6402:3223:b0:572:6e36:f0f7 with SMTP id 4fb4d7f45d1cf-578519bbf75mr18449a12.6.1716984873520; Wed, 29 May 2024 05:14:33 -0700 (PDT) Date: Wed, 29 May 2024 13:12:08 +0100 In-Reply-To: <20240529121251.1993135-1-ptosi@google.com> Mime-Version: 1.0 References: <20240529121251.1993135-1-ptosi@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240529121251.1993135-3-ptosi@google.com> Subject: [PATCH v4 02/13] KVM: arm64: Fix __pkvm_init_switch_pgd call ABI 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-20240529_051435_941789_EB7EFE77 X-CRM114-Status: GOOD ( 14.43 ) 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 Fix the mismatch between the (incorrect) C signature, C call site, and asm implementation by aligning all three on an API passing the parameters (pgd and SP) separately, instead of as a bundled struct. Remove the now unnecessary memory accesses while the MMU is off from the asm, which simplifies the C caller (as it does not need to convert a VA struct pointer to PA) and makes the code slightly more robust by offsetting the struct fields from C and properly expressing the call to the C compiler (e.g. type checker and kCFI). Fixes: f320bc742bc2 ("KVM: arm64: Prepare the creation of s1 mappings at EL2") Signed-off-by: Pierre-Clément Tosi --- arch/arm64/include/asm/kvm_hyp.h | 3 +-- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 17 +++++++++-------- arch/arm64/kvm/hyp/nvhe/setup.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 3e80464f8953..58b5a2b14d88 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -123,8 +123,7 @@ 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 phys, unsigned long size, - phys_addr_t pgd, void *sp, void *cont_fn); +void __pkvm_init_switch_pgd(phys_addr_t pgd, void *sp, void (*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..d859c4de06b6 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -265,33 +265,34 @@ alternative_else_nop_endif SYM_CODE_END(__kvm_handle_stub_hvc) +/* + * void __pkvm_init_switch_pgd(phys_addr_t pgd, void *sp, void (*fn)(void)); + */ SYM_FUNC_START(__pkvm_init_switch_pgd) /* Turn the MMU off */ pre_disable_mmu_workaround - mrs x2, sctlr_el2 - bic x3, x2, #SCTLR_ELx_M + mrs x9, sctlr_el2 + bic x3, x9, #SCTLR_ELx_M msr sctlr_el2, x3 isb tlbi alle2 /* Install the new pgtables */ - ldr x3, [x0, #NVHE_INIT_PGD_PA] - phys_to_ttbr x4, x3 + phys_to_ttbr x4, x0 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 + mov sp, x1 /* And turn the MMU back on! */ dsb nsh isb - set_sctlr_el2 x2 - ret x1 + set_sctlr_el2 x9 + ret x2 SYM_FUNC_END(__pkvm_init_switch_pgd) .popsection diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 859f22f754d3..1cbd2c78f7a1 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -316,7 +316,7 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus, { struct kvm_nvhe_init_params *params; void *virt = hyp_phys_to_virt(phys); - void (*fn)(phys_addr_t params_pa, void *finalize_fn_va); + typeof(__pkvm_init_switch_pgd) *fn; int ret; BUG_ON(kvm_check_pvm_sysreg_table()); @@ -340,7 +340,7 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus, /* 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(params->pgd_pa, (void *)params->stack_hyp_va, __pkvm_init_finalise); unreachable(); }