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 CB634C02192 for ; Wed, 5 Feb 2025 10:07:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 557EA280007; Wed, 5 Feb 2025 05:07:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 507AB280004; Wed, 5 Feb 2025 05:07:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38262280007; Wed, 5 Feb 2025 05:07:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 17AE5280004 for ; Wed, 5 Feb 2025 05:07:26 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C2956808D3 for ; Wed, 5 Feb 2025 10:07:25 +0000 (UTC) X-FDA: 83085463650.11.5C5532D Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by imf22.hostedemail.com (Postfix) with ESMTP id E5516C0007 for ; Wed, 5 Feb 2025 10:07:23 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=0L9SWYGq; spf=pass (imf22.hostedemail.com: domain of tabba@google.com designates 209.85.160.176 as permitted sender) smtp.mailfrom=tabba@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=1738750043; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=c20MAwUWneOb5uhlqcc0oyAOyqlg08B0X2hw2T3qX4k=; b=tDQjC02Me8nOtDYFYhavCdwYAYX8aktmbKiiNOV/5upAbhHsayV8mVxiKAzl7bUQOz/cYr gfJuGSpVJ7Q/Z4rMJLe1U89fNUkl75FjD1HUucRc0Cmx1S6XfffYNg4nNbx3gu4AIkIg1l tID1P2u7YzomCJJ2kjLKDQydOmJEzu8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738750043; a=rsa-sha256; cv=none; b=ml7NAQ5vhop9H7lRL8NKQ2gAAvN1HS+UZgykBvOOSVOjRMsgkghw3wsQIQp76NY+j81sPf ZwmPiGSencmuMIRra+CbmBhKLf6uiVvz0+I4mKINu5dwp5yWjwBJnpkrQ9+MZN6JITb+JM BqJex/ec4KH5hzN7/eo9yVmoh+D1y40= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=0L9SWYGq; spf=pass (imf22.hostedemail.com: domain of tabba@google.com designates 209.85.160.176 as permitted sender) smtp.mailfrom=tabba@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-4679b5c66d0so481921cf.1 for ; Wed, 05 Feb 2025 02:07:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738750043; x=1739354843; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=c20MAwUWneOb5uhlqcc0oyAOyqlg08B0X2hw2T3qX4k=; b=0L9SWYGqo2De503pXqklk96PsENSH7mRblkBYXeM+wROfa10vVHb/PQ+eRbswVBKpV tQJZeSivd8SDxusGbHoB/TfD38Sx4tJA05WgmtjFowVYBH2qcik2KT0XWmJ6IF3JN/j/ 29ldON84rmCjvQ60lzu/PagBdE722ZcVZv2kN1FrnvE4gCKt/9nezAYI4B2VQsapEhiL WeMd2qSlRzPB5eCxsYbGSImzm6g0dBmOZ4EB1k68xNi92uu6ibaDw4qrRYctk227jrLO wnqxoUXo4hjVKj4bgQFbTllmRS1vgddE+h7fm9oVBht/9IAMkaqrd5Em3kIgZdGVPDQ9 /Wjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738750043; x=1739354843; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c20MAwUWneOb5uhlqcc0oyAOyqlg08B0X2hw2T3qX4k=; b=DtVe0/omsDVJKeQa8YQ6dbwKsvFDMHP2a0NlErf4aIFP4rodTrrP8asR8lm3+FqJy6 M88FBKuuo1P4QWa5wTlWnNGihLzedNk3ttGJLbEZ3aCgSw9VNd6mrIT5xPXS/xXEzLHj tuIPYfWpVvL/HHLwnF+5GNvH2l41hPMFLOORIdkKTcsBM2zRcBwqRjMQZDmbPaQJCfEM qmW6E+qxIkPZeGc7uKgPFt/0C2vIjmnwJVNlOJEjiOGjyMKVkAVv8Sxt6r4VEpPZfy5S yRXbjPLXLlNIMakcxqTP9IkGS+MlGUTMTUTnXmdk1up4cgmYAci+a27bnq14H0i1fhRZ JVeg== X-Forwarded-Encrypted: i=1; AJvYcCXhUGsDop/E4x6LNj1KYQNqdrrAweHlC9Knk5O+A/J4Cnrz3pGrNj93UbGB6nrHY11VX58uEl4L2Q==@kvack.org X-Gm-Message-State: AOJu0Yxn6Bb6jnq5vRueEsZoDDe4VMOyEf5UOozoQmVXPf1GBZ0sbA2E v/ccgCyRh7cSngaWT0X+WHBTBgQkWU5H/CVvH0joDxhKO/fISdZxkj3eFENJi38bl14Hg772B0F 9sy2yypIxjogoYm2sYnLrd3zQI7HfgNJNAjEc0oL/dNDCD924oFIy X-Gm-Gg: ASbGncsp+cTDKDnRAt4BbtmuPl6LGwFvO1VeE685lbCsARJmxJYfsyC6yVRxuXELmgt 9YFlF+hbRlltBwY/O62YO1fl3aVun3LuhRO41poaPOZMgf7bj12rnVZC8ePlgKONZVk4zoxeN9r KM6SvtO1zykU28k3kDJmrMy3wxsg== X-Google-Smtp-Source: AGHT+IHJm5eP5IJraAdJ0l6P0p5bxXXWPNTIiR8y/Td3Y7ipBJy3707qicLON2w7/iwRKT9isEWGJ+QrxjhJcHJHUKw= X-Received: by 2002:a05:622a:1452:b0:466:8887:6751 with SMTP id d75a77b69052e-4701ab5f39emr6496161cf.23.1738750042843; Wed, 05 Feb 2025 02:07:22 -0800 (PST) MIME-Version: 1.0 References: <20250117163001.2326672-1-tabba@google.com> <20250117163001.2326672-7-tabba@google.com> In-Reply-To: From: Fuad Tabba Date: Wed, 5 Feb 2025 10:06:45 +0000 X-Gm-Features: AWEUYZmTnCpbaOTYVgyU9KFr2DxYz2vXTf9wZYg7lmcYPkuAFt5b5SD3LUAFzWs Message-ID: Subject: Re: [RFC PATCH v5 06/15] KVM: guest_memfd: Handle final folio_put() of guestmem pages To: Vishal Annapurve Cc: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, jthoughton@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: ian75n5wpiuhbrnb99u4nxw714hdju8u X-Rspam-User: X-Rspamd-Queue-Id: E5516C0007 X-Rspamd-Server: rspam03 X-HE-Tag: 1738750043-215374 X-HE-Meta: U2FsdGVkX19UiJBohVJNKqDMoVuJq2TNNl+bRpU9BK4NEVa3wLyYHKjoTRFh1bkzG86EdW7S3KCsHOyGSEEWcGD3x+hqV/McLmb4wnNMY46u7Kd4Ev9SWPpLdzpGxPfwoJm2HMN1Jy7FijSOnYUNWMjXTecP9lWR/7j0Ss71FnRR8iIzKUh6g/JsVe48MEYW7A0r3BLM+Sx4GX4j+S62MOgPC3nklHL3eDhmWipxcdBGOZiOoRJrFWCAk0f5488BW+8hzXATXQ/H1qFZlh0W3qMhGWqekdRC3mQAbNYG6wB1I1Fc/90URw04CKnZTscsI/FJDEFx/ivNndCReYNnw/A49sCxJVjnltGQY+rxb30fdzcF+JQSgOwPNDx/Utgxo2W7GX4XXuR4yhjzNFWkehmRjuIswFO2ZeNdRs1Az308hwe9kAYeHCTvBD3VD2T83OGNIpg6b9BHxlx6Ksx7chXiUhIws5DoodYVyobWgsBYjwlz/rgPzJTwK8c+EcksW/FYl8aszrW1ErtYECO9absPdMQ+ODYoITQOEDuezrZP0948cS22uhqpDA3us3fBA0QdCt7iMcx8kk2zCDy02DNBHQALZNm5/qxYeFZ2vQO8Fj7FUrHYVRR+pgi1qon5qHCIh0UQdeTlqWfYkCyRmtIqMJcButW56EhOyvSC/3QwIogQrXSAtkBU/JmCYT9BtFvgYtMG6Mks+RUCs3SZJq4vtEwgi5TsdGlBjN3jACR8VWJ30CpWDP0QWu3bdGxCX2/+jF+u2ZljDhT8O3XwQUa8wPNeLLRczIqt6yjjqGWKicm8afQRpjkT3scwKM6xi54UyZTm15QeHSx+zW1U+3xmn4mTGAnh2gs3yl2FOO6+7YTx+Urhc+d7hD9+X/sAzurngvdHlXYulMF/82h456bEJZ+9WEskYvq6Jxn05u7M8detWLIzRU6V0vZanWJVZx3k2TJbBNu0cG3Mt5v 8BBCaAtQ 2X0RsT3FPh+2Auboxdhp4KEootzPRrSWKV9LS+EPxDtNii7YNxCZyjXBbu7fnNATRrzeqaRDv+C4hXoHPuM6IxhcB7oPGXrmWfMQ1BDJDOxbf1wmMjPwwl7Z7WBw+xoHjpk3Dc9b92IjHOszY4tquMben/aqGzAS3TcaJR85rgES4C8M1/FqD3iJhXI6DwWRCkq2bKApqp+MSi/H8Ou24s6bM1HtiICWZrWZj68KG/aFwaDrHaFinfDWqwjaqszqAXjXMBe6G+TWlgmLU/35Yg2rYXbLi8ip2Nk3qzdAz41ey8auxsTg0Of1idWslZu2XfxvH5t7MFkLFAfxpkPgUEO4ct75+Sx0MVPpLhIk5whvR6QHsV0nV1LA//Fh2tt2jg2cSudWTQySpS0k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.036469, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Vishal, On Wed, 5 Feb 2025 at 00:42, Vishal Annapurve wrote= : > > On Fri, Jan 17, 2025 at 8:30=E2=80=AFAM Fuad Tabba wro= te: > > > > Before transitioning a guest_memfd folio to unshared, thereby > > disallowing access by the host and allowing the hypervisor to > > transition its view of the guest page as private, we need to be > > sure that the host doesn't have any references to the folio. > > > > This patch introduces a new type for guest_memfd folios, and uses > > that to register a callback that informs the guest_memfd > > subsystem when the last reference is dropped, therefore knowing > > that the host doesn't have any remaining references. > > > > Signed-off-by: Fuad Tabba > > --- > > The function kvm_slot_gmem_register_callback() isn't used in this > > series. It will be used later in code that performs unsharing of > > memory. I have tested it with pKVM, based on downstream code [*]. > > It's included in this RFC since it demonstrates the plan to > > handle unsharing of private folios. > > > > [*] https://android-kvm.googlesource.com/linux/+/refs/heads/tabba/guest= mem-6.13-v5-pkvm > > Should the invocation of kvm_slot_gmem_register_callback() happen in > the same critical block as setting the guest memfd range mappability > to NONE, otherwise conversion/truncation could race with registration > of callback? I don't think it needs to, at least not as far potencial races are concerned. First because kvm_slot_gmem_register_callback() grabs the mapping's invalidate_lock as well as the folio lock, and gmem_clear_mappable() grabs the mapping lock and the folio lock if a folio has been allocated before. Second, __gmem_register_callback() checks before returning whether all references have been dropped, and adjusts the mappability/shareability if needed. Cheers, /fuad