From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA225C43334 for ; Fri, 24 Jun 2022 21:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231538AbiFXVbA (ORCPT ); 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-Google-Smtp-Source: AGRyM1sMeT4iPH4Z55LvwsYjBdCB6PioE05w9SsEBuG3UpD3DTmlohwidwuec0jKYnkeFNx6hlYHlWLKjBQ= 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" 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