Date: Thu, 1 Feb 2018 16:48:40 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328687 - stable/11/sys/dev/nvme Message-ID: <201802011648.w11GmeQn026528@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Thu Feb 1 16:48:40 2018 New Revision: 328687 URL: https://svnweb.freebsd.org/changeset/base/328687 Log: MFC r322874, r322875 (by imp): Sanity check sizes Add compile time sanity checks to make sure that packed structures are the proper size, typically as defined in the NVMe standard. Modified: stable/11/sys/dev/nvme/nvme.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/nvme/nvme.h ============================================================================== --- stable/11/sys/dev/nvme/nvme.h Thu Feb 1 16:48:25 2018 (r328686) +++ stable/11/sys/dev/nvme/nvme.h Thu Feb 1 16:48:40 2018 (r328687) @@ -69,6 +69,8 @@ union cap_lo_register { } bits __packed; } __packed; +_Static_assert(sizeof(union cap_lo_register) == 4, "bad size for cap_lo_register"); + union cap_hi_register { uint32_t raw; struct { @@ -93,6 +95,8 @@ union cap_hi_register { } bits __packed; } __packed; +_Static_assert(sizeof(union cap_hi_register) == 4, "bad size of cap_hi_register"); + union cc_register { uint32_t raw; struct { @@ -123,6 +127,8 @@ union cc_register { } bits __packed; } __packed; +_Static_assert(sizeof(union cc_register) == 4, "bad size for cc_register"); + enum shn_value { NVME_SHN_NORMAL = 0x1, NVME_SHN_ABRUPT = 0x2, @@ -144,6 +150,8 @@ union csts_register { } bits __packed; } __packed; +_Static_assert(sizeof(union csts_register) == 4, "bad size for csts_register"); + enum shst_value { NVME_SHST_NORMAL = 0x0, NVME_SHST_OCCURRING = 0x1, @@ -165,6 +173,8 @@ union aqa_register { } bits __packed; } __packed; +_Static_assert(sizeof(union aqa_register) == 4, "bad size for aqa_resgister"); + struct nvme_registers { /** controller capabilities */ @@ -198,6 +208,8 @@ struct nvme_registers } doorbell[1] __packed; } __packed; +_Static_assert(sizeof(struct nvme_registers) == 0x1008, "bad size for nvme_registers"); + struct nvme_command { /* dword 0 */ @@ -231,6 +243,8 @@ struct nvme_command uint32_t cdw15; /* command-specific */ } __packed; +_Static_assert(sizeof(struct nvme_command) == 16 * 4, "bad size for nvme_command"); + struct nvme_status { uint16_t p : 1; /* phase tag */ @@ -241,6 +255,8 @@ struct nvme_status { uint16_t dnr : 1; /* do not retry */ } __packed; +_Static_assert(sizeof(struct nvme_status) == 2, "bad size for nvme_status"); + struct nvme_completion { /* dword 0 */ @@ -258,6 +274,8 @@ struct nvme_completion { struct nvme_status status; } __packed; +_Static_assert(sizeof(struct nvme_completion) == 4 * 4, "bad size for nvme_completion"); + struct nvme_dsm_range { uint32_t attributes; @@ -265,6 +283,8 @@ struct nvme_dsm_range { uint64_t starting_lba; } __packed; +_Static_assert(sizeof(struct nvme_dsm_range) == 16, "bad size for nvme_dsm_ranage"); + /* status code types */ enum nvme_status_code_type { NVME_SCT_GENERIC = 0x0, @@ -423,6 +443,8 @@ struct nvme_power_state { uint8_t ps_rsvd10[9]; } __packed; +_Static_assert(sizeof(struct nvme_power_state) == 32, "bad size for nvme_power_state"); + #define NVME_SERIAL_NUMBER_LENGTH 20 #define NVME_MODEL_NUMBER_LENGTH 40 #define NVME_FIRMWARE_REVISION_LENGTH 8 @@ -583,6 +605,8 @@ struct nvme_controller_data { uint8_t vs[1024]; } __packed __aligned(4); +_Static_assert(sizeof(struct nvme_controller_data) == 4096, "bad size for nvme_controller_data"); + struct nvme_namespace_data { /** namespace size */ @@ -673,6 +697,8 @@ struct nvme_namespace_data { uint8_t vendor_specific[3712]; } __packed __aligned(4); +_Static_assert(sizeof(struct nvme_namespace_data) == 4096, "bad size for nvme_namepsace_data"); + enum nvme_log_page { /* 0x00 - reserved */ @@ -715,6 +741,8 @@ struct nvme_error_information_entry { uint8_t reserved[35]; } __packed __aligned(4); +_Static_assert(sizeof(struct nvme_error_information_entry) == 64, "bad size for nvme_error_information_entry"); + union nvme_critical_warning_state { uint8_t raw; @@ -729,6 +757,8 @@ union nvme_critical_warning_state { } __packed bits; } __packed; +_Static_assert(sizeof(union nvme_critical_warning_state) == 1, "bad size for nvme_critical_warning_state"); + struct nvme_health_information_page { union nvme_critical_warning_state critical_warning; @@ -765,6 +795,8 @@ struct nvme_health_information_page { uint8_t reserved2[296]; } __packed __aligned(4); +_Static_assert(sizeof(struct nvme_health_information_page) == 512, "bad size for nvme_health_information_page"); + struct nvme_firmware_page { struct { @@ -777,6 +809,8 @@ struct nvme_firmware_page { uint8_t reserved2[448]; } __packed __aligned(4); +_Static_assert(sizeof(struct nvme_firmware_page) == 512, "bad size for nvme_firmware_page"); + struct intel_log_temp_stats { uint64_t current; @@ -789,6 +823,8 @@ struct intel_log_temp_stats uint64_t min_oper_temp; uint64_t est_offset; } __packed __aligned(4); + +_Static_assert(sizeof(struct intel_log_temp_stats) == 13 * 8, "bad size for intel_log_temp_stats"); #define NVME_TEST_MAX_THREADS 128
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802011648.w11GmeQn026528>