Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3549156pxu; Mon, 30 Nov 2020 05:39:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJynSbul2z2F7teFfMh97PRbYonUjHhKNObROJ7wzZqtYt8aZClE5uMPGtCWqvVl5x8x14AW X-Received: by 2002:a50:b584:: with SMTP id a4mr21208434ede.301.1606743568215; Mon, 30 Nov 2020 05:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606743568; cv=none; d=google.com; s=arc-20160816; b=rk1BII8dHvAZ/qhifUGYjxvYwhVDYqQF9ZjVijW2TdPVlaUrL0qOiUePjfhqEQxwR2 oKjB6grbceanJl/jSM2MaQ/4JFCgVq+gD5stne2rVBy+nBjUE3thTlbnwgdecngZFskd XAiTzk8Aa9d/znofHFst8K9gDVJk+hnTapoSMhnD2qcfgYaQm4QalTccDNHG0djJJ6vo Qqm2jzuQvfRaddOSzeaXIf7JOhRAjXHxvTpXJXyEVmzT0C3EQHc9sjRZYiDEe7NJKMIp AQzy0kCRaFCwstWpDocc23xnHK4o6GIsPhdTaYjsDSlhlICRgqrkDqxlr3gq9/MX5lrO UyTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bRW8f8pUKxT89qoNu70H+Ac5/Csw8yyEopTBBO5sii4=; b=n6IqTWdAK5Q32+fAq+1RFyBNfaYR2//jfdBKf0TMar7XWujxxYCrJpe4UfBezYmnBp DBQRd3un+pkokq42bYiCX7WUABhqTml95G+/NHlwgWVp21C9kZ8rewwtWRuIuB0Mp+v7 X/vuzjiCNbggaIFGFvQzcC2+9/lLRkUaxkY+AgCS/e1vPcZUZcQ5dSNoYRx33yud9bEA 4XD5Lm4ZIBUMna4Jc99d783RvPukU96vk3yIJJIXMngU7hqGxpphA4kN/BHQ1PCVapB3 mNLiG4Eie2QVo8MikaRQ6hLIc+0sudTMqOhZ6i3A2kBTMz4bcORxU7e94g5ahkLTbxD2 iCEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dLD0NeIK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kq19si10230088ejb.117.2020.11.30.05.39.05; Mon, 30 Nov 2020 05:39:28 -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; dkim=pass header.i=@kernel.org header.s=default header.b=dLD0NeIK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727351AbgK3NfJ (ORCPT + 99 others); Mon, 30 Nov 2020 08:35:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:58670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727328AbgK3NfJ (ORCPT ); Mon, 30 Nov 2020 08:35:09 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2BAD720870; Mon, 30 Nov 2020 13:34:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606743268; bh=lc+QhqwU7aPlngAV30FSRSh9frD9YFy1xiMIDEc7/ek=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dLD0NeIKHfj3LKCzVj4ECu0YXu14LGj4tF3/fVOTM020EOYxI1Txtk987QZoYlVBq kggtg2/rFgP3M0oiF3Zj5q0z1/RKvpA111kLJUdRbY2B9vFbDGWa8wOubYBO8JH0EC p7wl2iZz9g4ZGJibeuO6fdU1Hd90R0+G/2Ze8W6Y= Date: Mon, 30 Nov 2020 13:34:21 +0000 From: Will Deacon To: Yanan Wang Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Marc Zyngier , Catalin Marinas , James Morse , Julien Thierry , Suzuki K Poulose , Gavin Shan , Quentin Perret , wanghaibin.wang@huawei.com, yezengruan@huawei.com, zhukeqian1@huawei.com, yuzenghui@huawei.com, jiangkunkun@huawei.com, wangjingyi11@huawei.com, lushenming@huawei.com Subject: Re: [RFC PATCH 2/3] KVM: arm64: Fix handling of merging tables into a block entry Message-ID: <20201130133421.GB24837@willie-the-truck> References: <20201130121847.91808-1-wangyanan55@huawei.com> <20201130121847.91808-3-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201130121847.91808-3-wangyanan55@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 30, 2020 at 08:18:46PM +0800, Yanan Wang wrote: > In dirty logging case(logging_active == True), we need to collapse a block > entry into a table if necessary. After dirty logging is canceled, when merging > tables back into a block entry, we should not only free the non-huge page > tables but also unmap the non-huge mapping for the block. Without the unmap, > inconsistent TLB entries for the pages in the the block will be created. > > We could also use unmap_stage2_range API to unmap the non-huge mapping, > but this could potentially free the upper level page-table page which > will be useful later. > > Signed-off-by: Yanan Wang > --- > arch/arm64/kvm/hyp/pgtable.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 696b6aa83faf..fec8dc9f2baa 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -500,6 +500,9 @@ static int stage2_map_walk_table_pre(u64 addr, u64 end, u32 level, > return 0; > } > > +static void stage2_flush_dcache(void *addr, u64 size); > +static bool stage2_pte_cacheable(kvm_pte_t pte); > + > static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, > struct stage2_map_data *data) > { > @@ -507,9 +510,17 @@ static int stage2_map_walk_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, > struct page *page = virt_to_page(ptep); > > if (data->anchor) { > - if (kvm_pte_valid(pte)) > + if (kvm_pte_valid(pte)) { > + kvm_set_invalid_pte(ptep); > + kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, > + addr, level); > put_page(page); This doesn't make sense to me: the page-table pages we're walking when the anchor is set are not accessible to the hardware walker because we unhooked the entire sub-table in stage2_map_walk_table_pre(), which has the necessary TLB invalidation. Are you seeing a problem in practice here? > + if (stage2_pte_cacheable(pte)) > + stage2_flush_dcache(kvm_pte_follow(pte), > + kvm_granule_size(level)); I don't understand the need for the flush either, as we're just coalescing existing entries into a larger block mapping. Will