-
Notifications
You must be signed in to change notification settings - Fork 396
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
rust: add initial netdevice support #908
Conversation
The CI system failure? The same code successfully passed the CIs on my repository: |
rust/kernel/net.rs
Outdated
ndo_get_tstamp: None, | ||
}; | ||
|
||
const unsafe fn build_device_ops() -> &'static bindings::net_device_ops { |
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.
The unsafe
function needs a specification about the condition when it's safe to use by comment Safety
.
rust/kernel/net.rs
Outdated
let ptr = unsafe { bindings::dev_get_drvdata(&mut (*netdev).dev) }; | ||
let dev = unsafe { Device::from_ptr(netdev) }; | ||
let data = unsafe { T::Data::borrow(ptr) }; |
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 lacks the SAFETY
comment. There are many other places also lacking a SAFETY
comment.
Besides, It is better to use from_kernel_result
to wrap a rust crate::error::Result
to a Linux kernel result.
For 'net_device', I find it's more common to use netdev_priv
to get data from the device.
I'm not a reviewer. Just have a look because I also wrap |
Thanks for the pointer.
|
It seems that I lack a BTW, our PRs both wrap the |
How it can be with
Surely. Your PR includes most of |
For The above procedure can be constrainted in the |
In the probe function, the driver calculates a pointer to the driver-defined data by using You have your virtio-net code somewhere? Still not sure how your registration works. btw, updated the code; adds SAFETY comments and uses |
I just merge part of the The |
virtio abstraction should not use |
The previous version has a problem. The private data should be added to the net_device in the probe function. This is done by storing the pointer where The virtio_device should have its this private data by the probe_callback function. |
I see what you try to do with |
Yes. This will lose the efficience of cache the data in the close area, making it similar to using 'dev->driver_data' in performance. |
I think that using |
One thing I'm worried is that I don't know whether the data pointed by |
Why you needs to use both
What do you mean? |
Are you sure that |
Yeah, I can't find any places where networking core touches |
I may find an example. This |
Hmm, this driver doesn't use |
That driver does only use I will check whether there is a way to use |
Your code looks quite promising! The only issue I see is a couple missing EDIT: Actually I noticed you're still using I am also not a reviewer, just yet another person eager to develop network drivers for Linux in Rust. The kernel is in dire need of an API on the Rust side to write network drivers so that every person who wants to write one doesn't have to reinvent the wheel so to speak. As I see it right now, this PR is a very good base that doesn't break the way things like I have a question however, wouldn't it be time to split everything related to |
Added minimum abstration APIs for network device drivers. Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Thanks for the comments! I've just update the code against the latest linux-rust branch.
It was just easier for me to submit a single module for initial submission. But it will be split in the future. |
Added minimum abstration APIs for network device drivers.
Signed-off-by: FUJITA Tomonori fujita.tomonori@gmail.com