modus
Menu
On this page

The entry entropy

The entropy service: the device service of the entropy device of the machine (virtio-rng, virtio 1.x over PCI). It reads bytes from the device for its one client, the root service, which mixes them into its random generator.

It has one device and nothing else: the registers of the device, one message interrupt, memory for the queue, the machine with the right Physical only, a copy of the configuration of the device, and the entropy ring. The root service found the device, enabled it and set its interrupt (src/library/modus/pci). The code that each virtio device service shares is in src/library/modus/virtio.

What it is for. It gives the seed of the system a source that is not the processor. The root service mixes the bytes in: they add to the seed and never replace it, so a device that gives zeros or the same bytes again changes nothing.

Who uses it. The root service starts it at boot when the machine has an entropy device at the place pci.ENTROPY_DEVICE, and is its one client. No other process can name the device or the ring.

The commands of the entropy ring (src/library/modus/contract/entropy_service): Read, with a count of 1 to 48 bytes. Its completion carries the bytes that the device gave, at most the count. A refusal gives a status and the values of an error record.

What a reader sees. No window: the line entropy: ok, a queue of <size> on the log. A failure at the start writes a line at the level error and stops the service.

What it does not prove. It does not test the bytes of the device: the root service refuses a read with no byte, with one value only, or equal to the read before it, and claims nothing more of the others.

See: The entropy device in the repository, Randomness: The seed of the system, and what is claimed

entropy module with an entry

Hash
3528741ac38eb5a0e58e9031b55e5287cfbcd31c4cbf9f7e6401a955674d0737
Size
45056 bytes
Exports
0
Imports
0
Imported by
0
License
MIT

The entropy service: the device service of the entropy device of the machine (virtio-rng, virtio 1.x over PCI)

FactValue
KindModules with an entry
Sourcesrc/modules/system/entropy
Boot imageyes: in the boot image, 45056 bytes in this build
Build settingsnone: the defaults of the source
Importsnone
Imported bynone

Neighbours

It imports no module, and no module imports it. The module graph shows it with the other modules that have no edge.

Exports

ExportWhat it does
entry()starts the device and then serves the entropy ring, until the machine stops

entry

entry()

entry starts the device and then serves the entropy ring, until the machine stops.

What it sets up: the machine handle with the right Physical, the entropy ring, and the configuration of the device that the root service copied. It finds the virtio registers, resets the device, and gives it the queue (start). It then writes entropy: ok, a queue of <size>.

The loop. After each wake:

  1. 1. It reads the used ring. When the device used the read in flight, it gives its completion; a used entry with no read in flight stops it.
  2. 2. With no read in flight and a place in the completion queue, it takes the next command: a Read with a good count goes to the device; any other command completes at once with its refusal.
  3. 3. It tells the device of the new read, and wakes the client when a completion came.
  4. 4. It waits for the interrupt of the device, and for a new command when no read is in flight.

The stop: with no ring, no configuration, no virtio registers, a device that needs a reset, or a device that uses a read that was not given (entropy: the device used a read that was not given), it writes the reason at the level error and stops with Failed. Else it never returns.

Form
The entry of the module: one parameter, an address, fixed by the contract.
Source
src/modules/system/entropy/main.odin:158

Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).

What the root service gives it

WhatValueAs the root service says
GrantsThe entropy device, whose one client is this service (driver_start).
Other terms of its start grant setnone
Budget that it asks for
  • working memory pages 179
  • pages of its threads 72
  • pages of the pictures of its window 0
  • pages of the module and its imports from the files of the build
  • processes 1
  • threads 1
The working memory: the rest of the pages that the root service gave it by its name, once the tool counts its module and its thread. With the IOMMU on, the tables of the domain of the device are paid from it at the first Memory_Physical, as for the block service: the same amount as the block service. See: The IOMMU: Device addresses in the repository

The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).

ENTROPY_DEVICE constant of the package pci

ENTROPY_DEVICE :: 0x13

The entropy device of the entropy service, when the machine has one: a.

src/library/modus/pci/pci.odin:202