Skip to contentSkip to conversation

dm-integrity: Add a lazy commit mode for journal

PATCH In review Simone Weiß 3 participants 6 messages Feb 9, 2024 – Feb 26, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-integrity: Add a lazy commit mode for journal

Extend the dm-integrity driver to omit writing unused journal data sectors. Instead of filling up the whole journal section, mark the last used sector with a special commit ID. The commit ID still uses the same base value, but section number and sector number are inverted. At replay when commit IDs are analyzed this special commit ID is detected as end of valid data for this section. The main goal is to prolong the live times of e.g. eMMCs by avoiding to write the whole journal data sectors.

The change is right now to be seen as experimental and gets applied if CONFIG_DMINT_LAZY_COMMIT is set to y. Note please that this is NOT planned for a final version of the changes. I would make it configurable via flags passed e.g. via dmsetup and stored in the superblock.

Architectural Limitations:
- A dm-integrity partition, that was previously used with lazy commit, can't be replayed with a dm-integrity driver not using lazy commit.
- A dm-integrity driver that uses lazy commit is expected
to be able to cope with a partition that was created and used without lazy commit.
- With dm-integrity lazy commit, a partially written journal (e.g. due to a power cut) can cause a tag mismatch during replay if the journal entry marking the end of the journal section is missing. Due to lazy commit, older journal entries are not erased and might be processed if they have the same commit ID as adjacent newer journal entries. If dm-integrity detects bad sections while replaying the journal, keep track about those sections and try to at least replay older, good sections.
This is based on the assumption that most likely the newest section(s) will be damaged, which might have been only partially written due to a sudden reset. Previously, the whole journal would be cleared in such a case.

---
This is just a very initial version. Bear that in mind please. I would like to get feedback about the general idea and am aware that further work is needed.

Tests done so far:
- Tests where executed on qemu.
- Test scripts can be found under:
[email protected]:simone-weiss/dm-integrity-lazy-commit.git
- Suggestions on how to test this further, what testscases to run this against are appreciated.

Further work:
- The superblock should carry information about lazy-commit. Should the version be increased for this?
- Add handling/logging if a partition that was created with lazy commits, but gets replayed with a "normal" journal mode.
- Allow configuration if you want to use lazy commits or normal commits in the journal if lazy commits are enabled
- userspace setup tooling like dmsetup should be adapted accordingly

 drivers/md/Kconfig        |  10 ++
 drivers/md/dm-integrity.c | 250 ++++++++++++++++++++++++++++++++------
 2 files changed, 222 insertions(+), 38 deletions(-)
drivers/md/Kconfig +10 -0
index 68ce56fc61d0..d28a65dd54ad 100644
@@ -604,6 +604,16 @@ config DM_INTEGRITY
 	  To compile this code as a module, choose M here: the module will
 	  be called dm-integrity.
 
+config DMINT_LAZY_COMMIT
+	tristate "Lazy commit for dm-integrity target"
+	depends on DM_INTEGRITY
+	default n
+	help
+	  Extend the dm-integrity driver to omit writing unused journal data.
+	  Instead use a special lazy commit id that marks the end of the data
+	  in the journal.
+	  To be seen as experimental.
+
 config DM_ZONED
 	tristate "Drive-managed zoned block device target support"
 	depends on BLK_DEV_DM
drivers/md/dm-integrity.c +212 -38

424 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 13 lines · Simone Weiß

Extend the dm-integrity driver to omit writing unused journal data sectors. Instead of filling up the whole journal section, mark the last used sector with a special commit ID. The commit ID still uses the same base value, but section number and sector number are inverted. At replay when commit IDs are analyzed this special commit ID is detected as end of valid data for this section. The main goal is to prolong the live times of e.g. eMMCs by avoiding to write the whole journal data sectors.

The change is right now to be seen as experimental and gets applied if CONFIG_DMINT_LAZY_COMMIT is set to y. Note please that this is NOT planned for a final version of the changes. I would make it configurable via flags passed e.g. via dmsetup and stored in the superblock.

