[PATCH v2] nvmet-tcp: fix data digest calculation for multiple H2CData PDUs

Sagi Grimberg sagi at grimberg.me
Thu Aug 10 02:07:38 PDT 2023



On 8/7/23 18:13, Varun Prakash wrote:
> 
>>> +{
>>> +	struct scatterlist *sg = &cmd->req.sg[cmd->sg_idx];
>>> +	struct bio_vec *iov = cmd->iov;
>>> +	u32 data_length = cmd->pdu_len;
>>> +
>>> +	crypto_ahash_init(hash);
>>> +
>>> +	if (iov->bv_offset) {
>>> +		struct scatterlist first_sg;
>>> +
>>> +		sg_init_table(&first_sg, 1);
>>> +		sg_set_page(&first_sg, sg_page(sg), iov->bv_len,
>>> +				iov->bv_offset);
>>> +
>>> +		data_length -= iov->bv_len;
>>> +
>>> +		if (data_length) {
>>> +			ahash_request_set_crypt(hash, &first_sg, NULL,
>>> +						iov->bv_len);
>>> +			crypto_ahash_update(hash);
>>> +			sg = sg_next(sg);
>>> +		} else {
>>> +			ahash_request_set_crypt(hash, &first_sg,
>>> +					(void *)&cmd->exp_ddgst, iov->bv_len);
>>> +			crypto_ahash_finup(hash);
>>> +			return;
>>> +		}
>>
>> What is the case for data_length=0 ? I'm not entirely clear how this can
>> happen.
> 
> This can happen if H2CData PDU data length is not a multiple of target page size.
> 
> For example if transfer length is 32K, page size is 4K and H2CData PDU data length is 6K,
> host will send 6 H2CData PDUs, for the last PDU iov->bv_offset = 2K,
> iov->bv_len = 2K and data_length = 2K.

I understand.

Looking into this, I'm almost thinking we should just give up and
iterate. at this point it unnecessarily complicates the code...



More information about the Linux-nvme mailing list