From patchwork Wed Sep 22 04:58:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Stevens X-Patchwork-Id: 12509463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E765C433F5 for ; Wed, 22 Sep 2021 04:59:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76CAC611C6 for ; Wed, 22 Sep 2021 04:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231704AbhIVFAg (ORCPT ); Wed, 22 Sep 2021 01:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbhIVFAf (ORCPT ); Wed, 22 Sep 2021 01:00:35 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7865C061574 for ; Tue, 21 Sep 2021 21:59:05 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so3640963pjb.2 for ; Tue, 21 Sep 2021 21:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=r8pnqtJ/F9dtMSy/EL+bGh8IDZAtWEdBtDhk0Wjztm0=; b=Du+uSsA4PBLae+9JAQuRNrZm3uPgW9fksM5M1X2Ex1FCd+Egj4prlRHnEo1B52xkAK 3uifhC4i7N5eJwHNl5jdbyPmjxZsqlppuAJxkMPpazWYiFeqr/G7EO0v9SSrQ7zNYex8 o/CSYx9lBA3kZAuEGJuZM0HoWR/gbBCa+a0IY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=r8pnqtJ/F9dtMSy/EL+bGh8IDZAtWEdBtDhk0Wjztm0=; b=2WfkUDKFnqyg12kbjjL9Ye4FAQdRuy9sK6V/3wKIwT5K6zXdfOpMKftcSx+kaBbOfO nPSFW6ngiOdI7wKKSdz72GcR++orjY13QSanPemyBhlckyp15n3jsFGrDd09MSCjUbaQ QMXd720tBxmdcFKwmqBSjEqgTnyQe89VvAkGHP/1ZtkzQMWLeRNBu/nEVxUl683P5xDP S3jo+D+DfNbvhXwHWGRWrwIGwpPW1UJ3UJAHFKUctrVSnm1EDAYKHDkQPeN0O0j/fe6n 5j6SLkveYWwkSRzku0lrMd6PINbDT4BGMQjn/jK7YawYVGDYEId6aJ6AFiHexHuOTjSH /hFQ== X-Gm-Message-State: AOAM532JaBX5pXHFaiBKjylVlTyGpPOanyiWjKCMCe9lL3eIX4Z63Itq jOF1UnePvnHPPAYOX1dblPsg5KaGJ/Qokw== X-Google-Smtp-Source: ABdhPJxYIlEiNMPJdImKxEKui7PG5ale479F/pI/UJmFAIAARNbsBTndPIXykFqKCp8H1Y6WOUf0+w== X-Received: by 2002:a17:90a:7782:: with SMTP id v2mr9114675pjk.9.1632286745479; Tue, 21 Sep 2021 21:59:05 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:9a20:20f1:af4d:610c]) by smtp.gmail.com with UTF8SMTPSA id g14sm700500pjk.20.2021.09.21.21.59.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Sep 2021 21:59:05 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, David Stevens Subject: [PATCH v2 0/2] KVM: x86: skip gfn_track allocation when possible Date: Wed, 22 Sep 2021 13:58:57 +0900 Message-Id: <20210922045859.2011227-1-stevensd@google.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: David Stevens Skip allocating gfn_track arrays when tracking of guest write access to pages is not required. For VMs where the allocation can be avoided, this saves 2 bytes per 4KB of guest memory. Write tracking is used to manage shadow page tables in three cases - when tdp is not supported, when nested virtualization is used, and for GVT-g. If tdp_enable is set and the kernel is compiled without GVT-g, then the gfn_track arrays can be allocated lazily when the shadow MMU is initialized. v1 -> v2: - lazily allocate gfn_track when shadow MMU is initialized, instead of looking at cpuid David Stevens (2): KVM: x86: add config for non-kvm users of page tracking KVM: x86: only allocate gfn_track when necessary arch/x86/include/asm/kvm_host.h | 8 ++++ arch/x86/include/asm/kvm_page_track.h | 5 +- arch/x86/kvm/Kconfig | 3 ++ arch/x86/kvm/mmu/mmu.c | 7 +++ arch/x86/kvm/mmu/page_track.c | 69 ++++++++++++++++++++++++++- arch/x86/kvm/x86.c | 2 +- drivers/gpu/drm/i915/Kconfig | 1 + 7 files changed, 91 insertions(+), 4 deletions(-)