File: mdevctl.rst

package info (click to toggle)
mdevctl 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,072 kB
  • sloc: sh: 731; makefile: 74
file content (643 lines) | stat: -rw-r--r-- 22,834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
=======
mdevctl
=======

----------------------------------
Mediated device management utility
----------------------------------

:Manual section: 8

SYNOPSIS
========

``mdevctl`` {COMMAND} [OPTIONS...]

``lsmdev`` [OPTIONS...]

DESCRIPTION
===========

``mdevctl`` is a utility for managing and persisting devices in the
mediated device device framework of the Linux kernel.  Mediated
devices are sub-devices of a parent device (ex. a vGPU) which
can be dynamically created and potentially used by drivers like
vfio-mdev for assignment to virtual machines.

``lsmdev`` is an alias for ``mdevctl list``.

OPTIONS
=======

The following options are understood:

``--addattr=ATTRIBUTE``
    Add an attribute *ATTRIBUTE*. Valid for the ``modify``
    command.

``-a|--auto``
    Automatically start the device on parent availability. Valid for
    ``define`` and ``modify`` commands.

``-d|--defined``
    List all defined devices, even if not active. Valid for the ``list``
    command. Modify the defined configuration of a device, even if the
    device is active. Valid for the ``modify`` command.

``--delattr``
    Delete an attribute entry. Valid for the ``modify`` command.

``--dumpjson``
    Dump the configuration for a device in JSON format when filtered to
    as single device and used with the ``list`` command.  When used
    with the ``types`` command, output machine readable type information.

``-i|--index=INDEX``
    Act on the attribute *INDEX*. Valid for the ``modify`` command.

``--jsonfile=FILE``
    Read the configuration for a device from a JSON file *FILE*.
    Valid for the ``define`` and ``start`` commands.

``-l|--live``
    Modify active device without modifying the defined configuration of
    the device. Valid for the ``modify`` command.

``-m|--manual``
    Do not start a device automatically on parent availability. Valid
    for the ``modify`` command.

``-p|--parent=PARENT``
    Specify or identify the device by its parent device. Note that the parent
    device is specified by its kernel sysfs name and is case-sensitive.

``-t|--type=TYPE``
    Specify or identify the device by its type.

``-u|--uuid=UUID``
    Specify or identify the device by its UUID.

``--value=VALUE``
    Set an attribute to *VALUE*, in the format accepted by the attribute.
    Valid for the ``modify`` command.

``-v|--verbose``
    Increase output verbosity, currently only adds attribute output to the
    ``list`` command.

``-V|--version``
    Print mdevctl version.

COMMANDS
========

The following commands are understood:

``define`` *DEVICESPEC*
    Define a config for an mdev device, identified either by an UUID (if
    the device already exists), or by the parent device and either the type
    or a JSON configuration file, and, optionally, the UUID. If no UUID is
    specified, one is autogenerated and printed. If no file is used,
    *-a|--auto* may be used to specify that the device should be started
    automatically.

``list``
    List mdev devices. With no options, currently running devices are listed.
    With ``-d|--defined``, previously defined devices are listed.
    Can be restricted to list only devices for a given parent or UUID. With
    ``--dumpjson`` output is provided in machine readable JSON format.
    When a UUID is provided and the output results in a single device, the
    JSON output format is compatible with the configuration file format.

``modify`` *DEVICESPEC*
    Modify the configuration for an mdev device, identified via its UUID
    and optionally its parent.
    Type and startup mode (auto or manual) can be modified by this command.
    Attributes can be added or deleted. Attributes to be deleted must be
    specified by their index; if an attribute is specified without an
    index, it is appended at the end of the attribute list.
    Active devices are unaffected by this command; changes in the configuration
    are applied the next time the device is started. Depending on installed
    callout scripts active devices can be modified. With ``-l|--live``
    modifications can be applied to active devices if a callout scripts supports
    the event ``live``. The option ``-d|--defined`` also direct the modification
    to the started device configuration.

