@@ -51,12 +51,14 @@ pub(crate) struct SyncItem {
5151impl SyncItem {
5252 fn parse_one ( file : & DrmFile , data : uapi:: drm_asahi_sync , out : bool ) -> Result < SyncItem > {
5353 if data. extensions != 0 {
54+ cls_pr_debug ! ( Errors , "drm_asahi_sync extension unexpected\n " ) ;
5455 return Err ( EINVAL ) ;
5556 }
5657
5758 match data. sync_type {
5859 uapi:: drm_asahi_sync_type_DRM_ASAHI_SYNC_SYNCOBJ => {
5960 if data. timeline_value != 0 {
61+ cls_pr_debug ! ( Errors , "Non-timeline sync object with a nonzero value\n " ) ;
6062 return Err ( EINVAL ) ;
6163 }
6264 let syncobj = drm:: syncobj:: SyncObj :: lookup_handle ( file, data. handle ) ?;
@@ -65,7 +67,10 @@ impl SyncItem {
6567 fence : if out {
6668 None
6769 } else {
68- Some ( syncobj. fence_get ( ) . ok_or ( EINVAL ) ?)
70+ Some ( syncobj. fence_get ( ) . ok_or_else ( || {
71+ cls_pr_debug ! ( Errors , "Failed to get fence from sync object\n " ) ;
72+ EINVAL
73+ } ) ?)
6974 } ,
7075 syncobj,
7176 chain_fence : None ,
@@ -80,7 +85,13 @@ impl SyncItem {
8085 Some (
8186 syncobj
8287 . fence_get ( )
83- . ok_or ( EINVAL ) ?
88+ . ok_or_else ( || {
89+ cls_pr_debug ! (
90+ Errors ,
91+ "Failed to get fence from timeline sync object\n "
92+ ) ;
93+ EINVAL
94+ } ) ?
8495 . chain_find_seqno ( data. timeline_value ) ?,
8596 )
8697 } ;
@@ -96,7 +107,10 @@ impl SyncItem {
96107 timeline_value : data. timeline_value ,
97108 } )
98109 }
99- _ => Err ( EINVAL ) ,
110+ _ => {
111+ cls_pr_debug ! ( Errors , "Invalid sync type {}\n " , data. sync_type) ;
112+ Err ( EINVAL )
113+ }
100114 }
101115 }
102116
@@ -199,6 +213,7 @@ impl File {
199213 let gpu = & device. data ( ) . gpu ;
200214
201215 if data. extensions != 0 || data. param_group != 0 || data. pad != 0 {
216+ cls_pr_debug ! ( Errors , "get_params: Invalid arguments\n " ) ;
202217 return Err ( EINVAL ) ;
203218 }
204219
@@ -276,6 +291,7 @@ impl File {
276291 file : & DrmFile ,
277292 ) -> Result < u32 > {
278293 if data. extensions != 0 {
294+ cls_pr_debug ! ( Errors , "vm_create: Unexpected extensions\n " ) ;
279295 return Err ( EINVAL ) ;
280296 }
281297
@@ -348,6 +364,7 @@ impl File {
348364 file : & DrmFile ,
349365 ) -> Result < u32 > {
350366 if data. extensions != 0 {
367+ cls_pr_debug ! ( Errors , "vm_destroy: Unexpected extensions\n " ) ;
351368 return Err ( EINVAL ) ;
352369 }
353370
@@ -375,6 +392,7 @@ impl File {
375392 || ( data. flags & !( uapi:: ASAHI_GEM_WRITEBACK | uapi:: ASAHI_GEM_VM_PRIVATE ) ) != 0
376393 || ( data. flags & uapi:: ASAHI_GEM_VM_PRIVATE == 0 && data. vm_id != 0 )
377394 {
395+ cls_pr_debug ! ( Errors , "gem_create: Invalid arguments\n " ) ;
378396 return Err ( EINVAL ) ;
379397 }
380398
@@ -422,6 +440,7 @@ impl File {
422440 ) ;
423441
424442 if data. extensions != 0 || data. flags != 0 {
443+ cls_pr_debug ! ( Errors , "gem_mmap_offset: Unexpected extensions or flags\n " ) ;
425444 return Err ( EINVAL ) ;
426445 }
427446
@@ -450,6 +469,7 @@ impl File {
450469 ) ;
451470
452471 if data. extensions != 0 {
472+ cls_pr_debug ! ( Errors , "gem_bind: Unexpected extensions\n " ) ;
453473 return Err ( EINVAL ) ;
454474 }
455475
@@ -459,7 +479,10 @@ impl File {
459479 uapi:: drm_asahi_bind_op_ASAHI_BIND_OP_UNBIND_ALL => {
460480 Self :: do_gem_unbind_all ( device, data, file)
461481 }
462- _ => Err ( EINVAL ) ,
482+ _ => {
483+ cls_pr_debug ! ( Errors , "gem_bind: Invalid op {}\n " , data. op) ;
484+ Err ( EINVAL )
485+ }
463486 }
464487 }
465488
@@ -469,20 +492,29 @@ impl File {
469492 file : & DrmFile ,
470493 ) -> Result < u32 > {
471494 if data. offset != 0 {
495+ pr_err ! ( "gem_bind: Offset not supported yet\n " ) ;
472496 return Err ( EINVAL ) ; // Not supported yet
473497 }
474498
475499 if ( data. addr | data. range ) as usize & mmu:: UAT_PGMSK != 0 {
500+ cls_pr_debug ! (
501+ Errors ,
502+ "gem_bind: Addr/range not page aligned: {:#x} {:#x}\n " ,
503+ data. addr,
504+ data. range
505+ ) ;
476506 return Err ( EINVAL ) ; // Must be page aligned
477507 }
478508
479509 if ( data. flags & !( uapi:: ASAHI_BIND_READ | uapi:: ASAHI_BIND_WRITE ) ) != 0 {
510+ cls_pr_debug ! ( Errors , "gem_bind: Invalid flags {:#x}\n " , data. flags) ;
480511 return Err ( EINVAL ) ;
481512 }
482513
483514 let mut bo = gem:: lookup_handle ( file, data. handle ) ?;
484515
485516 if data. range != bo. size ( ) . try_into ( ) ? {
517+ pr_err ! ( "gem_bind: Partial maps not supported yet\n " ) ;
486518 return Err ( EINVAL ) ; // Not supported yet
487519 }
488520
@@ -491,18 +523,42 @@ impl File {
491523
492524 if ( VM_SHADER_START ..=VM_SHADER_END ) . contains ( & start) {
493525 if !( VM_SHADER_START ..=VM_SHADER_END ) . contains ( & end) {
526+ cls_pr_debug ! (
527+ Errors ,
528+ "gem_bind: Invalid map range {:#x}..{:#x} (straddles shader range)\n " ,
529+ start,
530+ end
531+ ) ;
494532 return Err ( EINVAL ) ; // Invalid map range
495533 }
496534 } else if ( VM_USER_START ..=VM_USER_END ) . contains ( & start) {
497535 if !( VM_USER_START ..=VM_USER_END ) . contains ( & end) {
536+ cls_pr_debug ! (
537+ Errors ,
538+ "gem_bind: Invalid map range {:#x}..{:#x} (straddles user range)\n " ,
539+ start,
540+ end
541+ ) ;
498542 return Err ( EINVAL ) ; // Invalid map range
499543 }
500544 } else {
545+ cls_pr_debug ! (
546+ Errors ,
547+ "gem_bind: Invalid map range {:#x}..{:#x}\n " ,
548+ start,
549+ end
550+ ) ;
501551 return Err ( EINVAL ) ; // Invalid map range
502552 }
503553
504554 // Just in case
505555 if end >= VM_DRV_GPU_START {
556+ cls_pr_debug ! (
557+ Errors ,
558+ "gem_bind: Invalid map range {:#x}..{:#x} (intrudes in kernel range)\n " ,
559+ start,
560+ end
561+ ) ;
506562 return Err ( EINVAL ) ;
507563 }
508564
@@ -515,6 +571,11 @@ impl File {
515571 } else if data. flags & uapi:: ASAHI_BIND_WRITE != 0 {
516572 mmu:: PROT_GPU_SHARED_WO
517573 } else {
574+ cls_pr_debug ! (
575+ Errors ,
576+ "gem_bind: Must specify read or write (flags: {:#x})\n " ,
577+ data. flags
578+ ) ;
518579 return Err ( EINVAL ) ; // Must specify one of ASAHI_BIND_{READ,WRITE}
519580 } ;
520581
@@ -539,6 +600,7 @@ impl File {
539600 file : & DrmFile ,
540601 ) -> Result < u32 > {
541602 if data. flags != 0 || data. offset != 0 || data. range != 0 || data. addr != 0 {
603+ cls_pr_debug ! ( Errors , "gem_unbind_all: Invalid arguments\n " ) ;
542604 return Err ( EINVAL ) ;
543605 }
544606
@@ -589,6 +651,7 @@ impl File {
589651 | uapi:: drm_asahi_queue_cap_DRM_ASAHI_QUEUE_CAP_COMPUTE) )
590652 != 0
591653 {
654+ cls_pr_debug ! ( Errors , "queue_create: Invalid arguments\n " ) ;
592655 return Err ( EINVAL ) ;
593656 }
594657
@@ -623,6 +686,7 @@ impl File {
623686 file : & DrmFile ,
624687 ) -> Result < u32 > {
625688 if data. extensions != 0 {
689+ cls_pr_debug ! ( Errors , "queue_destroy: Unexpected extensions\n " ) ;
626690 return Err ( EINVAL ) ;
627691 }
628692
@@ -644,16 +708,44 @@ impl File {
644708 data : & mut uapi:: drm_asahi_submit ,
645709 file : & DrmFile ,
646710 ) -> Result < u32 > {
647- if data. extensions != 0
648- || data. flags != 0
649- || data. in_sync_count > MAX_SYNCS_PER_SUBMISSION
650- || data. out_sync_count > MAX_SYNCS_PER_SUBMISSION
651- || data. command_count > MAX_COMMANDS_PER_SUBMISSION
652- {
711+ debug:: update_debug_flags ( ) ;
712+
713+ if data. extensions != 0 {
714+ cls_pr_debug ! ( Errors , "submit: Unexpected extensions\n " ) ;
653715 return Err ( EINVAL ) ;
654716 }
655717
656- debug:: update_debug_flags ( ) ;
718+ if data. flags != 0 {
719+ cls_pr_debug ! ( Errors , "submit: Unexpected flags {:#x}\n " , data. flags) ;
720+ return Err ( EINVAL ) ;
721+ }
722+ if data. in_sync_count > MAX_SYNCS_PER_SUBMISSION {
723+ cls_pr_debug ! (
724+ Errors ,
725+ "submit: Too many in syncs: {} > {}\n " ,
726+ data. in_sync_count,
727+ MAX_SYNCS_PER_SUBMISSION
728+ ) ;
729+ return Err ( EINVAL ) ;
730+ }
731+ if data. out_sync_count > MAX_SYNCS_PER_SUBMISSION {
732+ cls_pr_debug ! (
733+ Errors ,
734+ "submit: Too many out syncs: {} > {}\n " ,
735+ data. out_sync_count,
736+ MAX_SYNCS_PER_SUBMISSION
737+ ) ;
738+ return Err ( EINVAL ) ;
739+ }
740+ if data. command_count > MAX_COMMANDS_PER_SUBMISSION {
741+ cls_pr_debug ! (
742+ Errors ,
743+ "submit: Too many commands: {} > {}\n " ,
744+ data. command_count,
745+ MAX_COMMANDS_PER_SUBMISSION
746+ ) ;
747+ return Err ( EINVAL ) ;
748+ }
657749
658750 let gpu = & device. data ( ) . gpu ;
659751 gpu. update_globals ( ) ;
0 commit comments