Skip to content

Commit ad4b3b8

Browse files
committed
docs: Add device hotplugging documentation
Add documentation for the new PCI device hotplug/unplug feature (developer preview) and update the CHANGELOG. Signed-off-by: Ilias Stamatis <ilstam@amazon.com>
1 parent 25cb84a commit ad4b3b8

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ and this project adheres to
1010

1111
### Added
1212

13+
- [#5786](https://github.com/firecracker-microvm/firecracker/pull/5786): Added
14+
developer preview support for hotplugging and hot-unplugging PCI virtio
15+
devices (block, pmem, net) on a running microVM. The guest must manually
16+
rescan the PCI bus after hotplug and remove the device before unplug since no
17+
automatic notification mechanism is implemented yet. More information can be
18+
found in the [Device Hotplugging](docs/device-hotplug.md) documentation page.
1319
- [#5323](https://github.com/firecracker-microvm/firecracker/pull/5323): Add
1420
support for Vsock Unix domain socket path overriding on snapshot restore. More
1521
information can be found in the

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ The **API endpoint** can be used to:
116116
- Add a [entropy device](docs/entropy.md) to the microVM.
117117
- Add a [pmem device](docs/pmem.md) to the microVM.
118118
- Configure and manage [memory hotplugging](docs/memory-hotplug.md).
119+
- `[Developer Preview]` [Hot-plug and hot-unplug](docs/device-hotplug.md) virtio
120+
PCI devices while the VM is running.
119121
- Start the microVM using a given kernel image, root file system, and boot
120122
arguments.
121123
- [x86_64 only] Stop the microVM.

docs/device-hotplug.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Device Hotplugging [Developer Preview]
2+
3+
> [!WARNING]
4+
>
5+
> This feature is currently in
6+
> [Developer Preview](RELEASE_POLICY.md#developer-preview-features). It may have
7+
> limitations, and its API or behavior may change in future releases.
8+
9+
Device hotplugging allows attaching and detaching PCI virtio devices to a
10+
running microVM without requiring a reboot. Supported device types are:
11+
12+
- `virtio-block`
13+
- `virtio-pmem`
14+
- `virtio-net`
15+
16+
## Prerequisites
17+
18+
- **PCI transport enabled**: Firecracker must be started with the `--enable-pci`
19+
flag. Device hotplugging is not supported with MMIO transport.
20+
- **Guest kernel with PCI support**: The guest kernel must have PCI and the
21+
relevant virtio drivers enabled. See the
22+
[kernel policy documentation](kernel-policy.md) for details.
23+
24+
## Limitations
25+
26+
- **No automatic guest notification**: Firecracker does not currently deliver a
27+
hotplug notification to the guest. After hotplugging a device, the guest must
28+
manually rescan the PCI bus to discover it. Similarly, before unplugging, the
29+
guest must manually remove the device.
30+
31+
## Hotplugging a device
32+
33+
Hotplugging uses the same API endpoints used for pre-boot device configuration.
34+
The only difference is that the request is issued after the VM has started.
35+
36+
```console
37+
socket_location=/run/firecracker.socket
38+
39+
curl --unix-socket $socket_location -i \
40+
-X PUT 'http://localhost/drives/block1' \
41+
-H 'Accept: application/json' \
42+
-H 'Content-Type: application/json' \
43+
-d '{
44+
"drive_id": "block1",
45+
"path_on_host": "/path/to/block.ext4",
46+
"is_root_device": false,
47+
"is_read_only": false
48+
}'
49+
```
50+
51+
### Discovering the device in the guest
52+
53+
Since no hotplug notification is delivered to the guest, a PCI bus rescan is
54+
required to make the guest discover the new device:
55+
56+
```bash
57+
echo 1 > /sys/bus/pci/rescan
58+
```
59+
60+
After the rescan, the device will appear in `lspci` and the corresponding device
61+
node (e.g. `/dev/vdb`, `/dev/pmem1`) will be created by the guest kernel.
62+
63+
## Hot-unplugging a device
64+
65+
Hot-unplugging is a two-step process: first the guest must release the device,
66+
then the host issues the unplug request.
67+
68+
### Step 1: Remove the device from the guest
69+
70+
Before issuing the unplug API call, the guest must gracefully release the
71+
device. For example, unmount any mounted filesystems and remove the PCI device:
72+
73+
```bash
74+
# Unmount the filesystem (if applicable)
75+
umount /mnt/block1
76+
77+
# Remove the device from the guest
78+
echo 1 > /sys/bus/pci/devices/0000:00:01.0/remove
79+
```
80+
81+
Replace `0000:00:01.0` with the actual PCI BDF (Bus:Device.Function) address of
82+
the device, which can be found via `lspci`.
83+
84+
### Step 2: Unplug from the host
85+
86+
Issue a `DELETE` request to the corresponding device endpoint:
87+
88+
```console
89+
curl --unix-socket $socket_location -i \
90+
-X DELETE 'http://localhost/drives/block1'
91+
```

0 commit comments

Comments
 (0)