Commit Graph

12 Commits

Author SHA1 Message Date
Lee Jones
a07b60e85c ANDROID: dm-bow: Protect Ranges fetched and erased from the RB tree
Bug: 195565510
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Change-Id: Ic8134eb902aa7d929e3121b2f69b1d258f570652
(cherry picked from commit 98c15b2bad1a277da43c65c642f8c3c3ee07bacc)
2022-05-10 13:25:21 +00:00
Lee Jones
7a7eadac58 Revert "ANDROID: dm-bow: Protect Ranges fetched and erased from the RB tree"
This reverts commit f3ca80cced.

Reason for revert: Needs rework - causes unforeseen deadlock.

Bug: 227141277
Change-Id: I46f2b3d34c6a6a0a96d0fcc10086aa0d1687b127
Signed-off-by: Lee Jones <joneslee@google.com>
2022-03-31 11:20:55 +00:00
Lee Jones
f3ca80cced ANDROID: dm-bow: Protect Ranges fetched and erased from the RB tree
Bug: 195565510
Change-Id: Ic87a27d3ffe51b5290a7ff7a87fddd8305fd42af
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2022-03-11 15:47:21 +00:00
Eric Biggers
537d3bb974 ANDROID: dm: sync inline crypto support with patches going upstream
Replace the following patches with upstream versions
(well, almost upstream; as of 2021-02-12 they are queued for 5.12 at
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/log/?h=for-next):

	ANDROID-dm-add-support-for-passing-through-inline-crypto-support.patch
	ANDROID-dm-enable-may_passthrough_inline_crypto-on-some-targets.patch
	ANDROID-block-Introduce-passthrough-keyslot-manager.patch

Also, resolve conflicts with the following non-upstream patches for
hardware-wrapped key support.  Notably, we need to handle the field
blk_keyslot_manager::features in a few places:

	ANDROID-block-add-hardware-wrapped-key-support.patch
	ANDROID-dm-add-support-for-passing-through-derive_raw_secret.patch

Finally, update non-upstream device-mapper targets (dm-bow and
dm-default-key) to use the new way of specifying inline crypto
passthrough support (DM_TARGET_PASSES_CRYPTO) rather than the old way
(may_passthrough_inline_crypto).  These changes should be folded into:

	ANDROID-dm-bow-Add-dm-bow-feature.patch
	ANDROID-dm-add-dm-default-key-target-for-metadata-encryption.patch

Test: tested on db845c; verified that inline crypto support gets passed
      through over dm-linear.
Bug: 162257830
Change-Id: I5e3dea1aa09fc1215c90857b5b51d9e3720ef7db
Signed-off-by: Eric Biggers <ebiggers@google.com>
2021-02-19 10:48:51 +00:00
Eric Biggers
98777a7eb7 Merge commit 382625d0d4 ("Merge tag 'for-5.9/block-20200802' of git://git.kernel.dk/linux-block") into android-mainline
Conflicts:
	drivers/md/dm-bow.c
	drivers/md/dm-default-key.c
	drivers/md/dm.c
	fs/crypto/inline_crypt.c

Replace bdev->bd_queue with bdev_get_queue(bdev).

