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.129.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 36A636121 for ; Wed, 14 Dec 2022 11:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671016975; 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; bh=yxc01zNwMiugjthmgVOlTrtXQnLfLvXjRGMFtbZZLpc=; b=TRsRFy5HWKRJqqxwbSC38MkkVL+pzQVaN48RIhRUvbQBZyedt24vDxP9faiB3QhLUvtPSW jUDazLShTTjthZ9qY/reRE4y5Cap5trYiKq0KlvknrQ+4PgoYPXpD9HQWOo6Qg6rAtYfiW /1ZfU7LhfXDdM3IHhUpPVAiJXEkDOlY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-593-pizQUL_FOFGUR3aIUBVqpQ-1; Wed, 14 Dec 2022 06:22:54 -0500 X-MC-Unique: pizQUL_FOFGUR3aIUBVqpQ-1 Received: by mail-wm1-f72.google.com with SMTP id i132-20020a1c3b8a000000b003d0f49bc21bso7087814wma.6 for ; Wed, 14 Dec 2022 03:22:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yxc01zNwMiugjthmgVOlTrtXQnLfLvXjRGMFtbZZLpc=; b=n8oLH0LLuYFPKaOE1+vPrSifd5TnYTIgKbgfy9asEOhUtKUQw74TiXNeCXtwFyXTai RiS7/+jHTZDgredj8taYLW67XqG5JWsLkORvQr5iGQZC14O79g9tbq3WSecIjwLLA+N5 8YUVjReNZVCZuQDBkLG60dHClY7XZ+/oNxSAfhKx8BCI2HpPIqHEWL3ccym2bPin0Dcq AVysKX/E6IGzU16yoQKltX9oKYjEW/e+TkqXPEyF5/3M5QXT6YdN0nvpc75BCCqw85yp d4dAyjd4axiJDi4D4oZo5Hpx0UPevRVcMlOx1/Mxkdj73YsQpUQlYprVJIPHm5j0vhI2 PrPQ== X-Gm-Message-State: ANoB5plibxJBTA1QmnbFnPK047cduc28v4+jLRSrk1T9yNY7fhshCdCe uwGhPQ0h7CHBIhxGIwbBp4BTuRxcf81KhUo96dJGNStGe+0VEB9iqd2j5//rLWP2OB7MBub5D3I 29VndyFqMJNAuz01gTcWR X-Received: by 2002:a05:600c:1da2:b0:3cf:5fd2:87a0 with SMTP id p34-20020a05600c1da200b003cf5fd287a0mr17488517wms.40.1671016973462; Wed, 14 Dec 2022 03:22:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4UNUk6/OXN07sN3FMRll3MrS2ehO8GnTfEO+JQv3BigUvXvNgLJLKqkas5vWijxjr/1KiucA== X-Received: by 2002:a05:600c:1da2:b0:3cf:5fd2:87a0 with SMTP id p34-20020a05600c1da200b003cf5fd287a0mr17488468wms.40.1671016973157; Wed, 14 Dec 2022 03:22:53 -0800 (PST) Received: from ?IPV6:2003:cb:c703:7700:dd7c:92f8:481f:b96b? (p200300cbc7037700dd7c92f8481fb96b.dip0.t-ipconnect.de. [2003:cb:c703:7700:dd7c:92f8:481f:b96b]) by smtp.gmail.com with ESMTPSA id o3-20020a05600c510300b003cfa3a12660sm8504320wms.1.2022.12.14.03.22.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Dec 2022 03:22:52 -0800 (PST) Message-ID: <10bd4fc0-4fc0-bd98-6926-7d721a3bb12e@redhat.com> Date: Wed, 14 Dec 2022 12:22:49 +0100 Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH mm-unstable RFC 00/26] mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE on all architectures with swap PTEs To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , John Hubbard , Jason Gunthorpe , Mike Rapoport , Yang Shi , Vlastimil Babka , Nadav Amit , Andrea Arcangeli , Peter Xu , linux-mm@kvack.org, x86@kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-xtensa@linux-xtensa.org, Albert Ou , Anton Ivanov , Borislav Petkov , Brian Cain , Christophe Leroy , Chris Zankel , Dave Hansen , "David S. Miller" , Dinh Nguyen , Geert Uytterhoeven , Greg Ungerer , Guo Ren , Helge Deller , "H. Peter Anvin" , Huacai Chen , Ingo Molnar , Ivan Kokshaysky , "James E.J. Bottomley" , Johannes Berg , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Nicholas Piggin , Palmer Dabbelt , Paul Walmsley , Richard Henderson , Richard Weinberger , Rich Felker , Russell King , Stafford Horne , Stefan Kristiansson , Thomas Bogendoerfer , Thomas Gleixner , Vineet Gupta , WANG Xuerui , Yoshinori Sato References: <20221206144730.163732-1-david@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20221206144730.163732-1-david@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 06.12.22 15:47, David Hildenbrand wrote: > This is the follow-up on [1]: > [PATCH v2 0/8] mm: COW fixes part 3: reliable GUP R/W FOLL_GET of > anonymous pages > > After we implemented __HAVE_ARCH_PTE_SWP_EXCLUSIVE on most prominent > enterprise architectures, implement __HAVE_ARCH_PTE_SWP_EXCLUSIVE on all > remaining architectures that support swap PTEs. > > This makes sure that exclusive anonymous pages will stay exclusive, even > after they were swapped out -- for example, making GUP R/W FOLL_GET of > anonymous pages reliable. Details can be found in [1]. > > This primarily fixes remaining known O_DIRECT memory corruptions that can > happen on concurrent swapout, whereby we can lose DMA reads to a page > (modifying the user page by writing to it). > > To verify, there are two test cases (requiring swap space, obviously): > (1) The O_DIRECT+swapout test case [2] from Andrea. This test case tries > triggering a race condition. > (2) My vmsplice() test case [3] that tries to detect if the exclusive > marker was lost during swapout, not relying on a race condition. > > > For example, on 32bit x86 (with and without PAE), my test case fails > without these patches: > $ ./test_swp_exclusive > FAIL: page was replaced during COW > But succeeds with these patches: > $ ./test_swp_exclusive > PASS: page was not replaced during COW > > > Why implement __HAVE_ARCH_PTE_SWP_EXCLUSIVE for all architectures, even > the ones where swap support might be in a questionable state? This is the > first step towards removing "readable_exclusive" migration entries, and > instead using pte_swp_exclusive() also with (readable) migration entries > instead (as suggested by Peter). The only missing piece for that is > supporting pmd_swp_exclusive() on relevant architectures with THP > migration support. > > As all relevant architectures now implement __HAVE_ARCH_PTE_SWP_EXCLUSIVE,, > we can drop __HAVE_ARCH_PTE_SWP_EXCLUSIVE in the last patch. > > > RFC because some of the swap PTE layouts are really tricky and I really > need some feedback related to deciphering these layouts and "using yet > unused PTE bits in swap PTEs". I tried cross-compiling all relevant setups > (phew, I might only miss some power/nohash variants), but only tested on > x86 so far. As I was messing with sparc64 either way and got debian to boot under QEMU, I verified that the sparc64 change also seems to work as expected (under sun4u). -- Thanks, David / dhildenb