From patchwork Mon Nov 22 09:58:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ganapatrao Kulkarni X-Patchwork-Id: 12693297 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 E72F2C433F5 for ; Mon, 22 Nov 2021 11:11:34 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/rYcJBlsuc7wEvxdRpl3PKeHaGvwaZ94r5+8IZ3/jv4=; b=zCS6/wxGEQrT9X yJrzt0Nn5q89FuViWPECl/q5G5/IABJ9KHPnqSYeQqt8dBXgP2jPf+Cl31Jnoh5oKlPLDOIuzvcUp MXWj6TzGWGWShQ0GmR7TdNJ/Cg1BbQvBGhjq5fizDBMC6cmm26l8CmFoBtwDbVmKoxa4OBpLm2cr1 QlApZ/vjae2zUAiHribNgPj4DQdvV0fzH5EONPR6wInFCjlyQtVzWppEkxU3UqbEJdVz3UkDUiuHx 6OLoxvHFWyhUVIJfKyfD1nk7ZKEXi04PgsPH8OljQbr/TEmBy+2vPCiUM7In+4hX/YCAe507OGKSj HmHqP1xHMNcbsqvRo3ZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp7BJ-00Fyl6-EW; Mon, 22 Nov 2021 11:08:21 +0000 Received: from mail-sn1anam02on2125.outbound.protection.outlook.com ([40.107.96.125] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp65q-00Fj9g-GK for linux-arm-kernel@lists.infradead.org; Mon, 22 Nov 2021 09:58:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GrOD36GMyJkb7c7RadtaLAQ+2jPOlKzqURBP02IMFy1vyxGRhCC47KQEhrIsOXG7NWOFe4K3BqdTKDp3ME+1z2ua49HXdogYSb7HDye1GFOmynaCv+a8rmQNmaGe6NzZ62NGhtPFoO0IGrtXYC1U/M9LZfUvaJrfkL3cVC0Olb2lK9ygeH5kOIuBBPtQ0ls/A98Zq3QsXOUDUWrPyNloZmBiiOFchPRLL7WEO9BKx5QjhreuedGx4q8gTmmd4f7jPO7jIF187wdqAksaHwOKn7c6oJMzdQCaqAvLI17txVUjzSMA1Q08SubYS7u4jdeFvyWle/R6ya2q0P2lbtzqfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UUuPIxzOLTeVM+HhcYZiOgnZeN28d/gzNV+CL7Q9Nbo=; b=Pa2xu5DJJJ05UCsks4GYeiIVcpAsXaLH8HPZDvBUECABNtkm99NOX2WkR7jb1pUJxtpt/okYPuab6dak6+Y/EDS1e4LIh/pgxqESxrHfW+whzvMPAPlxa2dJxP6/xLZXKgged1SD0Aw/JwkjQRco8UdEBR0ttBdiTtpfvq9R8sAbXFBpHkH/oAJHfQcE4DoEAT2k33k4oxJug/RVTR4/PcoT2e5FH2H7rpTLsIf9JJISZ8Op/MKDzfYFB3T3p4TV3U8hbY8WB2Fdwqd5IcvuCUDpr41c2Fn5pX4KlGby4BJ0z3se+o9zeq6UZPLoWqrP5f++OtJCPVjHqjv2a1v4FA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UUuPIxzOLTeVM+HhcYZiOgnZeN28d/gzNV+CL7Q9Nbo=; b=Vms236mcnSZfokbiN00HY8khs48zv7QhmqhTln42y2DUK8sdWrORm7/egLmTqnYGXOW9DpufoMaL7YWRm5DEBZfwqqAO0aMHrOUH/FfWaFwj0DvDO5MowIXqZToWmDUfzVl8AX4anMdyLakFTEs165zemSSwqDKJx3sC78pNGG8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) by DM6PR01MB4122.prod.exchangelabs.com (2603:10b6:5:29::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Mon, 22 Nov 2021 09:58:28 +0000 Received: from DM8PR01MB6824.prod.exchangelabs.com ([fe80::ec55:306:a75d:8529]) by DM8PR01MB6824.prod.exchangelabs.com ([fe80::ec55:306:a75d:8529%9]) with mapi id 15.20.4713.025; Mon, 22 Nov 2021 09:58:28 +0000 From: Ganapatrao Kulkarni To: maz@kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, andre.przywara@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, darren@os.amperecomputing.com, d.scott.phillips@amperecomputing.com, gankulkarni@os.amperecomputing.com Subject: [PATCH 1/2] KVM: arm64: Use appropriate mmu pointer in stage2 page table init. Date: Mon, 22 Nov 2021 01:58:02 -0800 Message-Id: <20211122095803.28943-2-gankulkarni@os.amperecomputing.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211122095803.28943-1-gankulkarni@os.amperecomputing.com> References: <20211122095803.28943-1-gankulkarni@os.amperecomputing.com> X-ClientProxiedBy: CH2PR05CA0056.namprd05.prod.outlook.com (2603:10b6:610:38::33) To DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) MIME-Version: 1.0 Received: from engdev025.amperecomputing.com (4.28.12.214) by CH2PR05CA0056.namprd05.prod.outlook.com (2603:10b6:610:38::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.13 via Frontend Transport; Mon, 22 Nov 2021 09:58:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b064ab31-2b93-4e71-e4e5-08d9ad9ea1e9 X-MS-TrafficTypeDiagnostic: DM6PR01MB4122: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 80XkJnoaNGOVdWk3GyH0Ghb8jEjeniYGsDs8Rmtu1co6pb0/rOkICpkplKOAySW/yRP36IphYi5JJiKSWmMuqYJdVBnQK3S7M5ctNf2D+rgleFRV3pCNExB+Q69d122pTHHLjnIaUxxL57l2qnuXGwORR++yDyUTQyvdf00VzgMw1NQsBUTOCt8tz3dHVnBGqOQEDdfveQsk3LUuicA4bv0GPG8yf1zw6A81Wo/T+3snAedWr/USnfcA8qETKgJSGP7VhIGlA7JFzhANAckziJNiODsj8RlNsoSrsv8Vnk87EmzRQNVV4mYWakxIfStJCourrZom+MzP9AALhyfIbQ5tFFVkvRAyc7Mb+09DufR8zom02hH4FUDycRuMx5Tm5h7Qb+uREgKIMhSJ/7K+7IiMHUMOI72n/3UxOb1ysWdFvrhYeirN2L14AzM5n4C9fLJbSt8fcsEKhcv/6dEI97mTXPvg2T6nHGzs47c0CRSqXat2uUEVVRYIlZCVMPJpR2x4N5tGOkrYg0nN6lA2QPbdlcHPjsUnVtSj2MI4/F3zFk2OEoL0nll9BDmHZa9rZamdrG7M7ddHElTj9I30A5zgtNDsZ4g5r1BwSt6mYgaNOuD7mYPjzOHjj/NENhXiV0Yi39M2EaPyHdQBbrWb9UkYSwjr4x/h0GcVpiuShoL84nbkQs7dXcWbjGVBYtnxPyfN3Ye5fXXmk6/95M9njg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM8PR01MB6824.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(4326008)(6512007)(1076003)(8936002)(6486002)(186003)(316002)(38350700002)(66556008)(5660300002)(66476007)(83380400001)(8676002)(26005)(66946007)(6666004)(52116002)(956004)(2616005)(508600001)(2906002)(6916009)(38100700002)(107886003)(86362001)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: M8OJKFRAKkfq2sz1iSdRI5FOkP2IJuN2ZS9ub/tMue+NadoVdbJiwhd+y+iowB7s/JIad+60i4ySo7VboILiAkxVNMt3YaCcWDtVmPurX+KNUsuLlT0n1kpagtE1f9AMS9Y7kfaP39mgvu4po3GdJuXw3rEhwJFVDaVrRswIk2/ZPqc+LhiY9MRSdz6ejvDpL8miiFWiPLDRmDqThYOIBTV68A3w4uEWCzEk6NzJfkhlLbdQ/Vg9TskmwL771dvc/45BRVW43EydxJbfQifgKS0WmMFHehHN0UjKzu69VAhyYUQb8Mb4RK4x+UmUqNt3NzdLtFvn9FIhwai+8/gvp9BGgreFuN8mFMtR73QcVRD36BG1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34cDrwtE3RNUoNEra38AbI0krLTC7Jbfj9xPcIXUmZkKqd/D4LQwuU+vHL+b0Hv8ytDb1Ul9cgsHgTKuL6iVtKOl5gvCww8JvbOMB5xUXcwOiMdK5TuqiU0ct791RXhSRdtxkOowRH19uYex06lwYYuvg5bV9+Fz4OVuO0d1NJLH2oj/Ys4+oXeYfL4S6sA4cd7+9V9JYDs3SCUYq7glVuj9zheL/EJNk17LkK45862t7Aylm6RzSoJ120FLQDxEYz2SrunxvqMkK/+rTmh1Ar79V5RK0alI0DNZhvaGkY4ltKpWfMM65USg== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: b064ab31-2b93-4e71-e4e5-08d9ad9ea1e9 X-MS-Exchange-CrossTenant-AuthSource: DM8PR01MB6824.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2021 09:58:28.4306 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LcfYKN6K4a3MrlY987xaBzgJbsqRr+22ZjW3yGyFlrtvEaRJG9cVSO09e+1Q90gZp9i05iUBWnOkoLJlzwhaZjyn6stsa3jD8JgGfoJt+xPUJG0VY/YU4RYd1Qa2C53O X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB4122 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211122_015834_599489_BD65566D X-CRM114-Status: GOOD ( 13.95 ) 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 The kvm_pgtable_stage2_init/kvm_pgtable_stage2_init_flags function assume arch->mmu is same across all stage 2 mmu and initializes the pgt(page table) using arch->mmu. Using armc->mmu is not appropriate when nested virtualization is enabled since there are multiple stage 2 mmu tables are initialized to manage Guest-Hypervisor as well as Nested VM for the same vCPU. Add a mmu argument to kvm_pgtable_stage2_init that can be used during initialization. This patch is a preparatory patch for the nested virtualization series and no functional changes. Signed-off-by: Ganapatrao Kulkarni Reviewed-by: Ganapatrao Kulkarni --- arch/arm64/include/asm/kvm_pgtable.h | 6 ++++-- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/pgtable.c | 3 ++- arch/arm64/kvm/mmu.c | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 4f432ea3094c..9c0c380f8e3b 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -223,16 +223,18 @@ u64 kvm_get_vtcr(u64 mmfr0, u64 mmfr1, u32 phys_shift); * @arch: Arch-specific KVM structure representing the guest virtual * machine. * @mm_ops: Memory management callbacks. + * @mmu: The pointer to the s2 MMU structure * @flags: Stage-2 configuration flags. * * Return: 0 on success, negative error code on failure. */ int kvm_pgtable_stage2_init_flags(struct kvm_pgtable *pgt, struct kvm_arch *arch, struct kvm_pgtable_mm_ops *mm_ops, + struct kvm_s2_mmu *mmu, enum kvm_pgtable_stage2_flags flags); -#define kvm_pgtable_stage2_init(pgt, arch, mm_ops) \ - kvm_pgtable_stage2_init_flags(pgt, arch, mm_ops, 0) +#define kvm_pgtable_stage2_init(pgt, arch, mm_ops, mmu) \ + kvm_pgtable_stage2_init_flags(pgt, arch, mm_ops, mmu, 0) /** * kvm_pgtable_stage2_destroy() - Destroy an unused guest stage-2 page-table. diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 4b60c0056c04..cf7e034a0453 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -99,7 +99,7 @@ int kvm_host_prepare_stage2(void *mem_pgt_pool, void *dev_pgt_pool) return ret; ret = kvm_pgtable_stage2_init_flags(&host_kvm.pgt, &host_kvm.arch, - &host_kvm.mm_ops, KVM_HOST_S2_FLAGS); + &host_kvm.mm_ops, mmu, KVM_HOST_S2_FLAGS); if (ret) return ret; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index fa85da30c9b8..85acd9e19ed0 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1018,6 +1018,7 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size) int kvm_pgtable_stage2_init_flags(struct kvm_pgtable *pgt, struct kvm_arch *arch, struct kvm_pgtable_mm_ops *mm_ops, + struct kvm_s2_mmu *mmu, enum kvm_pgtable_stage2_flags flags) { size_t pgd_sz; @@ -1034,7 +1035,7 @@ int kvm_pgtable_stage2_init_flags(struct kvm_pgtable *pgt, struct kvm_arch *arch pgt->ia_bits = ia_bits; pgt->start_level = start_level; pgt->mm_ops = mm_ops; - pgt->mmu = &arch->mmu; + pgt->mmu = mmu; pgt->flags = flags; /* Ensure zeroed PGD pages are visible to the hardware walker */ diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 0cf6ab944adc..6cf86cafc65a 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -495,7 +495,7 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu) if (!pgt) return -ENOMEM; - err = kvm_pgtable_stage2_init(pgt, &kvm->arch, &kvm_s2_mm_ops); + err = kvm_pgtable_stage2_init(pgt, &kvm->arch, &kvm_s2_mm_ops, mmu); if (err) goto out_free_pgtable;