Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2984712rdb; Wed, 15 Nov 2023 17:29:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm1qNFbZ0xvTU6el8NHpaLbv/m1mPP+p3UBg9TDQtnvpJKXK4rSeGQ/ofzCkYFOi9eR0LB X-Received: by 2002:a81:8a41:0:b0:5a7:fd05:2af2 with SMTP id a62-20020a818a41000000b005a7fd052af2mr16362569ywg.2.1700098186125; Wed, 15 Nov 2023 17:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700098186; cv=none; d=google.com; s=arc-20160816; b=GhUjEVwW09qpj3mLKx5YomsjRaeNh07DS/rDDSjRULCG7s1DUsB640dlzLbZG/5u8o xiSxd+V26KspuJxyOpDfO8eJzqkCJ6BnmyL1S1CZ0xDPKq4GGjq/oBmI/1mVsvc8S60V NjX/iTfVqozWLLEHLo4odpPtfije3ayE/FfBykOFig5g8J9/+XdOA6zl1CAhvhhh/nhZ u7qAudIpah4lROy+SPeZm7R9eVlsqbqpYcSYNmaZN2St/z1c0+En/4jsWsiwSHfwy33t XCqFHPt29Dwr6ru0AxD6Qh3NpkC+6wV5J2SBQFJkAI98LzLXvV2Zi10dGKVc1DIliaIo XzsQ== 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id fb23-20020a056a002d9700b006b28fa70b3bsi11170299pfb.86.2023.11.15.17.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:29:46 -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 21CFF80E7130; Wed, 15 Nov 2023 17:29:43 -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 S1344481AbjKPB3c (ORCPT + 99 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 ); 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 ; 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 ; 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 To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , "Kirill A . Shutemov" , Lorenzo Stoakes , Axel Rasmussen , Matthew Wilcox , John Hubbard , Mike Rapoport , peterx@redhat.com, Hugh Dickins , David Hildenbrand , Andrea Arcangeli , Rik van Riel , James Houghton , Yang Shi , Jason Gunthorpe , Vlastimil Babka , Andrew Morton 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: 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:44 -0800 (PST) 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 --- mm/gup.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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); -- 2.41.0