[PATCH] nvmet-tcp: Don't kmap() pages which can't come from HIGHMEM

Keith Busch kbusch at kernel.org
Wed Aug 17 10:44:20 PDT 2022


On Wed, Aug 17, 2022 at 07:04:27PM +0200, Fabio M. De Francesco wrote:
> @@ -329,7 +312,6 @@ static void nvmet_tcp_map_pdu_iovec(struct nvmet_tcp_cmd *cmd)
>  	u32 length, offset, sg_offset;
>  
>  	length = cmd->pdu_len;
> -	cmd->nr_mapped = DIV_ROUND_UP(length, PAGE_SIZE);
>  	offset = cmd->rbytes_done;
>  	cmd->sg_idx = offset / PAGE_SIZE;
>  	sg_offset = offset % PAGE_SIZE;
> @@ -338,7 +320,7 @@ static void nvmet_tcp_map_pdu_iovec(struct nvmet_tcp_cmd *cmd)
>  	while (length) {
>  		u32 iov_len = min_t(u32, length, sg->length - sg_offset);
>  
> -		iov->iov_base = kmap(sg_page(sg)) + sg->offset + sg_offset;
> +		iov->iov_base = page_address(sg_page(sg)) + sg->offset + sg_offset;
>  		iov->iov_len = iov_len;
>  
>  		length -= iov_len;
> @@ -347,8 +329,7 @@ static void nvmet_tcp_map_pdu_iovec(struct nvmet_tcp_cmd *cmd)
>  		sg_offset = 0;
>  	}
>  
> -	iov_iter_kvec(&cmd->recv_msg.msg_iter, READ, cmd->iov,
> -		cmd->nr_mapped, cmd->pdu_len);
> +	iov_iter_kvec(&cmd->recv_msg.msg_iter, READ, cmd->iov, 0, cmd->pdu_len);
>  }

I earlier meant just use a local variable for 'nr_mapped' rather than replace
it with '0'. I don't think that 0 segments would result in usable kvec.

I'm not even sure the existing code is correct, though. The sg->length can be
higher order than a PAGE_SIZE, so it may be over-reporting nr_segs. It's just
supposed to be the number of initialized iov's.

Anway, the rest looks good.



More information about the Linux-nvme mailing list