From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DA09208DA for ; Tue, 30 Jul 2024 10:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722334670; cv=none; b=N9odnML+BhGrKKeb8W1gZNKqIyIzJlAw+KJlD8nr2zpcG4ONlybfZX3ojmTGfMBHGrza9ptk+rZXiqjawnWKHy9HrRqIGlAtP1jyO/DYhiqdBwBzvBwd4s5XHigpjhU2x8wTmFlLwswsJv2nKonv5Ddtiev8+7aG37sT6wWnozE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722334670; c=relaxed/simple; bh=iNcv7NMi5eQwkUBbwceXg1bU0C6jvh9VNi8yqX7p7Ws=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FfZVj2boMAN2V53V/YCo2RDan6//tGxMMT0wK73gg1IUDw3dNrQh2SrzHEF1E438Rns3ctQ2Rn9rVg/cuKJsyUU7lX7wXrlZGUATBgKD4Tb/C2BRw0dbDyT8RGcL3+/wCjs13nPnQM1aTIq6DeKubqCJIwGRCn7WMSAgck8ehX8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JtUTqNJk; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JtUTqNJk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722334667; 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=zHRUb9ZKLORwY2zU7h4UGQhjsrDz/4w8N8RZFuBzYHM=; b=JtUTqNJkvp+eAEMI4GgwXh26EMpH95IB3kz7NaJyalIqV5BAV1dyx/qxfE2TEuP5qeEfoQ 9cc0eUxt1nbOCbfCwuzjzQLgR6vvmXsU6V2XIPpBguOkZxxgCcDYGQvt6/3D8dCK3rDMFn nAWlFrCRW638Q5ude3Fy70FsOEdOXno= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-kdau-ZayOGy6cPq_OHlnmg-1; Tue, 30 Jul 2024 06:17:46 -0400 X-MC-Unique: kdau-ZayOGy6cPq_OHlnmg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4280b119a74so26368735e9.3 for ; Tue, 30 Jul 2024 03:17:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722334665; x=1722939465; 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=zHRUb9ZKLORwY2zU7h4UGQhjsrDz/4w8N8RZFuBzYHM=; b=fq+hvW4FjxTwthyTXG224LdBF1V/Wdj8tGz5hG1ewgYW4I5aj6yUlfGKtjQmtHs30V XsJV+AiIXcQwksmG4yBb4OZs4P2bxwn2nIe3+TVHNuabUlfyn2cIUso/pPyg3VywsN5w zeMlRq+n1Vao2Fh6j8ha5kJx/Jlvx6qArdFarZN11Yb4HHfuIvxzSlV/OvEX64Sr0TU5 9VwIEonkoWxeMv1BFwYNhmWTbkSDlPMvJ7G9+8uBuTM3ZGa0zGQZeMKXNgGlGB1m9Y8a 4HMBdDw+O2wU15W1TnBJQ+Acc0gHaY8SM+7Rxf5HbmQyQmEZkaICOdaSLYON4HmJ59kw fvrg== X-Forwarded-Encrypted: i=1; AJvYcCVFl74dKtyHzuHbuasWfN49O6rqpfySMOmJ4Z3wELsbHar7WaLdr3XvcDmNfAypfBOlvD4el49c5a5TdJB5O4dDAa8802T9J9PhZ+Y6 X-Gm-Message-State: AOJu0YyqqhWPAIrlcgNdRgrzrbxQVv42o3yadvX+1fjw+Yk+HMTlXe7a tDeW8rNC2Rlnzczpm0OST6uV6Cmd2/u8NsvWofZCP8UE0mUAjY5X91jYDawREb3AIeXM0ZOh0eD sToPrDGu5c6Q5EaeXxo6gJsBmpLNYa+kWVwxqkNG6LGKx3LPCRIAdHGd4wfASBQ== X-Received: by 2002:a05:600c:1d1f:b0:424:ad14:6b79 with SMTP id 5b1f17b1804b1-42811d6dbfbmr70600825e9.8.1722334665203; Tue, 30 Jul 2024 03:17:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaV3qdlWbx8GtSBR66ch3gw4ikSw7LdpBZJNqVhSBuZwL0kQOQs9tiBzue/s+Uc3umEEsqRQ== X-Received: by 2002:a05:600c:1d1f:b0:424:ad14:6b79 with SMTP id 5b1f17b1804b1-42811d6dbfbmr70600525e9.8.1722334664689; Tue, 30 Jul 2024 03:17:44 -0700 (PDT) Received: from [192.168.3.141] (p4ff233ea.dip0.t-ipconnect.de. [79.242.51.234]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4280d37bb88sm152794745e9.38.2024.07.30.03.17.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jul 2024 03:17:44 -0700 (PDT) Message-ID: <1195d9ce-3f16-4b11-b6d2-88f593a25e0d@redhat.com> Date: Tue, 30 Jul 2024 12:17:42 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 0/8] Unmapping guest_memfd from Direct Map To: Patrick Roy , "Vlastimil Babka (SUSE)" , seanjc@google.com, pbonzini@redhat.com, akpm@linux-foundation.org, dwmw@amazon.co.uk, rppt@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, willy@infradead.org, graf@amazon.com, derekmn@amazon.com, kalyazin@amazon.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, dmatlack@google.com, tabba@google.com, chao.p.peng@linux.intel.com, xmarcalx@amazon.co.uk References: <20240709132041.3625501-1-roypat@amazon.co.uk> <7e175521-38bb-49f0-b1fb-8820f8708c9c@amazon.co.uk> From: David Hildenbrand Content-Language: en-US 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 WhVhdl0qEYB8lkBEU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Jk+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: <7e175521-38bb-49f0-b1fb-8820f8708c9c@amazon.co.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 26.07.24 08:55, Patrick Roy wrote: > > > On Mon, 2024-07-22 at 13:28 +0100, "Vlastimil Babka (SUSE)" wrote: >>> === Implementation === >>> >>> This patch series introduces a new flag to the `KVM_CREATE_GUEST_MEMFD` >>> to remove its pages from the direct map when they are allocated. When >>> trying to run a guest from such a VM, we now face the problem that >>> without either userspace or kernelspace mappings of guest_memfd, KVM >>> cannot access guest memory to, for example, do MMIO emulation of access >>> memory used to guest/host communication. We have multiple options for >>> solving this when running non-CoCo VMs: (1) implement a TDX-light >>> solution, where the guest shares memory that KVM needs to access, and >>> relies on paravirtual solutions where this is not possible (e.g. MMIO), >>> (2) have KVM use userspace mappings of guest_memfd (e.g. a >>> memfd_secret-style solution), or (3) dynamically reinsert pages into the >>> direct map whenever KVM wants to access them. >>> >>> This RFC goes for option (3). Option (1) is a lot of overhead for very >>> little gain, since we are not actually constrained by a physical >>> inability to access guest memory (e.g. we are not in a TDX context where >>> accesses to guest memory cause a #MC). Option (2) has previously been >>> rejected [1]. >> >> Do the pages have to have the same address when they are temporarily mapped? >> Wouldn't it be easier to do something similar to kmap_local_page() used for >> HIMEM? I.e. you get a temporary kernel mapping to do what's needed, but it >> doesn't have to alter the shared directmap. >> >> Maybe that was already discussed somewhere as unsuitable but didn't spot it >> here. > > For what I had prototyped here, there's no requirement to have the pages > mapped at the same address (I remember briefly looking at memremap to > achieve the temporary mappings, but since that doesnt work for normal > memory, I gave up on that path). However, I think guest_memfd is moving > into a direction where ranges marked as "in-place shared" (e.g. those > that are temporarily reinserted into the direct map in this RFC) should > be able to be GUP'd [1]. I think for that the direct map entries would > need to be present, right? Yes, we'd allow GUP. Of course, one could think of a similar extension like secretmem that would allow shared memory to get mapped into user page tables but would disallow any GUP on (shared) guest_memfd memory. -- Cheers, David / dhildenb