Skip to contentSkip to conversation

Q about dm-verity per bio data

DISCUSSION Mike Snitzer 2 participants 3 messages Jul 10, 2018 1 message not in the archive Device mapper

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 26 lines · On Tue, Jul 10 2018 at 8:58am -0400, [email protected]…

Hi Mike and Milan,
I'd like to consult with you,
I'm trying to rewrite a patch I submitted few month ago according to comments I got, Eric Bigger asked my to adopt the method used in dm-crypt for dynamic allocations. ([dm-devel] [PATCH 2/2] md: dm-verity: allow parallel processing of bio blocks)

I saw you rewrite lately in verity_ctr (dm-verity-target.c) the alignment and the calculation of ti->per_io_data_size, and also did similar modification at crypt_ctr, in dm-crypt.c And I suspect it's the source of my problem.

In my new patch edition as a preparation for parallelization of requests I've added new structure (dm_verity_request ) to the end of dm-verity "per bio data" area. And enlarged accordingly the size of per_io_data_size

I keep getting kernel panic such as " bad PC value" or cpu salls. I guess there's something related to alignment that is missing

Here my code (it's not the complete patch I intend to submit) but it demonstrate my modification and triggers the mentioned panics:

Please let me know if you see any issues with alignment or per_io_data_size size calculation that is missing. Thank you,
Yael

drivers/md/dm-verity-target.c +0 -0
index 0cb81c7ed2bb..8d6fbe1a1ae2 100644

drivers/md/dm-verity-target.c static void verity_for_io_block(struct dm_verity *v, struct dm_verity_io *io, · line 364

Quoted 6 lines
drivers/md/dm-verity-target.c +0 -0
@@ -359,6 +359,7 @@ static void verity_for_io_block(struct dm_verity *v, struct dm_verity_io *io,
         * until you consider the typical block size is 4,096B.
         * Going through this loops twice should be very rare.
         */
        sg_set_page(&sg[*nents], bv.bv_page, len, bv.bv_offset);
 
        bio_advance_iter(bio, iter, len);

This hunk doesn't have any change.. and in general when I attempt to apply the patch I get:

patching file drivers/md/dm-verity-target.c
patch: **** malformed patch at line 33: @@ -447,6 +448,10 @@ static int verity_verify_io(struct dm_verity_io *io)

Quoted 12 lines
drivers/md/dm-verity-target.c +4 -0
@@ -447,6 +448,10 @@ static int verity_verify_io(struct dm_verity_io *io)
                unsigned int total_len = 0;
                sector_t cur_block = io->block + b;
                struct ahash_request *req = verity_io_hash_req(v, io);
+               struct dm_verity_request *vreq = verity_io_req(io);
+
+               vreq->sg = sg;
+               vreq->cur_block = cur_block;
 
                if (v->validated_blocks &&
                    likely(test_bit(cur_block, v->validated_blocks))) {

drivers/md/dm-verity-target.c static int verity_map(struct dm_target *ti, struct bio *bio) · line 652

Quoted 7 lines
drivers/md/dm-verity-target.c +1 -0
@@ -641,6 +646,7 @@ static int verity_map(struct dm_target *ti, struct bio *bio)
        bio->bi_end_io = verity_end_io;
        bio->bi_private = io;
        io->iter = bio->bi_iter;
+       io->vreq = (struct dm_verity_request *)((struct dm_verity_fec_io *)verity_io_digest_end(v, io) + 1);
 
        verity_fec_init_io(io);
 

The above looks very wrong, 2 issues I'm seeing:

1)
your new 'struct dm_verity_request' follows the 'want_digest' in 'struct dm_verity_io' right?

So why are you then advancing from 'want_digest' by 'struct dm_verity_fec_io' to point to (struct dm_verity_request *)!?

'struct dm_verity_fec_io' would still follow all the per-bio-data associated with 'struct dm_verity_io'.

And doesn't dm-verity-fec.c:fec_io() need updating so that it skips over your 'struct dm_verity_io'?

You need to introduce new helpers, something like this:

drivers/md/dm-verity-fec.c +1 -1
index 684af08d0747..f3922421d58d 100644
@@ -28,7 +28,7 @@ bool verity_fec_is_enabled(struct dm_verity *v)
  */
 static inline struct dm_verity_fec_io *fec_io(struct dm_verity_io *io)
 {
-	return (struct dm_verity_fec_io *) verity_io_digest_end(io->v, io);
+	return (struct dm_verity_fec_io *) verity_io_end(io);
 }
 
 /*
drivers/md/dm-verity.h +11 -0
index 3441c10b840c..937d580adf0b 100644
@@ -115,6 +115,17 @@ static inline u8 *verity_io_digest_end(struct dm_verity *v,
 	return verity_io_want_digest(v, io) + v->digest_size;
 }
 
+static inline struct dm_verity_request *verity_io_req(struct dm_verity_io *io)
+{
+	return (struct dm_verity_request *) verity_io_digest_end(io->v, io);
+}
+
+static inline void *verity_io_end(struct dm_verity_io *io)
+{
+	struct dm_verity_request *io_req = verity_io_req(io);
+	return io_req + 1;
+}
+
 extern int verity_for_bv_block(struct dm_verity *v, struct dm_verity_io *io,
 			       struct bvec_iter *iter,
 			       int (*process)(struct dm_verity *v,

2)
There is no need to add 'struct dm_verity_request *vreq;' to 'struct dm_verity_io':

Quoted 12 lines
drivers/md/dm-verity.h +1 -1
index 3441c10b840c..6ccf6f215fe3 100644
@@ -78,19 +78,31 @@ struct dm_verity_io {
        struct bvec_iter iter;
 
        struct work_struct work;
-
+       struct dm_verity_request *vreq;
        /*
         * Three variably-size fields follow this struct:

drivers/md/dm-verity.h struct dm_verity_io { · line 92

Quoted 10 lines
drivers/md/dm-verity.h +1 -1
         *
         * u8 hash_req[v->ahash_reqsize];
         * u8 real_digest[v->digest_size];
         * u8 want_digest[v->digest_size];
-        *
+        * struct dm_verity_request
         * To access them use: verity_io_hash_req(), verity_io_real_digest()
         * and verity_io_want_digest().
         */
 };

Just access it using the correct verity_io_req().

#2 lore raw
Quoted 54 lines

-----Original Message-----
From: Mike Snitzer <[email protected]>
Sent: Tuesday, 10 July 2018 19:30
To: [email protected]
Cc: 'Milan Broz' <[email protected]>; Yael Chemla <[email protected]>; [email protected]
Subject: Re: Q about dm-verity per bio data

Quoted 4 lines · On Tue, Jul 10 2018 at 8:58am -0400, [email protected]…

Hi Mike and Milan,
I'd like to consult with you,
I'm trying to rewrite a patch I submitted few month ago according to comments I got, Eric Bigger asked my to adopt the method used in dm-

crypt for dynamic allocations.

Quoted 5 lines

([dm-devel] [PATCH 2/2] md: dm-verity: allow parallel processing of bio blocks)

I saw you rewrite lately in verity_ctr (dm-verity-target.c) the alignment and the calculation of ti->per_io_data_size, and also did similar

modification at crypt_ctr, in dm-crypt.c And I suspect it's the source of my problem.

Quoted 2 lines

In my new patch edition as a preparation for parallelization of requests I've

added new structure (dm_verity_request ) to the end of dm-verity "per bio data" area.

Quoted 6 lines

And enlarged accordingly the size of per_io_data_size

I keep getting kernel panic such as " bad PC value" or cpu salls. I guess there's something related to alignment that is missing

Here my code (it's not the complete patch I intend to submit) but it

demonstrate my modification and triggers the mentioned panics:

Quoted 2 lines

Please let me know if you see any issues with alignment or

per_io_data_size size calculation that is missing.

drivers/md/dm-verity-target.c static void verity_for_io_block(struct dm_verity *v,

Quoted 9 lines

Thank you,
Yael

(quoted diff) +0 -0

b/drivers/md/dm-verity-target.c index 0cb81c7ed2bb..8d6fbe1a1ae2 100644

drivers/md/dm-verity-target.c +0 -0
@@ -359,6 +359,7 @@ static void verity_for_io_block(struct dm_verity *v,

struct dm_verity_io *io,

Quoted 5 lines
drivers/md/dm-verity-target.c +0 -0
         * until you consider the typical block size is 4,096B.
         * Going through this loops twice should be very rare.
         */
        sg_set_page(&sg[*nents], bv.bv_page, len, bv.bv_offset);
 
Quoted 9 lines

drivers/md/dm-verity-target.c static void verity_for_io_block(struct dm_verity *v, · line 364

Quoted 1 line
drivers/md/dm-verity-target.c +0 -0
        bio_advance_iter(bio, iter, len);

This hunk doesn't have any change.. and in general when I attempt to apply the patch I get:

patching file drivers/md/dm-verity-target.c
patch: **** malformed patch at line 33: @@ -447,6 +448,10 @@ static int verity_verify_io(struct dm_verity_io *io)

I minimized my patch to only the structure addition to per bio data, all the rest was omitted. I wanted to consult with you on this matter only. And I'm sorry for sending diff between files instead of a patch format, moreover there's a patch that comes before it, therfore you got this hunk.

Quoted 19 lines
Quoted 11 lines
drivers/md/dm-verity-target.c +4 -0
@@ -447,6 +448,10 @@ static int verity_verify_io(struct dm_verity_io *io)
                unsigned int total_len = 0;
                sector_t cur_block = io->block + b;
                struct ahash_request *req = verity_io_hash_req(v, io);
+               struct dm_verity_request *vreq = verity_io_req(io);
+
+               vreq->sg = sg;
+               vreq->cur_block = cur_block;
 
                if (v->validated_blocks &&
                    likely(test_bit(cur_block, v->validated_blocks)))
Quoted 1 line

{ @@ -641,6 +646,7 @@ static int verity_map(struct dm_target *ti, struct

bio *bio)

Quoted 6 lines
        bio->bi_end_io = verity_end_io;
        bio->bi_private = io;
        io->iter = bio->bi_iter;

+ io->vreq = (struct dm_verity_request *)((struct
+ dm_verity_fec_io *)verity_io_digest_end(v, io) + 1);

Quoted 8 lines
Quoted 2 lines
        verity_fec_init_io(io);

The above looks very wrong, 2 issues I'm seeing:

1)
your new 'struct dm_verity_request' follows the 'want_digest' in 'struct dm_verity_io' right?

You're right currently documentation is misleading, it's actually after everything that resides in per bio data. thus dmverity per bio data looks as follows:

u8 hash_req[v->ahash_reqsize];
u8 real_digest[v->digest_size];
u8 want_digest[v->digest_size];
struct dm_verity_fec_io ;
struct dm_verity_request;

therefore io->vreq is set to location after fec_io structure at per bio memory area (see verity_map).

Quoted 45 lines

So why are you then advancing from 'want_digest' by 'struct dm_verity_fec_io' to point to (struct dm_verity_request *)!?

'struct dm_verity_fec_io' would still follow all the per-bio-data associated with 'struct dm_verity_io'.

And doesn't dm-verity-fec.c:fec_io() need updating so that it skips over your 'struct dm_verity_io'?

You need to introduce new helpers, something like this:

drivers/md/dm-verity-fec.c index renamed from drivers/md/dm-verity-fec.c +0 -0

684af08d0747..f3922421d58d 100644

drivers/md/dm-verity-fec.c +1 -1
@@ -28,7 +28,7 @@ bool verity_fec_is_enabled(struct dm_verity *v)
  */
 static inline struct dm_verity_fec_io *fec_io(struct dm_verity_io *io)  {
-	return (struct dm_verity_fec_io *) verity_io_digest_end(io->v, io);
+	return (struct dm_verity_fec_io *) verity_io_end(io);
 }
 
 /*
drivers/md/dm-verity.h index renamed from drivers/md/dm-verity.h +0 -0

3441c10b840c..937d580adf0b 100644

drivers/md/dm-verity.h +9 -0
@@ -115,6 +115,17 @@ static inline u8 *verity_io_digest_end(struct
 dm_verity *v,
 	return verity_io_want_digest(v, io) + v->digest_size;  }
 
+static inline struct dm_verity_request *verity_io_req(struct
+dm_verity_io *io) {
+	return (struct dm_verity_request *) verity_io_digest_end(io->v, io); }
+
+static inline void *verity_io_end(struct dm_verity_io *io) {
+	struct dm_verity_request *io_req = verity_io_req(io);
+	return io_req + 1;
+}
+
 extern int verity_for_bv_block(struct dm_verity *v, struct dm_verity_io *io,
 			       struct bvec_iter *iter,
 			       int (*process)(struct dm_verity *v,
Quoted 4 lines

2)
There is no need to add 'struct dm_verity_request *vreq;' to 'struct dm_verity_io':

vreq pointer is preparation for same solution as in dm-crypt, where there's a pointer to the request structure either located at per bio memory area, or dynimicly allocated request, see ctx->r.req (dm-crypt.c at crypt_alloc_req_skcipher)
so when certain cipher is done asynchronously (see in crypt_convert handling of -EINPROGRESS) this pointer will point to a dynamically allocated request, while async cipher will be satisfied with the single request structure resides at per bio area.

Quoted 24 lines
Quoted 12 lines
drivers/md/dm-verity.h index renamed from drivers/md/dm-verity.h +0 -0

3441c10b840c..6ccf6f215fe3 100644

drivers/md/dm-verity.h +1 -1
@@ -78,19 +78,31 @@ struct dm_verity_io {
        struct bvec_iter iter;
 
        struct work_struct work;
-
+       struct dm_verity_request *vreq;
        /*
         * Three variably-size fields follow this struct:

drivers/md/dm-verity.h struct dm_verity_io { · line 92

Quoted 10 lines
drivers/md/dm-verity.h +1 -1
         *
         * u8 hash_req[v->ahash_reqsize];
         * u8 real_digest[v->digest_size];
         * u8 want_digest[v->digest_size];
-        *
+        * struct dm_verity_request
         * To access them use: verity_io_hash_req(), verity_io_real_digest()
         * and verity_io_want_digest().
         */
 };

Just access it using the correct verity_io_req().

#3 lore raw
Quoted 39 lines · On Tue, Jul 10 2018 at 1:33pm -0400, [email protected]…
Quoted 39 lines

-----Original Message-----
From: Mike Snitzer <[email protected]>
Sent: Tuesday, 10 July 2018 19:30
To: [email protected]
Cc: 'Milan Broz' <[email protected]>; Yael Chemla <[email protected]>; [email protected]
Subject: Re: Q about dm-verity per bio data

Quoted 4 lines · On Tue, Jul 10 2018 at 8:58am -0400, [email protected]…

Hi Mike and Milan,
I'd like to consult with you,
I'm trying to rewrite a patch I submitted few month ago according to comments I got, Eric Bigger asked my to adopt the method used in dm-

crypt for dynamic allocations.

Quoted 5 lines

([dm-devel] [PATCH 2/2] md: dm-verity: allow parallel processing of bio blocks)

I saw you rewrite lately in verity_ctr (dm-verity-target.c) the alignment and the calculation of ti->per_io_data_size, and also did similar

modification at crypt_ctr, in dm-crypt.c And I suspect it's the source of my problem.

Quoted 2 lines

In my new patch edition as a preparation for parallelization of requests I've

added new structure (dm_verity_request ) to the end of dm-verity "per bio data" area.

Quoted 6 lines

And enlarged accordingly the size of per_io_data_size

I keep getting kernel panic such as " bad PC value" or cpu salls. I guess there's something related to alignment that is missing

Here my code (it's not the complete patch I intend to submit) but it

demonstrate my modification and triggers the mentioned panics:

Quoted 2 lines

Please let me know if you see any issues with alignment or

per_io_data_size size calculation that is missing.

...

Quoted 31 lines
Quoted 19 lines
Quoted 11 lines
(quoted diff) +4 -0
@@ -447,6 +448,10 @@ static int verity_verify_io(struct dm_verity_io *io)
                unsigned int total_len = 0;
                sector_t cur_block = io->block + b;
                struct ahash_request *req = verity_io_hash_req(v, io);
+               struct dm_verity_request *vreq = verity_io_req(io);
+
+               vreq->sg = sg;
+               vreq->cur_block = cur_block;
 
                if (v->validated_blocks &&
                    likely(test_bit(cur_block, v->validated_blocks)))
Quoted 1 line

{ @@ -641,6 +646,7 @@ static int verity_map(struct dm_target *ti, struct

bio *bio)

Quoted 6 lines
        bio->bi_end_io = verity_end_io;
        bio->bi_private = io;
        io->iter = bio->bi_iter;

+ io->vreq = (struct dm_verity_request *)((struct
+ dm_verity_fec_io *)verity_io_digest_end(v, io) + 1);

Quoted 8 lines
Quoted 2 lines
        verity_fec_init_io(io);

The above looks very wrong, 2 issues I'm seeing:

1)
your new 'struct dm_verity_request' follows the 'want_digest' in 'struct dm_verity_io' right?

You're right currently documentation is misleading, it's actually after everything that resides in per bio data. thus dmverity per bio data looks as follows:

Quoted 7 lines

u8 hash_req[v->ahash_reqsize];
u8 real_digest[v->digest_size];
u8 want_digest[v->digest_size];
struct dm_verity_fec_io ;
struct dm_verity_request;

therefore io->vreq is set to location after fec_io structure at per bio memory area (see verity_map).

Ah, OK, yes I see this now in verity_fec_ctr():

        /* Reserve space for our per-bio data */
        ti->per_io_data_size += sizeof(struct dm_verity_fec_io);

Given that, I'm not sure why your code is crashing.

Quoted 5 lines
Quoted 4 lines

2)
There is no need to add 'struct dm_verity_request *vreq;' to 'struct dm_verity_io':

Quoted 8 lines

vreq pointer is preparation for same solution as in dm-crypt, where there's a pointer to the request structure either located at per bio memory area, or dynimicly allocated request, see ctx->r.req (dm-crypt.c at crypt_alloc_req_skcipher)
so when certain cipher is done asynchronously (see in crypt_convert handling of -EINPROGRESS) this pointer will point to a dynamically allocated request, while async cipher will be satisfied with the single request structure resides at per bio area.

OK.