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 7E179C001DF for ; Mon, 24 Jul 2023 17:00:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D624E6B0074; Mon, 24 Jul 2023 13:00:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC4896B0075; Mon, 24 Jul 2023 13:00:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8C7F6B0078; Mon, 24 Jul 2023 13:00:44 -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 A5CA26B0074 for ; Mon, 24 Jul 2023 13:00:44 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 59A8D40BED for ; Mon, 24 Jul 2023 17:00:44 +0000 (UTC) X-FDA: 81047119608.15.F446DB0 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf27.hostedemail.com (Postfix) with ESMTP id 29EBC40017 for ; Mon, 24 Jul 2023 17:00:37 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=iUh3Wr2E; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3NK6-ZAYKCLcpbXkgZdlldib.Zljifkru-jjhsXZh.lod@flex--seanjc.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3NK6-ZAYKCLcpbXkgZdlldib.Zljifkru-jjhsXZh.lod@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690218038; 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=RiFFb9olEr1IXMurVCQB0i8J9xB8UVFiN6yE37xYj5w=; b=u6S3uYT2hHnyJ65QlgBD2Fn8Tw/N2Dfh/16yFZLGFf2eAIlktiu4IUsIAQoAhTu9+n9lAl dT2RulUr85mXohsmcTlmhjWq7vcyCpfhvA0DYAESn8A/XuQmtC444Pv4A8K1Beg3wHc5qu ODlc5vrTr5aVBDxNjB0x2xCHpuAD/aM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=iUh3Wr2E; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3NK6-ZAYKCLcpbXkgZdlldib.Zljifkru-jjhsXZh.lod@flex--seanjc.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3NK6-ZAYKCLcpbXkgZdlldib.Zljifkru-jjhsXZh.lod@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690218038; a=rsa-sha256; cv=none; b=gCFXd3XYmlGGMLhp9m78Pb9HE9IHGrIUCtd8brgX3D3MRn0L+zkaQZAce/M/X34y2d0gm3 DNcW6XVEu7fSGpAOqaOFtbBhdlJoAaBjGiBJ/unPgURSBwKmR80vNd6u1juKFVEhAZ0oU9 aA63sTwtq6ntvkxri5hzu/gniZL4HHU= Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-268068d80b9so756802a91.3 for ; Mon, 24 Jul 2023 10:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690218036; x=1690822836; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RiFFb9olEr1IXMurVCQB0i8J9xB8UVFiN6yE37xYj5w=; b=iUh3Wr2Es7ZayOSlRIyCXv0ISRPLliUqI/wxpz9npizX1RGnl3Zt97AZrYUR8pVjnH OwuM0g2/mnG2Ws1vH1RTNrF8tqURzEVkr4hahdERkph4Nww3rEaO/unCqdjsW1luIjbU y9Vd6q8CcxdQP+GEmRHglSZNO6vM+UxAwTBpxBMCbqTq0hlf3MD2sKnPBjpHoFEjKPFr Tmb3ea8A/X/JO92m7TD8v5eZc4l7fpKAQniXW7MS+8KISe8P4Nbdl//npN/iD7LNKC4a rVBOiRv2FN5pQA6p+V2In5eaYYH21fAVeDedlt36+Mezc1EEot9BPPcgeqHdCs8LHv6O cdZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690218036; x=1690822836; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RiFFb9olEr1IXMurVCQB0i8J9xB8UVFiN6yE37xYj5w=; b=KlBclvV4uScHvvtJn7SUOH6RpgnkDoPLmK1gUQn35qJrrBR6+fwVfK7mEm7Y6AAngm pUlIWZ1+AzodkkrSF4kjAZKEuskccvCQ7BEEsFe8vyZY0fpfVJejGLRvNJag3FD1rd68 L7q3b9Hp+7+W540D4qUf4n3+KpbhDubUXldwpOOL1Ntbye9Yty6zm7kR+4SmfZ3v/Uv1 rZDEq4k2xf3uFEyZp+V500vYFlSM61RqqnLfyAS9V405ZhdcgLPOoYjNeu7UtOfAc4ll 5IOW9InccAqxbmT3ZQ0yzLBgCelu6qsaljaMiPKqhkua5lxpyzuQHU5bSdAXASpRwBXn Bktg== X-Gm-Message-State: ABy/qLZl3nEzmiekMV8r64E4BUmgD+KyZ5B/4q9ZXvsiByDIamGASo2B FsPLoRc9VKYKpbOk18DTVP8FsarHZoA= X-Google-Smtp-Source: APBJJlGFNY8Nsd+UpmzZCGDOgI47OKk03bkzsFP32ko2G/RNTdNXayC/49Rk0sPPfbjIVmYJcM3mAoRuscc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:2308:b0:1b8:80c9:a98e with SMTP id d8-20020a170903230800b001b880c9a98emr42778plh.13.1690218036394; Mon, 24 Jul 2023 10:00:36 -0700 (PDT) Date: Mon, 24 Jul 2023 10:00:34 -0700 In-Reply-To: <110f1aa0-7fcd-1287-701a-89c2203f0ac2@amd.com> Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> <110f1aa0-7fcd-1287-701a-89c2203f0ac2@amd.com> Message-ID: Subject: Re: [RFC PATCH v11 00/29] KVM: guest_memfd() and per-page attributes From: Sean Christopherson To: "Nikunj A. Dadhania" Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="us-ascii" X-Rspamd-Queue-Id: 29EBC40017 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: hj1et7ddnrz1zu4wixep3ditrn6wd9pr X-HE-Tag: 1690218037-556485 X-HE-Meta: U2FsdGVkX19IYnZo3WpCVX5SN+qX64w/rXyX29kE6sWk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SQMqWvFV+SrRTZndx1AhWQHICo3tozjwuyQIADz+EXjIqtBJ7b+6A9T8ifDfR3eFaCCog3jn788BKIEoelRMfpAr2fireiHQVFsnsLBvhPHOSfoge8vfRRUf1tmA3fKIcS1WXQracTK6qePC686LU5Ie2UjWEbwArdflVWpfmjEtovpPzE3qabNvwlUwJwGc+37wE0BCwe9B5dv7ndkf64wRZJ/QhIOzrJNNRtyeW/SmUnx15w59O9kaCBuslrtcfLwTCX9IhrvzguzAiHcp6gQNdnuthAQWCYMfqmF/T2j0+xFL01jmJfZLTdFT7Zv8dDIFF6ovIWNeRJ9pFOFzUINLZ04rmHFYTj8xQacTIowGxdoLIYJCTAobiob5NYkzfDEJGQkQltIx1Eok/+/GeQb20WPMEv3hvNSbn3+XBdsf4uqx7aEr20KlhjtaK2Q17loLk9mjbhXQQ+To8oLU+7kv2uUVnbmAKlwL97Zwv3GPA+cNE96c3UI/uJsH/46+WrvOWicQq/lEbkZ9fizLw9VsaSnIYBFXhN+MSv/j0P5SNclvs1mlTBbsvQpMWkWjlyC045uUe8P4v2WDho= 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, Jul 24, 2023, Nikunj A. Dadhania wrote: > On 7/19/2023 5:14 AM, Sean Christopherson wrote: > > This is the next iteration of implementing fd-based (instead of vma-based) > > memory for KVM guests. If you want the full background of why we are doing > > this, please go read the v10 cover letter[1]. > > > > The biggest change from v10 is to implement the backing storage in KVM > > itself, and expose it via a KVM ioctl() instead of a "generic" sycall. > > See link[2] for details on why we pivoted to a KVM-specific approach. > > > > Key word is "biggest". Relative to v10, there are many big changes. > > Highlights below (I can't remember everything that got changed at > > this point). > > > > Tagged RFC as there are a lot of empty changelogs, and a lot of missing > > documentation. And ideally, we'll have even more tests before merging. > > There are also several gaps/opens (to be discussed in tomorrow's PUCK). > > As per our discussion on the PUCK call, here are the memory/NUMA accounting > related observations that I had while working on SNP guest secure page migration: > > * gmem allocations are currently treated as file page allocations > accounted to the kernel and not to the QEMU process. We need to level set on terminology: these are all *stats*, not accounting. That distinction matters because we have wiggle room on stats, e.g. we can probably get away with just about any definition of how guest_memfd memory impacts stats, so long as the information that is surfaced to userspace is useful and expected. But we absolutely need to get accounting correct, specifically the allocations need to be correctly accounted in memcg. And unless I'm missing something, nothing in here shows anything related to memcg. > Starting an SNP guest with 40G memory with memory interleave between > Node2 and Node3 > > $ numactl -i 2,3 ./bootg_snp.sh > > PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND > 242179 root 20 0 40.4g 99580 51676 S 78.0 0.0 0:56.58 qemu-system-x86 > > -> Incorrect process resident memory and shared memory is reported I don't know that I would call these "incorrect". Shared memory definitely is correct, because by definition guest_memfd isn't shared. RSS is less clear cut; gmem memory is resident in RAM, but if we show gmem in RSS then we'll end up with scenarios where RSS > VIRT, which will be quite confusing for unaware users (I'm assuming the 40g of VIRT here comes from QEMU mapping the shared half of gmem memslots). > Accounting of the memory happens in the host page fault handler path, > but for private guest pages we will never hit that. > > * NUMA allocation does use the process mempolicy for appropriate node > allocation (Node2 and Node3), but they again do not get attributed to > the QEMU process > > Every 1.0s: sudo numastat -m -p qemu-system-x86 | egrep -i "qemu|PID|Node|Filepage" gomati: Mon Jul 24 11:51:34 2023 > > Per-node process memory usage (in MBs) > PID Node 0 Node 1 Node 2 Node 3 Total > 242179 (qemu-system-x86) 21.14 1.61 39.44 39.38 101.57 > Per-node system memory usage (in MBs): > Node 0 Node 1 Node 2 Node 3 Total > FilePages 2475.63 2395.83 23999.46 23373.22 52244.14 > > > * Most of the memory accounting relies on the VMAs and as private-fd of > gmem doesn't have a VMA(and that was the design goal), user-space fails > to attribute the memory appropriately to the process. > > /proc//numa_maps > 7f528be00000 interleave:2-3 file=/memfd:memory-backend-memfd-shared\040(deleted) anon=1070 dirty=1070 mapped=1987 mapmax=256 active=1956 N2=582 N3=1405 kernelpagesize_kB=4 > 7f5c90200000 interleave:2-3 file=/memfd:rom-backend-memfd-shared\040(deleted) > 7f5c90400000 interleave:2-3 file=/memfd:rom-backend-memfd-shared\040(deleted) dirty=32 active=0 N2=32 kernelpagesize_kB=4 > 7f5c90800000 interleave:2-3 file=/memfd:rom-backend-memfd-shared\040(deleted) dirty=892 active=0 N2=512 N3=380 kernelpagesize_kB=4 > > /proc//smaps > 7f528be00000-7f5c8be00000 rw-p 00000000 00:01 26629 /memfd:memory-backend-memfd-shared (deleted) > 7f5c90200000-7f5c90220000 rw-s 00000000 00:01 44033 /memfd:rom-backend-memfd-shared (deleted) > 7f5c90400000-7f5c90420000 rw-s 00000000 00:01 44032 /memfd:rom-backend-memfd-shared (deleted) > 7f5c90800000-7f5c90b7c000 rw-s 00000000 00:01 1025 /memfd:rom-backend-memfd-shared (deleted) This is all expected, and IMO correct. There are no userspace mappings, and so not accounting anything is working as intended. > * QEMU based NUMA bindings will not work. Memory backend uses mbind() > to set the policy for a particular virtual memory range but gmem > private-FD does not have a virtual memory range visible in the host. Yes, adding a generic fbind() is the way to solve silve.