From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com,
akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
dvhart@linux.intel.com, fweisbec@gmail.com, oleg@redhat.com,
bobby.prani@gmail.com, Boqun Feng <boqun.feng@gmail.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH tip/core/rcu 07/13] sparse: Add __private to privatize members of structs
Date: Tue, 23 Feb 2016 21:12:44 -0800 [thread overview]
Message-ID: <1456290770-18659-7-git-send-email-paulmck@linux.vnet.ibm.com> (raw)
In-Reply-To: <20160224051221.GA17099@linux.vnet.ibm.com>
From: Boqun Feng <boqun.feng@gmail.com>
In C programming language, we don't have a easy way to privatize a
member of a structure. However in kernel, sometimes there is a need to
privatize a member in case of potential bugs or misuses.
Fortunately, the noderef attribute of sparse is a way to privatize a
member, as by defining a member as noderef, the address-of operator on
the member will produce a noderef pointer to that member, and if anyone
wants to dereference that kind of pointers to read or modify the member,
sparse will yell.
Based on this, __private modifier and related operation ACCESS_PRIVATE()
are introduced, which could help detect undesigned public uses of
private members of structs. Here is an example of sparse's output if it
detect an undersigned public use:
| kernel/rcu/tree.c:4453:25: warning: incorrect type in argument 1 (different modifiers)
| kernel/rcu/tree.c:4453:25: expected struct raw_spinlock [usertype] *lock
| kernel/rcu/tree.c:4453:25: got struct raw_spinlock [noderef] *<noident>
Also, this patch improves compiler.h a little bit by adding comments for
"#else" and "#endif".
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
include/linux/compiler.h | 12 ++++++++----
scripts/checkpatch.pl | 3 ++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 00b042c49ccd..c845356952bb 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -20,12 +20,14 @@
# define __pmem __attribute__((noderef, address_space(5)))
#ifdef CONFIG_SPARSE_RCU_POINTER
# define __rcu __attribute__((noderef, address_space(4)))
-#else
+#else /* CONFIG_SPARSE_RCU_POINTER */
# define __rcu
-#endif
+#endif /* CONFIG_SPARSE_RCU_POINTER */
+# define __private __attribute__((noderef))
extern void __chk_user_ptr(const volatile void __user *);
extern void __chk_io_ptr(const volatile void __iomem *);
-#else
+# define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
+#else /* __CHECKER__ */
# define __user
# define __kernel
# define __safe
@@ -44,7 +46,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
# define __percpu
# define __rcu
# define __pmem
-#endif
+# define __private
+# define ACCESS_PRIVATE(p, member) ((p)->member)
+#endif /* __CHECKER__ */
/* Indirect macros required for expanded argument pasting, eg. __LINE__. */
#define ___PASTE(a,b) a##b
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0147c91fa549..874132b26d23 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -269,7 +269,8 @@ our $Sparse = qr{
__init_refok|
__kprobes|
__ref|
- __rcu
+ __rcu|
+ __private
}x;
our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
--
2.5.2
next prev parent reply other threads:[~2016-02-24 5:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 5:12 [PATCH tip/core/rcu 0/13] Miscellaneous fixes for 4.6 Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 01/13] rcu: Assign false instead of 0 for ->core_needs_qs Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 02/13] rcu: Update rcu_report_qs_rsp() comment Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 03/13] rcu: Stop treating in-kernel CPU-bound workloads as errors Paul E. McKenney
2016-02-25 9:43 ` Peter Zijlstra
2016-02-25 17:20 ` Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 04/13] rcu: Set rdp->gpwrap when CPU is idle Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 05/13] rcutorture: Correct no-expedite console messages Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 06/13] rcu: Remove useless rcu_data_p when !PREEMPT_RCU Paul E. McKenney
2016-02-24 5:12 ` Paul E. McKenney [this message]
2016-02-24 5:12 ` [PATCH tip/core/rcu 08/13] RCU: Privatize rcu_node::lock Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 09/13] irq: Privatize irq_common_data::state_use_accessors Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 10/13] rcu: Make rcu/tiny_plugin.h explicitly non-modular Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 11/13] rcu: Document unique-name limitation for DEFINE_STATIC_SRCU() Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 12/13] rcu: Catch up rcu_report_qs_rdp() comment with reality Paul E. McKenney
2016-02-24 5:12 ` [PATCH tip/core/rcu 13/13] rcu: Remove rcu_user_hooks_switch Paul E. McKenney
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=1456290770-18659-7-git-send-email-paulmck@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=bobby.prani@gmail.com \
--cc=boqun.feng@gmail.com \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=dvhart@linux.intel.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®