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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 7D3DAC433E0 for ; Wed, 30 Dec 2020 00:44:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 102A7207B8 for ; Wed, 30 Dec 2020 00:44:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 102A7207B8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 404356B00AC; Tue, 29 Dec 2020 19:44:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DBB98D006A; Tue, 29 Dec 2020 19:44:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 317C96B00B0; Tue, 29 Dec 2020 19:44:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 1CB6E6B00AC for ; Tue, 29 Dec 2020 19:44:01 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D7D733629 for ; Wed, 30 Dec 2020 00:44:00 +0000 (UTC) X-FDA: 77648101440.06.page75_4907a77274a0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id ED29F10045844 for ; Wed, 30 Dec 2020 00:43:50 +0000 (UTC) X-HE-Tag: page75_4907a77274a0 X-Filterd-Recvd-Size: 4900 Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Dec 2020 00:43:50 +0000 (UTC) Received: by mail-il1-f170.google.com with SMTP id t9so13614732ilf.2 for ; Tue, 29 Dec 2020 16:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lOiPPkpSsEAQ0zxYp5UTZKOHbm2BfrBMjuXQfTnFZWA=; b=Oc1B6WW0iNuElnS4egirusGp/Q0piWDKw4KcN2CqVO5VZrmP8z5Ehbkebz0CcyCUgE xGwDhZ4IUv8KqOs/e5Gn11HTiwAlbdiZg6XjTCdFwnW+dbHqGRxnT1dNN1EXR191KCt9 j8yBMQnIuxei2l8ygOOk+1/ypbBauslfsqH9R0UjhcWXpiY7qoX/EiE0yMF5FcGPfYys tPvNVsPdjpKXzS3bQHF0+RqRuiLJtW9YhukpMMbabrmoOTwGDW2RQWOltZEvugRkMg/p zBTU0zDQYQkBeuNdjnGD4YSbRvI56Vbn0VRMCz9dZxiCh/nYV9g73BxU/vfW6MZJDEeV yLLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lOiPPkpSsEAQ0zxYp5UTZKOHbm2BfrBMjuXQfTnFZWA=; b=ZCHHh/gOsnuDd9RTEQ6Rl7lh37/2y3w0F3WfxfjC57TwGXhcqncrl1pMZByyLiL4iI Q1SGbqmG1UAe50pdZEACc5imr5N1xUQftJp9dL0J35nVzEvdZRzbvghlEnX+9RKXkP4q /xztSBm8vqzx24rCGvpBTU3JEz26FUaEiAEprwIz22MqiaU0FVkaqiekXl9POnPgfZme 8q8wtoSTd/xEc9cWNnUrt9EmOLGAlB4JZhSnDh39BiKZOEGtKkCZOeISb12HNSw03PXO cdX4WpV6HP2OuToVHC/L+Z3gp3uOPbke9b66V5gzK3NwvUMhnfAI9MJGAPGFNjoUJ9ha hP1g== X-Gm-Message-State: AOAM532kWX5u5ARoK31aNta/Yxn11ZcHFUYFV7m7IwHkHzdIIcC3rk/9 07cckIRvdWkTs9Z0x9MLul6iNJ3WzDOSjiyi97+3xg== X-Google-Smtp-Source: ABdhPJxoQTntep7ZwkHF/HQM/gxUfa5JwXkagyn/nfNavIWHvoNnUtpP6lFPLFpaUHVLgyhAgm1gieSRjJNPCZZC2TI= X-Received: by 2002:a05:6e02:f86:: with SMTP id v6mr50131230ilo.56.1609289029749; Tue, 29 Dec 2020 16:43:49 -0800 (PST) MIME-Version: 1.0 References: <20201212053152.3783250-1-pcc@google.com> <20201223143411.e889bcad32e5a1c0252c745c@linux-foundation.org> <20201229112524.4a7b8525949c4a50e5c4ecb6@linux-foundation.org> In-Reply-To: <20201229112524.4a7b8525949c4a50e5c4ecb6@linux-foundation.org> From: Peter Collingbourne Date: Tue, 29 Dec 2020 16:43:38 -0800 Message-ID: Subject: Re: [PATCH] mm: improve mprotect(R|W) efficiency on pages referenced once To: Andrew Morton Cc: Kostya Kortchinsky , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" 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 Tue, Dec 29, 2020 at 11:25 AM Andrew Morton wrote: > > 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? Sent a v2 with the new info added to the commit message. Peter