Skip to content

opengl: add /usr/share/nvidia #12840

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

Merged
merged 15 commits into from
Feb 15, 2024
Merged

Conversation

ZoopOTheGoop
Copy link
Contributor

This allows access to /usr/share/nvidia in the opengl plug. Nvidia apparently requests this be available in containers as per discussion in #12794

@codecov-commenter
Copy link

codecov-commenter commented May 23, 2023

Codecov Report

Attention: 28 lines in your changes are missing coverage. Please review.

Comparison is base (54a3194) 78.69% compared to head (d415854) 78.88%.
Report is 555 commits behind head on master.

Files Patch % Lines
osutil/kcmdline/kcmdline.go 67.74% 19 Missing and 1 partial ⚠️
interfaces/builtin/opengl.go 86.04% 4 Missing and 2 partials ⚠️
boot/cmdline.go 50.00% 1 Missing ⚠️
bootloader/grub.go 0.00% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12840      +/-   ##
==========================================
+ Coverage   78.69%   78.88%   +0.18%     
==========================================
  Files        1001     1031      +30     
  Lines      124257   130948    +6691     
==========================================
+ Hits        97788   103302    +5514     
- Misses      20316    21216     +900     
- Partials     6153     6430     +277     
Flag Coverage Δ
unittests 78.88% <79.56%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mvo5 mvo5 added the Needs security review Can only be merged once security gave a :+1: label May 24, 2023
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

The rule itself seems fine but will it work in the expected way? The path /usr/share/nvidia will be the path inside the mount namespace which will have the coreXX dirs under /usr/share and not the host system dirs? But maybe I'm missing something?

@ZoopOTheGoop
Copy link
Contributor Author

No you're right I forgot to do a mount of the host fs, need to find where to do that

@ZoopOTheGoop
Copy link
Contributor Author

finally got it working, change was more minor than I had thought

Copy link
Contributor

@jhenstridge jhenstridge left a comment

Choose a reason for hiding this comment

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

I think you're going to need additional code to add a spec.AddUpdateNSf call so that snap-update-ns's AppArmor profile will allow it to perform this mount.

We should also test that this works in the spread tests. I'd suggest updating tests/main/interfaces-opengl-nvidia/task.yaml to do:

  • Create the /usr/share/nvidia directory in the prepare step, and add a file inside named as you'd expect the quirks json to be named.
  • In the execute step, check that the gl-core16 snap can read the file from its sandbox.
  • Remove the directory in the restore step.

@ZoopOTheGoop
Copy link
Contributor Author

I'm not sure if I got the tests right, but the changes requested should be done modulo that. I had tested the plug in the steam snap where it worked presumably due to steam interface rules compounding with the opengl rules, but the AddUpdateNSf stuff was necessary for a test snap that only had the opengl plug.

Copy link
Contributor

@jhenstridge jhenstridge left a comment

Choose a reason for hiding this comment

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

This is looking a lot closer to ready. The spread test needs some changes though, since it's not actually testing whether the paths are accessible within the sandbox.

Copy link
Contributor

@jhenstridge jhenstridge left a comment

Choose a reason for hiding this comment

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

It looks like the spread tests are in as good a state as we can expect.

There's one last change, and I think the branch will be ready to go: please update the opengl_test.go unit tests to:

  1. in the AppArmor test, check that spec.UpdateNS() includes the rules letting snap-update-ns mount /usr/share/nvidia.
  2. Add a TestMountSpec test that demonstrates that the interface adds the mount rules.

You can use the tests in desktop_test.go as a guide for what these should look like.

Copy link
Contributor

@jhenstridge jhenstridge left a comment

Choose a reason for hiding this comment

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

With these last tweaks to the unit tests, I think the branch will be ready.

Copy link
Contributor

@jhenstridge jhenstridge left a comment

Choose a reason for hiding this comment

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

Looks good!

@pedronis pedronis added this to the 2.61 milestone Sep 7, 2023
Copy link
Contributor

@alexmurray alexmurray left a comment

Choose a reason for hiding this comment

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

LGTM!

@alexmurray alexmurray removed the Needs security review Can only be merged once security gave a :+1: label Sep 14, 2023
@mvo5 mvo5 modified the milestones: 2.61, 2.62 Oct 4, 2023
@mvo5 mvo5 requested review from pedronis and removed request for mvo5 October 12, 2023 11:19
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

