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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 504A5C001DC for ; Wed, 19 Jul 2023 08:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:Message-ID: In-Reply-To:Subject:cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7lcRyZfCQKr0SB/unzIajG4fcPzGg+Q1/r4+/DXsgtw=; b=qZi1Ui2oaAnDwj p6kqSRZfZRI/h0r3eJmf3S1y7tga6wAzkJ2p22LvdLzoUOFRvPmug5EzpO52hND/dvVKp19AxOunR 3zQO1y6pKQ/uYmK/cxH99/tNIJ+wXVx8KciaY8oXTf2I47TVTKx8ayMf+4xSh/T+VJHM0g5tsIz2P kVjDdWtfoxosQE3qLhK0KE7qCaOZe8sYVqiPmg6B12hCVnxD3IRNvjJ3wrVAwMR35e6BlWQIUt51p 43lFh4zL7SHD8QwGC76BP+oY3hDYlPJ9WILYHJ4Jq1/OTvPk4YHQ/8vsKHl4dSrx+rbDFHO59/06I NduQg7w+4eN5Yuoquucw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM2QO-006Inp-2i; Wed, 19 Jul 2023 08:20:44 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM2QI-006Ikb-0W for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 08:20:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Message-ID:In-Reply-To:Subject:cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=kE1rj6hT4IpsuXlwWAbwyeMLg8 FO0QqImE1eY8D4hGjNj/SdH6UweyGHJ46hDJw/xf4aI/s20EBtsy4Mvbg3GyCcu0sUISNA3DWAlSH +wX2s6XhB6pz6/I8XBjMHciHP4o181UFcffPR8JVOsLwmdXQQB9+lccY3O5OKAEsO5W9WntjI25uK ndF1q3WQG1mfIchkkd6HpABC8uz0TOizf5/9O6hgKAnaMk/FGNaxl5iLM8zn+DerqZoGg2DwUdYYW Li+Gw5XfEVa6wdr9C9oJo3SS07ABtE+wzfvxE39jkHJ0Dms3CPJrAkuKMGre6Eocd6FFmSfQSEqAJ rkkj2lFA==; Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLXnj-009Scx-35 for linux-arm-kernel@lists.infradead.org; Mon, 17 Jul 2023 23:38:50 +0000 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-bff89873d34so3821998276.2 for ; Mon, 17 Jul 2023 16:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689637062; x=1692229062; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=k9GbXOYqPe1POhby7opK5kclsobljuvSzYRz76LxTowmpjIJR51rHEsa/yMmfrNLqD Tx4kCMNCwjq5YXwP018228iomQaNPdM3GDlsazU1hVWtrnBNJ79PmOggaaMmyYtQSVFj /8hsbtkFxoXWDYPpBRhOoq1X2gAYexB2wShawSOOUGS5+lYJhd3LDyigzAMix5UgaKww CG7lL2pMXLSVSK1RTDS/lgzSXnvShQzpWdMiRaxfe9dQ5E+8Fbrrngyu27DzmzUSFTGO dXgfcxfYHfaAP3EZDPV7qeD1XhCeYDZANKuXxc+riOKnWQl9GUKFj4HBYfXczIocRlPN lH5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689637062; x=1692229062; 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=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=cGKYk7T/tWzXyAMBAd+Aa0tgRpdwXZZ2kln/lcGaVyLg7u/PWxrbU/13xKThn70mZF 9Wct1LoJPGJ0JjeJwmg+GZfNMnaxyHgTUVWfGTlDCKx9XBqE1QaFOydn8LXYdAr8nVMo m2izUHgRt/gkpfBRfNyJliCjSp33Tezhas5vCH/bRjJIaa6CwWsAVgikK8QPYJkmRz1s sY0/LwGFqEYTcOVRs1wbVY1CVHTIoHeH1a1u6upJ+x5Mbp2mN/o9AUkmKcr6kLXo1G5M K8ic6u0esz3V2d1TZjW3n5qtBlOwBwli4hvm/qGM5ET0pREtJh6DALneeDJOr7FjhoQl 6Y1Q== X-Gm-Message-State: ABy/qLbBCWvnLvzaZXrBvpTktq87ADdr1P8D56BYL2U42DTtBaQqN9Bb dTA77MOuULUQ/6NyyuQCS/9w/w== X-Google-Smtp-Source: APBJJlHbG9lgcp914LKgXhja8Amg4xcjiZMX1if2yS+Nn7RkrbWXjIgJApIlAYuBISZHBJ/wewImPQ== X-Received: by 2002:a81:4f0c:0:b0:56d:2f9d:42cc with SMTP id d12-20020a814f0c000000b0056d2f9d42ccmr7057474ywb.51.1689637061083; Mon, 17 Jul 2023 16:37:41 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d126-20020a0ddb84000000b00577139f85dfsm151563ywe.22.2023.07.17.16.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 16:37:40 -0700 (PDT) Date: Mon, 17 Jul 2023 16:37:31 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Ryan Roberts cc: Yu Zhao , Hugh Dickins , Matthew Wilcox , Andrew Morton , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 3/4] mm: FLEXIBLE_THP for improved performance In-Reply-To: <5df787a0-8e69-2472-cdd6-f96a3f7dfaaf@arm.com> Message-ID: <8bdfd8d8-5662-4615-86dc-d60259bd16d@google.com> References: <20230714160407.4142030-1-ryan.roberts@arm.com> <20230714161733.4144503-3-ryan.roberts@arm.com> <432490d1-8d1e-1742-295a-d6e60a054ab6@arm.com> <5df787a0-8e69-2472-cdd6-f96a3f7dfaaf@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_003848_268086_E1475698 X-CRM114-Status: GOOD ( 28.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 17 Jul 2023, Ryan Roberts wrote: > >>>> +static int alloc_anon_folio(struct vm_fault *vmf, struct folio **folio) > >>>> +{ > >>>> + int i; > >>>> + gfp_t gfp; > >>>> + pte_t *pte; > >>>> + unsigned long addr; > >>>> + struct vm_area_struct *vma = vmf->vma; > >>>> + int prefer = anon_folio_order(vma); > >>>> + int orders[] = { > >>>> + prefer, > >>>> + prefer > PAGE_ALLOC_COSTLY_ORDER ? PAGE_ALLOC_COSTLY_ORDER : 0, > >>>> + 0, > >>>> + }; > >>>> + > >>>> + *folio = NULL; > >>>> + > >>>> + if (vmf_orig_pte_uffd_wp(vmf)) > >>>> + goto fallback; > >>>> + > >>>> + for (i = 0; orders[i]; i++) { > >>>> + addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << orders[i]); > >>>> + if (addr >= vma->vm_start && > >>>> + addr + (PAGE_SIZE << orders[i]) <= vma->vm_end) > >>>> + break; > >>>> + } > >>>> + > >>>> + if (!orders[i]) > >>>> + goto fallback; > >>>> + > >>>> + pte = pte_offset_map(vmf->pmd, vmf->address & PMD_MASK); > >>>> + if (!pte) > >>>> + return -EAGAIN; > >>> > >>> It would be a bug if this happens. So probably -EINVAL? > >> > >> Not sure what you mean? Hugh Dickins' series that went into v6.5-rc1 makes it > >> possible for pte_offset_map() to fail (if I understood correctly) and we have to > >> handle this. The intent is that we will return from the fault without making any > >> change, then we will refault and try again. > > > > Thanks for checking that -- it's very relevant. One detail is that > > that series doesn't affect anon. IOW, collapsing PTEs into a PMD can't > > happen while we are holding mmap_lock for read here, and therefore, > > the race that could cause pte_offset_map() on shmem/file PTEs to fail > > doesn't apply here. > > But Hugh's patches have changed do_anonymous_page() to handle failure from > pte_offset_map_lock(). So I was just following that pattern. If this really > can't happen, then I'd rather WARN/BUG on it, and simplify alloc_anon_folio()'s > prototype to just return a `struct folio *` (and if it's null that means ENOMEM). > > Hugh, perhaps you can comment? I agree with your use of -EAGAIN there: I find it better to allow for the possibility, than to go to great effort persuading that it's impossible; especially because what's possible tomorrow may differ from today. And notice that, before my changes, there used to be a pmd_trans_unstable() check above, implying that it is possible for it to fail (for more reasons than corruption causing pmd_bad()) - one scenario would be that the pte_alloc() above succeeded *because* someone else had managed to insert a huge pmd there already (maybe we have MMF_DISABLE_THP but they did not). But I see from later mail that Yu Zhao now agrees with your -EAGAIN too, so we are all on the same folio. Hugh p.s. while giving opinions, I'm one of those against using "THP" for large but not pmd-mappable folios; and was glad to see Matthew arguing the same way when considering THP_SWPOUT in another thread today. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 EF5BEEB64DC for ; Mon, 17 Jul 2023 23:37:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 680D66B0071; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6315C6B0074; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D2CE8D0001; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3EF2F6B0071 for ; Mon, 17 Jul 2023 19:37:44 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 197AAC0452 for ; Mon, 17 Jul 2023 23:37:44 +0000 (UTC) X-FDA: 81022718448.02.04EFE3E Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf13.hostedemail.com (Postfix) with ESMTP id 429A220008 for ; Mon, 17 Jul 2023 23:37:42 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xgmV+C3G; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=hughd@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=1689637062; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=nbbL9DQh9Km1/JeAp2FeCQ7XzuaNiMU1fqDt2+TqYPBI72Myu7y3Fx9NMzkJqk3+cVk/+o DbGApCmF5K4bUbu8seVPyIOfsHNcTh8+7ssB3pMjjAsS1+DI2WTcDwhiKcE7nQ5HVMrQCz 2O3d6chS2kp6IsjfxDbQ5LldFuY8/H8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689637062; a=rsa-sha256; cv=none; b=cZItgOMmZBxf9YXlBGfP6boO9O5ajN1rK4RJLJNKCioaX11T2CAcI++k/sww67BCstUQzh JPHLOGR+dJht5ffkkKsourzcdKZSOvkhox+2ys6Tk5ir4HGNbUizst+jAsVzGf1K+uaWqq ewFiaXfJVmorSEmzET6mBW7sNRBGk6o= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=xgmV+C3G; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-c01e1c0402cso3828338276.0 for ; Mon, 17 Jul 2023 16:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689637061; x=1692229061; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=xgmV+C3G4eKZrk06U+JRuxOEbOvrN8vsGVx7JH5ITC5xHrh8dYiRF7tBA0EJtNrDP2 wOqChQD4Jrv4EbshHiPvhsxYuat1xtKSTyUoK8bv/Mwf8W3j50zYsrqP0nm5bwbGZW8l bpUdpXg3sWLAOzI0goJtj1gpJ8tIDaKzOBSrYC4SXKq1naWk5HgzCuPjAm7yEXt2z7ct eLnrySKUHZmL3iguIw3nA5turmozcLLMv2kKOzdDFs2O+ZKzrWiZIcl4DCjlsVcdQ0/f lsZ4XFCgYcb3pH0LH+U+WL7ciZp6yBKJPcDKZZWrT1WkhCS960H684y8mePbsVJneIz9 +7RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689637061; x=1692229061; 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=ZLu2xhwd4SAqbSYI2ps1VyFCry+LyNldvcwZWPQNIvo=; b=Sb7GQT5tWO6wd7GJXXs+UXCyRDElrkE4NHPywxmVz2m6OKNlVszcvKrfmN1GeRUhnX OD87C/nnyCxFIf8gSZbSBlN8CRJTOQL8BJ9ujEsANn6wrsFge5A5R/nAMvUfgLcwAA8E mOc94OuVSjmudhI0RNTIxWMZMDzQdex9j79BPzbQOgCTdYAfWnwS9GBDnVZIT4V1D2cF fiqJcZfn1V4IhXxRZ9tpONgc8mr/tVkhuX1IXRhBdIJs1MWJS3wpBZG8pnnK0Bo8yohk AGRwb81eCmVKgmmolUdr1crquzqiw5ikmuaZNvdWdPVpumMrQR9tr60+be5otIhu2rHa curg== X-Gm-Message-State: ABy/qLY+ZZuiF8kuUu8gcz3mxr27zAwFtMqF+R2Pi0T3LBgVX6MWFeFj nVE2PA8wGY6AjBxkicTvhF4SnA== X-Google-Smtp-Source: APBJJlHbG9lgcp914LKgXhja8Amg4xcjiZMX1if2yS+Nn7RkrbWXjIgJApIlAYuBISZHBJ/wewImPQ== X-Received: by 2002:a81:4f0c:0:b0:56d:2f9d:42cc with SMTP id d12-20020a814f0c000000b0056d2f9d42ccmr7057474ywb.51.1689637061083; Mon, 17 Jul 2023 16:37:41 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d126-20020a0ddb84000000b00577139f85dfsm151563ywe.22.2023.07.17.16.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 16:37:40 -0700 (PDT) Date: Mon, 17 Jul 2023 16:37:31 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Ryan Roberts cc: Yu Zhao , Hugh Dickins , Matthew Wilcox , Andrew Morton , "Kirill A. Shutemov" , Yin Fengwei , David Hildenbrand , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 3/4] mm: FLEXIBLE_THP for improved performance In-Reply-To: <5df787a0-8e69-2472-cdd6-f96a3f7dfaaf@arm.com> Message-ID: <8bdfd8d8-5662-4615-86dc-d60259bd16d@google.com> References: <20230714160407.4142030-1-ryan.roberts@arm.com> <20230714161733.4144503-3-ryan.roberts@arm.com> <432490d1-8d1e-1742-295a-d6e60a054ab6@arm.com> <5df787a0-8e69-2472-cdd6-f96a3f7dfaaf@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 429A220008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: a4dxqtu3ebj6exgyhcezi76mbf1k57yb X-HE-Tag: 1689637061-833171 X-HE-Meta: U2FsdGVkX18rYrKdcl5lS72Njt/4ETWM/6uMnWsdoLxLyLCo4zDJ2IfDUayaPH6umdDzrhsU1vkiGytBenuMAeKdShKtzmFjom1jqlGoQBGMZFU4M5WF5odYU5343Vrjr8BVA2AQcPgKanSnO+T64K6ttawrhDibdd6DLRLW6XDtbFKMkYikzBrWOkgvS7qwDs4vvU7KCz5lpf/clM8J6cxyUxjzGtEkCJtz8HjylbHHkdSkY+nJNPR3wVJaiAOImNJreP1JPVd50MEwQqMvxR+0RevyU/j7X1StBdIugAqkFpxvy92BYXi7xKeIIVqAtiR2IK1EFeFqPAZDEsSpJmjs/GmoEnYfZpCuWhR4rWUWcEHHigg45kOQ0kV3NJIXrXZfjSJU+Igy6bV4Bg8IN+0qOFIDTmTAf1B3ltRknIGuHqxkWkZYVUKzmh28ydXNFVQWwK3yM30P4aJJAViE0SRQV359za+3J1qn+AHXQbi/o1Ayqtu5uvxs1KjCZuxdBjXTm6q6sIWlfzvt32u9a/95LH4uIbDa10q5EEfzdqwLzxzV1ggV1hIX9ReFMIQZ0uss3/DTsbeNtSA7NDstARtElxu3cFeZjbB4z0miAczHip9OfqdnkxKz6oyPAh9A5tgKbGu+OmnIjKlZ0n3bXh67ctUKBmnEjF6KRq+zeip7fhJ/wKDA2giCWSayxpxUB9Qvuvz80QruEUJXnaeG+/9ubD9J4lQvHmgfujHq/7s1Ndh/DCOiQmfg8fXQJup+rDclctCU1y5n+hfw8uwsD9y3iFMeRhpwWaf6VnwdSTjSdLxhoAHhdb1wPTR1ptDC1GTdJrNzDNWpeZg3c2LxUwUB0GjZoCqd9TQnatIGQ5SF+4d1EyLjf1lk2QDVmKdwTtyq5y3vx4PkSDNpAahOzgpxW5UpIeI89Bakdp1VdVShCgucMfWhk7uumxmZuZEHLOhyTCtyJ5g+mydBg4B 64IK1sXS ZgaJwKN1dg6/nnEEfcwmBzSPqnTFVwRf7mtVKBvtmWlVnGRF/beFw/yy5LTCQvjOulzekXpk6Rjh3xcQXF+AwTLK7EWUu9561kbumONHkD0UEIEkEJtCBhjJkizKZjYcjO5Bz072lp2tZeDs6G0tD+MAGARFJpm9fCU8o2wKXmMQmU2kF+6K1aPM4fKFdQLkhZ0wbN7HrJjfsW/ifWUSocebM7qStqP5BTSDr9ySTwXrGJ4Ynt1VH78sL+5Rczc28G6o3r187KwwRzanYdvVQbjTbLrFGcu19/WO+SsHHlq4YWzxXvHynjyfvE1ZJbiUvHl4Q040FK6jus4wx16O/S4AA4qbvdNs5SK15Cr3dfRj6N8FeJ3Fgp+HTBUPgGoBHkpyiudWpKnYob3U+q0/v2VFjDNfYwWVaTM2E 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 Mon, 17 Jul 2023, Ryan Roberts wrote: > >>>> +static int alloc_anon_folio(struct vm_fault *vmf, struct folio **folio) > >>>> +{ > >>>> + int i; > >>>> + gfp_t gfp; > >>>> + pte_t *pte; > >>>> + unsigned long addr; > >>>> + struct vm_area_struct *vma = vmf->vma; > >>>> + int prefer = anon_folio_order(vma); > >>>> + int orders[] = { > >>>> + prefer, > >>>> + prefer > PAGE_ALLOC_COSTLY_ORDER ? PAGE_ALLOC_COSTLY_ORDER : 0, > >>>> + 0, > >>>> + }; > >>>> + > >>>> + *folio = NULL; > >>>> + > >>>> + if (vmf_orig_pte_uffd_wp(vmf)) > >>>> + goto fallback; > >>>> + > >>>> + for (i = 0; orders[i]; i++) { > >>>> + addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << orders[i]); > >>>> + if (addr >= vma->vm_start && > >>>> + addr + (PAGE_SIZE << orders[i]) <= vma->vm_end) > >>>> + break; > >>>> + } > >>>> + > >>>> + if (!orders[i]) > >>>> + goto fallback; > >>>> + > >>>> + pte = pte_offset_map(vmf->pmd, vmf->address & PMD_MASK); > >>>> + if (!pte) > >>>> + return -EAGAIN; > >>> > >>> It would be a bug if this happens. So probably -EINVAL? > >> > >> Not sure what you mean? Hugh Dickins' series that went into v6.5-rc1 makes it > >> possible for pte_offset_map() to fail (if I understood correctly) and we have to > >> handle this. The intent is that we will return from the fault without making any > >> change, then we will refault and try again. > > > > Thanks for checking that -- it's very relevant. One detail is that > > that series doesn't affect anon. IOW, collapsing PTEs into a PMD can't > > happen while we are holding mmap_lock for read here, and therefore, > > the race that could cause pte_offset_map() on shmem/file PTEs to fail > > doesn't apply here. > > But Hugh's patches have changed do_anonymous_page() to handle failure from > pte_offset_map_lock(). So I was just following that pattern. If this really > can't happen, then I'd rather WARN/BUG on it, and simplify alloc_anon_folio()'s > prototype to just return a `struct folio *` (and if it's null that means ENOMEM). > > Hugh, perhaps you can comment? I agree with your use of -EAGAIN there: I find it better to allow for the possibility, than to go to great effort persuading that it's impossible; especially because what's possible tomorrow may differ from today. And notice that, before my changes, there used to be a pmd_trans_unstable() check above, implying that it is possible for it to fail (for more reasons than corruption causing pmd_bad()) - one scenario would be that the pte_alloc() above succeeded *because* someone else had managed to insert a huge pmd there already (maybe we have MMF_DISABLE_THP but they did not). But I see from later mail that Yu Zhao now agrees with your -EAGAIN too, so we are all on the same folio. Hugh p.s. while giving opinions, I'm one of those against using "THP" for large but not pmd-mappable folios; and was glad to see Matthew arguing the same way when considering THP_SWPOUT in another thread today.