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: 12631539 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46D7FC433EF for ; Mon, 22 Nov 2021 09:58:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238955AbhKVKBh (ORCPT ); Mon, 22 Nov 2021 05:01:37 -0500 Received: from mail-sn1anam02on2110.outbound.protection.outlook.com ([40.107.96.110]:37558 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238875AbhKVKBg (ORCPT ); Mon, 22 Nov 2021 05:01:36 -0500 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/gvp9BGgreFuN8mFMtR73QcVRD36BG1M5MnEZagwkvJdLkc6e10twd2BT/yyIjpG7TCwKKsBAGb5xuWB0pysH/CDJaa3wz2SS3aXioWUXRP22pcAXkHv03SoZdqZbMND/2Y75Ddz3Am5XuExJXvVi1j6SS5h9ncSYJNrciEYYCg/oipuoa+LMeMy2uHwRC1sBWuB30Q4fz5yyDv0G/YsxZXJlaQVgJFWUWQpHzkckpbS/L5Kqdnn9o/JWSGyA6ChLqd2EO/DJ+AqMqmB++SpaBh3sPJ4DgtX2Rpkt+nnJOhKlURqwMLhSLEvOTAh/i4SYLl+8ZKtAdbZalYMS4Mji7rTzkjTTcSWCruk/IZMJltylncGkMxLB3BhGNZ8NmZOzOQugwbnYYxKmVWIjFB7bIjfGupY62JCayBfdW6KWE3LVsqTh85TwIxv4G8G6cX0izOiaQey/oUgt7Aw6XmoixY+xfKbr/n7XV6rxji9tQwAJv+8j+Sv8XGHjBMWhcsWNnvJ+InJW0xnXCTTKwJicn2bcKBBAyHKaqj/Yv98nqyJGq53w0msuiesaLmOqV/pCmgCx4IMMXPPjw9FT4r1Y+kOstoX4LwgaTnwflRrJTyQYiA8nAUE8v20p31H0alsSQdqz7YEIR5zmT+J7drOzl5sCxHh4tYl0t7EuvBrKViwYvWJmS7CGRf7SO+PvDvFm3MtkGUp3VB6Hb1SDDRs93bYPyuh5KM7xd587vjUFN1WcscimEiDGILUafQWFoq58wBDuC9evTMwWKDXQFC4TJp0wM3SeHQRwtlYBlIpKDUzr2rc4WymZzfWQfd2ZjwYAWSuuc42gIYhQVFE0MCLmMYSMw21m3ZjkUEF4MJyBn8MtUTKP+95cPVE1AvMqFw6O4prsY2n0MzW10vnjeyUmmEaVVJwuRRJ9/i3tZ2359kWBg+WcS8q/2Ky/t+FiFrEmMXaV2Pfp7OmRWO4duYhm9OEZP+rPAH8YdOGOG2Vi/WWzR9/rhGdp8GP8ppkiYTApySjVDIEZsoiEWK7mWaY+6/O+lBxNLb5QLsDnGtE81O+uWrbZUQJI3m43xMKv52R4X07RGogcvBNV34cDrwtE3RNUoNEra38AbI0krLTC7Jbfj9xPcIXUmZkKqd/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 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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; From patchwork Mon Nov 22 09:58:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ganapatrao Kulkarni X-Patchwork-Id: 12631541 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C140C433FE for ; Mon, 22 Nov 2021 09:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238983AbhKVKBi (ORCPT ); Mon, 22 Nov 2021 05:01:38 -0500 Received: from mail-dm6nam12on2099.outbound.protection.outlook.com ([40.107.243.99]:15136 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238871AbhKVKBh (ORCPT ); Mon, 22 Nov 2021 05:01:37 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ui+YOdN6jbxFoj1ZzTA+sSC7gzr9cFsy2XHynu5Mi/6xmyGSV1kZKE7XO8mEqDfIPHcB8552CfKQvxPUkfuKZ5vv80iNiT+XqYoZ/sBDZKLKegx6yoPzYbwV+zqgJqa2Yr2kwE8RlICBbMJX9uCw7Xxnf9ACiGBAzFkLU4VcuTHJzf7bDfo0M0kl7b1gD1HTYPXTPM6KWkZu1R6qzg3Io2PUedMg3BG7c6He7K3vqNsNRat3ZwZh7PBldop1genJrsDGLaSDrq/zFYK26g9sTqcep063a0xxBwREKfHAHqO84uDeuZ3u+fBcibz+vJb33/YltkOkqw/n1F1NXcYLAQ== 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=3DJreqAjXHLWdWpJd1RYObTOLVCDMK3Rp3GPJBL2cXk=; b=dbObIsVWCdjOMv3Q58iA1gzeKpBW/aAfs5Z6/94yw9dsrJzGjTmMZRcN2Br6zLy6OIP/MYvFEA7uk/7/tpWXQIrxuVhHiyLxcwayxUiOidcNDPTVnNpnOb0m0wsTUjWrhV9FWVshY1uPStYWOd5RZNn/OJFUP4LGeUF8kME/XX4HfVWQICo06N4ZzKwNcfrrsU7FwDTkStb0ONYFcntfX0OEnTNyI4oBwZStHh78hHhqTVM/qzdOvWxtM4tAPS/4n+ldjKCToZg7gF1rAdwUy/PrvL7eN6ztuZ30T2quzHX5ya/4e7tBTpd56NYYuJrztFEP5a1mYz00NmnSayL9uw== 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=3DJreqAjXHLWdWpJd1RYObTOLVCDMK3Rp3GPJBL2cXk=; b=ijd+IeGmcjxHR7/XBTvphYsQnoGRTk29JZ/MxD9n4KVhSouQrHbleYqYbHbDq0VBDYhTBeEgdmcgZY+LAI0FoMmq9ZaOExI9PTcowOhOYVcfqliYyeozzyLx4nBbWY7IEdRpTkT60+EVBoB55EqWXdAzBDHI2PgtxoSGrRAU9jI= 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 DM6PR01MB4124.prod.exchangelabs.com (2603:10b6:5:1d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.24; Mon, 22 Nov 2021 09:58:29 +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:29 +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 2/2] KVM: arm64: nv: fixup! Support multiple nested Stage-2 mmu structures Date: Mon, 22 Nov 2021 01:58:03 -0800 Message-Id: <20211122095803.28943-3-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:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c13fac82-feca-4e22-0f16-08d9ad9ea2b1 X-MS-TrafficTypeDiagnostic: DM6PR01MB4124: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R/P9f9ti+LNpX1prLXg7YxW9u8RcvdSlVpgTDZ37NSHfTxejy8NojEh1waTnwow26Z3WM5Hfp5/YB9hwt6idUJOTUcH69DAKbkQG9pj+rg4vyf42B73Ewiz8TXuvzPuhbxhDODz3F7smYK817YIpoROUeFdPEzcJRIcoJnAqGiZt2gliLcXqNgP5ntsqS7asjsEKv3qBCbffoy8wjRjQeL4qF+G3f9fl5jUR+t6emL6ClHJptynjDYHS45og8PUMArhGYI4tlUD4qALjgiEK5k1x7pZq3rjlpZtioUqIw5tpJGxejYCYPQp3b/WX4RmL7obBZdAJ7+1zqX7yIyVwvuknQaVm2ywDmdT6dMOnMA+/Fqc7+e7P2PfHTEvORPDrBqiCW7Jakj6s29B6i7tFKfSCHd+5pNNqbPSQepzQ4TAcdLtE9R7gR4lFTU3LiyqGdCAOluARSoqZA08xlgX+oG4tXvhsJDDR0aOOfgGrNBaygq/24dSB1qnQE1EEfEnGSXXQP7JV7Zf2bo/Qr47Lc3VNqejTTk5k9llIPNShqcxVxIR+TVkgOT11CwxTC3Co0S9/SVLsWTLy1MJYE0kCk0kLGkNH/cTmOd9N95tVb6ZSDl9/k3iMDlwknMpsP1SW3DNHPkEt2b+SICL5VuMpTNbnkWwAyDecmoiYMfJgCA4KUpNuU/hpoQHwpnmVorD7Q1NyiFJZ7zv3kQdCE/03LtMtBf2d4zRx9PTcgoDrLKbtbp8gT93X5MzxQ/KJmExJqJ9k6QM0mkhX20c7gZwjr+mEj1KFgTSg6A9WcgqVw3Y= 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)(86362001)(6506007)(6512007)(316002)(6486002)(66946007)(1076003)(6916009)(5660300002)(966005)(8936002)(6666004)(2906002)(38350700002)(4326008)(66556008)(66476007)(956004)(2616005)(83380400001)(107886003)(38100700002)(508600001)(26005)(186003)(52116002)(8676002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W6rNEJzUg8iXb7BUThK4U9/GgEXvrHRtD+6avgGJvGruinNVvBjM8Dz0xhuR9JLQ2EuwoKp6AFrUcY/9zd32Nby1tqAhGYzC/Vyo1ZavYnqYbznpAjV3WF9IFTa/t0hlBaMYUp6uoodloWjGjy1d4wPep+yssHomQfqHEGldoxNU+ZOwSmnrHJPcLv+y7MGK+pJy5CQluZ4o1NcMFGPOfp/ZSO2+NlZSD+QHK63eF9LsDR7qLzr79auCZ7W9obItDq184ONRN74Hs28Bl9liDi9Z842RxFZlkuuC0XQ9w22nBP16KtR5i1aK7nF4YkKG1Hqp/RxwFKh9ezhghBWV/yUxRt1HOjxUQ/iG2IxY6nqGkl9TwzJWH9Anjn7rO8Rgb4yuXy7Hi3G4S28gqOSiphKnls7IIgIf/gtoQ3GlSwSneOxlg309s9E0R+5KB2LfkO/jgZ/BojT8CRczrc0O1vZh8imyIXbg8l7pvgABoLgpgQylmJW8hWYpJFSsv12WxpfpnkN4wXfrICWKbd6Fi9emZwEyWfh89HpUBLjvCgjCd0rcpd9gWgSYEHh2eEB6vCgwMnFza37yt2ab3LFtIqEvuXPXFwpteIeYs8LAREJTD7mktSloK8eAv5Q8bVpq24f+vT9k9I2+MMJnQtjK4xFBnyYu1bBatLmi87hBbey5AjbBnG7+GURr411v1vosYwHT1ckzrgz0t+CdBe6GQu6rby9NiO4B/YqZ0KeGKTM5oLloDdhYiSFWFTfSzeiFz3CaOB1ZjdSE8oIbEftKBZJg6y36uBF0nSO8Ef1Y43E27Oz9adWPzShE/x04QyUifK5gpMpmQWCuihJj3qjDWnGrvd3gU+s32WEfpPj6u0T8hBbVrAlM7cTuBJYUoVwNfwfCs1WLmc09DA5652tIRoB1QnNdZmD84LEVeCrQYLVfUNciA+2mGV6E7wh+vuXb5GlS170mkkK4HaviPYf5iyiyMepd6JlOWj971p1I4VHbXe8N73ac+JXXYgT3rLWm8YeGhY8rJCOmYptGRbv2ljGlnU1pyWHoPZqPTXcLKGSTRE7Bwx7BWotS/pAULe5d+nwnDUKBUCTtZPuKHCyc2Re1z6bPdTS22e93NvAYY3VOTJtXDRrKaiNb2i9+ksg3yl/PPq0Qpe6NyD6pvK/COY0SLw6e68LiNTTdxbr9/IHqhQaEKdz6EzIGL638PjR/kk4DK8dfb/v9bCof3Ip0IQHsX9BGz13cj6vn1Ojs6zdAyueHfKwm8SoUdEjPprAFKig61e3dtEbxljUEfpwy120RBMV16/b9Fy3148YGuLafCAS/PMAGxbJtZ9Eo6+5xET686rK1+S67n3PNopYcjTMvslBwuF3nXuhd0lHFk5Tv7yxZJmxNVBYk/oan1l13lcdDLbHhjzwcSV/QxARYdHmjZHPcdcq59bOBMX5eHdDhGELNNYuew7YU38DZfYFdn54cGFUfM9k8JCRm4OJf5W/qoHYBvaLT4DwZykACnwPmmXKWCduWCzvYRYly0LI6BMmCrnpGj1o0rDNIR1hJX2BhfPm8s8DczeqJQ7QpxZxz7F3cCZdzBoOcdAOlBjAAtnA3h4gjujkqxBg0+51+JE14Z4CgXfa5bVKrmUuwiStgsrrXWwtBkAUh3LYoZeCkwRbgo1JEnNgLrx48RuDoVcfE1GIaV9blClEpYz0tFJNiWr7Yh+wDS1ShM/978CVJaVbaCk8/QeZrn5B/3e8Jxw== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: c13fac82-feca-4e22-0f16-08d9ad9ea2b1 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:29.7528 (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: UxRXn+9qtOQ8j8YzkwfbNH/ozF1xX5uhbQ9O4LHj+9VxWG9p7Ar10tibzfYXKyuI7yl4pxQoxoxXVja4C4dt4VNS/enh8RodZS6IBI/MOwNNLkeLv1i2TxEJBC7QGcgJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB4124 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Commit 1776c91346b6 ("KVM: arm64: nv: Support multiple nested Stage-2 mmu structures")[1] added a function kvm_vcpu_init_nested which expands the stage-2 mmu structures array when ever a new vCPU is created. The array is expanded using krealloc() and results in a stale mmu address pointer in pgt->mmu. Adding a fix to update the pointer with the new address after successful krealloc. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/ branch kvm-arm64/nv-5.13 Signed-off-by: Ganapatrao Kulkarni Reviewed-by: Ganapatrao Kulkarni --- arch/arm64/kvm/nested.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index 4ffbc14d0245..57ad8d8f4ee5 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -68,6 +68,8 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu) num_mmus * sizeof(*kvm->arch.nested_mmus), GFP_KERNEL | __GFP_ZERO); if (tmp) { + int i; + if (kvm_init_stage2_mmu(kvm, &tmp[num_mmus - 1]) || kvm_init_stage2_mmu(kvm, &tmp[num_mmus - 2])) { kvm_free_stage2_pgd(&tmp[num_mmus - 1]); @@ -80,6 +82,13 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu) } kvm->arch.nested_mmus = tmp; + + /* Fixup pgt->mmu after krealloc */ + for (i = 0; i < kvm->arch.nested_mmus_size; i++) { + struct kvm_s2_mmu *mmu = &kvm->arch.nested_mmus[i]; + + mmu->pgt->mmu = mmu; + } } mutex_unlock(&kvm->lock);