the addition to dirs.go seems a bit unwarranted, there's already a bit too many things there already as it is and interfaces usually don't add to it

dirs/dirs.go Outdated
@@ -115,6 +115,8 @@ var (
SnapDeviceSaveDir string
SnapDataSaveDir string

NvidiaProfilesDir string
Copy link
Collaborator

Choose a reason for hiding this comment

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

we probably shouldn't define this here, but simply compute what we need in opengl.go

@pedronis pedronis self-assigned this Oct 13, 2023
@zyga zyga self-requested a review February 1, 2024 10:36
This avoids making the crowded surface of dirs.go even larger. Tweak the code
to differentiate between /usr/share/nvidia in the host and in the per-snap
mount namespace.

Signed-off-by: Zygmunt Krynicki <[email protected]>
@zyga
Copy link
Contributor

zyga commented Feb 1, 2024

@ZoopOTheGoop @pedronis I've pushed an update that removes the change from dirs.go while retaining the semantics. I've adjusted the code in opengl.go a little, to make the mount namespace manipulation clearer by making a distinction between paths in host mount namespace and that of the snap application. Have look please.

Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

LGTM with a little naming tweak

@@ -172,6 +185,10 @@ unix (bind,listen) type=seqpacket addr="@cuda-uvmfd-[0-9a-f]*",
unix (send, receive) type=dgram peer=(addr="@var/run/nvidia-xdriver-*"),
`

type openGlInterface struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type openGlInterface struct {
type openglInterface struct {

to be consistent with rest of the names used in this file

@zyga
Copy link
Contributor

zyga commented Feb 9, 2024

I will refrain from self-reviewing this but I think it is good to merge.

@Meulengracht Meulengracht requested a review from pedronis February 9, 2024 09:35
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thanks

@Meulengracht Meulengracht merged commit a1703df into canonical:master Feb 15, 2024
fredldotme pushed a commit to fredldotme/snapd that referenced this pull request Mar 2, 2024
* add mount rules to opengl plug

* properly allow mounts in apparmor

* add tests for /usr/share/nvidia

* update tests

* generate apparmor rules properly

* fix file naming in tests

* unit tests

* fix tests without /usr/share/nvidia

* add TearDownTest

* fix apparmor test dir ordering

* convert back to raw string

* remove superfluous characters

* i/builtin: move /usr/share/nvidia to opengl internals

This avoids making the crowded surface of dirs.go even larger. Tweak the code
to differentiate between /usr/share/nvidia in the host and in the per-snap
mount namespace.

Signed-off-by: Zygmunt Krynicki <[email protected]>

* i/builtin: rename openGlInterface to openglInterface

Signed-off-by: Zygmunt Krynicki <[email protected]>

* tests: add details to tests/main/interfaces-opengl-nvidia/task.yaml

Signed-off-by: Zygmunt Krynicki <[email protected]>

---------

Signed-off-by: Zygmunt Krynicki <[email protected]>
Co-authored-by: Zygmunt Krynicki <[email protected]>
fredldotme pushed a commit to fredldotme/snapd that referenced this pull request Jun 4, 2024
* add mount rules to opengl plug

* properly allow mounts in apparmor

* add tests for /usr/share/nvidia

* update tests

* generate apparmor rules properly

* fix file naming in tests

* unit tests

* fix tests without /usr/share/nvidia

* add TearDownTest

* fix apparmor test dir ordering

* convert back to raw string

* remove superfluous characters

* i/builtin: move /usr/share/nvidia to opengl internals

This avoids making the crowded surface of dirs.go even larger. Tweak the code
to differentiate between /usr/share/nvidia in the host and in the per-snap
mount namespace.

Signed-off-by: Zygmunt Krynicki <[email protected]>

* i/builtin: rename openGlInterface to openglInterface

Signed-off-by: Zygmunt Krynicki <[email protected]>

* tests: add details to tests/main/interfaces-opengl-nvidia/task.yaml

Signed-off-by: Zygmunt Krynicki <[email protected]>

---------

Signed-off-by: Zygmunt Krynicki <[email protected]>
Co-authored-by: Zygmunt Krynicki <[email protected]>
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.

9 participants