Quoted 11 lines

Architectural Limitations:
- A dm-integrity partition, that was previously used with lazy commit, can't be replayed with a dm-integrity driver not using lazy commit.
- A dm-integrity driver that uses lazy commit is expected
to be able to cope with a partition that was created and used without lazy commit.
- With dm-integrity lazy commit, a partially written journal (e.g. due to a power cut) can cause a tag mismatch during replay if the journal entry marking the end of the journal section is missing. Due to lazy commit, older journal entries are not erased and might be processed if they have the same commit ID as adjacent newer journal entries.

Hi

I was thinking about it and I think that this problem is a showstopper.

Suppose that a journal section contains these commit IDs:

	2	2	2	2(EOF)	3	3	3	3

The IDs "3" are left over from previous iterations. The IDs "2" contain the current data. And now, the journal rolls over and we attempt to write all 8 pages with the ID "3". However, a power failure happens and we only write 4 pages with the ID "3". So, the journal will look like:

	3(new)	3(new)	3(new)	3(new)	3(old)	3(old)	3(old)	3(old)

After a reboot, the journal-replay logic will falsely believe that the whole journal section is consistent and it will attempt to replay it.

This could be fixed by having always increasing commit IDs - the commit IDs have 8 bytes, so we can assume that they never roll-over and it would prevent us from mixing old IDs into the current transaction.

Mikulas

Quoted 10 lines

If dm-integrity detects bad sections while
replaying the journal, keep track about those sections and try to at least replay older, good sections.
This is based on the assumption that most likely the newest section(s) will be damaged, which might have been only partially written due to a sudden reset. Previously, the whole journal would be cleared in such a case.

#2 lore raw
Quoted 51 lines · Mikulas Patocka

CAUTION: This email originated from outside of the Elektrobit organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 16 lines · Simone Weiß

Extend the dm-integrity driver to omit writing unused journal data sectors. Instead of filling up the whole journal section, mark the last used sector with a special commit ID. The commit ID still uses the same base value,
but section number and sector number are inverted. At replay when commit IDs are analyzed this special commit ID is detected as end of valid data for this
section. The main goal is to prolong the live times of e.g. eMMCs by avoiding
to write the whole journal data sectors.

The change is right now to be seen as experimental and gets applied if CONFIG_DMINT_LAZY_COMMIT is set to y. Note please that this is NOT planned for a final version of the changes. I would make it configurable via flags passed e.g. via dmsetup and stored in the superblock.

Quoted 14 lines

Architectural Limitations:
- A dm-integrity partition, that was previously used with lazy commit, can't be replayed with a dm-integrity driver not using lazy commit.
- A dm-integrity driver that uses lazy commit is expected
 to be able to cope with a partition that was created and used without lazy commit.
- With dm-integrity lazy commit, a partially written journal (e.g. due to a power cut) can cause a tag mismatch during replay if the journal entry marking
 the end of the journal section is missing. Due to lazy commit, older journal
 entries are not erased and might be processed if they have the same commit ID
 as adjacent newer journal entries.

Hi

I was thinking about it and I think that this problem is a showstopper.

Suppose that a journal section contains these commit IDs:

        2       2       2       2(EOF)  3       3       3       3

The IDs "3" are left over from previous iterations. The IDs "2" contain the current data. And now, the journal rolls over and we attempt to write all 8 pages with the ID "3". However, a power failure happens and we only write 4 pages with the ID "3". So, the journal will look like:

Quoted 8 lines

        3(new)  3(new)  3(new)  3(new)  3(old)  3(old)  3(old)  3(old)

After a reboot, the journal-replay logic will falsely believe that the whole journal section is consistent and it will attempt to replay it.

This could be fixed by having always increasing commit IDs - the commit IDs have 8 bytes, so we can assume that they never roll-over and it would prevent us from mixing old IDs into the current transaction.

Hi

