From patchwork Mon Nov 26 23:31:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 10699369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B806813BB for ; Mon, 26 Nov 2018 23:31:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A927A2A63F for ; Mon, 26 Nov 2018 23:31:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D9442A642; Mon, 26 Nov 2018 23:31:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32AC02A63F for ; Mon, 26 Nov 2018 23:31:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DE2E6B4471; Mon, 26 Nov 2018 18:31:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 58C956B4472; Mon, 26 Nov 2018 18:31:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4552F6B4473; Mon, 26 Nov 2018 18:31:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 01C436B4471 for ; Mon, 26 Nov 2018 18:31:19 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id w19-v6so22292428plq.1 for ; Mon, 26 Nov 2018 15:31:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :in-reply-to:message-id:references:user-agent:mime-version; bh=zVzA8Mp4h/6ZwRFyfdsiGQfp0RMyxpY9T9eRR6DfAgs=; b=cVXUmdusBy8BBQ/ysA4ZUUZPCE8uKCgs9jhUGXWYCjeAYG3DWGph9o0hgxl+mWzJYg aIBOe37KOdYP68vAE23c6AM6ZFwdCXtYvCCJctkd2yTTFaVTq5Pgmc+5iCwkT7RdUU6l q5if516dimHBUC4uB561axvZ+d3jrF4oC3uCldvk5xO4MPP6e/4BgCfz5B3pxL6HB2GY G5kso9Losy0xwyC4W6GIpb//uL6dCJvJZpuH0E/MzNo3sAioNwkn/Poe1kDFKGGD7oce RI9oyAmxVrMYgAaqgn2izQpO1/zG2BDPUaELzm7pPa3GPtnd6tkp1Ph8QG5t85BuQZqN GrIg== X-Gm-Message-State: AA+aEWYDyCAyQovNHmBgm7od/wFyxuWYM8Ced6M027b/pH+DzqjLworA 0HhlobximYwUXHpLPsnsn5OaXsCXxA9ukSvkGEgF+LRGDSd0muEpLo0KbUa1VYNYiLm1PhKcJ4K Jp4jj8NL3y/WxahOBI9NCijQZ6c7L0VBZF+qGVcnwncaEtYWXTwFAN5UssjVkUaeLeGx3WH75PI TRwtVHmoEpbnjAMs15/H60y9HOIAuFs2/biyV+/lmghb+7PCruHb5A8fBrPMLrBRnKacWorEo0L +fALDqiyW/YI2MgzxrAQw+Phdq3kg1ZOaVTrDsuHJcz0q6ll/oL2nmwZouN7QxcG1FUoxgVM0Fl lXx/LpfqA0LFrRR3Q2TDip1Fqr1tMI8KKiPg0KpCr2WFqmmt46oYfWfb/SWRkVx0WkKgiJbOmRL v X-Received: by 2002:a63:4f20:: with SMTP id d32mr26898746pgb.47.1543275078645; Mon, 26 Nov 2018 15:31:18 -0800 (PST) X-Received: by 2002:a63:4f20:: with SMTP id d32mr26898696pgb.47.1543275077838; Mon, 26 Nov 2018 15:31:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543275077; cv=none; d=google.com; s=arc-20160816; b=IVimCFFvaxuYExO80G5SA+rChmFTnRU6ZnV/OJljgvGzrYzuiljuyKgyh1HY76/ZoA Q3qbISbnbVQPvWWjaaV75C77HGPDSuAo67UCx+Wyu6iT7TXIT77+O8xoJkljCr8tbuVQ AUEwSHUNHGtQye1sqmHJASs8hrYYmNlehgYRXHQCsSTR/RI1RyCNLK9pJWjxFcmTMMb4 Z1XVfz0oNRhXzl4U9O7Vzh6LrmawAqKJba+5yZvwbLK6oM7uIUAL5w3ZQUjp25VX/zdF vkurKEMSmdY4g2l+kt5vnkzvbjtkSw4CHZNjtdo7rzsmRtieJEew54I+DICmSmadNhSL C0rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:dkim-signature; bh=zVzA8Mp4h/6ZwRFyfdsiGQfp0RMyxpY9T9eRR6DfAgs=; b=GsR8d9MNXTZijgzKtJRxNV8cegH3oQqdNOYG5awFP+O6GHzF3htAWAw0Cp51lxI3P2 eliwcJRSbl1lsPsfqfJY3EaKwgLyQcEKZJAnmA16509FHZHyGE3PsNaPM0ZyQoeZKr61 NRFZ1/OKbz4Snjhqwotjwm6qjK/7btCVhXL5vVtPpg5ctacpmCaU5hQ8p6fq/Vs60/AS nvBciQ0PEnuhFj4gaayNPeLe2zY3MqbI4TEj3g2tWRRnzazZL5aT/VER0yIKSOanY4fO 7GDAUmK7vxwfYzQ5T0RMbWpixLQaxSvprO+uveAqbu3eXRLhY/8EHKn2WfHVORKWl1+u nkXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HsJSpizO; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q15sor2537704plr.34.2018.11.26.15.31.17 for (Google Transport Security); Mon, 26 Nov 2018 15:31:17 -0800 (PST) Received-SPF: pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HsJSpizO; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 :user-agent:mime-version; bh=zVzA8Mp4h/6ZwRFyfdsiGQfp0RMyxpY9T9eRR6DfAgs=; b=HsJSpizOSdjB3Vxed4Eyk8bCyskpFvAnzktWRkGCPqDa5PwDqEj1MeLHgA4NkFVKUV GfjWDIze+EhWGLami33PyCHqq1MEdL8ZUqIH+m8cT6rca50RI/wAEI1PCvArqCH5H6vZ dPf07LlmcHy6Uln73m16E2nmZP8zjU+c+1gIxy+5QZtvtg3Vxf5JwuOtwUwTGv/N55bt 6UojtCxNnCG3xRyi9y8ybzwhLa7gAjMSdDtyePxzOMt0OMkEawEBwC32NEXDPKeuV0Hd K3FxSzcf+J7EkuEaoHDfYl9pEMbBAT1yrX9u2gzLHV9CR3v+m82Kb0gLbYB+ifbksxcu yJuw== X-Google-Smtp-Source: AFSGD/X3JGNl8UgIBSdaKqOITIAiEm3NGBiWWvaqT1RtOflNNijsYX/JDpHQwkGVxwD/J459+OUE+A== X-Received: by 2002:a17:902:7c0a:: with SMTP id x10mr30351675pll.65.1543275077124; Mon, 26 Nov 2018 15:31:17 -0800 (PST) Received: from [100.112.89.103] ([104.133.8.103]) by smtp.gmail.com with ESMTPSA id f62sm1594471pgc.67.2018.11.26.15.31.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Nov 2018 15:31:16 -0800 (PST) Date: Mon, 26 Nov 2018 15:31:15 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , "Kirill A. Shutemov" , Matthew Wilcox , linux-mm@kvack.org Subject: [PATCH 09/10] mm/khugepaged: collapse_shmem() do not crash on Compound In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP collapse_shmem()'s VM_BUG_ON_PAGE(PageTransCompound) was unsafe: before it holds page lock of the first page, racing truncation then extension might conceivably have inserted a hugepage there already. Fail with the SCAN_PAGE_COMPOUND result, instead of crashing (CONFIG_DEBUG_VM=y) or otherwise mishandling the unexpected hugepage - though later we might code up a more constructive way of handling it, with SCAN_SUCCESS. Fixes: f3f0e1d2150b2 ("khugepaged: add support of collapse for tmpfs/shmem pages") Signed-off-by: Hugh Dickins Cc: Kirill A. Shutemov Cc: stable@vger.kernel.org # 4.8+ --- mm/khugepaged.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 55930cbed3fd..2c5fe4f7a0c6 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1399,7 +1399,15 @@ static void collapse_shmem(struct mm_struct *mm, */ VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(!PageUptodate(page), page); - VM_BUG_ON_PAGE(PageTransCompound(page), page); + + /* + * If file was truncated then extended, or hole-punched, before + * we locked the first page, then a THP might be there already. + */ + if (PageTransCompound(page)) { + result = SCAN_PAGE_COMPOUND; + goto out_unlock; + } if (page_mapping(page) != mapping) { result = SCAN_TRUNCATED;