Commit Graph

37 Commits

Author SHA1 Message Date
Paul Lawrence
7fd4fbe615 ANDROID: incremental fs: Move throttling to outside page lock
Bug: 241479010
Test: incfs_test passes, play confirm behavior in bug is fixed
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ie51f2b76d0873057f54fecf7fcc793c66df20969
2023-02-22 17:37:54 +00:00
Paul Lawrence
5d9b0e83e3 ANDROID: incremental fs: Fix race between truncate and write last block
Also fix race whereby multiple providers writinig the same block would
actually write out the same block.

Note that multiple_providers_test started failing when incfs was ported
to 5.15, and these fixes are needed to make the test reliable

Bug: 264703896
Test: incfs-test passes, specifically multiple_providers_test. Ran 100
      times
Change-Id: I05ad5b2b2f62cf218256222cecb79bbe9953bd97
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2023-02-22 17:36:34 +00:00
Tadeusz Struk
3e45af8a72 ANDROID: incremental-fs: limit mount stack depth
Syzbot recently found a number of issues related to incremental-fs
(see bug numbers below). All have to do with the fact that incr-fs
allows mounts of the same source and target multiple times.
This is a design decision and the user space component "Data Loader"
expects this to work for app re-install use case.
The mounting depth needs to be controlled, however, and only allowed
to be two levels deep. In case of more than two mount attempts the
driver needs to return an error.
In case of the issues listed below the common pattern is that the
reproducer calls:

mount("./file0", "./file0", "incremental-fs", 0, NULL)

many times and then invokes a file operation like chmod, setxattr,
or open on the ./file0. This causes a recursive call for all the
mounted instances, which eventually causes a stack overflow and
a kernel crash:

