Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp482779rdb; Thu, 2 Nov 2023 09:04:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlPI0c6lcMcP74zJV10YXb2xv3DsdvZWWMv+eExsLkXIn00Ztr3uEF3S45JF+cYk20VuAf X-Received: by 2002:a17:902:a389:b0:1c9:c46c:71fc with SMTP id x9-20020a170902a38900b001c9c46c71fcmr14275074pla.59.1698941059537; Thu, 02 Nov 2023 09:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698941059; cv=none; d=google.com; s=arc-20160816; b=OD7sqyOB77DbCrEwCRN6bsgqxHwTHuuX/ip13GfOeAfpkmih1QgiurZ5BqWXSkagAC u4kBMQIyIkRZbCgt2t67QeFKg0DKE++YP0hKviJcEqhR6gqalF+NCeXOKxd/e4GgLHvI l5965NLM7bZkCq9wgIdVBv3aqlx9eIY9S6x2Dylv7TpYjdIxsJUuztY2HuVvNoy1zz59 +68j0txwoWW4rNTqRFQxY53OEWtWhOhUCJfu+7VkmNSj0k2ICeDXHJAEzm5F8q3/FyML CHS6/Dc7oIDzozfcuXRT29bDZMjyjW4y9Alw2W8OWI3b8sLMqFVpy2JUU+PBfFe6FRNW BdcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=2iqXbuRKMyvTfyAi0R6oHncN26PfYTo3tctDI41vJWU=; fh=DS8a+jPfo4AO5DrfnsssN4rETGYNGL7ghriL4WZYroQ=; b=HOlY9b8VZl9AE31Gg/CSED7LwTSqZs2OF+xsSaEvHxR8/EdqOqGocj+YMH5gPgwBoJ EXNXCl3yxo22KnEwIwGn/1WDc0qPCVpW5AreiJ75oOoV4GZ5D/ekSHtHvFxMWJL6SCyN FfYFDK+2ye6k/ilXoDYnvhTQUSzYi6xNXmGbQf6/vJmeqDrg0mngJPDPcYfE7EneyZne B9jY27x4JBngEPLul4LAFpj49zjo0AjCQx56CBeRkoFulwtm8AaxV/aBMfXMVddxCIcp +qdFO+mSdQcpgfDwHXyrW2y9zW9Pc8aWWHvgpByPVQmYmmxE1SV9Hvb5NLNDSQHXeRMp OIzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TJNOze6k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bj6-20020a170902850600b001cc38a6cb77si79545plb.204.2023.11.02.09.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 09:04:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TJNOze6k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 910EF817C8BE; Thu, 2 Nov 2023 09:04:09 -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 S1377086AbjKBQDu (ORCPT + 99 others); Thu, 2 Nov 2023 12:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234506AbjKBQDs (ORCPT ); Thu, 2 Nov 2023 12:03:48 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 103C512E for ; Thu, 2 Nov 2023 09:03:45 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1cc281f1214so9107485ad.2 for ; Thu, 02 Nov 2023 09:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698941024; x=1699545824; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2iqXbuRKMyvTfyAi0R6oHncN26PfYTo3tctDI41vJWU=; b=TJNOze6kt+FsA9v0I74BIpCjw9fge82sCtaK3cxtT6c0KZEdKSzBh4zG31U+RQGN7+ RBc5D+JpR6UnV3KagOIZh/k0QWAS7g+80tHuxJWkMkRcptC9bydUspTt+ACMT2HAase2 fXKjWpOYXDOWK/pGCUZdZDZUFeL6l0Um/28DOwX4QiyMEnKher3A3Rm80G3S+GZA8zOu 8WeQaicXLIC7Cclvl/uP6/detJrBYWN3Khg0/VrDjV7a/4uhH35JM2byF4Fn7t6fjYJG lcIyR8iLWXR3b1X3wXSx08815FLcwy3qN//DPxL2Py0ry4RP/UvDUbRELdcVSBVZTg4/ g/Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698941024; x=1699545824; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2iqXbuRKMyvTfyAi0R6oHncN26PfYTo3tctDI41vJWU=; b=YXSNODTmPFuW/OAKm0LjdE/Ts8mWTK1U8JRC6xAdpVuYl4Rou2l1jJQgYLfnNZKD6O GKB38Wbfkh2ykoYJeVYpf6ZokemF2Q3YpbJabvR5g4kztFaHAqJ1mtpWBEZGzDW9v1Kq RvvqIRIEKXU/So7HsxQpb7uOWR2JRaKyD3LOC6MX8tWTKPHnjuJu6hRM+sBpFHdHTVkd FeL6HiYpD4+mBPNcUNo4p4KHGaAGsWZTBmZsxUo9BrFyBudMbLDuEy6VgCkjQfGVvBxb nLF8W6xS+86Dt0nzp/BpE9fBag2Hk6Hzv2E6WGCuKvq4ZtfI6wvcAnHFg8vke+UKevJV Qfzw== X-Gm-Message-State: AOJu0Yx5DmhoUZHSMdymvATyzabXpX6ABJYSgFc9DOI0uljyOUZJHovD ThUz+Mbn1Uk305P//z59sooPhR1+oYg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:1304:b0:1cc:2ffe:5a33 with SMTP id iy4-20020a170903130400b001cc2ffe5a33mr266680plb.8.1698941024519; Thu, 02 Nov 2023 09:03:44 -0700 (PDT) Date: Thu, 2 Nov 2023 09:03:42 -0700 In-Reply-To: <6642c379-1023-4716-904f-4bbf076744c2@redhat.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-17-seanjc@google.com> <6642c379-1023-4716-904f-4bbf076744c2@redhat.com> Message-ID: Subject: Re: [PATCH v13 16/35] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory From: Sean Christopherson To: Paolo Bonzini Cc: David Matlack , 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?Q?Micka=C3=ABl_Sala=C3=BCn?=" , 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="us-ascii" 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:04:09 -0700 (PDT) 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 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. I don't see how this can work. It's not a M:1 scenario (where M is multiple gfns), it's a 1:N scenario (wheren N is multiple offsets). The *gfn* doesn't change on a conversion, what needs to change to do non-in-place conversion is the pfn, 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, 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.