From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C75B8C07E9D for ; Mon, 26 Sep 2022 16:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235890AbiIZQGh (ORCPT ); Mon, 26 Sep 2022 12:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234696AbiIZQGC (ORCPT ); Mon, 26 Sep 2022 12:06:02 -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 0B68324F for ; Mon, 26 Sep 2022 07:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664204032; 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; bh=JiDPhoXeiEYDPNNsZkNx5skNUhZVDc2YhX8tUxT6Z4I=; b=fI80kL3/xNroi1iv9ML+QqXqRM6pfZryDUAxfezu/H83BgdaDWMvCh6E0tui6c1VXdyydw P9+XKmPphByjuKYf+qJNW57bK7K4IcbSyxyvPtnx4boaNQdfiOaeXwFevfbE8OiBfIm6gQ 7YB0vMCUW7GfVzLgpmXcBU1JcWT+MBc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-441-J11LbTknMRejY-Kem5zGkg-1; Mon, 26 Sep 2022 10:53:41 -0400 X-MC-Unique: J11LbTknMRejY-Kem5zGkg-1 Received: by mail-wr1-f72.google.com with SMTP id x1-20020adfbb41000000b0022b113add45so1273984wrg.10 for ; Mon, 26 Sep 2022 07:53:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=JiDPhoXeiEYDPNNsZkNx5skNUhZVDc2YhX8tUxT6Z4I=; b=Nh3RPu4EAEfTdqcga23wQurGgUYl8Jn8g4LE7k8jXo7CMaXSWGrIrZGrJfMMDuZx2P 2Nl3/to8SVV3cEJ47mpbcbUZQkuawaKmHpkc4pCBxtWt2j3Y4SpFChEO7O6KVoZSOBqt b9Pjr5/gVNh9+nOKOsNIRRVW/YOtvBpP3XVnp00t5tWm5A7PRuBxdd1JWkYrs8DlDAHH RBz6caAbVmW1RTNsElRqmT9AEL/ioVidd1FlVpfk+1r1Ul5Ntw3GpQNAxo1NdIY2Oj8Q 6uF4hDFD3efc6NBOU7uNKuEu+Isgh0z2PeiU5CAt5JpJ8jBHjn1by4QUaNwunVOZVPez ngGA== X-Gm-Message-State: ACrzQf0diwhldc4ObHj+DxO9HWIyNRaTbu4YvYXmBRl4m1zWc0GVM3/p xZB7gJCbGYE3O/zehU14q+Y96indFc83yOqWjNJWr7SRn+nX9WAuQovbAOsW+m8yx5DLGd9Odmu Ix9h4PHEFCqW2u6oDXRw0 X-Received: by 2002:a05:600c:a07:b0:3ab:945:77c4 with SMTP id z7-20020a05600c0a0700b003ab094577c4mr22424181wmp.97.1664204020678; Mon, 26 Sep 2022 07:53:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4F1aj6dFmsu9oiMooh87XJHOqSDiWx3ICISxNlRpzSCeG1iwk0ewGaZ3Lrv8KXjMX88Z1kZg== X-Received: by 2002:a05:600c:a07:b0:3ab:945:77c4 with SMTP id z7-20020a05600c0a0700b003ab094577c4mr22424160wmp.97.1664204020377; Mon, 26 Sep 2022 07:53:40 -0700 (PDT) Received: from ?IPV6:2003:cb:c703:4b00:e090:7fa6:b7d6:d4a7? (p200300cbc7034b00e0907fa6b7d6d4a7.dip0.t-ipconnect.de. [2003:cb:c703:4b00:e090:7fa6:b7d6:d4a7]) by smtp.gmail.com with ESMTPSA id r64-20020a1c4443000000b003b4935f04a4sm13954042wma.5.2022.09.26.07.53.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Sep 2022 07:53:39 -0700 (PDT) Message-ID: <0a99aa24-599c-cc60-b23b-b77887af3702@redhat.com> Date: Mon, 26 Sep 2022 16:53:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH v8 1/8] mm/memfd: Introduce userspace inaccessible memfd Content-Language: en-US To: "Kirill A. Shutemov" Cc: "Kirill A . Shutemov" , Paolo Bonzini , Sean Christopherson , Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com References: <20220915142913.2213336-1-chao.p.peng@linux.intel.com> <20220915142913.2213336-2-chao.p.peng@linux.intel.com> <20220923005808.vfltoecttoatgw5o@box.shutemov.name> <20220926144854.dyiacztlpx4fkjs5@box.shutemov.name> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220926144854.dyiacztlpx4fkjs5@box.shutemov.name> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On 26.09.22 16:48, Kirill A. Shutemov wrote: > On Mon, Sep 26, 2022 at 12:35:34PM +0200, David Hildenbrand wrote: >> On 23.09.22 02:58, Kirill A . Shutemov wrote: >>> On Mon, Sep 19, 2022 at 11:12:46AM +0200, David Hildenbrand wrote: >>>>> diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h >>>>> index 6325d1d0e90f..9d066be3d7e8 100644 >>>>> --- a/include/uapi/linux/magic.h >>>>> +++ b/include/uapi/linux/magic.h >>>>> @@ -101,5 +101,6 @@ >>>>> #define DMA_BUF_MAGIC 0x444d4142 /* "DMAB" */ >>>>> #define DEVMEM_MAGIC 0x454d444d /* "DMEM" */ >>>>> #define SECRETMEM_MAGIC 0x5345434d /* "SECM" */ >>>>> +#define INACCESSIBLE_MAGIC 0x494e4143 /* "INAC" */ >>>> >>>> >>>> [...] >>>> >>>>> + >>>>> +int inaccessible_get_pfn(struct file *file, pgoff_t offset, pfn_t *pfn, >>>>> + int *order) >>>>> +{ >>>>> + struct inaccessible_data *data = file->f_mapping->private_data; >>>>> + struct file *memfd = data->memfd; >>>>> + struct page *page; >>>>> + int ret; >>>>> + >>>>> + ret = shmem_getpage(file_inode(memfd), offset, &page, SGP_WRITE); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + *pfn = page_to_pfn_t(page); >>>>> + *order = thp_order(compound_head(page)); >>>>> + SetPageUptodate(page); >>>>> + unlock_page(page); >>>>> + >>>>> + return 0; >>>>> +} >>>>> +EXPORT_SYMBOL_GPL(inaccessible_get_pfn); >>>>> + >>>>> +void inaccessible_put_pfn(struct file *file, pfn_t pfn) >>>>> +{ >>>>> + struct page *page = pfn_t_to_page(pfn); >>>>> + >>>>> + if (WARN_ON_ONCE(!page)) >>>>> + return; >>>>> + >>>>> + put_page(page); >>>>> +} >>>>> +EXPORT_SYMBOL_GPL(inaccessible_put_pfn); >>>> >>>> Sorry, I missed your reply regarding get/put interface. >>>> >>>> https://lore.kernel.org/linux-mm/20220810092532.GD862421@chaop.bj.intel.com/ >>>> >>>> "We have a design assumption that somedays this can even support non-page >>>> based backing stores." >>>> >>>> As long as there is no such user in sight (especially how to get the memfd >>>> from even allocating such memory which will require bigger changes), I >>>> prefer to keep it simple here and work on pages/folios. No need to >>>> over-complicate it for now. >>> >>> Sean, Paolo , what is your take on this? Do you have conrete use case of >>> pageless backend for the mechanism in sight? Maybe DAX? >> >> The problem I'm having with this is how to actually get such memory into the >> memory backend (that triggers notifiers) and what the semantics are at all >> with memory that is not managed by the buddy. >> >> memfd with fixed PFNs doesn't make too much sense. > > What do you mean by "fixed PFN". It is as fixed as struct page/folio, no? > PFN covers more possible backends. For DAX, you usually bypass the buddy and map /dev/mem or a devdax. In contrast to ordinary memfd that allocates memory via the buddy. That's the difference I see -- and I wonder how it could work. > >> When using DAX, what happens with the shared <->private conversion? Which >> "type" is supposed to use dax, which not? >> >> In other word, I'm missing too many details on the bigger picture of how >> this would work at all to see why it makes sense right now to prepare for >> that. > > IIUC, KVM doesn't really care about pages or folios. They need PFN to > populate SEPT. Returning page/folio would make KVM do additional steps to > extract PFN and one more place to have a bug. Fair enough. Smells KVM specific, though. -- Thanks, David / dhildenb