From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E686B47F53 for ; Mon, 8 Jul 2024 08:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720426292; cv=none; b=RX33eC3Sny/BaVl7TK7XkIPW7kAmcZ9MDKR9Nls+BsuyI8nw2TXhssqSnur+1vLETJpFkgbj8YkH8+p7rk+xR78RDrA2FM6x6ml3KrIsJ0WhPBZLrYJQz0dBmf0g/VLJuXL+kaI4HN0PMb5wYdbTiSTsXHhWBao5gIp21rSX7M4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720426292; c=relaxed/simple; bh=2oLuXobac5roJSa3IO5/5qzJKdTUjyDWzEQLC8i5HaQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nqgHlcKT4m9BUoQ6BDtYVFkT5kEeT+bFPyZ8AyeAiisOTdQDVmar/yxLePm9curxYVm07nPWWw9d3q7Yk5A9msWXToc0myjcoYrFi0hbTxIoAylxFxM5dEC8EZu3RW8Y++wMv5GoS4V1cHStxES9d+E+VarCx5ATmlR71zKMsn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CRDh1ppo; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CRDh1ppo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720426289; h=from:from: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:autocrypt:autocrypt; bh=Gp+JU/F91iJfi0msXelpd8IVzKHprY8FUr3nyaI8s/Y=; b=CRDh1ppojph0lN/tUL2mekl2l1WsWpgjT+L+wEm3k6/u6nNgRDBPPk2CL+l3OQ7uwUTl7X i0pW1WxmfI6T+ystmAYTzO/6RskWBuexa1mjzBRJ0qsllnLDV1fJu6biNp7jzcitE+IdDM rfPsTraNv2gIEwSDNJa2R67zBsRF4QA= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-78-b2WbAM__M8uzQDe2H5tfuA-1; Mon, 08 Jul 2024 04:11:28 -0400 X-MC-Unique: b2WbAM__M8uzQDe2H5tfuA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a7275e17256so320920366b.0 for ; Mon, 08 Jul 2024 01:11:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720426287; x=1721031087; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Gp+JU/F91iJfi0msXelpd8IVzKHprY8FUr3nyaI8s/Y=; b=hZoVz+SAu9Ebr/Pj9T7SHggYfmXzf0RObDyO+rayauR0qISsRONELF11ECi8gDIisx skzLOplB3G0sxgw0Uy6atvb2VLLiQvQxIY5NEis9qb/JErmQXu6P1PsHao2lhtDye+sX 3raoKfY1hYSv2qhsKLkT4EDCdf2+5CsfWwKcme/s9Aj9KTQB9ki2OLrSoHYvHYKfI3VF 9UTH8QmC6FK0WgtlpnaHNWanyD16xq8CNXWCdp9TCpExtT0PZAZVSHSWWFGv8WGeOq/N skUfcO5bMGWyBOLHXhwOryUKe7/ytUggj7MOByLrkKRBoVm4DLmZwfQN1uYc7tYSDmtl BszA== X-Forwarded-Encrypted: i=1; AJvYcCUJLopKPBcfvcshOUoekNmdUl3GVPVOJsSoPs+QvBF68UrPbHCBSUkoYfWCT8I1lnyPUNOz6HhpD12pqGk+bjjHIktqesGoRUu2IcxM X-Gm-Message-State: AOJu0Ywx0LVR5s9UxoqLmprbr2vTRYy8RHEUFmhKL8W+pMKN57WbAiVj OhFr8v/Dl93hFNkHHadB4z1d46agxkXveiYvH9TccCyBp8WMc/G3KVmXxuCJnLbNxj0GB8xi/z+ 7FMb/I7HUR+o2tvyibMFG0wsLcgvnvZzIIk02/on7liAh43H/PnxWOW5/ETvRMQ== X-Received: by 2002:a05:6402:311c:b0:58c:adad:cbb with SMTP id 4fb4d7f45d1cf-58e5cc0b694mr5634062a12.38.1720426287098; Mon, 08 Jul 2024 01:11:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERhu1ncMdDmYLIvyQzpQhR84SA4zIqAfzm6r9bAw/Jyk06nNBrd+LkPTmKZbo4Xr0uenl3oQ== X-Received: by 2002:a05:6402:311c:b0:58c:adad:cbb with SMTP id 4fb4d7f45d1cf-58e5cc0b694mr5634038a12.38.1720426286701; Mon, 08 Jul 2024 01:11:26 -0700 (PDT) Received: from [100.81.188.195] ([178.24.249.36]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-593c7f2845fsm411567a12.95.2024.07.08.01.11.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jul 2024 01:11:26 -0700 (PDT) Message-ID: <7439da2e-4a60-4643-9804-17e99ce6e312@redhat.com> Date: Mon, 8 Jul 2024 10:11:24 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v21 1/4] mm: add VM_DROPPABLE for designating always lazily freeable mappings To: Linus Torvalds Cc: "Jason A. Donenfeld" , linux-kernel@vger.kernel.org, patches@lists.linux.dev, tglx@linutronix.de, linux-crypto@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, Greg Kroah-Hartman , Adhemerval Zanella Netto , Carlos O'Donell , Florian Weimer , Arnd Bergmann , Jann Horn , Christian Brauner , David Hildenbrand , linux-mm@kvack.org References: <20240707002658.1917440-1-Jason@zx2c4.com> <20240707002658.1917440-2-Jason@zx2c4.com> <1583c837-a4d5-4a8a-9c1d-2c64548cd199@redhat.com> <6705c6c8-8b6a-4d03-ae0f-aa83442ec0ab@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5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7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 08.07.24 02:08, Linus Torvalds wrote: > On Sun, 7 Jul 2024 at 14:01, David Hildenbrand wrote: >> >> At least MAP_DROPPABLE doesn't quite make sense with hugetlb, but at least >> the other ones do have semantics with hugetlb? > > Hmm. > > How about we just say that VM_DROPPABLE really is something separate > from MAP_PRIVATE or MAP_SHARED.. So it would essentially currently imply MAP_ANON|MAP_PRIVATE, without COW (not shared with a child process). Then, we should ignore any fd+offset that is passed (or bail out); I assume that's what your proposal below does automatically without diving into the code. > > And then we make the rule be that VM_DROPPABLE is never dumped and > always dropped on fork, just to make things simpler. The semantics are much more intuitive. No need for separate mmap flags. > > It not only avoids a flag, but it actually makes sense: the pages > aren't stable for dumping anyway, and not copying them on fork() not > only avoids some overhead, but makes it much more reliable and > testable. > > IOW, how about taking this approach: > > --- a/include/uapi/linux/mman.h > +++ b/include/uapi/linux/mman.h > @@ -17,5 +17,6 @@ > #define MAP_SHARED 0x01 /* Share changes */ > #define MAP_PRIVATE 0x02 /* Changes are private */ > #define MAP_SHARED_VALIDATE 0x03 /* share + validate extension flags */ > +#define MAP_DROPPABLE 0x08 /* 4 is not in MAP_TYPE on parisc? */ > > /* > > with do_mmap() doing: > > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1369,6 +1369,23 @@ unsigned long do_mmap(struct file *file, > pgoff = 0; > vm_flags |= VM_SHARED | VM_MAYSHARE; > break; > + case MAP_DROPPABLE: > + /* > + * A locked or stack area makes no sense to > + * be droppable. > + * > + * Also, since droppable pages can just go > + * away at any time, it makes no sense to > + * copy them on fork or dump them. > + */ > + if (flags & MAP_LOCKED) > + return -EINVAL; Likely we'll have to adjust mlock() as well. Also, I think we should just bail out with hugetlb as well. > + if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP)) > + return -EINVAL; > + > + vm_flags |= VM_DROPPABLE; > + vm_flags |= VM_WIPEONFORK | VM_DONTDUMP; Further, maybe we want to disallow madvise() clearing these flags here, just to be consistent. > + fallthrough; > case MAP_PRIVATE: > /* > * Set pgoff according to addr for anon_vma. > > which looks rather simple. > > The only oddity is that parisc thing - every other archiecture has the > MAP_TYPE bits being 0xf, but parisc uses 0x2b (also four bits, but > instead of the low four bits it's 00101011 - strange). I assume, changing that would have the risk of breaking stupid user space, right? (that sets a bit without any semantics) > > So using 8 as a MAP_TYPE bit for MAP_DROPPABLE works everywhere, and > if we eventually want to do a "signaling" MAP_DROPPABLE we could use > 9. Sounds good enough. > > This has the added advantage that if somebody does this on an old > kernel,. they *will* get an error. Because unlike the 'flag' bits in > general, the MAP_TYPE bit space has always been tested. > > Hmm? As a side note, I'll raise that I am not a particular fan of the "droppable" terminology, at least with the "read 0s" approach. From a user perspective, the memory might suddenly lose its state and read as 0s just like volatile memory when it loses power. "dropping pages" sounds more like an implementation detail. Something like MAP_VOLATILE might be more intuitive (similar to the proposed MADV_VOLATILE). But naming is hard, just mentioning to share my thought :) -- Cheers, David / dhildenb