Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp268889rwb; Tue, 13 Dec 2022 17:23:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5IMZpvT3mBR/BmEOmxXQ20AHXnepehOA+7zBlixESvU+ax17BuwHnCcPhOmorsJdzNGXDP X-Received: by 2002:a05:6402:4d6:b0:45c:835c:1ecf with SMTP id n22-20020a05640204d600b0045c835c1ecfmr19636563edw.29.1670980987386; Tue, 13 Dec 2022 17:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670980987; cv=none; d=google.com; s=arc-20160816; b=o0HbxmwVkEsOnt7/demtFn8aALdE+zoDjMIzgjHQzjPrOBlht/OKnFE1y7KYmj4XTW e4CgKnNYnRc3tHGHmQ8FDbzlJI9YIYWlG+n8+lIs0ij2tuX5oJqOPyQaHzVM4Vs669Ip swcuoy7oNF7zTF8ghwlg/X7u4IDecqipiIU0Hrf+xtWCBlLeuq44GZiR/bzECgw9EvS6 4PuBwg7iv7wvZU27L9sao+ThyF4h2kseirxo51moBZQMBYa60Tea3p3mfLqCU6KKPoFe nkY2iI2zz9zltceA7YdCVSYcskydcmwYUN+Pszj+5hRrBQMkVRMjXtKpUFm1QiNVEyY2 GuPg== 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=iFJYz9RAFRJ+ma2+igrLKsa/K85AMCF2nSwG0/0Is0I=; b=o0WmnxFzIEb2qHX2MdKZgg8LKkDxf0c6Aw0gFEZQ44GJpfH0ClCwRO4bFWxVw023vE FgpBPf07F7IAEUwSZLxJOROeavb69zoaKvMzW/wDymuKMxvSODzqJa47fk3Ie5VjeBQH 8UzyFRUXjsH4j7J6f2aV4VXLsMjKWxePx2/51ek/oFjNiRl3snXuUCjBckENiayjmHGb 71BVsxn6ou+lpKuX4EF8ut9u7i1VjZN/nYxCxmnxZYrrFY2Rl5aiMOBwBCGFZOqRU/EY WPHYfKVXSAXUEX+n2FWjftuyDcY9FtEW1e69rrkWwtnJqgX0KKEtgV5ZVD+dtkIY+nXR LpGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="QBApAcl/"; 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 nc39-20020a1709071c2700b007c1052c9243si10959308ejc.15.2022.12.13.17.22.49; Tue, 13 Dec 2022 17:23:07 -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="QBApAcl/"; 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 S237565AbiLNA7N (ORCPT + 72 others); Tue, 13 Dec 2022 19:59:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236624AbiLNA7L (ORCPT ); Tue, 13 Dec 2022 19:59:11 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1274121894 for ; Tue, 13 Dec 2022 16:59:10 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id d3so1706657plr.10 for ; Tue, 13 Dec 2022 16:59:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iFJYz9RAFRJ+ma2+igrLKsa/K85AMCF2nSwG0/0Is0I=; b=QBApAcl/A+aitPzndwPA9qXJhieD/pjgx4M9t9NTIehcfML4td7MICu9t4Oghq7QRj O44kHWV4flSd0eNwu+gXmtQJgGs0VAMocQLcobYnljcEwOTioPSnGVIlM4Fb7fzpE+1F vgkdvDMbf9BpRNwqJXkL9A0FimSByviQUn2bU5IIeMcf6SwTK/8NHfyqPrGx/GAt3Xd4 XWGJWuEmhI1FCN2nUfSHNinJ5wsWsavN6g2h+rvxqCYZ2Kp/udfGcAO8iMsTcjS+BMjN aKKa079MIksRGv9HDWHpCWj5X3wyNjaaIgDEm8jC5sUEOPaaXoDNqz/hcEcKmDp3Zdvi B8lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iFJYz9RAFRJ+ma2+igrLKsa/K85AMCF2nSwG0/0Is0I=; b=3oA4LCCA8LaIPLG4MIP1fw7hBwl1ZC+tDBVfWkCqe4fCA/CriG3uNiUKF11bBFwbgV Cry6Nga0hxDL1lZVRO6Ow2XI8e1pEbsL0CpBrIFu0ZyXWk9v+J25OLz6Cg2uXY195HUl po+i8iYSOhNSB34ugDRL0q1hZURtF+ivhqKUlhnDRI20R+co4T25dl9gny1pfPCNH6YG BB59VBLRudgTFRlAniUKM+GIKr3O9QlFogv4BeTEaSxFdcySrKPGf15YEi8i7OyOCywa IEi3mCVOCRnn4SGBwv14xYgtmI3S6tERsaii5H9aQ9F+wOFtzJ9V/e48/x6LeQspcAL3 jNgA== X-Gm-Message-State: ANoB5pkm81/V6xwjd0iRKobegxmYd4jr7iGLwjLyHvquNiyzhx+8QYLy izgEW8pDYqOcCar9h9/3pO5VAg== X-Received: by 2002:a05:6a20:3d19:b0:a3:49d2:9504 with SMTP id y25-20020a056a203d1900b000a349d29504mr318777pzi.3.1670979549423; Tue, 13 Dec 2022 16:59:09 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id n12-20020a170903110c00b0018c990ce7fesm466293plh.239.2022.12.13.16.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 16:59:08 -0800 (PST) Date: Wed, 14 Dec 2022 00:59:04 +0000 From: Sean Christopherson To: Ben Gardon Cc: David Matlack , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Peter Xu , Vipin Sharma Subject: Re: [PATCH 2/7] KVM: x86/MMU: Move rmap_iterator to rmap.h Message-ID: References: <20221206173601.549281-1-bgardon@google.com> <20221206173601.549281-3-bgardon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Tue, Dec 13, 2022, Ben Gardon wrote: > On Fri, Dec 9, 2022 at 3:04 PM David Matlack wrote: > > > > > +/* > > > + * 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 Heh, you definitely aren't the only one. > > 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() I would strongly prefer to keep "spte" in this one regardless of what other naming changes we do (see below). Maybe just for_each_spte()? IMO, "pte_list_entry" unnecessarily obfuscates that it's a list of SPTEs. > > 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. I generally like this idea too, but tying into my above comment, before jumping in I think we should figure out what end state we want, i.e. get the bikeshedding out of the way now to hopefully avoid dragging out a series while various things get nitpicked. E.g. if we if we just rename the structs and their macros, then we'll end up with things like static bool slot_rmap_write_protect(struct kvm *kvm, struct pte_list_head *rmap_head, const struct kvm_memory_slot *slot) { return rmap_write_protect(rmap_head, false); } which isn't terrible, but there's still opportunity for cleanup, e.g. rmap_write_protect() could easily be sptes_write_protect() or write_protect_sptes(). That will generate a naming conflict of sorts with pte_list_head if we don't also rename that to spte_list_head. And I think capturing that it's a list of SPTEs and not guest PTEs will be helpful in general. And if we rename pte_list_head, then we might as well commit 100% and use consisnent nomenclature across the board, e.g. end up with static bool sptes_clear_dirty(struct kvm *kvm, struct sptes_list_head *head, const struct kvm_memory_slot *slot) { u64 *sptep; struct spte_list_iterator iter; bool flush = false; for_each_spte(head, &iter, sptep) { if (spte_ad_need_write_protect(*sptep)) flush |= spte_wrprot_for_clear_dirty(sptep); else flush |= spte_clear_dirty(sptep); } return flush; } versus the current static bool __rmap_clear_dirty(struct kvm *kvm, struct kvm_rmap_head *rmap_head, const struct kvm_memory_slot *slot) { u64 *sptep; struct rmap_iterator iter; bool flush = false; for_each_rmap_spte(rmap_head, &iter, sptep) if (spte_ad_need_write_protect(*sptep)) flush |= spte_wrprot_for_clear_dirty(sptep); else flush |= spte_clear_dirty(sptep); return flush; }