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 287E9CDD0FB for ; Tue, 22 Oct 2024 22:54:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A1E68D0003; Tue, 22 Oct 2024 18:54:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 451C68D0001; Tue, 22 Oct 2024 18:54:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 341758D0003; Tue, 22 Oct 2024 18:54:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 16B738D0001 for ; Tue, 22 Oct 2024 18:54:15 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6FEE8C056D for ; Tue, 22 Oct 2024 22:53:56 +0000 (UTC) X-FDA: 82702742724.23.3E52D80 Received: from cvs.openbsd.org (cvs.openbsd.org [199.185.137.3]) by imf03.hostedemail.com (Postfix) with ESMTP id B3CEF20004 for ; Tue, 22 Oct 2024 22:54:04 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=openbsd.org header.s=selector1 header.b=lFjN3toC; spf=pass (imf03.hostedemail.com: domain of deraadt@openbsd.org designates 199.185.137.3 as permitted sender) smtp.mailfrom=deraadt@openbsd.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729637601; 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:dkim-signature; bh=WHzMrjfMruvIpHlEeAVxdb46yOKuKbxbn7rKbjAxujE=; b=b2dlGpOi8SW2uZCGGuXtOo1lbCHN3UVrmetl16wDU7yKqH5rSk9hTMgaYBkctgDmr5PJQf o7mBe+8k9AIxbaxKHnxxhU1NtqB8hShq+/z2kACZgUD32lELH2YxfDBlK7QNYBSI57HwWi VPxhnh92v1VBpuzTq68yZCMpaZk5mpg= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=openbsd.org header.s=selector1 header.b=lFjN3toC; spf=pass (imf03.hostedemail.com: domain of deraadt@openbsd.org designates 199.185.137.3 as permitted sender) smtp.mailfrom=deraadt@openbsd.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729637601; a=rsa-sha256; cv=none; b=QbzWL62F3wEBKKGMw1EdH2ap/WOWiLdzpLBDI2EFAYjaTHmjOkDhPfI1jUMA5TxZyoI3mg LExX37MKzmm0qmeeLKrTUtcwFXaCFuIxy0pu9bBRE9oUNL2iZ6J6NKYybYaekmzGVII4le gnaDWyEBK1Nku/utl1esdX22cust9J4= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=selector1; bh=WHzMrjfMru vIpHlEeAVxdb46yOKuKbxbn7rKbjAxujE=; h=date:references:in-reply-to: subject:cc:to:from; d=openbsd.org; b=lFjN3toCofQICkNsgOwYoO6iSIp7lx39o awIIft8WIVAsZ9DztAffz7LJqnfH4DTfPocBxsBD6t67EXKeu3eipzkVdvleVoAkNZ8a1P FsKJ7gzPEwP+23He9FJlEzg2+K3mmwy/TILcjoDQXKU7Fr6PoNzr95etBic+wJMXZ/vuhj 4eq9tNnt5AhWjWtsvhiBVvSqiRqdBo1C3er+wU8Vh4PYeCnf+6CUwY5tE15VpSZmmVxoxZ PeiduAN5QDp9t7qyBuIpDDjWLMJRYGzQArETpt9tnzpcSrNafYSiou39NpF7libGRiz3Cn CI3803K611G0LzgunV2rb1ur943gA== Received: from cvs.openbsd.org (localhost [127.0.0.1]) by cvs.openbsd.org (OpenSMTPD) with ESMTP id 373605c3; Tue, 22 Oct 2024 16:54:10 -0600 (MDT) From: "Theo de Raadt" To: Vlastimil Babka cc: Jeff Xu , Pedro Falcato , akpm@linux-foundation.org, keescook@chromium.org, torvalds@linux-foundation.org, usama.anjum@collabora.com, corbet@lwn.net, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, sroettger@google.com, linux-hardening@vger.kernel.org, willy@infradead.org, gregkh@linuxfoundation.org, surenb@google.com, merimus@google.com, rdunlap@infradead.org, stable@vger.kernel.org Subject: Re: [PATCH v1 1/2] mseal: Two fixes for madvise(MADV_DONTNEED) when sealed In-reply-to: <8f68ad82-2f60-49f8-b150-0cf183c9cc71@suse.cz> References: <20241017005105.3047458-1-jeffxu@chromium.org> <20241017005105.3047458-2-jeffxu@chromium.org> <5svaztlptf4gs4sp6zyzycwjm2fnpd2xw3oirsls67sq7gq7wv@pwcktbixrzdo> <8f68ad82-2f60-49f8-b150-0cf183c9cc71@suse.cz> Comments: In-reply-to Vlastimil Babka message dated "Tue, 22 Oct 2024 17:55:43 +0200." MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 22 Oct 2024 16:54:10 -0600 Message-ID: <35887.1729637650@cvs.openbsd.org> X-Rspam-User: X-Stat-Signature: s4hw7rc7qy14p1qam1kgoezy4y3m3i5t X-Rspamd-Queue-Id: B3CEF20004 X-Rspamd-Server: rspam11 X-HE-Tag: 1729637644-486534 X-HE-Meta: U2FsdGVkX1/z05pjFwu0wLUMmmArV9Bi5CvPNF7E4O1K21o9h7qfBAd5sjPVFKAPS+FzuN0fpsx6D+9aW7uP0tMWzoUI/7DJKr4Jt8dO2gPGaO4DxLPdRdAU2+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/+BRj3j2CtYbrmw2NWYoPTBV0GBVcZnMVddZuBbiXaJ9I4A33cuNFTdTyg/qIEt2Ff/IXFB+BHaSETkT9l6eauNZ6ef5MkDgJ87PiKWVcBTJsN7zdW2tb8MKFoXu3PmDsR68rS/a4kOxuX0GvFkLk8YqosqhKUcmKEtucWyyRJz+1NH5Bp4o9q9nPlRKKQ5PoSYQZBWAMNcT9Ol3nd/7IjG5bOTUlTqAlaXNA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000126, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Vlastimil Babka wrote: > On 10/17/24 22:57, Jeff Xu wrote: > > On Thu, Oct 17, 2024 at 1:49=E2=80=AFPM Pedro Falcato wrote: > >> > > >> > > > For file-backed, private, read-only memory mappings, we previous= ly did > >> > > > not block the madvise(MADV_DONTNEED). This was based on > >> > > > the assumption that the memory's content, being file-backed, cou= ld be > >> > > > retrieved from the file if accessed again. However, this assumpt= ion > >> > > > failed to consider scenarios where a mapping is initially create= d as > >> > > > read-write, modified, and subsequently changed to read-only. The= newly > >> > > > introduced VM_WASWRITE flag addresses this oversight. > >> > > > >> > > We *do not* need this. It's sufficient to just block discard opera= tions on read-only > >> > > private mappings. > >> > I think you meant blocking madvise(MADV_DONTNEED) on all read-only > >> > private file-backed mappings. > >> > > >> > I considered that option, but there is a use case for madvise on tho= se > >> > mappings that never get modified. > >> > > >> > Apps can use that to free up RAM. e.g. Considering read-only .text > >> > section, which never gets modified, madvise( MADV_DONTNEED) can free > >> > up RAM when memory is in-stress, memory will be reclaimed from a > >> > backed-file on next read access. Therefore we can't just block all > >> > read-only private file-backed mapping, only those that really need t= o, > >> > such as mapping changed from rw=3D>r (what you described) > >> > >> Does anyone actually do this? If so, why? WHYYYY? > >> > > This is a legit use case, I can't argue that it isn't. >=20 > Could the same effect be simply achieved with MADV_COLD/MADV_PAGEOUT? That > should be able to reclaim the pages as well if they are indeed not used, = but > it's non-destructive and you don't want to allow destructive madvise anyw= ay > (i.e. no throwing away data that would be replaced by zeroes or original > file content on the next touch) so it seems overall a better fit for seal= ed > areas? Comment from the sidelines: That seems clever enough.