From patchwork Mon Apr 4 23:41:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12800931 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 4688CC433F5 for ; Mon, 4 Apr 2022 23:42:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3B7F6B0073; Mon, 4 Apr 2022 19:42:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE87F6B0074; Mon, 4 Apr 2022 19:42:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B0E56B0075; Mon, 4 Apr 2022 19:42:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id 8E1416B0073 for ; Mon, 4 Apr 2022 19:42:14 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4F053824C45B for ; Mon, 4 Apr 2022 23:42:04 +0000 (UTC) X-FDA: 79320822168.19.B55B5AF Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf19.hostedemail.com (Postfix) with ESMTP id C72261A0007 for ; Mon, 4 Apr 2022 23:42:03 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id p4-20020a631e44000000b00399598a48c5so380389pgm.1 for ; Mon, 04 Apr 2022 16:42:03 -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=CaD5i7uWV8aXENdqT5/Q1IvKQzX6yvHELCk0D3aIz+A=; b=jZKt3Q4Wq9KSvffmXMldabyC+4MvZErOoCul5wp26X3fVT7avqVOywE6dRTV5JJo11 Lm4ZyJkQKcU6bzStWVXFKpng/HMzb0ZtmfE6Nd/d6RU6cNkQ84Wt3BpalH6kyvulvAYr zShnZTa4A2gBE2r/kwAWzJBueRGlu4o86+XfaQ68iLhbvA/N2T1r2CnXE7LYiv3IBC9b 3CL7MFjQ40fQAwER6JcDbx/XuT0DGvKUPlXuLZNEWli6lVkHQPjWTLNfDUk4OjPqLTYU 2oyOjUsiPjPTpHWPApftGdp/0I5gf1OiMGXydG4zv0rrxfDYablQdArb0FX9DyXUBsbK 23jQ== 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=CaD5i7uWV8aXENdqT5/Q1IvKQzX6yvHELCk0D3aIz+A=; b=0sr6lcdabhx9qsCoykzmCEY9dPF6DVEVbwqcUN0LpS8aiDJDEjjUtZRketsEYf+BPc SisL/hKdzjjXOoxIhmIvC0iIgDuvTaRfr22re1g1jQTFGrNi3+tJ4ZxbDdqYlx8+Vfa1 tiaz7ysRM7PRIOa65VgBfiPS70TCWUcNuyqbT/tu3h0VMGTzoXv0giYTYAuRnME4ZXTk RoC1wZ77ypEuKWnGCPD20MLPEzXTVSTJ0tMzaOiug3KPFYo3dduR/VaTwiuP9RS+2TkF dS/6v6ayFYeydS5TsqvJ7wF9bvC6+QpF591I9aydUStykSZ5b9osZrTvlbRU9iytj1y0 wwdA== X-Gm-Message-State: AOAM531i/TehnTq/NxgHcc+QkKxLnAkY/JFkWUyrD2nQcIBPOqFs3s3F k3/ATvRn/KDNmPXc/+ZNQG3H4OdnrG0X+PhQ X-Google-Smtp-Source: ABdhPJznx5CPgiI0z19F0ZkzF+3RdCQG8+R2KZlvfK7h7Xj/Uh7x/vARspwj7iObyoaIy9/NWmWCwv74G/ufbWL6 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:db48:b0:1ca:ab67:d75 with SMTP id u8-20020a17090adb4800b001caab670d75mr73933pjx.1.1649115722406; Mon, 04 Apr 2022 16:42:02 -0700 (PDT) Date: Mon, 4 Apr 2022 23:41:50 +0000 In-Reply-To: <20220404234154.1251388-1-yosryahmed@google.com> Message-Id: <20220404234154.1251388-2-yosryahmed@google.com> Mime-Version: 1.0 References: <20220404234154.1251388-1-yosryahmed@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH v2 1/5] KVM: mm: add a helper to account page table pages used by KVM. From: Yosry Ahmed To: Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: mizhang@google.com, David Matlack , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt , Andrew Morton , Yosry Ahmed X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C72261A0007 X-Stat-Signature: 54ksqsidfgkazh874koh156jccqdjcbs Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=jZKt3Q4W; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3SoJLYgoKCJUNDHGNz6B325DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3SoJLYgoKCJUNDHGNz6B325DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--yosryahmed.bounces.google.com X-Rspam-User: X-HE-Tag: 1649115723-700239 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..ca46b68e7086 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_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