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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D2EDC02181 for ; Mon, 20 Jan 2025 17:55:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tZvym-0002Yo-Op; Mon, 20 Jan 2025 12:54:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tZvyj-0002YT-0P for qemu-devel@nongnu.org; Mon, 20 Jan 2025 12:54:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tZvyg-0002Qc-Em for qemu-devel@nongnu.org; Mon, 20 Jan 2025 12:54:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737395660; 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=fYnLdliWSGmaUfugGw8WuUfmfo1s70VQgXIJESgNN48=; b=Qc6wRn+bzd/V1MLNcpc/aSFED38sgsM0hBhScWlovO3ADY2SFrE5VrxWH2F/R9OStE9ZFr gvBC7dinZJFz6+5sHUl+2AOMiNI3HVSEzrlfy7wxXL7WFXLcgFFbDZrxH9HuB5LxipkZIW jLWQ/+rqmGKEeJQ2THzx6vXMO3tI6nk= 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-19-NGadS0k2N2GV0UHRQOT4_Q-1; Mon, 20 Jan 2025 12:54:18 -0500 X-MC-Unique: NGadS0k2N2GV0UHRQOT4_Q-1 X-Mimecast-MFC-AGG-ID: NGadS0k2N2GV0UHRQOT4_Q Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38bf5ef17b2so2706132f8f.0 for ; Mon, 20 Jan 2025 09:54:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737395658; x=1738000458; 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=fYnLdliWSGmaUfugGw8WuUfmfo1s70VQgXIJESgNN48=; b=qn+Pbs1x3ACaOKh9ixS2zcJfVE/2DrV+y9x06VtbYuH8rZZUgvZaaquG1puFWF+Sxw Ukkro+8VPP1fVsXJdrRX8LNYdtLKaiaNXGoZOkAiosceyAnidCTG/S2rY6L/oIZ1/VdL fZPkKcXTTpPeLRzCRVsHAD8OZdojI2qURTj7lUn/W7+LVorMkNFOrVnJL6qT8qMFo7in QaLzaNhpyVVbq4oEfEBo5CSOHXfyl9clJpMC36fIuLgG/IqbmovQunyjhhLiB1xGo42j lRdKmNA4S46nzZLOrTgeITFKt9l2P+isZQUBp7qzWk2fpecb4EVptSUMlShM8E/glU8r uc6Q== X-Forwarded-Encrypted: i=1; AJvYcCX01/2PGbyK9wDxgdhpKK2uJxRQJwP2TAkHywB3dl5Op1yl/UAtQZSf8XYRlvgYNjfXoNtT/y3K8XRx@nongnu.org X-Gm-Message-State: AOJu0YwRBaD7CEchUnvoXifhPe0N9xEbru5/nNJTQHLpf4r8VWXweS+w CKXhoHWeGNVxhRiLNKlOhPwgXYh85/DneY4G04dAN7N2nwhR97sMJlv1EF8d3QGC0pUwnH+q6vm /GTUK9xtRc7C533rGX8oWh+RmvZsdoqhAl+/sPC+4U3ZVccfYH2Xa X-Gm-Gg: ASbGnctvPlMmjFhb9Xa2m6lsOw3d4wyM21jWEQNUDjp0oaz+oDkPUR2o4SoapK/NYwk 5H4TMW0mOFUJTzGtGoAu8IilloYH/AW7bpdGm+6DnE2lrjo1eLsNVHcTV8s2KR4X2LNOFLSHwVf wvCAXerTi45g+PxMBRaIFGA7PSXunc/HSN/f7Wwh0WeOwGIHQ/rLgraCWxEXgWJ7e/CGW3cK3ln zVLY53TPamIFMRBg26kj4ACRA4RdhkKkZhOtbdkHHPjTlv6fCZ+GvrJ3NML9yic7fotaqKowed7 LqNG39bm8zhMjeNPBgmcBx0Yk3COjZqUkvkR3WfHZV/d0z8XwHchRFjnXSB39ekRMU91af+0h0R PoWh/L5aY+aTyGlVrhVsQbw== X-Received: by 2002:a5d:47c8:0:b0:385:df43:2179 with SMTP id ffacd0b85a97d-38bf577ffc2mr12264830f8f.17.1737395657702; Mon, 20 Jan 2025 09:54:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGF0Li6RML8iGqrMyWg8gYDqrWoCDCt83DCHdznRt0Ep3b+Xo0wNqhRBFAzpq1sxVaXzk2Ggg== X-Received: by 2002:a5d:47c8:0:b0:385:df43:2179 with SMTP id ffacd0b85a97d-38bf577ffc2mr12264809f8f.17.1737395657282; Mon, 20 Jan 2025 09:54:17 -0800 (PST) Received: from ?IPV6:2003:cb:c72e:e400:431d:9c08:5611:693c? (p200300cbc72ee400431d9c085611693c.dip0.t-ipconnect.de. [2003:cb:c72e:e400:431d:9c08:5611:693c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c16610a0sm132936005e9.1.2025.01.20.09.54.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jan 2025 09:54:16 -0800 (PST) Message-ID: <7e60d2d8-9ee9-4e97-8a45-bd35a3b7b2a2@redhat.com> Date: Mon, 20 Jan 2025 18:54:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/7] guest_memfd: Introduce an object to manage the guest-memfd with RamDiscardManager To: Peter Xu Cc: Alexey Kardashevskiy , Chenyi Qiang , Paolo Bonzini , =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= , Michael Roth , qemu-devel@nongnu.org, kvm@vger.kernel.org, Williams Dan J , Peng Chao P , Gao Chao , Xu Yilun References: <20241213070852.106092-1-chenyi.qiang@intel.com> <20241213070852.106092-3-chenyi.qiang@intel.com> <80ac1338-a116-48f5-9874-72d42b5b65b4@intel.com> <9dfde186-e3af-40e3-b79f-ad4c71a4b911@redhat.com> 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 WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAub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J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-3, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 20.01.25 18:21, Peter Xu wrote: > On Mon, Jan 20, 2025 at 11:48:39AM +0100, David Hildenbrand wrote: >> Sorry, I was traveling end of last week. I wrote a mail on the train and >> apparently it was swallowed somehow ... >> >>>> Not sure that's the right place. Isn't it the (cc) machine that controls >>>> the state? >>> >>> KVM does, via MemoryRegion->RAMBlock->guest_memfd. >> >> Right; I consider KVM part of the machine. >> >> >>> >>>> It's not really the memory backend, that's just the memory provider. >>> >>> Sorry but is not "providing memory" the purpose of "memory backend"? :) >> >> Hehe, what I wanted to say is that a memory backend is just something to >> create a RAMBlock. There are different ways to create a RAMBlock, even >> guest_memfd ones. >> >> guest_memfd is stored per RAMBlock. I assume the state should be stored per >> RAMBlock as well, maybe as part of a "guest_memfd state" thing. >> >> Now, the question is, who is the manager? >> >> 1) The machine. KVM requests the machine to perform the transition, and the >> machine takes care of updating the guest_memfd state and notifying any >> listeners. >> >> 2) The RAMBlock. Then we need some other Object to trigger that. Maybe >> RAMBlock would have to become an object, or we allocate separate objects. >> >> I'm leaning towards 1), but I might be missing something. > > A pure question: how do we process the bios gmemfds? I assume they're > shared when VM starts if QEMU needs to load the bios into it, but are they > always shared, or can they be converted to private later? You're probably looking for memory_region_init_ram_guest_memfd(). > > I wonder if it's possible (now, or in the future so it can be >2 fds) that > a VM can contain multiple guest_memfds, meanwhile they request different > security levels. Then it could be more future proof that such idea be > managed per-fd / per-ramblock / .. rather than per-VM. For example, always > shared gmemfds can avoid the manager but be treated like normal memories, > while some gmemfds can still be confidential to install the manager. I think all of that is possible with whatever design we chose. The situation is: * guest_memfd is per RAMBlock (block->guest_memfd set in ram_block_add) * Some RAMBlocks have a memory backend, others do not. In particular, the ones calling memory_region_init_ram_guest_memfd() do not. So the *guest_memfd information* (fd, bitmap) really must be stored per RAMBlock. The question *which object* implements the RamDiscardManager interface to manage the RAMBlocks that have a guest_memfd. We either need 1) Something attached to the RAMBlock or the RAMBlock itself. This series does it via a new object attached to the RAMBlock. 2) A per-VM entity (e.g., machine, distinct management object) In case of 1) KVM looks up the RAMBlock->object to trigger the state change. That object will inform all listeners. In case of 2) KVM calls the per-VM entity (e.g., guest_memfd manager), which looks up the RAMBlock and triggers the state change. It will inform all listeners. -- Cheers, David / dhildenb