Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3925711pxb; Mon, 8 Feb 2021 03:46:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoyqOMP55oIzMr8hafQxF5MIwAhPllswSFg4msTdhVXyvlgz2lT69ZWus63QotQqJ6qdtR X-Received: by 2002:a17:906:1f42:: with SMTP id d2mr16479061ejk.297.1612784809985; Mon, 08 Feb 2021 03:46:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612784809; cv=none; d=google.com; s=arc-20160816; b=hoDI5k6553u3ILscyK+myMYB7eVGmbvdsRFw9uGnYNKnA3ph7/tqRDbxmCoRSxu4wx epUqs6UzWR8qVJCWDhd15wG20jcLplJGfwA6udMuK3S/gbWy4QZvHu8BF14BkHu4UtF3 CacFwF/98thsQgBK6VJEgLSWETYc9faHvFr5RLPUZ9D2ESeiie9yvKJ3zAGQiYLGdVWR ereoAwuaZ1E66jxm4sVkvMPrmJva8P2NgDQ4Lkp1XzW348Z9skxucd+69LzsBd5DnXJs Oxa4nWC7hRI5xzie/BKKWZDtC4hVf4kspVHRODTjkmkz886jygjhlXe0Jt+t7lguXTM0 OZiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=EPo8bI8ZYPtITZJRxEtTCE0cfpiZLX5YcScNjUxgCnE=; b=XtJIPa8l6xs/C6j4G99lBe6YKY9riKfQhpRoGZkhcyexO7bWHv79I2ZGX7lHDkVp65 GafXS4iDvKILjJtkJAmqHhwNyvkjYL7fErEw51IXYDXywlvOQSPl86fSiNtnaRt6eFHX Xh31r/5Yz1jJva2izxNZ5Ea0lDRsBtnzBGB1SgvynuLtuEvzyhPHlecjC4cIY/nDG3ch ZKbjyw3Sw9IYSKrpuYlupcIxLfMRb4n2YmcV5HedtLcseCIpPgCh8DiHhmMIjk3WENEU Fg1Wz3FA48WU81vLn3Xp/Bx7mroFibUVIUJeKVuSoxr78qpIvs3ixWDxXxVUK8vaQmAg cs2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bw26si10762450ejb.644.2021.02.08.03.46.26; Mon, 08 Feb 2021 03:46:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232109AbhBHLnB (ORCPT + 99 others); Mon, 8 Feb 2021 06:43:01 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:12151 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233065AbhBHLXv (ORCPT ); Mon, 8 Feb 2021 06:23:51 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DZ3WW1s5Tz165PY; Mon, 8 Feb 2021 19:21:43 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Mon, 8 Feb 2021 19:22:56 +0800 From: Yanan Wang To: Marc Zyngier , Will Deacon , "Catalin Marinas" , James Morse , "Julien Thierry" , Suzuki K Poulose , Gavin Shan , Quentin Perret , , , , CC: , , , Yanan Wang Subject: [RFC PATCH 3/4] KVM: arm64: Install the block entry before unmapping the page mappings Date: Mon, 8 Feb 2021 19:22:49 +0800 Message-ID: <20210208112250.163568-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210208112250.163568-1-wangyanan55@huawei.com> References: <20210208112250.163568-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When KVM needs to coalesce the normal page mappings into a block mapping, we currently invalidate the old table entry first followed by invalidation of TLB, then unmap the page mappings, and install the block entry at last. It will cost a long time to unmap the numerous page mappings, which means there will be a long period when the table entry can be found invalid. If other vCPUs access any guest page within the block range and find the table entry invalid, they will all exit from guest with a translation fault which is not necessary. And KVM will make efforts to handle these faults, especially when performing CMOs by block range. So let's quickly install the block entry at first to ensure uninterrupted memory access of the other vCPUs, and then unmap the page mappings after installation. This will reduce most of the time when the table entry is invalid, and avoid most of the unnecessary translation faults. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 78a560446f80..308c36b9cd21 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -434,6 +434,7 @@ struct stage2_map_data { kvm_pte_t attr; kvm_pte_t *anchor; + kvm_pte_t *follow; struct kvm_s2_mmu *mmu; struct kvm_mmu_memory_cache *memcache; @@ -553,15 +554,14 @@ static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level, if (!kvm_block_mapping_supported(addr, end, data->phys, level)) return 0; - kvm_set_invalid_pte(ptep); - /* - * Invalidate the whole stage-2, as we may have numerous leaf - * entries below us which would otherwise need invalidating - * individually. + * If we need to coalesce existing table entries into a block here, + * then install the block entry first and the sub-level page mappings + * will be unmapped later. */ - kvm_call_hyp(__kvm_tlb_flush_vmid, data->mmu); data->anchor = ptep; + data->follow = kvm_pte_follow(*ptep); + stage2_coalesce_tables_into_block(addr, level, ptep, data); return 0; } @@ -614,20 +614,18 @@ static int stage2_map_walk_table_post(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, struct stage2_map_data *data) { - int ret = 0; - if (!data->anchor) return 0; - free_page((unsigned long)kvm_pte_follow(*ptep)); - put_page(virt_to_page(ptep)); - - if (data->anchor == ptep) { + if (data->anchor != ptep) { + free_page((unsigned long)kvm_pte_follow(*ptep)); + put_page(virt_to_page(ptep)); + } else { + free_page((unsigned long)data->follow); data->anchor = NULL; - ret = stage2_map_walk_leaf(addr, end, level, ptep, data); } - return ret; + return 0; } /* -- 2.23.0