Skip to content

Commit df326e7

Browse files
author
Mike Snitzer
committed
dm verity: allow optional args to alter primary args handling
The previous commit ("dm verity: Add optional "try_verify_in_tasklet" feature") imposed that CRYPTO_ALG_ASYNC mask be used even if the optional "try_verify_in_tasklet" feature was not specified. This was because verity_parse_opt_args() was called after handling the primary args (due to it having data dependencies on having first parsed all primary args). Enhance verity_ctr() so that simple optional args, that don't have a data dependency on primary args parsing, can alter how the primary args are handled. In practice this means verity_parse_opt_args() gets called twice. First with the new 'only_modifier_opts' arg set to true, then again with it set to false _after_ parsing all primary args. This allows the v->use_tasklet flag to be properly set and then used when verity_ctr() parses the primary args and then calls crypto_alloc_ahash() with CRYPTO_ALG_ASYNC conditionally set. Signed-off-by: Mike Snitzer <[email protected]>
1 parent 5721d4e commit df326e7

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

drivers/md/dm-verity-target.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,8 @@ static int verity_parse_verity_mode(struct dm_verity *v, const char *arg_name)
10271027
}
10281028

10291029
static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
1030-
struct dm_verity_sig_opts *verify_args)
1030+
struct dm_verity_sig_opts *verify_args,
1031+
bool only_modifier_opts)
10311032
{
10321033
int r;
10331034
unsigned argc;
@@ -1050,6 +1051,8 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
10501051
argc--;
10511052

10521053
if (verity_is_verity_mode(arg_name)) {
1054+
if (only_modifier_opts)
1055+
continue;
10531056
r = verity_parse_verity_mode(v, arg_name);
10541057
if (r) {
10551058
ti->error = "Conflicting error handling parameters";
@@ -1058,6 +1061,8 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
10581061
continue;
10591062

10601063
} else if (!strcasecmp(arg_name, DM_VERITY_OPT_IGN_ZEROES)) {
1064+
if (only_modifier_opts)
1065+
continue;
10611066
r = verity_alloc_zero_digest(v);
10621067
if (r) {
10631068
ti->error = "Cannot allocate zero digest";
@@ -1066,6 +1071,8 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
10661071
continue;
10671072

10681073
} else if (!strcasecmp(arg_name, DM_VERITY_OPT_AT_MOST_ONCE)) {
1074+
if (only_modifier_opts)
1075+
continue;
10691076
r = verity_alloc_most_once(v);
10701077
if (r)
10711078
return r;
@@ -1076,12 +1083,16 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
10761083
continue;
10771084

10781085
} else if (verity_is_fec_opt_arg(arg_name)) {
1086+
if (only_modifier_opts)
1087+
continue;
10791088
r = verity_fec_parse_opt_args(as, v, &argc, arg_name);
10801089
if (r)
10811090
return r;
10821091
continue;
10831092

10841093
} else if (verity_verify_is_sig_opt_arg(arg_name)) {
1094+
if (only_modifier_opts)
1095+
continue;
10851096
r = verity_verify_sig_parse_opt_args(as, v,
10861097
verify_args,
10871098
&argc, arg_name);
@@ -1148,6 +1159,15 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
11481159
goto bad;
11491160
}
11501161

1162+
/* Parse optional parameters that modify primary args */
1163+
if (argc > 10) {
1164+
as.argc = argc - 10;
1165+
as.argv = argv + 10;
1166+
r = verity_parse_opt_args(&as, v, &verify_args, true);
1167+
if (r < 0)
1168+
goto bad;
1169+
}
1170+
11511171
if (sscanf(argv[0], "%u%c", &num, &dummy) != 1 ||
11521172
num > 1) {
11531173
ti->error = "Invalid version";
@@ -1219,11 +1239,8 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
12191239
goto bad;
12201240
}
12211241

1222-
/*
1223-
* FIXME: CRYPTO_ALG_ASYNC should be conditional on v->use_tasklet
1224-
* but verity_parse_opt_args() happens below and has data dep on tfm.
1225-
*/
1226-
v->tfm = crypto_alloc_ahash(v->alg_name, 0, CRYPTO_ALG_ASYNC);
1242+
v->tfm = crypto_alloc_ahash(v->alg_name, 0,
1243+
v->use_tasklet ? CRYPTO_ALG_ASYNC : 0);
12271244
if (IS_ERR(v->tfm)) {
12281245
ti->error = "Cannot initialize hash function";
12291246
r = PTR_ERR(v->tfm);
@@ -1285,8 +1302,7 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
12851302
if (argc) {
12861303
as.argc = argc;
12871304
as.argv = argv;
1288-
1289-
r = verity_parse_opt_args(&as, v, &verify_args);
1305+
r = verity_parse_opt_args(&as, v, &verify_args, false);
12901306
if (r < 0)
12911307
goto bad;
12921308
}

0 commit comments

Comments
 (0)