Commit 09784062 authored by Sunil Khatri's avatar Sunil Khatri Committed by Alex Deucher
Browse files

drm/amdgpu: use atomic operation to achieve lockless serialization



In amdgpu_seq64_alloc there is a possibility that two difference cores
from two separate NODES can try to and could get the same free slot.
So this fixes that race here using atomic test_and_set clear operations.

Signed-off-by: default avatarSunil Khatri <sunil.khatri@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 4d50a14d346141e03a7c3905e496d91e048bc30c)
parent a1d4b228
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -175,11 +175,14 @@ int amdgpu_seq64_alloc(struct amdgpu_device *adev, u64 *va,
{
	unsigned long bit_pos;

	for (;;) {
		bit_pos = find_first_zero_bit(adev->seq64.used, adev->seq64.num_sem);
		if (bit_pos >= adev->seq64.num_sem)
			return -ENOSPC;

	__set_bit(bit_pos, adev->seq64.used);
		if (!test_and_set_bit(bit_pos, adev->seq64.used))
			break;
	}

	*va = bit_pos * sizeof(u64) + amdgpu_seq64_get_va_base(adev);

@@ -205,7 +208,7 @@ void amdgpu_seq64_free(struct amdgpu_device *adev, u64 va)

	bit_pos = (va - amdgpu_seq64_get_va_base(adev)) / sizeof(u64);
	if (bit_pos < adev->seq64.num_sem)
		__clear_bit(bit_pos, adev->seq64.used);
		clear_bit(bit_pos, adev->seq64.used);
}

/**