Thread (4 messages) 4 messages, 2 authors, 2017-02-04

Re: Doubt related to immutable biovecs

From: Ming Lei <tom.leiming@gmail.com>
Date: 2017-02-04 07:59:19

On Thu, Feb 2, 2017 at 5:35 PM, Suraj Choudhari
[off-list ref] wrote:
Thanks very much Ming and all !
You are welcome!
I referred to multipage bvec patches link and it was indeed good & insightful.

I have few more query related to immutable bvecs & multipage bvecs, in
particular related to 4.4 kernel --

1) My understanding is bi_vcnt can't be used for a cloned BIO because
'bio_clone_fast' does NOT update the bi_vcnt field in the cloned BIO.
Is my understanding correct ?
Yes and no.

A cloned BIO may just map to a range of vectors from the source bio via
helpers.
2)  For a block device driver, is it be safe to use the 'bi_vcnt' of a
BIO that's received from the upper layers, in order to access the
bvecs array, particularly in the '4.4' kernel ?
No, as we mentioned, it isn't safe to do that, especially after v4.3 introduces
bio splitting, which may cause a block driver to see a cloned bio easily.

Also dm may pass a cloned a bio to block driver too.

So please use bio helpers to iterate the bvec instead of direct access.
     - I am thinking it may be safe to access bi_vcnt as long as the
block driver has NOT received a CLONE bio from upper layer.  The
reason I think can be bvecs are not multipage in 4.4. Is my
understanding right ?
Yes, but why not use use the helpers transparently for both cloned bio
and non-cloned?

Thanks,
Ming
Thanks & Regards,
Suraj




On Fri, Jan 20, 2017 at 9:27 PM, Ming Lei [off-list ref] wrote:
quoted
Hi,

On Fri, Jan 20, 2017 at 9:41 PM, Suraj Choudhari
[off-list ref] wrote:
quoted
Hello,

I've some queries related to accessing the 'bio_vec' and 'bi_vcnt'
members in the BIO structure after the kernel changes implemented for
the 'immutable biovecs' -

Background -
-  From the changes done for the immutable biovecs, I understand that
the driver code now no longer needs to reference the 'bi_vcnt' and
'bi_io_vec' fields directly. Instead we can use the 'bvec_iter'
iterator in order to to access the bio_vec.
-  We've iterator functions bio_iter_iovec() and bio_advance_iter() as
well, which return us literal 'struct biovecs' taking into account the
bi_bvec_done and bi_size values.

Doubts  -
1)  Few functions in the block layer and some drivers still directly
refer to the 'bi_vcnt' and 'bio_vec' members of the BIO structure
[instead of accessing bio_vecs using the bvec_iter iterator].
Would there be some changes in the functions to compulsorily use the
'bvec_iter' in order to access bio_vecs?  If yes, are such changes
Generally speaking, yes, it is always better to use iterator helpers.
quoted
related to the 'multipage biovec' feature ?
Yes, it is a must for supporting multipage bvec.
quoted
2)  Can there be some problem if a driver directly accesses the
bi_io_vec [bio_vec] in the bio structure based on the values of bi_idx
and bi_vcnt ? [instead of using the bvec_iter iterator].
The direct access can't work any more once switching to multipage bvec,
and you can find some hint in the following link:

https://lkml.org/lkml/2017/1/15/266

Also .bi_vcnt can't be used for BIO_CLONED bio, and it is very easy
to make mistakes to access the table directly if someone don't understand
the iterator details enough.


Thanks,
Ming Lei


-- 
Ming Lei
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help