``start`` *DEVICESPEC*
    Start a mediated device. This command can be used to start either a
    previously-defined device or a newly-created transient device.

    If the UUID and optional parent argument matches an existing device definition,
    then the existing device will be started. It is an error to specify a device
    type that conflicts with the existing device definition.

    If the UUID argument is omitted or if the specified UUID and parent does not
    match an existing device definition, a new transient device will be started.
    If the UUID is omitted, a new UUID will be automatically generated. When
    starting a new transient device, the parent and device type must be specified.
    A ``--jsonfile`` may replace the ``--type`` specification and also include
    additional attributes in JSON format to be applied to the started device.

``stop`` *DEVICESPEC*
    Stop an mdev device, specified via its UUID.

``types``
    List the mdev device types known to the system by parent device.  Output
    may be limited to a single parent device with the ``-p|--parent`` option.
    JSON output format is used with the ``--dumpjson`` option.

``undefine`` *DEVICESPEC*
    Undefine, or remove the configuration for an mdev device, specified by
    its UUID and optionally its parent. If a UUID exists for multiple
    parents, all of them will be removed unless restricted to a single parent.
    Running devices are unaffected by this command.

NOTE ON DEVICE SPECIFICATION
============================

For a given UUID, only one device with that UUID may be running at the
same time. However, it is possible to define multiple devices with the
same UUID under different parent devices. Therefore, it is sometimes
necessary to specify the parent device alongside the UUID to uniquely
identify a device.

EXIT STATUS
===========
On success, 0 is returned, a non-zero failure code otherwise.

EXAMPLES
========

List running mdev devices::

    # mdevctl list
    85006552-1b4b-45ef-ad62-de05be9171df 0000:00:02.0 i915-GVTg_V4_4
    83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 (defined)

List defined mdev devices::

    # mdevctl list -d
    83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 auto
    b0a3989f-8138-4d49-b63a-59db28ec8b48 0000:00:02.0 i915-GVTg_V4_8 auto
    5cf14a12-a437-4c82-a13f-70e945782d7b 0000:00:02.0 i915-GVTg_V4_4 manual

List mdev types supported on the host system::

    # mdevctl types
    0000:00:02.0
      i915-GVTg_V4_2
        Available instances: 1
        Device API: vfio-pci
        Description: low_gm_size: 256MB high_gm_size: 1024MB fence: 4 resolution: 1920x1200 weight: 8 
      i915-GVTg_V4_1
        Available instances: 0
        Device API: vfio-pci
        Description: low_gm_size: 512MB high_gm_size: 2048MB fence: 4 resolution: 1920x1200 weight: 16 
      i915-GVTg_V4_8
        Available instances: 4
        Device API: vfio-pci
        Description: low_gm_size: 64MB high_gm_size: 384MB fence: 4 resolution: 1024x768 weight: 2 
      i915-GVTg_V4_4
        Available instances: 3
        Device API: vfio-pci
        Description: low_gm_size: 128MB high_gm_size: 512MB fence: 4 resolution: 1920x1200 weight: 4 

Modify a defined device from automatic start to manual::

    # mdevctl modify --uuid 83c32df7-d52e-4ec1-9668-1f3c7e4df107 --manual
    # mdevctl list -d
    83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 manual
    b0a3989f-8138-4d49-b63a-59db28ec8b48 0000:00:02.0 i915-GVTg_V4_8 auto
    5cf14a12-a437-4c82-a13f-70e945782d7b 0000:00:02.0 i915-GVTg_V4_4 manual

Stop a running mdev device::

    # mdevctl stop -u 83c32df7-d52e-4ec1-9668-1f3c7e4df107

Start an mdev device that is not defined::

    # uuidgen
    6eba5b41-176e-40db-b93e-7f18e04e0b93
    # mdevctl start -u 6eba5b41-176e-40db-b93e-7f18e04e0b93 -p 0000:00:02.0 --type i915-GVTg_V4_1
    # mdevctl list
    85006552-1b4b-45ef-ad62-de05be9171df 0000:00:02.0 i915-GVTg_V4_4
    6eba5b41-176e-40db-b93e-7f18e04e0b93 0000:00:02.0 i915-GVTg_V4_1

Promote the new created mdev to a defined device::

    # mdevctl define --uuid 6eba5b41-176e-40db-b93e-7f18e04e0b93
    # mdevctl list -d
    83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 manual
    6eba5b41-176e-40db-b93e-7f18e04e0b93 0000:00:02.0 i915-GVTg_V4_1 manual
    b0a3989f-8138-4d49-b63a-59db28ec8b48 0000:00:02.0 i915-GVTg_V4_8 auto
    5cf14a12-a437-4c82-a13f-70e945782d7b 0000:00:02.0 i915-GVTg_V4_4 manual

ADVANCED EXAMPLES (ATTRIBUTES AND JSON)
---------------------------------------

::

    # mdevctl list -d
    783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual

Add some attributes::

    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_adapter --value=5
    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_adapter --value=6
    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_domain --value=0xab
    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_control_domain --value=0xab
    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_domain --value=4
    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_control_domain --value=4
    # mdevctl list -dv
    783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual
      Attrs:
        @{0}: {"assign_adapter":"5"}
        @{1}: {"assign_adapter":"6"}
        @{2}: {"assign_domain":"0xab"}
        @{3}: {"assign_control_domain":"0xab"}
        @{4}: {"assign_domain":"4"}
        @{5}: {"assign_control_domain":"4"}

Dump the JSON configuration::

    # mdevctl list -d -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --dumpjson
    {
      "mdev_type": "vfio_ap-passthrough",
      "start": "manual",
      "attrs": [
        {
          "assign_adapter": "5"
        },
        {
          "assign_adapter": "6"
        },
        {
          "assign_domain": "0xab"
        },
        {
          "assign_control_domain": "0xab"
        },
        {
          "assign_domain": "4"
        },
        {
          "assign_control_domain": "4"
        }
      ]
    }

Remove some attributes::

    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --delattr --index=5
    # mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --delattr --index=4
    # mdevctl list -dv
    783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual
      Attrs:
        @{0}: {"assign_adapter":"5"}
        @{1}: {"assign_adapter":"6"}
        @{2}: {"assign_domain":"0xab"}
        @{3}: {"assign_control_domain":"0xab"}

Define an mdev device from a file::

    # cat vfio_ap_device.json
    {
      "mdev_type": "vfio_ap-passthrough",
      "start": "manual",
      "attrs": [
        {
          "assign_adapter": "5"
        },
        {
          "assign_domain": "0x47"
        },
        {
          "assign_domain": "0xff"
        }
      ]
    }
    # mdevctl define -p matrix --jsonfile vfio_ap_device.json
    e2e73122-cc39-40ee-89eb-b0a47d334cae
    # mdevctl list -dv
    783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual
      Attrs:
        @{0}: {"assign_adapter":"5"}
        @{1}: {"assign_adapter":"6"}
        @{2}: {"assign_domain":"0xab"}
        @{3}: {"assign_control_domain":"0xab"}
    e2e73122-cc39-40ee-89eb-b0a47d334cae matrix vfio_ap-passthrough manual
      Attrs:
        @{0}: {"assign_adapter":"5"}
        @{1}: {"assign_domain":"0x47"}
        @{2}: {"assign_domain":"0xff"}

CONFIGURATION FILE FORMAT
=========================

Configuration files are in JSON. Attributes in "``attrs``" are optional. ::

    {
      "mdev_type": "TYPE",
      "start": "auto|manual",
      "attrs": [
        {
          "attribute0": "VALUE"
        },
        {
          "attribute1": "VALUE"
        }
      ]
    }

INVOKING EXTERNAL SCRIPTS FOR DEVICE EVENTS
===========================================

mdevctl supports invoking external scripts to handle additional device
type-specific configurations and to broadcast notifications regarding changes
or updates to a device. These scripts are invoked before, after, and/or during
mdevctl's "primary command execution" (e.g. writing the device configuration
file for define, or activating a device for start).

Essentially, the procedure in mdevctl looks like this:

    - command-line parsing & setup
    - invoke live-command call-out [1]_
    - invoke pre-command call-out
    - primary command execution [2]_
    - invoke post-command call-out [2]_
    - invoke notifier

    .. [1] executed only if live update is requested.
    .. [2] skipped if step ``invoke pre-command call-out`` fails.

