Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp935037rdb; Wed, 1 Nov 2023 07:04:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjpflbZ4ogAFwviOwTFyqu8YmA3P7T0VlIoSTHVFWPi5luXIdLO7u9TNfXBk18pJ1liezp X-Received: by 2002:a17:902:f687:b0:1cc:6101:2094 with SMTP id l7-20020a170902f68700b001cc61012094mr7840305plg.14.1698847455713; Wed, 01 Nov 2023 07:04:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698847455; cv=none; d=google.com; s=arc-20160816; b=fJqCikZKBjl3KywBcIvLuLYI8RRZFrHCRxbhPYAYFl6VwXwKiW/3Yn351B2e9kH2u3 7rNcmfxi6JjNbhr7TWBalO0Bw18Yei5OI+9XihTTyTQmz5L0P9OOTQ5MYx6ZlVkdza1q B3opqwBLDkGtkn5VZVVwuPRWtbA1bebT8K+co/9j0FotN0FW8MoKesrmjGjq/9x/wJxG g7NAiOuLoSIuhPQoHDFOUSh1liqGwP1Gc+B35B96xWo6DGwkthxYvbgxxkBsCtUcjIjB hALpuaS6X9dO2aReqP1LX9asLGQcl0Xjw/bkpDI40/jFevM9gnDe5heJwrwmjfQ9cSLq faTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:content-language:references:cc:to :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=4qPavatvkwmUdF4Ofe6L1kWMfN08faPQqt3/qXkkW6s=; fh=ITbjFonzRW6ew2zwP7v+jI9RITS0CIdFuFsPkUdyBOc=; b=c2Go3e2dsIadSXaePhYSiW2SacUtlfz9BUB/2TNY460Pie2nQww3xDRGIROS3S9/1o QPcaUJCszBU3CWTEPvbeCQgsbud8PlaPl5VS4UMAKfcgIj6ymGXrUoBR5KgK9Q48pT1q o4n7Ve9ssue35g1bM17QLuT3GU9wUf2NWmUxKbi/XFEyHcLoUap6cXaqAgPJFTcLVW/M fqUfCOPlGGRhmB7o0OLWu5oSfGpVThHs8G3kdVMbcbfebAH8OZWbICQixZjYXPCbK53U tUxBz4oXa7vMR/F9nyoiVFRwY+1yhM6CarDZL0l47wlHgQPSPMFWlzdG/MPep8dQYvOE i9AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EAD5juXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id g2-20020a170902e38200b001ca67f26f5esi2909889ple.283.2023.11.01.07.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 07:04:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EAD5juXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4DA5A805B058; Wed, 1 Nov 2023 07:04:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344082AbjKAOEF (ORCPT + 99 others); Wed, 1 Nov 2023 10:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235509AbjKAOEA (ORCPT ); Wed, 1 Nov 2023 10:04:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70435115 for ; Wed, 1 Nov 2023 07:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698847391; 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=4qPavatvkwmUdF4Ofe6L1kWMfN08faPQqt3/qXkkW6s=; b=EAD5juXp3LudtC4ja00PuXMBKc2677XFRA0KDpoAvbYv9ZlS7Kq/btFXLHTamtJ8MJ/CKF KiYnmZ5pbnzgpnEDXZusolwng0EV3AuWx5W7xI8Qe458oZk2KZI1iV/e8cjwjK0TdBVZoq YcqHAPPfdYHS2dsa9BaEou53zSNfUqs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-KxzlL554M0us4FJfigQfHw-1; Wed, 01 Nov 2023 10:03:03 -0400 X-MC-Unique: KxzlL554M0us4FJfigQfHw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40845fe2d1cso48462005e9.0 for ; Wed, 01 Nov 2023 07:02:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698847374; x=1699452174; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language: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=4qPavatvkwmUdF4Ofe6L1kWMfN08faPQqt3/qXkkW6s=; b=HRiC8zaKlNcEr0uq7Kae9ol/bLYzOjGMBDWZLGs7T8QqCYkNpT2oX31VNy/Z8pAeUq kRCu0LDQaaUv0k2RAPn4mkyc1U9aN+0lYl9OX/JboBowER2RAKvT0Efw6gU9ruqkokXK T7D1ifrwx/IWZpBg6p72cHJC5Qt3KHLowgyEFPgd6Wr/NL7atHZ4HiOWXUeaFd12FF1s 8GpDs+PXa0P3BeSZbHZALcjqIQNdW3UNUkW/tUR5V/8p15gQuzK9cgTX2ecGozjL1fu7 7ej0dlJoo7JHjVbT3caOvHZEyDqFzvkbEkPbuq2RhAN7dJqGARWF0FCD7Cxq1YrHh1dT WqQg== X-Gm-Message-State: AOJu0Yw089LNAMrFhPiMF8fZH3CppEaD2nqCR+jWwWlE+AJjAPZ+JQSm KbPcLKSj7z79nqNwlBQrdJ0UJZYb7Ox1WYgIbZ74I6XeslZUqbeJQPTW36ErTqor1+li8ttnNRx 5H2ytxZhAL6SMRZolMebtM496 X-Received: by 2002:a05:600c:3c9a:b0:404:2dbb:8943 with SMTP id bg26-20020a05600c3c9a00b004042dbb8943mr14116074wmb.2.1698847374222; Wed, 01 Nov 2023 07:02:54 -0700 (PDT) X-Received: by 2002:a05:600c:3c9a:b0:404:2dbb:8943 with SMTP id bg26-20020a05600c3c9a00b004042dbb8943mr14116042wmb.2.1698847373782; Wed, 01 Nov 2023 07:02:53 -0700 (PDT) Received: from ?IPV6:2003:cb:c70b:f400:399f:9457:3eb8:da7f? (p200300cbc70bf400399f94573eb8da7f.dip0.t-ipconnect.de. [2003:cb:c70b:f400:399f:9457:3eb8:da7f]) by smtp.gmail.com with ESMTPSA id dn11-20020a0560000c0b00b0032da319a27asm4253674wrb.9.2023.11.01.07.02.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Nov 2023 07:02:53 -0700 (PDT) Message-ID: <1358598e-2c5b-4600-af54-64bf241dc760@redhat.com> Date: Wed, 1 Nov 2023 15:02:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Sharing page tables across processes (mshare) To: Khalid Aziz , Matthew Wilcox , Mike Kravetz , Peter Xu , rongwei.wang@linux.alibaba.com, Mark Hemment Cc: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" References: <4082bc40-a99a-4b54-91e5-a1b55828d202@oracle.com> Content-Language: en-US From: David Hildenbrand 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 UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKrXNcTDpG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RL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <4082bc40-a99a-4b54-91e5-a1b55828d202@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 01 Nov 2023 07:04:12 -0700 (PDT) > ---------- > What next? > ---------- > > There were some more discussions on this proposal while I was on > leave for a few months. There is enough interest in this feature to > continue to refine this. I will refine the code further but before > that I want to make sure we have a common understanding of what this > feature should do. Did you follow-up on the alternatives discussed in a bi-weekly mm session on this topic or is there some other reason you are leaving that out? To be precise, I raised that both problems should likely be decoupled (sharing of page tables as an optimization, NOT using mprotect to catch write access to pagecache pages). And that page table sharing better remains an implementation detail. Sharing of page tables (as learned by hugetlb) can easily be beneficial to other use cases -- for example, multi-process VMs; no need to bring in mshare. There was the concern that it might not always be reasonable to share page tables, so one could just have some kind of hint (madvise? mmap flag?) that it might be reasonable to try sharing page tables. But it would be a pure internal optimization. Just like it is for hugetlb we would unshare as soon as someone does an mprotect() etc. Initially, you could simply ignore any such hint for filesystems that don't support it. Starting with shmem sounds reasonable. Write access to pagecache pages (or also read-access?) would ideally be handled on the pagecache level, so you could catch any write (page tables, write(), ... and eventually later read access if required) and either notify someone (uffd-style, just on a fd) or send a signal to the faulting process. That would be a new feature, of course. But we do have writenotify infrastructure in place to catch write access to pagecache pages already, whereby we inform the FS that someone wants to write to a PTE-read-only pagecache page. Once you combine both features, you can easily update only a single shared page table when updating the page protection as triggered by the FS/yet-to-be-named-feature and have all processes sharing these page tables see the change in one go. > > As a result of many discussions, a new distinct version of > original proposal has evolved. Which one do we agree to continue > forward with - (1) current version which restricts sharing to PMD sized > and aligned file mappings only, using just a new mmap flag > (MAP_SHARED_PT), or (2) original version that creates an empty page > table shared mshare region using msharefs and mmap for arbitrary > objects to be mapped into later? So far my opinion on this is unchanged: turning an implementation detail (sharing of page tables) into a feature to bypass per-process VMA permissions sounds absolutely bad to me. The original concept of mshare certainly sounds interesting, but as discussed a couple of times (LSF/mm), it similarly sounds "dangerous" the way it was originally proposed. Having some kind of container that multiple process can mmap (fd?), and *selected* mmap()/mprotect()/ get rerouted to the container could be interesting; but it might be reasonable to then have separate operations to work on such an fd (ioctl), and *not* using mmap()/mprotect() for that. And one might only want to allow to mmap that fd with a superset of all permissions used inside the container (and only MAP_SHARED), and strictly filter what we allow to map into such a container. page table sharing would likely be an implementation detail. Just some random thoughts (some of which I previously raised). Probably makes sense to discuss that in a bi-weekly mm meeting (again, this time with you as well). -- Cheers, David / dhildenb