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 55DC9C47DD9 for ; Wed, 28 Feb 2024 13:01:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C2846B0082; Wed, 28 Feb 2024 08:01:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 872CA6B0085; Wed, 28 Feb 2024 08:01:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69D946B0087; Wed, 28 Feb 2024 08:01:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 56D386B0082 for ; Wed, 28 Feb 2024 08:01:03 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8A62941011 for ; Wed, 28 Feb 2024 13:01:02 +0000 (UTC) X-FDA: 81841222764.16.01165F9 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 123ABC0026 for ; Wed, 28 Feb 2024 13:00:57 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PAVrqzcM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709125258; 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=MUWm0cXW6yvbU9b2WCasL+WpCJTeaRlO8Yy7Zz3dmv8=; b=y+R2Z85xdB6l2h5eCHOrF8U9YaCuh93SXo60JRIjkHzqIToOwurQXSTPdQGib/5rLOGsqJ Tt0QCXgWgdTPhhouWhwTcy54A3MdMYe08h/MFysDcs+bjKT63r76SSm1ScX7WbNz2SsAu2 bo1LUqpqBJdNvrvkZSO15KrYSIT3/dI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PAVrqzcM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709125258; a=rsa-sha256; cv=none; b=UNKPWe46BlVEKVjbzZiMQcT8u7RmaN7F5YqDyBalulNycrIUI9rh4mUXTzoswypqmC3cpJ ZDUTI+6qH0B34rCKvQnojHBDvHLajCmxkLQ5KxqPKNHMzvXfg5FhkvkobV7sNV/2i0YwP8 2cOZaCrdeefT2tsoT9D7MvwPjrQtaxA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709125257; 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=MUWm0cXW6yvbU9b2WCasL+WpCJTeaRlO8Yy7Zz3dmv8=; b=PAVrqzcM2i6I14pHzp7yG8F9nhczfqaGh1yRtM/nm1nGEiV0ZHknYrznDoTxrEUrRF8Fng Db36pBTQxumTMd1LPNlzknrNEBGoNGLponFzTqlO5/NLBwzm9H0m69TWe5be5+kNG61VTg Cn04MZJUqgS0d9Qjx9kk3RhPO73AWqg= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-nq1BhCOWOsWi7Ndeg6nbUw-1; Wed, 28 Feb 2024 08:00:55 -0500 X-MC-Unique: nq1BhCOWOsWi7Ndeg6nbUw-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a3ec1d8b1e2so297196966b.3 for ; Wed, 28 Feb 2024 05:00:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709125254; x=1709730054; 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=MUWm0cXW6yvbU9b2WCasL+WpCJTeaRlO8Yy7Zz3dmv8=; b=pKSQzOioCYmjDDwZDAyylLAoFphlmckDU8bVWp7WiTun9Mqzg+klqOvb9XGMMUbkPl Sc1SjWJNXrv5+YMUCrWv7MKGLGqM7hoHe7IYVWukzJO1wk+zj7JUFosgXXWvKdsAQD3e LRVRial2sOL1eXwQNcKZ7T3PnTHO9mFiJyAIrKSuxISkuizvl33ztUildSeufrYZuJ5K 94hrsKI6ufbSjvaRuJNMV7bkWerJjAc2wnhY3yeCxj6A/2xxdWwol3cg3B8ylx87BAA5 YdI2gS/Fl+jFX4LtMMs8bak4vfXtCAN77DZb2+1kb7+PlFGTwVFu8yUGn4EkBav8Yu6E f7tg== X-Forwarded-Encrypted: i=1; AJvYcCX3NDOUEderxRLRQrHzG6V67fe/ix524yeEyQLfN/wE3TeAliGqHteUfrR2EIzRp6aimC4fH34J/iZPLbO5o6hfl8w= X-Gm-Message-State: AOJu0YwZJqbkhEwtY8Z3qcwkfBMEnrIkepMxCkJbJZuP0XVUHddN7hkx 42uP+5BC7ARsjO97g/is4y9oaTUTEl5MgzusUyAuNAPfiX4WyWq9dRFJkoOLXQ2XCHhNRVqWN5e ko+X/6iuG2NI7XEuwWXVhqGQIIpsJJFkfjMfsoM3hvcyl0DD/ X-Received: by 2002:a17:906:f2d1:b0:a43:f924:d52 with SMTP id gz17-20020a170906f2d100b00a43f9240d52mr1147098ejb.70.1709125254489; Wed, 28 Feb 2024 05:00:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcFqIhn5CwyQE2cGmYGkiHNS+VGwIl7vCt3bGJg37Td5Ss4WzLUnP5DpaQBmMmvYXWclZ4gQ== X-Received: by 2002:a17:906:f2d1:b0:a43:f924:d52 with SMTP id gz17-20020a170906f2d100b00a43f9240d52mr1147042ejb.70.1709125253890; Wed, 28 Feb 2024 05:00:53 -0800 (PST) Received: from [10.32.64.237] (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id w9-20020a1709061f0900b00a3e4fc3919esm1828862ejj.31.2024.02.28.05.00.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Feb 2024 05:00:53 -0800 (PST) Message-ID: <99a94a42-2781-4d48-8b8c-004e95db6bb5@redhat.com> Date: Wed, 28 Feb 2024 14:00:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: folio_mmapped To: Quentin Perret Cc: 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, seanjc@google.com, 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, vannapurve@google.com, 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, will@kernel.org, keirf@google.com, linux-mm@kvack.org References: <20240222161047.402609-1-tabba@google.com> <20240222141602976-0800.eberman@hu-eberman-lv.qualcomm.com> <40a8fb34-868f-4e19-9f98-7516948fc740@redhat.com> <20240226105258596-0800.eberman@hu-eberman-lv.qualcomm.com> <925f8f5d-c356-4c20-a6a5-dd7efde5ee86@redhat.com> <755911e5-8d4a-4e24-89c7-a087a26ec5f6@redhat.com> 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/pT4wJCfxwocmqaRr6UY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H9pum9PuoE/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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 123ABC0026 X-Stat-Signature: 48dpdnr7bdsq9gc9q6tbdjnshahsym4e X-HE-Tag: 1709125257-981 X-HE-Meta: U2FsdGVkX19EJA4vZfplHWPzQF6/utUjgZ2g8oFwO+k7GnGmTOQ9q7l5FtTwuHF85tQJ2zDgBvCvnBcylCsVZ+pQaQtgfSO5VdTOdOz23tF5W6INGWjR7N5IFlu11n0GELxaMbS/PwEYSR1jOMy2SVXcug80oaw/eL9A5acyagpZ4myiKWM3gnh4w86bPJgGETitCX/KIgfJz7v4NAUOx9oWpz9iv5NQFa+o8ISeO3oAnqAj2CxCLjPoHt4TqQ5IvRFcao3PSd0ur8y0GEVNkeomkjMF2+j3DhnxYmhuKb90Y8tRtVN+jAYFpykEd75z45DxJfVhvzMfv2vw42ZAYNibhSdV1c23Lf0LWFIDjATp9lTa/aH1SsYkCG4w7gcdG9hi09dB7fu/ihjvUC6NVZIkWtnjcowwhk0GRK2XfeuQNm2vQniEPg6OzD4I6aW1UNSg2+tqrFq9i4uElSGUQjwlUVbPIuRYq0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-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: >>> To add a layer of paint to the shed, the usage of SIGBUS for >>> something that is really a permission access problem doesn't feel >> >> SIGBUS stands for "BUS error (bad memory access)." >> >> Which makes sense, if you try accessing something that can no longer be >> accessed. It's now inaccessible. Even if it is temporarily. >> >> Just like a page with an MCE error. Swapin errors. Etc. You cannot access >> it. >> >> It might be a permission problem on the pKVM side, but it's not the >> traditional "permission problem" as in mprotect() and friends. You cannot >> resolve that permission problem yourself. It's a higher entity that turned >> that memory inaccessible. > > Well that's where I'm not sure to agree. Userspace can, in fact, get > back all of that memory by simply killing the protected VM. With the Right, but that would likely "wipe" the pages so they can be made accessible again, right? That's the whole point why we are handing the pages over to the "higher entity", and allow someone else (the VM) to turn them into a state where we can no longer read them. (if you follow the other discussion, it would actually be nice if we could read them and would get encrypted content back, like s390x does; but that's a different discussion and I assume pretty much out of scope :) ) > approach suggested here, the guestmem pages are entirely accessible to > the host until they are attached to a running protected VM which > triggers the protection. It is very much userspace saying "I promise not > to touch these pages from now on" when it does that, in a way that I > personally find very comparable to the mprotect case. It is not some > other entity that pulls the carpet from under userspace's feet, it is > userspace being inconsistent with itself that causes the issue here, and > that's why SIGBUS feels kinda wrong as it tends to be used to report > external errors of some sort. I recall that user space can also trigger SIGBUS when doing some mmap()+truncate() thingies, and probably a bunch more, that could be fixed up later. I don't see a problem with SIUGBUS here, but I do understand your view. I consider the exact signal a minor detail, though. > >>> appropriate. Allocating memory via guestmem and donating that to a >>> protected guest is a way for userspace to voluntarily relinquish access >>> permissions to the memory it allocated. So a userspace process violating >>> that could, IMO, reasonably expect a SEGV instead of SIGBUS. By the >>> point that signal would be sent, the page would have been accounted >>> against that userspace process, so not sure the paging examples that >>> were discussed earlier are exactly comparable. To illustrate that >>> differently, given that pKVM and Gunyah use MMU-based protection, there >>> is nothing architecturally that prevents a guest from sharing a page >>> back with Linux as RO. >> >> Sure, then allow page faults that allow for reads and give a signal on write >> faults. >> >> In the scenario, it even makes more sense to not constantly require new >> mmap's from user space just to access a now-shared page. >> >>> Note that we don't currently support this, so I >>> don't want to conflate this use case, but that hopefully makes it a >>> little more obvious that this is a "there is a page, but you don't >>> currently have the permission to access it" problem rather than "sorry >>> but we ran out of pages" problem. >> >> We could user other signals, at least as the semantics are clear and it's >> documented. Maybe SIGSEGV would be warranted. >> >> I consider that a minor detail, though. >> >> Requiring mmap()/munmap() dances just to access a page that is now shared >> from user space sounds a bit suboptimal. But I don't know all the details of >> the user space implementation. > > Agreed, if we could save having to mmap() each page that gets shared > back that would be a nice performance optimization. > >> "mmap() the whole thing once and only access what you are supposed to >> access" sounds reasonable to me. If you don't play by the rules, you get a >> signal. > > "... you get a signal, or maybe you don't". But yes I understand your > point, and as per the above there are real benefits to this approach so > why not. > > What do we expect userspace to do when a page goes from shared back to > being guest-private, because e.g. the guest decides to unshare? Use > munmap() on that page? Or perhaps an madvise() call of some sort? Note > that this will be needed when starting a guest as well, as userspace > needs to copy the guest payload in the guestmem file prior to starting > the protected VM. Let's assume we have the whole guest_memfd mapped exactly once in our process, a single VMA. When setting up the VM, we'll write the payload and then fire up the VM. That will (I assume) trigger some shared -> private conversion. When we want to convert shared -> private in the kernel, we would first check if the page is currently mapped. If it is, we could try unmapping that page using an rmap walk. Then, we'd make sure that there are really no other references and protect against concurrent mapping of the page. Now we can convert the page to private. As we want to avoid the rmap walk, user space can be nice and simply MADV_DONTNEED the shared memory portions once it's done with it. For example, after writing the payload. Just a thought, maybe I am missing some details. -- Cheers, David / dhildenb