Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp203559rwb; Tue, 13 Dec 2022 16:16:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf6tteaqRpkdddJ1U5e6O59wyekAzeqwcqpY+LFha0mmL0vTaH5Wz4ZyYEDPTrkNGMaol00/ X-Received: by 2002:a17:902:f60a:b0:187:282d:6990 with SMTP id n10-20020a170902f60a00b00187282d6990mr24936876plg.28.1670977017572; Tue, 13 Dec 2022 16:16:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670977017; cv=none; d=google.com; s=arc-20160816; b=kZVCnq5g1aiqBhApKqIoQyHZJKWU5/CR4ZPbm+iHQAal+efKqWiamPkken3mxN0Pu2 z1OVSe/VAzyNubkYoN0H064gUEuV6p+mhltaB2DysTE/tMz4MhkQc6OTiN8Q6OvAuLH0 nzjps7ZC/jgDqNw5B+4RP5DOqiUTXkR2pI742HcMwHOGLU2H/iMBHswkJuAMsxObz+Ea JKxtdz8iFYPHHehlruZO6GD6ACsGH6gEUemUBxS/AiWtdOHh7PrRjgy2PV68o7ILehtb yWl223marB1nJbHifhX/VdOx3l1ShHaEG1m0BOlU/L0pAbuASnP1q+U73FRkH//DsmyV ty3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8b5WecLz6ilBB8EW+pZrrbCkPphDzyvb2ZEZHud8SYQ=; b=VkKB1IghQiUrO7tZUypokKBztbUqoqAjk8R9y7TxFv4HMA/yGKPXAFwR8SFzQctwC5 FrW31ylVvNa7pjiVifIgmfuT6v8sKpYIbItU8soQ+6d0+Jr0T5d8giDsQbdvayeHNQ0N oVUvu3/ThofpMSMByewJGkh+9AOhBJMW5AcL8NsNEFqnOPlD2Vk2wO51hdLlY/2SLlv8 Qedn69owdcNT5vLVApadz7XC0C37kQp5ls2YtJH5tw8/yH00tftZQqI1m3+Pkh92TuAe YX3EwvChdESJdNFGPTcePamQPR6r9EpOzEj78TWSGmOjCXu6H9598Jt/NxTDy0SQHwMe ufJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lEyLKj1q; 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 5-20020a630e45000000b0047865b303a5si13688405pgo.762.2022.12.13.16.16.46; Tue, 13 Dec 2022 16:16:57 -0800 (PST) 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=lEyLKj1q; 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 S237276AbiLNAPW (ORCPT + 73 others); Tue, 13 Dec 2022 19:15:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236726AbiLNAOx (ORCPT ); Tue, 13 Dec 2022 19:14:53 -0500 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48DB22935F for ; Tue, 13 Dec 2022 16:12:29 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id s14so11505789qvo.11 for ; Tue, 13 Dec 2022 16:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8b5WecLz6ilBB8EW+pZrrbCkPphDzyvb2ZEZHud8SYQ=; b=lEyLKj1qb43Cid0n7/PIPiHIcAYXLprGcR4kUQ+r7d9F69GNPAqUYGInIf95DtSFFf ss8dF706t++3sJZpm2mAYlReOwWCwxPEsqfmndv8GSXWPYJd+FCGQriGo65LNzyo1RVE RGDw/fR4YlZOV17x81AafRWabC8E+wiFS8lFWNzBUGryfY1QAgtDKqJL9gp+wIm4Ckb3 dMU4J0KydTH8dCuX8uKunomy6djuU+arcoZ83R7Rzgc9SwJs1NTPfwW/GtERbt5aXbfK PPCfiLkM13M9CDItTmii+JlQFa/Ze7/FCz+Ewxq613SGYJIuB6NfOVzQ+FPCuwjR8gnk l1Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8b5WecLz6ilBB8EW+pZrrbCkPphDzyvb2ZEZHud8SYQ=; b=Kov+Rubul/V1C2F593C9V5RL1vZhXzS985AKHZJ6lGnTGWVl6heZi4vEeWwlERcs3N m9IVBff4x4yHVZib3Ei0FotLQkpFe7exZ6yN+M+j9Igu+ajtPlaSu+TLKFeTLdAclm2K /4mvIduqdlDfgrlP50xOiaaYQbOub/TmMrOAlF7xoODlgk1i/NqyufVUj2eBJUua6EoS 9OUriOzUSiEbSwaczwMnieRZTvz30ReOpppGTrKB+YNTWFLbajPXX3ZzFYEW3JXvsIbS JQcbNVYT3vMNfl1LqAzPS3MAsm+LrzAIm4pV7Bci5Hl9T5qbBfzCqp80MOC6Cdy+OBWj AgqQ== X-Gm-Message-State: ANoB5plhizN7hoJQSNQQRqgVdbds2kmb44Kuj5u49xYl3EGtfpKzD5nL YZ6gQPJyOiCrDRHAVZ4wi+IdKL/Qa7af1yc04Y5+sw== X-Received: by 2002:a0c:e6a9:0:b0:4bb:892a:fc11 with SMTP id j9-20020a0ce6a9000000b004bb892afc11mr68783673qvn.28.1670976748276; Tue, 13 Dec 2022 16:12:28 -0800 (PST) MIME-Version: 1.0 References: <20221206173601.549281-1-bgardon@google.com> <20221206173601.549281-3-bgardon@google.com> In-Reply-To: From: Ben Gardon Date: Tue, 13 Dec 2022 16:12:17 -0800 Message-ID: Subject: Re: [PATCH 2/7] KVM: x86/MMU: Move rmap_iterator to rmap.h To: David Matlack Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Peter Xu , Sean Christopherson , Vipin Sharma Content-Type: text/plain; charset="UTF-8" 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, 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 On Fri, Dec 9, 2022 at 3:04 PM David Matlack wrote: > > On Tue, Dec 06, 2022 at 05:35:56PM +0000, Ben Gardon wrote: > > In continuing to factor the rmap out of mmu.c, move the rmap_iterator > > and associated functions and macros into rmap.(c|h). > > > > No functional change intended. > > > > Signed-off-by: Ben Gardon > > --- > > arch/x86/kvm/mmu/mmu.c | 76 ----------------------------------------- > > arch/x86/kvm/mmu/rmap.c | 61 +++++++++++++++++++++++++++++++++ > > arch/x86/kvm/mmu/rmap.h | 18 ++++++++++ > > 3 files changed, 79 insertions(+), 76 deletions(-) > > > [...] > > diff --git a/arch/x86/kvm/mmu/rmap.h b/arch/x86/kvm/mmu/rmap.h > > index 059765b6e066..13b265f3a95e 100644 > > --- a/arch/x86/kvm/mmu/rmap.h > > +++ b/arch/x86/kvm/mmu/rmap.h > > @@ -31,4 +31,22 @@ void free_pte_list_desc(struct pte_list_desc *pte_list_desc); > > void pte_list_remove(u64 *spte, struct kvm_rmap_head *rmap_head); > > unsigned int pte_list_count(struct kvm_rmap_head *rmap_head); > > > > +/* > > + * Used by the following functions to iterate through the sptes linked by a > > + * rmap. All fields are private and not assumed to be used outside. > > + */ > > +struct rmap_iterator { > > + /* private fields */ > > + struct pte_list_desc *desc; /* holds the sptep if not NULL */ > > + int pos; /* index of the sptep */ > > +}; > > + > > +u64 *rmap_get_first(struct kvm_rmap_head *rmap_head, > > + struct rmap_iterator *iter); > > +u64 *rmap_get_next(struct rmap_iterator *iter); > > + > > +#define for_each_rmap_spte(_rmap_head_, _iter_, _spte_) \ > > + for (_spte_ = rmap_get_first(_rmap_head_, _iter_); \ > > + _spte_; _spte_ = rmap_get_next(_iter_)) > > + > > I always found these function names and kvm_rmap_head confusing since > they are about iterating through the pte_list_desc data structure. The > rmap (gfn -> list of sptes) is a specific application of the > pte_list_desc structure, but not the only application. There's also > parent_ptes in struct kvm_mmu_page, which is not an rmap, just a plain > old list of ptes. > > While you are refactoring this code, what do you think about doing the > following renames? > > struct kvm_rmap_head -> struct pte_list_head > struct rmap_iterator -> struct pte_list_iterator > rmap_get_first() -> pte_list_get_first() > rmap_get_next() -> pte_list_get_next() > for_each_rmap_spte() -> for_each_pte_list_entry() > > Then we can reserve the term "rmap" just for the actual rmap > (slot->arch.rmap), and code that deals with sp->parent_ptes will become > a lot more clear IMO (because it will not longer mention rmap). > > e.g. We go from this: > > struct rmap_iterator iter; > u64 *sptep; > > for_each_rmap_spte(&sp->parent_ptes, &iter, sptep) { > ... > } > > To this: > > struct pte_list_iterator iter; > u64 *sptep; > > for_each_pte_list_entry(&sp->parent_ptes, &iter, sptep) { > ... > } I like this suggestion, and I do think it'll make things more readable. It's going to be a huge patch to rename all the instances of kvm_rmap_head, but it's probably worth it.