Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp499418rdb; Thu, 2 Nov 2023 09:29:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGV/pQR7gB8+fK0dp2Ezfoyfjc0uWVQ6fAPwNKmf39AzQvjOK7Ag3Y8dbf2Oox5e/Y0rrky X-Received: by 2002:a17:90b:3449:b0:27d:3f08:cc21 with SMTP id lj9-20020a17090b344900b0027d3f08cc21mr18078563pjb.5.1698942548751; Thu, 02 Nov 2023 09:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698942548; cv=none; d=google.com; s=arc-20160816; b=UT5I8dLN4FPPqg6kMLBpXWuj2fmMKWFpmyQRKTJSbO1431smBBstFFIWImCrnM5tqk cAAntlI16FRbgLF5PHOWWMzBZhFPAVdWQEpwkCub4Vk7iAH9aD9OO3q1e7sbvP+cbScT VQKvx6GAWtTGJghsg2+iA+IV/AalW2Z3AV7xGW88yxxXqgLZISuN74YYfEPlKWn1UG3+ tXtH3vSRuTk08sXpnf7RU12aCJoek8TYSMoJhcPbj6odXFqkHbyW+7gbRfTdARYwguk6 qwr6kygqdAivzFX8Mh460ByhQGRVCrMa7PRUnwFrGPGJwjkyKlf8MwweLn88CHuduW/I pCCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=20owt2l3/cxGLzLA2xbevoL+xSQuNASMB596X3+ow7c=; fh=qdyjXyB1NmbWuUvP2GQHevOARl2q6dCcNPNdvYweWg0=; b=qbS7nDR8MxQeglSyURm0l6VOo021Kz+CttVaUzYayw/SepQeyKgX/Py/HxEVGbjTvj no/Fc7ck2DWDnFXZ2b/FOaIWnJsf+qkWApCvI38kvU8bjsYkm8b1MOk5KmHlFYX9vRSa z7vA03vA0kzETb9e+rx8islhnz8dsWdQJVoCJNoN5TSZX9XK4mbygU7tjJha3qnzX1kR HXL1Q4h6fklB9wZiQ5dekapEFeOD1AAjsseCwfzrgE8boOg1GSMFUVRpwAUKt0JEVMFn l/oMqO8dTEr9vaL2IGCU5LrAfGA5QkpAxb2mWUoqrjFel2XkB8JijXDmztmLQ+xkvDMX 4O5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="iP3n4d/O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id nv7-20020a17090b1b4700b00278f81e54cdsi126310pjb.19.2023.11.02.09.29.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 09:29:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="iP3n4d/O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 73D4B8184502; Thu, 2 Nov 2023 09:29:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229458AbjKBQ3B (ORCPT + 99 others); Thu, 2 Nov 2023 12:29:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376933AbjKBQ26 (ORCPT ); Thu, 2 Nov 2023 12:28:58 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADCA512D for ; Thu, 2 Nov 2023 09:28:54 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-32fb1c35fe0so200737f8f.1 for ; Thu, 02 Nov 2023 09:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698942533; x=1699547333; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=20owt2l3/cxGLzLA2xbevoL+xSQuNASMB596X3+ow7c=; b=iP3n4d/OPngbE98wbRDR3NysfZjhFfYHlQVQlVBVc9y+2/IJSvqtZz866SXw/mX+/e W0pJF0hWV7u78rKyEJP7X+RqylVKogh2sx+8h9p7boqcoyUCTkc5limXF7CmLJDfcO64 ZVrNM92P6dDLOSAV+cQzWAkB0Oi1ZUWaebe4LyULhZgDomckhwu5VVQTDzeOX4bgRpgA /0tUSYkqtqp21tSUpv2QVc+s8tqJQkzTBfAXMfgsTGtf7UpIn7H/jiKHA6oIQEXZVTaZ Cs+HgkrMeohH6Yri08aBNMoVe4FgY5Dfy/Og6XJljrTyIxyihRg7OtaXxruVXMlYQ06a MXjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698942533; x=1699547333; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=20owt2l3/cxGLzLA2xbevoL+xSQuNASMB596X3+ow7c=; b=jjasPjge1w06g73XKzjw1W1U9lJFKmU81H6CUvCIF8naIwm7g6dgVpUDxetrUUi5m9 LnW2/oF3OWCmi7kPWTt3cB0tMdGd5a7fV5g2E0ZeJj2NHJqjXJeYZuDjkeOqG3b3EOOI jqY5vSduCabpw5hPgRvifwZr+18sIdiFxSOXsb1noawaiMswPOBB1NDHOJW0mYDM6GPH WlZMbdJS/MkqV7UZMcARSMZ/2B/RuN/lvQKr+c3HvFkjlyKg5GPtDjOLHSzRrHpp3hxC a8FY4nrBMzzuTwTp1muoE/t89/g/hu92B0A8V6v1O5Vwj9GqwBLjGvxqeGs8q26Uzu+O MKAg== X-Gm-Message-State: AOJu0Yzj/nSaZP1sSdiY+uzFd4hMH47qkK5zwn3KLv07dYMHXva4XI7c VpQgsyNmmvMayaVsI7pYw0PoZ5E6u8eHmzmOjQ/jkA== X-Received: by 2002:a5d:4b51:0:b0:32d:8e54:29f6 with SMTP id w17-20020a5d4b51000000b0032d8e5429f6mr14415276wrs.47.1698942532901; Thu, 02 Nov 2023 09:28:52 -0700 (PDT) MIME-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-17-seanjc@google.com> <6642c379-1023-4716-904f-4bbf076744c2@redhat.com> In-Reply-To: From: David Matlack Date: Thu, 2 Nov 2023 09:28:23 -0700 Message-ID: Subject: Re: [PATCH v13 16/35] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory To: Sean Christopherson Cc: Paolo Bonzini , 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?TWlja2HDq2wgU2FsYcO8bg==?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 09:29:06 -0700 (PDT) On Thu, Nov 2, 2023 at 9:03=E2=80=AFAM Sean Christopherson wrote: > > On Thu, Nov 02, 2023, Paolo Bonzini wrote: > > On 10/31/23 23:39, David Matlack wrote: > > > > > Maybe can you sketch out how you see this proposal being extensib= le to > > > > > using guest_memfd for shared mappings? > > > > For in-place conversions, e.g. pKVM, no additional guest_memfd is n= eeded. What's > > > > missing there is the ability to (safely) mmap() guest_memfd, e.g. K= VM 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 gu= est_memfd? > > > > For TDX/SNP, you could have a hook from KVM_SET_MEMORY_ATTRIBUTES to gu= est > > 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 tie= d 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. > > I don't see how this can work. It's not a M:1 scenario (where M is multi= ple gfns), > it's a 1:N scenario (wheren N is multiple offsets). The *gfn* doesn't ch= ange on > a conversion, what needs to change to do non-in-place conversion is the p= fn, which > is effectively the guest_memfd+offset pair. > > So yes, we *could* support non-in-place conversions within a single guest= _memfd, > but it would require a second offset, Why can't KVM free the existing page at guest_memfd+offset and allocate a new one when doing non-in-place conversions? > at which point it makes sense to add a > second file descriptor as well. Userspace could still use a single guest= _memfd > instance, i.e. pass in the same file descriptor but different offsets.