-
Notifications
You must be signed in to change notification settings - Fork 436
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
Implement a #[vtable]
macro
#322
Conversation
This comment has been minimized.
This comment has been minimized.
Review of
|
I see this pattern in #264 again so we definitely want a single macro abstraction for all vtables. |
As you know, this is something that I wanted to do for
|
I don't know if #264 need this, but #208 certainly do.
Are there reasons not to implement read_iter/write_iter? The current trait design essentially guarantees that it either both or none are supported. Without specialization, it makes no sense to support one but not another. If we really want to let the implementor decide, then generics should not be used. If we do want them to opt out (rather than opt in), we can just add a manual
I would suggest the opposite. I would also argue that it is also less complex than the current declarative macro. I got confused when I first saw the This procedural macro is simpler to use, less error prone, less code, less boilerplate, and generate a good documentation. 60 lines of boilerplate for each vtable and hours of debugging caused by forgetting to add the name of method to the |
I don't understand why you're so against proc macros, but I want to make one point: any complexities in proc macros are used to reduce complexities elsewhere. As long as the reduced complexities outweigh the introduced complexities, we should definitely go for it. As for this case, given that there we are going to have at least 2 (maybe 3) trait users and a couple impl users of this macro, and certainly more in the future, I believe the macro certainly reduces the overall complexity. |
rust/macros/vtable.rs
Outdated
const_items = "const USE_VTABLE_ATTR: () = ();".to_owned(); | ||
|
||
for f in functions { | ||
write!(const_items, "const HAS_{}: bool = true;", f.to_uppercase()).unwrap(); |
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.
line 66 adds a doc comment about the const value, which is missing in this line.
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.
It's intentional to have doc comment only in trait but not in impls.
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.
Than I misread. Then nevermind
fa059e1
to
bcb1aed
Compare
rust/kernel/irq.rs
Outdated
@@ -9,6 +9,7 @@ | |||
|
|||
#![allow(dead_code)] | |||
|
|||
use crate::prelude::*; |
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.
nit: are you including the prelude just for vtable
? If so, I think it's better to add macros::vtable
to the list below.
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 think it should generally be fine to include prelude. I could remove the Error
and Result
import so that this import is used more than just vtable
.
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.
Even if you want to include prelude::*
, you should add it to the line below for consistency.
Now, given the choice of adding macros::vtable
or prelude::*
, I think the former is preferable because we don't pollute the namespace with more symbols than needed. (prelude is meant for drivers.)
You're obviously welcome to disagree with our handling or prelude
, but in that case I'd argue that you're unnecessarily conflating issues: let's open another PR or issue to discuss that if you'd like. I'm ready to merge this once we come to an agreement on the use
clause.
Use a single `#[vtable]` macro to replace the current boilerplating of `ToUse`, `USE_NONE`, `declare_file_operations` required for declaring and implementing traits that maps to Linux's pure vtables and contains optional methods. Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Thank you, @nbdd0121! |
On Raspberry Pis without onboard USB hub frequent device reconnects can trigger a interrupt storm after DWC2 entered host clock gating. This is caused by a race between _dwc2_hcd_suspend() and the port interrupt, which sets port_connect_status. The issue occurs if port_connect_status is still 1, but there is no connection anymore: usb 1-1: USB disconnect, device number 25 dwc2 3f980000.usb: _dwc2_hcd_suspend: port_connect_status: 1 dwc2 3f980000.usb: Entering host clock gating. Disabling IRQ #66 irq 66: nobody cared (try booting with the "irqpoll" option) CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 6.12.0-gc1bb81b13202-dirty #322 Hardware name: BCM2835 Call trace: unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x50/0x64 dump_stack_lvl from __report_bad_irq+0x38/0xc0 __report_bad_irq from note_interrupt+0x2ac/0x2f4 note_interrupt from handle_irq_event+0x88/0x8c handle_irq_event from handle_level_irq+0xb4/0x1ac handle_level_irq from generic_handle_domain_irq+0x24/0x34 generic_handle_domain_irq from bcm2836_chained_handle_irq+0x24/0x28 bcm2836_chained_handle_irq from generic_handle_domain_irq+0x24/0x34 generic_handle_domain_irq from generic_handle_arch_irq+0x34/0x44 generic_handle_arch_irq from __irq_svc+0x88/0xb0 Exception stack(0xc1d01f20 to 0xc1d01f68) 1f20: 0004ef3c 00000001 00000000 00000000 c1d09780 c1f6bb5c c1d04e54 c1c60ca8 1f40: c1d04e94 00000000 00000000 c1d092a8 c1f6af20 c1d01f70 c1211b98 c1212f40 1f60: 60000013 ffffffff __irq_svc from default_idle_call+0x1c/0xb0 default_idle_call from do_idle+0x21c/0x284 do_idle from cpu_startup_entry+0x28/0x2c cpu_startup_entry from kernel_init+0x0/0x12c handlers: [<e3a25c00>] dwc2_handle_common_intr [<58bf98a3>] usb_hcd_irq Disabling IRQ #66 So avoid this by reading the connection status directly. Fixes: 113f86d ("usb: dwc2: Update partial power down entering by system suspend") Signed-off-by: Stefan Wahren <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
Use a single
#[vtable]
macro to replace the current boilerplating ofToUse
,USE_NONE
, declare_file_operations` required for declaring and implementing traits that maps to Linux's pure vtables and contains optional methods.This'll be more natural and less noisy than the current approach, and it paves the way for other vtables such as the one in #208 so that we don't need a
ToUse
,USE_NONE
and a macro for each vtable trait.Little note that this just scans the tokens so cannot handle case like
but this is very rare. I think we can live with this for now; we can always migrate to proper parsing later if we ever get
syn
vendored.