DataLinkLayer Experiment #179064
Replies: 3 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
-
1. Buffer Pool Management
2. Magic Number Usage
3. Mutex and Workqueue Handling
4. General Code Style and Readability
5. General Suggestions and Potential Issues
Summary Table
|
Beta Was this translation helpful? Give feedback.
-
|
Hey! This is some seriously ambitious stuff, kernel networking code is tough. I've been looking through your DataLinkLayer implementation and have some thoughts that might help: Stuff That Needs AttentionThe skb reference thing looks sketchy When you do this in skb_get(skb);
INIT_WORK(&frw->wt,ContinueReceiver);
schedule_work(&frw->wt);You're grabbing a reference to the skb, but there's no guarantee the work scheduler sees that increment before it runs. Toss in Double device lookup is wasteful In GFP_KERNEL in packet receive path? Nah struct ForwardReceiverContent*frc=kmem_cache_alloc(ForwardReceiverContentCachie, GFP_KERNEL);This can sleep, which you really don't want in RX context. Change it to The Locking SituationYour mutex usage in Try something like: // Do your allocations first
struct Device*d=kmalloc(sizeof(*d), GFP_ATOMIC);
if (!d) return;
// Set up the device
memcpy(d->dll.Address, eth_hdr(skb)->h_source, 6);
INIT_LIST_HEAD(&d->lh);
// NOW lock and double-check
mutex_lock(&h->l);
struct Device*existing = SearchDevice(skb,h);
if (existing) {
mutex_unlock(&h->l);
kfree(d);
// use existing instead
return;
}
list_add(&d->lh, &h->dlh);
mutex_unlock(&h->l);Honestly though, for device lookups you might want RCU instead of mutexes. It's mostly reads, right? Mutexes are kinda heavy for that. Couple Other ThingsYour module exit doesn't wait for work items to finish. Add The timeout being a static global is fine for now, but you might want to make it a module parameter so people can tune it without recompiling: static uint device_timeout_minute = 10;
module_param(device_timeout_minute, uint, 0644);Overall this is pretty cool work. Kernel networking is genuinely hard and you're clearly getting the core concepts. Just needs some polish on the concurrency stuff. Have you tested this under load? I'd be curious what happens if you hammer it with packets while devices are timing out. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Hello everyone,
I’m experimenting with a kernel-level DataLinkLayer in C.
You can view the full code here: DataLinkLayer.c
I’m especially interested in feedback on:
Any suggestions for improvements or potential issues would be highly appreciated.
Thanks!
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions