Message ID | 20231116012908.392077-6-peterx@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2924207vqg; Wed, 15 Nov 2023 17:29:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQhj4Orx8d/tcZbxKVTJa2o0Yhfu73YXyPZ8GvLJqhrHrmmNnG2PfjHx/MpgfDgBgz4i2K X-Received: by 2002:a17:902:864c:b0:1cc:2771:6fbe with SMTP id y12-20020a170902864c00b001cc27716fbemr6491949plt.39.1700098182561; Wed, 15 Nov 2023 17:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700098182; cv=none; d=google.com; s=arc-20160816; b=dldBQtpxtg0RdTh245wm2d/ZIv+fYoQaMINlnIFq0NJnY3FBXn7mL3BVxfvvTHRDh6 B0dQGygDzbmVje4J3njGXs9MufRtolTB/zLDskPQoQ4ZzDLKEUaXGXAMeOsWq98Dv+HD 11rsN+RLUyGE9oYjKafooEtoJ6UBRVMLoyExlab3dyadB21PNXC2Sfdp1nr1oy64go4h M5esrpVpXVkoKeScmhWvMyqCZ4kDFEpDbMXWWcYo5/qNfbNhYJJTqXUJ7pqYJOohkZBM uqhuYSe3yLhIjTsyBi6OohDkrSznQE7ndM6JzOzBlvjYIiMcC4HdXtcOFVhCDqRb0HxF jz7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iVPh5vUSg15R+EjRvyUTGLnvTLGftOOyrePNaUJdD/U=; fh=o+FJD7UTEFgAOwGBZppViFyhRpBzPGRfoO/6xzRNnMs=; b=BB9AmIoagSzOs3qhJSko8eZB8Lykcj3sjKC8xokeb9CcpIf1fi/moaPJswqxdMPFcy ZBNZbHd3lm5vsnhhNCQk/c4dmBRTnqIwTdP9Stz+ln0e/21gIxlPQVYg5z6cQh14RpDh MyOCOCLDGa6e/RoYs3kbHQIRuEjSfqZ/HDNwY4Gi2SgTIjvUHDV3ydIJ6tKGOTLlSEhg fyI9kwXBTVVaymVcR22ntpcES9HgX7j/8vhy8BrQKdECStQsuXKKZhnf0rV3NJkasYYp TZ209braIOZ8K1CFt/21xUd5RhU5wnWfE5Wrg3l7ve9Ku2mGNLHohzKPZvFeLjLDcXUi m3/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JGtAcCe9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c10-20020a170902aa4a00b001cc2ef72ab2si10489836plr.68.2023.11.15.17.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:29:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JGtAcCe9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A7B3780E73DF; Wed, 15 Nov 2023 17:29:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344485AbjKPB3c (ORCPT <rfc822;lhua1029@gmail.com> + 28 others); Wed, 15 Nov 2023 20:29:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344454AbjKPB30 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Nov 2023 20:29:26 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA18199 for <linux-kernel@vger.kernel.org>; Wed, 15 Nov 2023 17:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700098162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iVPh5vUSg15R+EjRvyUTGLnvTLGftOOyrePNaUJdD/U=; b=JGtAcCe9WHOXOtrqPb64GnJVE6w2GU9IMp9LSE+DCMXMvb/Im37grqe9PWvvqtY4HcefFj WyIj0z31+EEpk2kdYStFkdrNIgI9U+cFwKMStyfJg7XNxvbpUGRqM2DvZHAThMl0jYI4L4 zPG1GL6D+HI1VFF8Be/T/EVW3xRIdMU= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-2VO4HHQ_NoW6PizvXzl5Nw-1; Wed, 15 Nov 2023 20:29:20 -0500 X-MC-Unique: 2VO4HHQ_NoW6PizvXzl5Nw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-41eb42115e9so899351cf.1 for <linux-kernel@vger.kernel.org>; Wed, 15 Nov 2023 17:29:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700098159; x=1700702959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iVPh5vUSg15R+EjRvyUTGLnvTLGftOOyrePNaUJdD/U=; b=EVLJgYzbG9zKeP5DkNaiA2171uiCSv9C/hxeJUnOv70IgsOv6/gSE8Qm18Sofmlnig YYmOqMdC7mYAPoH+mV3HaYCr38Dr8Q4uQ9+XSBjn0/C6iNNDvo9VBLJiOiZF6pqc1JII Nc2w9qhuZvfMBvLBtg2HyxoOEKfy82HR2Ah39v3xtXJG+lUmihqPc84RW1nOePihrAMv ELrUhGJB+SAsnHuGEgkx2r8toH2TKSqVfKPu+TVuDQZCleMQmuO/D8J00fr/gFqBUd1T ia9y+LZpR60K7OhuHrkqPTIfX+AXL7347oK1mUP8igHeempXhLNXRoss8yKw7p0OsU6+ /aig== X-Gm-Message-State: AOJu0YxfDVtwfqnbd+Q5vdzrIoYyS+bt29fhzaD1F3Ib40eLhmBL9Pv7 qvs79cMkLCjx3/xe7UUrXXiIVyvd7TGON4B5915qqtxJZSriCCmna5h9Vu1UW071Tg7gPJGncI5 EmxBx3JOcFG/4VciACw+od0YKoZ/wHo5YacMD8I7bWtu5KLw1H66ypsWzA/AD6c6uEKcjLokER2 fUWjveEQ== X-Received: by 2002:ac8:4716:0:b0:421:b9be:d4a4 with SMTP id f22-20020ac84716000000b00421b9bed4a4mr6891661qtp.0.1700098159514; Wed, 15 Nov 2023 17:29:19 -0800 (PST) X-Received: by 2002:ac8:4716:0:b0:421:b9be:d4a4 with SMTP id f22-20020ac84716000000b00421b9bed4a4mr6891630qtp.0.1700098159208; Wed, 15 Nov 2023 17:29:19 -0800 (PST) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id c24-20020ac85198000000b0041e383d527esm3922598qtn.66.2023.11.15.17.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:29:18 -0800 (PST) From: Peter Xu <peterx@redhat.com> To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz <mike.kravetz@oracle.com>, "Kirill A . Shutemov" <kirill@shutemov.name>, Lorenzo Stoakes <lstoakes@gmail.com>, Axel Rasmussen <axelrasmussen@google.com>, Matthew Wilcox <willy@infradead.org>, John Hubbard <jhubbard@nvidia.com>, Mike Rapoport <rppt@kernel.org>, peterx@redhat.com, Hugh Dickins <hughd@google.com>, David Hildenbrand <david@redhat.com>, Andrea Arcangeli <aarcange@redhat.com>, Rik van Riel <riel@surriel.com>, James Houghton <jthoughton@google.com>, Yang Shi <shy828301@gmail.com>, Jason Gunthorpe <jgg@nvidia.com>, Vlastimil Babka <vbabka@suse.cz>, Andrew Morton <akpm@linux-foundation.org> Subject: [PATCH RFC 05/12] mm/gup: Fix follow_devmap_p[mu]d() to return even if NULL Date: Wed, 15 Nov 2023 20:29:01 -0500 Message-ID: <20231116012908.392077-6-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231116012908.392077-1-peterx@redhat.com> References: <20231116012908.392077-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 17:29:41 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782682151779757430 X-GMAIL-MSGID: 1782682151779757430 |
Series |
mm/gup: Unify hugetlb, part 2
|
|
Commit Message
Peter Xu
Nov. 16, 2023, 1:29 a.m. UTC
This seems to be a bug not by any report but by code observations.
When GUP sees a devpmd or devpud, it should return whatever value returned
from follow_devmap_p[mu]d(). If page==NULL returned, it means a fault is
probably required. Skipping return the NULL should allow the code to fall
through, which can cause unexpected behavior.
It was there at least before the follow page rework (080dbb618b) in 2017,
so 6 years. Not yet digging for a Fixes, assuming it can hardly trigger
even if the logical bug does exist.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
mm/gup.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
Comments
On Wed, Nov 15, 2023 at 08:29:01PM -0500, Peter Xu wrote: > This seems to be a bug not by any report but by code observations. > > When GUP sees a devpmd or devpud, it should return whatever value returned > from follow_devmap_p[mu]d(). If page==NULL returned, it means a fault is > probably required. Skipping return the NULL should allow the code to fall > through, which can cause unexpected behavior. > > It was there at least before the follow page rework (080dbb618b) in 2017, > so 6 years. Not yet digging for a Fixes, assuming it can hardly trigger > even if the logical bug does exist. > > Signed-off-by: Peter Xu <peterx@redhat.com> I'd still add a fixes tag and send if off to Linux for 6.7-rc instead of letting it linger. Otherwise looks good: Reviewed-by: Christoph Hellwig <hch@lst.de>
On Wed, Nov 22, 2023 at 11:25:28PM -0800, Christoph Hellwig wrote: > On Wed, Nov 15, 2023 at 08:29:01PM -0500, Peter Xu wrote: > > This seems to be a bug not by any report but by code observations. > > > > When GUP sees a devpmd or devpud, it should return whatever value returned > > from follow_devmap_p[mu]d(). If page==NULL returned, it means a fault is > > probably required. Skipping return the NULL should allow the code to fall > > through, which can cause unexpected behavior. > > > > It was there at least before the follow page rework (080dbb618b) in 2017, > > so 6 years. Not yet digging for a Fixes, assuming it can hardly trigger > > even if the logical bug does exist. > > > > Signed-off-by: Peter Xu <peterx@redhat.com> > > I'd still add a fixes tag and send if off to Linux for 6.7-rc instead > of letting it linger. Will do. > > Otherwise looks good: > > Reviewed-by: Christoph Hellwig <hch@lst.de> When rethinking, "return page" is correct for devmap, but it should be better to always use no_page_table() instead for page==NULL when trying to return NULL for follow_page(), even if no_page_table() should constantly return NULL for devmap, afaict, so it should be the same. So I'll make it slightly different when reposting separately, please feel free to have another look. Thanks,
diff --git a/mm/gup.c b/mm/gup.c index a8b73a8289ad..0e00204761d2 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -708,8 +708,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, ptl = pmd_lock(mm, pmd); page = follow_devmap_pmd(vma, address, pmd, flags, &ctx->pgmap); spin_unlock(ptl); - if (page) - return page; + return page; } if (likely(!pmd_trans_huge(pmdval))) return follow_page_pte(vma, address, pmd, flags, &ctx->pgmap); @@ -756,8 +755,7 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma, ptl = pud_lock(mm, pud); page = follow_devmap_pud(vma, address, pud, flags, &ctx->pgmap); spin_unlock(ptl); - if (page) - return page; + return page; } if (unlikely(pud_bad(*pud))) return no_page_table(vma, flags);