From patchwork Thu Nov 16 01:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13457480 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 B2C6FC2BB3F for ; Thu, 16 Nov 2023 01:29:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48ED56B03E5; Wed, 15 Nov 2023 20:29:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 418EF6B03E7; Wed, 15 Nov 2023 20:29:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26BA36B03E8; Wed, 15 Nov 2023 20:29:24 -0500 (EST) 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 0F6BD6B03E5 for ; Wed, 15 Nov 2023 20:29:24 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D6FCF12041C for ; Thu, 16 Nov 2023 01:29:23 +0000 (UTC) X-FDA: 81462084606.22.C1F54B8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id BCF1CA0011 for ; Thu, 16 Nov 2023 01:29:21 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aaMlRdgz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1700098161; a=rsa-sha256; cv=none; b=7hdLAPbqYKCKqdaLV0Pe7XH3FyS0qpqbIufyW5Rk7YlGjH5sd+yvzmEXrECFRBRQHQYzAG UDF5plrCVBJOIi8+ZALobhU6Ci8W2Gvznx4YfciXC4xQ2UKiInq2EYDinDR8t5eSgzD6S6 ZzhscZfNAumo8njTj7UWoWsP5ADm6ko= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aaMlRdgz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1700098161; 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:in-reply-to:references:references:dkim-signature; bh=iVPh5vUSg15R+EjRvyUTGLnvTLGftOOyrePNaUJdD/U=; b=nwg6e/M01+LSBcHR6e8Q9wUpDnwppetpjz48ZIrMqXyliWMebVwnlNbOrAZ98oGhxuO2bJ FXtcKTOabgiHwYQj7ngZifFMIRunlh9U5HYbKHKRqiXZzZwg4dCvNEK/igeThieMI6VnWT S8mD493+BRXsmqKNKuiTzPPclERwCMc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700098161; 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: in-reply-to:in-reply-to:references:references; bh=iVPh5vUSg15R+EjRvyUTGLnvTLGftOOyrePNaUJdD/U=; b=aaMlRdgzjqAA+phZ9tlYXBcK2YG/2nG3Fuf9K895ifmdXGs4k7aH1nv/zT9ZzQZzRfwjdm +iV4sSQEAg1FlYBJpu3RBZ5eyZfI5LaefZJK71N5IT/AFjRtny4K3bfgUP1kD+2VW3zbdk KOwOpBL+RfQ0qDGB7ZBJH5B3dZOa1h8= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-iGh0QhGVOaCGhy8CXKvh5Q-1; Wed, 15 Nov 2023 20:29:19 -0500 X-MC-Unique: iGh0QhGVOaCGhy8CXKvh5Q-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-41eb42115e9so899281cf.1 for ; Wed, 15 Nov 2023 17:29:19 -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=P1c1tRJ+men8QgtmxN7moj0uYy94nyP0VdkqxyjACiRr5S6DlPnz8Pmzv0JsjOqW+m s/r8mzUIorbpCJairoCPY9F1i/1Rdx4T/cubqcf+IbW1NNS2VP7mkmOKBaUn12HOw2k1 Xje7pdh58JvAaMjEFgItS7SrTlVsDyLjDzp6q3NW0n+aQZRwL/zhDnOuy5I6AShmXyo2 YmFWdPPHtNDk7o6n6JVJOYYeEyi6OYo0TzbRnL4N/j1aWSAiRQedb/jTfVfqsMiqO9Jk 6lT3eYwzX//isuyUGW7B632tpR9u2NBe4kEyMD2dd4zzPbYh2yKkegfT9EWIJMrBAouL TVDA== X-Gm-Message-State: AOJu0Yy239YObwbuPKu5Gcef2YJGVDeFxhk17kjTduGC3xc3Dyt5HMnZ vHCdD7UtTEpDZNIIm7CdRPXQFpdEVSLNB7+iOyUisEyNkjWazEWqRqJ0hf8roeZpjCYDvhVnLxo s6X2NlfqJdJY= X-Received: by 2002:ac8:4716:0:b0:421:b9be:d4a4 with SMTP id f22-20020ac84716000000b00421b9bed4a4mr6891657qtp.0.1700098159444; Wed, 15 Nov 2023 17:29:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJxMhrfIQJHLleHfYWSj3v7NIOAggKaUbuvyUHKkhcdknXN7d9JWqJ2v9ElBIqwX+6WGc0WQ== 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BCF1CA0011 X-Stat-Signature: 6b9wj3qb4csomas3tmdkqjnnyhboca5d X-HE-Tag: 1700098161-817415 X-HE-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+zDir4o5waOHtQeuEZBovjZMLNwlFCKQTHskOTl9r3P+lhkShY7S/CNsg1KdABM4IX/H/gEWg1oygw5on9qMIPjgY5y+QaqPN/IkgiVsrFBpYLZiQ+wzqdFCss7lJDzVzPfTOz9znHyYE9iV27QYgcTEJm2IJfa7xip0pAd239eDf42G7eBE/ORlwIGIO5lIpWLwyMx4rJtaMosjtVkn3eP38lNl8Q+DjU+fkAK57V+LNvDRZMSsMfgnjEIK51i6o0Fgs/pcZ2cjWcJbbKVf9VpnKSDghTMcN0LRERwEND1ug06rSBvI2/0xhWfVUzngCYvI//ztGRZ1GLnPcCeIWdi0sfVdJxVxjEpvAeuLg== 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 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 Reviewed-by: Christoph Hellwig --- 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);