From patchwork Fri Apr 30 11:52:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shahin, Md Shahadat Hossain" X-Patchwork-Id: 12233155 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.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64, SPF_HELO_NONE,SPF_PASS 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 4F4A5C433ED for ; Fri, 30 Apr 2021 11:52:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F8B2613E8 for ; Fri, 30 Apr 2021 11:52:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbhD3Lxc (ORCPT ); Fri, 30 Apr 2021 07:53:32 -0400 Received: from smtp-fw-9103.amazon.com ([207.171.188.200]:58215 "EHLO smtp-fw-9103.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbhD3Lxb (ORCPT ); Fri, 30 Apr 2021 07:53:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1619783564; x=1651319564; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Dtx/M6xk+T/uqMTyekx1GTapviS8Xmbt6xkcI97Wv+c=; b=rnShq6/TRzXYXseTCKcSqbIzVCNOrTKuNduQnXbXy4Ql+DgVLKloNM2p pytkcoQy/DJtBrHQhqFq/PRRCDQVJWU4cl4fB630CXyBdmYKvzgh43GLF m76vGtOw7wRtDs2vflUptnIUoMy4bl2yewrbZKcI+UuwtllJMo9X9JW0R g=; X-IronPort-AV: E=Sophos;i="5.82,262,1613433600"; d="scan'208";a="930352322" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-1a-af6a10df.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 30 Apr 2021 11:52:34 +0000 Received: from EX13D49EUA004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-af6a10df.us-east-1.amazon.com (Postfix) with ESMTPS id 107F0A1FB1; Fri, 30 Apr 2021 11:52:32 +0000 (UTC) Received: from EX13D09EUA004.ant.amazon.com (10.43.165.157) by EX13D49EUA004.ant.amazon.com (10.43.165.250) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 30 Apr 2021 11:52:31 +0000 Received: from EX13D09EUA004.ant.amazon.com ([10.43.165.157]) by EX13D09EUA004.ant.amazon.com ([10.43.165.157]) with mapi id 15.00.1497.015; Fri, 30 Apr 2021 11:52:31 +0000 From: "Shahin, Md Shahadat Hossain" To: "kvm@vger.kernel.org" CC: "Szczepanek, Bartosz" , "seanjc@google.com" , "bgardon@google.com" , "pbonzini@redhat.com" Subject: [PATCH v2] kvm/x86: Fix 'lpages' kvm stat for TDM MMU Thread-Topic: [PATCH v2] kvm/x86: Fix 'lpages' kvm stat for TDM MMU Thread-Index: AQHXPbWN7k8o6AHTZ0CvACgVIr8ztw== Date: Fri, 30 Apr 2021 11:52:31 +0000 Message-ID: <1619783551459.35424@amazon.de> Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.43.162.28] MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Large pages not being created properly may result in increased memory access time. The 'lpages' kvm stat used to keep track of the current number of large pages in the system, but with TDP MMU enabled the stat is not showing the correct number. This patch extends the lpages counter to cover the TDP case. Signed-off-by: Md Shahadat Hossain Shahin Cc: Bartosz Szczepanek Reviewed-by: Ben Gardon --- arch/x86/kvm/mmu/tdp_mmu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index bc1283ed4db6..f89a140b8dea 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -240,6 +240,13 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, if (old_spte == new_spte) return; + if (is_large_pte(old_spte) != is_large_pte(new_spte)) { + if (is_large_pte(old_spte)) + atomic64_sub(1, (atomic64_t*)&kvm->stat.lpages); + else + atomic64_add(1, (atomic64_t*)&kvm->stat.lpages); + } + /* * The only times a SPTE should be changed from a non-present to * non-present state is when an MMIO entry is installed/modified/