riscv: fix build break after macro-to-function conversion in generic cacheflush.h
[sfrench/cifs-2.6.git] / Documentation / device-mapper / dm-integrity.txt
1 The dm-integrity target emulates a block device that has additional
2 per-sector tags that can be used for storing integrity information.
3
4 A general problem with storing integrity tags with every sector is that
5 writing the sector and the integrity tag must be atomic - i.e. in case of
6 crash, either both sector and integrity tag or none of them is written.
7
8 To guarantee write atomicity, the dm-integrity target uses journal, it
9 writes sector data and integrity tags into a journal, commits the journal
10 and then copies the data and integrity tags to their respective location.
11
12 The dm-integrity target can be used with the dm-crypt target - in this
13 situation the dm-crypt target creates the integrity data and passes them
14 to the dm-integrity target via bio_integrity_payload attached to the bio.
15 In this mode, the dm-crypt and dm-integrity targets provide authenticated
16 disk encryption - if the attacker modifies the encrypted device, an I/O
17 error is returned instead of random data.
18
19 The dm-integrity target can also be used as a standalone target, in this
20 mode it calculates and verifies the integrity tag internally. In this
21 mode, the dm-integrity target can be used to detect silent data
22 corruption on the disk or in the I/O path.
23
24 There's an alternate mode of operation where dm-integrity uses bitmap
25 instead of a journal. If a bit in the bitmap is 1, the corresponding
26 region's data and integrity tags are not synchronized - if the machine
27 crashes, the unsynchronized regions will be recalculated. The bitmap mode
28 is faster than the journal mode, because we don't have to write the data
29 twice, but it is also less reliable, because if data corruption happens
30 when the machine crashes, it may not be detected.
31
32 When loading the target for the first time, the kernel driver will format
33 the device. But it will only format the device if the superblock contains
34 zeroes. If the superblock is neither valid nor zeroed, the dm-integrity
35 target can't be loaded.
36
37 To use the target for the first time:
38 1. overwrite the superblock with zeroes
39 2. load the dm-integrity target with one-sector size, the kernel driver
40         will format the device
41 3. unload the dm-integrity target
42 4. read the "provided_data_sectors" value from the superblock
43 5. load the dm-integrity target with the the target size
44         "provided_data_sectors"
45 6. if you want to use dm-integrity with dm-crypt, load the dm-crypt target
46         with the size "provided_data_sectors"
47
48
49 Target arguments:
50
51 1. the underlying block device
52
53 2. the number of reserved sector at the beginning of the device - the
54         dm-integrity won't read of write these sectors
55
56 3. the size of the integrity tag (if "-" is used, the size is taken from
57         the internal-hash algorithm)
58
59 4. mode:
60         D - direct writes (without journal) - in this mode, journaling is
61                 not used and data sectors and integrity tags are written
62                 separately. In case of crash, it is possible that the data
63                 and integrity tag doesn't match.
64         J - journaled writes - data and integrity tags are written to the
65                 journal and atomicity is guaranteed. In case of crash,
66                 either both data and tag or none of them are written. The
67                 journaled mode degrades write throughput twice because the
68                 data have to be written twice.
69         B - bitmap mode - data and metadata are written without any
70                 synchronization, the driver maintains a bitmap of dirty
71                 regions where data and metadata don't match. This mode can
72                 only be used with internal hash.
73         R - recovery mode - in this mode, journal is not replayed,
74                 checksums are not checked and writes to the device are not
75                 allowed. This mode is useful for data recovery if the
76                 device cannot be activated in any of the other standard
77                 modes.
78
79 5. the number of additional arguments
80
81 Additional arguments:
82
83 journal_sectors:number
84         The size of journal, this argument is used only if formatting the
85         device. If the device is already formatted, the value from the
86         superblock is used.
87
88 interleave_sectors:number
89         The number of interleaved sectors. This values is rounded down to
90         a power of two. If the device is already formatted, the value from
91         the superblock is used.
92
93 meta_device:device
94         Don't interleave the data and metadata on on device. Use a
95         separate device for metadata.
96
97 buffer_sectors:number
98         The number of sectors in one buffer. The value is rounded down to
99         a power of two.
100
101         The tag area is accessed using buffers, the buffer size is
102         configurable. The large buffer size means that the I/O size will
103         be larger, but there could be less I/Os issued.
104
105 journal_watermark:number
106         The journal watermark in percents. When the size of the journal
107         exceeds this watermark, the thread that flushes the journal will
108         be started.
109
110 commit_time:number
111         Commit time in milliseconds. When this time passes, the journal is
112         written. The journal is also written immediatelly if the FLUSH
113         request is received.
114
115 internal_hash:algorithm(:key)   (the key is optional)
116         Use internal hash or crc.
117         When this argument is used, the dm-integrity target won't accept
118         integrity tags from the upper target, but it will automatically
119         generate and verify the integrity tags.
120
121         You can use a crc algorithm (such as crc32), then integrity target
122         will protect the data against accidental corruption.
123         You can also use a hmac algorithm (for example
124         "hmac(sha256):0123456789abcdef"), in this mode it will provide
125         cryptographic authentication of the data without encryption.
126
127         When this argument is not used, the integrity tags are accepted
128         from an upper layer target, such as dm-crypt. The upper layer
129         target should check the validity of the integrity tags.
130
131 recalculate
132         Recalculate the integrity tags automatically. It is only valid
133         when using internal hash.
134
135 journal_crypt:algorithm(:key)   (the key is optional)
136         Encrypt the journal using given algorithm to make sure that the
137         attacker can't read the journal. You can use a block cipher here
138         (such as "cbc(aes)") or a stream cipher (for example "chacha20",
139         "salsa20", "ctr(aes)" or "ecb(arc4)").
140
141         The journal contains history of last writes to the block device,
142         an attacker reading the journal could see the last sector nubmers
143         that were written. From the sector numbers, the attacker can infer
144         the size of files that were written. To protect against this
145         situation, you can encrypt the journal.
146
147 journal_mac:algorithm(:key)     (the key is optional)
148         Protect sector numbers in the journal from accidental or malicious
149         modification. To protect against accidental modification, use a
150         crc algorithm, to protect against malicious modification, use a
151         hmac algorithm with a key.
152
153         This option is not needed when using internal-hash because in this
154         mode, the integrity of journal entries is checked when replaying
155         the journal. Thus, modified sector number would be detected at
156         this stage.
157
158 block_size:number
159         The size of a data block in bytes.  The larger the block size the
160         less overhead there is for per-block integrity metadata.
161         Supported values are 512, 1024, 2048 and 4096 bytes.  If not
162         specified the default block size is 512 bytes.
163
164 sectors_per_bit:number
165         In the bitmap mode, this parameter specifies the number of
166         512-byte sectors that corresponds to one bitmap bit.
167
168 bitmap_flush_interval:number
169         The bitmap flush interval in milliseconds. The metadata buffers
170         are synchronized when this interval expires.
171
172
173 The journal mode (D/J), buffer_sectors, journal_watermark, commit_time can
174 be changed when reloading the target (load an inactive table and swap the
175 tables with suspend and resume). The other arguments should not be changed
176 when reloading the target because the layout of disk data depend on them
177 and the reloaded target would be non-functional.
178
179
180 The layout of the formatted block device:
181 * reserved sectors (they are not used by this target, they can be used for
182   storing LUKS metadata or for other purpose), the size of the reserved
183   area is specified in the target arguments
184 * superblock (4kiB)
185         * magic string - identifies that the device was formatted
186         * version
187         * log2(interleave sectors)
188         * integrity tag size
189         * the number of journal sections
190         * provided data sectors - the number of sectors that this target
191           provides (i.e. the size of the device minus the size of all
192           metadata and padding). The user of this target should not send
193           bios that access data beyond the "provided data sectors" limit.
194         * flags
195           SB_FLAG_HAVE_JOURNAL_MAC - a flag is set if journal_mac is used
196           SB_FLAG_RECALCULATING - recalculating is in progress
197           SB_FLAG_DIRTY_BITMAP - journal area contains the bitmap of dirty
198                 blocks
199         * log2(sectors per block)
200         * a position where recalculating finished
201 * journal
202         The journal is divided into sections, each section contains:
203         * metadata area (4kiB), it contains journal entries
204           every journal entry contains:
205                 * logical sector (specifies where the data and tag should
206                   be written)
207                 * last 8 bytes of data
208                 * integrity tag (the size is specified in the superblock)
209             every metadata sector ends with
210                 * mac (8-bytes), all the macs in 8 metadata sectors form a
211                   64-byte value. It is used to store hmac of sector
212                   numbers in the journal section, to protect against a
213                   possibility that the attacker tampers with sector
214                   numbers in the journal.
215                 * commit id
216         * data area (the size is variable; it depends on how many journal
217           entries fit into the metadata area)
218             every sector in the data area contains:
219                 * data (504 bytes of data, the last 8 bytes are stored in
220                   the journal entry)
221                 * commit id
222         To test if the whole journal section was written correctly, every
223         512-byte sector of the journal ends with 8-byte commit id. If the
224         commit id matches on all sectors in a journal section, then it is
225         assumed that the section was written correctly. If the commit id
226         doesn't match, the section was written partially and it should not
227         be replayed.
228 * one or more runs of interleaved tags and data. Each run contains:
229         * tag area - it contains integrity tags. There is one tag for each
230           sector in the data area
231         * data area - it contains data sectors. The number of data sectors
232           in one run must be a power of two. log2 of this value is stored
233           in the superblock.