From patchwork Tue Aug 23 00:46:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12951573 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 F00CFC28D13 for ; Tue, 23 Aug 2022 00:46:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CBC68D0005; Mon, 22 Aug 2022 20:46:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72DB68D0001; Mon, 22 Aug 2022 20:46:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5594A8D0005; Mon, 22 Aug 2022 20:46:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 43E548D0001 for ; Mon, 22 Aug 2022 20:46:48 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1AD95121352 for ; Tue, 23 Aug 2022 00:46:48 +0000 (UTC) X-FDA: 79829017296.06.A58B24C Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf01.hostedemail.com (Postfix) with ESMTP id C022440028 for ; Tue, 23 Aug 2022 00:46:47 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id d10-20020a056a00198a00b005367ac052bbso1827196pfl.16 for ; Mon, 22 Aug 2022 17:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=5wbHjJjCu3OWrOn0g8QSFmD92QscX6sNHkdnPnrNJvc=; b=GGOXmJOAwFS6LKwoOWp4bp7t6wNw/r+7YZKC8GNGkd18DnlB6LfP9CL34RL2KPfceG AXZl8PPfPtapEOLbCmJ/rNGm5f6yciTGJoywKkjojZNxw+GL1YEMWcjzDhmGBCk/MdMy 4t7Q1LoMp7rN7dy2pMFqxMAJGP7jixHUwhGq1q/8ObLjXUCDxT+pRv0n8APeUo1COdXm hZwjDYvOa5gy4NpGGIl+jhzRr9f9Ii2wUpWXASQIPm5HwhVrZhUzyQI6uum045xl3TUP 3jXo+RDzJG2rD4y1NqG9xsCTA/WKZF3fW3AxCEi9F87GMBLRezoaX2KOatGvk8ccetqZ Mr+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=5wbHjJjCu3OWrOn0g8QSFmD92QscX6sNHkdnPnrNJvc=; b=nkDTTitG/XbYf6LALCOeCc/R8M/jHTGvO5WsE4REpBw8pW4NNZ6YQVpygYIUXpYPaw ISr44rTXCDLT/6cIZUAS5TucgyBGkkO0I6mbcw3eWm+oToPsQzvpTSp5mLV6rMMMjxE2 ArF1EsmqTePXo7+VHRshc2wVxTJn4gZ/BfjLJUImsVumYk+LiqUBmjsWncXsgRCcsLmh jwPZRjmwouCNsS1zZR2YliZ5EyT8E6L45AFqDsk/GY0aSpHYNkFeEekl8Dj9cnqDDxoU gDp1LHR6S0Z2K4pMAB4KO5aOkrvBdQnztJvLw+NsgokWRrYNqd3Hp7W0JatlF++473SM Mqcg== X-Gm-Message-State: ACgBeo2JLJRElslqWwGopScm9abQQNvpDQlszknFJgKV5FcJ+wIt6Tj9 hbf6vi/fa1k7bFy+b3TiuWY36e6L+nffYHQ3 X-Google-Smtp-Source: AA6agR4dQrwU/uwhH/YBd8bM5leaexCVvoGHCx2rlR/Vt0DcZKu7/ZnqA8s5ncAFX9MqU3Pk76hGv0BKG2GC/oz4 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:15cb:b0:52e:6100:e7a7 with SMTP id o11-20020a056a0015cb00b0052e6100e7a7mr22724154pfu.23.1661215606877; Mon, 22 Aug 2022 17:46:46 -0700 (PDT) Date: Tue, 23 Aug 2022 00:46:37 +0000 In-Reply-To: <20220823004639.2387269-1-yosryahmed@google.com> Message-Id: <20220823004639.2387269-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220823004639.2387269-1-yosryahmed@google.com> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH v7 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=1661215607; a=rsa-sha256; cv=none; b=P35+G+gnP0BevhRzlCO+wuZMFAIuuA51as+72hdDWicqmnHp0XXJUkP4DKdng0WRyY0anK YV2r/A/aLpE8L6Yme52Vv67VxP1lpXXOk4abbje5Kn13wRgOqQHylbNq9IbDWYtBt+hry3 B5Lrr2/dIwgJFLpJXjcSE+Za5UqImlA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GGOXmJOA; spf=pass (imf01.hostedemail.com: domain of 3diMEYwoKCOslbfelNUZRQTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3diMEYwoKCOslbfelNUZRQTbbTYR.PbZYVahk-ZZXiNPX.beT@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=1661215607; 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=5wbHjJjCu3OWrOn0g8QSFmD92QscX6sNHkdnPnrNJvc=; b=pIUXCl6g3bk1SoiCvFjHexRkOczF1EgD+GOqSm4ICN0lt7gFHkUmcIjklS88UypOhqx6Ip xirLBPs7ckNYdtFmoqS1FVYjlYNTuFJNP99znFz+C+2vu+aDLP7hhUilaHe6vBXxqm1PrQ DK+EDQsIEFsBF4cDlRH7Zos/X0O+KDE= X-Rspamd-Queue-Id: C022440028 X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GGOXmJOA; spf=pass (imf01.hostedemail.com: domain of 3diMEYwoKCOslbfelNUZRQTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3diMEYwoKCOslbfelNUZRQTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Stat-Signature: gjfaifumq16n1igxatmcrynbtump1jdy X-HE-Tag: 1661215607-303418 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index f4519d3689e1..04c7e5f2f727 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2247,6 +2247,19 @@ 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). + * + * kvm_account_pgtable_pages() is thread-safe because mod_lruvec_page_state() + * is thread-safe. + */ +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