Skip to content

Commit ce944f3

Browse files
committed
Merge tag 'drm-fixes-2024-04-19' of https://gitlab.freedesktop.org/drm/kernel
Pull drm fixes from Dave Airlie: "Regular week of fixes, seems to be about right for this time in the release cycle, amdgpu, and nouveau are the main one with some scattered fixes otherwise. ttm: - Stop pooling cached NUMA pages amdgpu: - Fix invalid resource->start check - USB-C DSC fix - Fix a potential UAF in VA IOCTL - Fix visible VRAM handling during faults amdkfd: - Fix memory leak in create_process failure radeon: - Silence UBSAN warnings from variable sized arrays nouveau: - dp: Don't probe DP ports twice - nv04: Fix OOB access - nv50: Disable AUX bus for disconnected DP ports - nvkm: Fix instmem race condition panel: - Don't unregister DSI devices in several drivers v3d: - Fix enabled_ns increment xe: - Fix bo leak on error path during fb init - Fix use-after-free due to order vm is put and destroyed" * tag 'drm-fixes-2024-04-19' of https://gitlab.freedesktop.org/drm/kernel: drm/radeon: silence UBSAN warning (v3) drm/radeon: make -fstrict-flex-arrays=3 happy drm/amdgpu: fix visible VRAM handling during faults drm/amdgpu: validate the parameters of bo mapping operations more clearly Revert "drm/amd/display: fix USB-C flag update after enc10 feature init" drm/amdkfd: Fix memory leak in create_process failure drm/amdgpu: remove invalid resource->start check v2 drm/xe/vm: prevent UAF with asid based lookup drm/xe: Fix bo leak in intel_fb_bo_framebuffer_init drm/panel: novatek-nt36682e: don't unregister DSI device drm/panel: visionox-rm69299: don't unregister DSI device drm/nouveau/dp: Don't probe eDP ports twice harder drm/nouveau/kms/nv50-: Disable AUX bus for disconnected DP ports drm/v3d: Don't increment `enabled_ns` twice drm/vmwgfx: Sort primary plane formats by order of preference drm/vmwgfx: Fix crtc's atomic check conditional drm/vmwgfx: Fix prime import/export drm/ttm: stop pooling cached NUMA pages v2 drm: nv04: Fix out of bounds access nouveau: fix instmem race condition around ptr stores
2 parents 54c2354 + 52c8b6e commit ce944f3

30 files changed

+320
-172
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
819819

820820
p->bytes_moved += ctx.bytes_moved;
821821
if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
822-
amdgpu_bo_in_cpu_visible_vram(bo))
822+
amdgpu_res_cpu_visible(adev, bo->tbo.resource))
823823
p->bytes_moved_vis += ctx.bytes_moved;
824824

825825
if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
617617
return r;
618618

619619
if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
620-
bo->tbo.resource->mem_type == TTM_PL_VRAM &&
621-
amdgpu_bo_in_cpu_visible_vram(bo))
620+
amdgpu_res_cpu_visible(adev, bo->tbo.resource))
622621
amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved,
623622
ctx.bytes_moved);
624623
else
@@ -1272,23 +1271,25 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo, bool evict)
12721271
void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
12731272
struct amdgpu_mem_stats *stats)
12741273
{
1274+
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
1275+
struct ttm_resource *res = bo->tbo.resource;
12751276
uint64_t size = amdgpu_bo_size(bo);
12761277
struct drm_gem_object *obj;
12771278
unsigned int domain;
12781279
bool shared;
12791280

12801281
/* Abort if the BO doesn't currently have a backing store */
1281-
if (!bo->tbo.resource)
1282+
if (!res)
12821283
return;
12831284

12841285
obj = &bo->tbo.base;
12851286
shared = drm_gem_object_is_shared_for_memory_stats(obj);
12861287

1287-
domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type);
1288+
domain = amdgpu_mem_type_to_domain(res->mem_type);
12881289
switch (domain) {
12891290
case AMDGPU_GEM_DOMAIN_VRAM:
12901291
stats->vram += size;
1291-
if (amdgpu_bo_in_cpu_visible_vram(bo))
1292+
if (amdgpu_res_cpu_visible(adev, bo->tbo.resource))
12921293
stats->visible_vram += size;
12931294
if (shared)
12941295
stats->vram_shared += size;
@@ -1389,10 +1390,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
13891390
/* Remember that this BO was accessed by the CPU */
13901391
abo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
13911392

1392-
if (bo->resource->mem_type != TTM_PL_VRAM)
1393-
return 0;
1394-
1395-
if (amdgpu_bo_in_cpu_visible_vram(abo))
1393+
if (amdgpu_res_cpu_visible(adev, bo->resource))
13961394
return 0;
13971395

13981396
/* Can't move a pinned BO to visible VRAM */
@@ -1415,7 +1413,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
14151413

14161414
/* this should never happen */
14171415
if (bo->resource->mem_type == TTM_PL_VRAM &&
1418-
!amdgpu_bo_in_cpu_visible_vram(abo))
1416+
!amdgpu_res_cpu_visible(adev, bo->resource))
14191417
return VM_FAULT_SIGBUS;
14201418

