From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 887F2C43461 for ; Fri, 11 Sep 2020 20:13:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0683B21D81 for ; Fri, 11 Sep 2020 20:13:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="YD2gQHu7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0683B21D81 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 43D596B0002; Fri, 11 Sep 2020 16:13:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EF526B0003; Fri, 11 Sep 2020 16:13:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 306126B0037; Fri, 11 Sep 2020 16:13:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 1C02A6B0002 for ; Fri, 11 Sep 2020 16:13:04 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CFEF33643 for ; Fri, 11 Sep 2020 20:13:03 +0000 (UTC) X-FDA: 77251879446.27.bread01_4f0cd8e270f1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 9F3F23D668 for ; Fri, 11 Sep 2020 20:13:03 +0000 (UTC) X-HE-Tag: bread01_4f0cd8e270f1 X-Filterd-Recvd-Size: 5659 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 11 Sep 2020 20:13:02 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08BKA7X3014506; Fri, 11 Sep 2020 20:12:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=RJJA5VIeYEDyLlWxqH87o0yLo3b4m+0xgt6JvxypFdQ=; b=YD2gQHu7lSiJapybCXsLhCgpZK9ro2yjDfqZwk3OdxozfUNdSBSSRhrHxPQl/jZZ9FCg XFHqQfFh+5OhxodNwXwuzizuTOQhbdOoZDLXeWSPw/LeYwQx3kEJxOEMIUOgcWjlpFBX 8oQak2VLFTstPWh72LCWNjxA5p0z428RYdtg3cUJTI45kHG6uU4Pd4oHxNcnUFFgZgkD JYRc7eSvahLEPru7HbzDLbVtKegkYwZb3EtzuY9SfKQLxoSI86ZnKCEV3GS9v2e+oXpV Ts8QM+2XwGnN25nzKVF+UMV65PkuizaVTySSzF1bPiCGVgGvp4090g9s2fRvkZ2GAK1t fA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 33c3ang6y1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 11 Sep 2020 20:12:55 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08BKAUY4191652; Fri, 11 Sep 2020 20:12:54 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 33cmm40qqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Sep 2020 20:12:54 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 08BKCrAM029955; Fri, 11 Sep 2020 20:12:53 GMT Received: from monkey.oracle.com (/50.38.35.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Sep 2020 13:12:52 -0700 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Michal Hocko , "Kirill A . Shutemov" , Davidlohr Bueso , Andrew Morton , Mike Kravetz Subject: [PATCH] hugetlb: add lockdep check for i_mmap_rwsem held in huge_pmd_share Date: Fri, 11 Sep 2020 13:12:48 -0700 Message-Id: <20200911201248.88537-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9741 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009110163 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9741 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 mlxscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009110163 X-Rspamd-Queue-Id: 9F3F23D668 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable 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: As a debugging aid, huge_pmd_share should make sure i_mmap_rwsem is held if necessary. To clarify the 'if necessary', expand the comment block at the beginning of huge_pmd_share. No functional change. The added i_mmap_assert_locked() call is only enabled if CONFIG_LOCKDEP. Ideally, this should have been included with commit 34ae204f1851 ("hugetlbfs: remove call to huge_pte_alloc without i_mmap_rwsem"). Signed-off-by: Mike Kravetz --- mm/hugetlb.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 81a41aa080a5..61469fd3ad92 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5337,10 +5337,16 @@ void adjust_range_if_pmd_sharing_possible(struct = vm_area_struct *vma, * !shared pmd case because we can allocate the pmd later as well, it ma= kes the * code much cleaner. * - * This routine must be called with i_mmap_rwsem held in at least read m= ode. - * For hugetlbfs, this prevents removal of any page table entries associ= ated - * with the address space. This is important as we are setting up shari= ng - * based on existing page table entries (mappings). + * This routine must be called with i_mmap_rwsem held in at least read m= ode if + * sharing is possible. For hugetlbfs, this prevents removal of any pag= e + * table entries associated with the address space. This is important a= s we + * are setting up sharing based on existing page table entries (mappings= ). + * + * NOTE: This routine is only called from huge_pte_alloc. Some callers = of + * huge_pte_alloc know that sharing is not possible and do not take + * i_mmap_rwsem as a performance optimization. This is handled by the + * if !vma_shareable check at the beginning of the routine. i_mmap_rwsem= is + * only required for subsequent processing. */ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *p= ud) { @@ -5357,6 +5363,7 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigne= d long addr, pud_t *pud) if (!vma_shareable(vma, addr)) return (pte_t *)pmd_alloc(mm, pud, addr); =20 + i_mmap_assert_locked(mapping); vma_interval_tree_foreach(svma, &mapping->i_mmap, idx, idx) { if (svma =3D=3D vma) continue; --=20 2.25.4