Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp799765iog; Fri, 24 Jun 2022 14:32:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLaZJ+Psi4FYbgr0muw0+uUsZDmR85voCiaEpRt+hD4ph7GFegSTxVzfHR4msGl7odaDvG X-Received: by 2002:a63:3713:0:b0:40c:b98c:5e4b with SMTP id e19-20020a633713000000b0040cb98c5e4bmr781426pga.8.1656106368105; Fri, 24 Jun 2022 14:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656106368; cv=none; d=google.com; s=arc-20160816; b=GeSxsI1LRaNENM4NqZvFrjNp195JWaKb3cpfSaVZ+mHrVCImQS1LWNmASIc5RGv/WY 9P0IwUdTN3tLbWsoxdAAap62lNGIMMVCr74LZnfcMsUvFpCRxSMB4Ve+uWxF5Xw9N4Ux Ek3Es9jGQW1XnMpwR4mlAZ99f+TT/dsN+XZu1PfxeAJCTaN5ucF31YfWjl301vvswhTo wUP0oOWBmYTJd+uLdjwNFdizg1+rXf+29CDZ6w7Fg6kQZKWiGuIh5b/xMSI3NX7NYlsI Du/vFlPybanpXOPHdeL11i4zZJZZnyayaSGMNGZn095cZDt0o+MeupmV5gJ1JtlijsMF Qv1g== 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:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=aVL8GM5UlCYwkYpjstIne4ze+uj4PFzbjfg18IJWQlI=; b=0AdBTdHNuYxvy26uXZ6GEY/OyToODaR4k51bqTpKKqFpnoT66P6YjOzJMPG5ZFMjvU wvwVYypT6pEazNYOf2/k2SJCa12Rr5rJttxi5HbgWty0cUHNjjFdYHvkvPo4gGqVxOzZ YlQ8H+vZR6VnEuKplJwzuAJmyq9l80BbjuPfPzXdenPmLBmgn7gNF6c2ZwWs3xbYC0fe vuHeYETCJbX029L3NtauO+fu7szgM9+thBTIZs4iyld3xJY53PZ20ua5HQjZbNasYeHe yKzkmmEoeByIepVL1QdY+8J6ROSyvDXIimLtBXvTh5s3GKUjJ2KIJq6/vMZBxW6ZBQ16 wH8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MNWyh9kW; 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 a15-20020a170902710f00b00168ef343fd7si4131364pll.274.2022.06.24.14.32.36; Fri, 24 Jun 2022 14:32:48 -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=MNWyh9kW; 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 S231537AbiFXVbA (ORCPT + 99 others); Fri, 24 Jun 2022 17:31:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231459AbiFXVaz (ORCPT ); Fri, 24 Jun 2022 17:30:55 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF3157FD39 for ; Fri, 24 Jun 2022 14:30:54 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 15-20020a63020f000000b003fca9ebc5cbso1546806pgc.22 for ; Fri, 24 Jun 2022 14:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=aVL8GM5UlCYwkYpjstIne4ze+uj4PFzbjfg18IJWQlI=; b=MNWyh9kWGEe9f3b2ZEyrpQTABz+TEx0AgE7yK61YYChhZL7DpPrgNJw4jZlShrPH/T 6yxzaoxZaBvuHcdqqjG151wMMqI9GWvT+vTYyU8+pqY1vAmC0Vby0UZt58enP6mxuhOz hwgvzRX3qsiRUe9uezVcYWRZwbNL4DurMF99wwND4yZ9krO96vGb41YJMkO76M3cDHEM metf14q/h4Gfwimqb6G6rfwRVgJxjeupcvFyno3QqtZq/vLSk66tFvf5CNz38R+j3yxN bFAYk1w781QG4K555lmuC80JPNPT6FcRFRaYpj2+WrdQ5XXODK5MFTqSBdkf10lJvPo+ bHcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=aVL8GM5UlCYwkYpjstIne4ze+uj4PFzbjfg18IJWQlI=; b=kPFQW2WJCVFhgf1pyruhcVXQYpWqacsthxk5cgEX6PafU+J4Db+nsKZqOvNV27/rWm dUaKtEfW/+Ne0pFuBwyYJZ03CFd/JE+ICaiW1VmgpacZ4S3a18ZgZMk8g0fIATDVNlmW y2Rmmx20srFtAAIlyKt3BjruUNTOUIGrazMg8vRK+WEkbdFRn2LdLpHL8NGSimh1XTh6 BcGynVJeQJJ0CsFJIDrrhFIB+SbHDRnBw4wSi5DhMzB/6f9yf8I85r62q3izCYEl3Eq7 ezTJc/7liVUzrZMkyj5Ic1yUlWdMuBj3nBnkRsPKGUsto7LUzh+UBzuRgfR/2jHcFnD6 JsTA== X-Gm-Message-State: AJIora/eJPJVIUa3JJJAewDOY37ZEBqK1xEn+Hmy36c0xZw9jTbgQNjD 5VWJehEHdF2oiqTi5juGBCIJbqNrYXE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:e809:b0:16a:22dc:d23a with SMTP id u9-20020a170902e80900b0016a22dcd23amr1098100plg.119.1656106254367; Fri, 24 Jun 2022 14:30:54 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 24 Jun 2022 21:30:37 +0000 In-Reply-To: <20220624213039.2872507-1-seanjc@google.com> Message-Id: <20220624213039.2872507-3-seanjc@google.com> Mime-Version: 1.0 References: <20220624213039.2872507-1-seanjc@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v2 2/4] KVM: x86/mmu: Expand quadrant comment for PG_LEVEL_4K shadow pages From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 Tweak the comment above the computation of the quadrant for PG_LEVEL_4K shadow pages to explicitly call out how and why KVM uses role.quadrant to consume gPTE bits. Opportunistically wrap an unnecessarily long line. No functional change intended. Link: https://lore.kernel.org/all/YqvWvBv27fYzOFdE@google.com Cc: David Matlack Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index b04e9ce2469a..83ca71361acd 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2166,7 +2166,8 @@ static struct kvm_mmu_page *kvm_mmu_get_shadow_page(struct kvm_vcpu *vcpu, return __kvm_mmu_get_shadow_page(vcpu->kvm, vcpu, &caches, gfn, role); } -static union kvm_mmu_page_role kvm_mmu_child_role(u64 *sptep, bool direct, unsigned int access) +static union kvm_mmu_page_role kvm_mmu_child_role(u64 *sptep, bool direct, + unsigned int access) { struct kvm_mmu_page *parent_sp = sptep_to_sp(sptep); union kvm_mmu_page_role role; @@ -2193,9 +2194,15 @@ static union kvm_mmu_page_role kvm_mmu_child_role(u64 *sptep, bool direct, unsig * uses 2 PAE page tables, each mapping a 2MiB region. For these, * @role.quadrant encodes which half of the region they map. * - * Note, the 4 PAE page directories are pre-allocated and the quadrant - * assigned in mmu_alloc_root(). So only page tables need to be handled - * here. + * Concretely, a 4-byte PDE consumes bits 31:22, while an 8-byte PDE + * consumes bits 29:21. To consume bits 31:30, KVM's uses 4 shadow + * PDPTEs; those 4 PAE page directories are pre-allocated and their + * quadrant is assigned in mmu_alloc_root(). A 4-byte PTE consumes + * bits 21:12, while an 8-byte PTE consumes bits 20:12. To consume + * bit 21 in the PTE (the child here), KVM propagates that bit to the + * quadrant, i.e. sets quadrant to '0' or '1'. The parent 8-byte PDE + * covers bit 21 (see above), thus the quadrant is calculated from the + * _least_ significant bit of the PDE index. */ if (role.has_4_byte_gpte) { WARN_ON_ONCE(role.level != PG_LEVEL_4K); -- 2.37.0.rc0.161.g10f37bed90-goog