From: Matthew Wilcox <willy@infradead.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] sched: Make const-safe
Date: Wed, 14 Dec 2022 18:03:04 +0000 [thread overview]
Message-ID: <Y5oP2Psz++gHholO@casper.infradead.org> (raw)
In-Reply-To: <Y5mTJVi2PBix+Gy6@hirez.programming.kicks-ass.net>
On Wed, Dec 14, 2022 at 10:11:01AM +0100, Peter Zijlstra wrote:
> On Mon, Dec 12, 2022 at 02:49:46PM +0000, Matthew Wilcox (Oracle) wrote:
> > With a modified container_of() that preserves constness, the compiler
> > finds some pointers which should have been marked as const. task_of()
> > also needs to become const-preserving for the !FAIR_GROUP_SCHED case so
> > that cfs_rq_of() can take a const argument. No change to generated code.
>
> More const more better I suppose.. Thanks!
>
> Happen to have a sha for the container_of() commit handy?
There isn't one yet. Obviously we can't make container_of()
const-preserving until we've fixed all the places which would warn.
The diff I have in my tree looks like this:
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 1d898f9158b4..9416e6cc8c88 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -20,7 +20,10 @@
static_assert(__same_type(*(ptr), ((type *)0)->member) || \
__same_type(*(ptr), void), \
"pointer type mismatch in container_of()"); \
- ((type *)(__mptr - offsetof(type, member))); })
+ __mptr -= offsetof(type, member); \
+ _Generic(ptr, \
+ const typeof(*(ptr)) *: (const type *)__mptr, \
+ default: ((type *)__mptr)); })
/**
* container_of_const - cast a member of a structure out to the containing
I have all of fs/ and net/ compiling cleanly now. There are a few
places which really need the const-removing properties, and I've made
those call a new macro called container_of_not_const(), but I don't
like that name.
next prev parent reply other threads:[~2022-12-14 18:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 14:49 [PATCH v2] sched: Make const-safe Matthew Wilcox (Oracle)
2022-12-14 9:11 ` Peter Zijlstra
2022-12-14 18:03 ` Matthew Wilcox [this message]
2022-12-16 10:46 ` Peter Zijlstra
2022-12-20 12:59 ` Peter Zijlstra
2022-12-27 12:13 ` [tip: sched/core] " tip-bot2 for Matthew Wilcox (Oracle)
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=Y5oP2Psz++gHholO@casper.infradead.org \
--to=willy@infradead.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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