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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=no 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 E6436C433F5 for ; Fri, 24 Sep 2021 03:35:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8721F60F94 for ; Fri, 24 Sep 2021 03:35:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8721F60F94 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 139406B006C; Thu, 23 Sep 2021 23:35:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E8F26B0071; Thu, 23 Sep 2021 23:35:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F40F36B0073; Thu, 23 Sep 2021 23:35:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id E4B8A6B006C for ; Thu, 23 Sep 2021 23:35:40 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8DB768249980 for ; Fri, 24 Sep 2021 03:35:40 +0000 (UTC) X-FDA: 78621052440.30.E45D515 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf02.hostedemail.com (Postfix) with ESMTP id 161F57001A24 for ; Fri, 24 Sep 2021 03:35:38 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R991e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UpOFCZC_1632454534; Received: from 30.240.96.158(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0UpOFCZC_1632454534) by smtp.aliyun-inc.com(127.0.0.1); Fri, 24 Sep 2021 11:35:35 +0800 Message-ID: <60cf45a1-53c9-d9d8-efda-c9ccbe08c65f@linux.alibaba.com> Date: Fri, 24 Sep 2021 11:35:33 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:93.0) Gecko/20100101 Thunderbird/93.0 Subject: Re: [PATCH v2 1/2] mm, thp: check page mapping when truncating page cache Content-Language: en-US To: Andrew Morton Cc: Matthew Wilcox , Linux MM , Linux Kernel Mailing List , song@kernel.org, william.kucharski@oracle.com, Hugh Dickins References: <20210906121200.57905-1-rongwei.wang@linux.alibaba.com> <20210922070645.47345-2-rongwei.wang@linux.alibaba.com> <20210923194343.ca0f29e1c4d361170343a6f2@linux-foundation.org> From: Rongwei Wang In-Reply-To: <20210923194343.ca0f29e1c4d361170343a6f2@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf02.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.56 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 161F57001A24 X-Stat-Signature: hqhq5x3ed9f3db79txwtx8drdzngk5hk X-HE-Tag: 1632454538-826078 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: On 9/24/21 10:43 AM, Andrew Morton wrote: > On Thu, 23 Sep 2021 01:04:54 +0800 Rongwei Wang wrote: > >> >>> On Sep 22, 2021, at 7:37 PM, Matthew Wilcox wro= te: >>> >>> On Wed, Sep 22, 2021 at 03:06:44PM +0800, Rongwei Wang wrote: >>>> Transparent huge page has supported read-only non-shmem files. The f= ile- >>>> backed THP is collapsed by khugepaged and truncated when written (fo= r >>>> shared libraries). >>>> >>>> However, there is race in two possible places. >>>> >>>> 1) multiple writers truncate the same page cache concurrently; >>>> 2) collapse_file rolls back when writer truncates the page cache; >>> As I've said before, the bug here is that somehow there is a writable= fd >>> to a file with THPs. That's what we need to track down and fix. >> Hi, Matthew >> I am not sure get your means. We know =E2=80=9Cmm, thp: relax the VM_D= ENYWRITE constraint on file-backed THPs" >> Introduced file-backed THPs for DSO. It is possible {very rarely} for = DSO to be opened in writeable way. >> >> ... >> >>> https://lore.kernel.org/linux-mm/YUdL3lFLFHzC80Wt@casper.infradead.or= g/ >> All in all, what you mean is that we should solve this race at the sou= rce? > Matthew is being pretty clear here: we shouldn't be permitting > userspace to get a writeable fd for a thp-backed file. > > Why are we permitting the DSO to be opened writeably? If there's a > legitimate case for doing this then presumably "mm, thp: relax the Hi, we have written a user case to trigger this race mentioned above.=20 this case just create one reader to open DSO in RDONLY mode, and keep making the mapping page of DSO use=20 huge pages by madvise, then multiple writer to open and write the same DSO. I will send it later after simple adjust. Thanks > VM_DENYWRITE constraint on file-backed THPs: should be fixed or > reverted. > > If there is no legitimate use case for returning a writeable fd for a > thp-backed file then we should fail such an attempt at open(). This > approach has back-compatibility issues which need to be thought about. > Perhaps we should permit the open-writeably attempt to appear to > succeed, but to really return a read-only fd?