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 DD79BC2BD09 for ; Fri, 28 Jun 2024 01:25:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F43A6B009E; Thu, 27 Jun 2024 21:25:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A47D6B009F; Thu, 27 Jun 2024 21:25:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16BDD6B00A0; Thu, 27 Jun 2024 21:25:57 -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 E96B96B009E for ; Thu, 27 Jun 2024 21:25:56 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 96E8C81408 for ; Fri, 28 Jun 2024 01:25:56 +0000 (UTC) X-FDA: 82278555912.07.E7E7AD7 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.7]) by imf30.hostedemail.com (Postfix) with ESMTP id 5EACD80002 for ; Fri, 28 Jun 2024 01:25:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=Rn3fwgiy; spf=pass (imf30.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.7 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719537945; a=rsa-sha256; cv=none; b=c73mObAU6phROYViaM5sZAiCWxXXPh17dt4v/4R+3HZWJE1HfxTPCvUfsRvU2HTDCN81HU SfobulVuC9HZqicbAjaJ4dxSTV12Yu8QmRsUWPrKOWSQ/Rddng/jyC77cz+5gruoAmw0dO LJFK5PbVoZDA1ssJXHgHUGi44a15r48= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=Rn3fwgiy; spf=pass (imf30.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.7 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719537945; 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=tTOy6Kq3aNVWHj/osQBSoy/9+UEn0MO184Z7Lmt65g4=; b=EfapoT2kJ45UZHVQrKooS9uKa8TjvMRQxltX14sQHc2NM01JJkZ3gad65n+KYqhLPvPuq4 KNtHKOU6f8IamDTdWmtHrp9yoaBYZWCaj2IxH4S2EPTl04CBVnEes1pxyEqGs/PNwqg1O8 354HgODEgAZbzBpOU4OOQrGPdqJRDFQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:From: Content-Type; bh=tTOy6Kq3aNVWHj/osQBSoy/9+UEn0MO184Z7Lmt65g4=; b=Rn3fwgiy5jx0QWHgKQoup4vLNXxWu8hqTUrCjxxT7XMicWWAgC+NigrX4NebqS gLdQ7j41rHMR0rFgFFfVBPCr0HEspsoX3z/M7Rabp1D+tkZrQg+LgEa8Iux26xfP RgvQYhCAWfejscynWy7EEiidX+yNHv8IvysoS5geF3SP0= Received: from [172.21.22.210] (unknown [118.242.3.34]) by gzga-smtp-mta-g1-0 (Coremail) with SMTP id _____wDX_9kZEX5m77HCAA--.18751S2; Fri, 28 Jun 2024 09:25:48 +0800 (CST) Message-ID: <4850060d-7fc2-4869-a901-38f11058bd40@126.com> Date: Fri, 28 Jun 2024 09:25:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [v2 PATCH] mm: gup: do not call try_grab_folio() in slow path To: Peter Xu , Andrew Morton Cc: Yang Shi , david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20240627221413.671680-1-yang@os.amperecomputing.com> <20240627163242.39b0a716bd950a895c032136@linux-foundation.org> From: Ge Yang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wDX_9kZEX5m77HCAA--.18751S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZFW5CF48Cw13Ar48Gr1UGFg_yoW5GF4xpF y3Ka9xKFWkJr10kws7tws5XFWFyrZ8JryUXws5Gr1xua98ua4xWr48X34FkF98W348Ga10 vFW2y3srZa1DZa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jt5rxUUUUU= X-Originating-IP: [118.242.3.34] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiOhwMG2VExE332wABs0 X-Stat-Signature: yhc5m6btwepqmcz1q3h1rjphmqnwgud8 X-Rspamd-Queue-Id: 5EACD80002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719537952-745612 X-HE-Meta: U2FsdGVkX1+QPGMUk281iuRObdiYJH261lXM4KoSGhB5bNLWxnoAJH1CTRUoG93Hxx1Jczyo4nCPkci7PenYXa9Rg1g3EGcXvaACV2vujE0BVELsVdLOsm/ZcEdMlyQ1OjBEIAwX2AAPwwGMVq3lfgOtDfxZvgByhy31u6DCMOTbcsy2reWP8B5TdpY1kh54A3xdcS5zM70Kynb9vwd11efTx4pTtOR4kfgrW+ZvhP4dmEvG11Z2wWn1BqRpjuRG86e6F5qSiDJTeyRmaojhF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sQJaFpjo0KZFPqc18fXHcI7Y1m0cBcToRWZ8upkefwvjzOmP05TEeM86Xtpy5hs8XG4+Qn+peXVl/UhAYTFpk25PyShpBWWBwjsazQWA9574wXoPkQB/grmLxuY2TbWPg5LslRDwIBHaI8IrUkLPowemvp7SNIuEuZL2CC6wqBOYdpxizxsRwTSmca/rZutqp41hG 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: List-Subscribe: List-Unsubscribe: 在 2024/6/28 7:43, Peter Xu 写道: > On Thu, Jun 27, 2024 at 04:32:42PM -0700, Andrew Morton wrote: >> On Thu, 27 Jun 2024 19:19:40 -0400 Peter Xu wrote: >> >>> Yang, >>> >>> On Thu, Jun 27, 2024 at 03:14:13PM -0700, Yang Shi wrote: >>>> The try_grab_folio() is supposed to be used in fast path and it elevates >>>> folio refcount by using add ref unless zero. We are guaranteed to have >>>> at least one stable reference in slow path, so the simple atomic add >>>> could be used. The performance difference should be trivial, but the >>>> misuse may be confusing and misleading. >>> >>> This first paragraph is IMHO misleading itself.. >>> >>> I think we should mention upfront the important bit, on the user impact. >>> >>> Here IMO the user impact should be: Linux may fail longterm pin in some >>> releavnt paths when applied over CMA reserved blocks. And if to extend a >>> bit, that include not only slow-gup but also the new memfd pinning, because >>> both of them used try_grab_folio() which used to be only for fast-gup. >> >> It's still unclear how users will be affected. What do the *users* >> see? If it's a slight slowdown, do we need to backport this at all? > > The user will see the pin fails, for gpu-slow it further triggers the WARN > right below that failure (as in the original report): > > folio = try_grab_folio(page, page_increm - 1, > foll_flags); > if (WARN_ON_ONCE(!folio)) { <------------------------ here > /* > * Release the 1st page ref if the > * folio is problematic, fail hard. > */ > gup_put_folio(page_folio(page), 1, > foll_flags); > ret = -EFAULT; > goto out; > } > > For memfd pin and hugepd paths, they should just observe GUP failure on > those longterm pins, and it'll be the caller context to decide what user > can see, I think. > >> >>> >>> The patch itself looks mostly ok to me. >>> >>> There's still some "cleanup" part mangled together, e.g., the real meat >>> should be avoiding the folio_is_longterm_pinnable() check in relevant >>> paths. The rest (e.g. switch slow-gup / memfd pin to use folio_ref_add() >>> not try_get_folio(), and renames) could be good cleanups. >>> >>> So a smaller fix might be doable, but again I don't have a strong opinion >>> here. >> >> The smaller the better for backporting, of course. > > I think a smaller version might be yangge's patch, plus Yang's hugepd > "fast" parameter for the hugepd stack, then hugepd can also use > try_grab_page(). memfd-pin change can be a separate small patch perhaps > squashed. > If needed, I can submit a new version based on Yang's V1 version. > I'll leave how to move on to Yang. > > Thanks, >