From patchwork Mon Jun 6 22:20:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12871131 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90453C43334 for ; Mon, 6 Jun 2022 22:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1LkWT1xiwNrIibExG3oq0zRNwB4xMDWUz7VKHJ4CSh0=; b=aGnT2++NjztUGq2aCZ4yOhNc1z V578lqi6sVHVW9RpLSMn2yaJ9dF08qZO8IeHVPCaCDY996eYAWXRuOU08+WIKzfX1Uq+DadYLWX+L 0Mav4kpfaTNhNAFuX4R5JX3Wm24J2y7m0vC+UsAN5Xewyrpwbix9AA3Jwuhwlb13xWwau2BidtKyk 8bsJV4FZCheeBBtk4UEaEGpYAlMHTbUVjLEviMhKYJqv0ai9yohhBFK8LFrVvyFOIbiBne3b8oJUa u89T1gS7dfM3fIVNzt53BvgetZz0mPAUcHqkVhwBCQGLr6g8FZ09o7Ud4Zj2/MP61VLvI0Pt00iRK TiWULM6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyL6I-002yu3-RD; Mon, 06 Jun 2022 22:21:30 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyL5z-002yn2-Uc for linux-arm-kernel@lists.infradead.org; Mon, 06 Jun 2022 22:21:13 +0000 Received: by mail-pf1-x44a.google.com with SMTP id 128-20020a621786000000b0051b8426c375so8390573pfx.15 for ; Mon, 06 Jun 2022 15:21:11 -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=ZKvJKacIZPpFbnd53bS1EL2rZ1vkQiMgyn6fonmD758=; b=Zr9Q8V4nfUck7UMPiqqnChLoKCpFiU004y5VHpcxyH5mWHlhwIzYxUURvWJBq4dUhI PEflFN4+yWiPedkxFNguL6KLVrX7tdllycYtTzVDtLTM5fSldbL5YGtSdvQhicV/VqNC W9LyO1FZ89oe3glk7cppYh1QOUL7GWHvzV40mkYxY6Ot8nmOdZ1BmyJNi7r9lWo5/W5N bMn6eQ26xiiSsDdv1sGuFTHXiFY4OC6CrIrPysYNh3IdjDsmHyydvK25MNicujeQ5HDt CqB1bPPFGYC0qLNs/TbMrK22nRwsnULJfjNvc7HFOqj+269yjI72P9tp9IKYvoEk/5A9 jikw== 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=ZKvJKacIZPpFbnd53bS1EL2rZ1vkQiMgyn6fonmD758=; b=kBB8aTY9AU0uLbUAZKqTsLX0RyBp5lqB3YAuGMKuPknmtdvqzKUOlGlEh/GZaLWWBX xKifNnojy3lK5DcStlp1MCO+RBX6jpcB/NXzVrhzBstpdSfUWYY3abwnQA5q9Fa9IzoU LDW7aGjmOMtE4JVETSAUF2AQvfzT9qfx3QvqFt3/nApp0r5yJqx6tYzDdpefFTjbJOV4 5PvoND7L0D8WfZ4D4LWOPfEOc57EUZD8VgurJtMNdW8CVu8Jds7idsOcVCWGFSuK2z4W l+IuZ9JDvBGAMcc7OyuLhwEl6fsnQUH0w1uZBA4IXmZzNr1m4li9DRnMNBSynkQtxgQH BGBA== X-Gm-Message-State: AOAM5317NnuGptqerp4idt9eP9P1QMMx/oJ/coSVzoisk3zhxlxOBvtg laHdKPsUH3rEtIQf8ruuRmMhI/y1Z1GWM1qz X-Google-Smtp-Source: ABdhPJydFOJZXIlcEjQkgSriWABs0ECYT0csN/ZfxbgjEAFbaZOYZU1KL+PBDU3VaJNjamZ58gakzobgmymrjjXn X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90b:1650:b0:1e4:cff1:5a86 with SMTP id il16-20020a17090b165000b001e4cff15a86mr28806822pjb.30.1654554070851; Mon, 06 Jun 2022 15:21:10 -0700 (PDT) Date: Mon, 6 Jun 2022 22:20:56 +0000 In-Reply-To: <20220606222058.86688-1-yosryahmed@google.com> Message-Id: <20220606222058.86688-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220606222058.86688-1-yosryahmed@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v5 2/4] KVM: mmu: add a helper to account memory used by KVM MMU. From: Yosry Ahmed To: Tejun Heo , Johannes Weiner , Zefan Li , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220606_152112_024073_79C4ABA3 X-CRM114-Status: GOOD ( 10.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a helper to account pages used by KVM for page tables in secondary 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 883e86ec8e8c4..645585f3a4bed 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2246,6 +2246,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