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

krun: create context after loading the library #1695

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

slp
Copy link
Contributor

@slp slp commented Mar 19, 2025

Newer versions of libkrun no longer link against libkrunfw (the library bundling the kernel) and, instead, they load it dynamically when creating the context.

This implies we need to call krun_create_ctx ealier, before switching namespaces, or libkrun won't be able to find libkrunfw.

Copy link
Member

@rhatdan rhatdan left a comment

Choose a reason for hiding this comment

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

LGTM
@giuseppe @flouthoc PTAL

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM

@siteshwar
Copy link

siteshwar commented Mar 19, 2025

You may want to remove this variable as its not used:

Error: COMPILER_WARNING (CWE-563): [#def1]
crun-1.20-build/crun-HEAD/src/libcrun/handlers/krun.c: scope_hint: In function 'libkrun_exec'
crun-1.20-build/crun-HEAD/src/libcrun/handlers/krun.c:90:11: warning[-Wunused-but-set-variable]: variable 'ctx_id' set but not used
#   90 |   int32_t ctx_id, ret;
#      |           ^~~~~~
#   88|     void *handle;
#   89|     uint32_t num_vcpus, ram_mib;
#   90|->   int32_t ctx_id, ret;
#   91|     cpu_set_t set;
#   92|   

@slp slp force-pushed the krun-create-ctx branch from 4f080f3 to 7cfd931 Compare March 19, 2025 17:42
@slp
Copy link
Contributor Author

slp commented Mar 19, 2025

You may want to remove this variable as its not used:

Error: COMPILER_WARNING (CWE-563): [#def1]
crun-1.20-build/crun-HEAD/src/libcrun/handlers/krun.c: scope_hint: In function 'libkrun_exec'
crun-1.20-build/crun-HEAD/src/libcrun/handlers/krun.c:90:11: warning[-Wunused-but-set-variable]: variable 'ctx_id' set but not used
#   90 |   int32_t ctx_id, ret;
#      |           ^~~~~~
#   88|     void *handle;
#   89|     uint32_t num_vcpus, ram_mib;
#   90|->   int32_t ctx_id, ret;
#   91|     cpu_set_t set;
#   92|   

This wonderful warning has actually detected a bug. I was always using the same ctx_id for both krun and krun-sev. This works because they happen to return the same integer, but was wrong. I've just fixed it, thanks!

@siteshwar
Copy link

You may want to remove this variable as its not used:

Error: COMPILER_WARNING (CWE-563): [#def1]
crun-1.20-build/crun-HEAD/src/libcrun/handlers/krun.c: scope_hint: In function 'libkrun_exec'
crun-1.20-build/crun-HEAD/src/libcrun/handlers/krun.c:90:11: warning[-Wunused-but-set-variable]: variable 'ctx_id' set but not used
#   90 |   int32_t ctx_id, ret;
#      |           ^~~~~~
#   88|     void *handle;
#   89|     uint32_t num_vcpus, ram_mib;
#   90|->   int32_t ctx_id, ret;
#   91|     cpu_set_t set;
#   92|   

This wonderful warning has actually detected a bug. I was always using the same ctx_id for both krun and krun-sev. This works because they happen to return the same integer, but was wrong. I've just fixed it, thanks!

No problems! In the future, please keep an eye on the osh-diff-scan check in the CI.

@slp slp force-pushed the krun-create-ctx branch 2 times, most recently from 3586302 to a80c2e4 Compare March 20, 2025 12:31
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

Thanks!

LGTM

@giuseppe
Copy link
Member

@eriksjolund PTAL, if you are fine with the new version, I'll merge it


krun_create_ctx = dlsym (handle, "krun_create_ctx");
if (krun_create_ctx == NULL)
return crun_make_error (err, 0, "could not find symbol in `libkrun.so`");
Copy link
Contributor

Choose a reason for hiding this comment

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

libkrun.so might sometimes be libkrun-sev.so in the error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be reasonable to remove the .so to avoid inferring we're talking about that specific library, or do we need it to point to the right library?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can just change the error message in the krun library, or something like that

Newer versions of libkrun no longer link against libkrunfw (the
library bundling the kernel) and, instead, they load it dynamically
when creating the context.

This implies we need to call krun_create_ctx ealier, before
switching namespaces, or libkrun won't be able to find libkrunfw.

Signed-off-by: Sergio Lopez <[email protected]>
@slp slp force-pushed the krun-create-ctx branch from a80c2e4 to 8675baf Compare March 20, 2025 13:27
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@eriksjolund
Copy link
Contributor

lgtm

@giuseppe giuseppe merged commit 4284382 into containers:main Mar 20, 2025
35 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants