Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3441938iog; Mon, 27 Jun 2022 16:31:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uTkbxTc+p4VSWt/5bK472ktbbSHvRabYGECgoiDdDy3wnQKjStKbTnSRNr93KCkpkWuoux X-Received: by 2002:a17:90a:b397:b0:1ec:c9b4:29cf with SMTP id e23-20020a17090ab39700b001ecc9b429cfmr18397562pjr.134.1656372662346; Mon, 27 Jun 2022 16:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656372662; cv=none; d=google.com; s=arc-20160816; b=ARNF1/kovQzji3LmAwxAIuTgT2tTv+bNxkFLO0PbxZv0dra0jZHeY51/RkutQtFnGt ezCf3tDfRod938p1+Cgi1u0pdsKVdv9jrd4zRJ77kKv9z87UYC9GOgEj8JlmF58SS6RF GqKR9DjppuEunVJKtG2KzG5oatnHGPn3PDWpsaF/LGKg4R3syE1M2U19q0mZZkYa7OOm ca3iR19qk9jOPIwzAnhfAE9K2O4y4wDa3J+OcwITegkbboNoBXzmXvXGOvL+Q0cTqhgN VbXcHHlyV/nsPA7qg47dwZg/veGgDnHz2U+1vQwcqvA59GhDgpR4Ap27xBiASasQSZNv JURQ== 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=7zL1TDH7VwdCezBjRhOqzaqCe5lZyZMVmoHZOpV7Cmc=; b=WQBewqC/qPQ/WrN9E+H3zksBhGWHHwpyvm2jBTh/6DtBiZ6YROMx2ESGlWr+cVHXds p58Wv7/G+UNALEjvoH4QRiv738rGPv0WoobKWCJNzFpcCHGGSX2sZDp4HGWy8TtxEdZF NhFPAziI5B4q39CK7tY3XBF5azqpcBULq/8LDYj+G7PDZqxhERESrU3Um8xhla84m1Ui AupaklIsXkhckjt9me0+NqEcn8gYt8v+OwvWMbhA+B6844KqcFO20geGxfn/dObZP5UF iz8F440Vo9fgrmhWoTDATRZAcw4hN2oXQYIsdkucX4JsTPbF7H8YWuq0CHkUR/oHNmWg UH1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rjsO5C+1; 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 w13-20020a63fb4d000000b0040d02d4b446si16338278pgj.682.2022.06.27.16.30.49; Mon, 27 Jun 2022 16:31: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=rjsO5C+1; 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 S240745AbiF0WuR (ORCPT + 99 others); Mon, 27 Jun 2022 18:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240124AbiF0WuP (ORCPT ); Mon, 27 Jun 2022 18:50:15 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EA66E8A for ; Mon, 27 Jun 2022 15:50:15 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id dw10-20020a17090b094a00b001ed00a16eb4so10837463pjb.2 for ; Mon, 27 Jun 2022 15:50:15 -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=7zL1TDH7VwdCezBjRhOqzaqCe5lZyZMVmoHZOpV7Cmc=; b=rjsO5C+1IaaqQBLfXoCoFrmOyck8dX2dTqxLBdeqWhMf6pZwohC2qEoU+sGdPQYPOU 6ckWujrZfUQA/i+KZo0h2vJoT542bIuoWPJ23sq1o36v95oMhFqVo9ByAi+NJJAV+CuG D0Fxs9AZzNrnOv/09svdFX6Qcvpmikum6Qs+O/rQUN6zwOpEKnnzzc4MZkjtvki5n+Ih R5v9j4QYvMShcbo25jEP8FyRi2BPlDRNT8tUduIcsvyq/CkuqwEhFCtAggA/HPHy/IqS dfarLqF+XEMplrRuMMuiIZrOQFCPgm0R45oR0iyheZoj17R21nCZwhkLjHZgK2Y0LO7l Ry+Q== 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=7zL1TDH7VwdCezBjRhOqzaqCe5lZyZMVmoHZOpV7Cmc=; b=DrGrJaFt7bHg38KrOSSIkS/Onfbyx9PWvD6iYJOHUOc7Z4v1wsGnP4Pk/Lk9lxfP6/ hJnIGoT2cTLfmJyzDb131N2H5dL3MZ8yBBAmkN91meOja3SXci3DaPjNVZTEO4ZlH6jQ SAx7Qrwyxwih+gLG9zBgGGlWY1T+wAzCr2ZUT66A21crzb/JfEBe9nem9sWw4xwaOHXZ pUKmp0LatVHzs7L1jI8DKWoq9zebv+QWFALXuWS07hko4UZWAQdlOSVmZA2vPMc8Zp19 fbvdTSvJGNjWHcclpIIGVov3QZZ27ORqf1uRtydy5d7eocQLqPX+qriPivomFXi2i0oQ /aWA== X-Gm-Message-State: AJIora/Eb59LGT1IwQKu+eQLKQPI5NDSk/LactnlalPoGdWucOocEY/u U74I22rC3pxnGxjVq+wXabdcAA== X-Received: by 2002:a17:902:cec9:b0:16a:644a:6019 with SMTP id d9-20020a170902cec900b0016a644a6019mr461279plg.82.1656370214406; Mon, 27 Jun 2022 15:50:14 -0700 (PDT) Received: from google.com (223.103.125.34.bc.googleusercontent.com. [34.125.103.223]) by smtp.gmail.com with ESMTPSA id u4-20020a170902714400b0015e8d4eb28fsm7780728plm.217.2022.06.27.15.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 15:50:13 -0700 (PDT) Date: Mon, 27 Jun 2022 22:50:09 +0000 From: David Matlack To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu Subject: Re: [PATCH 2/4] KVM: x86/mmu: Defer "full" MMU setup until after vendor hardware_setup() Message-ID: References: <20220624232735.3090056-1-seanjc@google.com> <20220624232735.3090056-3-seanjc@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, 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 On Mon, Jun 27, 2022 at 03:40:49PM +0000, Sean Christopherson wrote: > On Sat, Jun 25, 2022, David Matlack wrote: > > On Fri, Jun 24, 2022 at 11:27:33PM +0000, Sean Christopherson wrote: > > > Alternatively, the setup could be done in kvm_configure_mmu(), but that > > > would require vendor code to call e.g. kvm_unconfigure_mmu() in teardown > > > and error paths, i.e. doesn't actually save code and is arguably uglier. > > [...] > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > > index 17ac30b9e22c..ceb81e04aea3 100644 > > > --- a/arch/x86/kvm/mmu/mmu.c > > > +++ b/arch/x86/kvm/mmu/mmu.c > > > @@ -6673,10 +6673,8 @@ void kvm_mmu_x86_module_init(void) > > > * loaded as many of the masks/values may be modified by VMX or SVM, i.e. need > > > * to be reset when a potentially different vendor module is loaded. > > > */ > > > -int kvm_mmu_vendor_module_init(void) > > > +void kvm_mmu_vendor_module_init(void) > > > { > > > - int ret = -ENOMEM; > > > - > > > /* > > > * MMU roles use union aliasing which is, generally speaking, an > > > * undefined behavior. However, we supposedly know how compilers behave > > > @@ -6687,7 +6685,13 @@ int kvm_mmu_vendor_module_init(void) > > > BUILD_BUG_ON(sizeof(union kvm_mmu_extended_role) != sizeof(u32)); > > > BUILD_BUG_ON(sizeof(union kvm_cpu_role) != sizeof(u64)); > > > > > > + /* Reset the PTE masks before the vendor module's hardware setup. */ > > > kvm_mmu_reset_all_pte_masks(); > > > +} > > > + > > > +int kvm_mmu_hardware_setup(void) > > > +{ > > > > Instead of putting this code in a new function and calling it after > > hardware_setup(), we could put it in kvm_configure_mmu().a > > Ya, I noted that as an alternative in the changelog but obviously opted to not > do the allocation in kvm_configure_mmu(). Doh! My mistake. The idea to use kvm_configure_mmu() came to me while reviewing patch 3 and I totally forgot about that blurb in the commit message when I came back here to leave the suggestion. > I view kvm_configure_mmu() as a necessary > evil. Ideally vendor code wouldn't call into the MMU during initialization, and > common x86 would fully dictate the order of calls so that MMU setup. We could force > that, but it'd require something gross like filling a struct passed into > ops->hardware_setup(), and probably would be less robust (more likely to omit a > "required" field). > > In other words, I like the explicit kvm_mmu_hardware_setup() call from common x86, > e.g. to show that vendor code needs to do setup before the MMU, and so that MMU > setup isn't buried in a somewhat arbitrary location in vendor hardware setup. Agreed, but if we're not going to get rid of kvm_configure_mmu(), we're stuck with vendor-specific code calling into the MMU code during hardware setup either way. > > I'm not dead set against handling this in kvm_configure_mmu() (though I'd probably > vote to rename it to kvm_mmu_hardware_setup()) if anyone has a super strong opinion. Your call. I'll put in a vote for using kvm_configure_mmu() and renaming to kvm_mmu_hardware_setup(). > > > This will result in a larger patch diff, but has it eliminates a subtle > > and non-trivial-to-verify dependency ordering between > > Verification is "trivial" in that this WARN will fire if the order is swapped: > > if (WARN_ON_ONCE(!nr_sptes_per_pte_list)) > return -EIO; Ah I missed that, that's good. Although I was thinking more from a code readability standpoint. > > > kvm_configure_mmu() and kvm_mmu_hardware_setup() and it will co-locate > > the initialization of nr_sptes_per_pte_list and the code that uses it to > > create pte_list_desc_cache in a single function.