aboutsummaryrefslogtreecommitdiffstats
path: root/sys/cam/nvme/nvme_da.c
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2018-03-20 03:37:14 +0000
committerWarner Losh <imp@FreeBSD.org>2018-03-20 03:37:14 +0000
commitafdbfe1e1b5a47db04854f2656357e8aa1505d28 (patch)
tree196878997b23526718a08d4a93c61cf2f78a2abd /sys/cam/nvme/nvme_da.c
parent6f591d13fd9eed58aa183a23f6c7025c163b4de2 (diff)
downloadsrc-afdbfe1e1b5a47db04854f2656357e8aa1505d28.tar.gz
src-afdbfe1e1b5a47db04854f2656357e8aa1505d28.zip
Starting LBA is a 64bit number, so use htole64 instead of htole32. The
latter casts the LBA to a 32-bit number before assigning it to the 64 bit structure entity. This works fine on the first 2TB of TRIMs, but terrible beyond that due to trucation. Also, add an assert to make sure we don't end too many DSM TRIM entries in one request. Sponsored by: Netflix
Notes
Notes: svn path=/head/; revision=331239
Diffstat (limited to 'sys/cam/nvme/nvme_da.c')
-rw-r--r--sys/cam/nvme/nvme_da.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c
index cf2da478753a..072410736c99 100644
--- a/sys/cam/nvme/nvme_da.c
+++ b/sys/cam/nvme/nvme_da.c
@@ -164,7 +164,7 @@ static void ndasuspend(void *arg);
#define NDA_DEFAULT_RETRY 4
#endif
#ifndef NDA_MAX_TRIM_ENTRIES
-#define NDA_MAX_TRIM_ENTRIES 256 /* Number of DSM trims to use, max 256 */
+#define NDA_MAX_TRIM_ENTRIES (NVME_MAX_DSM_TRIM / sizeof(struct nvme_dsm_range))/* Number of DSM trims to use, max 256 */
#endif
static SYSCTL_NODE(_kern_cam, OID_AUTO, nda, CTLFLAG_RD, 0,
@@ -218,6 +218,8 @@ static void
nda_nvme_trim(struct nda_softc *softc, struct ccb_nvmeio *nvmeio,
void *payload, uint32_t num_ranges)
{
+ KASSERT(num_ranges * sizeof(struct nvme_dsm_range) < NVME_MAX_DSM_TRIM);
+
cam_fill_nvmeio(nvmeio,
0, /* retries */
ndadone, /* cbfcnp */
@@ -957,7 +959,7 @@ ndastart(struct cam_periph *periph, union ccb *start_ccb)
dsm_range->length =
htole32(bp1->bio_bcount / softc->disk->d_sectorsize);
dsm_range->starting_lba =
- htole32(bp1->bio_offset / softc->disk->d_sectorsize);
+ htole64(bp1->bio_offset / softc->disk->d_sectorsize);
dsm_range++;
if (dsm_range >= dsm_end)
break;