From patchwork Tue Jun 28 22:09:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12899017 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 2E053CCA479 for ; Tue, 28 Jun 2022 22:09:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FDA98E0005; Tue, 28 Jun 2022 18:09:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ADC38E0001; Tue, 28 Jun 2022 18:09:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FF718E0005; Tue, 28 Jun 2022 18:09:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 30A808E0001 for ; Tue, 28 Jun 2022 18:09:48 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0B1D436E81 for ; Tue, 28 Jun 2022 22:09:48 +0000 (UTC) X-FDA: 79629037656.04.FFEA09C Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf09.hostedemail.com (Postfix) with ESMTP id B197B140034 for ; Tue, 28 Jun 2022 22:09:47 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id 190-20020a6219c7000000b005251ad26d6eso5717606pfz.16 for ; Tue, 28 Jun 2022 15:09:47 -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=hqFBlBT797q6Bk+fNjYVKQU7mV5jV3ma9qnt5KK3uBo=; b=JEAq+g+yt98HJQFYcbZo11EgdQCrTknULQcgOojyYtX5/1qIJPFoMDpUb0JvS07kBs UBB0lOj3a7XuYN+RxZH7OqEQNbrIbIfwbCX+Napc1EFMPMrzrqRPrpv6TLBnEGIk4l6e D8NTKSe14qutuJxDTg6f/mJOdQOL1xHUrqnK3PlzvOfoI2lI6HUiSSkGIdpK0f7vh6H4 6O9GKuEoHUyXKiAyRapcd/Jdby2QsOa/y878lIAO/AkXQnUJ/iuK6p0Jig+0f5ZboxYv e9Ap/B7iZODIQKB3o8NbA9y6v8baiPB6zs+62vjyZxY29inV33HeqiOuSq0QsRfR0U2q Gycw== 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=hqFBlBT797q6Bk+fNjYVKQU7mV5jV3ma9qnt5KK3uBo=; b=kgN1h2trNLR2AsH7zxM7lTt4oPM04yb8YUtJ4reaYG0k7RjHUZi6SWT+wAhPWx9Y5h 0Qi0ujxzan0/le1gBNLBwX3hO+Ubhpi7HjhEnWDroGM/k3iRGRridfrhadvDF+CF8GrT vOotGSuRCHkJtPq88wS45ZbWNJtrijC6SXaOAyxOpe3PEwrXmQc0nnPEqozA3ePWReqh PubCZM9rCKATRNQl59xTIwM8bPvtjUDDogZCrxMvq6g04DjjQGC66OJHVt62VS2bFQln HeWn9TS7DSKqIdhhyJzVu2YzeRG53VDu6Nq6+fdGgNWzwxwlCbEjGsDg3LNUs2+2mUmZ BXaA== X-Gm-Message-State: AJIora/FDUQAr2RrVRNdeITiai817v14IH9+PUwpElXhbEAbc7MdfFgM AP5mbufOQUdMQKcr9d+oanwUuNnrd1qTB60c X-Google-Smtp-Source: AGRyM1smcFnstKabQ4toVMOHujMO/7vgP/k20+XUxS7A/7XLJg4mWmkTw/RyJ8/gkqU1w7+Eoe95tXVR0LKZACoL X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:15d6:b0:525:3757:4b98 with SMTP id o22-20020a056a0015d600b0052537574b98mr6883216pfu.64.1656454186604; Tue, 28 Jun 2022 15:09:46 -0700 (PDT) Date: Tue, 28 Jun 2022 22:09:36 +0000 In-Reply-To: <20220628220938.3657876-1-yosryahmed@google.com> Message-Id: <20220628220938.3657876-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220628220938.3657876-1-yosryahmed@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v6 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: Huang@google.com, Shaoqin , 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656454187; a=rsa-sha256; cv=none; b=TdqWmMgLVXTnY9OrHsMFVdss/YSpVyoAtjeROjnNeKwuv8wJFRAM+VtFIh1S9S5TodzkGd 2gFNhH/V0WlwdVmUgvYugtt6UiOZ8x2Ev3rTqSq+m1dbqWWQ8gl4RxVlYYloGt8LGO8/kh oxv2lH+35YEsADeKA1mr3z4Zr/bXxFg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=JEAq+g+y; spf=pass (imf09.hostedemail.com: domain of 3Kny7YgoKCC0hXbahJQVNMPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3Kny7YgoKCC0hXbahJQVNMPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656454187; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hqFBlBT797q6Bk+fNjYVKQU7mV5jV3ma9qnt5KK3uBo=; b=7yDJOZVfkh6EqCfl7i671Unz3p/p4BLPhs1dtD1frPjf7HR5D+ua4EYrlO9JeCuYg7iNbm zNqyTpD6G0FQROzVKe4RdiQotDpITjdnsaWwxrBeAbetogMA/qStP4dIXt1V/E+pYA/vhC HYb1EE/Ygq7bxIBnlTwZ9N0/Kx+roGA= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B197B140034 X-Rspam-User: X-Stat-Signature: 3r5xqbkmjsy9re4hp4yfg9j5whs6s866 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=JEAq+g+y; spf=pass (imf09.hostedemail.com: domain of 3Kny7YgoKCC0hXbahJQVNMPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3Kny7YgoKCC0hXbahJQVNMPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1656454187-43834 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 memory secondary pagetable stats. This function will be used by subsequent patches in different archs. Signed-off-by: Yosry Ahmed Acked-by: Marc Zyngier --- include/linux/kvm_host.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 3b40f8d68fbb1..032821d77e920 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2241,6 +2241,16 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) } #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ +/* + * If more than one page is being (un)accounted, @virt must be the address of + * the first page of a block of pages what 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