From patchwork Mon Dec 3 20:08:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 10710493 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 5F38413BF for ; Mon, 3 Dec 2018 20:09:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 509862B2E0 for ; Mon, 3 Dec 2018 20:09:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 433482B32D; Mon, 3 Dec 2018 20:09:11 +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 D3C612B2E0 for ; Mon, 3 Dec 2018 20:09:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EDED6B6AD9; Mon, 3 Dec 2018 15:09:09 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 89B296B6ADA; Mon, 3 Dec 2018 15:09:09 -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 762E26B6ADB; Mon, 3 Dec 2018 15:09:09 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 4B04E6B6AD9 for ; Mon, 3 Dec 2018 15:09:09 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id v74so14171331qkb.21 for ; Mon, 03 Dec 2018 12:09:09 -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=OlWM2kIS3Z19L+4h3PRXLv5xgaZsAIbrRBC+3bhtAHM=; b=hrSaJ1vPLtNMwcDiKiJeV4nWtCd2unHrv6/jAMxEWMvHFUGWMl0kbisrRV19wlrZ8w 6/xKRQN3L5XxRO2GcPMc5e9aK49PDpDwAWvxOp5Tqgm4EWV34l7fetEQwNoPHKiCI4Ug DMKV18M9OZHyEe/CLM4caBDGbs9UCIqkVCI0Qlk4dh2OKNwBjfcOeZsc2+Iv6MRxQpCe FlbM+HC6Gn2UUy2wPYk96kL3JcjJ+H4Zltl8zcyWmLlbSjyknF220ZQsgGnlrStG7E/O w2cWfHyfRb24fVcbxM4VmdvwWP5xFWcq/jubTBPpEccZ79wmHWHr53c1mRr8b5gLsxf3 IlWw== X-Gm-Message-State: AA+aEWb+9ksqhqfYUbAo4VGQA1IQicWm++ItHJVq1PYA/J1GNbgR8dzt 6Ff/DEsBx0fR5JtpjCpo9KssTnC+M6qS4gJu4aFgOB0ULLW3eZgU/N3wV1ys2mFg3OepeCteddM 3BExRfs59ZIg+pwEEib6pG2lFAjXNtn9RS0xclvmczzbKYR6h4i/dxKQTHjVwSMJBXQ== X-Received: by 2002:ac8:6892:: with SMTP id m18mr16314978qtq.157.1543867748982; Mon, 03 Dec 2018 12:09:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/V0FkgomE9gw400d/LNW2PqEt9voDLIC5zLBfKQ/ppgdZJ+PmeD6s3p49eEtEgn9xrTlksk X-Received: by 2002:ac8:6892:: with SMTP id m18mr16314945qtq.157.1543867748424; Mon, 03 Dec 2018 12:09:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543867748; cv=none; d=google.com; s=arc-20160816; b=o1pX9t1cGj4b2uasKi78yBrdDWXjWd+AbJGzZR/xdjQwhp8a72R7RhckR41GM7h3gi 7aa0yNJtx9UnuEpH15g20wojfbd3Km+I4lTUEmYKaKmN9LQLN1AO11dyjDA74ptK1rf0 aSxKpxaw4hy3H8UP1vX9gb1FAAQgMlunQTwVfOFfBhMwdlBVUyHrYUFDXZRLtzDATVaM 0TLrciyPW7g+ERCHwySr0hpdpoZSLnKv4xOV25lF5gAgIEAVQgP+UuUHXQRBIptjvZQo n7ZsU5zzHChy4IrlUMO6WAEjezn5o5xB8PnbYD0O8Ng0rJWq0GledUeyIJieHA1Ymkv1 eIIg== 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=OlWM2kIS3Z19L+4h3PRXLv5xgaZsAIbrRBC+3bhtAHM=; b=dvXTRjFY6imILMiLbeK/Y9P2t6ERtsdxhVkDfdBvd9jjfs6cCMLycY2nSJu7JlPPnV SY3OKazJ3dskA3onnBbUBim4ZVymROcml/r2sSRgNlecKGMxy3GQ2HHIpAwxkPUFpIzm KHHafI18ul4P6evJvHNsXsYAn06dP/UPsj7KNtEaYhdY2lnVgfQCJOqTOFOf0rJ1ndVk CLOZ3n60md+Okc5xkMbLe4zJEqgxv2uNjrwFWUFQInSbVQy/pdu4vAQuuOsbC9wd3GXo LqZbuFsqgLS0bTLnzpSz/WFOCypMFXNqtTpPQMT20v4oLz3+V9DBuMMjSGcPbtmmXC/8 GcNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=2yP37D10; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id x189si183100qke.171.2018.12.03.12.09.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 12:09:08 -0800 (PST) Received-SPF: pass (google.com: domain of mike.kravetz@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=2yP37D10; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB3Jwl0a086283; Mon, 3 Dec 2018 20:08:58 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=OlWM2kIS3Z19L+4h3PRXLv5xgaZsAIbrRBC+3bhtAHM=; b=2yP37D10zf6yzKz+Jz9KKzevG4xdMaGEKEGLTIxtftWW+nQ9K3UdVfgUGgun3F1tEzQO fP0WCBdzXeUqKVHSV8kUG6UV3rjbzHILqICQWp1e9mlwu2ALHb/mfzfjXLP5ZyKKgPKg 8XrS0Cbcu6VgkfF3lT7Lz3y+AcXizMjEbwoTLPZK56YhL+/L997ynwLAyWrsXtzL84EM /NZxllxboONKBSJVIRISxuVHAuKJ6ZKeI2pgstpQEWWTguleno45faFQWB0Rlc1l9tl+ 0DUiJJq+E3u/dMoRCZgbbPiJ4uAac7szaNYhKIteXXEDV4NaAiQVV7ndENjNcCILws0/ pw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2p3j8q8kpu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 03 Dec 2018 20:08:58 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wB3K8weu017915 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 3 Dec 2018 20:08:58 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wB3K8v1Y017153; Mon, 3 Dec 2018 20:08:57 GMT Received: from monkey.oracle.com (/50.38.38.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 03 Dec 2018 12:08:56 -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 0/3] hugetlbfs: use i_mmap_rwsem for better synchronization Date: Mon, 3 Dec 2018 12:08:47 -0800 Message-Id: <20181203200850.6460-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.17.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9096 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=454 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812030183 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 These 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. There are two primary issues addressed here: 1) For shared pmds, huge PE 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. I broke up the larger RFC into separate patches addressing each issue. Hopefully, this is easier to understand/review. Mike Kravetz (3): hugetlbfs: use i_mmap_rwsem for more pmd sharing synchronization hugetlbfs: Use i_mmap_rwsem to fix page fault/truncate race hugetlbfs: remove unnecessary code after i_mmap_rwsem synchronization 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(-)