Casting away noderef and address spaces?
Hi all,
I need to use typeof(), but I want to change address spaces. I can't see
how to do that: AFAICT it's not possible. This doesn't work:
#define __percpu __attribute__((noderef, address_space(3)))
/* Turn v back into a normal var. */
#define convert(v) \ (*(__attribute__((address_space(0), force)) typeof(&v))(v))
int main(int argc, char *argv)
{
unsigned int __percpu x;
convert(x) = 0;
return 0;
}Thanks,
Rusty.
Christopher Li
maintainerQuoted 3 lines · Rusty Russell
#define convert(v) \
(*(__attribute__((address_space(0), force)) typeof(&v))(v))Am I reading it right? You are trying to dereferenc a type instead of a pointer?
I don't think you can do that with sparse.
Are you trying to declare the per_cpu as the third address space and force every usage of the per_cpu variable going through the conversion?
Chris
Quoted 7 lines · Christopher Li
Quoted 3 lines · Rusty Russell
#define convert(v) \ (*(__attribute__((address_space(0), force)) typeof(&v))(v))Am I reading it right? You are trying to dereferenc a type instead of a pointer?
I don't think you can do that with sparse.
The right solution is
(*(typeof(v) __attribute__((address_space(0), force)) *)(&v))
Cast there will take a pointer to type of V and force-cast it to pointer to unqualified type of V. *(cast)&v will do the obvious thing. Will trim both the AS and noderef.
Christopher Li
maintainerQuoted 6 lines · Al Viro
The right solution is
(*(typeof(v) __attribute__((address_space(0), force)) *)(&v))Cast there will take a pointer to type of V and force-cast it to pointer to unqualified type of V. *(cast)&v will do the obvious thing. Will trim both the AS and noderef.
Thanks, that is much better. However sparse don't know how to handle it yet.
/tmp/typeof.c:11:64: warning: incorrect type in assignment (invalid types)/tmp/typeof.c:11:64: expected unknown type 11 <noident>/tmp/typeof.c:11:64: got int
classify_type does not know how to handle SYM_TYPEOF yet. Let me see if I can make it to work.
Chris
Quoted 8 lines · Christopher Li
Quoted 6 lines · Al Viro
The right solution is
(*(typeof(v) __attribute__((address_space(0), force)) *)(&v))Cast there will take a pointer to type of V and force-cast it to pointer to unqualified type of V. *(cast)&v will do the obvious thing. Will trim both the AS and noderef.
Quoted 8 lines
Thanks, that is much better. However sparse don't know how to handle it yet.
/tmp/typeof.c:11:64: warning: incorrect type in assignment (invalid types)/tmp/typeof.c:11:64: expected unknown type 11 <noident>/tmp/typeof.c:11:64: got int
classify_typedoes not know how to handleSYM_TYPEOFyet. Let me see if I can make it to work.
Works here (built from 8f208e215a531d2b32aec0428fd5eaa24ae3100b)...
But yes, SYM_TYPEOF is a brittle mess, so whether that works or not is, er, version-dependent ;-/
I really ought to resurrect lazy-type-expressions branch...
Christopher Li
maintainerQuoted 4 lines · Al Viro
Works here (built from
8f208e215a531d2b32aec0428fd5eaa24ae3100b)...But yes,
SYM_TYPEOFis a brittle mess, so whether that works or not is, er, version-dependent ;-/
Very strange. That is exactly what I have in my clean sparse git tree. I just clone it a few minutes ago. It give me errors on your example.
On my clean tree, I need the attached patch to get it to work.
Quoted 3 lines
I really ought to resurrect lazy-type-expressions branch...
Are you sure you don't have some of those bits left over on your git tree? If you submit your lazy-type-expressions patch, I can help to review it.
BTW, I am normally lazy enough that I am happy about just submitting patches. On the other hand, I am tried of these sparse patches floating around the mailing list. I can start a branch to merge the proper patches. Maybe some thing like a development branch for sparse.
Is that some thing other people want?
Chris
Quoted 6 lines · Christopher Li
BTW, I am normally lazy enough that I am happy about just submitting patches. On the other hand, I am tried of these sparse patches floating around the mailing list. I can start a branch to merge the proper patches. Maybe some thing like a development branch for sparse.
Is that some thing other people want?
I'd use/test such a branch rather than scraping the mailing list for useful bits.
Harvey
Quoted 6 lines
BTW, I am normally lazy enough that I am happy about just submitting patches. On the other hand, I am tried of these sparse patches floating around the mailing list. I can start a branch to merge the proper patches. Maybe some thing like a development branch for sparse.
Is that some thing other people want?
Please do so. We need some progress on sparse and current maintainer seems to be occupied by other things at the moment.
Sam
Quoted 11 lines · Sam Ravnborg
Quoted 6 lines
BTW, I am normally lazy enough that I am happy about just submitting patches. On the other hand, I am tried of these sparse patches floating around the mailing list. I can start a branch to merge the proper patches. Maybe some thing like a development branch for sparse.
Is that some thing other people want?Please do so. We need some progress on sparse and current maintainer seems to be occupied by other things at the moment.
Sam
Hello.
How about?
http://git.zaytsev.su/git?p=sparse.git;a=shortlog;h=discuss
This branch holds the two patch collections* I recently sent to the mailing list. I
think it includes every useful patch that does not break the kernel check, and even some that do. ;)
The last time we spoke (yesterday) Josh was going to merge the patches really soon. The idea was to merge everything except the context patches, make a release, add the context patches, and wait for someone to fix them.
Quoted 3 lines · Alexey Zaytsev
The last time we spoke (yesterday) Josh was going to merge the patches really soon. The idea was to merge everything except the context patches, make a release, add the context patches, and wait for someone to fix them.
Make sure to revert those that are in the tree now though, before the release.
johannes
Quoted 9 lines · Johannes Berg
Quoted 3 lines · Alexey Zaytsev
The last time we spoke (yesterday) Josh was going to merge the patches really soon. The idea was to merge everything except the context patches, make a release, add the context patches, and wait for someone to fix them.
Make sure to revert those that are in the tree now though, before the release.
By the way, are you sure the latest series you have sent is correct? To me it seems that it does not make any warnings go away, and adds quite some more:
http://zaytsev.su/tmp/build.diff.txt
Quoted 3 lines · Alexey Zaytsev
By the way, are you sure the latest series you have sent is correct? To me it seems that it does not make any warnings go away, and adds quite some more:
http://zaytsev.su/tmp/build.diff.txt
Yes, because the context name wasn't previously used it messes up in places with that patch set... This was discussed a few times previously, you should be able to find it on list archives.
johannes
Quoted 3 lines · Alexey Zaytsev
By the way, are you sure the latest series you have sent is correct? To me it seems that it does not make any warnings go away, and adds quite some more:
http://zaytsev.su/tmp/build.diff.txt
include/net/sch_generic.h:225:2: warning: label 'continue' already bound
This, of course, shouldn't happen. I thought I'd fixed it, but who knows. I think it should all just be reverted :)
johannes
Christopher Li
maintainerQuoted 10 lines · Johannes Berg
Quoted 3 lines · Alexey Zaytsev
By the way, are you sure the latest series you have sent is correct? To me it seems that it does not make any warnings go away, and adds quite some more:
http://zaytsev.su/tmp/build.diff.txt
include/net/sch_generic.h:225:2: warning: label 'continue' already boundThis, of course, shouldn't happen. I thought I'd fixed it, but who knows. I think it should all just be reverted :)
Hi,
Do you want to resend your change which revert the context changes? Make it base on Josh's git's tree and I will merge your changes in my branch.
It will take me a while to get up to speed with the git goodness. I will start with merging Alexey's resend patches.
Chris
Quoted 3 lines · Christopher Li
Do you want to resend your change which revert the context changes? Make it base on Josh's git's tree and I will merge your changes in my branch.
Below. Or I can give it to you in git if you prefer. I still think we should redo this in some form so that annotations with different contexts can work properly, but I don't have time to take care of it right now.
Quoted 2 lines
It will take me a while to get up to speed with the git goodness. I will start with merging Alexey's resend patches.
Mind you, he sent a few of my patches, so ignore those.
johannes
From ca95b62edf1600a2b55ed9ca0515d049807a84fc Mon Sep 17 00:00:00 2001
From: Johannes Berg <[email protected]>
Date: Tue, 23 Dec 2008 10:53:19 +0100
Subject: [PATCH] Revert context tracking code
--- inline.c | 12 +- linearize.c | 31 ++- linearize.h | 7 +- parse.c | 134 +--------- parse.h | 3 +- sparse.1 | 41 +--- sparse.c | 424 ++++--------------------------- symbol.h | 3 +- validation/context-dynamic.c | 171 ------------- validation/context-named.c | 553 ---------------------------------------- validation/context-statement.c | 69 ----- validation/context.c | 114 +------- 12 files changed, 107 insertions(+), 1455 deletions(-) delete mode 100644 validation/context-dynamic.c delete mode 100644 validation/context-named.c delete mode 100644 validation/context-statement.c
inline.c +2 -10
@@ -331,18 +331,10 @@ static struct statement *copy_one_statement(struct statement *stmt)case STMT_CONTEXT :case STMT_EXPRESSION : {struct expression *expr =copy_expression (stmt->expression); -struct statement *newstmt;if (expr == stmt->expression)break ; - newstmt =dup_statement (stmt); - newstmt->expression = expr; -if (stmt->required) { - expr =copy_expression (stmt->required); -if (expr == stmt->required) -break ; - newstmt->required = expr; - } - stmt = newstmt; + stmt =dup_statement (stmt); + stmt->expression = expr;break ; }case STMT_RANGE : {
linearize.c +16 -15
@@ -68,6 +68,7 @@ static struct entrypoint *alloc_entrypoint(void)static struct basic_block *alloc_basic_block (struct entrypoint *ep,struct position pos) {struct basic_block *bb =__alloc_basic_block (0 ); + bb->context =-1 ; bb->pos = pos; bb->ep = ep;return bb;
@@ -440,7 +441,7 @@ const char *show_instruction(struct instruction *insn)break ;case OP_CONTEXT : - buf +=sprintf (buf,"%s%d,%d" ,"" , insn->increment, insn->inc_false); + buf +=sprintf (buf,"%s%d" , insn->check ?"check: " :"" , insn->increment);break ;case OP_RANGE : buf +=sprintf (buf,"%s between %s..%s" ,show_pseudo (insn->src1),show_pseudo (insn->src2),show_pseudo (insn->src3));
@@ -1234,12 +1235,22 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi FOR_EACH_PTR(ctype->contexts, context) {int in = context->in;int out = context->out; - -if (out - in || context->out_false - in) { +int check =0 ; +int context_diff; +if (in <0 ) { + check =1 ; + in =0 ; + } +if (out <0 ) { + check =0 ; + out =0 ; + } + context_diff = out - in; +if (check || context_diff) { insn =alloc_instruction (OP_CONTEXT ,0 ); - insn->increment = out - in; + insn->increment = context_diff; + insn->check = check; insn->context_expr = context->context; - insn->inc_false = context->out_false - in;add_one_insn (ep, insn); } }END_FOR_EACH_PTR (context);
@@ -1674,16 +1685,6 @@ static pseudo_t linearize_context(struct entrypoint *ep, struct statement *stmt) value = expr->value; insn->increment = value; - insn->inc_false = value; - - expr = stmt->required; - value =0 ; - -if (expr && expr->type ==EXPR_VALUE ) - value = expr->value; - - insn->required = value; - insn->context_expr = stmt->context;add_one_insn (ep, insn);return VOID ;
linearize.h +3 -4
@@ -117,7 +117,8 @@ struct instruction {struct pseudo_list *arguments; };struct /* context */ { -int increment, required, inc_false; +int increment; +int check;struct expression *context_expr; };struct /* asm */ {
@@ -220,13 +221,11 @@ enum opcode {struct basic_block_list ;struct instruction_list ; -struct context_list_list ;struct basic_block {struct position pos;unsigned long generation; -int context_check_recursion; -struct context_list_list *checked_contexts; +int context;struct entrypoint *ep;struct basic_block_list *parents;/* sources */ struct basic_block_list *children;/* destinations */
parse.c +10 -124
186 lines not on this page · raw message
parse.h +1 -2
@@ -39,10 +39,9 @@ struct statement {struct symbol *label;struct statement *label_statement; }; -struct {/* __context__ */ +struct {struct expression *expression;struct expression *context; -struct expression *required; };struct /* return_statement */ {struct expression *ret_value;
sparse.1 +10 -33
53 lines not on this page · raw message
sparse.c +51 -373
467 lines not on this page · raw message
symbol.h +1 -2
@@ -71,8 +71,7 @@ enum keyword {struct context {struct expression *context; -unsigned int in, out, out_false; -int exact; +unsigned int in, out; };extern struct context *alloc_context (void );
validation/context-dynamic.c deleted +0 -171
171 lines not on this page · raw message
validation/context-named.c deleted +0 -553
553 lines not on this page · raw message
validation/context-statement.c deleted +0 -69
69 lines not on this page · raw message
validation/context.c +14 -100
123 lines not on this page · raw message
Signature · 1 line
1.6.0.6
Christopher Li
maintainerQuoted 5 lines · Johannes Berg
Below. Or I can give it to you in git if you prefer. I still think we should redo this in some form so that annotations with different contexts can work properly, but I don't have time to take care of it right now.
Thanks for the patch. It applied cleanly. I am still checking weather I use git properly. I will publish my git tree soon.
Chris
Quoted 6 lines · On Tuesday 23 December 2008 07:27:50 Al Viro wrote:
The right solution is
(*(typeof(v) __attribute__((address_space(0), force)) *)(&v))Cast there will take a pointer to type of V and force-cast it to pointer to unqualified type of V. *(cast)&v will do the obvious thing. Will trim both the AS and noderef.
Thanks Al, that worked, but seems to tickle another bug (sparse 0.4.1, Ubuntu).
rusty@vivaldi:/tmp$ sparse foo.c foo.c:11:20: warning: incorrect type in assignment (invalid types) foo.c:11:20: expected unknown type 11<noident> foo.c:11:20: got int
Here's my sample program now:
#define __percpu __attribute__((noderef, address_space(3)))
/* Turn v back into a normal var. */
#define convert(v) \
(*(typeof(v) __attribute__((address_space(0), force)) *)(&v))int main(int argc, char *argv)
{
unsigned int __percpu x;
convert(x) = 0;
return 0;
}Christopher Li
maintainerQuoted 5 lines · Rusty Russell
rusty@vivaldi:/tmp$ sparse foo.c foo.c:11:20: warning: incorrect type in assignment (invalid types) foo.c:11:20: expected unknown type 11<noident> foo.c:11:20: got int
I think you need this patch for sparse. The version of sparse you have does not handle typeof based type compare yet.
Chris