From patchwork Tue Dec 18 22:35:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 10736449 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 8AC316C2 for ; Tue, 18 Dec 2018 22:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B5C42AA1A for ; Tue, 18 Dec 2018 22:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DFDE2B05C; Tue, 18 Dec 2018 22:36:15 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY 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 009532AA1A for ; Tue, 18 Dec 2018 22:36:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A49F8E000B; Tue, 18 Dec 2018 17:36:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3533F8E0001; Tue, 18 Dec 2018 17:36:14 -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 2426A8E000B; Tue, 18 Dec 2018 17:36:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by kanga.kvack.org (Postfix) with ESMTP id F04218E0001 for ; Tue, 18 Dec 2018 17:36:13 -0500 (EST) Received: by mail-io1-f71.google.com with SMTP id f24so16769970ioh.21 for ; Tue, 18 Dec 2018 14:36:13 -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:from:to:cc:subject:date :message-id; bh=ZEyi/mJaQCtnsfh/MuvJPVrz32g9rgqB4m3iXTu6uXo=; b=kJm2Epmc8hdEGoTZfLyDgSno6HSNC0lkGWJBRJPbYoUh73LkuU2i4aWIx5nP0tFK41 wo1XjXo1fayZOHJiYJqs8bXHq+gw7/mBthdxADkUUAgNkDG+v2N0ird9GkbuZuRPO+Or IDLQRVndoVb1Lwdyx+/S9FPOr6wqgDYyF9oAmCRNhmwENvqmDMCMppm1/dDw0ZrsdUxt CgtoP4W8I5idgyKQSgtiU+cbT6WJT7QOB2HgXthoOz7djjg5Go/4gidaPoFECTQQGhHY ZDd5QEfG9T5BiVffQ4mF/uCDlEMTIN3BQ+4+RUT50BGRhVVedG3kVvrKZYd9hSh/tAsV fyHA== X-Gm-Message-State: AA+aEWZhU65C26VzaqKrSqu+DcsKL+/aiOFOSDRqWppMQv/OrhEsrzlb lfRoTEw1DQwXEwbMbIpuxRvwXpwLJxn4/DPTp7TpIBu7iNyFmPq2kwwBN/pyMt4L6iyMZT3GGWG ZdVHOfhudw290iWUqDU/mitiPJHZB7ssEgySnpmKmNo3BgYm3slWBkEJkrLd9RafuQw== X-Received: by 2002:a6b:900b:: with SMTP id s11mr16210140iod.159.1545172573707; Tue, 18 Dec 2018 14:36:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/XiI7ELDTDBh8ZTLZinuLekTpHvgR2Do1sI/Q6m5F1KE9IIz6AzoLdGBadjAQ8IuZBJsGVD X-Received: by 2002:a6b:900b:: with SMTP id s11mr16210112iod.159.1545172573024; Tue, 18 Dec 2018 14:36:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545172572; cv=none; d=google.com; s=arc-20160816; b=L8hqsP48knaBkDJk8DXCC99glALNMJf/z5NYAUYiIxvBNWm/rfCe1CInL2pKcre6nR 9pNsczwsyK4HPej+Mm/u5fylRR1cvjgwhKlbpaRH+NFom8Y7pcQbtTEEnBRyY/OgkQB7 P86r2siZqsPd00w93meI0DIOS9Nqvn19Kts5BwJ6ILxaXe8QuakpXhWnNptl6j3RCTGj ZeXd2AB1FMHopwdvwpPCzPPzxvgsQodqyMSDRzsHifKZT96/WSM99nxNBe7vz+rmrWv+ ZKk+A5hzg96/F9b00VIGHekw6CKK9ptorHL8u8XCbWzj5LHyVQdVK1fVNpRdlkBIowtg VjLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=ZEyi/mJaQCtnsfh/MuvJPVrz32g9rgqB4m3iXTu6uXo=; b=ap5Osbj+gBoHHKrzLdJIUJBhoyECgIrpjDmFYec2+MJVHeels91CfklQ6fL91PtY99 henvgjvsd2uIfeRNzp0bLfssjsL9DT+zIflQ3ZPuHrq7YS6XmyfNLdYf9OuA1LLYWXvQ FF4t5BTXRGbb041ql9gTTtBN/BZDEKLa9IKexvSawR4q76w/0HGuhOnseA5UGeyT9G2h nVB0GeEKPJ5FdqiHuKz6CNnxGXUk8cYcuueppVWLhfI59HqIebNKpMa5kKEsVMjIhJRr /hY74Po0+EuexxacLSVYEe7RdAKajk0L0qlCCedl7g9JAbK/3L8rZZx/4xEHtgOJwuzG 6OkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=XmGvtUJG; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id m14si1878363itl.54.2018.12.18.14.36.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 14:36:12 -0800 (PST) Received-SPF: pass (google.com: domain of mike.kravetz@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=XmGvtUJG; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBIMY49G194290; Tue, 18 Dec 2018 22:36:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=ZEyi/mJaQCtnsfh/MuvJPVrz32g9rgqB4m3iXTu6uXo=; b=XmGvtUJG6WHgkEdyvGm2qRovE+L/Llr2whf9j6f2QMBrX8llq+V23XCL0ZBkE76LKcaN iBoxw+/MgZqtS7zY20UVvhEj7+OvYmMgBfIsouBNwpKmzkIrRLnChSFzxXny9EtpED3r eStWa1/9Sg7YKemyUE7gPP0VB/l/mbq9V6LBgigoLzJ45ZdvlP0qmJwCpOliF/KHnlEG l1grgSNoX/UrXcSFjUy14Re/o16IrHZfW3/ICu7ov5zEiVDxvNIwTwfDORgIxYLBTone 1MWEWZNM6cmQzcLk9lHyA8qRAUy/70rjm0lut/jLwnuOt3/kPOyMu+yXHvLdVmVFtA1L Xg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2pct8qx3w5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Dec 2018 22:36:05 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wBIMa5mH012213 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Dec 2018 22:36:05 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBIMa4bP029999; Tue, 18 Dec 2018 22:36:04 GMT Received: from monkey.oracle.com (/50.38.38.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 18 Dec 2018 14:36:04 -0800 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Michal Hocko , Hugh Dickins , Naoya Horiguchi , "Aneesh Kumar K . V" , Andrea Arcangeli , "Kirill A . Shutemov" , Davidlohr Bueso , Prakash Sangappa , Andrew Morton , Mike Kravetz Subject: [PATCH v2 0/2] hugetlbfs: use i_mmap_rwsem for better synchronization Date: Tue, 18 Dec 2018 14:35:55 -0800 Message-Id: <20181218223557.5202-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.17.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9111 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=424 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812180184 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 There are two primary issues addressed here: 1) For shared pmds, huge PTE pointers returned by huge_pte_alloc can become invalid via a call to huge_pmd_unshare by another thread. 2) hugetlbfs page faults can race with truncation causing invalid global reserve counts and state. Both issues are addressed by expanding the use of i_mmap_rwsem. These issues have existed for a long time. They can be recreated with a test program that causes page fault/truncation races. For simple mappings, this results in a negative HugePages_Rsvd count. If racing with mappings that contain shared pmds, we can hit "BUG at fs/hugetlbfs/inode.c:444!" or Oops! as the result of an invalid memory reference. v1 -> v2 Combined patches 2 and 3 of v1 series as suggested by Aneesh. No other changes were made. Patches are a follow up to the RFC, http://lkml.kernel.org/r/20181024045053.1467-1-mike.kravetz@oracle.com Comments made by Naoya were addressed. Mike Kravetz (2): hugetlbfs: use i_mmap_rwsem for more pmd sharing synchronization hugetlbfs: Use i_mmap_rwsem to fix page fault/truncate race fs/hugetlbfs/inode.c | 50 +++++++++---------------- mm/hugetlb.c | 87 +++++++++++++++++++++++++++++++------------- mm/memory-failure.c | 14 ++++++- mm/migrate.c | 13 ++++++- mm/rmap.c | 3 ++ mm/userfaultfd.c | 11 +++++- 6 files changed, 116 insertions(+), 62 deletions(-)