From patchwork Thu Nov 23 18:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13466523 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 C694EC5AD4C for ; Thu, 23 Nov 2023 18:02:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BD816B06C6; Thu, 23 Nov 2023 13:02:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46DC86B06C9; Thu, 23 Nov 2023 13:02:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 335056B06CB; Thu, 23 Nov 2023 13:02:30 -0500 (EST) 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 20FFF6B06C6 for ; Thu, 23 Nov 2023 13:02:30 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E021240E02 for ; Thu, 23 Nov 2023 18:02:29 +0000 (UTC) X-FDA: 81489988818.03.69A624F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id C9E9F1C0035 for ; Thu, 23 Nov 2023 18:02:26 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RZCRR6Cp; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1700762546; 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: references:dkim-signature; bh=4EEXViqB805TEJLl95Oc48y0HOh1LGI/lPszglbnn4k=; b=x8Ts1O5r1tg9wyCTdVbUnvAZ67SxbVCP50QvxmIW8B7mQnsw+mOmsPvnmKbYwaUO+57x87 IzdKPWJpwOoZc+0WDurWehZTNKP4D/CniEFCAI5s/dtWYSI4tE3GNoGkrHxkUdjWDrFbrg VWAB9brLPBs4AiLYc4XXRNWVKqRMH5w= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RZCRR6Cp; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1700762546; a=rsa-sha256; cv=none; b=bWo8CfqRyKggksKZ6mohN/jilpUybrvbCgPhNBbtztFdzt0dhgaJxT69wBKEuPCWu7dhH9 mZlmZLQGp6rPJJ3OAaHDhvrr6cnfMECIbAsCAP82YIzKeZoWDfDDWATOdIY86SCULy+vYW LcK1l84iWvTX92AgBL2vZPg32YqQIOQ= 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-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4EEXViqB805TEJLl95Oc48y0HOh1LGI/lPszglbnn4k=; b=RZCRR6CpN3eUcwKfnOh/W6BE479IjkEfFhuUz+DUSoPtp/Fo+scyb3fC61mMNvbFNwspYr wCMznrAxQ3Y89RCxpG54YRU+7dPVjz5nbhN0ATPTBkkm9GJCsRmN1O6PqHHo+byS4semiT zAoYO1yoeFlu1UWiYu1eY93RH0Fsbg0= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-35-OL3AoIGrMqmb2AMR3dpn4g-1; Thu, 23 Nov 2023 13:02:25 -0500 X-MC-Unique: OL3AoIGrMqmb2AMR3dpn4g-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-67a06b43afcso1967506d6.1 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=tTMxc22/wDPzWN04pGTbmre+PzfC5Bd1eFhTVc0s2lPF38fRQX7OXxF8dbpW4gs79s 9P46XTXxxduaFc3bOKWjEXQVvvlLMG8FsFcjVT0hK8J3dt6Hz1P5HcFJOQ3NcefeqvqW EhgtB+CXsjB1X0iv0qpWY6MdTftEDtjl5VYOy4tkKWPQnUzT8vbb79kn6vA8fzqLib1n oyOoT1+CWqg4ScdPDpzyS6UMuecUUbU1TBLSciXNw8K1Klja3STuu/rd3RBOJGY1BgHQ vseFQ7hZXOY/nmkQ5cLYQMshnypcXRZviKSqtvxKp08pjotKDYrZpPEmIyo5kL05Gray xQLQ== X-Gm-Message-State: AOJu0Yx+b5cbiVKNQslFqPLZlAO1QnNpCVgbKjsCNHUGJOgTDHxjZJjS hm37hiIRbknCAwhDWxuXH7rd/qVEGDi3MyvrABfn68JkfrC+axoDeCm8hnRFEyOOmGxcdhSx2Zc d7GY3vCMDrqW4LfGzAkNLhkD8/pWOSHoSrv8zSgJwpBPBSYB5rDJTDwV3GHZDP2GS7tVI X-Received: by 2002:ad4:420f:0:b0:679:d8a9:ef41 with SMTP id k15-20020ad4420f000000b00679d8a9ef41mr273808qvp.0.1700762544502; Thu, 23 Nov 2023 10:02:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUr77F/yyuIsbmtEQQMFGKhS5qNFNQVBgvQdBpyjkNFaD58T2jqzyON33YgIFslunf28Y/Jg== 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: C9E9F1C0035 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ginxfr8xkp4c6hx4hz7g543g94ukh5q3 X-HE-Tag: 1700762546-709315 X-HE-Meta: U2FsdGVkX1+C6289tGfR4J7oOJFnm1GWVbbfYcnqfA04JTIZuyUCsHwlMKjuCkVX0GBYi5IglmZ0UEx6EWjfq7tnjCBzVYq0jU1gRKPIOMKmPwTrB45C+nG7mkcDaanVfk58w+HqSgp2LIydva417fGlxwMOgQX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kyKmmiG4XuLWIChq4OnkgwfQ69/Rz50Rd0Cg+2ej+OigXkDHPQsFicK7zjqX+5EBM2mtZFYBYEMojCiX4uInCXEp/QFccngftdMQLxt7sQWQu6tOCkTWpCwzZxLTHR2EX2z3UhNUEIFYkrQH2favfSddo2WluaUmvuH698X8a0z/k30Fp5dNfDT9rR0Ns3TVdLTd8iSfQYcRxm7MAQ5E+CI8g9KoSXOfYXj1muUF5uhW6sZi1/MhBW6/NkStDGIfCMqL6qx8BPcV34bW8nvYy358ZUtd4pC0DSH1hZFzYPHRXA5BIPJGNl 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: 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 Acked-by: David Hildenbrand --- 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);