From patchwork Mon Jan 21 07:57:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10772827 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 041CA1390 for ; Mon, 21 Jan 2019 08:00:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA2A929D61 for ; Mon, 21 Jan 2019 08:00:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDE5F29D63; Mon, 21 Jan 2019 08:00: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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE 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 650E829D61 for ; Mon, 21 Jan 2019 08:00:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A9158E0011; Mon, 21 Jan 2019 03:00:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 631F08E0001; Mon, 21 Jan 2019 03:00: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 4D2F88E0011; Mon, 21 Jan 2019 03:00:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 1F5AE8E0001 for ; Mon, 21 Jan 2019 03:00:19 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id q3so20337899qtq.15 for ; Mon, 21 Jan 2019 00:00:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=hfIqzaLx8cim+nIa8TVvSLzSI024ej8iZBzn/c9pUVU=; b=JvBD7AHFCiD7mtBKKnVmRgNzPKfR2+txozNqapzxcikL3WnHTPMGHa9N4C4uS79xmM 2LfanUSlCXcygVFmY7DIXvQBvXF8MYks1BmZbVGwqeHBz7KWnsaiqeSBQcdz80fpt6IW fM9LU0q+cPHcLpT4x1OqZ18xc9XnDCKBnE2BHvi8tjgA/FPiiF7Yum2gq6EQtr2Rt66r eigjqSQqZTGwqfNCAqMa6vhisgEJXCJ8sM7hy6P3h/OcLKOJqzxBwIs9Urq77yST3Zlk KYkCTRmQqSO6IBRtgx/vAZtLLIkCdEX4QtqZSXyrR9BJ+i8ucuAYZqOIbPX/YRjaSs61 2h+g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AJcUuke78vpFrkLPZZ/U6obsccj5pj+VF5zD7Nqn7ESqqsq/r3MHystG xeCZ0bh+7rPiuuaPMuFthSVszcrVLj8Koi+sGyzwyzJlGYtYgFrIyoVKg03nxwV+bqnTkHRFx8s tyO2GbPKLQEAzvsSzXXAZAo7aB3H/+83MXK1aqB/TlHcBEq4R5Am1lMX+nJMcgQ4HAw== X-Received: by 2002:ac8:17f0:: with SMTP id r45mr25571050qtk.206.1548057618916; Mon, 21 Jan 2019 00:00:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN5LxHu3uAOQuB8K6OrqvouiwjTe3g8WlnjYCsQ2TjMSHxYN0cbsOG3j29lPpaoKj4VJIYuV X-Received: by 2002:ac8:17f0:: with SMTP id r45mr25571023qtk.206.1548057618429; Mon, 21 Jan 2019 00:00:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548057618; cv=none; d=google.com; s=arc-20160816; b=Xu7sPgX97FUoIIWcWH+3veE/vrsdOMb7fbgEFp7tU2zKuo4z2WNBZOqusVt+lPk/mS qdIhthLAxWcWvUtW3/hUY0D76nXxeawvHnoNMZpGZ6rCCE+BMhwVXF5BXL78PtXjg7eE dHnqw6rp0RjycO5XePcX14CFHH07Em3h7IespSiQNFM1s3hWFZhm4pJ9J0BiwvPCjyLb NR8EMKFc31cRdzzXCFnm0xCJZTwdRKgTRF9ycnW4KTbwFpuSeHKXB5uoxCs7C6o7varN OgpqdiCA/bUOAaTwfoZ0nP9JymsvjJqbRQusF1Y3N2yj5isExlzSoKhZHvNiAPyPlbQZ sf8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=hfIqzaLx8cim+nIa8TVvSLzSI024ej8iZBzn/c9pUVU=; b=CSIvkUbS27YIuel94TFOHjladdpdVwMx2X/1ncPUJR6TmgSj1hqjLpxc2jQDl94qix 0UC+nR5F+igZbzkwwV+MjiUvaMeIoEf4+rf1oQbdpV4TRJl8cB6f6yMaFIUMjTVBxbgE aBVvja/KrUjL5zPH/32s5nMcefvhvQ/g2C0aIuEFEgOA0WV3JAP3eUh06qQ1DgDmo3Mn meIbv059pRDR2b7S40fcLrgwTSH/aHd2k7tDV/wZpow8E/NsbdeeNz+EYAw84QEjGWyh NxWGVnE7Ie5QA6k9w/VopdhQ2AdgzPuvkB8TonSUPuKYiAHbSC6TkwkSBXThYd3GvbV4 EAMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id g14si2490491qti.392.2019.01.21.00.00.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 00:00:18 -0800 (PST) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56F07750DA; Mon, 21 Jan 2019 08:00:17 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-116.nay.redhat.com [10.66.14.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42FE4608C7; Mon, 21 Jan 2019 08:00:10 +0000 (UTC) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Maya Gokhale , Jerome Glisse , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Denis Plotnikov , Shaohua Li , Andrea Arcangeli , Pavel Emelyanov , Mike Kravetz , Marty McFadden , Mike Rapoport , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH RFC 21/24] khugepaged: skip collapse if uffd-wp detected Date: Mon, 21 Jan 2019 15:57:19 +0800 Message-Id: <20190121075722.7945-22-peterx@redhat.com> In-Reply-To: <20190121075722.7945-1-peterx@redhat.com> References: <20190121075722.7945-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 21 Jan 2019 08:00:17 +0000 (UTC) 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 Don't collapse the huge PMD if there is any userfault write protected small PTEs. The problem is that the write protection is in small page granularity and there's no way to keep all these write protection information if the small pages are going to be merged into a huge PMD. The same thing needs to be considered for swap entries and migration entries. So do the check as well disregarding khugepaged_max_ptes_swap. Signed-off-by: Peter Xu --- include/trace/events/huge_memory.h | 1 + mm/khugepaged.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h index dd4db334bd63..2d7bad9cb976 100644 --- a/include/trace/events/huge_memory.h +++ b/include/trace/events/huge_memory.h @@ -13,6 +13,7 @@ EM( SCAN_PMD_NULL, "pmd_null") \ EM( SCAN_EXCEED_NONE_PTE, "exceed_none_pte") \ EM( SCAN_PTE_NON_PRESENT, "pte_non_present") \ + EM( SCAN_PTE_UFFD_WP, "pte_uffd_wp") \ EM( SCAN_PAGE_RO, "no_writable_page") \ EM( SCAN_LACK_REFERENCED_PAGE, "lack_referenced_page") \ EM( SCAN_PAGE_NULL, "page_null") \ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 8e2ff195ecb3..92f06e1c941e 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -29,6 +29,7 @@ enum scan_result { SCAN_PMD_NULL, SCAN_EXCEED_NONE_PTE, SCAN_PTE_NON_PRESENT, + SCAN_PTE_UFFD_WP, SCAN_PAGE_RO, SCAN_LACK_REFERENCED_PAGE, SCAN_PAGE_NULL, @@ -1125,6 +1126,15 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, pte_t pteval = *_pte; if (is_swap_pte(pteval)) { if (++unmapped <= khugepaged_max_ptes_swap) { + /* + * Always be strict with uffd-wp + * enabled swap entries. Please see + * comment below for pte_uffd_wp(). + */ + if (pte_swp_uffd_wp(pteval)) { + result = SCAN_PTE_UFFD_WP; + goto out_unmap; + } continue; } else { result = SCAN_EXCEED_SWAP_PTE; @@ -1144,6 +1154,19 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, result = SCAN_PTE_NON_PRESENT; goto out_unmap; } + if (pte_uffd_wp(pteval)) { + /* + * Don't collapse the page if any of the small + * PTEs are armed with uffd write protection. + * Here we can also mark the new huge pmd as + * write protected if any of the small ones is + * marked but that could bring uknown + * userfault messages that falls outside of + * the registered range. So, just be simple. + */ + result = SCAN_PTE_UFFD_WP; + goto out_unmap; + } if (pte_write(pteval)) writable = true;