Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp473322rdb; Thu, 2 Nov 2023 08:50:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBSxDel1Fi6rVKKA2WWPROfJPtEdiEWZb4rTjhZSmEUiGjX5rel7AcoTX/6IuZvwa3KrND X-Received: by 2002:a17:90b:1a89:b0:280:6e68:a5a8 with SMTP id ng9-20020a17090b1a8900b002806e68a5a8mr10096927pjb.22.1698940224455; Thu, 02 Nov 2023 08:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698940224; cv=none; d=google.com; s=arc-20160816; b=g+rycRCu0yy/82YVMhFFqyFg3V08wl3qQQ2E5N2oHZTKmJTHl/9CmFsO41YEimeNNW V3GvW9Y8EjlmGQJ2njUdDiYC3nS5NjN2cYD0Ld6yU017zUeqcVYL1/nI3qENBVLujt5R j4JX8Ml38dluSKTCJY2NVYlyFWyIqZJNXvYRq1aKB/kH00kTliaAehs1lVdf6LhTZ4D0 0Pr4Hr9yw5XMhttwDPZB0vmRa1aOlopTunsZ2SjJvWAMl5O6/bSsceFU0BBV0ucBNVa2 bnda9q/55D6BEYHsd+OdGx9dU4IDrChQVN1oyV2varDTdnv7jkP++ps0PQ+bIVI8QQ1F mfRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=bDYfxJY1gaw7RnFMn6xzv+L48r7jo/5hW3rLClryTog=; fh=AhhuH5qfw5q3UqZ2AungJq7S3hjA7+BaQ1QPXWDQYQI=; b=qlEn7liPc6i4L4G0CumXxvZ+RXZQfX0X3iLOVUkZEbeHdVTKGJYL4wqi9gkRYcDq0M RLRCLPIszmEdNXFpRqPBjB4I7ODzEInBSwfpreSi1k+wkCF/OuiBoaTujgm+ovy4UnAI BTgHfO9A6SkgvpUTTjfgcZP/6gFTX7B/zbByzFJ7sKwM54YB4ercV1clv2E2MNWE0hbG Hfo5qf0bZV6l2hjMoe79Nxtt9t6+17evd2jfDCniPDvLEvvekyoSBX1HbSgo6un5bl1x JSDvIlQhdvkmdWPKIVyoLcmP56q+JFJC2Nu3/bOaHTdop4qnox3GU1uDDX6GYTg9snQP NkTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TcBZMnGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id w5-20020a17090aad4500b0027da95531c9si35023pjv.134.2023.11.02.08.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 08:50:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TcBZMnGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 02CD38119045; Thu, 2 Nov 2023 08:50:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376569AbjKBPtp (ORCPT + 99 others); Thu, 2 Nov 2023 11:49:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377065AbjKBPtn (ORCPT ); Thu, 2 Nov 2023 11:49:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A36185 for ; Thu, 2 Nov 2023 08:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698940133; 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=bDYfxJY1gaw7RnFMn6xzv+L48r7jo/5hW3rLClryTog=; b=TcBZMnGmsYbQrpoA8QaEmyVl47Go9IXo/HBge6ljOO82iM2iuRC+Ya+kU044qMswnBP2oE qlj5AGEe9GI2b7rI4vB6fxVqlD8HSLhxC5/124COl2f8QeW9agBJBRD0S/RBqp4pnrPlSm LmfkxWbDNS4XHPLvda5efkkuvG8AdhM= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-2NegdT8qNsuD43czfgBd_A-1; Thu, 02 Nov 2023 11:48:51 -0400 X-MC-Unique: 2NegdT8qNsuD43czfgBd_A-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-77a3fb5b214so113533185a.1 for ; Thu, 02 Nov 2023 08:48:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698940131; x=1699544931; h=content-transfer-encoding:in-reply-to: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=bDYfxJY1gaw7RnFMn6xzv+L48r7jo/5hW3rLClryTog=; b=N1JridbvnGcuwx2Fyo0UFHGbWPnLXvr6tFwfnskXcYsIeLqJt3t2nTXoryfb9kR2MR Vb/jOE9SGr3dmzFE7FxLEgDRUBKQNZE1P6c3BLDwyj8Zc6Fu3hjDqIJ5WGaRQUrbFJsT x7TfwAHZRpV0NuasWXrEFH8RfgHN9647KfJJGczAckZcibw9aB59bxJ8TwAqRvdDcfbj MPW8t+hxPhDaCnZ/pIhc0SG+Nh2tXS/Vg9Cb9toodbAI0eGozCBgMeM5aKkFQUCMWMho BPdT/La3d7lak+t4CynNKvp36r0DPB+A1i5nJv5zzKKD92ap+ANItxNEDzEKRreAG2eg K1DQ== X-Gm-Message-State: AOJu0Yw/nsEciCZhsgO3uu5tpYAkfRMZjrmEEN61WPXY7qHg7STENF6k XVpLlQqleqPqK6jarU+zX1RSsWmR8wBhmYNttePcXiIO7wuIq8jur6Ca+5IByR7FBgFc9fmN7ad j1qlteJdhO1azWqRDqVv1qXxS X-Received: by 2002:a05:620a:8404:b0:76f:456:3916 with SMTP id pc4-20020a05620a840400b0076f04563916mr16196046qkn.43.1698940131021; Thu, 02 Nov 2023 08:48:51 -0700 (PDT) X-Received: by 2002:a05:620a:8404:b0:76f:456:3916 with SMTP id pc4-20020a05620a840400b0076f04563916mr16196036qkn.43.1698940130729; Thu, 02 Nov 2023 08:48:50 -0700 (PDT) Received: from [192.168.1.174] ([151.48.250.237]) by smtp.googlemail.com with ESMTPSA id m2-20020a05620a290200b00767da10efb6sm39016qkp.97.2023.11.02.08.48.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Nov 2023 08:48:50 -0700 (PDT) Message-ID: <6642c379-1023-4716-904f-4bbf076744c2@redhat.com> Date: Thu, 2 Nov 2023 16:48:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v13 16/35] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory Content-Language: en-US To: David Matlack , Sean Christopherson Cc: Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8?= =?UTF-8?Q?n?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-17-seanjc@google.com> From: Paolo Bonzini Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSOdw5F5Utxfp1wOjD/v92Lrax0hjiX DResHSt48q+8FrZzY+AUbkUS+Jm34qjswdrgsC5uxeVcLkBgWLmov2kMaMROT0YmFY6A3m1S P/kXmHDXxhe23gKb3dgwxUTpENDBGcfEzrzilWueOeUWiOcWuFOed/C3SyijBx3Av/lbCsHU Vx6pMycNTdzU1BuAroB+Y3mNEuW56Yd44jlInzG2UOwt9XjjdKkJZ1g0P9dwptwLEgTEd3Fo UdhAQyR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VEEVGSRF m8dgkcJDB7Tps0IkNrUi4yof3B3shR+vMY3i3Ip0e41zKx0CvlAhMOo6otaHmcxr35sWq1Jk tLkbn3wG+fPQCVudJJECvVQ//UAthSSEklA50QtD2sBkmQ14ZryEyTHQ+E42K3j2IUmOLriF dNr9NvE1QGmGyIcbw2NIVEBOK/GWxkS5+dmxM2iD4Jdaf2nSn3jlHjEXoPwpMs0KZsgdU0pP JQzMUMwmB1wM8JxovFlPYrhNT9MAEQEAAcLBMwQYAQIACQUCVEJx7gIbDAAKCRB+FRAMzTZp sadRDqCctLmYICZu4GSnie4lKXl+HqlLanpVMOoFNnWs9oRP47MbE2wv8OaYh5pNR9VVgyhD OG0AU7oidG36OeUlrFDTfnPYYSF/mPCxHttosyt8O5kabxnIPv2URuAxDByz+iVbL+RjKaGM GDph56ZTswlx75nZVtIukqzLAQ5fa8OALSGum0cFi4ptZUOhDNz1onz61klD6z3MODi0sBZN Aj6guB2L/+2ZwElZEeRBERRd/uommlYuToAXfNRdUwrwl9gRMiA0WSyTb190zneRRDfpSK5d usXnM/O+kr3Dm+Ui+UioPf6wgbn3T0o6I5BhVhs4h4hWmIW7iNhPjX1iybXfmb1gAFfjtHfL xRUr64svXpyfJMScIQtBAm0ihWPltXkyITA92ngCmPdHa6M1hMh4RDX+Jf1fiWubzp1voAg0 JBrdmNZSQDz0iKmSrx8xkoXYfA3bgtFN8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 02 Nov 2023 08:50:22 -0700 (PDT) On 10/31/23 23:39, David Matlack wrote: >>> Maybe can you sketch out how you see this proposal being extensible to >>> using guest_memfd for shared mappings? >> For in-place conversions, e.g. pKVM, no additional guest_memfd is needed. What's >> missing there is the ability to (safely) mmap() guest_memfd, e.g. KVM needs to >> ensure there are no outstanding references when converting back to private. >> >> For TDX/SNP, assuming we don't find a performant and robust way to do in-place >> conversions, a second fd+offset pair would be needed. > Is there a way to support non-in-place conversions within a single guest_memfd? For TDX/SNP, you could have a hook from KVM_SET_MEMORY_ATTRIBUTES to guest memory. The hook would invalidate now-private parts if they have a VMA, causing a SIGSEGV/EFAULT if the host touches them. It would forbid mappings from multiple gfns to a single offset of the guest_memfd, because then the shared vs. private attribute would be tied to the offset. This should not be a problem; for example, in the case of SNP, the RMP already requires a single mapping from host physical address to guest physical address. Paolo