Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3823902pxb; Tue, 26 Jan 2021 05:52:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6Q4xXJLuQKgu58nP0yUbxODd8zW+JXRoEfnOFOHc+vJwAZTvh+gi5DfXPN7iRx0WsZaCM X-Received: by 2002:a05:6402:757:: with SMTP id p23mr4740655edy.245.1611669167689; Tue, 26 Jan 2021 05:52:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611669167; cv=none; d=google.com; s=arc-20160816; b=OdmD5qMXsoTg7mxDDdTstvGKIhG2FYz07GrMSh0c6zkFzudYR0iHqNREqlpTLz0gg3 gh1wAaZWmFHpZ4/etG104kP4ytVt1vSeXS8Jnv03rgH5ve1S+Z5+9ThgyUkY0VwmTzVP w4DOcZD0h76Kq4MYnjYTLos/xMNBRYqKN17N3NbDgSm6b7JTe0WHeIyB9RD77x0AIC7l u8I1fXorvCHCx8Nsjt/zz2vU29YD1u7wpLbcVWyseyCNHUL0FU8ygRP/Ixep5o4EdWZo VYrnqJTrazHK1kT4WZGO6KB+IKsQNz3cV1bLm88m+8orsvCXvvITUVc5bta5L54LzoVk RIAw== 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=TIpFxQRMIa3UlWU+M7mg14F68R0wRsvBus7EpJnADXQ=; b=wTsA/YEVXjPA7l5oB9QBFRbIEBqZUTt/oCY189+HN4Mu56r72sVloIxJYulT452Y7K 0tNoDBN9RDwRQ93wFHrehVf/BwuC3xL9dEG7B9iBT8Rd4GQD95ZMqFN2pwVAglp8Tn56 tl+Dz1W0TTPxXIpz9JKmgwlU3Qs1a5ELHN1Wt2Nw0x5KJXKh6kS7G/tA2dtf138ZvOtg dZAnInQI/A+IDuZBaLhJADhZdO7izAtyjX60zu4Xx1VH7IujVHxmsjVz/6lNJ2jSAHqm neYESf9DCKYfiQiNtLHt2BuZPPpOxJfn9EQD7VSEyWgKXzg9exQoAdKarlaiC8LPZX8g BZUg== 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 re20si7161297ejb.277.2021.01.26.05.52.23; Tue, 26 Jan 2021 05:52:47 -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 S2405356AbhAZNt5 (ORCPT + 99 others); Tue, 26 Jan 2021 08:49:57 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:11447 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404868AbhAZNnB (ORCPT ); Tue, 26 Jan 2021 08:43:01 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DQ7Db06DfzjCXQ; Tue, 26 Jan 2021 21:41:19 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 26 Jan 2021 21:42:10 +0800 From: Yanan Wang To: , , , , Marc Zyngier , Will Deacon , Catalin Marinas CC: Mark Rutland , James Morse , Julien Thierry , Suzuki K Poulose , , , , , Yanan Wang Subject: [RFC PATCH v1 5/5] KVM: arm64: Adapt page-table code to new handling of coalescing tables Date: Tue, 26 Jan 2021 21:42:02 +0800 Message-ID: <20210126134202.381996-6-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210126134202.381996-1-wangyanan55@huawei.com> References: <20210126134202.381996-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 With new handling of coalescing tables, we can install the block entry before unmap of the old table mappings. So make the installation in stage2_map_walk_table_pre(), and elide the installation from function stage2_map_walk_table_post(). Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index ab1c94985ed0..fb755aac4384 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -436,6 +436,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; @@ -550,13 +551,13 @@ static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level, 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 there is an existing table entry and block mapping is needed here, + * then set the anchor and replace it with a block entry. The sub-level + * mappings will later be unmapped lazily. */ - kvm_call_hyp(__kvm_tlb_flush_vmid, data->mmu); data->anchor = ptep; - return 0; + data->follow = kvm_pte_follow(*ptep); + return stage2_coalesce_tables_into_block(addr, level, ptep, data); } static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, @@ -608,20 +609,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.19.1