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 D865816C444 for ; Fri, 21 Jun 2024 07:43:53 +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=1718955835; cv=none; b=X9XRZurg7mXCFZEYDPBh8/XgqwqQrys3xzVF3xxdZptImnaN3Gk5sVPDWj+7zxOCYlzH7RCDQmMgFdP3OgrAKyVGRAfkZBrWt+YNV4y0CN5MUtOtR/70pmlm3gC9nSWcH8TYnAxBZto+dUPA+yQfq00pI9JVsCz1rXSnxzErk1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718955835; c=relaxed/simple; bh=YNBcFfzbWAq+jVZSQczcHRECwRi328adu6VUAsu6zYI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=n3cl59aMTKPualWbj7MGKr4cKFo2Rrq+q9bGAZVWzlr/77q//qvGmnOAAJ1t8IjduqWG8No5252EdeATxh+Ar5RafbF69shpcTUSveatBVGM3effMO5PKtLimnddUTGjlfaoS+2K2ZtZyr8GTIoeX2fZGlR1JN0RFMNwo5HMhsk= 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=DNUuFrNP; 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="DNUuFrNP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718955832; 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=PXQ4efuXmJaBuTYOu/+WHETOQnkAh+ulGBOP07t9dcc=; b=DNUuFrNPvRzjzqAzOG+4HLqaGpu6dfjga7PCgrB8WfR7788Oogb1L6031lGq51Tn+ahQAx 73uYeozoaTAmzcgzQmRyofPyWCbFuVuLMnVxqOaY6EYUWwKtHD5204oZvC4PBbfDcZEmn0 yZZwALRFxlxvLqSK40ClLAT5hKzYoP4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-153-ktAE2IW-Puq3Ws4GltAz4g-1; Fri, 21 Jun 2024 03:43:51 -0400 X-MC-Unique: ktAE2IW-Puq3Ws4GltAz4g-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4217f941ca8so12659645e9.1 for ; Fri, 21 Jun 2024 00:43:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718955830; x=1719560630; 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=PXQ4efuXmJaBuTYOu/+WHETOQnkAh+ulGBOP07t9dcc=; b=UVRt4PkrEH8qXpTk7SkmkJju1MyBcB+WbSNds0/BkpkxLkKT/l8ahQnN2X26DYtGdK qTAu1BvPJe7wg/vj968WEdFSl6TSxIs66Gl6CCddsBxMNpGDPuqgaLJkIotmsAXPVRQH wKGo6Cr2aZ5vl6iybwvrFXuNh2sWjmJw+UGkgYF9wLnebTlEZnBm6c7W5y+smmPTnjOA 4FOqa/cUBR1zCTCn4wFtNQ/0UZ98Nxwqk1YqqPfvl+RRPoaBkgdISZSYEVHDImlkFUr8 ScuoUQFhCWwsJ6zdRI0C/GmPKP24vZhHmSuLgoTuGhY3UONC+uzsS1qz+DTNHuw1z5m5 WI/w== X-Forwarded-Encrypted: i=1; AJvYcCW7862bCF1mZjvDorD1im0NSw7JMd01uL9AyZqpsfHYryX+E4xWgEqyCWOgk3ZtSy7TB4rapPo/4VGzBPwZ0ztxD9a/rstdMYrdQWhmyw== X-Gm-Message-State: AOJu0YxrfEBRQmvuy+zENiH4xWrbpmDARwTtkU5n1M/yNX101ETwPlYA sLy0RMx0nEbwWo2wj28nimzX63GkQ3X4Co0nzw1O7kBMQAJLCSoNpVCML1w2GGrIVB5gTsalU7D C7wBhqRHfdIrb+FyT4/XrUCnEFBzqv/AtJVeHoVvSrad1GkMLpqzvOyRNPUnVeSw= X-Received: by 2002:a05:600c:12d1:b0:420:173f:e1e9 with SMTP id 5b1f17b1804b1-42475183abcmr50829065e9.21.1718955829950; Fri, 21 Jun 2024 00:43:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGFhPCh+f56fSUHi3uGdtrIekqv4PyB9COw2ZzQozbPAmaFpHnj4r7upN+wLk//8erbglA0Q== X-Received: by 2002:a05:600c:12d1:b0:420:173f:e1e9 with SMTP id 5b1f17b1804b1-42475183abcmr50828995e9.21.1718955829516; Fri, 21 Jun 2024 00:43:49 -0700 (PDT) Received: from ?IPV6:2003:cb:c725:e600:4063:2059:fd18:9d65? (p200300cbc725e60040632059fd189d65.dip0.t-ipconnect.de. [2003:cb:c725:e600:4063:2059:fd18:9d65]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0b63d4sm52393385e9.3.2024.06.21.00.43.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Jun 2024 00:43:49 -0700 (PDT) Message-ID: <96df0073-6fde-4252-a9cb-22eeb0a876bb@redhat.com> Date: Fri, 21 Jun 2024 09:43:47 +0200 Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 0/5] mm/gup: Introduce exclusive GUP pinning To: Sean Christopherson , Jason Gunthorpe Cc: Fuad Tabba , Christoph Hellwig , John Hubbard , Elliot Berman , Andrew Morton , Shuah Khan , Matthew Wilcox , maz@kernel.org, kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, pbonzini@redhat.com References: <20240620135540.GG2494510@nvidia.com> <6d7b180a-9f80-43a4-a4cc-fd79a45d7571@redhat.com> <20240620142956.GI2494510@nvidia.com> <385a5692-ffc8-455e-b371-0449b828b637@redhat.com> <20240620163626.GK2494510@nvidia.com> <66a285fc-e54e-4247-8801-e7e17ad795a6@redhat.com> <20240620231133.GN2494510@nvidia.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//bLwzj9IVsaQpKDqW6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di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 21.06.24 01:54, Sean Christopherson wrote: > On Thu, Jun 20, 2024, Jason Gunthorpe wrote: >> On Thu, Jun 20, 2024 at 01:30:29PM -0700, Sean Christopherson wrote: >>> I.e. except for blatant bugs, e.g. use-after-free, we need to be able to guarantee >>> with 100% accuracy that there are no outstanding mappings when converting a page >>> from shared=>private. Crossing our fingers and hoping that short-term GUP will >>> have gone away isn't enough. >> >> To be clear it is not crossing fingers. If the page refcount is 0 then >> there are no references to that memory anywhere at all. It is 100% >> certain. >> >> It may take time to reach zero, but when it does it is safe. > > Yeah, we're on the same page, I just didn't catch the implicit (or maybe it was > explicitly stated earlier) "wait for the refcount to hit zero" part that David > already clarified. > >> Many things rely on this property, including FSDAX. >> >>> For non-CoCo VMs, I expect we'll want to be much more permissive, but I think >>> they'll be a complete non-issue because there is no shared vs. private to worry >>> about. We can simply allow any and all userspace mappings for guest_memfd that is >>> attached to a "regular" VM, because a misbehaving userspace only loses whatever >>> hardening (or other benefits) was being provided by using guest_memfd. I.e. the >>> kernel and system at-large isn't at risk. >> >> It does seem to me like guest_memfd should really focus on the private >> aspect. We'll likely have to enter that domain for clean huge page support and/or pKVM here either way. Likely the future will see a mixture of things: some will use guest_memfd only for the "private" parts and anon/shmem for the "shared" parts, others will use guest_memfd for both. >> >> If we need normal memfd enhancements of some kind to work better with >> KVM then that may be a better option than turning guest_memfd into >> memfd. > > Heh, and then we'd end up turning memfd into guest_memfd. As I see it, being > able to safely map TDX/SNP/pKVM private memory is a happy side effect that is > possible because guest_memfd isn't subordinate to the primary MMU, but private > memory isn't the core idenity of guest_memfd. Right. > > The thing that makes guest_memfd tick is that it's guest-first, i.e. allows mapping > memory into the guest with more permissions/capabilities than the host. E.g. access > to private memory, hugepage mappings when the host is forced to use small pages, > RWX mappings when the host is limited to RO, etc. > > We could do a subset of those for memfd, but I don't see the point, assuming we > allow mmap() on shared guest_memfd memory. Solving mmap() for VMs that do > private<=>shared conversions is the hard problem to solve. Once that's done, > we'll get support for regular VMs along with the other benefits of guest_memfd > for free (or very close to free). I suspect there would be pushback from Hugh trying to teach memfd things it really shouldn't be doing. I once shared the idea of having a guest_memfd+memfd pair (managed by KVM or whatever more genric virt infrastructure), whereby we could move folios back and forth and only the memfd pages can be mapped and consequently pinned. Of course, we could only move full folios, which implies some kind of option b) for handling larger memory chunks (gigantic pages). But I'm not sure if that is really required and it wouldn't be just easier to let the guest_memfd be mapped but only shared pages are handed out. -- Cheers, David / dhildenb