From 2eb3c431bd87860ffce8934840a763d19ecb3259 Mon Sep 17 00:00:00 2001 From: Nitin Kumbhar Date: Fri, 13 Sep 2019 11:26:53 +0530 Subject: [PATCH] gpu: nvgpu: add check for unaligned access Add a build time check to confirm that unaligned accesses are enabled for NvGPU driver. If unaligned access is not enabled it results in a build error. Currently it only checks for ARM build of NvGPU driver. JIRA NVGPU-3908 JIRA NVGPU-3561 Change-Id: Ifd190a8f489844ed36b5c5cb51b48257ef051f9f Signed-off-by: Nitin Kumbhar Reviewed-on: https://git-master.nvidia.com/r/2197150 Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../gpu/nvgpu/include/nvgpu/static_analysis.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/gpu/nvgpu/include/nvgpu/static_analysis.h b/drivers/gpu/nvgpu/include/nvgpu/static_analysis.h index 214d3bb58..7507f86bd 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/static_analysis.h +++ b/drivers/gpu/nvgpu/include/nvgpu/static_analysis.h @@ -442,6 +442,31 @@ static inline s32 nvgpu_safe_cast_s64_to_s32(s64 sl_a) } } +/* + * Skip unaligned access check in NvGPU when it's built for unit testing with + * __NVGPU_UNIT_TEST__. As NvGPU UT build is not used on any production system, + * there is no need to consider security aspects related NvGPU UT build. + */ +#if !defined(__NVGPU_UNIT_TEST__) + +/* + * NvGPU driver is built for ARM targets with unaligned-access enabled. Confirm + * enabling of unaligned-access with a check for __ARM_FEATURE_UNALIGNED. + * + * This confirmation helps argue NvGPU security in context of CERT-C EXP36-C and + * INT36-C violations which flag misalignment. + * + * If and when NvGPU is built using a different compiler/architecture (non-ARM), + * a similar check for that architecture is required. If an unaligned access is + * not possible, then the CERT-C violations due to unaligned access need to be + * fixed. + */ +#if !defined(__ARM_FEATURE_UNALIGNED) +#error "__ARM_FEATURE_UNALIGNED not defined. Check static_analysis.h" +#endif + +#endif + #define NVGPU_PRECISION(v) _Generic(v, \ unsigned int : __builtin_popcount, \ unsigned long : __builtin_popcountl, \