Skip to content

Conversation

marquiz
Copy link
Contributor

@marquiz marquiz commented Aug 1, 2025

The linux.intelRdt.enableMonitoring field enables the creation of a per-container monitoring group. The monitoring group is removed when the container is destroyed.

Refs: opencontainers/runtime-spec#1287

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch 4 times, most recently from 520aadd to d141fb0 Compare August 4, 2025 14:18
@@ -474,6 +474,16 @@ func (m *Manager) Apply(pid int) (err error) {
return newLastCmdError(err)
}

// Create MON group
if monPath := m.GetMonPath(); monPath != "" {
if err := os.MkdirAll(monPath, 0o755); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Where is this path? Inside the container? On the host?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is on the host (now changed to Mkdir)

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch 3 times, most recently from 169609d to 4024488 Compare August 6, 2025 06:55
@marquiz
Copy link
Contributor Author

marquiz commented Aug 6, 2025

Review comments from @rata addressed. Rebased. Submitted the first commit as a separate PR (#4840), too

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch 2 times, most recently from 86329fe to 2380794 Compare August 7, 2025 19:06
@marquiz
Copy link
Contributor Author

marquiz commented Aug 7, 2025

Rebased

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch 2 times, most recently from e31d98c to 4af20b5 Compare August 18, 2025 11:32
@marquiz
Copy link
Contributor Author

marquiz commented Aug 18, 2025

Updated:

  • rebased
  • go.mod: bumped runtime-spec to latest tip of the main branch
  • features.go: set linux.intelRdt.monitoring to true

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch 2 times, most recently from fd132e2 to 4e43d65 Compare August 26, 2025 17:23
@marquiz
Copy link
Contributor Author

marquiz commented Aug 26, 2025

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

Please remove the fmt.Println() lines

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch from 4e43d65 to 2fbcde5 Compare August 27, 2025 12:44
@@ -478,6 +478,16 @@ func (m *Manager) Apply(pid int) (err error) {
return newLastCmdError(err)
}

// Create MON group
if monPath := m.GetMonPath(); monPath != "" {
if err := os.Mkdir(monPath, 0o755); err != nil && !os.IsExist(err) {
Copy link
Member

Choose a reason for hiding this comment

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

Who has control of this path? In runc this is trusted, okay, but is it exposed in k8s or containerd or some other to the user?

Not sure with the https://github.com/intel/k8s-rdt-controller what is exposed to an end user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's runc, it's in this very same file (and patch):

func (m *Manager) GetMonPath() string {
	if closPath := m.GetPath(); closPath != "" && m.config.IntelRdt.EnableMonitoring {
		path, err := securejoin.SecureJoin(filepath.Join(closPath, "mon_groups"), m.id)

So it's basically <clos-dir>/mon_groups/<container-id>

Copy link
Member

@rata rata Aug 28, 2025

Choose a reason for hiding this comment

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

Thanks, and that comes from intelRdtRoot. But where does that come from? Is there any way an unprivileged user (or just anyone that is not the sysadmin or so) can control any path component (or the intelRDT root)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That, in turn, comes from parsing the output of statfs syscall (unix.Statfs()). Note that in the case of runc update the closPath is taken from the config.json of the container.

In any case I cannot see any way that an unprivileged user can control the path

Copy link
Member

Choose a reason for hiding this comment

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

So statfs will have some string value and we will mkdir it on the host, outside of the container rootfs?

Copy link
Member

Choose a reason for hiding this comment

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

This conversation was broken out of this thread, it continued in the main PR discussion. The final answer I found for this is posted here: #4832 (comment)

Basically, the fs will be mounted somewhere on the host by the admin and we might create/delete some dirs inside that. None of that is accessible to the container process.

@marquiz correct me if I'm getting something wrong.

Copy link
Member

Choose a reason for hiding this comment

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

@kolyshkin PTAL, I'd like someone else to look at this part too, just in case I'm missing something :)

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch from 2fbcde5 to abafdf8 Compare August 29, 2025 10:31
@marquiz
Copy link
Contributor Author

marquiz commented Aug 29, 2025

Rebased (see if the unrelated linter errors go away...)

@@ -478,6 +478,16 @@ func (m *Manager) Apply(pid int) (err error) {
return newLastCmdError(err)
}

// Create MON group
if monPath := m.GetMonPath(); monPath != "" {
if err := os.Mkdir(monPath, 0o755); err != nil && !os.IsExist(err) {
Copy link
Member

Choose a reason for hiding this comment

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

So statfs will have some string value and we will mkdir it on the host, outside of the container rootfs?

@marquiz
Copy link
Contributor Author

marquiz commented Aug 29, 2025

So statfs will have some string value and we will mkdir it on the host, outside of the container rootfs?

Yes the data comes from the Linux kernel. See statfs syscall, e.g. https://man7.org/linux/man-pages/man2/statfs.2.html

@rata
Copy link
Member

rata commented Sep 2, 2025

@marquiz that manpage doesn't tell anything about intelrdt :-). But ok, I guess you need to mount the restctrl fs like shown here and therefore the host admin decides where it is mounted, no container will have write access to any file/dir there, I guess.

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

This mostly LGTM. But let's use the well-known table tests (or are you avoiding them for a reason?)

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch from abafdf8 to dac3655 Compare September 3, 2025 14:33
@marquiz
Copy link
Contributor Author

marquiz commented Sep 3, 2025

Updated, review comments addressed

@rata @kolyshkin

@rata rata self-requested a review September 3, 2025 15:05
@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch 2 times, most recently from ce987d5 to 88604c3 Compare September 3, 2025 18:32
@marquiz
Copy link
Contributor Author

marquiz commented Sep 3, 2025

Updated @rata

Signed-off-by: Markus Lehtonen <[email protected]>
@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch from 88604c3 to c0415e2 Compare September 3, 2025 20:56
@marquiz
Copy link
Contributor Author

marquiz commented Sep 3, 2025

Rebased to resolve conflicts

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

Sorry I didn't check the tests before. Let's improve and reduce the c&p. Let's make it more standard golang table-tests.

defer m.mu.Unlock()
if err := os.Remove(m.GetPath()); err != nil && !os.IsNotExist(err) {
return err
if m.config.IntelRdt != nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Let's do a quick return if intelRdt is nil and remove the indentation for the rest of the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as suggested

Comment on lines 116 to 118
closPath := filepath.Join(intelRdtRoot, closID)
intelrdt := newManager(helper.config, "", closPath)
if err := intelrdt.Apply(1234); err == nil {
t.Fatal("unexpected success when applying pid")
}
Copy link
Member

Choose a reason for hiding this comment

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

It seems this can be part of the for ... range tests loop,a s it's c&p in every testFunc(). Yes, one needs a slightly different param, but that can be part of the test struct, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests refactored

Comment on lines 219 to 231
helper.config.IntelRdt = &configs.IntelRdt{
ClosID: closID,
}

closPath := filepath.Join(intelRdtRoot, closID)
if err := os.MkdirAll(closPath, 0o755); err != nil {
t.Fatal(err)
}

intelrdt := newManager(helper.config, "container-1", closPath)
if err := intelrdt.Apply(1234); err != nil {
t.Fatalf("Apply() failed: %v", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

idem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored

@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch from c0415e2 to d7032f0 Compare September 4, 2025 14:00
The linux.intelRdt.enableMonitoring field enables the creation of
a per-container monitoring group. The monitoring group is removed when
the container is destroyed.

Signed-off-by: Markus Lehtonen <[email protected]>
@marquiz marquiz force-pushed the devel/rdt-enablemonitoring branch from d7032f0 to 19e2d0a Compare September 4, 2025 14:58
@marquiz
Copy link
Contributor Author

marquiz commented Sep 4, 2025

Updated: test refactored

@rata @kolyshkin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants