Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
493 changes: 441 additions & 52 deletions drivers/misc/apple-h2fmi-ro.c

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions drivers/mtd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ config MTD_APPLE_SFTL
read-only as partitions of a second disk, applesftlNlwvm, with their
LwVM number, PARTUUID and name.

config MTD_APPLE_SFTL_J2A_WRITE
bool "Fenced writes to iPad 3 64 GB PPN 1.3 Linux LwVM partitions"
depends on MTD_APPLE_SFTL
default n
help
Allow the SFTL writer on the iPad 3 (j2a) 64 GB PPN 1.3 (8 KiB,
lpp=2) geometry. Block writes are strictly fenced to validated
contiguous Linux or XBOOTLDR LwVM partition chunks; iOS System and
Data partitions, free chunks and the LwVM header remain read-only.
Raw MTD writes stay disabled. Say N for a read-only kernel.

config MTD_APPLE_SFTL_KUNIT_TEST
tristate "KUnit tests for Apple VFL/SwissPPNFTL" if !KUNIT_ALL_TESTS
depends on KUNIT && MTD_APPLE_SFTL
Expand Down
75 changes: 75 additions & 0 deletions drivers/mtd/apple-sftl-account-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,88 @@ static void account_native_free_allocation(struct kunit *test)
KUNIT_EXPECT_EQ(test, plan.landing, 7);
}

static void account_64gb_8k_lpp2(struct kunit *test)
{
struct apple_sftl_layout layout;
struct apple_sftl_extent runs[] = {
{ 0, 2, 100 * APPLE_SFTL_STRIDE },
{ 2, APPLE_SFTL_LOGICAL_PAGES - 3, APPLE_SFTL_NO_ADDRESS },
{ APPLE_SFTL_LOGICAL_PAGES - 1, 1, 2056 * APPLE_SFTL_STRIDE + 1 },
};
struct apple_sftl_snapshot map = {
.runs = runs, .nr_runs = ARRAY_SIZE(runs),
.subblocks = APPLE_SFTL_64GB_8K_SUBBLOCKS, .lpp = 2,
};
struct apple_sftl_checkpoint image = {};
struct apple_sftl_allocation plan = {};
u8 footer_2[APPLE_SFTL_META] = { 0x1c, 4 }; /* 2 chunks (1 x 8 KiB page) */
u8 *stats, *sb0, *sb100, *sb2056, *reads;
u32 blocks[] = { 802, 830 };
u32 i;

KUNIT_ASSERT_TRUE(test, apple_sftl_layout_for(APPLE_SFTL_64GB_8K_SUBBLOCKS, 2, &layout));
KUNIT_EXPECT_EQ(test, layout.lpp, (u8)2);
KUNIT_EXPECT_EQ(test, layout.stats_start, 2U);
KUNIT_EXPECT_EQ(test, layout.sb_start, 4U);
KUNIT_EXPECT_EQ(test, layout.user_seq_start, 10U);
KUNIT_EXPECT_EQ(test, layout.read_count_start, 20U);
KUNIT_EXPECT_EQ(test, layout.opaque_records, APPLE_SFTL_64GB_8K_ACCOUNT_RECORDS);

/* 24 opaque + 32 map = 56 records (matches measured live 64 GB iPad3,3). */
image.count = APPLE_SFTL_64GB_8K_ACCOUNT_RECORDS + 32;
image.records = kunit_kcalloc(test, image.count, sizeof(*image.records), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, image.records);
apple_sftl_test_native_prefix_64gb_8k(image.records);
for (i = APPLE_SFTL_64GB_8K_ACCOUNT_RECORDS; i < image.count; i++) {
image.records[i].meta[0] = 0x1f;
image.records[i].meta[1] = 4;
put_unaligned_le32(U32_MAX, image.records[i].meta + 12);
}
stats = image.records[2].data;
sb0 = image.records[4].data;
sb100 = sb0 + 100 * 8;
sb2056 = image.records[8].data + 8 * 8; /* 2056 - 2048 = 8 */

/* Verify valid LBA recomputation across 2057 subblocks. */
KUNIT_ASSERT_EQ(test, apple_sftl_account_map(&image, &map), 0);
KUNIT_EXPECT_EQ(test, get_unaligned_le16(sb100 + 2), 2);
KUNIT_EXPECT_EQ(test, get_unaligned_le16(sb2056 + 2), 1);
KUNIT_EXPECT_EQ(test, get_unaligned_le64(stats + TEST_VALID_STAT_OFFSET), 3ULL);

/* Verify 2-chunk BTOC footer (lpp=2) retire and release. */
sb100[0] = 3;
sb100[1] = 4; /* chunks=2 << 1 */
put_unaligned_le16(0, sb100 + 2);
put_unaligned_le16(71, sb100 + 6);
reads = image.records[20].data + 100 * 4;
put_unaligned_le32(42, reads);
put_unaligned_le16(2, footer_2 + 12);
put_unaligned_le16(0xffff, footer_2 + 14);
KUNIT_ASSERT_EQ(test, apple_sftl_account_retire(&image, 100, footer_2), 0);
KUNIT_EXPECT_EQ(test, sb100[0], (u8)9);
KUNIT_EXPECT_EQ(test, get_unaligned_le32(reads), 0U);
KUNIT_ASSERT_EQ(test, apple_sftl_account_release(&image, 100, APPLE_SFTL_ERASED_DONOR), 0);
KUNIT_EXPECT_EQ(test, sb100[0], (u8)1);
KUNIT_EXPECT_EQ(test, get_unaligned_le16(sb100 + 6), 72);

/* Verify context pair and free-block allocation on 24-record prefix. */
image.records[4 + 802 / 512].data[(802 % 512) * 8] = 7;
image.records[4 + 830 / 512].data[(830 % 512) * 8] = 7;
map.opaque = image.records;
map.nr_opaque = APPLE_SFTL_64GB_8K_ACCOUNT_RECORDS;
KUNIT_EXPECT_TRUE(test, apple_sftl_account_context_pair(&map, blocks));
KUNIT_ASSERT_EQ(test, apple_sftl_account_plan_allocation(&map, &plan), 0);
KUNIT_EXPECT_EQ(test, plan.landing, 100);
}

static struct kunit_case account_cases[] = {
KUNIT_CASE(account_recompute_valid_lbas),
KUNIT_CASE(account_invalid_layout_or_map),
KUNIT_CASE(account_footer_user_sequence),
KUNIT_CASE(account_context_and_retired_donor),
KUNIT_CASE(account_native_free_allocation),
KUNIT_CASE(account_saved_counts_before_refresh),
KUNIT_CASE(account_64gb_8k_lpp2),
{}
};

Expand Down
Loading
Loading