From patchwork Fri Apr 29 20:11:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12832698 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 5DCCAC433F5 for ; Fri, 29 Apr 2022 20:11:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF3CF6B0073; Fri, 29 Apr 2022 16:11:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E2A8C6B0074; Fri, 29 Apr 2022 16:11:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF24A6B0075; Fri, 29 Apr 2022 16:11:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id C121A6B0073 for ; Fri, 29 Apr 2022 16:11:49 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 972DF2094D for ; Fri, 29 Apr 2022 20:11:49 +0000 (UTC) X-FDA: 79411012338.10.6BFD2C6 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 1FABC1C0023 for ; Fri, 29 Apr 2022 20:11:44 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id c194-20020a6335cb000000b0039d9a489d44so4211547pga.6 for ; Fri, 29 Apr 2022 13:11:48 -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=HQRALrLqPLOKdX3/Qrvlj2304W4cY881g6B2XTfjhjE=; b=e1Gj1cFIx7qA9DjuG4CERdhHtwjjaMyqc0jE42K6DIa/HcAF7kLYbOh7A4zE3CfdpC MXLc5TLYF/85xAw4JqYk5Z+4VaQG+kEY5rcUmOxE6tic9A7AB/r3soW+wIKvxsx6s6sb dwf/GudGOtBTMTSquKo6sp/pI7w4IG3EJ9Ed+c2JR8p72budxuezZoM2UOclpII5lS61 jLjhhkg61TxTY5Ps6VReS8PPdn/lF7OSnXOocjCyRcBRNrRTP7mhwtpcGmbPstkKa1Z3 UjsKnboQEBlCrWAyY27GIJsYPsHmlwb5DzS1Loav7ERt/ViNzQEWA6OAJ7ojRdb9jzbP ysnA== 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=HQRALrLqPLOKdX3/Qrvlj2304W4cY881g6B2XTfjhjE=; b=ebzmG+uheoQXZHmK4gQnZmCIkkDM3iFBjoTQLX7N1SItTxuq5PQCkzSGHbUJE+9gqM 3v1Dap5XaKqQe9nEvQ0KJfX+GnYQM+bvbyno/YLZcVEvQN0N/xflTSVXgR7ehU2OebyD Kb1+eYFxihBlmkDNe0iHqeQOVj0soD0zLp3YDm6GQii0RsGN8w+tQv7vOuwAwkpMQIyD 7ExaYFDd7A3ZRva3/cmdETQra/ljIk0RwJGo5xa/Bj1sFiWziVvEiZZW0MDNrCKcmKNy Z3maAt7RFJLiAORSkY8EWPwl3u2eWgwUOs9hA/LH1yhMAhxFx45lbY5jry95ts55RlWB UUsQ== X-Gm-Message-State: AOAM532wd68/N9z7PmlSirztlgqxohJJ6BTiQhFQcXJu2R9IxXhTFKep pvt27+iPt8Q9RGJAO0k1Rz08pid46lME9T99 X-Google-Smtp-Source: ABdhPJyFiTvIOFIZYo+38It2ytGBtkvfsnlq74KMff/yRu6trFEODoofBTp8U5qgZN1B+vJQKJMiROSbmndcmE1m X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a62:87cd:0:b0:50d:bf61:3de9 with SMTP id i196-20020a6287cd000000b0050dbf613de9mr906362pfe.16.1651263107958; Fri, 29 Apr 2022 13:11:47 -0700 (PDT) Date: Fri, 29 Apr 2022 20:11:29 +0000 In-Reply-To: <20220429201131.3397875-1-yosryahmed@google.com> Message-Id: <20220429201131.3397875-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220429201131.3397875-1-yosryahmed@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v4 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-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1FABC1C0023 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=e1Gj1cFI; spf=pass (imf21.hostedemail.com: domain of 3g0ZsYgoKCNoUKONU6DIA9CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3g0ZsYgoKCNoUKONU6DIA9CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Stat-Signature: nhnuahezuozr4x5gzdbnhtaiz3zh6xs9 X-HE-Tag: 1651263104-845660 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 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