Thanks for the review of the concept. I was out this week and could only think about it now. I understood it right, that the proposal is to add an extra value to the commit ID, that is e.g. incremented when integrity_commit is executed?

If so, I tried this quickly and looks good on first glance. Will check and test further next.

Simone

Quoted 13 lines

Mikulas

Quoted 10 lines

 If dm-integrity detects bad sections while
 replaying the journal, keep track about those sections and try to at least replay older, good sections.
 This is based on the assumption that most likely the newest section(s) will be damaged, which might have been only partially written due to a sudden reset. Previously, the whole journal would be cleared in such a case.

maintainer
#3 lore raw
Quoted 62 lines · Simone
Quoted 51 lines · Mikulas Patocka

CAUTION: This email originated from outside of the Elektrobit organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 16 lines · Simone Weiß

Extend the dm-integrity driver to omit writing unused journal data sectors. Instead of filling up the whole journal section, mark the last used sector with a special commit ID. The commit ID still uses the same base value,
but section number and sector number are inverted. At replay when commit IDs are analyzed this special commit ID is detected as end of valid data for this
section. The main goal is to prolong the live times of e.g. eMMCs by avoiding
to write the whole journal data sectors.

The change is right now to be seen as experimental and gets applied if CONFIG_DMINT_LAZY_COMMIT is set to y. Note please that this is NOT planned for a final version of the changes. I would make it configurable via flags passed e.g. via dmsetup and stored in the superblock.

Quoted 14 lines

Architectural Limitations:
- A dm-integrity partition, that was previously used with lazy commit, can't be replayed with a dm-integrity driver not using lazy commit.
- A dm-integrity driver that uses lazy commit is expected
 to be able to cope with a partition that was created and used without lazy commit.
- With dm-integrity lazy commit, a partially written journal (e.g. due to a power cut) can cause a tag mismatch during replay if the journal entry marking
 the end of the journal section is missing. Due to lazy commit, older journal
 entries are not erased and might be processed if they have the same commit ID
 as adjacent newer journal entries.

Hi

I was thinking about it and I think that this problem is a showstopper.

Suppose that a journal section contains these commit IDs:

        2       2       2       2(EOF)  3       3       3       3

The IDs "3" are left over from previous iterations. The IDs "2" contain the current data. And now, the journal rolls over and we attempt to write all 8 pages with the ID "3". However, a power failure happens and we only write 4 pages with the ID "3". So, the journal will look like:

Quoted 8 lines

        3(new)  3(new)  3(new)  3(new)  3(old)  3(old)  3(old)  3(old)

After a reboot, the journal-replay logic will falsely believe that the whole journal section is consistent and it will attempt to replay it.

This could be fixed by having always increasing commit IDs - the commit IDs have 8 bytes, so we can assume that they never roll-over and it would prevent us from mixing old IDs into the current transaction.

Hi

Quoted 8 lines

Thanks for the review of the concept. I was out this week and could only think about it now. I understood it right, that the proposal is to add an extra value to the commit ID, that is e.g. incremented when integrity_commit is executed?

If so, I tried this quickly and looks good on first glance. Will check and test further next.

Simone

I propose to use the commit ID 0 when writing the journal for the first time, then 1 when the journal rolls over, 2 when it rolls over again, 3 when it rolls over again, 4 on another roll over and so on up to 0x7fffffffffffffff (which will be never reached in practice).

And use the top bit as an end-of-section marker. As the commit IDs will never roll over, it won't happen that an old transaction would be mixed into a new transaction on partial journal write.

Mikulas

#4 lore raw
Quoted 93 lines · Mikulas Patocka

CAUTION: This email originated from outside of the Elektrobit organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 75 lines · Simone
Quoted 57 lines · Mikulas Patocka

CAUTION: This email originated from outside of the Elektrobit organization. Do
not click links or open attachments unless you recognize the sender and know
the content is safe.

Quoted 18 lines · Simone Weiß

