From patchwork Wed Oct 24 04:50:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 10654167 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 6E68614BD for ; Wed, 24 Oct 2018 04:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5334129E53 for ; Wed, 24 Oct 2018 04:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44B352A2A9; Wed, 24 Oct 2018 04:51:12 +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 D5BDD29E53 for ; Wed, 24 Oct 2018 04:51:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 667A66B0003; Wed, 24 Oct 2018 00:51:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 615A46B0005; Wed, 24 Oct 2018 00:51:10 -0400 (EDT) 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 504536B0007; Wed, 24 Oct 2018 00:51:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-it1-f199.google.com (mail-it1-f199.google.com [209.85.166.199]) by kanga.kvack.org (Postfix) with ESMTP id 26A026B0003 for ; Wed, 24 Oct 2018 00:51:10 -0400 (EDT) Received: by mail-it1-f199.google.com with SMTP id d7-v6so3680210itf.7 for ; Tue, 23 Oct 2018 21:51:10 -0700 (PDT) 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=AyUcklR2+ZE2sBdFRyUml0HTUf4myfsqASFPXEU59fM=; b=sfwj4qz9KEGjYwTUw0yQ+YNHv+Y6a6iR8CYuU+kquPcnEQJ4LBLqwMhvUPRbF3bsm1 9AEHLvWFAfUMBhXro4WHviA2+wc8Rhn0xYl26QVv7KTBDphGl3zN1xpHSA9cov4QBOrh SFfwSqU//k0x8Ds29/XMM6mSHAyQAJSfv1ABcJjqe3M9Qfw8Jy1Il+W3w13hROAhIIc0 07ibLKfw/TI/+cyE0aZ+D0KLOVqBrA+wpXrABzsjpdAIIiaWE5ruMgBMmnckRnO59XGI 7HZTu19H4G8Tao3G99aj0HMZcpk0FmyU74gOZLHRZzlxmVhh8UmoooZjQgvag8KmgMva IYeg== X-Gm-Message-State: AGRZ1gLiTSG5QdOzWe4hQhU09DkAsLT7ZsGGxFRCqqSyNtp+tOHrGBm2 I0WlXvqUEn6vZYUC/yx8ebekTpg6yZTIk5jKak2saGMYqJ5+EOoqOX+NppUCOHnj2S5Aqfg/35l bzhlgtBFokRJWgTGBjJkEjOFeTiZdjcafHgshW9V82YZy3+yki/MoOJDAySnxIPd8nQ== X-Received: by 2002:a24:554c:: with SMTP id e73-v6mr581006itb.157.1540356669829; Tue, 23 Oct 2018 21:51:09 -0700 (PDT) X-Google-Smtp-Source: AJdET5cJWmqOejDtLwmsdvW0LoccWbby5sUzRgdV5aC/icZEO6LhXEXFDqoySOEiG/tgEAGupcww X-Received: by 2002:a24:554c:: with SMTP id e73-v6mr580994itb.157.1540356669007; Tue, 23 Oct 2018 21:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540356668; cv=none; d=google.com; s=arc-20160816; b=KYV4wJzO3uQBXx2QVUz/DfIeZTyld7/oFCM74GtVGrfkLbNVQbb3ReXFkUvo7K8sE+ VLgpYFxJMWDB1YYyk5pf2J+WT4xK9T8fd5NBIITpP5GAmjavTKd5IxB3n+M0V3R33qTy rtHa9S1BIB8qnY7Uul5JLR4dmZUs4bqc8fT/9VobeZoXi5OLlhoz/0OC3KqR9tsr8YP7 FRran938JLnqn5Kn2RA01yExut8jWdfgb0jrJN/AzA0PWAKZvR5utCB1KIPEwP0tGcm6 +GxN+WGg81qLWFKZEBaR+raYKDNSvn5Y4EqfxCuLXjlB+9ggaFmMz1mqHP/hA2s3VC+z ZcvQ== 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=AyUcklR2+ZE2sBdFRyUml0HTUf4myfsqASFPXEU59fM=; b=NpUnR7F/DQlad05WACF2SpiAPJ2TvartNf4hjoQiBKvpU6QV7qtW/HFUb7tEsrTTto cfMJAlTTXxqsIyyClyjzvy1zjVpOhv+CeBKzQkwwJkUT4P8RejZHznyHjrWSMv2/CkO3 J0nuIQmk9L+3dSD7cCY8IlP8gin5hcgczzPZsU041ip+fPNuatAKiYng++JOQWxnFrvH xVEgrACNdOGzs31KWWx5WRkDYiUWSe0cOQPJHP/d94WQPV3O7r4qcSpf2QHUih6AaBVh AI8FK5+K1rtgJy5jq3bEM2ufJSWEpgnSCIFpRMW6hythmYqS1yXw0e+xl0ofOR0m5V1s BEqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=kQSYQ8HL; 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 j199-v6si2562591ita.114.2018.10.23.21.51.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 21:51:08 -0700 (PDT) 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=kQSYQ8HL; 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 w9O4iBX0162936; Wed, 24 Oct 2018 04:51:01 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=AyUcklR2+ZE2sBdFRyUml0HTUf4myfsqASFPXEU59fM=; b=kQSYQ8HLZILUYGeuBe27keoBJCsvaZhQT1sZJ4jngejfGu92yrlSZWTi8qlQ6UzXCFnz epnscRlbPpuSib+xTXpHKin5oygBB1yjsi6Akw4lnbt5JeqxCr+np2WworkgaLDDPFx+ 4mjEIDFy2xzn9sTmjmYXSaEoHTgt330zNs93Vk/qlUjMCrAEPxSN3yFpkCUBeHOhQHoQ 71kxx1HefRwo+Kdkayl6jolNVKpmcgr5vAsE/HJsFZtND9eIX22LZFoXa10JJA/NxMZN xS4KkiCoEkUrOKG4ASuAuacqJP+DtNC6fGlDNwbY1PQvs+xyaeogX+f3amm+vpYYsppr WQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2n7w0qs1qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Oct 2018 04:51:00 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9O4p0O2002338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Oct 2018 04:51:00 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 w9O4owdr011897; Wed, 24 Oct 2018 04:50:58 GMT Received: from monkey.oracle.com (/50.38.38.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 23 Oct 2018 21:50:57 -0700 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Michal Hocko , Hugh Dickins , Naoya Horiguchi , "Aneesh Kumar K . V" , Andrea Arcangeli , "Kirill A . Shutemov" , Davidlohr Bueso , Prakash Sangappa , Mike Kravetz Subject: [PATCH RFC v2 0/1] hugetlbfs: Use i_mmap_rwsem for pmd share and fault/trunc Date: Tue, 23 Oct 2018 21:50:52 -0700 Message-Id: <20181024045053.1467-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.17.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9055 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=283 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810240042 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 This patch addresses issues with page fault/truncation synchronization. The first issue was noticed as a negative hugetlb reserved page counts during DB development testing. Code inspection revealed that the most likely cause were races with truncate and page faults. In fact, I could write a not too complicated program to cause the races and recreate the issue. A more dangerous issue exists when you introduce huge pmd sharing to page fault/truncate races. The fist thing that happens in huge page fault processing is a call to huge_pte_alloc to get a ptep. Suppose that ptep points to a shared pmd. Now, another thread could perform a truncate and unmap everyone mapping the file. huge_pmd_unshare can be called for the mapping on which the first thread is operating. huge_pmd_unshare can clear pud pointing to the pmd. After this, the ptep points to another task's page table or worse. This leads to bad things such as incorrect page map/reference counts or invaid memory references. Fix this all by modifying the usage of i_mmap_rwsem to cover fault/truncate races as well as handling of shared pmds Mike Kravetz (1): hugetlbfs: use i_mmap_rwsem for pmd sharing and truncate/fault sync fs/hugetlbfs/inode.c | 21 ++++++++++---- mm/hugetlb.c | 65 +++++++++++++++++++++++++++++++++----------- mm/rmap.c | 10 +++++++ mm/userfaultfd.c | 11 ++++++-- 4 files changed, 84 insertions(+), 23 deletions(-)