Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
prekucki committed Aug 20, 2024
2 parents 3bf5bf2 + 2c800d6 commit a079f6e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ jobs:
VERSION=${TAGV_NAME#v}
echo "::set-output name=tagv::${TAG_NAME}"
echo "::set-output name=version::${VERSION}"
- uses: golemfactory/build-deb-action@v4
- uses: golemfactory/build-deb-action@v0.6
id: deb
with:
debVersion: ${{ steps.version.outputs.version }}
Expand Down
28 changes: 25 additions & 3 deletions runtime/init-container/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,23 @@ static int find_device_major(const char *name) {
return major;
}

static int nvidia_gpu_count() {
int counter;
int res;
char buf[sizeof "sys/class/drm/card000"];

for (counter = 0; counter < 256; counter++) {
res = snprintf(buf, sizeof buf, "sys/class/drm/card%d", counter);
CHECK_BOOL(res > 0);
CHECK_BOOL(res < (int)sizeof buf);
/* iterate as long as devices are there, nothing unloads/unbinds
* devices so there should be no holes in numbering */
if (faccessat(g_sysroot_fd, buf, F_OK, 0) != 0)
break;
}
return counter;
}

int main(int argc, char **argv) {
CHECK_BOOL(setvbuf(stdin, NULL, _IONBF, BUFSIZ) == 0);
CHECK_BOOL(setvbuf(stdout, NULL, _IONBF, BUFSIZ) == 0);
Expand Down Expand Up @@ -2232,16 +2249,21 @@ int main(int argc, char **argv) {
}

if (nvidia_loaded) {
char buf[sizeof "dev/nvidia000"];
if (do_sandbox == false) {
fprintf(stderr, "Sandboxing is disabled, refusing to enable Nvidia GPU passthrough.\n");
fprintf(stderr, "Please re-run the container with sandboxing enabled or disable GPU passthrough.\n");
errno = 0;
CHECK_BOOL(0);
}
int nvidia_major = CHECK(find_device_major("nvidia-frontend"));
/* TODO: multi-card support needs more /dev/nvidia%d nodes */
res = mknodat(g_sysroot_fd, "dev/nvidia0", S_IFCHR | (0666 & 0777), nvidia_major << 8 | 0);
CHECK_BOOL(res == 0 || (res == -1 && errno == EEXIST));
int nvidia_count = nvidia_gpu_count();
for (int i = 0; i < nvidia_count; i++) {
res = snprintf(buf, sizeof buf, "dev/nvidia%d", i);
CHECK_BOOL(res >= (int)sizeof "dev/nvidia" && res < (int)sizeof buf);
res = mknodat(g_sysroot_fd, buf, S_IFCHR | (0666 & 0777), nvidia_major << 8 | i);
CHECK_BOOL(res == 0 || (res == -1 && errno == EEXIST));
}
res = mknodat(g_sysroot_fd, "dev/nvidiactl", S_IFCHR | (0666 & 0777), nvidia_major << 8 | 255);
CHECK_BOOL(res == 0 || (res == -1 && errno == EEXIST));
nvidia_major = CHECK(find_device_major("nvidia-uvm"));
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct Cli {
inet_endpoint: Option<Url>,
/// PCI device identifier
#[structopt(long, env = "YA_RUNTIME_VM_PCI_DEVICE")]
pci_device: Option<String>,
pci_device: Option<Vec<String>>,
#[structopt(flatten)]
test_config: TestConfig,
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/self_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const FILE_TEST_IMAGE: &str = "self-test.gvmi";
const FILE_TEST_EXECUTABLE: &str = "ya-self-test";

pub(crate) async fn test(
pci_device_id: Option<String>,
pci_device_id: Option<Vec<String>>,
test_config: TestConfig,
) -> Result<(), Error> {
run_self_test(verify_status, pci_device_id, test_config).await;
Expand All @@ -38,7 +38,7 @@ pub(crate) fn verify_status(status: anyhow::Result<Value>) -> anyhow::Result<Str

pub(crate) async fn run_self_test<HANDLER>(
handle_result: HANDLER,
pci_device_id: Option<String>,
pci_device_id: Option<Vec<String>>,
test_config: TestConfig,
) where
HANDLER: Fn(anyhow::Result<Value>) -> anyhow::Result<String>,
Expand Down Expand Up @@ -108,7 +108,7 @@ pub(crate) async fn run_self_test<HANDLER>(
.await;
}

fn self_test_runtime(deployment: Deployment, pci_device_id: Option<String>) -> Runtime {
fn self_test_runtime(deployment: Deployment, pci_device_id: Option<Vec<String>>) -> Runtime {
let runtime_data = RuntimeData {
deployment: Some(deployment),
pci_device_id,
Expand Down
8 changes: 5 additions & 3 deletions runtime/src/vmrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct RuntimeData {
pub inet: Option<ContainerEndpoint>,
pub deployment: Option<Deployment>,
pub ga: Option<Arc<Mutex<GuestAgent>>>,
pub pci_device_id: Option<String>,
pub pci_device_id: Option<Vec<String>>,
}

impl RuntimeData {
Expand Down Expand Up @@ -109,8 +109,10 @@ pub async fn start_vmrt(
]);

if let Some(pci_device_id) = &data.pci_device_id {
cmd.arg("-device");
cmd.arg(format!("vfio-pci,host={}", pci_device_id).as_str());
for device_id in pci_device_id.iter() {
cmd.arg("-device");
cmd.arg(format!("vfio-pci,host={}", device_id).as_str());
}
} else {
cmd.arg("-vga");
cmd.arg("none");
Expand Down

0 comments on commit a079f6e

Please sign in to comment.