Extend the dm-integrity driver to omit writing unused journal data sectors.
Instead of filling up the whole journal section, mark the last used sector with a special commit ID. The commit ID still uses the same base value,
but section number and sector number are inverted. At replay when commit IDs
are analyzed this special commit ID is detected as end of valid data for this
section. The main goal is to prolong the live times of e.g. eMMCs by avoiding
to write the whole journal data sectors.

The change is right now to be seen as experimental and gets applied if CONFIG_DMINT_LAZY_COMMIT is set to y. Note please that this is NOT planned for a final version of the changes. I would make it configurable via flags passed e.g. via dmsetup and stored in the superblock.

Quoted 16 lines

Architectural Limitations:
- A dm-integrity partition, that was previously used with lazy commit, can't be replayed with a dm-integrity driver not using lazy commit.
- A dm-integrity driver that uses lazy commit is expected
 to be able to cope with a partition that was created and used without lazy commit.
- With dm-integrity lazy commit, a partially written journal (e.g. due to a
 power cut) can cause a tag mismatch during replay if the journal entry marking
 the end of the journal section is missing. Due to lazy commit, older journal
 entries are not erased and might be processed if they have the same commit
ID
 as adjacent newer journal entries.

Hi

I was thinking about it and I think that this problem is a showstopper.

Suppose that a journal section contains these commit IDs:

        2       2       2       2(EOF)  3       3       3       3

The IDs "3" are left over from previous iterations. The IDs "2" contain the current data. And now, the journal rolls over and we attempt to write all 8 pages with the ID "3". However, a power failure happens and we only write 4 pages with the ID "3". So, the journal will look like:

Quoted 8 lines

        3(new)  3(new)  3(new)  3(new)  3(old)  3(old)  3(old)  3(old)

After a reboot, the journal-replay logic will falsely believe that the whole journal section is consistent and it will attempt to replay it.

This could be fixed by having always increasing commit IDs - the commit IDs have 8 bytes, so we can assume that they never roll-over and it would prevent us from mixing old IDs into the current transaction.

Hi

Thanks for the review of the concept. I was out this week and could only think
about it now. I understood it right, that the proposal is to add an extra value
to the commit ID, that is e.g. incremented when integrity_commit is executed?

Quoted 5 lines

If so, I tried this quickly and looks good on first glance. Will check and test
further next.

Simone

I propose to use the commit ID 0 when writing the journal for the first time, then 1 when the journal rolls over, 2 when it rolls over again, 3 when it rolls over again, 4 on another roll over and so on up to 0x7fffffffffffffff (which will be never reached in practice).

Quoted 5 lines

And use the top bit as an end-of-section marker. As the commit IDs will never roll over, it won't happen that an old transaction would be mixed into a new transaction on partial journal write.

Mikulas

Hi,

I can do it this way for sure as well. Another point still in my mind is the
superblock: I would like to get rid of the build time switch and carry information about lazy commits enabled in the superblock. As there is J, B, D and R as mode already, a new mode L or such could be added. I will work on this and also take a look at stuff like dmsetup to check if something would be needed there. If there are further points for now on anyone's mind, please tell.

Best,
Simone

#5 lore raw

On 2/26/24 7:47 AM, Weiß, Simone wrote:
...

Quoted 6 lines

I can do it this way for sure as well. Another point still in my mind is the
superblock: I would like to get rid of the build time switch and carry information about lazy commits enabled in the superblock. As there is J, B, D and R as mode already, a new mode L or such could be added. I will work on this and also take a look at stuff like dmsetup to check if something would be needed there. If there are further points for now on anyone's mind, please tell.

Just FYI: I do not think you need to add anything to dmsetup, but integritysetup (part of the cryptsetup project) needs to understand new metadata and dm-integrity table options.

And I guess it needs to add a new option to use the new mode.

Perhaps it is best to create an issue for cryptsetup to discuss it, but it will not be merged until the kernel code is on the way to mainline.

Milan