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 0B6E7C25B50 for ; Mon, 23 Jan 2023 23:38:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C8E16B0071; Mon, 23 Jan 2023 18:38:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1792F6B0072; Mon, 23 Jan 2023 18:38:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F34486B0074; Mon, 23 Jan 2023 18:38:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E018B6B0071 for ; Mon, 23 Jan 2023 18:38:14 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B6D8D1A022C for ; Mon, 23 Jan 2023 23:38:14 +0000 (UTC) X-FDA: 80387679708.10.981813A Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf28.hostedemail.com (Postfix) with ESMTP id E0830C0005 for ; Mon, 23 Jan 2023 23:38:12 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VkzHwRGn; spf=pass (imf28.hostedemail.com: domain of seanjc@google.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674517092; 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=PDHB0ODlMstmhFdpIes6JLYo5+ikO8l0oYaAPmmlt1c=; b=ccpttt/C/Swuo/0Hvy/vN/tG/lCldOT9KHyqKb09f/UGbABvNNtvyoFHEFdnHbNtHIrZRZ eETwmldvnzNxzGdCwpbUFpK5rX4MAfTllcakgSG4LCIgwRR679hapoj4LtuLznWBHjspVC BahnOCnbVloKohyBMePJxjcNNwHV6Uo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VkzHwRGn; spf=pass (imf28.hostedemail.com: domain of seanjc@google.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674517092; a=rsa-sha256; cv=none; b=w2DY1RgUeNhAgKLfq7s/w0K0aEeB7Ur+S1XUhp1xxkEKsnimnRK+RfGGCB7daXk+REvrp/ eUewy72SYCXxvLmubhbt3aXbq+lWr1ay/2nKXZZmnTwU8yEOdeirvCRugKqMionZ+Wfw1I +LdBq0adH8Umrgrglh4g4ryyoaxzSII= Received: by mail-pj1-f44.google.com with SMTP id b10so13202314pjo.1 for ; Mon, 23 Jan 2023 15:38:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=PDHB0ODlMstmhFdpIes6JLYo5+ikO8l0oYaAPmmlt1c=; b=VkzHwRGnuLzzOCe+jd2+aXAC1B0Pi316N1RkmUx4r6ANqJcx0x+5Q72Z8UUWxTdy1r pG5SCyLEjYuMfqhsFLdkkFHinHiEydOUFzX+r5WNej9OPd87nM0d7yREV+Rq8DkVOrGV NNXVLr+T0ZRr5iz2mMx1Z0IHdQwR/sXaSDOinZlAX/u9O36ljHgPvbEvKqpZSoiKL/Ql 2n5bBmNgSGwr5j9NkL7X+hI5ejHfVg7U5tPdlMMUlM5A7mUt0EJEbSqS9aevYAkYpR2i P7CyNcMiBR5cvRjvE+wd+fhWDFEx7SAIHLLtgqKHLWXCd78gvhmYm3A32QaiqopBK3SZ eGPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PDHB0ODlMstmhFdpIes6JLYo5+ikO8l0oYaAPmmlt1c=; b=MywjcLI073ic5nY13TslqANJkDuC6VTAhp1ejug5rEQ49stNzFP9E04DyCh56YjrSt qqygqzuJCZSuej4tT7ky0MDizI27pDuvZavCfd0k9KXKtRwyScjgKgRt6zRzZyu7fwa+ F00luYM7opNOxEZNfJrc2FJdOZ4bvFlkK4Bm1O8AvkXox6fyPW0G5CGhMRAzIaIlBevW k9EryPVrLdUYo3vJcCjuIxVCteNYQuMoBh/TZmcIdiJ1VL+cb/sX1UYz6Y/9GzrtEkQk /qous6qvvn9WYZuFk3QHEI5rwpSzFFFC7bSQB2QamcBJgwCFV4ob0Mi08p9iIrJV7ykk 5pDw== X-Gm-Message-State: AFqh2ko5577dF1VJxuejw0L5cRWrSOJRJuYjIB/U6bUpOF+oZFJC5Fzl z348IrNl0CIEUlfgc8BNTKTMRg== X-Google-Smtp-Source: AMrXdXtrvJkyeLq8anFSJnOID4b9C3AaKf59uOM0fvrdASPfrf/mhyTzO8Q2iNKbj2o8vaNJGqEopA== X-Received: by 2002:a05:6a20:3ca7:b0:b8:c646:b0e2 with SMTP id b39-20020a056a203ca700b000b8c646b0e2mr1004683pzj.3.1674517091557; Mon, 23 Jan 2023 15:38:11 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b00499a90cce5bsm102181pgo.50.2023.01.23.15.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 15:38:10 -0800 (PST) Date: Mon, 23 Jan 2023 23:38:07 +0000 From: Sean Christopherson To: "Huang, Kai" Cc: "chao.p.peng@linux.intel.com" , "vbabka@suse.cz" , "tglx@linutronix.de" , "linux-arch@vger.kernel.org" , "kvm@vger.kernel.org" , "jmattson@google.com" , "Lutomirski, Andy" , "ak@linux.intel.com" , "kirill.shutemov@linux.intel.com" , "Hocko, Michal" , "tabba@google.com" , "qemu-devel@nongnu.org" , "david@redhat.com" , "michael.roth@amd.com" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "dhildenb@redhat.com" , "bfields@fieldses.org" , "linux-fsdevel@vger.kernel.org" , "x86@kernel.org" , "bp@alien8.de" , "ddutile@redhat.com" , "rppt@kernel.org" , "shuah@kernel.org" , "vkuznets@redhat.com" , "naoya.horiguchi@nec.com" , "linux-api@vger.kernel.org" , "qperret@google.com" , "arnd@arndb.de" , "pbonzini@redhat.com" , "Annapurve, Vishal" , "mail@maciej.szmigiero.name" , "wanpengli@tencent.com" , "yu.c.zhang@linux.intel.com" , "hughd@google.com" , "aarcange@redhat.com" , "mingo@redhat.com" , "hpa@zytor.com" , "Nakajima, Jun" , "jlayton@kernel.org" , "joro@8bytes.org" , "linux-mm@kvack.org" , "Wang, Wei W" , "steven.price@arm.com" , "linux-doc@vger.kernel.org" , "Hansen, Dave" , "akpm@linux-foundation.org" , "linmiaohe@huawei.com" Subject: Re: [PATCH v10 1/9] mm: Introduce memfd_restricted system call to create restricted user memory Message-ID: References: <20221202061347.1070246-2-chao.p.peng@linux.intel.com> <5c6e2e516f19b0a030eae9bf073d555c57ca1f21.camel@intel.com> <20221219075313.GB1691829@chaop.bj.intel.com> <20221220072228.GA1724933@chaop.bj.intel.com> <126046ce506df070d57e6fe5ab9c92cdaf4cf9b7.camel@intel.com> <20221221133905.GA1766136@chaop.bj.intel.com> <010a330c-a4d5-9c1a-3212-f9107d1c5f4e@suse.cz> <0959c72ec635688f4b6c1b516815f79f52543b31.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0959c72ec635688f4b6c1b516815f79f52543b31.camel@intel.com> X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: rn3gyncrbwoo1fmfiwici83f7fw6h1be X-Rspamd-Queue-Id: E0830C0005 X-HE-Tag: 1674517092-76913 X-HE-Meta: U2FsdGVkX19TTKyFWTV/m39mvtT9qboqGty4IOkktUk/7vVqsfLwqnRmpOJ1o6TAR2avyRjdCGcM1UcuWDZXyqCUwTVA6kqiHgOTDpl9jCAWQoeXxhy3sFqh96RA4CrJ4zln3S3bCUD9W8odhzBF8cUqEplj3wSs/qUDl2C6BTDauLvrDpiJOXSN0N7q35g+aTuqLm0CwUrrjYf9qRxo06N4GLKVP8Kdqq2oXATOD/yzKBSwyaFSWgSF6AFtyAsvdqt9COiqIwTRk6B77Pt8ZpJnqXW8MDu5Oh/XyIRMpE2GgM4VOFq1qO7CE038k6gvlaHk0GcHhq4DS9UpZCcmqjHVKuwilpkiTfzeBy+BzRarlvxyrUdZly17ugWdX2yFpUfdnYMx1HYZzwYPHamBVgGBUgDwepl049m6P7kf2OUXfc9pTd74t2ez5Ay9GZENuG+I6oaqtZDttpVUK9QnZ5OqfCuj0JpXnmX1heMNE6ZDhwzvC16Pq/ZK5iQUn+J/BIQKcnwH8+cM4zljFxUzy1RLbXKNB76JkGrOXS/6GdSH/uZTJpKZe2dVlC3npTwZoIkrua2hnVqAoisJ4HCvotinwhB3iEUSc54pD5S/YhB8uJzRFQFLA/kny75Ot1hbsQ27EX1hKIdrUx11CrD2g9bJs7+knFGOhGlbccYDnlHgQAiv6EE8T0R/pzUz7NdzCVxdS6P5/iGl7duy5YQP5q1VZ0mgeqae38DfkE3JVY0k8tIF4E6bqQxnI794mD0BOfNslDOpdQHgMU0mwZWVIhP+8+dggFp67gJ2y50gs4FT91EYVUH/z2wR3wMb/tdva5Nu9B7gJOU4Fsc/LExB4o3WCFn9Zg1+UUx1SAqkxKEIId91q+WW6HkTcoGSHsC/uZNNo1l5gr1V6+hgVDvNe04ugiec5UZdaERQ0A52gBUsSQ9remFJbCe4LS1D4pOw7IMVGynA2Cla2wuNxXc eIWzVTKr /J9A6TDh/ReLYyc6SOIqBs41otV5U+dxSAdy+apcxLVkNmKVnUr06psfHXz9Vt/+WDuSlPhrNZRBsh6bevbULQ+M1B/8Vw0y+IUvMdAth0S4IA15PNxZB8LivuOB6xqQF8mqmYC1RY1oFzwsVG+vZnPrkgkbNjkLgii7uWLt3lH3zcP2/y0KhwgaVvlaCFaoc1d9M1iMKo5uk85Ow2Yc9KlE6Z73um8nLsIxhHehBCWyKGqr8UgdmudXVbkH1AsFut1awAELe27QrHhyy7vmZDmbCWME5LXFpQwr2aJNHpbSp9WzoxUiSxL4oSxgomg3PrtkIIdCBCtUsceFUNwcPPhbfrY3d9YE3U1YJeQDeHSg6sQszi650wqbvHm6b0FmzX5iVHIGYOBaPoWx0pDCKYGvEs60gUazCVlWRVyclaw+86tEkLCah4DSxaE+JaLZM1HZP3dIIi7g9AKieEMmBxI3hvA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jan 23, 2023, Huang, Kai wrote: > On Mon, 2023-01-23 at 15:03 +0100, Vlastimil Babka wrote: > > On 12/22/22 01:37, Huang, Kai wrote: > > > > > I argue that this page pinning (or page migration prevention) is not > > > > > tied to where the page comes from, instead related to how the page will > > > > > be used. Whether the page is restrictedmem backed or GUP() backed, once > > > > > it's used by current version of TDX then the page pinning is needed. So > > > > > such page migration prevention is really TDX thing, even not KVM generic > > > > > thing (that's why I think we don't need change the existing logic of > > > > > kvm_release_pfn_clean()).  > > > > > > > > This essentially boils down to who "owns" page migration handling, and sadly, > > > page migration is kinda "owned" by the core-kernel, i.e. KVM cannot handle page > > > migration by itself -- it's just a passive receiver. > > > > > > For normal pages, page migration is totally done by the core-kernel (i.e. it > > > unmaps page from VMA, allocates a new page, and uses migrate_pape() or a_ops- > > > > migrate_page() to actually migrate the page). > > > In the sense of TDX, conceptually it should be done in the same way. The more > > > important thing is: yes KVM can use get_page() to prevent page migration, but > > > when KVM wants to support it, KVM cannot just remove get_page(), as the core- > > > kernel will still just do migrate_page() which won't work for TDX (given > > > restricted_memfd doesn't have a_ops->migrate_page() implemented). > > > > > > So I think the restricted_memfd filesystem should own page migration handling, > > > (i.e. by implementing a_ops->migrate_page() to either just reject page migration > > > or somehow support it). > > > > While this thread seems to be settled on refcounts already,  > > > > I am not sure but will let Sean/Paolo to decide. My preference is whatever is most performant without being hideous :-) > > just wanted > > to point out that it wouldn't be ideal to prevent migrations by > > a_ops->migrate_page() rejecting them. It would mean cputime wasted (i.e. > > by memory compaction) by isolating the pages for migration and then > > releasing them after the callback rejects it (at least we wouldn't waste > > time creating and undoing migration entries in the userspace page tables > > as there's no mmap). Elevated refcount on the other hand is detected > > very early in compaction so no isolation is attempted, so from that > > aspect it's optimal. > > I am probably missing something, Heh, me too, I could have sworn that using refcounts was the least efficient way to block migration. > but IIUC the checking of refcount happens at very last stage of page migration too