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 0FCE1C2BD09 for ; Thu, 27 Jun 2024 23:43:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A231B6B00A5; Thu, 27 Jun 2024 19:43:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D3436B00A6; Thu, 27 Jun 2024 19:43:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89BCB6B00A7; Thu, 27 Jun 2024 19:43:52 -0400 (EDT) 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 6C2216B00A5 for ; Thu, 27 Jun 2024 19:43:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EB1E3A0157 for ; Thu, 27 Jun 2024 23:43:51 +0000 (UTC) X-FDA: 82278298662.02.B666BF9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id C47B92000E for ; Thu, 27 Jun 2024 23:43:49 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BEeY2+rt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719531815; a=rsa-sha256; cv=none; b=ShMUVxuGkXj1dT7Dw5HV7BCORR6A3KilH6kdaxE2pyCE3/ZGpQJuwW3rSoxMJPb2wYvI0B t+l5Z+q86+Xsnba11MMYRpzo0AzFIhQ3VQYR2bw5/Xlep/5cPTtR0kxEKtB5i9+qvhFxbL L/xGEqYZJrhe83S60B6P64q3DtjAIcY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BEeY2+rt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719531815; 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=Iihd8gyXaTK/eS/7NE9gghzxDsNIhcxbmKKrWECTt2U=; b=jy587vB11oogb/lY2gfomxNihvfKOWq9NlHWbBpWoss4ZSiXMh0gJVL7LpsFoZGPtByPfD E8z+5uT2mUIjcjnzVEOC6jsjzsiHzsHsK27nHZexeXVWA1Ae6ViYBxjPxtm/d8JZjxgVDm 0IZ/+JMyHqcKFJ5l2Ps2cN51wojRZK0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719531829; 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: in-reply-to:in-reply-to:references:references; bh=Iihd8gyXaTK/eS/7NE9gghzxDsNIhcxbmKKrWECTt2U=; b=BEeY2+rtdesnFfmVylHLxRzqayM4qFsMHREuzxwDiOnAHWYLKEFigUPApsGiLgOTmBH7ri U86emz2Vl4BSZMm8/5liRQKiJYDvsQzb9YZgZS7QEobJP974k/JgAtgxuqM5uh2/t5k4aK P1rmTqpc4VcMCdtB2uFc9ZzI/JYq8eE= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-2XMshr0UM0GN6xSF3XohYw-1; Thu, 27 Jun 2024 19:43:47 -0400 X-MC-Unique: 2XMshr0UM0GN6xSF3XohYw-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3d24b04815eso10791b6e.3 for ; Thu, 27 Jun 2024 16:43:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719531826; x=1720136626; h=in-reply-to: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=Iihd8gyXaTK/eS/7NE9gghzxDsNIhcxbmKKrWECTt2U=; b=MSpLblQQxHI69OMYrmdpMYfFdaRHQXrSF7c6ybmBo3h08SEoO8H9qqqOA3MOeXu5fb neMksxu1Ak7846HvDwmXomzMypVUcA4hE5gRi7jHVNrpEp7JyNUZrQNz2oSIohudHtWn xCAiA/8NiCGNyswe1wukTvvbX0coENl7/37CeridmO5pb7KPVIMB72zNxz5I5K7pu+IS T6n/8CnZLaOms/O1HjFKz5xxYREZUSiaeXRFOR5P3HNHnHGJMTZA38ChQilVmpVbIXIo OrsM0NykkJ+X0YtsbwDhHXGFoLbV5mVpLMTDc6Rcy4GaWH/60cipp3ZLugIfUCtVPpOP TBYQ== X-Forwarded-Encrypted: i=1; AJvYcCW4OAMqhRBRUIFnWiyDdGMCWBLAVa2+psj49z7s8UjymNKgdnTUSWAgM+1+fSqB6mNRz+XAwprnWgX/irfqj7wrvww= X-Gm-Message-State: AOJu0YxFfJTRCGwOXx3rEd9TLH5YAgMiVY0+P07kgUVHf62cZ+uG9C+g zash4PQr2IG7Qe9UBdvgjrdKjYi6u9rg2GbZvXQ4WJjjFPUi82tB1vkAr6IfWXM8jiAwF9nWsIb qe2LCUcRHePH46uLD/Ff9mxlpNJhwvECKl9P4udnrT59R3YGu X-Received: by 2002:a05:6830:4581:b0:700:cd64:b65 with SMTP id 46e09a7af769-700cd64148cmr7374922a34.0.1719531826435; Thu, 27 Jun 2024 16:43:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9FkEGY1E26IdOAs8EQP58uudvAQdli3PHkfSqokwSqpokiAmzs3MKI6eyPxywyIZHfUTa4A== X-Received: by 2002:a05:6830:4581:b0:700:cd64:b65 with SMTP id 46e09a7af769-700cd64148cmr7374907a34.0.1719531826023; Thu, 27 Jun 2024 16:43:46 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-446514b2484sm2671841cf.81.2024.06.27.16.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 16:43:45 -0700 (PDT) Date: Thu, 27 Jun 2024 19:43:44 -0400 From: Peter Xu To: Andrew Morton Cc: Yang Shi , yangge1116@126.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [v2 PATCH] mm: gup: do not call try_grab_folio() in slow path Message-ID: References: <20240627221413.671680-1-yang@os.amperecomputing.com> <20240627163242.39b0a716bd950a895c032136@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: <20240627163242.39b0a716bd950a895c032136@linux-foundation.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C47B92000E X-Stat-Signature: njwxdtkbt3bqhjtwx66bm361sz7395zr X-Rspam-User: X-HE-Tag: 1719531829-167350 X-HE-Meta: U2FsdGVkX1+6Iv5NyBLB/CSwVj3clN6+6q1l8+NaUMA/QqNH1loxZN7gG8mf5HPoSsxFyUdG8XVYnPEqH6neXsBXQLafGWIOISR0699JYHJ314+m9B4jlkZgcgFAZcxXG/3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5+wfGognSLCj1wYg6zSKPSm9hx05d9q0Tp2VQ8DFME7D97Muxeixr/sx7Q/s+jiSMKcVxMxY2CnD7iNd3D/Zf0IzzjTHCNfvGqEHx6aBdIyvChlmZsel1zFQEwzYAJySJemnlaRFz+RXwBWvrhvhL3BUfgeaI/9GEhSjIzB3Z4LgWcdv3BLGVIiSuHYWcYaKyU 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: 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. I'll leave how to move on to Yang. Thanks, -- Peter Xu