EVENT SCRIPTS
-------------

A call-out or notification event invokes a script along with a set of
parameters detailing the type of call-out, mdevctl's command execution
progress, and the mediated device. The parameters are as follows:

<CONFIG> | SCRIPT <``-t=``\ *type* ``-e=``\ *event*
``-a=``\ *action* ``-s=``\ *state* ``-u=``\ *UUID*
``-p=``\ *parent*>

``CONFIG``
    The device's JSON configuration, provided via standard input.

``-t=``\ *type*
    The device type.

``-e=``\ *event*
    Event type of call-out that is invoked. For call-out scripts, this may be
    ``pre``, ``live``, ``post``, or ``get``. For notification scripts, this will
    always be ``notify``.

``-a=``\ *action*
    An action synonymous with an mdevctl command (e.g. define, start).

``-s=``\ *state* 
    A trinary state of the mdevctl command execution. The possibilities are
    ``none`` if the mdevctl command has yet to execute, ``success``
    if the mdevctl command completed successfully, or ``failure`` if there
    was a problem executing the mdevctl command.

``-u=``\ *UUID*
    UUID of the mediated device.

``-p=``\ *parent*
    Parent of the mediated the device.

CALL-OUT EVENT SCRIPTS
----------------------

A call-out event script is invoked during a ``live``, ``pre``, ``post`` or
``get`` event. mdevctl will attempt each script stored in the mdevctl callouts
directory until either a script that satisfies the device type is found or all
scripts have been attempted. A device script must check the "TYPE" parameter to
ensure the specified device type is supported, otherwise error code 2 should be
returned. If no script is found for the specified device type, then mdevctl
will carry on as normal.

These scripts are stored in */usr/lib/mdevctl/scripts.d/callouts*. The same
script is invoked for ``live``, ``pre``, ``post``, and ``get`` call-out events
for the device type.

``Live-Command``

    A live-command call-out event is invoked once before the pre-command call-out
    event execution. This only occurs if the ``live`` option is specified on the
    ``modify`` command and the device modified is active.
    Event type is ``live``. State will always be ``none``.

    If the ``live`` command line option is specified any non-zero return code results in
    a live modification failure except for all call-outs return with return code 2
    resulting in a ``live update not supported`` information.
    The return code is disruptive if also the option ``defined`` is provided and will
    prevent the update of the defined device configuration.  

    A notification event will follow if the ``live`` command line option is specified.

    This event is only supported for the ``modify`` command.

``Pre-Command``

    A pre-command call-out event is invoked once prior to primary command execution.
    Event type is ``pre``. State will always be ``none``.

    Any non-zero return code (exempting 2) will prevent mdevctl from performing
    the primary command execution and mdevctl will abort early.

    A notification event will follow only if an error code (exempting 2) is
    observed.

    This event is not supported for the ``list``, ``types``, or ``version``
    commands.

``Post-Command``

    A post-command call-out event is invoked once after primary command execution.
    Event type is ``post``. State will be ``success`` if mdevctl was able to
    finish primary command execution successfully, or ``failure`` otherwise.

    The same script used for the pre event is used for the post event.

    Any return code is non-disruptive.

    A notification event will always follow a post-command call-out.

    This event is not supported for the ``list``, ``types``, or ``version``
    commands.

``Get-attributes``

    A get event is invoked during a ``define`` and ``list`` command to
    acquire device attributes from an active device. Event type is ``get``. Action
    is ``attributes``. State is ``none``. Note that, unlike other call-outs
    events, **get-attributes does not expect a device config on stdin, and an
    array of JSON formatted device attributes is returned via stdout**.

    The same script used for the pre event is used for the get event. If the script
    is not designed to support a get event, then the return code is 0.

    For ``define``, a non-zero return code (exempting 2) will disrupt the define
    command entirely.

    For ``list``, any return code is non-disruptive.

    A script must return a JSON formatted array of device attributes on standard
    output. Example::

        [
            {
                "attribute0": "VALUE"
            },
            {
                "attribute1": "VALUE"
            }
        ]

