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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AB3CC6FA83 for ; Mon, 26 Sep 2022 14:53:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CB8D8E0063; Mon, 26 Sep 2022 10:53:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9885F8E0047; Mon, 26 Sep 2022 10:53:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F4AE8E0063; Mon, 26 Sep 2022 10:53:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6F46A8E0047 for ; Mon, 26 Sep 2022 10:53:44 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 23090C0962 for ; Mon, 26 Sep 2022 14:53:44 +0000 (UTC) X-FDA: 79954530768.25.9C637AF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id C7255C000E for ; Mon, 26 Sep 2022 14:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664204023; 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=Q9xdlHbtjOU2mAEK6q4yNOww8UP3KqhA2O6Rvo3QJmtSXITTaFbiylB4czH2yLAUy+PCwO bVQ12InAwtONtlfEWDD6gvxlx6a4w2LZrWLYjFq588t0VPE+nTdhDObt/pNraUBP2Ltgp3 76O+Fnbr39a47+ndyr4xWegfSHaagfE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-377-Y3g3EcSaM6yuPniOBkNYcA-1; Mon, 26 Sep 2022 10:53:41 -0400 X-MC-Unique: Y3g3EcSaM6yuPniOBkNYcA-1 Received: by mail-wr1-f69.google.com with SMTP id o7-20020adfba07000000b00228663f217fso1263918wrg.20 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=zu5kNmIdKPu5OIVUhy2Po3T3kWnXDhUwkw/CttLD2rgwiaC+lY6q6nzvjtoZ1OpG3a EzGtxwI/coXfRhEXkLnOK7X7n+CUsnckUP5lL6IhER2QnAaMcdoLW0Tp/YsMx532/P5y VAeDUwpR++OkP0fez4oKeeTPzHCs5SYaIlXnox+KXcavucspjiTYA2J23kLudXRQFRMA u79TyGuuHYrjStWC9uvVvCSU/67vGtaDkfKIhFrsBtJ7Wp5MxJwBsVZB4AcjOJtFqyXT vuZy52068j9Xo0jLq97vQYlUVK95Bu3lgtASdRHOjCrAC+zdKkSabZVB0pBsxOk1T5/s roFg== X-Gm-Message-State: ACrzQf05wjmjVag03rIsiSiShJ31LnlMeoIJoBFghl9QuYf3USnJo0LJ 0v/FVczc8GnpbClWcEgfgmSBkhvqCX7bR0ZxUH9jweDqyqzQdOG3WkNDAdXPg64eVY0ktkOXu4I 2dgAi8lrrBYA= X-Received: by 2002:a05:600c:a07:b0:3ab:945:77c4 with SMTP id z7-20020a05600c0a0700b003ab094577c4mr22424222wmp.97.1664204020715; 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664204023; a=rsa-sha256; cv=none; b=UQJ6fLDugUczV3A/NEu+D5wr9elieqMlHoFB8YkHdCOYgAFFU9EVVWxyS1176CE5FQ5Suf 4hHUSR0rPebbKE3W8/T0L/+E04iASUSh5+KyKZKpxxGryY2Ci5RGAd0J+W5kznv6WFevtO fXXTU6W2MEQ94eI5UHm4N3hoq1K8XfA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q9xdlHbt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664204023; h=from:from:sender: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:dkim-signature; bh=JiDPhoXeiEYDPNNsZkNx5skNUhZVDc2YhX8tUxT6Z4I=; b=MiOqZ/fGJpjZwLMwtGiIA6TC4Zg6AWhyqQk0sZoEQSGxwdHwgO5LjWf2xdCFE/ylAlyOiV 1DbCuK/cqvXc8U1N01Fb8MCXLe8AbkYi7m0/jDUF3F0trZnRsaOQH0ZfzwUVVaEg5qaG9D 6u6795kFN/uGYeXLxAB4uT+NmD2MeHk= Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Q9xdlHbt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Stat-Signature: 7bg5nzyj7nuof8kw5p5586ywwjfy53at X-Rspamd-Queue-Id: C7255C000E X-Rspamd-Server: rspam06 X-HE-Tag: 1664204023-568546 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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