From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EE0BC433E2 for ; Thu, 10 Sep 2020 12:35:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EADAC206A1 for ; Thu, 10 Sep 2020 12:35:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="oqx7gKks"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="kQRGPBHL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EADAC206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YoRKV9MRCMUGaMEQ3jXTk44HPFhy/2EC6Ddh4MqfUvY=; b=oqx7gKksLZ5lp0qK+wgMBqlXN RwvdsxKtA7O5OwBVo5g6McNqtUXBIM+/KkZ7sEMAXs3F789EfhOG3ArSqTGyUvtYXtsjeaGKlxshq QmnOCdfyBuvuQSosJ8A9pi5/LsScpaSRZwQSRe55Hplge03KY3g0kn7dCWRkJBGBtaR7Nvnu2puQ7 HnQW0sLkwgyoDsWzietClToROpzZGMtL1q0AgPId4Yl7v5vqn75KjjFYy1HNkkQP0HMYuvbGkFjQ4 4cbWpRDXIEwJfQ+UCmXa18nLWty6ntnq/hwnWiqUgn7LBi878rPAFoEzEQQCyn7BX+uOl2utRrKww c2u2GMOrw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGLmH-0004ZA-J3; Thu, 10 Sep 2020 12:34:13 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGLmF-0004Yk-8t for linux-arm-kernel@lists.infradead.org; Thu, 10 Sep 2020 12:34:12 +0000 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 68ACC20882; Thu, 10 Sep 2020 12:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599741250; bh=8eR8TAoPbqwWQ2DQ19kAdxvtNuwY3QaCmzLRuqS+Cww=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kQRGPBHLvgUUv7jh6W3obasoLJnq3nsvGbavxuBcpB5v00Wh/cTs1QLCzfyyJYvuQ GumvkDQeBrpSJuMHjrTT06qVghug3SLOI0Ffa+syyUdY1kaIBwN1GMT4XjndYAhVHo YPJ/W1+f42Ogz3DED0b7cgwb+uWmDBTzoORYb1Bw= Date: Thu, 10 Sep 2020 13:34:05 +0100 From: Will Deacon To: Alexandru Elisei Subject: Re: [PATCH v4 06/21] KVM: arm64: Add support for stage-2 map()/unmap() in generic page-table Message-ID: <20200910123404.GA18100@willie-the-truck> References: <20200907152344.12978-1-will@kernel.org> <20200907152344.12978-7-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200910_083411_440550_351AEAB8 X-CRM114-Status: GOOD ( 30.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gavin Shan , Suzuki Poulose , Marc Zyngier , Quentin Perret , James Morse , Catalin Marinas , kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 10, 2020 at 12:20:42PM +0100, Alexandru Elisei wrote: > On 9/7/20 4:23 PM, Will Deacon wrote: > > +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) { > > + data->anchor = NULL; > > + ret = stage2_map_walk_leaf(addr, end, level, ptep, data); > > + } > > I had another look at this function. If we're back to the anchor entry, then that > means that we know from the pre-order visitor that 1. the mapping is supported at > this level and 2. that the pte was invalidated. This means that > kvm_set_valid_leaf_pte() will succeed in changing the entry. How about instead of > calling stage2_map_walk_leaf() -> stage2_map_walker_try_leaf() -> > kvm_set_valid_leaf_pte() we call kvm_set_valid_leaf_pte() directly, followed by > get_page(virt_to_page(ptep)? It would make the code a lot easier to follow > (stage2_map_walk_leaf() is pretty complicated, imo, but that can't really be > avoided), and also slightly faster. I'm not sure I agree. I would consider kvm_set_valid_leaf_pte() to be lower level, and not the right function to be calling here. Rather, stage2_map_walk_leaf() is what would have been called if we hadn't spotted the potential for a block mapping anyway, so I much prefer that symmetry. It also means that if stage2_map_walk_leaf() grows some extra logic in future that we need to take into account here, we won't miss anything. > > +/* > > + * This is a little fiddly, as we use all three of the walk flags. The idea > > + * is that the TABLE_PRE callback runs for table entries on the way down, > > + * looking for table entries which we could conceivably replace with a > > + * block entry for this mapping. If it finds one, then it sets the 'anchor' > > + * field in 'struct stage2_map_data' to point at the table entry, before > > + * clearing the entry to zero and descending into the now detached table. > > + * > > + * The behaviour of the LEAF callback then depends on whether or not the > > + * anchor has been set. If not, then we're not using a block mapping higher > > + * up the table and we perform the mapping at the existing leaves instead. > > + * If, on the other hand, the anchor _is_ set, then we drop references to > > + * all valid leaves so that the pages beneath the anchor can be freed. > > + * > > + * Finally, the TABLE_POST callback does nothing if the anchor has not > > + * been set, but otherwise frees the page-table pages while walking back up > > + * the page-table, installing the block entry when it revisits the anchor > > + * pointer and clearing the anchor to NULL. > > + */ > > The comment does wonders at explaining what is going on, thank you. Glad it helps! Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel