Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp516137rdh; Thu, 23 Nov 2023 10:02:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFURlsF5wfbQe1F8nZ2nRJsI1VjpFRrpQaeo0Dab7q7b95vy3PjbXOS6FAk8o1tUAq3GvCS X-Received: by 2002:a05:6a20:1594:b0:18b:a51c:eb4b with SMTP id h20-20020a056a20159400b0018ba51ceb4bmr489473pzj.14.1700762576002; Thu, 23 Nov 2023 10:02:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700762575; cv=none; d=google.com; s=arc-20160816; b=LTUk2hVARJYf/Jg1mBXRJY7QcMHx4Nc4PiDw+bv8tuDUq+klAT8gkcZZ5qnJG7klYj U9mfkJ4RgazOHlZI82In0WS0hTk1gcbxDI0NHRXEavYPnNno8vJBGexz2OKtgZsoE+PZ T9wA8EsyAN++GROR+mLXl5wnmnSLbgqJcCOOYPTcsiFzqM8h/p6n0NTmG9eoi7LdBepQ j5QQSI9IIW8FRKKPkr5Z04kSgIySH9/DhkR+XNrvGM7IWoDhP1orgMQM46z323p9N1t4 5JvbWFjODeO9A/7PjWdXPFskec3ZPSTFC/bulTSesTUqksJwFsXaubZyEi3cuxiB/Jf6 9CYg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=4EEXViqB805TEJLl95Oc48y0HOh1LGI/lPszglbnn4k=; fh=1h37GgTKWT2dcNXRShUqFifROqUVIkVTBR9DaxLTIOA=; b=0SII2KjFig7bY0+ttPgJBUTqISt2vkekvyOdbTOFgitu6LmyIO13GyA/NkDQ1JtRVf u0JZsdH3+d7X0ZCVSHkkVgn46s/izrl+m86yExCTpwBqFCHrdRPZoEazoCqNmgFe5GH5 cC+WgdA0/2CKTMMZnHdxwVHuXaXq3Hq0Tfs/gJf89iCuZk8M2/vVONNFOd6vtk9dI9OP UkshCFmMBUziFf/LwOoQ1viTNxVSwLBsK4lui/fSs2ID3g4QH+xtGgnMWVEp1SjwmL39 /3Jy5n0GvStN4QPrOW8uMXT6QWfZ429WRjTeUfyay3cKCyrJydxDb932t2R9ZZnUcVOl yyVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iQM2FzLO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id cn2-20020a056a020a8200b005be09b7cf8fsi1677009pgb.102.2023.11.23.10.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 10:02:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iQM2FzLO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id AA47E809B9D5; Thu, 23 Nov 2023 10:02:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229981AbjKWSCW (ORCPT + 99 others); Thu, 23 Nov 2023 13:02:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjKWSCV (ORCPT ); Thu, 23 Nov 2023 13:02:21 -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 E8FF3D41 for ; Thu, 23 Nov 2023 10:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700762546; 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; bh=4EEXViqB805TEJLl95Oc48y0HOh1LGI/lPszglbnn4k=; b=iQM2FzLOiwoYKUGqIMdAHh3rSeG6/y1SK/SWyDhqrOyVm9itztVZn9boGg1BlyZbLVsk/S MfGDcU56elmktZEQ408DvZJ99qt6jo59swYjG7R80WRtxISLG09xmrmoNglrURmJu/Yqe+ b1TUIQx9f4wMiRrVXna+hTEaUaHwPBw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-aewL9pyOOc-jHFR0DY4Hdw-1; Thu, 23 Nov 2023 13:02:25 -0500 X-MC-Unique: aewL9pyOOc-jHFR0DY4Hdw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-67a05428cceso2146146d6.0 for ; Thu, 23 Nov 2023 10:02:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700762544; x=1701367344; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4EEXViqB805TEJLl95Oc48y0HOh1LGI/lPszglbnn4k=; b=Pm+zGSrbyvWYMCO2e/AxE1OdkIG5pp94liJKQ3/jNPIlpXLWaGh5OnhPVRGHX76feo YaZ3E3zfdhcoxDwaiI4COYbZwkrybXMVMW/lZCQbuwNGZfBhh7JYtdik+3D5NiuJnIQ6 B/df5fuCXLx2HEmkzPxU3J6PzaGtuT2G1Dtrx85/CSPlUBox8JhdsF+99SSp8zPOmGHP KQWy7Qde7re00dUxq0naXfsQLffOdQk1COwJd17NKvmDysNMdfdVMvT5GDTLCQEWX0ou W7E4Aob14HGt19sUagFjKc4GVNDYuJ1bOdXnobI16+U9P/CaDxBp6JQ+AIaC/+RiRck/ Q2Rg== X-Gm-Message-State: AOJu0YyDllhig5Rk+hCzbL4nu7OKnaDq25uwpfCaAp1Tg7j9Ah9eAoYa QWQEVVuT65p8ZEGeFVD8+p23z97rOHKc90WzaVHGRi4fjiSarBqRUpKutBlSDCGMUvr49JAKDvi MwIJkCLRQ4WYhksKD79yCPljrS2m+yQse X-Received: by 2002:ad4:420f:0:b0:679:d8a9:ef41 with SMTP id k15-20020ad4420f000000b00679d8a9ef41mr273790qvp.0.1700762544394; Thu, 23 Nov 2023 10:02:24 -0800 (PST) X-Received: by 2002:ad4:420f:0:b0:679:d8a9:ef41 with SMTP id k15-20020ad4420f000000b00679d8a9ef41mr273772qvp.0.1700762544131; Thu, 23 Nov 2023 10:02:24 -0800 (PST) Received: from x1n.redhat.com (cpe688f2e2cb7c3-cm688f2e2cb7c0.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id s2-20020a0cdc02000000b0065af9d1203dsm693210qvk.121.2023.11.23.10.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 10:02:23 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Andrew Morton , Dan Williams , Mel Gorman , Matthew Wilcox , "Aneesh Kumar K . V" , Christoph Hellwig Subject: [PATCH] mm/gup: Fix follow_devmap_p[mu]d() on page==NULL handling Date: Thu, 23 Nov 2023 13:02:22 -0500 Message-ID: <20231123180222.1048297-1-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Thu, 23 Nov 2023 10:02:41 -0800 (PST) This is a bug found not by any report but only by code observations. When GUP sees a devpmd/devpud and if page==NULL is returned, it means a fault is probably required. Here falling through when page==NULL can cause unexpected behavior. Fix both cases by catching the page==NULL cases with no_page_table(). Fixes: 3565fce3a659 ("mm, x86: get_user_pages() for dax mappings") Fixes: 080dbb618b4b ("mm/follow_page_mask: split follow_page_mask to smaller functions.") Cc: Dan Williams Cc: Mel Gorman Cc: Matthew Wilcox Cc: Aneesh Kumar K.V Cc: Christoph Hellwig Signed-off-by: Peter Xu --- mm/gup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 231711efa390..0a5f0e91bfec 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -710,6 +710,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, spin_unlock(ptl); if (page) return page; + return no_page_table(vma, flags); } if (likely(!pmd_trans_huge(pmdval))) return follow_page_pte(vma, address, pmd, flags, &ctx->pgmap); @@ -758,6 +759,7 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma, spin_unlock(ptl); if (page) return page; + return no_page_table(vma, flags); } if (unlikely(pud_bad(*pud))) return no_page_table(vma, flags); -- 2.41.0