-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module!
improvements
#278
base: rust
Are you sure you want to change the base?
module!
improvements
#278
Conversation
This comment has been minimized.
This comment has been minimized.
@@ -0,0 +1,401 @@ | |||
use proc_macro::{Literal, Span}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing SPDX
.
rust/macros/syn/mod.rs
Outdated
//! Shared parsing functions for use in procedural macros. These functions are | ||
//! from [syn](https://github.com/dtolnay/syn). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//! Shared parsing functions for use in procedural macros. These functions are | |
//! from [syn](https://github.com/dtolnay/syn). | |
//! Shared parsing functions for use in procedural macros. | |
//! | |
//! These functions come from the [`syn`](https://github.com/dtolnay/syn) crate. |
Are the files too different from the original ones? If not, perhaps recording in the comment the Git tag from where they were checked out would be nice. If yes, doing it in the commit message is fair.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I does make a few changes to strip away anything that depends on macros, bigint and unicode-xid. But I agree it's better to also record version number in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great, thanks for removing those bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also mentioning that in the comment would be nice too (i.e. so that people doing future updates, if any, are aware of that and do not add bigint
etc. back).
Looks great, as usual! GitHub does not allow to comment on the commit messages themselves :( So I put those here:
(I also really miss the "suggestion" feature in the commit-by-commit view -- if someone knows how to easily do it without having to move to the "changes" view, please let me know!). |
This comment has been minimized.
This comment has been minimized.
Renaming to libmacros allows us to potentially have more procedural macros in the future without introducing additional crates. Signed-off-by: Gary Guo <[email protected]>
`module!` macro currently have some ad-hoc literal parsing. `syn` crate provides some proper parsing for us to use. Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
`TokenStream` itself is very hard to use for parsing, as it does not provide lookahead capability. `syn`'s buffer will provide cleanup opportunity. Signed-off-by: Gary Guo <[email protected]>
Make use of `syn` buffer's lookahead capability to remove `try_*` parsing functions. Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Doing so allows `module_misc_device!` to do codegen directly instead of generating a `module!` invocation. Generating `module!` invocation is error-prone and would require significant effort when features are added to `module!` macro or when syntax is changed. Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Review of
|
Perhaps let's take the chance of the conflict to split this into smaller PRs. The first commit can go in its own PR if others agree on having all procedural macros in a single crate. It would be best to put the pros/cons of that in the commit message. |
I couldn't think of any pros for having each procedural macro in their own crate. |
Hmm... faster re-compilation on changes? Perhaps compilation speed overall since it can be parallelized? (because otherwise we use codegen-units 1) What about the pros of a single crate? Easier |
Using |
Of course, but that is how the flags are setup at the moment; i.e. I was explaining why having split crates would increase compilation speed in our current setup (because if a reader does not know about |
To be clear: I am happy if we decide to split the flags for proc macros if we end up with a big |
When both bpf_spin_lock and bpf_timer are present in a BPF map value, copy_map_value needs to skirt both objects when copying a value into and out of the map. However, the current code does not set both s_off and t_off in copy_map_value, which leads to a crash when e.g. bpf_spin_lock is placed in map value with bpf_timer, as bpf_map_update_elem call will be able to overwrite the other timer object. When the issue is not fixed, an overwriting can produce the following splat: [root@(none) bpf]# ./test_progs -t timer_crash [ 15.930339] bpf_testmod: loading out-of-tree module taints kernel. [ 16.037849] ================================================================== [ 16.038458] BUG: KASAN: user-memory-access in __pv_queued_spin_lock_slowpath+0x32b/0x520 [ 16.038944] Write of size 8 at addr 0000000000043ec0 by task test_progs/325 [ 16.039399] [ 16.039514] CPU: 0 PID: 325 Comm: test_progs Tainted: G OE 5.16.0+ #278 [ 16.039983] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ArchLinux 1.15.0-1 04/01/2014 [ 16.040485] Call Trace: [ 16.040645] <TASK> [ 16.040805] dump_stack_lvl+0x59/0x73 [ 16.041069] ? __pv_queued_spin_lock_slowpath+0x32b/0x520 [ 16.041427] kasan_report.cold+0x116/0x11b [ 16.041673] ? __pv_queued_spin_lock_slowpath+0x32b/0x520 [ 16.042040] __pv_queued_spin_lock_slowpath+0x32b/0x520 [ 16.042328] ? memcpy+0x39/0x60 [ 16.042552] ? pv_hash+0xd0/0xd0 [ 16.042785] ? lockdep_hardirqs_off+0x95/0xd0 [ 16.043079] __bpf_spin_lock_irqsave+0xdf/0xf0 [ 16.043366] ? bpf_get_current_comm+0x50/0x50 [ 16.043608] ? jhash+0x11a/0x270 [ 16.043848] bpf_timer_cancel+0x34/0xe0 [ 16.044119] bpf_prog_c4ea1c0f7449940d_sys_enter+0x7c/0x81 [ 16.044500] bpf_trampoline_6442477838_0+0x36/0x1000 [ 16.044836] __x64_sys_nanosleep+0x5/0x140 [ 16.045119] do_syscall_64+0x59/0x80 [ 16.045377] ? lock_is_held_type+0xe4/0x140 [ 16.045670] ? irqentry_exit_to_user_mode+0xa/0x40 [ 16.046001] ? mark_held_locks+0x24/0x90 [ 16.046287] ? asm_exc_page_fault+0x1e/0x30 [ 16.046569] ? asm_exc_page_fault+0x8/0x30 [ 16.046851] ? lockdep_hardirqs_on+0x7e/0x100 [ 16.047137] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 16.047405] RIP: 0033:0x7f9e4831718d [ 16.047602] Code: b4 0c 00 0f 05 eb a9 66 0f 1f 44 00 00 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d b3 6c 0c 00 f7 d8 64 89 01 48 [ 16.048764] RSP: 002b:00007fff488086b8 EFLAGS: 00000206 ORIG_RAX: 0000000000000023 [ 16.049275] RAX: ffffffffffffffda RBX: 00007f9e48683740 RCX: 00007f9e4831718d [ 16.049747] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00007fff488086d0 [ 16.050225] RBP: 00007fff488086f0 R08: 00007fff488085d7 R09: 00007f9e4cb594a0 [ 16.050648] R10: 0000000000000000 R11: 0000000000000206 R12: 00007f9e484cde30 [ 16.051124] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 16.051608] </TASK> [ 16.051762] ================================================================== Fixes: 6813466 ("bpf: Add map side support for bpf timers.") Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
This is a large PR. It's best reviewed by commits.
Rename libmodule to libmacros
Renaming to libmacros allows us to potentially have more procedural macros in the future without introducing additional crates.
Vendor literal parsing from syn crate
accept str instead of bstr in module!
Fixes #252. Doing so requires capability to parse strings so I vendored in the
lit
mod from syn.Vendor buffer from syn crate
module macro cleanup using buffer
Some cleanup with
buffer
mod vendored from syn.TokenStream
itself is very hard to use for parsing, because it does not provide lookahead capability. With the buffer it can be simplified a lot.cleanup modinfo generation in module!
separate parse and codegen in module!
These organizes the code so that parsing and codegen are split into two phased. This allows the
module_misc_device
macro to do codegen directly, so it does not have to re-generate themodule!
invocation.multiple author/alias support in module!
Fixes #244, fixes #246. Becomes a very simple change with all the cleanups made.
allow any constexpr to be used as param default
With syn's buffer's lookahead capability this also becomes a trivial change.