From 6725ca10ab4710a79b29ab2e0098e352b8dbcec8 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Wed, 20 Mar 2019 19:04:07 +0800 Subject: [PATCH] Fix IXGBE driver with drop and update user with working userland networking --- kernel/Cargo.lock | 4 +++- kernel/src/arch/x86_64/consts.rs | 2 +- kernel/src/drivers/net/ixgbe.rs | 19 +++++++++++++++++-- user | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index bf16e11..6761aa4 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -196,6 +196,7 @@ dependencies = [ [[package]] name = "isomorphic_drivers" version = "0.1.0" +source = "git+https://github.com/rcore-os/isomorphic_drivers#4a6546922bc5b1255631840f63d6b8b595b39de9" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -315,7 +316,7 @@ dependencies = [ "console-traits 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "device_tree 1.0.3 (git+https://github.com/rcore-os/device_tree-rs)", "heapless 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "isomorphic_drivers 0.1.0", + "isomorphic_drivers 0.1.0 (git+https://github.com/rcore-os/isomorphic_drivers)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "once 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -611,6 +612,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum hash32 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12d790435639c06a7b798af9e1e331ae245b7ef915b92f70a39b4cf8c00686af" "checksum heapless 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "56b960caff1a46f1fb3c1eb05f0575ac21c6248364ebebde11b11116e099881c" +"checksum isomorphic_drivers 0.1.0 (git+https://github.com/rcore-os/isomorphic_drivers)" = "" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" diff --git a/kernel/src/arch/x86_64/consts.rs b/kernel/src/arch/x86_64/consts.rs index 0534ef1..7543779 100644 --- a/kernel/src/arch/x86_64/consts.rs +++ b/kernel/src/arch/x86_64/consts.rs @@ -23,7 +23,7 @@ pub const KERNEL_SIZE: usize = PML4_SIZE; pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE; pub const KERNEL_HEAP_PML4: usize = (KERNEL_HEAP_OFFSET & PML4_MASK) / PML4_SIZE; /// Size of kernel heap -pub const KERNEL_HEAP_SIZE: usize = 64 * 1024 * 1024; // 64 MB +pub const KERNEL_HEAP_SIZE: usize = 32 * 1024 * 1024; // 32 MB pub const MEMORY_OFFSET: usize = 0; diff --git a/kernel/src/drivers/net/ixgbe.rs b/kernel/src/drivers/net/ixgbe.rs index d53910f..17ba90a 100644 --- a/kernel/src/drivers/net/ixgbe.rs +++ b/kernel/src/drivers/net/ixgbe.rs @@ -25,9 +25,9 @@ use volatile::Volatile; use crate::memory::active_table; use crate::net::SOCKETS; +use crate::sync::FlagsGuard; use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::{MutexGuard, SpinNoIrq}; -use crate::sync::FlagsGuard; use crate::HEAP_ALLOCATOR; use super::super::{provider::Provider, DeviceType, Driver, DRIVERS, NET_DRIVERS, SOCKET_ACTIVITY}; @@ -39,6 +39,21 @@ struct IXGBEDriver { size: usize, } +impl Drop for IXGBEDriver { + fn drop(&mut self) { + let _ = FlagsGuard::no_irq_region(); + let header = self.header; + let size = self.size; + if let None = active_table().get_entry(header) { + let mut current_addr = header; + while current_addr < header + size { + active_table().map_if_not_exists(current_addr, current_addr); + current_addr = current_addr + PAGE_SIZE; + } + } + } +} + pub struct IXGBEInterface { iface: Mutex>, driver: IXGBEDriver, @@ -225,7 +240,7 @@ pub fn ixgbe_init( let ixgbe = ixgbe::IXGBEDriver::init(Provider::new(), header, size); let ethernet_addr = EthernetAddress::from_bytes(&ixgbe.get_mac().as_bytes()); - let net_driver = IXGBEDriver{ + let net_driver = IXGBEDriver { inner: ixgbe, header, size, diff --git a/user b/user index 9484651..fae914b 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit 9484651b977e75d66a56f0f99b3865e424ea8d48 +Subproject commit fae914b11b8de423d3b11f7259db03cf6cdf3d21