linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Jason Gunthorpe <jgg@ziepe.ca>,
	"Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Matthew Wilcox <willy@infradead.org>, <linux-mm@kvack.org>,
	<kirill.shutemov@linux.intel.com>, <pasha.tatashin@soleen.com>
Subject: Re: [PATCH 1/5] mm: Constify a lot of struct page arguments
Date: Thu, 9 Apr 2020 13:47:03 -0700	[thread overview]
Message-ID: <f7e082ff-dd2e-8f69-fd71-8e5847212141@nvidia.com> (raw)
In-Reply-To: <20200409171210.GJ11886@ziepe.ca>

On 4/9/20 10:12 AM, Jason Gunthorpe wrote:
> On Thu, Apr 09, 2020 at 05:47:44PM +0300, Kirill A. Shutemov wrote:
>> On Thu, Apr 09, 2020 at 07:32:38AM -0700, Matthew Wilcox wrote:
>>> On Thu, Apr 09, 2020 at 05:28:51PM +0300, Kirill A. Shutemov wrote:
>>>>> We have a few places that do things like
>>>>>
>>>>> mm/filemap.c:           if (unlikely(compound_head(page)->mapping != mapping)) {
>>>>
>>>> Good point.
>>>>
>>>> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>>>
>>> Darn, I hoped you'd have a better idea.  I feel quite ashamed of this patch.
>>
>> I had two ideas. Both awful.
>>
>>   - Rename compound_head() to __compound_head() or something and make it
>>     return void *. Then wrap it into a macro that would cast return type to
>>     type of the argument. It would allow to regain *some* type safety.
>>
>>   - Provide two implementations and use C11 _Generic() :P
>>     (bump GCC version requirements first)
> 
> I saw people using static_assert stuff in the kernel, maybe C11 is
> feasible now? It is 9 years old..


ohhh, if this patch is a reliable indicator of what const correctness looks
like in the kernel, then we're going to end up with a lot movement in that
direction, too. With that in mind, let's provide some counter-force, by:

1) Poking around at the C11 idea, just in case It Is Time. Because clearly
the C language dialect that we're using now is not *quite* up to doing const
correctness, so moving the language ahead is likely to give us the cleanest
solution. Better than writing our own language in macros, which yes, I
realize is a way to compensate. But, uggghhh. :)

2) Perhaps providing two routines with different names might be the answer
in this case? This avoids macros, still provides a const cast (which is
breaks the chain of const correctness, but on the other hand, we still get
most of the const goodness--the rest comes when the language supports it):

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 222f6f7b2bb3..71e2d07ddcf4 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -186,6 +186,11 @@ static inline struct page *compound_head(struct page *page)
         return page;
  }
  
+static inline const struct page *compound_head_const(struct page *page)
+{
+       return (const struct page*)compound_head(page);
+}
+
  static __always_inline int PageTail(struct page *page)
  {
         return READ_ONCE(page->compound_head) & 1;
diff --git a/mm/debug.c b/mm/debug.c
index 2189357f0987..9a1f37a80ed7 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -44,7 +44,7 @@ const struct trace_print_flags vmaflag_names[] = {
  
  void __dump_page(struct page *page, const char *reason)
  {
-       struct page *head = compound_head(page);
+       const struct page *head = compound_head_const(page);
         struct address_space *mapping;
         bool page_poisoned = PagePoisoned(page);
         bool compound = PageCompound(page);

...etc

thanks,
-- 
John Hubbard
NVIDIA


  reply	other threads:[~2020-04-09 20:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08 15:01 [PATCH 0/5] Improve page poisoning implementation Matthew Wilcox
2020-04-08 15:01 ` [PATCH 1/5] mm: Constify a lot of struct page arguments Matthew Wilcox
2020-04-08 15:14   ` Pavel Tatashin
2020-04-09 14:09   ` Kirill A. Shutemov
2020-04-09 14:15     ` Matthew Wilcox
2020-04-09 14:28       ` Kirill A. Shutemov
2020-04-09 14:32         ` Matthew Wilcox
2020-04-09 14:47           ` Kirill A. Shutemov
2020-04-09 15:00             ` Kirill A. Shutemov
2020-04-09 17:12             ` Jason Gunthorpe
2020-04-09 20:47               ` John Hubbard [this message]
2020-04-08 15:01 ` [PATCH 2/5] mm: Rename PF_POISONED_PAGE to page_poison_check Matthew Wilcox
2020-04-08 15:21   ` Pavel Tatashin
2020-04-09 14:14   ` Kirill A. Shutemov
2020-04-08 15:01 ` [PATCH 3/5] mm: Remove casting away of constness Matthew Wilcox
2020-04-08 15:23   ` Pavel Tatashin
2020-04-09 14:19   ` Kirill A. Shutemov
2020-04-08 15:01 ` [PATCH 4/5] mm: Check for page poison in both page_to_nid implementations Matthew Wilcox
2020-04-08 15:24   ` Pavel Tatashin
2020-04-09 14:21   ` Kirill A. Shutemov
2020-04-08 15:01 ` [PATCH 5/5] mm: Check page poison before finding a head page Matthew Wilcox
2020-04-08 15:32   ` Pavel Tatashin
2020-04-09 14:25   ` Kirill A. Shutemov
2020-04-08 15:11 ` [PATCH 0/5] Improve page poisoning implementation Pavel Tatashin
2020-04-09 20:55   ` John Hubbard

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=f7e082ff-dd2e-8f69-fd71-8e5847212141@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --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