BUG: stack guard page was hit at ffffc90000c0fff8
kernel stack overflow (double-fault): 0000 [#1] PREEMPT SMP KASAN

This change also cleans up the mount error path to properly clean
allocated resources and call deactivate_locked_super(), which
causes the incfs_kill_sb() to be called, where the sb is freed.

Bug: 211066171
Bug: 213140206
Bug: 213215835
Bug: 211914587
Bug: 211213635
Bug: 213137376
Bug: 211161296

Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org>
Change-Id: I08d9b545a2715423296bf4beb67bdbbed78d1be1
2022-04-06 17:24:59 +00:00
Paul Lawrence
b6e60f0673 ANDROID: Incremental fs: Add uid to INCFS_IOC_GET_LAST_READ_ERROR
Bug: 186796876
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I552cae5e87b004202364ba5c9c5f9febb9e106f2
2021-05-17 20:08:43 +00:00
Paul Lawrence
25c3b9e0fe ANDROID: Incremental fs: Make sysfs_name changeable on remount
Bug: 187829246
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I1762f170c8a8a2fb7672f65c402e82ab95aeef8a
2021-05-17 20:08:37 +00:00
Paul Lawrence
acc13a8440 ANDROID: Incremental fs: Add INCFS_IOC_GET_LAST_READ_ERROR
Bug: 184291759
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: If46e91f9c992337d53970573c238be965187761e
2021-04-23 15:16:39 +00:00
Paul Lawrence
6cce4fa251 ANDROID: Incremental fs: Fix INCFS_MAGIC_NUMBER casts
Sparse complains about casting a five byte number to a ulong on 32-bit
platorms. Fix by anding the constant with ULONG_MAX

Bug: 186015158
Test: incfs_test passes, sparse reports no warnings on 32 & 64 bit builds
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic83e03626b7f290370d75b3aaba187b8392fb344
2021-04-23 15:16:32 +00:00
Paul Lawrence
44ffa65110 ANDROID: Incremental fs: Add status to sysfs
Adding seven sysfs entries per mount:

reads_failed_timed_out
reads_failed_hash_verification
reads_failed_other
reads_delayed_pending
reads_delayed_pending_us
reads_delayed_min
reads_delayed_min_us

to allow for status monitoring from userland

Change-Id: I50677511c2af4778ba0c574bb80323f31425b4d0
Test: incfs_test passes
Bug: 160634343
Bug: 184291759
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2021-04-23 15:16:25 +00:00
Paul Lawrence
f4c368a3f9 ANDROID: Incremental fs: Add FS_IOC_READ_VERITY_METADATA
Bug: 180942327
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I6d6532496c072145f22bcf9ff4499ec3f52e94b5
2021-04-23 15:16:03 +00:00
Paul Lawrence
2a8c6b0f30 ANDROID: Incremental fs: Finer readlog compression internally
Bug: 182196484
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Icad395115ad81cc267046f7a41b41046077bb78b
2021-04-01 11:10:22 -07:00
Paul Lawrence
c630401723 ANDROID: Incremental fs: Store fs-verity state in backing file
Now fsverity state is preserved across inode eviction.

Added incfs.verity xattr to track when a file is fs-verity enabled.

Bug: 160634504
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I41d90abd55527884d9eff642c9834ad837ff6918
2021-03-01 16:15:46 +00:00
Paul Lawrence
5bb92dffc9 ANDROID: Incremental fs: Add FS_IOC_ENABLE_VERITY
Add FS_IOC_ENABLE_VERITY ioctl

When called, calculate measurement, validate signature against fsverity,
and set S_VERITY flag.

This does not (yet) preserve the verity status once the inode is
evicted.

Bug: 160634504
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I88af2721f650098accc72a64528c7d85b753c7f6
2021-03-01 16:15:32 +00:00
Yurii Zubrytskyi
b79605a904 ANDROID: Incremental fs: fix .blocks_written
.blocks_writen file handling was missing some operations:
SELinux xattr handlers, safety checks for it being a
pseudo file etc.

This CL generalizes pseudo file handling so that all such
files work in a generic way and next time it should be
easier to add all operations at once.

Bug: 175823975
Test: incfs_tests pass
Change-Id: Id2b1936018c81c62c8ab4cdbaa8827e2679b513f
Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2021-01-14 16:02:38 +00:00
Paul Lawrence
5ef8ab7172 ANDROID: Incremental fs: Change per UID timeouts to microseconds
Bug: 174495152
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Id76d2fec83a0eb7b70ad85f1fac81bf319563a66
2020-12-10 20:16:01 +00:00
Paul Lawrence
95a43fc99f ANDROID: Incremental fs: Add zstd compression support
Bug: 160634783
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Iba28b535d2d5183859ffc721204b036434132d9b
2020-11-05 23:00:32 +00:00
Paul Lawrence
b1cc5f1b63 ANDROID: Incremental fs: Small improvements
Rmove bc_mutex used to protect metadata chain, now that is only
read at file open time
Remove certain unused mount options

Bug: 172482559
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Id70e5a5d08e5de79f391e19ea97e356f39a3ed51
2020-11-05 15:26:48 +00:00
Paul Lawrence
142953a07f ANDROID: Incremental fs: Add per UID read timeouts
Bug: 169056129
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I8cad9ee4095123bafba33abb65bbb339ba6ff8b5
2020-09-28 09:13:12 -07:00
Paul Lawrence
7e7bfa94e5 ANDROID: Incremental fs: Add .incomplete folder
Bug: 165929150
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ib6952391aea76bf0318cbad8da7a1276f8f9e8ba
2020-09-21 14:48:29 +00:00
Paul Lawrence
9cbdd375f6 ANDROID: Incremental fs: Fix filled block count from get filled blocks
Bug: 165929150
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I8845adcafcc3a3f01730e8b5534fb25ea3d551db
2020-09-17 21:19:18 +00:00
Paul Lawrence
c0391ecb55 ANDROID: Incremental fs: Add hash block counts to IOC_IOCTL_GET_BLOCK_COUNT
Bug: 166638631
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I0061a855ec563de8df40ba0b35292e99be33c6c0
2020-09-16 15:44:06 -07:00
Paul Lawrence
d4d1163e53 ANDROID: Incremental fs: Add INCFS_IOC_GET_BLOCK_COUNT
Bug: 166638631
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ia7a8cab87688fc401f0719df84fe79ea75887692
2020-09-16 18:05:34 +00:00
Paul Lawrence
cb776f4576 ANDROID: Incremental fs: Add .blocks_written file
Bug: 162856396
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I942582218cdc7741bcff2f264960b76cdfa1bb36
2020-09-10 10:13:08 -07:00
Paul Lawrence
7ab6cf0fec ANDROID: Incremental fs: Add UID to pending_read
Test: incfs_test passes
Bug: 160634477
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Iaf817cf1f7ccd0109b2114b425ea7f26718345ab
2020-08-19 17:13:16 +00:00
Paul Lawrence
3f4938108a ANDROID: Incremental fs: Create mapped file
Bug: 160634482
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic2ac8dfccd60f6c9c72c38bf323997fce7546c1c
2020-08-18 12:37:59 -07:00
Akilesh Kailash
f39f1b550a ANDROID: Incremental fs: Use R/W locks to read/write segment blockmap.
Use Read-Write locks for reading/writing segment in blockmap.
This should allow parallel reads when there are
multiple reads within same segment.

A small optimization in pending_reads_read(). Since
incfs_collect_pending_reads() already iterate to
populate buffer, new_max_sn - highest serial number
among all the pending read buffer can be done in the same
loop instead of looping again in pending_reads_read().

Bug: 161566104
Test: kernel selftest - incfs_test and incfs_perf

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Id00376b0e4cb8c0c0bc8264cdddd6f38c4aa85f0
2020-07-28 05:11:50 +00:00
Akilesh Kailash
0f406eaea5 ANDROID: Incremental fs: RCU locks instead of mutex for pending_reads.
Use RCU locks instead of pending_reads_mutex.
Current mutex is taking lock on entire mount_info
structure which seems a heavy operation.

Following fields of mount_info structure
are protected through spinlocks for multiple
writers and are RCU safe for readers:

- reads_list_head
- mi_pending_reads_count
- mi_last_pending_read_number
- data_file_segment.reads_list_head

We could probably use atomic_inc/atomic_dec for
mi_pending_reads_count and mi_last_pending_read_number
which can futher cut down spin_locks at couple of more places,
thereby only the list addition and removal can protected
by spinlock. This CL doesn't address it.

Bug: 161565969
Test: kernel selftest incfs_test and incfs_perf

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Iad7439657016764dce25d64c8b3df69b930452bc
2020-07-24 17:35:04 +00:00
Paul Lawrence
60bc6eaf98 ANDROID: Incremental fs: Fix four error-path bugs
Test: incfs_test passes
Bug: 158242405
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ib53e867fb2681489f720f6255354c1bce1d33997
2020-06-08 14:24:39 +00:00
Paul Lawrence
21e6d932da ANDROID: Incremental fs: Cache successful hash calculations
Bug: 155996534
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic508e6fa07c90decb29e07647dd3b0fc4d243ce8
2020-06-04 21:17:47 +00:00
Yurii Zubrytskyi
a34bcc8b20 ANDROID: Incremental fs: wake up log pollers less often
Waking up the waiters accounts for 80+% of the total logging
time, and about 40% of overall read_single_page() with no
signature verification. By throttling it to once every 16ms
we get back all read performance, reduce the waiter's CPU
usage and still leave it enough time to pull the logs out.

Bug: 155996534
Test: adb install megacity.apk & dd from the installed apk

Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I4a118dc226d7ca318cf099ba3e239f0120bb23c2
2020-05-14 14:32:55 +00:00
Paul Lawrence
b6b4a3a404 ANDROID: Incremental fs: Use simple compression in log buffer
Bug: 154342202
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ibcc641dd92596018c9f10b5bc7bd0db2642a80c7
2020-04-24 12:28:45 -07:00
Yurii Zubrytskyi
35deb33fa2 ANDROID: Incremental fs: make remount log buffer change atomic
Read log buffer can have multiple threads doing any of these
operations simultaneously:
- Polling for changes
- Reading log records
- Adding new log records
- Updating log buffer size, or enabling/disabling it completely

As we don't control the userspace, and it turns out that they
all currently originate from different processes, code needs to
be safe against parallel access to a read buffer and a request
for reallocating it.

This CL add an r/w spinlock to protect the buffer and its size.
Each remount takes the write lock, while everything else takes
a read lock. Remount makes sure it doesn't take too long by
preallocating and precalculating all updates, while other
operations don't care much about their critical section size -
they all can still run together.

Bug: 152633648
Test: manual remount + reading
Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I7271b4cb89f1ae2cbee6e5b073758f344c4ba66a
2020-04-08 16:53:20 +00:00
Paul Lawrence
2fb9b719ce ANDROID: Incremental fs: Fix remount
Bug: 153017385
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I13f3a3c91d746d725e0e21b1e2bcfe0a64a13716
2020-04-01 23:32:34 +00:00
Paul Lawrence
8d963bb240 ANDROID: Incremental fs: Add INCFS_IOC_GET_FILLED_BLOCKS
Test: incfs_test passes
Bug: 151240628
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I66d0ba1911adc5d68ed404585222e6a81a7eb94f
2020-03-26 21:02:02 +00:00
Paul Lawrence
bc6a70e849 ANDROID: Incremental fs: Remove signature checks from kernel
Test: selftests pass
Bug: 133435829
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ia7e69b1b0176202da4b418ea815b370cbdacd5c2
2020-03-18 16:22:17 +00:00
Paul Lawrence
21b07a7140 ANDROID: Incremental fs: Make fill block an ioctl
Filling blocks is not equivalent to writing a file, since they are
constrained by the root hash. selinux policy may wish to treat them
differently, for instance.

Test: incfs_test passes
Bug: 138149732
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic369b84b92547b1cfefe422bd881c4e466090aed
2020-03-18 16:21:50 +00:00
Paul Lawrence
2dbb045181 ANDROID: Incremental fs: Support xattrs
To make selinux work, add xattr support. This is a bit clunky -
it seems like it would be better for the log and pending read
functionality to be ioctls rather than this mixture of real
and virtual files.

Bug: 133435829
Change-Id: I56579fabe2ae7efb88f0344553948dc9573299aa
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2020-02-19 21:48:00 +00:00
Eugene Zemtsov
c6819dd778 ANDROID: Initial commit of Incremental FS
Fully working incremental fs filesystem

Signed-off-by: Eugene Zemtsov <ezemtsov@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>

Bug: 133435829
Change-Id: I14741a61ce7891a0f9054e70f026917712cbef78
2020-02-04 04:51:09 +00:00