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=-6.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 1B6ACC433DB for ; Tue, 29 Dec 2020 19:25:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6440C20825 for ; Tue, 29 Dec 2020 19:25:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6440C20825 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A2D516B009D; Tue, 29 Dec 2020 14:25:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E00D8D0036; Tue, 29 Dec 2020 14:25:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F4138D002C; Tue, 29 Dec 2020 14:25:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 788C76B009D for ; Tue, 29 Dec 2020 14:25:27 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2E34E3499 for ; Tue, 29 Dec 2020 19:25:27 +0000 (UTC) X-FDA: 77647298694.07.mass57_0108e532749e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 14F781803F9A2 for ; Tue, 29 Dec 2020 19:25:27 +0000 (UTC) X-HE-Tag: mass57_0108e532749e X-Filterd-Recvd-Size: 3348 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Dec 2020 19:25:26 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 79CD2207B1; Tue, 29 Dec 2020 19:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1609269925; bh=S53B3MXfxgRIbK6D3s82DloZ9F4fjewJwy+cHwDwW/w=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cWe9dtpnhSbg4h+UiuQvOP5pIPIc4UHeAhGrY1XREOUVycJ26CniF8lZe2NF2qjTi Ls4pW+cXZeTUetCraV0oGEy42CoYNW6f8zBXt1190+r0AS+hqSWbG36AzdESP+ykw8 U0bVqo2QzKJuFHKje8c+A7/7SHgYlb1xe4fZwB44= Date: Tue, 29 Dec 2020 11:25:24 -0800 From: Andrew Morton To: Peter Collingbourne Cc: Kostya Kortchinsky , linux-mm@kvack.org Subject: Re: [PATCH] mm: improve mprotect(R|W) efficiency on pages referenced once Message-Id: <20201229112524.4a7b8525949c4a50e5c4ecb6@linux-foundation.org> In-Reply-To: References: <20201212053152.3783250-1-pcc@google.com> <20201223143411.e889bcad32e5a1c0252c745c@linux-foundation.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Mon, 28 Dec 2020 18:09:28 -0800 Peter Collingbourne wrote: > On Wed, Dec 23, 2020 at 2:34 PM Andrew Morton wrote: > > > > On Fri, 11 Dec 2020 21:31:52 -0800 Peter Collingbourne wrote: > > > > > In the Scudo memory allocator [1] we would like to be able to > > > detect use-after-free vulnerabilities involving large allocations > > > by issuing mprotect(PROT_NONE) on the memory region used for the > > > allocation when it is deallocated. Later on, after the memory > > > region has been "quarantined" for a sufficient period of time we > > > would like to be able to use it for another allocation by issuing > > > mprotect(PROT_READ|PROT_WRITE). > > > > > > Before this patch, after removing the write protection, any writes > > > to the memory region would result in page faults and entering > > > the copy-on-write code path, even in the usual case where the > > > pages are only referenced by a single PTE, harming performance > > > unnecessarily. Make it so that any pages in anonymous mappings that > > > are only referenced by a single PTE are immediately made writable > > > during the mprotect so that we can avoid the page faults. > > > > > > > I worry that some other application out there does a similar thing, but > > only expects to very sparsely write to the area. It will see a big increase > > in mprotect() latency. > > > > Would it be better to implement this as a separate operation, rather > > than unconditionally tying it into mprotect()? Say, a new madvise() > > operation? > > So the case that you're concerned about would be highlighted by this > program, correct? > > ... > > So it seems that even with a single page fault the new approach is faster. > Cool, thanks. Can you please roll this new info into the changelog and resend?