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: 12871119 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 7C96CCCA482 for ; Mon, 6 Jun 2022 22:21:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C61E6B0074; Mon, 6 Jun 2022 18:21:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 975E26B0075; Mon, 6 Jun 2022 18:21:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83D516B0078; Mon, 6 Jun 2022 18:21:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 76DA06B0074 for ; Mon, 6 Jun 2022 18:21:12 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4C9C360D25 for ; Mon, 6 Jun 2022 22:21:12 +0000 (UTC) X-FDA: 79549232784.21.C1E67F9 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf19.hostedemail.com (Postfix) with ESMTP id D6EE91A001C for ; Mon, 6 Jun 2022 22:20:54 +0000 (UTC) Received: by mail-pj1-f74.google.com with SMTP id o8-20020a17090a9f8800b001dc9f554c7fso8255562pjp.4 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=osncGCILK5TF/91Kxv/b1JMbD7za5e+biaxHCkq+5R3c66kbRBgfcwQIZVUyXyelld Q4FwUbAweZuemxIl86/3r0lJHVWK+bBnLaRQ6HQga9JZj2fvVLN6k/jeiMhGJQ8BCxbp HPKW2wrTo9EmnQp7mZGBBNxv9wba84BpqSTlPsHJ1hb/bTwJO/w9FRsvWXG34208+MBK WrtevzHaKs6CcR+neXkvoZBiI5TXjmCsZzOrRCQ2kzoMl/3KxtZB0o4HfE15bo+JYkpY huC/gSF923t+F3DmkpV8rDfc9La1B34OFw0B8/DPOyLJIl53Yz8hXC0zxdwj1uvJDEwI ntPw== X-Gm-Message-State: AOAM530CCny11a+e3tIoQ2IWbi43EXuDK5K55MQtqq7Ebmth5hoW5pkF MjQ0N79Dsa2lbhoPgxtYaWY3U93A+fJT4Q7u 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-Stat-Signature: f51amydb88j53zxhwe9gfa1roexnrmi1 X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Zr9Q8V4n; spf=pass (imf19.hostedemail.com: domain of 31n2eYgoKCGcdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=31n2eYgoKCGcdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D6EE91A001C X-HE-Tag: 1654554054-55903 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 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