Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3837030rdg; Wed, 18 Oct 2023 07:28:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKtqL0IBOoDcQcSt2kdUANPQDeK5ItEE0eqnReRdXizsbNpbAJrc44bHBCyXDmZS6r6tEy X-Received: by 2002:a05:6a00:1827:b0:6be:2e07:5c5c with SMTP id y39-20020a056a00182700b006be2e075c5cmr6027930pfa.20.1697639314266; Wed, 18 Oct 2023 07:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697639314; cv=none; d=google.com; s=arc-20160816; b=v7cOepdUvYYXmmmKvYNJG4kSnZWmUQKJLb585AWM4i81WxZwyBYxPefMtr92t/78Pr oDFjLiYUcIPJUbGr9lvSb3okr3lXzRULlDIK2vnro2FUv4dA5rRnvBahDlYi7S4zM0Oc 3jfqHcByxqf+6cPAvebFQxLLhgv6jXSrQDBHi9QoTnqU+x2F641bcdb4jl5pcFRhRrwc Yd4k0OCYOIyGSMK/aVVj6vW6vIn9YRIzn/1r5WM8CxdnrGhzhGuWulND0eC1WscCS1pf WARClcjFQo0FjGavL/DPYtI9QBoVqyNwsinXiX6NX/usU2djKuP/4guYteiobqZ9PBir GL2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=d0L3+cFU4QsO14uhjYGccfA39wf1vKEGho7WfRP4LWs=; fh=Vqb1eM/QUPU0LYxkKF2SqHPocclThJR+sRMLXz8y5Qs=; b=RHN1cBVjWusgIFZXPEHKEfn4JfDYbj+6BA8IGhlmZRvydUq1vD2hH3LsYV4jOWnPf5 pMSxRHrJm6KsPlrOG7KHO9d8V65htj/zkOxJ0jAID41YhG5V6Myq0KEGfKQ9iMWI8hGq oPPO5qI9yL3FzCACd1JMRChIia2fce/mWVUn6TbnXTrHHdJmG95jWZeeJpnW/PZ2euFs 6SKHZavxDoe3khMKdad3ttsf+SgWls00A/NPbOSCnx9TeIMO6jfBGoghgut91QHModYU /yR4UAr+Il+3QdTLfBnG6mNQ71ukBgNLLM2mrHe7RIvrbWTLnIf+amPoub8OtC/WvvBF Y8qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vJ3le7qQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id m22-20020a056a00081600b006be7d402d8csi3005905pfk.6.2023.10.18.07.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 07:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vJ3le7qQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 96FA48075161; Wed, 18 Oct 2023 07:28:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345411AbjJRO2T (ORCPT + 99 others); Wed, 18 Oct 2023 10:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344873AbjJRO2Q (ORCPT ); Wed, 18 Oct 2023 10:28:16 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A58211B for ; Wed, 18 Oct 2023 07:28:14 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7d1816bccso104968517b3.1 for ; Wed, 18 Oct 2023 07:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697639293; x=1698244093; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=d0L3+cFU4QsO14uhjYGccfA39wf1vKEGho7WfRP4LWs=; b=vJ3le7qQhojZ3jig9CCsnVTkHz6sJkGyjuuD2EqBIjdd5kuDbLuVXl8Hg+HONy/hGg owdLDe14zUs4iVL675sNDSLP/NsCHX3UXA5N86Vp1Tug17rocbzX8rogY1BKPMQ3ueOe kPgmEL/F5sBGEX+Iy+1vbClB3nVhipQOUhZ658CVfJ/YJKSEJYkqSMrnyiB0jwpk6Qjn 149yl95Zm0so3x9OT9/HZQIyPBCG/A6ZoJ+PiwPJgnuxhyZP9jKTstr8qfs42/V87yoU ifpl7FwdzuOqJkKn39IRmgETz8/5jMM2Fq9ioWwY2M1bnVvP7qHWUqkm9bgtxILfyVIl mdwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697639293; x=1698244093; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d0L3+cFU4QsO14uhjYGccfA39wf1vKEGho7WfRP4LWs=; b=Q5OJ3R7zwhUrfDIwmbmS/ZYIVGNQqDB4a+/4EMIXEpkc+7SHdgbJh/mViy2K5rh5ya IOf7Y6IzmtosNyyTiQ9qju+tWjfpcBH3rEZlT7Ur8R5cAxTSJlCSoaaB1OWXYJQ/cHn7 1hJxwzL9kT2/l/l5mxm5TIWXZcqFFsAqi4DDJ27R9Zv2e1Jzkp6A92RQ8z+/ebnsA9L6 R30p8Ho5UFCAN10IuA74BnN6DeKzikOwE20xmcscaaZfgQR6z5/qYii4nbPopEJalGrS i/mBRiZrRF4rgnyFxorQetm7nV0jfwOrtfEFvEU+TaEIvsKt3KcKPxpYP1C5m5nejJ1G d8Vw== X-Gm-Message-State: AOJu0YxqSUDs9PwNbONUHP4LbksVG8EmzTk9eMXOZGICpUkdqxPJLlT6 2Nvrlv41iAcTBoVHvvcmFI338K64kEo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:cb4d:0:b0:592:7a39:e4b4 with SMTP id n74-20020a0dcb4d000000b005927a39e4b4mr125401ywd.6.1697639293380; Wed, 18 Oct 2023 07:28:13 -0700 (PDT) Date: Wed, 18 Oct 2023 07:28:11 -0700 In-Reply-To: <9483638a-e34b-4e01-baa4-445a5984301c@gmail.com> Mime-Version: 1.0 References: <20231017093335.18216-1-likexu@tencent.com> <9483638a-e34b-4e01-baa4-445a5984301c@gmail.com> Message-ID: Subject: Re: [PATCH] KVM: x86: Clean up included but non-essential header declarations From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , Maxim Levitsky , Ingo Molnar , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 18 Oct 2023 07:28:31 -0700 (PDT) On Wed, Oct 18, 2023, Like Xu wrote: > On 18/10/2023 5:31 am, Sean Christopherson wrote: > > On Tue, Oct 17, 2023, Like Xu wrote: > > > From: Like Xu > > > Removing these declarations as part of KVM code refactoring can also (when > > > the compiler isn't so smart) reduce compile time, compile warnings, and the > > > > Really, warnings? On what W= level? W=1 builds just fine with KVM_WERROR=y. > > If any of the "supported" warn levels triggers a warn=>error, then we'll fix it. > > > > > size of compiled artefacts, and more importantly can help developers better > > > consider decoupling when adding/refactoring unmerged code, thus relieving > > > some of the burden on the code review process. > > > > Can you provide an example? KVM certainly has its share of potential circular > > dependency pitfalls, e.g. it's largely why we have the ugly and seemingly > > arbitrary split between x86.h and asm/kvm_host.h. But outside of legitimate > > collisions like that, I can't think of a single instance where superfluous existing > > includes caused problems. On the other hand, I distinctly recall multiple > > instances where a header didn't include what it used and broke the build when the > > buggy header was included in a new file. > > I've noticed that during patch iterations, developers add or forget to > remove header declarations from previous versions (just so the compiler > doesn't complain), and the status quo is that these header declarations > are rapidly ballooning. That's hyperbolic BS. Here's the diff of includes in x86.c from v2.6.38 to now. @@ -1,20 +1,29 @@ +#include "ioapic.h" +#include "kvm_emulate.h" +#include "mmu/page_track.h" +#include "cpuid.h" +#include "pmu.h" +#include "hyperv.h" +#include "lapic.h" +#include "xen.h" +#include "smm.h" New KVM functionality and/or the result of refactoring code to break up large files. -#include +#include +#include Likely a refactoring of other code. Basically a wash. -#include Removal of an unnecessary vendor-specific include. +#include +#include These two look dubious and probably can be removed. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include New functionality and/or refactoring. -#include -#include -#include Removal from refactoring. +#include New functionality. +#include This one looks dubious and probably can be removed. +#include +#include +#include +#include +#include +#include New functionality and/or refactoring. +#include The tlbflush.h include _might_ be stale now that x86.c doesn't use cr4_read_shadow(), but it's also entirely possible there's a real need for it as tlbflush.h defines a lot more than just TLB flush stuff. +#include +#include +#include +#include New functionality and/or refactoring. So over the last *13 years*, x86.c has gained 3 includes that are likely now stale, and one that might be stale. Yes, the total number of includes has roughly doubled, but so has the size of x86.c! arch/x86/include/asm/kvm_host.h is a similar story. The number of includes has roughly doubled, but the size of kvm_host.h has nearly *tripled*. And at a glance, every single new include is warranted. @@ -3,12 +3,26 @@ #include #include #include +#include +#include +#include #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include +#include +#include +#include +#include I would hardly desribe either of those as "rapidly ballooning". > > > 43 files changed, 184 deletions(-) > > > > NAK, I am not taking a wholesale purge of includes. I have no objection to > > removing truly unnecessary includes, e.g. there are definitely some includes that > > are no longer necessary due to code being moved around. But changes like the > > removal of all includes from tdp_mmu.h and smm.h are completely bogus. If anything, > > smm.h clearly needs more includes, because it is certainly not including everything > > it is using. > > Thanks, this patch being nak is to be expected. As you've noticed in the > smm.h story, sensible dependencies should appear in sensible header files, > and are assembled correctly to promote better understanding (the compiler > seems to be happy on weird dependency combinations and doesn't complain > until something goes wrong). > > In addition to "x86.h and asm/kvm_host.h", we could have gone further in > the direction of "Make headers standalone", couldn't we ? I honestly have no idea what point you're trying to make. If you're asking "could be split up x86.h and asm/kvm_host.h into smaller headers", then the answer is "yes". But that's not at all what your proposed patch does, and such cleanups are usually non-trivial and come with a cost, e.g. complicates backporting fixes to stable trees. I'm obviously not opposed to cleaning up and reducing unnecessary includes, e.g. see the recent work I put into arch/x86/include/asm/kvm_page_track.h. But crap like this just wastes my time and makes me grumpy.