``Get-capabilities``

    A get event is invoked on every new mdevctl execution to find a matching script
    supporting versioning for the device type.
    Event type is ``get``. Action is ``capabilities``. State is ``none``.
    Note that, unlike other call-outs events, **get-capabilities provides a
    versioning JSON on stdin, and expects a versioning JSON is returned via
    stdout**.
    The provided JSON on stdin explains in ``provides`` which ``actions`` and
    ``events`` mdevctl supports. The information is offered to the script to
    derive its supported ``actions`` and ``events`` from but it there is no
    obligation for scripts to follow this pattern.
    A valid versioning JSON response provides in ``supports`` the supported
    actions in ``actions`` and the supported events in ``events``.

    If a valid versioning JSON is returned on stdout by the script and the
    return code is NOT 2 the script is considered a positive match for the
    provided device type. A script providing versioning is the primary choice
    for a device type when mdevctl is executing callouts or in other words if
    a script which supports versioning is found the script is used for every
    event and action for the device type. Should no versioning supporting
    script be found the none versioning search pattern is used.

    A script is provided on standard in with a versioning JSON describing the mdevctl
    supported version, actions and events. Example::

        {
          "provides": {
            "version": 1,
            "actions": [
              "start",
              "stop",
              "define",
              "undefine",
              "modify",
              "attributes",
              "capabilities"
            ],
            "events": [
              "pre",
              "post",
              "notify",
              "get"
            ]
          }
        }

    A script that wants to support versioning must return a versioning JSON on standard
    output. The script should list all supported actions in the actions array and all
    supported events in the events array. It is possible to add additional actions or
    events in the array but if mdevctl did not have these in the arrays in provides
    they are ignored. Example::

        {
          "supports": {
            "version": 1,
            "actions": [
              "start",
              "stop",
              "define",
              "undefine",
              "modify",
              "attributes",
              "capabilities"
            ],
            "events": [
              "pre",
              "post",
              "notify",
              "get"
            ]
          }
        }

AUTO-START CALL-OUTS
--------------------

For each device set to start automatically during system boot, mdevctl will
invoke the pre and post events. Action is the string ``start``.

Return code and notification event behavior is the same as documented for
the pre and post events. Errors reported by a script will disrupt the
auto-start for that particular device and the message will be reported to the
system log before attempting to the next auto-start device.

Note that if a notification script is used to convey information to another
program or daemon during the auto-start procedure, it is not guaranteed that
the program will already be active prior to mdevctl's invocation (e.g. the
auto-start event may occur before the libvirt daemon is activated).

NOTIFICATION EVENT SCRIPTS
--------------------------

Notification event scripts may be used to signal the state of the mediated
device or the state of an mdevctl command to other programs or loggers. Unlike
call-out scripts, notifier scripts are device-type agnostic.

``Notify``

    A notification event is invoked once either following a pre-command call-out
    failure or after a post-command call-out. Event is ``notify``. If following a
    pre event, then state will be ``none``. If following a post event, then
    state will mirror the value passed to the post-command call-out.

    These scripts are stored in */usr/lib/mdevctl/scripts.d/notifiers*. **All
    notification scripts will be invoked during a notification event**.

    A non-zero return code is ignored.

    This event is not supported for the ``list``, ``types``, or ``version``
    commands.

SCRIPT RETURN VALUES
--------------------

A call-out script should return one of the following values:

    - 0  if OK,
    - 1  if an error occurred,
    - 2  if the script does not support the device type

FILES
=====

*/etc/mdevctl.d/**

Configuration files are in one subdirectory per parent device and named
by UUID.

*/usr/lib/mdevctl/scripts.d/callouts/**

Scripts for pre/post/get call-out events. **NOTE**: these scripts were
previously located at */etc/mdevctl.d/scripts.d/callouts/**, but that location
is now deprecated.

*/usr/lib/mdevctl/scripts.d/notifiers/**

Scripts for notification call-out events. **NOTE**: these scripts were
previously located at */etc/mdevctl.d/scripts.d/notifiers/**, but that location
is now deprecated.

SEE ALSO
========

udev(7), udevadm(8), driverctl(8)