Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Mar 2018 03:37:14 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331239 - in head/sys: cam/nvme dev/nvme
Message-ID:  <201803200337.w2K3bE9N028537@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Tue Mar 20 03:37:14 2018
New Revision: 331239
URL: https://svnweb.freebsd.org/changeset/base/331239

Log:
  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

Modified:
  head/sys/cam/nvme/nvme_da.c
  head/sys/dev/nvme/nvme.h

Modified: head/sys/cam/nvme/nvme_da.c
==============================================================================
--- head/sys/cam/nvme/nvme_da.c	Tue Mar 20 03:37:09 2018	(r331238)
+++ head/sys/cam/nvme/nvme_da.c	Tue Mar 20 03:37:14 2018	(r331239)
@@ -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_c
 				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;

Modified: head/sys/dev/nvme/nvme.h
==============================================================================
--- head/sys/dev/nvme/nvme.h	Tue Mar 20 03:37:09 2018	(r331238)
+++ head/sys/dev/nvme/nvme.h	Tue Mar 20 03:37:14 2018	(r331239)
@@ -478,7 +478,6 @@ struct nvme_completion {
 _Static_assert(sizeof(struct nvme_completion) == 4 * 4, "bad size for nvme_completion");
 
 struct nvme_dsm_range {
-
 	uint32_t attributes;
 	uint32_t length;
 	uint64_t starting_lba;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803200337.w2K3bE9N028537>