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 0C0D91AD499 for ; Thu, 20 Jun 2024 14:14:29 +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=1718892871; cv=none; b=TRGQLlEENBdJp/Ifl5NUHmLFlCO04ttn3Fzj+0oHbo3SsxiwxEpKI51lJJ48XVZamlblImKajzApxjrsyrxp5g1MOFScfZUQS118FXLgOxrvgeCTmHimYWom0JjZ2TEC5SidTyR7Q3rsEEpl8RwPNbjQiALDaCHnA14ZnYCwIow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718892871; c=relaxed/simple; bh=+A5n0VgholTG/5KXvYQzlGgbOvrmJOn/c9i4a3yDERw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=CKrk8R5clWeRSN09LirYc9VgL3sNTAQ6Pv2fC6R+FzeIO8aA4IU9wm8YG70Hwz9zdyFsjUndy+YVGXRBuPjtmTUpoGmEQYYy0SOgOhtaHjQGMtOKF8Xl/1vUapJ+eOhOJfT/5Tf8xQgGZwLWsHEj/mYSqJeUFAvCMDv4SO9I8Ug= 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=KMx62eni; 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="KMx62eni" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718892869; 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=8YHhV1KpFjJzx2FPMSuwc2xc9dElDmjLPcw5n3EHpx8=; b=KMx62eniHhXBD1TEQQT7abpZP6J0T1q8TMM23aFtBRFgq3YRpKFMEa968lzz09eOP+PspB DDT9XRSqquiF62b0AEMk5phFH5FB4SDNcL+dqE+5HYOKkQ9Lb7vC1wAgfecHR6L67r0Ap2 +MGGpVP5DL1IIIpmcocuZZJ23wj3GBQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-4QYDSQIlM8SawndemAz1_w-1; Thu, 20 Jun 2024 10:14:27 -0400 X-MC-Unique: 4QYDSQIlM8SawndemAz1_w-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3643d0e3831so738689f8f.0 for ; Thu, 20 Jun 2024 07:14:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718892866; x=1719497666; 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=8YHhV1KpFjJzx2FPMSuwc2xc9dElDmjLPcw5n3EHpx8=; b=ekyvdHK8cIRRwPrD5Pue/VqsUkFG1VOOPeiactr5NRXzUPijNW45qMF/LX7YVXD2ln 7TBCce5hf9/EohV34gJYehEg6T4sh4B9+c+Um8ZUWi5WBtVpoPEZCIsB079eU/p8kZwU cfVMGdJvkmuNnzO10rPP+/le0iYZcKjLTMyP2ehJm6OJyKnZMGv+lLvhfZyppTHyMDJB QMn9BFm323FvBwYRzTyzHGgVh6FcT8qb8gX9Qqt5LexnOU53t7JVjCTYMeOI8wJs03ad 1GFk2qGp9b4qARngJQKC6XlDsrbnNCBpuqMSbYi7jtbdrrWHeTz8MmbC6gfNFkXst5de LG0Q== X-Forwarded-Encrypted: i=1; AJvYcCVPu79dyUVgjZqhTg7rZFLm1OX7dukvie+Whn1IzIWvtBO1ipOBr3EKHvZM+9HG9jI82F3glpaHu5WaCn7H0VtpOlwtF9MTre+IFiqg X-Gm-Message-State: AOJu0YxQcQycrnwxtCm2R7kJK9LO/Rdim4WDWd7hi1FWPk4gMBHUxQJw fwsvY7hijOh1qWOG6ASKbr/FsqBx3QZGT0aVyT9KX9FKBX3AztxPd8cvQFfSMQ8bXejspNJgWKm bNxxIGe6J03JN6C3GJouSi5PsoCn0n3iJ2bE6Si2XD1jlEUEFvNg7E1zbhywJ2Q== X-Received: by 2002:adf:fa49:0:b0:362:c971:d97c with SMTP id ffacd0b85a97d-36319a85fc4mr4043900f8f.63.1718892866388; Thu, 20 Jun 2024 07:14:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjBTFGDhSICBWeqaJ/g+1siYAs4hTMdRuzQ/UcpNoH8Mfb7Z30LbIVlGJzMcwVyzuH8D+uPg== X-Received: by 2002:adf:fa49:0:b0:362:c971:d97c with SMTP id ffacd0b85a97d-36319a85fc4mr4043880f8f.63.1718892865896; Thu, 20 Jun 2024 07:14:25 -0700 (PDT) Received: from ?IPV6:2003:cb:c719:5b00:61af:900f:3aef:3af3? (p200300cbc7195b0061af900f3aef3af3.dip0.t-ipconnect.de. [2003:cb:c719:5b00:61af:900f:3aef:3af3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36387d9b812sm4468939f8f.26.2024.06.20.07.14.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jun 2024 07:14:25 -0700 (PDT) Message-ID: <1ab73f42-9397-4fc7-8e62-2627b945f729@redhat.com> Date: Thu, 20 Jun 2024 16:14:23 +0200 Precedence: bulk X-Mailing-List: linux-kernel@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: Mostafa Saleh Cc: 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, Fuad Tabba , Jason Gunthorpe References: <20240618-exclusive-gup-v1-0-30472a19c5d1@quicinc.com> <7fb8cc2c-916a-43e1-9edf-23ed35e42f51@nvidia.com> <14bd145a-039f-4fb9-8598-384d6a051737@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/63r9WLZY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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 20.06.24 15:08, Mostafa Saleh wrote: > Hi David, > > On Wed, Jun 19, 2024 at 09:37:58AM +0200, David Hildenbrand wrote: >> Hi, >> >> On 19.06.24 04:44, John Hubbard wrote: >>> On 6/18/24 5:05 PM, Elliot Berman wrote: >>>> In arm64 pKVM and QuIC's Gunyah protected VM model, we want to support >>>> grabbing shmem user pages instead of using KVM's guestmemfd. These >>>> hypervisors provide a different isolation model than the CoCo >>>> implementations from x86. KVM's guest_memfd is focused on providing >>>> memory that is more isolated than AVF requires. Some specific examples >>>> include ability to pre-load data onto guest-private pages, dynamically >>>> sharing/isolating guest pages without copy, and (future) migrating >>>> guest-private pages. In sum of those differences after a discussion in >>>> [1] and at PUCK, we want to try to stick with existing shmem and extend >>>> GUP to support the isolation needs for arm64 pKVM and Gunyah. >> >> The main question really is, into which direction we want and can develop >> guest_memfd. At this point (after talking to Jason at LSF/MM), I wonder if >> guest_memfd should be our new target for guest memory, both shared and >> private. There are a bunch of issues to be sorted out though ... >> >> As there is interest from Red Hat into supporting hugetlb-style huge pages >> in confidential VMs for real-time workloads, and wasting memory is not >> really desired, I'm going to think some more about some of the challenges >> (shared+private in guest_memfd, mmap support, migration of !shared folios, >> hugetlb-like support, in-place shared<->private conversion, interaction with >> page pinning). Tricky. >> >> Ideally, we'd have one way to back guest memory for confidential VMs in the >> future. >> >> >> Can you comment on the bigger design goal here? In particular: >> >> 1) Who would get the exclusive PIN and for which reason? When would we >> pin, when would we unpin? >> >> 2) What would happen if there is already another PIN? Can we deal with >> speculative short-term PINs from GUP-fast that could introduce >> errors? >> >> 3) How can we be sure we don't need other long-term pins (IOMMUs?) in >> the future? > > Can you please clarify more about the IOMMU case? > > pKVM has no merged upstream IOMMU support at the moment, although > there was an RFC a while a go [1], also there would be a v2 soon. > > In the patches KVM (running in EL2) will manage the IOMMUs including > the page tables and all pages used in that are allocated from the > kernel. > > These patches don't support IOMMUs for guests. However, I don't see > why would that be different from the CPU? as once the page is pinned > it can be owned by a guest and that would be reflected in the > hypervisor tracking, the CPU stage-2 and IOMMU page tables as well. So this is my thinking, it might be flawed: In the "normal" world (e.g., vfio), we FOLL_PIN|FOLL_LONGTERM the pages to be accessible by a dedicated device. We look them up in the page tables to pin them, then we can map them into the IOMMU. Devices that cannot speak "private memory" should only access shared memory. So we must not have "private memory" mapped into their IOMMU. Devices that can speak "private memory" may either access shared or private memory. So we may have"private memory" mapped into their IOMMU. What I see (again, I might be just wrong): 1) How would the device be able to grab/access "private memory", if not via the user page tables? 2) How would we be able to convert shared -> private, if there is a longterm pin from that IOMMU? We must dynamically unmap it from the IOMMU. I assume when you're saying "In the patches KVM (running in EL2) will manage the IOMMUs including the page tables", this is easily solved by not relying on pinning: KVM just knows what to update and where. (which is a very different model than what VFIO does) Thanks! -- Cheers, David / dhildenb