Skip to content
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

fix: af_netlink problems in the new branch reported by RA #897

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
7ff7ce3
add netlink todo directory
val213 Apr 7, 2024
503f5a1
Merge branch 'DragonOS-Community:master' into uevent
val213 Apr 8, 2024
0e816cb
save the work 2 another system workplace
val213 Apr 17, 2024
e9c3b2f
save the work 2 another system workplace
val213 Apr 17, 2024
5fe5a71
add the demo of netlink_create and locate the kobject_uevent\kobject_…
val213 Apr 18, 2024
84e25b5
add the uevent directory and demo of kobject_uevent and kobject_ueven…
Apr 19, 2024
980402c
Merge branch 'DragonOS-Community:master' into uevent
val213 Apr 19, 2024
7cfc657
delete sth else in target
Apr 19, 2024
ba09f50
handle existing errors, ready for the next period of dev
Apr 25, 2024
7e7f5b0
阶段性提交,完成了kobjectuevent_env的部分逻辑,接下来需要实现uevent_ops结构体的转写
Apr 25, 2024
f1aed00
调整uevent_suppress和subsystem,修改分支日志打印信息
val213 Apr 25, 2024
c0ae5d2
调整uevent_suppress和subsystem,修改分支日志打印信息
val213 Apr 25, 2024
3530840
在kset中引入了KsetUeventOps的trait,待实现
val213 Apr 25, 2024
920632b
阶段性提交, 基本完成了处理kset的uevent_ops相关逻辑,新增一个trait和一个结构体,正在逐步完善kobject_ueven…
Apr 27, 2024
60c46ba
阶段性提交:完善大部分kobject_uevent_env函数的功能
Apr 28, 2024
f4b4565
add_uevent_var,kobject_uevent_net_broadcast,zap_modalias_env,完善其他细节的逻辑
Apr 29, 2024
9eb2cc0
阶段性提交,开始逐渐深入与netlink
val213 May 1, 2024
564aa91
Merge branch 'DragonOS-Community:master' into uevent
val213 May 13, 2024
b949fb9
Merge branch 'DragonOS-Community:master' into uevent
val213 May 13, 2024
6cb2e7d
阶段性提交,重构netlinktable和netlinksocket
val213 May 14, 2024
2df749a
merge the updates in the upstream master into uevent
val213 May 16, 2024
be571a4
replace kdebug with log::info!
val213 May 16, 2024
539c512
理清了sock和ueventsock的关系,重构了一部分原来的代码
val213 May 17, 2024
bd795ae
阶段性提交,新增了几个函数,进一步完善了netlink
val213 May 18, 2024
d61005a
Merge branch 'DragonOS-Community:master' into uevent
val213 May 19, 2024
678f4cc
阶段性提交,新增了Sk_Buff封装了一层PacketBuffer,需要解决mc_list迭代器实现方案和PacketBuffer提供的接…
val213 May 19, 2024
29c2775
Merge branch 'DragonOS-Community:master' into uevent
val213 May 21, 2024
274721f
初步解决mc_list迭代问题和consume_skb
val213 May 21, 2024
0e7f9fe
fmt
val213 May 22, 2024
ade4997
同步更改
val213 May 27, 2024
18b0dbf
asy to antoher workplace
val213 Jul 1, 2024
30c3481
初步解决现有代码中所有权和生命周期等问题
val213 Jul 2, 2024
f2ece48
fix nlk_sk and init test for uevent
val213 Jul 4, 2024
850b879
初步在driver中成功调用kobject_uevent()进行测试,标记需要发送uevent的地方
val213 Jul 5, 2024
8f1ddbe
ipml socket for netlinksock
val213 Jul 9, 2024
3570c5d
Merge branch 'DragonOS-Community:master' into uevent
val213 Jul 11, 2024
5221cb8
阶段性提交,完善netlink_proto相关内容
val213 Jul 12, 2024
8c1c57c
阶段性提交,初步实现netlink_add_usersock_entry等
val213 Jul 13, 2024
1d61b6c
实现netlink_proto_init()
val213 Jul 13, 2024
d9338d9
add NetProtoFamily and NetlinkFamulyOps
val213 Jul 14, 2024
38458c7
修复mprotect系统调用未正确设置vm_flags的错误 (#847)
MemoryShore Jul 16, 2024
af097f9
fix(time): modify update wall time (#836)
1037827920 Jul 16, 2024
2c5ea7b
chore: 调整triagebot.toml以适应新的组织架构 (#848)
fslongjin Jul 16, 2024
d8b63e3
netlink_insert大体框架,遇到nlk无法修改的问题
val213 Jul 16, 2024
9a4832f
doc: 完善README.md (#849)
fslongjin Jul 17, 2024
ef2a79b
chore: 更新sphinx相关配置,适应read the docs的更新 (#850)
fslongjin Jul 17, 2024
f3c378e
完善netlink_insert 和 netlink_lookup
val213 Jul 17, 2024
388556a
Merge branch 'DragonOS-Community:master' into uevent
val213 Jul 18, 2024
1ea2daa
feat(driver/net): 实现Loopback网卡接口 (#845)
smallcjy Jul 22, 2024
79ad6e5
fix: build-scripts和tools目录下的make check指定工具链版本 (#861)
fslongjin Jul 22, 2024
634349e
fix: tcp poll没有正确处理posix socket的listen状态的问题 (#859)
fslongjin Jul 24, 2024
bd70d2d
chore: 将工具链更新到2024-07-23 (#864)
fslongjin Jul 24, 2024
b6a5c42
考虑更换Sk_Buffer实现,留档原有方案
val213 Jul 25, 2024
86ee139
feat(fs): add eventfd syscall support (#858)
Godones Jul 25, 2024
1848595
更换Sk_Buffer实现
val213 Jul 25, 2024
816ee5a
refactor: 删除过时的va-pa转换函数,改为统一使用MMArch (#862)
fslongjin Jul 25, 2024
0f66893
需要解决Arc内部可变性问题
val213 Jul 26, 2024
61dfe4f
Merge branch 'DragonOS-Community:master' into uevent
val213 Jul 26, 2024
29d5f44
需要解决Arc内部可变性问题
val213 Jul 26, 2024
21595ba
解决sk:Arc内部可变性问题
val213 Jul 26, 2024
3c0a1c8
默认nightly-2024-07-23 & config改为config.toml (#872)
Jomocool Jul 26, 2024
703ce5a
fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。 (#870)
fslongjin Jul 27, 2024
412718e
基本实现netlink单播,todo回调函数
val213 Jul 27, 2024
3a74448
remove unused import
val213 Jul 27, 2024
59353d8
考虑是否引入回调函数,补充sockflags
val213 Jul 28, 2024
b265c74
updates test-uevent
val213 Jul 29, 2024
81fa02c
Merge branch 'DragonOS-Community:master' into uevent
val213 Jul 29, 2024
47369ed
Merge branch 'uevent' of github.com:val213/DragonOS into uevent
val213 Jul 29, 2024
051c776
add endpoint and complete to_endpoint function for NetLinkEndpoint
val213 Jul 31, 2024
0648a54
feat(cred): 初步实现Cred (#846)
Jomocool Aug 2, 2024
a1fc824
fix: 修复键盘码解析器没能正确处理类似ctrl C的控制字符的问题 (#877)
fslongjin Aug 6, 2024
c516366
success to call NetlinkSock bind fn and add a fn into Socket trait
val213 Aug 8, 2024
e91719f
Merge branch 'DragonOS-Community:master' into uevent
val213 Aug 8, 2024
c2f6a0b
Merge branches 'uevent' and 'uevent' of github.com:val213/DragonOS in…
val213 Aug 8, 2024
076ed47
modify handle in NetlinkSock
val213 Aug 16, 2024
21fed6e
merge new branch
val213 Aug 16, 2024
d2d96e3
fix af_netlink problems in the new branch reported by RA
val213 Aug 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@
"check",

],
"rust-analyzer.showUnlinkedFileNotification": false,
"files.autoSave": "onFocusChange",
"editor.fontSize": 17,
"editor.accessibilityPageSize": 15,
}
10 changes: 8 additions & 2 deletions kernel/src/driver/acpi/sysfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use log::{debug, error, warn};
use system_error::SystemError;

use super::{acpi_kset, AcpiManager};

use crate::driver::base::uevent::kobject_uevent::kobject_uevent;
use crate::driver::base::uevent::KobjectAction;
static mut __HOTPLUG_KSET_INSTANCE: Option<Arc<KSet>> = None;
static mut __ACPI_TABLES_KSET_INSTANCE: Option<Arc<KSet>> = None;
static mut __ACPI_TABLES_DATA_KSET_INSTANCE: Option<Arc<KSet>> = None;
Expand Down Expand Up @@ -115,7 +116,12 @@ impl AcpiManager {
acpi_table_attr_list().write().push(attr);
self.acpi_table_data_init(&header)?;
}

// TODO:UEVENT
unsafe{
let _ = kobject_uevent(acpi_tables_kset.clone() as Arc<dyn KObject>, KobjectAction::KOBJADD);
let _ = kobject_uevent( __ACPI_TABLES_DATA_KSET_INSTANCE.as_ref().map(|kset| kset.clone() as Arc<dyn KObject>).unwrap(), KobjectAction::KOBJADD);
let _ = kobject_uevent(__ACPI_TABLES_DYNAMIC_KSET_INSTANCE.as_ref().map(|kset| kset.clone() as Arc<dyn KObject>).unwrap(), KobjectAction::KOBJADD);
}
return Ok(());
}

Expand Down
1 change: 1 addition & 0 deletions kernel/src/driver/base/device/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ impl DriverManager {
}

// todo: 发送kobj bind的uevent
// kobject_uevent();
}

fn driver_is_bound(&self, device: &Arc<dyn Device>) -> bool {
Expand Down
7 changes: 5 additions & 2 deletions kernel/src/driver/base/device/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use super::{
bus::{bus_manager, Bus},
Device, DeviceMatchName, DeviceMatcher, IdTable,
};
use crate::driver::base::uevent::kobject_uevent::kobject_uevent;
use crate::driver::base::uevent::KobjectAction;
use crate::{
driver::base::{
device::{bus::BusNotifyEvent, dd::DeviceAttrCoredump, device_manager},
Expand All @@ -17,7 +19,6 @@ use alloc::{
use core::fmt::Debug;
use log::error;
use system_error::SystemError;

/// @brief: Driver error
#[allow(dead_code)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -218,7 +219,9 @@ impl DriverManager {
bus_manager().remove_driver(&driver);
})?;

// todo: 发送uevent
// todo: 发送uevent,类型问题
let _ = kobject_uevent(driver.clone() as Arc<dyn KObject>, KobjectAction::KOBJADD);
// deferred_probe_extend_timeout();

return Ok(());
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/driver/base/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl DeviceManager {
}

// todo: 发送uevent: KOBJ_ADD

// kobject_uevent();
// probe drivers for a new device
bus_probe_device(&device);

Expand Down
71 changes: 67 additions & 4 deletions kernel/src/driver/base/kobject.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::{any::Any, fmt::Debug, hash::Hash, ops::Deref};

use alloc::{
boxed::Box,
string::String,
sync::{Arc, Weak},
};
Expand All @@ -21,7 +22,7 @@ use crate::{

use system_error::SystemError;

use super::kset::KSet;
use super::{kset::KSet, uevent::kobject_uevent};

pub trait KObject: Any + Send + Sync + Debug + CastFromSync {
fn as_any_ref(&self) -> &dyn core::any::Any;
Expand Down Expand Up @@ -104,9 +105,7 @@ bitflags! {
const REMOVE_UEVENT_SENT = 1 << 2;
const INITIALIZED = 1 << 3;
}

}

#[derive(Debug)]
pub struct LockedKObjectState(RwLock<KObjectState>);

Expand Down Expand Up @@ -252,7 +251,7 @@ impl KObjectManager {
}

// todo: 发送uevent: KOBJ_REMOVE

// kobject_uevent();
sysfs_instance().remove_dir(&kobj);
kobj.update_kobj_state(None, Some(KObjectState::IN_SYSFS));
let kset = kobj.kset();
Expand All @@ -261,6 +260,70 @@ impl KObjectManager {
}
kobj.set_parent(None);
}

fn get_kobj_path_length(kobj: &Arc<dyn KObject>) -> usize {
let mut length = 1;
let mut parent = kobj.parent().unwrap().upgrade().unwrap();
/* walk up the ancestors until we hit the one pointing to the
* root.
* Add 1 to strlen for leading '/' of each level.
*/
loop {
if parent.name().is_empty() {
break;
}
length += parent.name().len() + 1;
if let Some(weak_parent) = parent.parent() {
parent = weak_parent.upgrade().unwrap();
}
}
return length;
}

/*
static void fill_kobj_path(struct kobject *kobj, char *path, int length)
{
struct kobject *parent;

--length;
for (parent = kobj; parent; parent = parent->parent) {
int cur = strlen(kobject_name(parent));
/* back up enough to print this name with '/' */
length -= cur;
memcpy(path + length, kobject_name(parent), cur);
*(path + --length) = '/';
}

pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
kobj, __func__, path);
}
*/
fn fill_kobj_path(kobj: &Arc<dyn KObject>, path: *mut u8, length: usize) {
let mut parent = kobj.parent().unwrap().upgrade().unwrap();
let mut length = length;
length -= 1;
loop {
let cur = parent.name().len();
length -= cur;
unsafe {
core::ptr::copy_nonoverlapping(parent.name().as_ptr(), path.add(length), cur);
*path.add(length - 1) = b'/';
}
if let Some(weak_parent) = parent.parent() {
parent = weak_parent.upgrade().unwrap();
}
}
}
// TODO: 实现kobject_get_path
// https://code.dragonos.org.cn/xref/linux-6.1.9/lib/kobject.c#139
pub fn kobject_get_path(kobj: &Arc<dyn KObject>) -> String {
let length = Self::get_kobj_path_length(kobj);
let path_raw = vec![0u8; length].into_boxed_slice();
let path = Box::into_raw(path_raw) as *mut u8;
Self::fill_kobj_path(kobj, path, length);
let path_string = unsafe { String::from_raw_parts(path, length, length) };
path_string
}
}

/// 动态创建的kobject对象的ktype
Expand Down
34 changes: 32 additions & 2 deletions kernel/src/driver/base/kset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use alloc::{

use core::hash::Hash;

use super::kobject::{
DynamicKObjKType, KObjType, KObject, KObjectManager, KObjectState, LockedKObjectState,
use super::{
kobject::{
DynamicKObjKType, KObjType, KObject, KObjectManager, KObjectState, LockedKObjectState,
},
uevent::KobjUeventEnv,
};
use crate::{
filesystem::kernfs::KernFSInode,
Expand All @@ -26,6 +29,8 @@ pub struct KSet {
/// 与父节点有关的一些信息
parent_data: RwLock<KSetParentData>,
self_ref: Weak<KSet>,
/// kset用于发送uevent的操作函数集。kset能够发送它所包含的各种子kobj、孙kobj的消息,即kobj或其父辈、爷爷辈,都可以发送消息;优先父辈,然后是爷爷辈,以此类推
pub uevent_ops: Option<Arc<dyn KSetUeventOps>>,
}

impl Hash for KSet {
Expand All @@ -51,6 +56,7 @@ impl KSet {
kobj_state: LockedKObjectState::new(None),
parent_data: RwLock::new(KSetParentData::new(None, None)),
self_ref: Weak::default(),
uevent_ops: Some(Arc::new(KSetUeventOpsDefault)),
};

let r = Arc::new(r);
Expand Down Expand Up @@ -91,6 +97,7 @@ impl KSet {
pub fn register(&self, join_kset: Option<Arc<KSet>>) -> Result<(), SystemError> {
return KObjectManager::add_kobj(self.self_ref.upgrade().unwrap(), join_kset);
// todo: 引入uevent之后,发送uevent
// kobject_uevent();
}

/// 注销一个kset
Expand Down Expand Up @@ -232,3 +239,26 @@ impl InnerKSet {
}
}
}
//https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/kobject.h#137
use core::fmt::Debug;
pub trait KSetUeventOps: Debug + Send + Sync {
fn filter(&self) -> Option<i32>;
fn uevent_name(&self) -> String;
fn uevent(&self, env: &KobjUeventEnv) -> i32;
}
#[derive(Debug)]
pub struct KSetUeventOpsDefault;

impl KSetUeventOps for KSetUeventOpsDefault {
fn filter(&self) -> Option<i32> {
Some(0)
}

fn uevent_name(&self) -> String {
String::new()
}

fn uevent(&self, env: &KobjUeventEnv) -> i32 {
0
}
}
1 change: 1 addition & 0 deletions kernel/src/driver/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pub mod map;
pub mod platform;
pub mod subsys;
pub mod swnode;
pub mod uevent;
Loading
Loading