Commit 0095e2b9 authored by Jim Harris's avatar Jim Harris
Browse files

bdev/nvme: account for 2MB straddle in queued_next_sge()



This function needs to check for SGEs that straddle a
2MB page boundary, and ensure it does not return
a length that will cross that boundary.

This cannot happen in practice currently with SPDK
since all buffers are allocated using rte_malloc(),
but an upcoming vhost-scsi target may produce
SGEs from a guest VM's physical memory that span
a 2MB boundary.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I8b83c7c39c4cf33815abb22ff2ebc90941b21e28
parent aac30ff3
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -639,6 +639,10 @@ queued_reset_sgl(void *ref, uint32_t sgl_offset)
	}
}

#define min(a, b) (((a)<(b))?(a):(b))

#define _2MB_OFFSET(ptr)	(((uintptr_t)ptr) &  (0x200000 - 1))

static int
queued_next_sge(void *ref, void **address, uint32_t *length)
{
@@ -658,6 +662,8 @@ queued_next_sge(void *ref, void **address, uint32_t *length)
		*length -= bio->iov_offset;
	}

	*length = min(*length, 0x200000 - _2MB_OFFSET(*address));

	bio->iov_offset += *length;
	if (bio->iov_offset == iov->iov_len) {
		bio->iovpos++;