Bug: 129280212
Bug: 160883801
Bug: 160885805
Bug: 162257830
Change-Id: I9b0b295472080dfc0990dcb769205e68d706ce0e
Signed-off-by: Eric Biggers <ebiggers@google.com>
2020-08-06 10:07:17 -07:00
Eric Biggers
228804d48c ANDROID: dm-bow: avoid truncating the logical block size
Upstream commit ad6bf88a6c ("block: fix an integer overflow in logical
block size") changed queue_limits::logical_block_size from 'unsigned
short' to 'unsigned int', and this commit has been backported to the LTS
branches.  Update the computation in dm_bow_io_hints() to match.

This mirrors upstream commit 64611a15ca ("dm crypt: avoid truncating
the logical block size") which fixed the same bug in dm-crypt.

Fixes: 7df64f6216 ("ANDROID: dm-bow: Add block_size option")
Change-Id: I45eba7d21cf178e4b8e624ef5f819a1ffb015a8d
Signed-off-by: Eric Biggers <ebiggers@google.com>
2020-06-19 18:51:08 +00:00
Paul Lawrence
7df64f6216 ANDROID: dm-bow: Add block_size option
Also consolidated changes to limits, including no longer changing
underlying device.

Bug: 153512828
Test: device boots, checkpoints can be committed or rolled back with and
without this parameter, parameter is accepted
Change-Id: I6fcb9bc21353a16ae0bf8998ffa22094eb1cbf3a
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2020-06-08 17:07:02 +00:00
hyeongseok.kim
ca986e448c ANDROID: dm-bow: Fix not to skip trim at framented range
If free blocks hole is smaller than discard_granularity,
TRIM to this range can be skipped.
Fix this by changing the granularity to 4kb at dm-bow layer,
not to skip TRIM to every tiny free blocks.

Bug: 154411183
Signed-off-by: hyeongseok.kim <hyeongseok@gmail.com>
Cc: hyeongseok.kim <hyeongseok.kim@lge.com>
Change-Id: Ic7c33d94a016d0ad5a75514eae1056c328c9c1ba
2020-04-21 16:15:54 +09:00
Dylan Chang
feff0b2236 ANDROID: dm-bow: Fix free_show value is incorrect
Fix free_show value is incorrect

Change-Id: If7f36a64afa600c980ee8a25393f8716a6ffd474
Signed-off-by: Dylan Chang <dylan.chang@oneplus.com>
Bug: 152116739
2020-03-26 16:04:21 +00:00
Eric Biggers
47c6ba1030 ANDROID: dm: enable may_passthrough_inline_crypto on some targets
dm-linear obviously can pass through inline crypto support.

In addition, we need dm-bow to pass through inline crypto support, as
the userdata partition in Android may be located on top of dm-bow.

Bug: 137270441
Change-Id: Ib9b0f67b77391fa450394568ceed441c1508de6e
Signed-off-by: Eric Biggers <ebiggers@google.com>
2020-01-24 10:53:45 -08:00
Paul Lawrence
d00a21b8eb ANDROID: dm-bow: Fix 32 bit compile errors
See https://www.kernel.org/doc/html/v4.17/core-api/printk-formats.html

Also 64-bit modulus not defined on 32-bit architectures

Test: i386_defconfig and x86_64_cuttlefish_defconfig compile
Change-Id: I57b9372e12e97b9a18232191b525e7601bc57a24
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2019-05-03 10:44:55 -07:00
Paul Lawrence
0ce3eb37e9 ANDROID: dm-bow: Add dm-bow feature
Based on https://www.redhat.com/archives/dm-devel/2019-March/msg00025.html

Third version of dm-bow. Key changes:

Free list added
Support for block sizes other than 4k
Handles writes during trim phase, and overlapping trims
Integer overflow error
Support trims even if underlying device doesn't
Numerous small bug fixes

bow == backup on write

USE CASE:

dm-bow takes a snapshot of an existing file system before mounting.
The user may, before removing the device, commit the snapshot.
Alternatively the user may remove the device and then run a command
line utility to restore the device to its original state.

dm-bow does not require an external device

dm-bow efficiently uses all the available free space on the file system.

IMPLEMENTATION:

dm-bow can be in one of three states.

In state one, the free blocks on the device are identified by issuing
an FSTRIM to the filesystem.

In state two, any writes cause the overwritten data to be backup up
to the available free space. While in this state, the device can be
restored by unmounting the filesystem, removing the dm-bow device
and running a usermode tool over the underlying device.

In state three, the changes are committed, dm-bow is in pass-through
mode and the drive can no longer be restored.

It is planned to use this driver to enable restoration of a failed
update attempt on Android devices using ext4.

Test: Can boot Android with userdata mounted on this device. Can commit
userdata after SUW has run. Can then reboot, make changes and roll back.

Known issues:

Mutex is held around entire flush operation, including lengthy I/O. Plan
is to convert to state machine with pending queues.

Interaction with block encryption is unknown, especially with respect
to sector 0.

Bug: 119769411
Bug: 129280212
Test: Dogfooded on Wahoo.
      Ran under Cuttlefish, running VtsKernelBowTest &
      VtsKernelCheckpointTest tests against 4.19, 4.14 & 4.9 kernels
Change-Id: Id70988bbd797ebe3e76fc175094388b423c8da8c
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2019-05-03 10:44:54 -07:00