From mboxrd@z Thu Jan 1 00:00:00 1970 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 985A4C433EF for ; Mon, 27 Jun 2022 16:29:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AC068E0002; Mon, 27 Jun 2022 12:29:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35C168E0001; Mon, 27 Jun 2022 12:29:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 224138E0002; Mon, 27 Jun 2022 12:29:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 163538E0001 for ; Mon, 27 Jun 2022 12:29:15 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D7D8832192 for ; Mon, 27 Jun 2022 16:29:14 +0000 (UTC) X-FDA: 79624550628.18.03496CD Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf14.hostedemail.com (Postfix) with ESMTP id C2883100031 for ; Mon, 27 Jun 2022 16:29:13 +0000 (UTC) Received: by mail-wr1-f43.google.com with SMTP id i1so9338793wrb.11 for ; Mon, 27 Jun 2022 09:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gq7iVePtX9OMXEUxruOPEde6hXUmiczdKpj9eXTuegY=; b=Ub1BAIMzdKFr+whCpBiAWhp0s8tYt12ZNPKk99qiMYNRD5+OYUzq488SqpH/xgr25t tP6UW3BBP+BkhP4WSdd4xXE6Ci/tsk2iyT5Bhr9RQbir03Oa/iDHCs+QNPuMohYTUcPi walxvoBGdCuOHpz56cewOoIomTU+g774SkXfUalipYiRJMVJoZ3pkUJWKDtxaJOUs9Wp z0yK72oV7D8umgBnfJqMPVe0CbYroH1c27oYPHH9DprMH4CUrxPNoWI6SVXsXvOIGR2j g7f70C02303LI4FevNbv4LB2Bfe3rGsWoe0WkiFs0zaMl+gMi3egdBS6vCi70LctvgjH FSRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gq7iVePtX9OMXEUxruOPEde6hXUmiczdKpj9eXTuegY=; b=dyRVzkyx86vU1RLGHABfTLElqaMhHUy+Vx2lZ5N8+rNEWxoofc4zky93ibBCAqBqJZ Bi60qu7NCdoBKuhjm+Gl7dOPOfTaCZJvXBbdR+cleVyEM43keyDNvMwp8E8YCVP+jlfU dhZVGxNVkmC35fh/H+DBbuT2+7J38kNEKtxqCuaVY6EfKT7Viv9sjr2DpW4CRuL/2A01 YefnoG85jxvunvHH/08CwOtX+qGf/PYbil0bJ3mbOBRWGu++qfYTAmwYC4tJOTINyX0r /fjjd8aj7n00v601/lfVetOhMuwI0KXoh9jFsPM7iClqgqOD0gLZNH93Oxdhh4Y5zm/g 8Dpg== X-Gm-Message-State: AJIora9rPBW39Kvwn0g2NDGSNZ5rvxSwQpSiTIe3Wg4FbzqHke4pIddo cIqbTciwqWIDxXK2hbwCjOG1Bld7hkIlem+ll/j8yw== X-Google-Smtp-Source: AGRyM1uGAMC8S/HveHGgFfIt33JanygNnC6EqBWAtLcqKvSeXaHFdpGJHdDoPIAbhtZxeIi7YUBzjamq9VMTyn+dDKo= X-Received: by 2002:a5d:4308:0:b0:219:e5a4:5729 with SMTP id h8-20020a5d4308000000b00219e5a45729mr13879267wrq.210.1656347352384; Mon, 27 Jun 2022 09:29:12 -0700 (PDT) MIME-Version: 1.0 References: <20220606222058.86688-1-yosryahmed@google.com> <20220606222058.86688-3-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Mon, 27 Jun 2022 09:28:36 -0700 Message-ID: Subject: Re: [PATCH v5 2/4] KVM: mmu: add a helper to account memory used by KVM MMU. To: Sean Christopherson Cc: Tejun Heo , Johannes Weiner , Zefan Li , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton , Cgroups , Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux-MM Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656347354; a=rsa-sha256; cv=none; b=f5dc6ImXvBaJ8AXCfzYJBQgqIraRJRcOxcB1C9QfABEqEJdNnqgvGGMZqy6mIchsrTUN/7 K7q+3vKLJD9p1eb+HBpaE2u4YSPlyGViKxzaLKZZjCVGSYTpp/hpaXCYdLkcg/TALM5opC m8Iq33hm7fl9OP/xUkoywJVu7E8vfJo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ub1BAIMz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of yosryahmed@google.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656347354; 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=gq7iVePtX9OMXEUxruOPEde6hXUmiczdKpj9eXTuegY=; b=5qbz6vuV4jmNmikPSC36dvud7K/Li8TlL7yWoFHFXil31fYJqYK4eQVXyN2YlaC5hI6poH sxMoDROBTCordYS0lVLDZDmmx0cTmSxUsFo+zPm2D0WBsT5XSkLUkhPuJ9lsrf6XADw80h g7i2Yu70pL1EDa6XoB8l75FXoRNGbDM= X-Stat-Signature: m7ao616j9yik57rk4dywxkkme3p4mspb X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C2883100031 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ub1BAIMz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of yosryahmed@google.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=yosryahmed@google.com X-HE-Tag: 1656347353-565864 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: On Mon, Jun 27, 2022 at 9:20 AM Sean Christopherson wrote: > > On Mon, Jun 06, 2022, Yosry Ahmed wrote: > > 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 > > But what if @nr is -2, which is technically less than 1? :-) > > > + * pages that were allocated together (i.e accounted together). > > Don't document assumptions, document the rules. And avoid "we", pronouns are > ambiguous, e.g. is "we" the author, or KVM, or something else entirely? > > /* > * 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. > */ > Looks much better, I will use that in the next version. Thanks! > > > + */ > > +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 > > -- > > 2.36.1.255.ge46751e96f-goog > >