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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A3A4C04A95 for ; Thu, 29 Sep 2022 06:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234797AbiI2GZY (ORCPT ); Thu, 29 Sep 2022 02:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232519AbiI2GZV (ORCPT ); Thu, 29 Sep 2022 02:25:21 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 025761007A for ; Wed, 28 Sep 2022 23:25:20 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MdNXk4m9lzWgx3; Thu, 29 Sep 2022 14:21:10 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 29 Sep 2022 14:25:17 +0800 Subject: Re: [PATCH v2 9/9] hugetlb: clean up code checking for fault/truncation races To: Mike Kravetz , , CC: Muchun Song , David Hildenbrand , Sven Schnelle , Michal Hocko , Peter Xu , Naoya Horiguchi , "Aneesh Kumar K . V" , Andrea Arcangeli , "Kirill A . Shutemov" , Davidlohr Bueso , Prakash Sangappa , James Houghton , Mina Almasry , Pasha Tatashin , Axel Rasmussen , Ray Fucillo , Andrew Morton References: <20220914221810.95771-1-mike.kravetz@oracle.com> <20220914221810.95771-10-mike.kravetz@oracle.com> From: Miaohe Lin Message-ID: Date: Thu, 29 Sep 2022 14:25:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220914221810.95771-10-mike.kravetz@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/9/15 6:18, Mike Kravetz wrote: > With the new hugetlb vma lock in place, it can also be used to handle > page fault races with file truncation. The lock is taken at the > beginning of the code fault path in read mode. During truncation, it > is taken in write mode for each vma which has the file mapped. The > file's size (i_size) is modified before taking the vma lock to unmap. > > How are races handled? > > The page fault code checks i_size early in processing after taking the > vma lock. If the fault is beyond i_size, the fault is aborted. If the > fault is not beyond i_size the fault will continue and a new page will > be added to the file. It could be that truncation code modifies i_size > after the check in fault code. That is OK, as truncation code will soon > remove the page. The truncation code will wait until the fault is > finished, as it must obtain the vma lock in write mode. As previous thread [1] points out, if vma->vm_private_data is NULL, there won't be any synchronization which provides the same type of synchronization around i_size as provided by the fault mutex as in [2]. ([2] will take the fault mutex for EVERY index in the truncated range) [1] https://lore.kernel.org/lkml/YyOKIhygl66cG8Yr@monkey/T/#m6b69af9e8cdba01246c2b210bd044bf895b815ee [2] https://lore.kernel.org/lkml/20220824175757.20590-5-mike.kravetz@oracle.com/ Except from that, this patch looks good to me. Thanks Mike. Thanks, Miaohe Lin