Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/amdgpu: read and authenticate ip discovery binary

read and authenticate ip discovery binary getting from
vram first, if it is not valid, read and authenticate
the one getting from file

Signed-off-by: Hawking Zhang <Hawking.Zhang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Hawking Zhang and committed by
Alex Deucher
2cb6577a 32f0e1a3

+23 -23
+23 -23
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
··· 249 249 struct binary_header *bhdr; 250 250 struct ip_discovery_header *ihdr; 251 251 struct gpu_info_header *ghdr; 252 - const struct firmware *fw; 253 252 uint16_t offset; 254 253 uint16_t size; 255 254 uint16_t checksum; ··· 259 260 if (!adev->mman.discovery_bin) 260 261 return -ENOMEM; 261 262 262 - if (amdgpu_discovery == 2) { 263 - r = request_firmware(&fw, "amdgpu/ip_discovery.bin", adev->dev); 264 - if (r) 265 - goto get_from_vram; 266 - dev_info(adev->dev, "Using IP discovery from file\n"); 267 - memcpy((u8 *)adev->mman.discovery_bin, (u8 *)fw->data, 268 - adev->mman.discovery_tmr_size); 269 - release_firmware(fw); 270 - } else { 271 - get_from_vram: 272 - r = amdgpu_discovery_read_binary_from_vram(adev, adev->mman.discovery_bin); 263 + r = amdgpu_discovery_read_binary_from_vram(adev, adev->mman.discovery_bin); 264 + if (r) { 265 + dev_err(adev->dev, "failed to read ip discovery binary from vram\n"); 266 + r = -EINVAL; 267 + goto out; 268 + } 269 + 270 + if(!amdgpu_discovery_verify_binary_signature(adev->mman.discovery_bin)) { 271 + dev_warn(adev->dev, "get invalid ip discovery binary signature from vram\n"); 272 + /* retry read ip discovery binary from file */ 273 + r = amdgpu_discovery_read_binary_from_file(adev, adev->mman.discovery_bin); 273 274 if (r) { 274 - DRM_ERROR("failed to read ip discovery binary\n"); 275 + dev_err(adev->dev, "failed to read ip discovery binary from file\n"); 276 + r = -EINVAL; 277 + goto out; 278 + } 279 + /* check the ip discovery binary signature */ 280 + if(!amdgpu_discovery_verify_binary_signature(adev->mman.discovery_bin)) { 281 + dev_warn(adev->dev, "get invalid ip discovery binary signature from file\n"); 282 + r = -EINVAL; 275 283 goto out; 276 284 } 277 285 } 278 286 279 287 bhdr = (struct binary_header *)adev->mman.discovery_bin; 280 - 281 - if (le32_to_cpu(bhdr->binary_signature) != BINARY_SIGNATURE) { 282 - DRM_ERROR("invalid ip discovery binary signature\n"); 283 - r = -EINVAL; 284 - goto out; 285 - } 286 288 287 289 offset = offsetof(struct binary_header, binary_checksum) + 288 290 sizeof(bhdr->binary_checksum); ··· 292 292 293 293 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 294 294 size, checksum)) { 295 - DRM_ERROR("invalid ip discovery binary checksum\n"); 295 + dev_err(adev->dev, "invalid ip discovery binary checksum\n"); 296 296 r = -EINVAL; 297 297 goto out; 298 298 } ··· 303 303 ihdr = (struct ip_discovery_header *)(adev->mman.discovery_bin + offset); 304 304 305 305 if (le32_to_cpu(ihdr->signature) != DISCOVERY_TABLE_SIGNATURE) { 306 - DRM_ERROR("invalid ip discovery data table signature\n"); 306 + dev_err(adev->dev, "invalid ip discovery data table signature\n"); 307 307 r = -EINVAL; 308 308 goto out; 309 309 } 310 310 311 311 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 312 312 le16_to_cpu(ihdr->size), checksum)) { 313 - DRM_ERROR("invalid ip discovery data table checksum\n"); 313 + dev_err(adev->dev, "invalid ip discovery data table checksum\n"); 314 314 r = -EINVAL; 315 315 goto out; 316 316 } ··· 322 322 323 323 if (!amdgpu_discovery_verify_checksum(adev->mman.discovery_bin + offset, 324 324 le32_to_cpu(ghdr->size), checksum)) { 325 - DRM_ERROR("invalid gc data table checksum\n"); 325 + dev_err(adev->dev, "invalid gc data table checksum\n"); 326 326 r = -EINVAL; 327 327 goto out; 328 328 }