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 E4C0EC54E67 for ; Thu, 28 Mar 2024 10:32:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 672976B0087; Thu, 28 Mar 2024 06:32:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 649166B0088; Thu, 28 Mar 2024 06:32:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C2826B0089; Thu, 28 Mar 2024 06:32:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2D9396B0087 for ; Thu, 28 Mar 2024 06:32:31 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C68C0141087 for ; Thu, 28 Mar 2024 10:32:30 +0000 (UTC) X-FDA: 81946083660.10.C0A0B6B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 7B7824001A for ; Thu, 28 Mar 2024 10:32:28 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LywfnhsE; spf=pass (imf17.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=1711621948; 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=a2lVbDhBQAGHbBTeKbzP4+/8kq2G3gaGnD2z+bIc43o=; b=luEej5gv2noDP+lVMZg+kBbVNwiuNCOa/OOZoz3BAjMM2Hr/eg1nLbh3FejkG1r+LVYHw3 kitwITVWI7AlIFGnUUaC7T+sPzRlBC9iNpUiZyBDsYWm3X9EddEj2ij+7D/R81Ne3H2jPM +N6+QMP9MlGr/76Gs7uOR0TWTg6jM+g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711621948; a=rsa-sha256; cv=none; b=oPRqRNUxh+XZHKguSBd+ZtTKX8bJtR6p7OkgF/nhQBqVQE/wdHxhOwUASR6lNzH5yaNgK3 E7KWHU+DclbWV0zji/QkYPU2QaVGTnNLlnNilAfErQmzNeRpDYfyH0I4jUTZp2Ha0WNkt3 woHinD9FtjuBGH8awl2GV8IyBHZz0ZY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LywfnhsE; spf=pass (imf17.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711621947; 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=a2lVbDhBQAGHbBTeKbzP4+/8kq2G3gaGnD2z+bIc43o=; b=LywfnhsE4hS9UchhDnNmZn4rfW9BTp6ZNBlXVssM1yCCHdtkgFtruarpnjxdoVgP8Gv+hV VZTxf+ioY7QL+ejjRAmKnMvA4Zo/FFemjlFMFvWdKcENVv2zl2M3n9wigxto7TCHHV7ziE KXVZfCC5FN8uIRCTVDSExkAbSyKM1DQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-Jm7Hvba0MRu5ILNahp5lbA-1; Thu, 28 Mar 2024 06:32:26 -0400 X-MC-Unique: Jm7Hvba0MRu5ILNahp5lbA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-33ed44cb765so397011f8f.2 for ; Thu, 28 Mar 2024 03:32:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711621945; x=1712226745; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=a2lVbDhBQAGHbBTeKbzP4+/8kq2G3gaGnD2z+bIc43o=; b=VyQDo+lDljNU3encnRrE/uCOz/He0XOPXOUSzKerYLsJIpuWIu5YaLlE/hHJ9/PAJR MQ2AbSgKkOVvTZ0KbW/ntSEq0D6t+9ohCmQ6mqaMfo79RBm7vJw3drJPoUHSGI+gykNZ 0MQkMfTf3dTpMCvaUS8jx6VfC0ol7mwYDSS6Ytismt4oGhQsPoU6SMegOX/lEHwG60cE +yDytFagvyAHPUdn1GnNBBrfMgggFVJ3njZbTZIH3jNyNjO4zOfmd37AwBYo4xSlZU5r +Nl7RiK6tNIZpE5JdCyotUN34lpEqRHIY2Pwh+CoX8qcLNHnYJa02Ov2N7bov7aknJ/H nygg== X-Forwarded-Encrypted: i=1; AJvYcCU/akGZwmO9NmBsSOjOGkdPWn0RCAy695BmQVutQu93Nw3kOMsAB3CSvjCwS3U0N/M73j2vSr8JKDMbct2DsfIcbfs= X-Gm-Message-State: AOJu0YwqqGmIjWYn8UqkuXOsoAmaV5ROHnsilSY+tIunZND6AURx5UjW xZx/he5ZKlKDtnMCI+GGc594GOx84RIkSVf3hSu1512D9/YEMmdM0KynIW9DNSiRrLD9SsvaPTl HqTNj6Uksnqx6Pf1kUYELyQr27VspnI3/HsB+794xz39L/Jkn X-Received: by 2002:a05:6000:b02:b0:341:b88b:1625 with SMTP id dj2-20020a0560000b0200b00341b88b1625mr1833220wrb.47.1711621945043; Thu, 28 Mar 2024 03:32:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtRmr7MLED52ndtuQiaribupCgpW5/XeVPL8xlVphG3frt96gyLBlt13aNtU8L03uNXpOcew== X-Received: by 2002:a05:6000:b02:b0:341:b88b:1625 with SMTP id dj2-20020a0560000b0200b00341b88b1625mr1833174wrb.47.1711621944502; Thu, 28 Mar 2024 03:32:24 -0700 (PDT) Received: from ?IPV6:2003:cb:c714:3600:8033:4189:6bd4:ea29? (p200300cbc7143600803341896bd4ea29.dip0.t-ipconnect.de. [2003:cb:c714:3600:8033:4189:6bd4:ea29]) by smtp.gmail.com with ESMTPSA id bx6-20020a5d5b06000000b00341e67a7a90sm1423428wrb.19.2024.03.28.03.32.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Mar 2024 03:32:24 -0700 (PDT) Message-ID: <5cec1f98-17a5-4120-bbf4-b487c2caf92c@redhat.com> Date: Thu, 28 Mar 2024 11:32:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: folio_mmapped To: Quentin Perret Cc: Will Deacon , Sean Christopherson , Vishal Annapurve , Matthew Wilcox , Fuad Tabba , kvm@vger.kernel.org, kvmarm@lists.linux.dev, pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, viro@zeniv.linux.org.uk, brauner@kernel.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, 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_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, keirf@google.com, linux-mm@kvack.org References: <7470390a-5a97-475d-aaad-0f6dfb3d26ea@redhat.com> <40f82a61-39b0-4dda-ac32-a7b5da2a31e8@redhat.com> <20240319143119.GA2736@willie-the-truck> <2d6fc3c0-a55b-4316-90b8-deabb065d007@redhat.com> <20240327193454.GB11880@willie-the-truck> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6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6SH9pum9PuoE/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: 7bit X-Rspamd-Queue-Id: 7B7824001A X-Rspam-User: X-Stat-Signature: xu9hzz6by9djd3jbwzed4ymrbs4fkbbf X-Rspamd-Server: rspam03 X-HE-Tag: 1711621948-174380 X-HE-Meta: U2FsdGVkX19VYMR3jXvLTSzJjypI8PZmIdwNr0wvW5vVx4lA+9qwi71hjOGNpNepyL64HPw+viraXT+GF1pOub+U2eWpyWk4qB2rR2S6d/plQf5yqEAgo5NKLpEdobg1fxAp2qDXyZuNAXNydvQAjUJsDOWu0O3aULS1yvgxDDIi00uFHnSc0+WeCmE0rf+He6HKpZ3UDcuRThajAKsXuyEH8vad5F+m2kEcveFcZBvTaHP06Kq3/ZN7OkeuQCsiKz45MQHjSgaltqWLYHcxXQ9xHeVIUYuSZY1ZyDZ6ZEQNL9b69Zm/yUG4WD0kJv/Co5rRxja5vOhTEKo++0X4uBfXesCiPnbplpLTKn6POR7o7IUbQWuDFttBKlSf0mJDrmtlJKVpE/rkZ0CFc3gSSN34K3J5BiUAs8MctwpKlIrIiBkSq+QKPFR0AvhETetk8WQW6I2W5mTOXwBJqaK5e5E8MhkQbwIEn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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: Hi! [...] > >> Any state I am missing? > > So there is probably state (0) which is 'owned only by the host'. It's a > bit obvious, but I'll make it explicit because it has its importance for > the rest of the discussion. Yes, I treated it as "simply not mapped into the VM". > > And while at it, there are other cases (memory shared/owned with/by the > hypervisor and/or TrustZone) but they're somewhat irrelevant to this > discussion. These pages are usually backed by kernel allocations, so > much less problematic to deal with. So let's ignore those. > >> Which transitions are possible? > > Basically a page must be in the 'exclusively owned' state for an owner > to initiate a share or donation. So e.g. a shared page must be unshared > before it can be donated to someone else (that is true regardless of the > owner, host, guest, hypervisor, ...). That simplifies significantly the > state tracking in pKVM. Makes sense! > >> (1) <-> (2) ? Not sure if the direct transition is possible. > > Yep, not possible. > >> (2) <-> (3) ? IIUC yes. > > Actually it's not directly possible as is. The ballooning procedure is > essentially a (1) -> (0) transition. (We also tolerate (3) -> (0) in a > single hypercall when doing ballooning, but it's technically just a > (3) -> (1) -> (0) sequence that has been micro-optimized). > > Note that state (2) is actually never used for protected VMs. It's > mainly used to implement standard non-protected VMs. The biggest Interesting. > difference in pKVM between protected and non-protected VMs is basically > that in the former case, in the fault path KVM does a (0) -> (1) > transition, but in the latter it's (0) -> (2). That implies that in the > unprotected case, the host remains the page owner and is allowed to > decide to unshare arbitrary pages, to restrict the guest permissions for > the shared pages etc, which paves the way for implementing migration, > swap, ... relatively easily. I'll have to digest that :) ... does that mean that for pKVM with protected VMs, "shared" pages are also never migratable/swappable? > >> (1) <-> (3) ? IIUC yes. > > Yep. > > >>> I agree on all of these and, yes, (3) is the problem for us. We've also >>> been thinking a bit about CoW recently and I suspect the use of >>> vm_normal_page() in do_wp_page() could lead to issues similar to those >>> we hit with GUP. There are various ways to approach that, but I'm not >>> sure what's best. >> >> Would COW be required or is that just the nasty side-effect of trying to use >> anonymous memory? > > That'd qualify as an undesirable side effect I think. Makes sense! > >>> >>>> I'm curious, may there be a requirement in the future that shared memory >>>> could be mapped into other processes? (thinking vhost-user and such things). >>> >>> It's not impossible. We use crosvm as our VMM, and that has a >>> multi-process sandbox mode which I think relies on just that... >>> >> >> Okay, so basing the design on anonymous memory might not be the best choice >> ... :/ > > So, while we're at this stage, let me throw another idea at the wall to > see if it sticks :-) > > One observation is that a standard memfd would work relatively well for > pKVM if we had a way to enforce that all mappings to it are MAP_SHARED. It should be fairly easy to enforce, I wouldn't worry too much about that. > KVM would still need to take an 'exclusive GUP' from the fault path > (which may fail in case of a pre-existing GUP, but that's fine), but > then CoW and friends largely become a non-issue by construction I think. > Is there any way we could enforce that cleanly? Perhaps introducing a > sort of 'mmap notifier' would do the trick? By that I mean something a > bit similar to an MMU notifier offered by memfd that KVM could register > against whenever the memfd is attached to a protected VM memslot. > > One of the nice things here is that we could retain an entire mapping of > the whole of guest memory in userspace, conversions wouldn't require any > additional efforts from userspace. A bad thing is that a process that is > being passed such a memfd may not expect the new semantic and the > inability to map !MAP_SHARED. But I guess a process that receives a I wouldn't worry about the !MAP_SHARED requirement. vhost-user and friends all *must* map it MAP_SHARED to do anything reasonable, so that's what they do. > handle to private memory must be enlightened regardless of the type of > fd, so maybe it's not so bad. > > Thoughts? The whole reason I brought up the guest_memfd+memfd pair idea is that you would similarly be able to do the conversion in the kernel, BUT, you'd never be able to mmap+GUP encrypted pages. Essentially you're using guest_memfd for what it was designed for: private memory that is inaccessible. -- Cheers, David / dhildenb