From: Ryan Roberts <ryan.roberts@arm.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v1] mm: More ptep_get() conversion
Date: Tue, 14 Nov 2023 16:46:42 +0000 [thread overview]
Message-ID: <1628606f-a396-448d-91ec-6c4ce85b5358@arm.com> (raw)
In-Reply-To: <ZVOguexQ2rGhnwN7@casper.infradead.org>
On 14/11/2023 16:30, Matthew Wilcox wrote:
> On Tue, Nov 14, 2023 at 03:49:45PM +0000, Ryan Roberts wrote:
>> Commit c33c794828f2 ("mm: ptep_get() conversion") converted all
>> (non-arch) call sites to use ptep_get() instead of doing a direct
>> dereference of the pte. Full rationale can be found in that commit's
>> log.
>>
>> Since then, three new call sites have snuck in, which directly
>> dereference the pte, so let's fix those up.
>>
>> Unfortunately there is no reliable automated mechanism to catch these;
>> I'm relying on a combination of Coccinelle (which throws up a lot of
>> false positives) and some compiler magic to force a compiler error on
>> dereference (While this approach finds dereferences, it also yields a
>> non-booting kernel so can't be committed).
>
> Well ... let's see what we can come up with.
>
> struct raw_pte {
> pte_t pte;
> };
pte_t is already a wrapper around the real value, at least on arm64:
typedef struct { pteval_t pte; } pte_t;
So doesn't adding extra wrapper just suggest that next year we will end up
adding a third, then a fourth...?
Fundamentally people can still just do pte->pte to dereference.
The approach I took with the compiler magic I describe above was to pass around:
typedef void* pte_handle_t;
which is just a pointer to pte_t, but you can't deref without an explcit cast.
So then I insert the explicit casts in the 5 or 6 places in the arm64 arch code
that they are required and it mostly just works. (I have the core patch which is
pretty small, then do find/replace on "pte_t *" -> "pte_handle_t" and it just
works).
But its a LOT of churn in the non-arch code, and leaves the other arches broken,
many of which are dereferencing all over the place - it would be a huge effort
to fix them all up.
>
> static inline pte_t ptep_get(struct raw_pte *rpte)
> {
> return rpte.pte;
> }
>
> Probably quite a lot of churn to put that into place, but better than
> a never-ending treadmill of fixing the places that people overlooked?
Yes and no... agree it would be nice to automatically guard against it, but I
didn't want to spend the next 6 months of my life fixing up all the other arches...
prev parent reply other threads:[~2023-11-14 16:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 15:49 Ryan Roberts
2023-11-14 16:30 ` Matthew Wilcox
2023-11-14 16:46 ` Ryan Roberts [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1628606f-a396-448d-91ec-6c4ce85b5358@arm.com \
--to=ryan.roberts@arm.com \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox