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 10997C7EE2E for ; Mon, 12 Jun 2023 20:17:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 208F56B0074; Mon, 12 Jun 2023 16:17:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 193548E0002; Mon, 12 Jun 2023 16:17:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00BE46B0078; Mon, 12 Jun 2023 16:17:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E1F8A6B0074 for ; Mon, 12 Jun 2023 16:17:02 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9F823C031A for ; Mon, 12 Jun 2023 20:17:02 +0000 (UTC) X-FDA: 80895204684.02.E54EC09 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id B5FEA14001A for ; Mon, 12 Jun 2023 20:17:00 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=AvnloMMf; dmarc=none; spf=pass (imf09.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686601020; 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=gqhNbAD+XSxAIMiaJQ4PDdnHAXjYLsAX06GFV8g8pq0=; b=BleISBS265WTBaN5MSgjbX/Ypq3y4j+EYXk420BqCR1J+OISCbHoOOEvWx4edra44IuiGP 1PKFiq5+Hrg885tAktah2OBt1ldaH0SGkuMWEdXqLlG55VERfBAavomFBrgavNFw/GLEo0 0DvBSmHdnwunrOQ0SwQEXWCNrbHENi8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=AvnloMMf; dmarc=none; spf=pass (imf09.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686601020; a=rsa-sha256; cv=none; b=WRRAyei+bg+DIfwNOKfPyMljfG5nHJLzO4akJwBFRrVYHubCrVteZRzn8lmecGhWQyLWtJ bK339MbibmHpt8ysAn5KfQDLHaaLlGvdyeYL3rNmvBaPOWctF01vQk0ditch0cjU4bIPGM FGyij1iNTmxnP5mHdv2xA4Ysl/Evlnk= 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 A24E662DDB; 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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B5FEA14001A X-Stat-Signature: utmk9aajr7kkbpdfhx3k8bj5byy9uwnj X-HE-Tag: 1686601020-748318 X-HE-Meta: U2FsdGVkX1+hKM45H1rGrjwHwHtGrf0qHQCi7GJ2JrQ3av9LLoCj9dIUbINcbaPPEAr/YpSOy0GVz9TZ3QompcZ8bb358+AsTsLAEbBoDUY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Vro4HQ+IgFSardoZ2w/TTPQIAN0XipwxQfd+Ofn9Oq+uidYkodsW92BbtZZul+6gtKbM3xRyo4XKrDX7MyG1mrgsxXMocQpgpMMNEYIJOg4eUNTxvfdrBN1g3QxNVqiK9yspmapBjo87RUIpWXOLrMadKS05Oop318fHYgcHHKzXrsRH4zsdPig+BQcB7tG1LxJrhgZs8Zn+HP1bUT/GjPMDaMORIGNimrTd6oV3BJ+isRTg5l3Gd0Z7uA/neojQkDp192kr1g9EviTl57xCT2obdpmOhjAeQvJ/LE9cSCcx+/2URxg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 ;)