From patchwork Tue Apr 26 05:39:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12826474 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26F2CC433F5 for ; Tue, 26 Apr 2022 05:39:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC0E76B0078; Tue, 26 Apr 2022 01:39:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A24376B007B; Tue, 26 Apr 2022 01:39:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8513F6B007E; Tue, 26 Apr 2022 01:39:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 726396B0078 for ; Tue, 26 Apr 2022 01:39:22 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3F0D725066 for ; Tue, 26 Apr 2022 05:39:22 +0000 (UTC) X-FDA: 79397927364.20.ED47C51 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf19.hostedemail.com (Postfix) with ESMTP id 1E8211A0041 for ; Tue, 26 Apr 2022 05:39:18 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id k2-20020a170902ba8200b0015613b12004so10726235pls.22 for ; Mon, 25 Apr 2022 22:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=75ck2E1viXT4HNKGmhZGUqApOq35yGNlgD3kbgrzKrw=; b=j/6W1Jv8f36ZodhL68vNcySdndUH2oV1c5OzKpRXYolTLJgwBi7OaIg/S/yKMnJp+b lqqaZUm1JBr3oQixRNwaNTgB81/saUAppnPAjz68yxAbmgh4igyoOQ92n9+HzD+TEgqv ajW2TFBTyLuEXXVz0pJuHgyUGpGRZnhkjtQoBS+4am6LkE8kl60VYw6Q/6q6/jo9xQNu GX4i53uLVaKJIRtdwjxSSMxM+nKgqH6qhEODIoJjq5XuOby3Ip1qDLu+YxucaAIrUMzY Psb6biLd1G6xVSJaPjnJffEREeUS4oL482CYqW+UsriFD7QsTwFn/nDOVqJKFywwwAfj 8XNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=75ck2E1viXT4HNKGmhZGUqApOq35yGNlgD3kbgrzKrw=; b=AmSJIVtxOvKY3Ha1+UCXuWYcG16QvQKMPht+LItoAVka9yX8MBa7gtfCgBmfE9pP/Z 8XSyhfTteKeC5rlcpzTW4xD7ccpaBDsDret1yW4I8chm6/MF3Yy4z+8IDg3bo88PIdZy luRQ6D0Jdz4IVGY2uXQRlpQwbGO+I7fzVX0cRkAMliyUcZqkT6co9S3TMqlrDvVesx7o c+4VqmtFosfaforCqCL74ZdGLNpVZDRuaZ0NTC6INKH/8Rg+NbO02X8XgGcTAjEZ0xd1 ZvnOF6jLcXtOXm7VhFwZvnHqqR+S3bF/Q+ZDpwhIl+un7chv791b6qg9758hcF3iCIyM vYGg== X-Gm-Message-State: AOAM532O2IrXkd5WOl0cOv3sX2yU8cXGRhZvbTIQ5U1DjjD+4zbBZ221 ujI4P5JZweF2dA4k9h5z0mz+keHr7gqlW7xP X-Google-Smtp-Source: ABdhPJz+02KDDV9V68suFOiQPkifF2E9mLN9n/bWhK+6QOZ7ZJ3fdHfj/Lkck5hrYAftknNAaw0TdY1+WqYFvIkS X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:9881:b0:158:f258:c3c3 with SMTP id s1-20020a170902988100b00158f258c3c3mr21548367plp.7.1650951560612; Mon, 25 Apr 2022 22:39:20 -0700 (PDT) Date: Tue, 26 Apr 2022 05:39:00 +0000 In-Reply-To: <20220426053904.3684293-1-yosryahmed@google.com> Message-Id: <20220426053904.3684293-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220426053904.3684293-1-yosryahmed@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 2/6] KVM: mmu: add a helper to account page table pages used by KVM. From: Yosry Ahmed To: Sean Christopherson , Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , James Morse , Catalin Marinas , Shameer Kolothum , Marc Zyngier , Alexandru Elisei , Suzuki K Poulose Cc: linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Yosry Ahmed X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1E8211A0041 X-Stat-Signature: 8cd1k9oos1tgic4ezgnc7miu3d8srg9z X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="j/6W1Jv8"; spf=pass (imf19.hostedemail.com: domain of 3iIVnYgoKCEsB154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3iIVnYgoKCEsB154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1650951558-730032 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a helper to account pages used by KVM for page tables as pagetable stats. This function will be used by subsequent patches in different archs. Signed-off-by: Yosry Ahmed --- include/linux/kvm_host.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 252ee4a61b58..54cc4634053c 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2221,6 +2221,15 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) } #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ +/* + * If nr > 1, we assume virt is the address of the first page of a block of + * pages that were allocated together (i.e accounted together). + */ +static inline void kvm_account_pgtable_pages(void *virt, int nr) +{ + mod_lruvec_page_state(virt_to_page(virt), NR_SECONDARY_PAGETABLE, nr); +} + /* * This defines how many reserved entries we want to keep before we * kick the vcpu to the userspace to avoid dirty ring full. This