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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F609C6FA83 for ; Thu, 29 Sep 2022 06:25:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9F408E0001; Thu, 29 Sep 2022 02:25:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4ECC6B0075; Thu, 29 Sep 2022 02:25:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D64DE8E0001; Thu, 29 Sep 2022 02:25:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C80FF6B0074 for ; Thu, 29 Sep 2022 02:25:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9FB7240FB1 for ; Thu, 29 Sep 2022 06:25:25 +0000 (UTC) X-FDA: 79964136210.20.2C77173 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf26.hostedemail.com (Postfix) with ESMTP id 84EEF140016 for ; Thu, 29 Sep 2022 06:25:24 +0000 (UTC) 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 ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664432725; a=rsa-sha256; cv=none; b=aUhgKwr73/VddDYJw4mi1G4ZMC+Rlh7H0h+4QiltVVi+2vzyFgT35+HT8MdwTpx98s/vqd 0DROZ9lE76OmUmk8uAweUr+HTITQF7pQxKG8ULkwuC7bltMSb+nSxwTTfNkYd4Sgq05ztU yh7fFHPlRsdq2en3JMKumQMG6EiW7x8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664432725; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QbYD620WOPZ/FUGzgUyL+9hjwkZuUrhhs3RnoXxBQa4=; b=N9OKEnEkGS9v3Uao9UWT8XIimPhd3a6p4zMPeTqKeRJB6npLZqikCdoXZMeDYz1zGW2dhW D5CyQZx8t7tAtxUIyvVDERXbGelDe/O8mx1YZ9zGnseeOWLnkneDWqsdhdhf5DBbEJlg9v xVKjCBL4eAyv2GXmy9+ZlXf8NAdQsio= Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: e6yt37k5fh3yxcqq5ugjfw9rj3a7xefa X-Rspamd-Queue-Id: 84EEF140016 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1664432724-923695 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: 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