From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FD2E7C for ; Thu, 15 Dec 2022 01:01:26 +0000 (UTC) Received: by mail-oi1-f170.google.com with SMTP id m204so4112793oib.6 for ; Wed, 14 Dec 2022 17:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=+AXpgMmuL3NSvfn8iBTUkD9z8GYz9GV/xJMhFU7McSc=; b=Hj80HcFk1+wGgWdM0qYtfoEP118g7pnbDZ1iaONKLRyq7ALD/XEV7vVSxyeyG5C332 DuC73/7jKGMCEB1dULH+KLHOKSeumpkwpUW+GG68qvMmQss4v6sir0gMkHngJ4x1PdNs 8vdv6ESeeyQvXXjiXz48kEds4m3Lm1jtvmFWcha7pPVkxpn+OyzTG9/53OGVegS45kva 5BafxskuHY7iVDaqjM/QPv26NHNdJ8WRDt4flC21tJbgAsNeqEiTNTWmog0Muzakrg+B VTXrP+16m5YsUQA7uxS09XE7vABC6lHuib020amhH4dBXy3QWuaWt/Jwty6r6MYSoUQT 6e1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+AXpgMmuL3NSvfn8iBTUkD9z8GYz9GV/xJMhFU7McSc=; b=4Qia7LfIL1mtN36xmHORPhPRMfRg6pLa9X3aOnwarKFbxVrJ08NA4VV6RTu1KJ02AI UCUl3w+saRLfpxov3JhDgpXdRKUrvPtCj8AgBOjP9lIEP4a6yx7r8mKrRnGLjM4eSklT EzCBQd5u7EKbrrpyQsiOx/Mu+4b5tQqv+0z6hspjbMNnYSR81dTrdaCLwtRMprYG95Rs P9jYkFG6o8G+5sIkRb7JCercWvGcpsgjJEShKs6hYMyQbW0E/4FmGeFPK4JXsQB5PZPv 4AkxO9Oytdkn38sljHNHcYUIXyyJlNkd+W1pSIb+nSk/svLbbFuBCYrfxtcJ+ssY8GWe uIgw== X-Gm-Message-State: ANoB5pmioMYC/RvGWtnImIHFAn5KElgp7LVXYvZvZKie5cebaDoaSSo0 GoqmM57MVz+7It3ttEfanA/j1w== X-Google-Smtp-Source: AA0mqf7KxsTUFtO5GJXQhQPOFp5+C1dzmEUY6YPXNbXSdYOeKDPdD1PHkb69Ov9jtK9L5BUY7Y7G2Q== X-Received: by 2002:a05:6808:2387:b0:35e:9bb3:b8fa with SMTP id bp7-20020a056808238700b0035e9bb3b8famr7121698oib.51.1671066085845; Wed, 14 Dec 2022 17:01:25 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id i8-20020a05620a404800b006feea093006sm11137891qko.124.2022.12.14.17.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 17:01:24 -0800 (PST) Date: Wed, 14 Dec 2022 17:01:13 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Michael Roth cc: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com, jarkko@kernel.org, ashish.kalra@amd.com, harald@profian.com, Hugh Dickins Subject: Re: [PATCH RFC v7 21/64] x86/fault: fix handle_split_page_fault() to work with memfd backed pages In-Reply-To: <20221214194056.161492-22-michael.roth@amd.com> Message-ID: <7f2228c4-1586-2934-7b92-1a9d23b6046@google.com> References: <20221214194056.161492-1-michael.roth@amd.com> <20221214194056.161492-22-michael.roth@amd.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Wed, 14 Dec 2022, Michael Roth wrote: > From: Hugh Dickins > > When the address is backed by a memfd, the code to split the page does > nothing more than remove the PMD from the page tables. So immediately > install a PTE to ensure that any other pages in that 2MB region are > brought back as in 4K pages. > > Signed-off-by: Hugh Dickins > Cc: Hugh Dickins > Signed-off-by: Ashish Kalra > Signed-off-by: Michael Roth Hah, it's good to see this again, but it was "Suggested-by" me, not "Signed-off-by" me. And was a neat pragmatic one-liner workaround for the immediate problem we had, but came with caveats. The problem is that we have one wind blowing in the split direction, and another wind (khugepaged) blowing in the collapse direction, and who wins for how long depends on factors I've not fully got to grips with (and is liable to differ between kernel releases). Good and bad timing to see it. I was just yesterday reviewing a patch to the collapsing wind, which reminded me of an improvement yet to be made there, thinking I'd like to try it sometime; but recallng that someone somewhere relies on the splitting wind, and doesn't want the collapsing wind to blow any harder - now you remind me who! Bad timing in that I don't have any quick answer on the right thing to do instead, and can't give it the thought it needs at the moment - perhaps others can chime in more usefully. Hugh p.s. I don't know where "handle_split_page_fault" comes in, but "x86/fault" in the subject looks wrong, since this appears to be in generic code; and "memfd" seems inappropriate too, but perhaps you have a situation where only memfds can reach handle_split_page_fault(). > --- > mm/memory.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/mm/memory.c b/mm/memory.c > index e68da7e403c6..33c9020ba1f8 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4999,6 +4999,11 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) > static int handle_split_page_fault(struct vm_fault *vmf) > { > __split_huge_pmd(vmf->vma, vmf->pmd, vmf->address, false, NULL); > + /* > + * Install a PTE immediately to ensure that any other pages in > + * this 2MB region are brought back in as 4K pages. > + */ > + __pte_alloc(vmf->vma->vm_mm, vmf->pmd); > return 0; > } > > -- > 2.25.1