Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1137670pxb; Thu, 23 Sep 2021 19:45:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznHOpFWWGFwAfrFOWXCxciQvLq96j3GA7+4j/6F8SuhuD7axz4EVGJQoOMgrva2i7jIJ7/ X-Received: by 2002:a50:d9cc:: with SMTP id x12mr2462526edj.44.1632451530397; Thu, 23 Sep 2021 19:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632451530; cv=none; d=google.com; s=arc-20160816; b=PUmHFFx8ff0XoDRxC90t1cWSAqE4U/i4PWxN7MSFhu+QO6Uen15msaVhZyh7l46po0 05G1VuCw5Rr7kATuNU2YZryqwSn4TUXrh3YmHYMDre4qkQlcksWS1lW5709LcmcaXdBI lvdWPEzRI/J6Wmv6qxWOK+Aoj+f2XG6YRK3yWPHi3vAwLix3KxBSgaqphXQQJ36y4Uvt S2jbDca5Z11H9FXztybTuTIzsXbQYtAr4JGJXniCBgef2rlaWQ5DRy+EbJ6QeJbijp7i +XA8oiaVJRmQ5FN9yMzhIAK6zLyZdC7qigSMDcON/AD2QioBTjU6SLy8je2Pef5HFWgr UbCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=rtpFkP8qMS2NNB1p9xj4NXYj4wfJt+YgA+okqd+nOnQ=; b=P4Onp5dv7X9/uM7AW1vAPC4y4WapoKs55TLZmrCkVPmckZMli6NkL/TJ8SA7pkRKUF nCw/F21fHiGOaESLitlojK8phP7AUIczIms5/OMXIaBHoBlJip+U/H7kPB+mOP9tyRyj Fyem+Vd6CX1r1VwC2yywBoLH4/vu5Z6gYQiYW+utJcaBPGJh8TCvJFGoe9vDa4q4WZdQ xzWcg+I17GsZ0kkatP7/SEYfNSawd6uzacXj1opi3Kw9iWmMFAXdap+YDesPilzDBS61 zR91tnSnRKr75flDiljUXXf0Si3Dcp+HVtkDES5JKTuSOHW4xAzBXta7p8Glq8yi0Zp8 stCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=NF4px9H0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de41si7741516ejc.244.2021.09.23.19.45.06; Thu, 23 Sep 2021 19:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=NF4px9H0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243921AbhIXCpR (ORCPT + 99 others); Thu, 23 Sep 2021 22:45:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:54454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233314AbhIXCpQ (ORCPT ); Thu, 23 Sep 2021 22:45:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 181AA610CB; Fri, 24 Sep 2021 02:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1632451424; bh=F3QkKswuGwQOCXfk/SaqNE24XSVoy4mqskLjR596bIw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NF4px9H06Hlw8rFhwiBjM+5UT5NYYROaIqe5rA0lXMeYHV596JNvS19bxrNuJ6BRc iUbLfYv3mjkROkmuJYuau4wv41xtutbQu3+yrXSgYoovteZJlKV/4N904TYIvHkzcY QgYhPsbQnRMtaW2FSXSwzshtXK4bIbaxk3WykHYE= Date: Thu, 23 Sep 2021 19:43:43 -0700 From: Andrew Morton To: Rongwei Wang Cc: Matthew Wilcox , Linux MM , Linux Kernel Mailing List , song@kernel.org, william.kucharski@oracle.com, Hugh Dickins Subject: Re: [PATCH v2 1/2] mm, thp: check page mapping when truncating page cache Message-Id: <20210923194343.ca0f29e1c4d361170343a6f2@linux-foundation.org> In-Reply-To: References: <20210906121200.57905-1-rongwei.wang@linux.alibaba.com> <20210922070645.47345-2-rongwei.wang@linux.alibaba.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 Sep 2021 01:04:54 +0800 Rongwei Wang wrote: > > > > On Sep 22, 2021, at 7:37 PM, Matthew Wilcox wrote: > > > > On Wed, Sep 22, 2021 at 03:06:44PM +0800, Rongwei Wang wrote: > >> Transparent huge page has supported read-only non-shmem files. The file- > >> backed THP is collapsed by khugepaged and truncated when written (for > >> 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 “mm, thp: relax the VM_DENYWRITE 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.org/ > All in all, what you mean is that we should solve this race at the source? 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 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?