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

dragonball: add pci root bus and root device #8564

Merged

Conversation

studychao
Copy link
Member

In order to follow up the PCI implementation in Dragonball, we need to add PCI root device and root bus support.

root device is a pseudo PCI root device to manage accessing to PCI configuration space.

root bus is mainly for emulating PCI root bridge and also create the PCI root bus with the given bus ID with the PCI root bridge.

fixes: #8563

Signed-off-by: Gerry Liu gerry@linux.alibaba.com
Signed-off-by: Zizheng Bian zizheng.bian@linux.alibaba.com
Signed-off-by: Shifang Feng fengshifang@linux.alibaba.com
Signed-off-by: Yang Su yang.su@linux.alibaba.com
Signed-off-by: Zha Bin zhabin@linux.alibaba.com
Signed-off-by: Xin Lin jingshan@linux.alibaba.com
Signed-off-by: Chao Wu chaowu@linux.alibaba.com

@katacontainersbot katacontainersbot added the size/huge Largest and most complex task (probably needs breaking into small pieces) label Dec 5, 2023
@@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0

use std::any::Any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's no compile warning check in CI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug in Dragonball CI and I have fixed it in #8599

@@ -30,22 +30,34 @@ mod bus;
mod configuration;
mod device;

pub use self::bus::PciBus;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change the style like below?

mod xxx;
pub use xxx:yyy;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.


use crate::fill_config_data;
use crate::{Error, PciBus, Result};
#[derive(PartialEq)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a blank line here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Member

@justxuewei justxuewei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @studychao! A few comments here.

let state = self.state.read().unwrap();
let (b, d, f, o) = parse_mmio_address(offset);
if let Some(bus) = state.buses.get(&b) {
return bus.read_config(d, f, o | ((offset as u32) & 0x3), data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you set a const for 0x3 to describe what it is? Or leave some comments here.

Copy link
Member Author

@studychao studychao Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out that 0x3 is useless in this method because parse_mmio_address will use the lowest 12 bits, so I remove them from the code.

let state = self.state.read().unwrap();
let (b, d, f, o) = parse_mmio_address(offset);
if let Some(bus) = state.buses.get(&b) {
return bus.write_config(d, f, o | (offset as u32 & 0x3), data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

let len = data.len();

// Only allow naturally aligned Dword, Word and Byte access.
if (len == 4 || len == 2 || len == 1) && offset as usize & (len - 1) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap this into an inline function? It is used three times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, actually it is used four times lol

let offset = offset.raw_value();
let len = data.len();

if (len == 4 || len == 2 || len == 1) && offset as usize & (len - 1) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

let len = data.len();

// Only allow naturally aligned Dword, Word and Byte access.
if (len == 4 || len == 2 || len == 1) && offset as usize & (len - 1) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines 286 to 301
let shift = (offset & 0x3) * 8;
if len == 4 {
state.io_addr = NativeEndian::read_u32(data);
} else if len == 2 {
state.io_addr &= !(0xffffu32 << shift);
state.io_addr |= u32::from(NativeEndian::read_u16(data)) << shift;
} else {
state.io_addr &= !(0xffu32 << shift);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of hard code here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments all added.

4..=7 => {
// Safe to unwrap because no legal to generate poisoned RwLock.
let state = self.state.read().unwrap();
if state.io_addr & 0x8000_0000 != 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard code again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment added.

bus_number,
device_number,
function_number,
register_number & !0x3u32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document added.

Comment on lines 360 to 383
(addr >> 20) & 0xff,
(addr >> 15) & 0x1f,
(addr >> 12) & 0x7,
addr & 0xfff,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const added.

@@ -324,8 +322,8 @@ impl PartialEq for PciBus {

#[inline]
fn check_pci_cfg_valid(dev: u32, func: u32, offset: u32, data_len: usize) -> bool {
dev > 0x1f || func !=0 || offset >= 0x1000 || offset & (data_len - 1 ) as u32 & 0x3 != 0
}
dev > 0x1f || func != 0 || offset >= 0x1000 || offset & (data_len - 1) as u32 & 0x3 != 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave some comments here?

Copy link
Contributor

@liubogithub liubogithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

In order to follow up the PCI implementation in Dragonball, we need to
add PCI root device and root bus support.

root device is a pseudo PCI root device to manage accessing to PCI
configuration space.

root bus is mainly for emulating PCI root bridge and also create the PCI
root bus with the given bus ID with the PCI root bridge.

fixes: kata-containers#8563

Signed-off-by: Gerry Liu <gerry@linux.alibaba.com>
Signed-off-by: Zizheng Bian <zizheng.bian@linux.alibaba.com>
Signed-off-by: Shifang Feng <fengshifang@linux.alibaba.com>
Signed-off-by: Yang Su <yang.su@linux.alibaba.com>
Signed-off-by: Zha Bin <zhabin@linux.alibaba.com>
Signed-off-by: Xin Lin <jingshan@linux.alibaba.com>
Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
Copy link
Contributor

@ZizhengBian ZizhengBian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@justxuewei justxuewei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, thanks!

@studychao
Copy link
Member Author

/test

@studychao
Copy link
Member Author

/test-arm

@studychao studychao merged commit dfaf006 into kata-containers:main Dec 13, 2023
170 of 181 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test runtime-rs size/huge Largest and most complex task (probably needs breaking into small pieces)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dragonball: pci root device and root bus support
6 participants