14211419
ttm_bo_move_to_lru_tail_unlocked(bo);
@@ -1579,6 +1577,7 @@ uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,
15791577
*/
15801578
u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)
15811579
{
1580+
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
15821581
struct dma_buf_attachment *attachment;
15831582
struct dma_buf *dma_buf;
15841583
const char *placement;
@@ -1587,10 +1586,11 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)
15871586

15881587
if (dma_resv_trylock(bo->tbo.base.resv)) {
15891588
unsigned int domain;
1589+
15901590
domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type);
15911591
switch (domain) {
15921592
case AMDGPU_GEM_DOMAIN_VRAM:
1593-
if (amdgpu_bo_in_cpu_visible_vram(bo))
1593+
if (amdgpu_res_cpu_visible(adev, bo->tbo.resource))
15941594
placement = "VRAM VISIBLE";
15951595
else
15961596
placement = "VRAM";

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -250,28 +250,6 @@ static inline u64 amdgpu_bo_mmap_offset(struct amdgpu_bo *bo)
250250
return drm_vma_node_offset_addr(&bo->tbo.base.vma_node);
251251
}
252252

253-
/**
254-
* amdgpu_bo_in_cpu_visible_vram - check if BO is (partly) in visible VRAM
255-
*/
256-
static inline bool amdgpu_bo_in_cpu_visible_vram(struct amdgpu_bo *bo)
257-
{
258-
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
259-
struct amdgpu_res_cursor cursor;
260-
261-
if (!bo->tbo.resource || bo->tbo.resource->mem_type != TTM_PL_VRAM)
262-
return false;
263-
264-
amdgpu_res_first(bo->tbo.resource, 0, amdgpu_bo_size(bo), &cursor);
265-
while (cursor.remaining) {
266-
if (cursor.start < adev->gmc.visible_vram_size)
267-
return true;
268-
269-
amdgpu_res_next(&cursor, cursor.size);
270-
}
271-
272-
return false;
273-
}
274-
275253
/**
276254
* amdgpu_bo_explicit_sync - return whether the bo is explicitly synced
277255
*/

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
133133

134134
} else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
135135
!(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) &&
136-
amdgpu_bo_in_cpu_visible_vram(abo)) {
136+
amdgpu_res_cpu_visible(adev, bo->resource)) {
137137

138138
/* Try evicting to the CPU inaccessible part of VRAM
139139
* first, but only set GTT as busy placement, so this
@@ -403,40 +403,55 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo,
403403
return r;
404404
}
405405

406-
/*
407-
* amdgpu_mem_visible - Check that memory can be accessed by ttm_bo_move_memcpy
406+
/**
407+
* amdgpu_res_cpu_visible - Check that resource can be accessed by CPU
408+
* @adev: amdgpu device
409+
* @res: the resource to check
408410
*
409-
* Called by amdgpu_bo_move()
411+
* Returns: true if the full resource is CPU visible, false otherwise.
410412
*/
411-
static bool amdgpu_mem_visible(struct amdgpu_device *adev,
412-
struct ttm_resource *mem)
413+
bool amdgpu_res_cpu_visible(struct amdgpu_device *adev,
414+
struct ttm_resource *res)
413415
{
414-
u64 mem_size = (u64)mem->size;
415416
struct amdgpu_res_cursor cursor;
416-
u64 end;
417417

418-
if (mem->mem_type == TTM_PL_SYSTEM ||
419-
mem->mem_type == TTM_PL_TT)
418+
if (!res)
419+
return false;
420+
421+
if (res->mem_type == TTM_PL_SYSTEM || res->mem_type == TTM_PL_TT ||
422+
res->mem_type == AMDGPU_PL_PREEMPT)
420423
return true;
421-
if (mem->mem_type != TTM_PL_VRAM)
424+
425+
if (res->mem_type != TTM_PL_VRAM)
422426
return false;
423427

424-
amdgpu_res_first(mem, 0, mem_size, &cursor);
425-
end = cursor.start + cursor.size;
428+
amdgpu_res_first(res, 0, res->size, &cursor);
426429
while (cursor.remaining) {
430+
if ((cursor.start + cursor.size) >= adev->gmc.visible_vram_size)
431+
return false;
427432
amdgpu_res_next(&cursor, cursor.size);
433+
}
428434

429-
if (!cursor.remaining)
430-
break;
435+
return true;
436+
}
431437

432-
/* ttm_resource_ioremap only supports contiguous memory */
433-
if (end != cursor.start)
434-
return false;
438+
/*
439+
* amdgpu_res_copyable - Check that memory can be accessed by ttm_bo_move_memcpy
440+
*
441+
* Called by amdgpu_bo_move()
442+
*/
443+
static bool amdgpu_res_copyable(struct amdgpu_device *adev,
444+
struct ttm_resource *mem)
445+
{
446+
if (!amdgpu_res_cpu_visible(adev, mem))
447+
return false;
435448

436-
end = cursor.start + cursor.size;
437-
}
449+
/* ttm_resource_ioremap only supports contiguous memory */
450+
if (mem->mem_type == TTM_PL_VRAM &&
451+
!(mem->placement & TTM_PL_FLAG_CONTIGUOUS))
452+
return false;
438453

439-
return end <= adev->gmc.visible_vram_size;
454+
return true;
440455
}
441456

