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 3CFF5C27C53 for ; Wed, 19 Jun 2024 12:16:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AACF78D007D; Wed, 19 Jun 2024 08:16:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5C598D0066; Wed, 19 Jun 2024 08:16:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AF348D007D; Wed, 19 Jun 2024 08:16:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 66F018D0066 for ; Wed, 19 Jun 2024 08:16:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CAF77A1189 for ; Wed, 19 Jun 2024 12:16:19 +0000 (UTC) X-FDA: 82247535678.28.4A829CD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 6D28CC0017 for ; Wed, 19 Jun 2024 12:16:17 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hu/x6v7I"; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718799371; 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=+CVGzV0WgyAWVjh7om6sIr5XcC5MzMlHd83b2E272eU=; b=eRUhryqCTpbZTqu6aAAfIb0qthfigAg/MMmHh3UU2DNNIzgeABYScm6NBhNfeZ3X1qIaTB tqk0rZ0eYtFEsPHvvUqpZTm6ICVUeERvIsBMqYUvPW5aoo2INLzToYQTY9GBAUSFbi2lok neE5HjqEYvDci6IRdnM/2t9KbuurKNo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="hu/x6v7I"; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718799371; a=rsa-sha256; cv=none; b=8XVHp8vxM2Q1T6opaENUCeJpTznrjCRffmtxmAeeNqetF1HW+au+xzMc4jfuc5zYD07iQN GOob4vz2+kEdnHDPe1366venqOJJSN3dH947ByJDuFuAQR6pDfNFGN60z+0ek/txYQxr5H JnSlpIHgtDjVXsmaNPlxJLsqVJf2A9k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718799376; h=from:from: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:autocrypt:autocrypt; bh=+CVGzV0WgyAWVjh7om6sIr5XcC5MzMlHd83b2E272eU=; b=hu/x6v7I6F+w3M7Rdw/ndwwWeoS2Wwyt4KKUrxDslJNW7tA2KWNuyD1Pgj5vVHs5pbajHf pe1NMmrXD0cWOG8Pn5oY4czGzum42jgHIwlhQeBHbZKlF2YnmoF/mMHrqEKx7IOrLsEyun Nvy3x28tFvvSJhCqieK6MeSTbGtX/5U= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-eoo7eoJ1PlmdSc2g1PKflw-1; Wed, 19 Jun 2024 08:16:15 -0400 X-MC-Unique: eoo7eoJ1PlmdSc2g1PKflw-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2ebe662e992so59301561fa.3 for ; Wed, 19 Jun 2024 05:16:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718799374; x=1719404174; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=+CVGzV0WgyAWVjh7om6sIr5XcC5MzMlHd83b2E272eU=; b=OpBF4tJ91E4klSn26OHoIgan78aOgfgLq6sgydbTKdL7iiJ08g0P2ICfhnlHtS1oHO 7CzXj5RXJJZLdg5FWUTroobjnJHtMtfpDU/4/cm3sWUTpGBBESAYyC5bvO/6GTc+GTRL j2X7zwdsQ/A5ArxsSITfRP3NojzeYQ6RhALcKcqbgH/w5udKEOxVF3aGtPunnc+ljPRr NigAVqBxfSAtZM9WLXIvAdjUQCIeA2uNuXdLNEA+FdZ5B29jb4qpTbH3/1wjSTguzGsT L6R3SJ0KOBU3x0UFB4yAirVZFRjFoepGPX2FqjRj+jeTbN2LBJqz9epbhnqObi1UTlvn 5y/w== X-Forwarded-Encrypted: i=1; AJvYcCXtyHBx/lg3CZFzr0L33V2G/6w57Ag4n+PoHKFhneQO4nbZ51HoOOJFZKdzgfmkCjs+vCdWMwovk1gDiXiW0DhZOV8= X-Gm-Message-State: AOJu0Yxa8esXJl96IIXSNfO0oE6pNqs5YOPuJMmOEUMC+flKqxwnQtCr aJHo7Sbhsjfj730SB2BsFDHNFRimS9IRPls/Ur3NKCLNsidnnUY9UbJ2AcGov4ZyEgVyJcfW/Md wLX2sZWa8KSr1xKd5F4sMcyvTr+PxflCLqUBg4CwOv66EMg8j X-Received: by 2002:a2e:b1c2:0:b0:2ec:30cd:fd77 with SMTP id 38308e7fff4ca-2ec3cea5775mr20000351fa.5.1718799373704; Wed, 19 Jun 2024 05:16:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZnKQf538+rtlBWYEvMqpV6n2p014UkqRTYYzQlkS/1LKOgUQLm17e16oxBDMh1iNDucRN6w== X-Received: by 2002:a2e:b1c2:0:b0:2ec:30cd:fd77 with SMTP id 38308e7fff4ca-2ec3cea5775mr20000091fa.5.1718799373135; Wed, 19 Jun 2024 05:16:13 -0700 (PDT) Received: from ?IPV6:2003:cb:c705:ab00:f9b6:da12:cad4:6642? (p200300cbc705ab00f9b6da12cad46642.dip0.t-ipconnect.de. [2003:cb:c705:ab00:f9b6:da12:cad4:6642]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-362e3e1abd5sm3048429f8f.47.2024.06.19.05.16.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Jun 2024 05:16:12 -0700 (PDT) Message-ID: <489d1494-626c-40d9-89ec-4afc4cd0624b@redhat.com> Date: Wed, 19 Jun 2024 14:16:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 0/5] mm/gup: Introduce exclusive GUP pinning To: Fuad Tabba Cc: John Hubbard , Elliot Berman , Andrew Morton , Shuah Khan , Matthew Wilcox , maz@kernel.org, kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, pbonzini@redhat.com, Jason Gunthorpe References: <20240618-exclusive-gup-v1-0-30472a19c5d1@quicinc.com> <7fb8cc2c-916a-43e1-9edf-23ed35e42f51@nvidia.com> <14bd145a-039f-4fb9-8598-384d6a051737@redhat.com> From: David Hildenbrand Autocrypt: addr=david@red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1ORZKANLnRAb0NH/UCzcsstw2TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Stat-Signature: zfs3c81honpr6fd76nzi1ko4jkxemjyo X-Rspam-User: X-Rspamd-Queue-Id: 6D28CC0017 X-Rspamd-Server: rspam02 X-HE-Tag: 1718799377-827153 X-HE-Meta: U2FsdGVkX1/DUPkHRb5qtQF1+9Q1X0MHmV/YrmSo3UzPSx/HurOgh+JMJkp339b/cf9WASabcACoB4JaLxGwLagIjbIKojgXhTD7tIQRYcpvVQD2FxQFSiUD6M39ICVT0cmkENmutcbc7tJ0gz4LD2ZjK1MREbkC/fU2JNu6ItjsE48Px9aIi706gGq4PUeN18sSnQGEspL09ld71iFInW+00uSR3lpEM4qNxh3j9gtfwIKiN3Nv/kl1nCNfK9ry+kyXPpd18MdSf3morHlHebSm0tJquX8/h5yJw3pXki3XfOnrvsK8L4R8dNed0v1CuPI4taF9PXyn2fWi/lOxpERbNFkAqrag0MjL1Y+7uFFo45ZvHjdPLo2wJNbuej4B+N/PEA+OuGtaWurQajh6V7pl0nbGJQAPK28Xv2y+Ynqs+05BSN5uF3uIBtYs5kjygge3NWfpOoCb82DFX1DbD9atRorwcxjWELfygH49L7ihmPPj4OwtT9/zJq29eHUgXVTPPHa9fQnxTDGapvYkIJdyKyltS4xUF378NNpyiLkVBcSUYKWAV14xVFhbq/szqPJXpapavt1DlDrFp29lazRWncTBRZOE7M01P+YvAF6i6c9CiX1iBILM0muDZPFfGZ7ENV153pL221H7pRZ3iQf3AyOwg0l0HpadfhA6p/khyPVobIzPFZAIorb6FvwsusK2yqVehIz8CILsiSKU+AwhpJFYdqoiazt4V9Ug6ra1clOmxnBumjG3Ot3AR5Uryj8vu+jPpmIsVinPIlteA4/V6Sd8wUF7+0CxBupWpCam0gRgRZpj0ArRB2qRnfIBQx6sBDP+OjZReCOqgVweEwTD9ZkRVO2Xp1UoXBO8EwPBanQTtzuFgUnuq2sFoMel+cJV4nI81Q/Lmiznbr41a/2FF2LPjxRdh1/4Mvx22HDYUnrpKhgXf0GcUDtelcZ1UTWlFsWBY8+wrj560v6 IsPJwNNY RRGccUdgazMsZGDMHp0EFUw7swQs4iPEFe7X26d3goje/pCwdUm2qOW1CJ/MjaMxjcW+2DPhvHn0ZvjX7nx9Miq7Rc/tcA01RtN9z97GHkWvRIRjf6RVlFr598Z6JnRYrJjRMSQ5p0f5WEjArxSgnsT9+QmUEMig2o3wXuib5K9oMSDMcpLQc3ytQEoDoOGpPBQOyUE8flZ/zPWHYIZ3cREAihx0DZ8tsNqazWi2Z3na38HKloAgHJm31zyPbe+FOfDltdj4wXp0vBIC2LY0LGAOG6uw5RzjTeastHhITgronEajYOgFmtdKVg+SAFv562x0kjg3GJ4NDCF0mJOaOPvJdStrt0avhXuNF6n3Fjnj60MfAka4/IocmpaY92aINYyB03Om0LOC7ewnYXT6UKG+fn3qd+7peq/FR3UhoiJ1oZnkkXmQcW+2CIReTxJTevmoQou7eM3NtUJfJeDCqpVOC8kxVmKGFA5Gk 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: List-Subscribe: List-Unsubscribe: On 19.06.24 11:11, Fuad Tabba wrote: > Hi John and David, > > Thank you for your comments. > > On Wed, Jun 19, 2024 at 8:38 AM David Hildenbrand wrote: >> >> Hi, >> >> On 19.06.24 04:44, John Hubbard wrote: >>> On 6/18/24 5:05 PM, Elliot Berman wrote: >>>> In arm64 pKVM and QuIC's Gunyah protected VM model, we want to support >>>> grabbing shmem user pages instead of using KVM's guestmemfd. These >>>> hypervisors provide a different isolation model than the CoCo >>>> implementations from x86. KVM's guest_memfd is focused on providing >>>> memory that is more isolated than AVF requires. Some specific examples >>>> include ability to pre-load data onto guest-private pages, dynamically >>>> sharing/isolating guest pages without copy, and (future) migrating >>>> guest-private pages. In sum of those differences after a discussion in >>>> [1] and at PUCK, we want to try to stick with existing shmem and extend >>>> GUP to support the isolation needs for arm64 pKVM and Gunyah. >> >> The main question really is, into which direction we want and can >> develop guest_memfd. At this point (after talking to Jason at LSF/MM), I >> wonder if guest_memfd should be our new target for guest memory, both >> shared and private. There are a bunch of issues to be sorted out though ... >> >> As there is interest from Red Hat into supporting hugetlb-style huge >> pages in confidential VMs for real-time workloads, and wasting memory is >> not really desired, I'm going to think some more about some of the >> challenges (shared+private in guest_memfd, mmap support, migration of >> !shared folios, hugetlb-like support, in-place shared<->private >> conversion, interaction with page pinning). Tricky. >> >> Ideally, we'd have one way to back guest memory for confidential VMs in >> the future. > > As you know, initially we went down the route of guest memory and > invested a lot of time on it, including presenting our proposal at LPC > last year. But there was resistance to expanding it to support more > than what was initially envisioned, e.g., sharing guest memory in > place migration, and maybe even huge pages, and its implications such > as being able to conditionally mmap guest memory. Yes, and I think we might have to revive that discussion, unfortunately. I started thinking about this, but did not reach a conclusion. Sharing my thoughts. The minimum we might need to make use of guest_memfd (v1 or v2 ;) ) not just for private memory should be: (1) Have private + shared parts backed by guest_memfd. Either the same, or a fd pair. (2) Allow to mmap only the "shared" parts. (3) Allow in-place conversion between "shared" and "private" parts. (4) Allow migration of the "shared" parts. A) Convert shared -> private? * Must not be GUP-pinned * Must not be mapped * Must not reside on ZONE_MOVABLE/MIGRATE_CMA * (must rule out any other problematic folio references that could read/write memory, might be feasible for guest_memfd) B) Convert private -> shared? * Nothing to consider C) Map something? * Must not be private For ordinary (small) pages, that might be feasible. (ZONE_MOVABLE/MIGRATE_CMA might be feasible, but maybe we could just not support them initially) The real fun begins once we want to support huge pages/large folios and can end up having a mixture of "private" and "shared" per huge page. But really, that's what we want in the end I think. Unless we can teach the VM to not convert arbitrary physical memory ranges on a 4k basis to a mixture of private/shared ... but I've been told we don't want that. Hm. There are two big problems with that that I can see: 1) References/GUP-pins are per folio What if some shared part of the folio is pinned but another shared part that we want to convert to private is not? Core-mm will not provide the answer to that: the folio maybe pinned, that's it. *Disallowing* at least long-term GUP-pins might be an option. To get stuff into an IOMMU, maybe a per-fd interface could work, and guest_memfd would track itself which parts are currently "handed out", and with which "semantics" (shared vs. private). [IOMMU + private parts might require that either way? Because, if we dissallow mmap, how should that ever work with an IOMMU otherwise]. 2) Tracking of mappings will likely soon be per folio. page_mapped() / folio_mapped() only tell us if any part of the folio is mapped. Of course, what always works is unmapping the whole thing, or walking the rmap to detect if a specific part is currently mapped. Then, there is the problem of getting huge pages into guest_memfd (using hugetlb reserves, but not using hugetlb), but that should be solvable. As raised in previous discussions, I think we should then allow the whole guest_memfd to be mapped, but simply SIGBUS/... when trying to access a private part. We would track private/shared internally, and track "handed out" pages to IOMMUs internally. FOLL_LONGTERM would be disallowed. But that's only the high level idea I had so far ... likely ignore way too many details. Is there broader interest to discuss that and there would be value in setting up a meeting and finally make progress with that? I recall quite some details with memory renting or so on pKVM ... and I have to refresh my memory on that. > > To be honest, personally (speaking only for myself, not necessarily > for Elliot and not for anyone else in the pKVM team), I still would > prefer to use guest_memfd(). I think that having one solution for > confidential computing that rules them all would be best. But we do > need to be able to share memory in place, have a plan for supporting > huge pages in the near future, and migration in the not-too-distant > future. Yes, huge pages are also of interest for RH. And memory-overconsumption due to having partially used huge pages in private/shared memory is not desired. > > We are currently shipping pKVM in Android as it is, warts and all. > We're also working on upstreaming the rest of it. Currently, this is > the main blocker for us to be able to upstream the rest (same probably > applies to Gunyah). > >> Can you comment on the bigger design goal here? In particular: > > At a high level: We want to prevent a misbehaving host process from > crashing the system when attempting to access (deliberately or > accidentally) protected guest memory. As it currently stands in pKVM > and Gunyah, the hypervisor does prevent the host from accessing > (private) guest memory. In certain cases though, if the host attempts > to access that memory and is prevented by the hypervisor (either out > of ignorance or out of malice), the host kernel wouldn't be able to > recover, causing the whole system to crash. > > guest_memfd() prevents such accesses by not allowing confidential > memory to be mapped at the host to begin with. This works fine for us, > but there's the issue of being able to share memory in place, which > implies mapping it conditionally (among others that I've mentioned). > > The approach we're taking with this proposal is to instead restrict > the pinning of protected memory. If the host kernel can't pin the > memory, then a misbehaving process can't trick the host into accessing > it. Got it, thanks. So once we pinned it, nobody else can pin it. But we can still map it? > >> >> 1) Who would get the exclusive PIN and for which reason? When would we >> pin, when would we unpin? > > The exclusive pin would be acquired for private guest pages, in > addition to a normal pin. It would be released when the private memory > is released, or if the guest shares that memory. Understood. > >> 2) What would happen if there is already another PIN? Can we deal with >> speculative short-term PINs from GUP-fast that could introduce >> errors? > > The exclusive pin would be rejected if there's any other pin > (exclusive or normal). Normal pins would be rejected if there's an > exclusive pin. Makes sense, thanks. > >> 3) How can we be sure we don't need other long-term pins (IOMMUs?) in >> the future? > > I can't :) :) > >> 4) Why are GUP pins special? How one would deal with other folio >> references (e.g., simply mmap the shmem file into a different >> process). > > Other references would crash the userspace process, but the host > kernel can handle them, and shouldn't cause the system to crash. The > way things are now in Android/pKVM, a userspace process can crash the > system as a whole. Okay, so very Android/pKVM specific :/ > >> 5) Why you have to bother about anonymous pages at all (skimming over s >> some patches), when you really want to handle shmem differently only? > > I'm not sure I understand the question. We use anonymous memory for pKVM. > "we want to support grabbing shmem user pages instead of using KVM's guestmemfd" indicated to me that you primarily care about shmem with FOLL_EXCLUSIVE? >>>> To that >>>> end, we introduce the concept of "exclusive GUP pinning", which enforces >>>> that only one pin of any kind is allowed when using the FOLL_EXCLUSIVE >>>> flag is set. This behavior doesn't affect FOLL_GET or any other folio >>>> refcount operations that don't go through the FOLL_PIN path. >> >> So, FOLL_EXCLUSIVE would fail if there already is a PIN, but >> !FOLL_EXCLUSIVE would succeed even if there is a single PIN via >> FOLL_EXCLUSIVE? Or would the single FOLL_EXCLUSIVE pin make other pins >> that don't have FOLL_EXCLUSIVE set fail as well? > > A FOLL_EXCLUSIVE would fail if there's any other pin. A normal pin > (!FOLL_EXCLUSIVE) would fail if there's a FOLL_EXCLUSIVE pin. It's the > PIN to end all pins! > >>>> >>>> [1]: https://lore.kernel.org/all/20240319143119.GA2736@willie-the-truck/ >>>> >>> >>> Hi! >>> >>> Looking through this, I feel that some intangible threshold of "this is >>> too much overloading of page->_refcount" has been crossed. This is a very >>> specific feature, and it is using approximately one more bit than is >>> really actually "available"... >> >> Agreed. > > We are gating it behind a CONFIG flag :) ;) > > Also, since pin is already overloading the refcount, having the > exclusive pin there helps in ensuring atomic accesses and avoiding > races. > >>> >>> If we need a bit in struct page/folio, is this really the only way? Willy >>> is working towards getting us an entirely separate folio->pincount, I >>> suppose that might take too long? Or not? >> >> Before talking about how to implement it, I think we first have to learn >> whether that approach is what we want at all, and how it fits into the >> bigger picture of that use case. >> >>> >>> This feels like force-fitting a very specific feature (KVM/CoCo handling >>> of shmem pages) into a more general mechanism that is running low on >>> bits (gup/pup). >> >> Agreed. >> >>> >>> Maybe a good topic for LPC! >> >> The KVM track has plenty of guest_memfd topics, might be a good fit >> there. (or in the MM track, of course) > > We are planning on submitting a proposal for LPC (see you in Vienna!) :) Great! -- Cheers, David / dhildenb