Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1049020imw; Thu, 14 Jul 2022 16:18:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u0PzHEn3aTv/IkNq8f01InNMHCZAaatXh5gVj9fUHQiB09TzuMnBcgkObdvrfbL/tfXO4e X-Received: by 2002:a05:6402:1e8f:b0:43a:ddfc:5c4e with SMTP id f15-20020a0564021e8f00b0043addfc5c4emr15456043edf.358.1657840682334; Thu, 14 Jul 2022 16:18:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657840682; cv=none; d=google.com; s=arc-20160816; b=dpMFn3aF6eSzldVN07dAS6qA5Ou4FQ+YDXkag9uXNUuJBs5YRODkJ1f6Zc2IP5kZBI RWkFIgeruLiRpz8LqPY4jm0BUqw7/wZD7uchREU4pqF5lJULPqGnB/kBlC/WnFpTGp81 BnasX51PdJflUKyHqlYFuSSALxiJvp3vmOd9KKdA0RzLJqHjSFr8Gh9kQB1cJFpFcoev rIpOHtVBkd3j3XlxdOlfhiICsw5vzW1Lh5YA/eNMOQAdEK5aLD4idBxElEvQxcyemyuc wEPRpiPbmdEHCcKPH77X52078izacafozvC7nN7c9Oxb1ssvNuxepikvHxzxRsWpfP1o ItZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1uA4mMpLpcRR07bw1byaro66HK9+gzc14ZtiPZ8jfjA=; b=TTUw13j/wKKuRPchqZ/IW+Qhvm9kx7Jx6DXNVaxO3v07cvso1gpVoUSNy2g6lO2vqN t5eFcvq9Vlf4ffmaMazvuy/9xefA4HY6DLWZ6BtiurkI6+0l25vh/s0mvbfIetLk+MlB vD7G0UzBOeH4S650a2inR9sffL0PAp6drxRDc6eJmid72/gY5ZiPKrDotXJsfNbN3jVJ vqBcMobuF/L+zvw311u2H3YrPv7S2esoGXLKRyb0BLsAI/bPqOClhKS1w8Fk7XPuyWwP 9fq9gewqN8hTLpsA6ihLZycWVc9cyk90bY/TM3cMHG7nhxUQnWELNRPlzkc83UaH16Kc oj5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=As7pQ8CU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs13-20020a1709073e8d00b0072ae569d6a0si3665121ejc.632.2022.07.14.16.17.37; Thu, 14 Jul 2022 16:18:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=As7pQ8CU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240879AbiGNXPv (ORCPT + 99 others); Thu, 14 Jul 2022 19:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240790AbiGNXPt (ORCPT ); Thu, 14 Jul 2022 19:15:49 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6179570E5A for ; Thu, 14 Jul 2022 16:15:48 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id k19so1740208pll.5 for ; Thu, 14 Jul 2022 16:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=1uA4mMpLpcRR07bw1byaro66HK9+gzc14ZtiPZ8jfjA=; b=As7pQ8CUT32Bd1LIq4AKb1ELuwXk+Tg1MdC1AUysMK9njWTOlc0OAsXlYWtrr15WJk t5DF7RJsJdX2IR1vzbg0HicaP5A2owgtHNkeSnINSoyTDbi8Ql5QDPkxKyD4dfoUrGJo tRetXkr7kWDTsVcYinNmDFQ39nrnuRrxNd5E4wCVyv1itFi0ABg2+6qKEqwMEprgc893 TSEFRiVf74mGYfN6ZZqIzL20etl7QHWiX4IciOkajGrieYbSwPZ+5UYHPMkPzIMhAkbL PcIKqJiZwDSy4YkQnQ7E94tuNJCizdBQWm0M7qr2DoUzRPC9iCHDUTY0QU51B8YEZlMw S2RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=1uA4mMpLpcRR07bw1byaro66HK9+gzc14ZtiPZ8jfjA=; b=IyOuBUDpXzV5pkJzCHEArol9wh0nunAtW0dRK7/3BlebI7RGch0i1H8j6oTpbKrZX7 c8UUrtiwXSe8opnYXysOOEEa3gVquvO+R4JWozPPJBtprh2IINobbSyxkidHrLXQqO4m KBZRInIy9gKDbYulrLPB/EyBJSSMwtxhSzQJhWg5wc587H37TIQZbbSRtnVdVRwUSfnr UOFra2zJtvyrtjaJ6B086L1IddSzS9mwtEAFKDli0SuuwZPHtY1AmwejjnEpwEDVkoaS IgaJLbGb3w6T9MzHfWJaMWiPzoSZHxySz0DsbNhzgenJHG2A3TkeG5AonR+ttXBEG5o3 2Bkw== X-Gm-Message-State: AJIora9EWeu8D0lOT60RCVhTp0FPXo7XDjvEJBZsn0t9ETcmZcdutdBi 0zJMuUihDtoSA3XZb/eDM8uBK+4iYgMRvg== X-Received: by 2002:a17:90a:c4f:b0:1df:a178:897f with SMTP id u15-20020a17090a0c4f00b001dfa178897fmr12107587pje.19.1657840547725; Thu, 14 Jul 2022 16:15:47 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id m5-20020a170902db0500b001677d4a9654sm2016703plx.265.2022.07.14.16.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 16:15:47 -0700 (PDT) Date: Thu, 14 Jul 2022 23:15:42 +0000 From: Sean Christopherson To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Maxim Levitsky , Lai Jiangshan Subject: Re: [PATCH 04/12] KVM: X86/MMU: Remove mmu_pages_clear_parents() Message-ID: References: <20220605064342.309219-1-jiangshanlai@gmail.com> <20220605064342.309219-5-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220605064342.309219-5-jiangshanlai@gmail.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the shortlog, I really want to capture the net effect. It took me a lot of staring and reading (and hopefully not misreading) to figure out that this is a glorified nop. KVM: x86/mmu: Update unsync children metadata via recursion, not bottom-up walk On Sun, Jun 05, 2022, Lai Jiangshan wrote: > From: Lai Jiangshan > > mmu_unsync_walk() is designed to be workable in a pagetable which has > unsync child bits set in the shadow pages in the pagetable but without > any unsync shadow pages. > > This can be resulted when the unsync shadow pages of a pagetable > can be walked from other pagetables and have been synced or zapped > when other pagetables are synced or zapped. > > So mmu_pages_clear_parents() is not required even when the callers of > mmu_unsync_walk() zap or sync the pagetable. There's one other critical piece that it took me a quite some time to suss out from the code: the @parent passed to mmu_sync_children() _is_ updated because mmu_sync_children() loops on mmu_unsync_walk(). It's only the parents of @parent that are not updated, but they weren't updated anyways because mmu_pages_clear_parents() doesn't operate on the parents of @parent. > So remove mmu_pages_clear_parents() and the child bits can be cleared in > the next call of mmu_unsync_walk() in one go. Ah, I missed (over and over) that the "next call" is the one right mmu_sync_children() and mmu_unsync_walk(), not a future call. Because I kept losing track of which pagetable was which, how about this for a changelog? When syncing a shadow page with unsync children, do not update the "unsync children" metadata from the bottom up, and instead defer the update to the next "iteration" of mmu_unsync_walk() (all users of mmu_unsync_walk() loop until it returns "no unsync children"). mmu_unsync_walk() is designed to handle the scenario where a shadow page has a false positive on having unsync children, i.e. unsync_children can be elevated without any child shadow pages actually being unsync. Such a scenario already occurs when a child is synced or zapped by a different walk of the page tables, i.e. with a different set of parents, as unmarking parents is done only for the current walk. Note, mmu_pages_clear_parents() doesn't update parents of @parent, so there's no change in functionality from that perspective. Removing mmu_pages_clear_parents() allows for further simplifying mmu_unsync_walk(), including removing the struct mmu_page_path since mmu_pages_clear_parents() was the only the function is the only user of it. With a cleaned up shortlog+changelog, and assuming I didn't misread everything... Reviewed-by: Sean Christopherson > > Removing mmu_pages_clear_parents() allows for further simplifying > mmu_unsync_walk() including removing the struct mmu_page_path since > the function is the only user of it. > > Signed-off-by: Lai Jiangshan > ---