442457
/*
@@ -529,8 +544,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
529544

530545
if (r) {
531546
/* Check that all memory is CPU accessible */
532-
if (!amdgpu_mem_visible(adev, old_mem) ||
533-
!amdgpu_mem_visible(adev, new_mem)) {
547+
if (!amdgpu_res_copyable(adev, old_mem) ||
548+
!amdgpu_res_copyable(adev, new_mem)) {
534549
pr_err("Move buffer fallback to memcpy unavailable\n");
535550
return r;
536551
}
@@ -557,7 +572,6 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_device *bdev,
557572
struct ttm_resource *mem)
558573
{
559574
struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
560-
size_t bus_size = (size_t)mem->size;
561575

562576
switch (mem->mem_type) {
563577
case TTM_PL_SYSTEM:
@@ -568,9 +582,6 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_device *bdev,
568582
break;
569583
case TTM_PL_VRAM:
570584
mem->bus.offset = mem->start << PAGE_SHIFT;
571-
/* check if it's visible */
572-
if ((mem->bus.offset + bus_size) > adev->gmc.visible_vram_size)
573-
return -EINVAL;
574585

575586
if (adev->mman.aper_base_kaddr &&
576587
mem->placement & TTM_PL_FLAG_CONTIGUOUS)

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ int amdgpu_vram_mgr_reserve_range(struct amdgpu_vram_mgr *mgr,
139139
int amdgpu_vram_mgr_query_page_status(struct amdgpu_vram_mgr *mgr,
140140
uint64_t start);
141141

142+
bool amdgpu_res_cpu_visible(struct amdgpu_device *adev,
143+
struct ttm_resource *res);
144+
142145
int amdgpu_ttm_init(struct amdgpu_device *adev);
143146
void amdgpu_ttm_fini(struct amdgpu_device *adev);
144147
void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,37 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev,
16131613
trace_amdgpu_vm_bo_map(bo_va, mapping);
16141614
}
16151615

1616+
/* Validate operation parameters to prevent potential abuse */
1617+
static int amdgpu_vm_verify_parameters(struct amdgpu_device *adev,
1618+
struct amdgpu_bo *bo,
1619+
uint64_t saddr,
1620+
uint64_t offset,
1621+
uint64_t size)
1622+
{
1623+
uint64_t tmp, lpfn;
1624+
1625+
if (saddr & AMDGPU_GPU_PAGE_MASK
1626+
|| offset & AMDGPU_GPU_PAGE_MASK
1627+
|| size & AMDGPU_GPU_PAGE_MASK)
1628+
return -EINVAL;
1629+
1630+
if (check_add_overflow(saddr, size, &tmp)
1631+
|| check_add_overflow(offset, size, &tmp)
1632+
|| size == 0 /* which also leads to end < begin */)
1633+
return -EINVAL;
1634+
1635+
/* make sure object fit at this offset */
1636+
if (bo && offset + size > amdgpu_bo_size(bo))
1637+
return -EINVAL;
1638+
1639+
/* Ensure last pfn not exceed max_pfn */
1640+
lpfn = (saddr + size - 1) >> AMDGPU_GPU_PAGE_SHIFT;
1641+
if (lpfn >= adev->vm_manager.max_pfn)
1642+
return -EINVAL;
1643+
1644+
return 0;
1645+
}
1646+
16161647
/**
16171648
* amdgpu_vm_bo_map - map bo inside a vm
16181649
*
@@ -1639,21 +1670,14 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
16391670
struct amdgpu_bo *bo = bo_va->base.bo;
16401671
struct amdgpu_vm *vm = bo_va->base.vm;
16411672
uint64_t eaddr;
1673+
int r;
16421674

1643-
/* validate the parameters */
1644-
if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
1645-
return -EINVAL;
1646-
if (saddr + size <= saddr || offset + size <= offset)
1647-
return -EINVAL;
1648-
1649-
/* make sure object fit at this offset */
1650-
eaddr = saddr + size - 1;
1651-
if ((bo && offset + size > amdgpu_bo_size(bo)) ||
1652-
(eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
1653-
return -EINVAL;
1675+
r = amdgpu_vm_verify_parameters(adev, bo, saddr, offset, size);
1676+
if (r)
1677+
return r;
16541678

16551679
saddr /= AMDGPU_GPU_PAGE_SIZE;
1656-
eaddr /= AMDGPU_GPU_PAGE_SIZE;
1680+
eaddr = saddr + (size - 1) / AMDGPU_GPU_PAGE_SIZE;
16571681

16581682
tmp = amdgpu_vm_it_iter_first(&vm->va, saddr, eaddr);
16591683
if (tmp) {
@@ -1706,17 +1730,9 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
17061730
uint64_t eaddr;
17071731
int r;
17081732

1709-
/* validate the parameters */
1710-
if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK)
1711-
return -EINVAL;
1712-
if (saddr + size <= saddr || offset + size <= offset)
1713-
return -EINVAL;
1714-
1715-
/* make sure object fit at this offset */
1716-
eaddr = saddr + size - 1;
1717-
if ((bo && offset + size > amdgpu_bo_size(bo)) ||
1718-
(eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT))
1719-
return -EINVAL;
1733+
r = amdgpu_vm_verify_parameters(adev, bo, saddr, offset, size);
1734+
if (r)
1735+
return r;
17201736

17211737
/* Allocate all the needed memory */
17221738
mapping = kmalloc(sizeof(*mapping), GFP_KERNEL);
@@ -1730,7 +1746,7 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
17301746
}
17311747

17321748
saddr /= AMDGPU_GPU_PAGE_SIZE;
1733-
eaddr /= AMDGPU_GPU_PAGE_SIZE;
1749+
eaddr = saddr + (size - 1) / AMDGPU_GPU_PAGE_SIZE;
17341750

17351751
mapping->start = saddr;
17361752
mapping->last = eaddr;
@@ -1817,10 +1833,14 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
18171833
struct amdgpu_bo_va_mapping *before, *after, *tmp, *next;
18181834
LIST_HEAD(removed);
18191835
uint64_t eaddr;
1836+
int r;
1837+
1838+
r = amdgpu_vm_verify_parameters(adev, NULL, saddr, 0, size);
1839+
if (r)
1840+
return r;
18201841

1821-
eaddr = saddr + size - 1;
18221842
saddr /= AMDGPU_GPU_PAGE_SIZE;
1823-
eaddr /= AMDGPU_GPU_PAGE_SIZE;
1843+
eaddr = saddr + (size - 1) / AMDGPU_GPU_PAGE_SIZE;
18241844

18251845
/* Allocate all the needed memory */
18261846
before = kzalloc(sizeof(*before), GFP_KERNEL);

drivers/gpu/drm/amd/amdkfd/kfd_process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,9 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
819819
mutex_lock(&kfd_processes_mutex);
820820

821821
if (kfd_is_locked()) {
822-
mutex_unlock(&kfd_processes_mutex);
823822
pr_debug("KFD is locked! Cannot create process");
824-
return ERR_PTR(-EINVAL);
823+
process = ERR_PTR(-EINVAL);
824+
goto out;
825825
}
826826

827827
/* A prior open of /dev/kfd could have already created the process. */

drivers/gpu/drm/amd/display/dc/dcn32/dcn32_dio_link_encoder.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,12 @@ void dcn32_link_encoder_construct(
248248
enc10->base.hpd_source = init_data->hpd_source;
249249
enc10->base.connector = init_data->connector;
250250

251-
enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
252-
253-
enc10->base.features = *enc_features;
254251
if (enc10->base.connector.id == CONNECTOR_ID_USBC)
255252
enc10->base.features.flags.bits.DP_IS_USB_C = 1;
256253

257-
if (enc10->base.connector.id == CONNECTOR_ID_USBC)
258-
enc10->base.features.flags.bits.DP_IS_USB_C = 1;
254+
enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
255+
256+
enc10->base.features = *enc_features;
259257

260258
enc10->base.transmitter = init_data->transmitter;
261259

0 commit comments

Comments
 (0)