intel-iommu: Add for_each_iommu() and for_each_active_iommu() macros
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · On Mon, 6 Apr 2009 21:59:01 GMT Linux Kernel Mailing List…
Gitweb: http://git.kernel.org/linus/8f912ba4d7cdaf7d31cf39fe5a9b7732308a256d Commit: 8f912ba4d7cdaf7d31cf39fe5a9b7732308a256d Parent: 20bec8ab1458c24bed0d5492ee15d87807fc415a Author: David Woodhouse <[email protected]> AuthorDate: Fri Apr 3 15:19:32 2009 +0100 Committer: David Woodhouse <[email protected]> CommitDate: Fri Apr 3 21:45:46 2009 +0100
Three days old? Never been in linux-next afaict.
Please don't do that.
Quoted 16 lines
intel-iommu: Add
for_each_iommu()andfor_each_active_iommu()macrosSigned-off-by David Woodhouse <[email protected]>Acked-by Ingo Molnar <[email protected]>--- include/linux/dmar.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)include/linux/dmar.h +0
-0@@ -44,6 +44,14 @@ extern struct list_head dmar_drhd_units;#define for_each_drhd_unit (drhd) \ list_for_each_entry(drhd, &dmar_drhd_units, list)
include/linux/dmar.h extern struct list_head dmar_drhd_units; · line 56
Quoted 10 lines
include/linux/dmar.h +8
-0+#define for_each_active_iommu (i, drhd) \ + list_for_each_entry(drhd, &dmar_drhd_units, list) \ + if (i=drhd->iommu, drhd->ignored) {} else + +#define for_each_iommu (i, drhd) \ + list_for_each_entry(drhd, &dmar_drhd_units, list) \ + if (i=drhd->iommu, 0) {} else +extern int dmar_table_init (void );extern int dmar_dev_scope_init (void );
From: Andrew Morton <[email protected]>
drivers/pci/intel-iommu.c:2637:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c: In function 'init_iommu_hw':drivers/pci/intel-iommu.c:2637: error: expected '(' before '{' token drivers/pci/intel-iommu.c:2638: error: '______r' undeclared (first use in this function) drivers/pci/intel-iommu.c:2638: error: (Each undeclared identifier is reported only once drivers/pci/intel-iommu.c:2638: error: for each function it appears in.) drivers/pci/intel-iommu.c:2641:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c:2641: error: expected '(' before '{' token drivers/pci/intel-iommu.c:2662:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c: In function 'iommu_flush_all':drivers/pci/intel-iommu.c:2662: error: expected '(' before '{' token drivers/pci/intel-iommu.c:2676:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c: In function 'iommu_suspend':drivers/pci/intel-iommu.c:2676: error: expected '(' before '{' token drivers/pci/intel-iommu.c:2678: error: too few arguments to function 'kzalloc' drivers/pci/intel-iommu.c:2685:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c:2685: error: expected '(' before '{' token drivers/pci/intel-iommu.c:2688: error: '__dummy' undeclared (first use in this function) drivers/pci/intel-iommu.c:2704:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c:2704: error: expected '(' before '{' token drivers/pci/intel-iommu.c:2721:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c:2737:35: error: macro "if" passed 2 arguments, but takes just 1 drivers/pci/intel-iommu.c: At top level:drivers/pci/intel-iommu.c:2745: error: 'iommu_resume' undeclared here (not in a function)
---
include/linux/dmar.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/dmar.h renamed from include/linux/dmar.h~include-linux-dmarh-fix-build-with-config_profile_all_branches +2 -2
@@ -47,11 +47,11 @@ extern struct list_head dmar_drhd_units;#define for_each_active_iommu (i, drhd) \ list_for_each_entry(drhd, &dmar_drhd_units, list) \ - if (i=drhd->iommu, drhd->ignored) {} else + if ((i=drhd->iommu, drhd->ignored)) {} else#define for_each_iommu (i, drhd) \ list_for_each_entry(drhd, &dmar_drhd_units, list) \ - if (i=drhd->iommu, 0) {} else + if ((i=drhd->iommu, 0)) {} elseextern int dmar_table_init (void );extern int dmar_dev_scope_init (void );
_
Quoted 4 lines · Andrew Morton
Three days old? Never been in linux-next afaict.
Please don't do that.
Sorry about that. There was some confusion about whether it was going via Ingo's or my tree, and it ended up in neither. It depended on certain things in Ingo's tree, so I couldn't easily add it to my tree any earlier.
I'm unconvinced by the fix -- can we find a way to fix the if() macro so that normal (if fugly) C code like this doesn't doesn't need this kind of workaround?
(Yes, it's fugly. But the original was worse IMHO:
https://lists.linux-foundation.org/pipermail/iommu/attachments/20090327/31f84f7d/attachment.txt )
Signature · 1 line
dwmw2
Quoted 4 lines · David Woodhouse
I'm unconvinced by the fix -- can we find a way to fix the
if()macro so that normal (if fugly) C code like this doesn't doesn't need this kind of workaround?
Something like this perhaps? I'd reformat it but dinner calls...
include/linux/compiler.h +2 -2
@@ -114,7 +114,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);* "Define 'is'", Bill Clinton * "Define 'if'", Steven Rostedt */ -#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) : \ +#define if(cond, ...) if (__builtin_constant_p((cond, ## __VA_ARGS__)) ? !!(cond, ## __VA_ARGS__) : \ ({ \ int ______r; \ static struct ftrace_branch_data \
@@ -125,7 +125,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); .file = __FILE__, \ .line = __LINE__, \ }; \ - ______r = !!(cond); \ + ______r = !!(cond, ## __VA_ARGS__); \ ______f.miss_hit[______r]++; \ ______r; \ }))
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 22 lines · On Mon, 06 Apr 2009 18:19:06 -0700 David Woodhouse <[email protected]> wrote:
Quoted 4 lines · David Woodhouse
I'm unconvinced by the fix -- can we find a way to fix the
if()macro so that normal (if fugly) C code like this doesn't doesn't need this kind of workaround?Something like this perhaps? I'd reformat it but dinner calls...
include/linux/compiler.h +1
-1@@ -114,7 +114,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);* "Define 'is'", Bill Clinton * "Define 'if'", Steven Rostedt */ -#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) : \ +#define if(cond, ...) if (__builtin_constant_p((cond, ## __VA_ARGS__)) ? !!(cond, ## __VA_ARGS__) : \ ({ \ int ______r; \ static struct ftrace_branch_data \
include/linux/compiler.h void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); · line 131
Quoted 8 lines
include/linux/compiler.h +1
-1@@ -125,7 +125,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); .file = __FILE__, \ .line = __LINE__, \ }; \ - ______r = !!(cond); \ + ______r = !!(cond, ## __VA_ARGS__); \ ______f.miss_hit[______r]++; \ ______r; \ }))
That would be better. If it works, please send something Linuswards?
Steven Rostedt
Acked-byQuoted 7 lines · David Woodhouse
Quoted 4 lines · David Woodhouse
I'm unconvinced by the fix -- can we find a way to fix the
if()macro so that normal (if fugly) C code like this doesn't doesn't need this kind of workaround?Something like this perhaps? I'd reformat it but dinner calls...
Use emacs Ctrl-c / ;-)
Quoted 16 lines
include/linux/compiler.h +1
-1@@ -114,7 +114,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);* "Define 'is'", Bill Clinton * "Define 'if'", Steven Rostedt */ -#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) : \ +#define if(cond, ...) if (__builtin_constant_p((cond, ## __VA_ARGS__)) ? !!(cond, ## __VA_ARGS__) : \ ({ \ int ______r; \ static struct ftrace_branch_data \
include/linux/compiler.h void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); · line 131
Quoted 8 lines
include/linux/compiler.h +1
-1@@ -125,7 +125,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); .file = __FILE__, \ .line = __LINE__, \ }; \ - ______r = !!(cond); \ + ______r = !!(cond, ## __VA_ARGS__); \ ______f.miss_hit[______r]++; \ ______r; \ }))
If this works then (after reformating)
-- Steve
Quoted 3 lines · Steven Rostedt
If this works then (after reformating)
Acked-by Steven Rostedt <[email protected]>
Yeah, it seems to work. This worried me briefly for a while but then I realised it was already there before my changes...
[dwmw2@macbook linux-2.6]$ grep CONFIG_PROFILE_ALL_BRANCHES .config # CONFIG_PROFILE_ALL_BRANCHES is not set
[dwmw2@macbook linux-2.6]$ make drivers/net/e100.o scripts/kconfig/conf -s arch/x86/Kconfig
CHK include/linux/version.h
CHK include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-x86
CC kernel/bounds.s GEN include/linux/bounds.h CC arch/x86/kernel/asm-offsets.s GEN include/asm/asm-offsets.h CALL scripts/checksyscalls.sh CC drivers/net/e100.o
[dwmw2@macbook linux-2.6]$ sed -i 's/.*\(CONFIG_PROFILE_ALL_BRANCHES\).*/\1=y/' .config [dwmw2@macbook linux-2.6]$ make drivers/net/e100.oscripts/kconfig/conf -s arch/x86/Kconfig
CHK include/linux/version.h
CHK include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-x86
CC kernel/bounds.s GEN include/linux/bounds.h CC arch/x86/kernel/asm-offsets.s GEN include/asm/asm-offsets.h CALL scripts/checksyscalls.sh CC drivers/net/e100.o
drivers/net/e100.c: In function ‘e100_hw_init’:drivers/net/e100.c:1344: warning: ‘err’ may be used uninitialized in this function
This happens in a lot of places, not just e100.
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 32 lines · David Woodhouse
Quoted 3 lines · Steven Rostedt
If this works then (after reformating)
Acked-by Steven Rostedt <[email protected]>Yeah, it seems to work. This worried me briefly for a while but then I realised it was already there before my changes...
[dwmw2@macbook linux-2.6]$ grep
CONFIG_PROFILE_ALL_BRANCHES.config #CONFIG_PROFILE_ALL_BRANCHESis not set
[dwmw2@macbook linux-2.6]$ makedrivers/net/e100.oscripts/kconfig/conf-sarch/x86/Kconfig
CHKinclude/linux/version.h
CHKinclude/linux/utsrelease.h
SYMLINKinclude/asm->include/asm-x86CC kernel/bounds.s GEN include/linux/bounds.h CC arch/x86/kernel/asm-offsets.s GEN include/asm/asm-offsets.h CALL scripts/checksyscalls.sh CC drivers/net/e100.o[dwmw2@macbook linux-2.6]$ sed -i 's/.*\(CONFIG_PROFILE_ALL_BRANCHES\).*/\1=y/' .config [dwmw2@macbook linux-2.6]$ make
drivers/net/e100.oscripts/kconfig/conf-sarch/x86/Kconfig
CHKinclude/linux/version.h
CHKinclude/linux/utsrelease.h
SYMLINKinclude/asm->include/asm-x86CC kernel/bounds.s GEN include/linux/bounds.h CC arch/x86/kernel/asm-offsets.s GEN include/asm/asm-offsets.h CALL scripts/checksyscalls.sh CC drivers/net/e100.o
Quoted 5 lines
drivers/net/e100.c: In function ?e100_hw_init?:drivers/net/e100.c:1344: warning: ?err? may be used uninitialized in this functionThis happens in a lot of places, not just e100.
Yeah, that's because the if macro exceeds gcc's threshold of calculating initialized variables.
-- Steve
David Woodhouse
Acked-by Steven RostedtThe PROFILE_ALL_BRANCHES option causes us to define if() as a macro... taking precisely one argument. This causes a build failure if the condition is actually a comma expression -- 'if (a(), b)'.
This patch turns the if() macro into a varargs macro which copes with a comma expression as its 'arguments'.
---
Some might argue that I shouldn't have been using if(a,b) in the first place, but in my defence it _should_ have worked, and it was less ugly than the original. I did this:
#define for_each_active_iommu(i, drhd) \
list_for_each_entry(drhd, &dmar_drhd_units, list) \
if (i=drhd->iommu, drhd->ignored) {} else... instead of what I was originally given, which was (with the first three macros added to list.h as a generic facility)...
#define list_first_entry_selected(pos, head, member, selector) \
pos = list_entry((head)->next, typeof(*pos), member), \
pos = ({while (!(selector) && (&pos->member != (head))) \
pos = list_entry(pos->member.next, typeof(*pos), member); \
pos; })
#define list_next_entry_selected(pos, head, member, selector) \
pos = list_entry(pos->member.next, typeof(*pos), member), \
pos = ({while (!(selector) && (&pos->member != (head))) \
pos = list_entry(pos->member.next, typeof(*pos), member); \
pos; })
#define list_for_each_entry_selected_do(pos, head, member, selector, to_do) \
for (list_first_entry_selected(pos, head, member, selector), \
({if (&pos->member != (head)) to_do}); \
prefetch(pos->member.next), &pos->member != (head); \
list_next_entry_selected(pos, head, member, selector), \
({if (&pos->member != (head)) to_do}))#define for_each_active_iommu(i, drhd) \
list_for_each_entry_selected_do(drhd, &dmar_drhd_units, list, \
!drhd->ignored, {i = drhd->iommu; })include/linux/compiler.h +4 -3
@@ -114,7 +114,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);* "Define 'is'", Bill Clinton * "Define 'if'", Steven Rostedt */ -#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) : \ +#define if(cond, ...) if (__builtin_constant_p((cond, ## __VA_ARGS__)) \ + ? !!(cond, ## __VA_ARGS__) : \ ({ \ int ______r; \ static struct ftrace_branch_data \
@@ -125,8 +126,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); .file = __FILE__, \ .line = __LINE__, \ }; \ - ______r = !!(cond); \ - ______f.miss_hit[______r]++; \ + ______r = !!(cond, ## __VA_ARGS__); \ + ______f.miss_hit[______r]++; \ ______r; \ }))#endif /* CONFIG_PROFILE_ALL_BRANCHES */
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 10 lines · David Woodhouse
Quoted 4 lines · Andrew Morton
Three days old? Never been in linux-next afaict.
Please don't do that.
Sorry about that. There was some confusion about whether it was going via Ingo's or my tree, and it ended up in neither. It depended on certain things in Ingo's tree, so I couldn't easily add it to my tree any earlier.
Well, they could have ended up in the x86 tree or in the IOMMU tree, but the patches were all very late and went through various review rounds with me so they had no chance to end up there in a finished state before the merge window.
I didnt mind you pushing them to Linus separately and gave an Acked-by for the bits and for that merge route, but all the usual protocols still have to be followed if you do that: review, testing, proper exposure.
Ingo
Quoted 7 lines · Ingo Molnar
Quoted 5 lines · David Woodhouse
Quoted 4 lines · Andrew Morton
Three days old? Never been in linux-next afaict.
Please don't do that.
It turns out they had actually been in linux-next, just not for long.
Quoted 10 lines
Quoted 4 lines
Sorry about that. There was some confusion about whether it was going via Ingo's or my tree, and it ended up in neither. It depended on certain things in Ingo's tree, so I couldn't easily add it to my tree any earlier.
Well, they could have ended up in the x86 tree or in the IOMMU tree, but the patches were all very late and went through various review rounds with me so they had no chance to end up there in a finished state before the merge window.
Quoted 4 lines
I didnt mind you pushing them to Linus separately and gave an Acked-by for the bits and for that merge route, but all the usual protocols still have to be followed if you do that: review, testing, proper exposure.
To avoid extra merges, my plan was to let Linus pull the original iommu-2.6.git tree, then fast-forward to HEAD and apply the suspend patches which depended on your new stuff. Then leave them to soak for as long as possible before asking Linus to pull again.
If Linus had pulled the iommu-2.6.git tree on Tuesday when I first asked, the suspend set would have been in linux-next for longer. Perhaps if I'd had the wit to remember to include a diffstat on Tuesday's pull request... :)
Signature · 1 line
dwmw2