Repository navigation
feat: add host PID broker server and device plugin integration #2417
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
hami-robot
merged 21 commits into
Project-HAMi:master
from
iemAnshuman:feat-hostpid-broker-server
Aug 28, 2026
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f792d89
add the host pid broker protocol
iemAnshuman f4e5258
serve host pids over unix sockets
iemAnshuman da40a54
start the host pid broker with the plugin
iemAnshuman 1199ccf
mount the host pid broker for workloads
iemAnshuman 3e6bc91
add the host pid broker chart gate
iemAnshuman 6c1e2bd
harden the host PID broker integration
iemAnshuman a83c20f
test host PID broker allocation response
iemAnshuman de7de73
test: bound partial broker response reads
iemAnshuman 9d61b41
test: verify recorded broker socket identity
iemAnshuman 4778c78
style: group host PID broker imports
iemAnshuman 05a628c
style: group host PID broker test imports
iemAnshuman 9a5b942
fix: retry transient broker accept errors
iemAnshuman 7b05d19
fix: rate limit broker transaction logs
iemAnshuman 9ad27a2
fix: check broker health during plugin startup
iemAnshuman 7c7ae67
docs: update host PID broker status
iemAnshuman 935a6de
test: cover host PID broker lifecycle
iemAnshuman 2a2178e
fix: harden the host PID lock parent
iemAnshuman 24ead56
docs: fix compound modifiers
iemAnshuman 5a41428
test: clarify parent ownership rejection
iemAnshuman 146ee02
test: reset allocation fixtures between paths
iemAnshuman c071efb
resolve conflict
iemAnshuman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The HAMi Authors. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "k8s.io/klog/v2" | ||
|
|
||
| "github.com/Project-HAMi/HAMi/pkg/device-plugin/nvidiadevice/nvinternal/hostpid" | ||
| ) | ||
|
|
||
| type runningHostPIDBroker struct { | ||
| broker *hostpid.Broker | ||
| done chan struct{} | ||
| serveErr error | ||
| } | ||
|
|
||
| func startHostPIDBroker() (*runningHostPIDBroker, error) { | ||
| if !hostpid.Enabled(os.Getenv(hostpid.EnvironmentVariable)) { | ||
| return nil, nil | ||
| } | ||
| broker, err := hostpid.ListenDefault() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| running := &runningHostPIDBroker{ | ||
| broker: broker, | ||
| done: make(chan struct{}), | ||
| } | ||
| go func() { | ||
| running.serveErr = broker.Serve() | ||
| close(running.done) | ||
| }() | ||
| klog.Infof("Host PID broker is listening on %s", hostpid.ServerSocketPath) | ||
| return running, nil | ||
| } | ||
|
|
||
| func (running *runningHostPIDBroker) stop() error { | ||
| closeErr := running.broker.Close() | ||
| <-running.done | ||
| return closeErr | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The HAMi Authors. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/Project-HAMi/HAMi/pkg/device-plugin/nvidiadevice/nvinternal/hostpid" | ||
| ) | ||
|
|
||
| func TestStartHostPIDBrokerDisabled(t *testing.T) { | ||
| for _, value := range []string{"", "0", "true", "false", "01", " 1"} { | ||
| t.Run(value, func(t *testing.T) { | ||
| t.Setenv(hostpid.EnvironmentVariable, value) | ||
| running, err := startHostPIDBroker() | ||
| if err != nil || running != nil { | ||
| t.Fatalf("running=%v err=%v", running, err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # Host PID broker | ||
|
|
||
| Status: local draft. The feature is disabled by default. | ||
|
|
||
| ## Purpose | ||
|
|
||
| HAMi-core needs the host PID of each CUDA process because NVML reports processes in the host PID namespace. The current fallback discovers that PID by creating a CUDA primary context while holding the post init lock. That work becomes serial when many processes call `cuInit()` together. | ||
|
|
||
| The host PID broker returns the caller's own host PID from Linux `SO_PEERCRED`. It runs inside the NVIDIA device plugin, whose pod already uses the host PID namespace. It does not read host procfs and does not accept a PID supplied by the client. | ||
|
|
||
| ## Requirements | ||
|
|
||
| 1. The NVIDIA device plugin must run on Linux as root. | ||
|
|
||
| 2. `devicePlugin.hostPID` must remain `true`. | ||
|
|
||
| 3. The workload must use a HAMi-core build that supports protocol version 1 and the `LIBVGPU_HOSTPID_BROKER` gate. | ||
|
|
||
| 4. The container runtime must support the read only nested bind mount used for `/tmp/vgpulock/hostpid`. | ||
|
|
||
| ## Enablement | ||
|
|
||
| Set the chart value below: | ||
|
|
||
| ```yaml | ||
| devicePlugin: | ||
| hostPID: true | ||
| hostPIDBroker: | ||
| enabled: true | ||
| ``` | ||
|
|
||
| The chart rejects a configuration that enables the broker while disabling the device plugin host PID namespace. | ||
|
|
||
| When enabled, the chart does four things: | ||
|
|
||
| 1. It sets `LIBVGPU_HOSTPID_BROKER=1` in the device plugin. | ||
|
|
||
| 2. It mounts the host directory `/var/run/hami/hostpid` into the device plugin. | ||
|
|
||
| 3. The device plugin creates `/var/run/hami/hostpid/broker.sock` and serves protocol version 1. | ||
|
|
||
| 4. Each allocation that receives HAMi-core also receives `LIBVGPU_HOSTPID_BROKER=1` and a read only mount from `/var/run/hami/hostpid` to `/tmp/vgpulock/hostpid`. | ||
|
|
||
| No value other than the exact string `1` enables the server or client. | ||
|
|
||
| ## Protocol | ||
|
|
||
| The protocol uses one request and one response on a Unix stream connection. Every integer is unsigned and encoded in network byte order. | ||
|
|
||
| | Field | Request bytes | Response bytes | | ||
| | --- | ---: | ---: | | ||
| | Magic `HPID` | 4 | 4 | | ||
| | Version | 2 | 2 | | ||
| | Command or status | 2 | 2 | | ||
| | Host PID | 0 | 4 | | ||
|
|
||
| Protocol version 1 supports command 1, which means get the caller's host PID. Status 0 is success. Status 1 means the request was invalid. | ||
|
|
||
| The server reads the peer credentials from the connected socket after validating the request. The client never sends a PID. | ||
|
|
||
| ## Security boundary | ||
|
|
||
| 1. The server requires effective UID 0 for its default path. | ||
|
|
||
| 2. The server directory is owned by root with mode `0711`. | ||
|
|
||
| 3. A root owned `0600` lock file prevents two brokers from replacing each other. | ||
|
|
||
| 4. The server rejects symlink directories, symlink lock files, regular file collisions, sockets owned by another UID, and active sockets. | ||
|
|
||
| 5. The server removes only a stale socket owned by the expected UID. During shutdown it removes the path only if its device and inode still match the socket it created. | ||
|
|
||
| 6. The workload sees the broker directory through a read only mount. The HAMi-core client checks the directory owner, directory write bits, socket type, socket owner, read only mount flag, and connected peer UID before trusting a response. | ||
|
|
||
| 7. A caller can request only its own PID. The kernel supplies that identity through `SO_PEERCRED` in the broker's host PID namespace. | ||
|
|
||
| The socket is available only to workloads that receive the allocation mount. A workload can still create connection pressure. The server limits active handlers, applies one transaction deadline, and closes excess connections. A client that cannot complete the transaction uses the existing bounded HAMi-core fallback. | ||
|
|
||
| ## Failure behavior | ||
|
|
||
| | Condition | Server behavior | HAMi-core behavior | | ||
| | --- | --- | --- | | ||
| | Feature disabled | No socket is created | Existing NVML discovery path | | ||
| | Server cannot start | Device plugin startup fails | No new allocation is served by that plugin instance | | ||
| | Socket missing or stale in a workload | No broker response | Existing NVML discovery path | | ||
| | Unsafe owner, mode, mount, or peer UID | Request is not trusted | Existing NVML discovery path | | ||
| | Malformed protocol reply | Request fails | Existing NVML discovery path | | ||
| | Slow or unresponsive broker | Server and client deadlines close the request | Existing NVML discovery path | | ||
| | Broker exits after plugin startup | Device plugin exits with the broker error | Kubernetes restarts the device plugin | | ||
|
|
||
| The broker never returns a guessed PID. A successful reply contains the PID supplied by the kernel. Every other outcome is a failure that leaves PID discovery to the existing path. | ||
|
|
||
| ## Rollout | ||
|
|
||
| 1. Install the server capable HAMi release with `hostPIDBroker.enabled=false`. | ||
|
|
||
| 2. Install the compatible HAMi-core library. With no broker mount it uses the existing fallback. | ||
|
|
||
| 3. Enable `hostPIDBroker.enabled` and wait for every NVIDIA device plugin pod to become ready. | ||
|
|
||
| 4. Restart or recreate selected workloads so their allocation responses include the broker mount and environment gate. | ||
|
|
||
| 5. Validate the selected workloads before widening the rollout. Check correct host PID assignment, CUDA context accounting, broker use, and fallback behavior. | ||
|
|
||
| Existing workloads do not gain a new mount when the device plugin changes. They continue through their existing path until they are recreated. | ||
|
|
||
| ## Rollback | ||
|
|
||
| 1. Set `hostPIDBroker.enabled=false`. | ||
|
|
||
| 2. Wait for the NVIDIA device plugin rollout. | ||
|
|
||
| 3. Recreate workloads when the broker mount should be removed. Workloads that still have a compatible broker mount can continue until they exit. | ||
|
|
||
| 4. A newer HAMi-core with no broker available uses the existing fallback, so the library does not need to be rolled back first. | ||
|
|
||
| This rollout contract applies to the broker feature. The separate PR 248 lock migration still requires its own mixed binary policy. | ||
|
|
||
| ## Validation required before release | ||
|
|
||
| 1. Go race tests for the broker, lifecycle, and allocation integration. | ||
|
|
||
| 2. The actual C client to Go server contract test. | ||
|
|
||
| 3. Missing, stale, unsafe, malformed, slow, saturated, restarting, and dying broker cases. | ||
|
|
||
| 4. Linux and CUDA builds for HAMi-core plus the client and context accounting tests. | ||
|
|
||
| 5. Kubernetes validation with the feature disabled, enabled, rolled forward, and rolled back. | ||
|
|
||
| 6. Concurrent `cuInit()` and first primary context benchmarks with raw output, environment details, source revisions, and checksums. | ||
|
|
||
| ## Known limits | ||
|
|
||
| 1. The design depends on Linux `SO_PEERCRED` and a device plugin in the host PID namespace. | ||
|
|
||
| 2. Sandboxed runtimes must be tested in real execution. A mounted Unix socket may be blocked or may not preserve the peer identity needed by this design. | ||
|
|
||
| 3. Existing workloads need recreation to receive or remove the allocation mount. | ||
|
|
||
| 4. Additional NVIDIA architectures, driver versions, CRI-O, rootless runtimes, gVisor, and Kata remain separate compatibility cells until each is tested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.