Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5144127pxj; Wed, 9 Jun 2021 10:06:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3Kqic/K3pf8Qn0xvE7jzkPOoiPh7iqfiOXVho/06k3qSC8ZvyILjFkPGxq2gayKFuJtQ+ X-Received: by 2002:a17:906:8988:: with SMTP id gg8mr882423ejc.266.1623258417724; Wed, 09 Jun 2021 10:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623258417; cv=none; d=google.com; s=arc-20160816; b=BVrVq8uggn0N5yfpPb5O9aEpyJZCw+D2TZCg6f3AcqNIg39/dyheGPfsG6bhop6pXy TJAiMfpMMj158kcz9vLgDc1sJkfqE4IovEjelqYfLuEQXZZTlVykipPUwF1r3BwwMH71 88CHOmRkkfWCdAX4dpgVAHMGWgawqYvN2WeLziZG3GZqgex6xRWQvbCLydc/9EN2GMMk g/vTu21bLHto5CaCbYF8oHoKqxsJI0XVrKD+Q/gCCGh1Osa1v9xQIM5r6p2ama1dfFyp GkN0lgBR8dL7orAEtoYzinKi5DUiw3rw2aIFIUKLHf6n82ePaTiTGyfltoTUGwt/bcBz ywrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=pMyjc9CYqvbfrzl29URaDu3TgxtX0dXCEwyNP3GAvus=; b=EmAKMu4Psx+uUGJrbXLGhBN2If2a1zuHAN/R2GYlPGgn6IcPuHANnQjl9y+ycLo40n GcOS8Yb76lLbGS827+Bayhp4CoksydatGKSnfn2z2DB45gN92eUiwZWW7/N1xCdocKPv IG3/cKKM5Tn7ueOdM+cRNAoeDKn1gEdNNuQy79AgSrhcxKzLMwhc7jfb3XiihAgDBRiC lF+QlgG9bqY78yTq3A+yrzj13HQvT4ttQBUiGQo/P2HwJihZY2kL6YvejhVD4FDEJRC1 0iGy3YsjUtX+sSjCklJdYcXj2Y4cUgdzhXo45M0H388V3X3yRRup+gmr24QuZdI0SLzE wqeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=e+RJ2E4Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v22si263991ejc.505.2021.06.09.10.06.33; Wed, 09 Jun 2021 10:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=e+RJ2E4Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231233AbhFIEUH (ORCPT + 99 others); Wed, 9 Jun 2021 00:20:07 -0400 Received: from mail-qk1-f175.google.com ([209.85.222.175]:38843 "EHLO mail-qk1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbhFIEUH (ORCPT ); Wed, 9 Jun 2021 00:20:07 -0400 Received: by mail-qk1-f175.google.com with SMTP id c138so9629039qkg.5 for ; Tue, 08 Jun 2021 21:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=pMyjc9CYqvbfrzl29URaDu3TgxtX0dXCEwyNP3GAvus=; b=e+RJ2E4Zeq65xDwtDBfefBHjqSQnt+ObhFB8cWd4WRWktC46wAECrkAZKegtHdI57U HyS/iTRZE/hQ/0dcjCit9KO1wTdujI5nzTGsQKyg9bQ9N2gU1tj4YVT8ng8kZREo+E96 xARjzVhT8FwML3scpPqULTgmVCY4SQM+lYFSWhA8HS/odAxZoSccQjNwV2nTcEMzZSqQ DIY1QHUYRNURhsUZE2XmNWgYyGCdf5Aae/6I2/mYb8dovDNSfNE1rHjzju6+5ttvsrpP qJbZyxiXkKTI3g8+QTZRDVwQ/qMO+rxvZW0EGckKBU+OweiVkeyZ3hQbL4N4AXxrI7DL 0XyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=pMyjc9CYqvbfrzl29URaDu3TgxtX0dXCEwyNP3GAvus=; b=hSe2qO4mSqIfIpC+ynNAUP2244hqKLc7bEjWO8ckFTe3V6uGzjQAxCqfV/ttoeZWtw e/2OKDSPwWN0g4MAEfm6IqPEsdgtqFXehw4Vz6dsLzn9my09832wXKaVXWgyQVHvQHfj SnLE35uVqodah0fVeZiZLCaQba8waG0EJfZD3/J6rXtzX1QkdqVPxnet6Wi3fVtWxqIY /95yFAYW19HLfpIlNCnCL6LAEHJDJ2FNKgb5U1iv+w4bSs+BtrCrIpltz4zrlFlYr+y2 oafGj+yDKzbeh8aDPLeHwI+rn6EnuCuXHm/Z/vke5xPn5FX8xpH7hyybTk3OKE8bWSRh L+hw== X-Gm-Message-State: AOAM530jvHgfYcrnJjTq5BY/HkzrjT93ujhYFc2Rv3nyCRVhh++OURxk BZbILmoq7YW7WeCrJFXifwLQ2g== X-Received: by 2002:a05:620a:39e:: with SMTP id q30mr25347667qkm.116.1623212219181; Tue, 08 Jun 2021 21:16:59 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id k19sm7673587qkj.89.2021.06.08.21.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 21:16:58 -0700 (PDT) Date: Tue, 8 Jun 2021 21:16:55 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , "Kirill A. Shutemov" , Yang Shi , Wang Yugui , Matthew Wilcox , Naoya Horiguchi , Alistair Popple , Ralph Campbell , Zi Yan , Miaohe Lin , Minchan Kim , Jue Wang , Peter Xu , Jan Kara , Shakeel Butt , Oscar Salvador , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/10] mm/thp: fix page_address_in_vma() on file THP tails In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jue Wang Anon THP tails were already supported, but memory-failure may need to use page_address_in_vma() on file THP tails, which its page->mapping check did not permit: fix it. hughd adds: no current usage is known to hit the issue, but this does fix a subtle trap in a general helper: best fixed in stable sooner than later. Fixes: 800d8c63b2e9 ("shmem: add huge pages support") Signed-off-by: Jue Wang Signed-off-by: Hugh Dickins Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Yang Shi Acked-by: Kirill A. Shutemov Cc: --- mm/rmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 144de54efc1c..e05c300048e6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -716,11 +716,11 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma) if (!vma->anon_vma || !page__anon_vma || vma->anon_vma->root != page__anon_vma->root) return -EFAULT; - } else if (page->mapping) { - if (!vma->vm_file || vma->vm_file->f_mapping != page->mapping) - return -EFAULT; - } else + } else if (!vma->vm_file) { + return -EFAULT; + } else if (vma->vm_file->f_mapping != compound_head(page)->mapping) { return -EFAULT; + } return vma_address(page, vma); } -- 2.26.2