Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp278965rwd; Mon, 12 Jun 2023 13:26:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55Euk3aKOiH67v94GJCCmhkiTBZ3t2SIBjdOk6j0VeJoETuLBIETCTgqlxwvKfEAkhSgNl X-Received: by 2002:a17:906:5d09:b0:978:af9d:c004 with SMTP id g9-20020a1709065d0900b00978af9dc004mr9404028ejt.4.1686601611823; Mon, 12 Jun 2023 13:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686601611; cv=none; d=google.com; s=arc-20160816; b=ICnaB+tZ8rGOY53zGyRIQ0bOWcLj0yWLSD0YB7lFMQ4mdjLQaewqRwLw4MZPfpJt8S btdyD3hQQB7Zfv51Ri73W9W2OedDp9kV7Mt2MW75u8+BYVmOZQD4X6kBayQmss3mWqBb bhoY1kT9bNFqS7QRyYAAdRgiK99IPN3PLzfWNQ7EuyIAL8/9OdRAjaQqdlqz3tR6X6WJ AvXJoB/ZhL6EG1JIjIn98uy1PzDscWtW2ACIW97Lhl0tboDZ3zEurOdDQzaRHwWdquqv J+sq4D0/6dkbaZqoHgdQ1loK2pTIlhw93J48+bkPiTiAxiNp8gypBlmCdmax3PhcjjJ7 mZUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=gqhNbAD+XSxAIMiaJQ4PDdnHAXjYLsAX06GFV8g8pq0=; b=KFhuxWPa11Ek19nrN1sgvUcpiqDXomj5qmJldwjT6T4kvig/gWBqjuPmg7csDxL6Kb Ix/zWYRO42BEUE7q81rcxoX4q4sBgVYBFHQ9+5V+ozwUdnpoOD9eG7cSp6cRTxUfNxu0 ArmEUKHDw4EapJb/8vUn44rq9JmawTLXUYL9O872gJsOxUFJYFH09lz6+zwGhpdMKfMm p3vKMsUxaDMSu9kWxiIAfTvpGmlOSFcLH3gMtetCuk0GlHdnGep+mxI15Nj+mBwJfGkM 35qu6of8r3DTDHKuua8QXVrah5+rLgtD52qap473opyeS4ynsupv04PPPylE2tUM269n Yq1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=AvnloMMf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e26-20020a1709067e1a00b00956fb99cb7dsi5534570ejr.1053.2023.06.12.13.26.26; Mon, 12 Jun 2023 13:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=AvnloMMf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233889AbjFLURG (ORCPT + 99 others); Mon, 12 Jun 2023 16:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230353AbjFLURD (ORCPT ); Mon, 12 Jun 2023 16:17:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13CF710CE for ; Mon, 12 Jun 2023 13:17:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9E3D1620F0 for ; Mon, 12 Jun 2023 20:16:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D4E2C433D2; Mon, 12 Jun 2023 20:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1686601019; bh=8YwIQ32/ViY707FKKgvZp3YPJFrRZ0aMF4dQkzNJeeo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=AvnloMMfQhyspWTCXbJI1zH2gVyj95+f4+W4RGfmmaNXGhaPd8jHRwHw0Qm3Hrjhr 0KW0YJ2+03iBgS4RJ/y9BmopWmjpF2nTfpBvGg6frcCf09oU0NfTSdWhQ83Tf+iWA5 TOaCwaJX+ZTwKgd5PeSmQeuGsXO7qxaGwalFpJKw= Date: Mon, 12 Jun 2023 13:16:56 -0700 From: Andrew Morton To: Ryan Roberts Cc: SeongJae Park , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Mike Rapoport , Yu Zhao , Jason Gunthorpe , David Airlie , Daniel Vetter , Dimitri Sivanich , Alex Williamson , Oleksandr Tyshchenko , Alexander Viro , Christian Brauner , Mike Kravetz , Muchun Song , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , =?ISO-8859-1?Q?J=E9r=F4me?= Glisse , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Naoya Horiguchi , Miaohe Lin , Pasha Tatashin , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , linux-kernel@vger.kernel.org, linux-mm@kvack.org, damon@lists.linux.dev Subject: Re: [PATCH v3 0/3] Encapsulate PTE contents from non-arch code Message-Id: <20230612131656.2ba4f95865f27e6b3b984936@linux-foundation.org> In-Reply-To: <20230612151545.3317766-1-ryan.roberts@arm.com> References: <20230612151545.3317766-1-ryan.roberts@arm.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 12 Jun 2023 16:15:42 +0100 Ryan Roberts wrote: > Hi All, > > (Including wider audience this time since changes touch a fair few subsystems) > > This is the second half of v3 of a series to improve the encapsulation of pte > entries by disallowing non-arch code from directly dereferencing pte_t pointers. That's basically all we have here for [0/N] cover letter content. I stole some words from the [3/3] changelog, so we now have: : A series to improve the encapsulation of pte entries by disallowing : non-arch code from directly dereferencing pte_t pointers. : : This means that by default, the accesses change from a C dereference to a : READ_ONCE(). This is technically the correct thing to do since where : pgtables are modified by HW (for access/dirty) they are volatile and : therefore we should always ensure READ_ONCE() semantics. : : But more importantly, by always using the helper, it can be overridden by : the architecture to fully encapsulate the contents of the pte. Arch code : is deliberately not converted, as the arch code knows best. It is : intended that arch code (arm64) will override the default with its own : implementation that can (e.g.) hide certain bits from the core code, or : determine young/dirty status by mixing in state from another source. > Based on earlier feedback, I split the series in 2; the first part, fixes for > existing bugs, was already posted at [3] and merged into mm-stable. This second > part contains the conversion from direct dereferences to instead use > ptep_get()/ptep_get_lockless(). > > See the v1 cover letter at [1] for rationale for this work. > > Based on feedback at v2, I've removed the new ptep_deref() helper I originally > added, and am now using the existing ptep_get() and ptep_get_lockless() helpers. > Testing on Ampere Altra (arm64) showed no difference in performance when using > ptep_deref() (*pte) vs ptep_get() (READ_ONCE(*pte)). > > Patches are based on mm-unstable (49e038b1919e) and a branch is available at [4] > (Let me know if this is the wrong branch to target - I'm still not familiar with > the details of the mm- dev process!). Note that Hugh Dickins's "mm: allow > pte_offset_map[_lock]() to fail" (now in mm-unstable) patch set caused a number > of conflicts which I've resolved. But due to that, you won't be able to apply > these patches on top of Linus's tree. I have an alternate branch on top of > v6.4-rc6 at [5]. Yep, that's all great, thanks. Is there some clever trick we can do to prevent new open-coded derefs of pte_t* from being introduced? I suppose we could convert pte_t to a single-member struct to force a compile error. That struct will get passed by value to ptep_get() so that's OK. But this isn't viable unless/until all architectures are converted :( Or we rely upon Ryan to grep the tree occasionally ;)