4242#include <stddef.h>
4343#include <stdint.h>
4444
45+ /* Command format errors during fuzzing are reported for virtually all
46+ * commands, and the resulting flood of logging becomes a severe
47+ * performance penalty (i.e. we get a lot less fuzzing done per CPU
48+ * cycle).
49+ */
50+ #ifdef CONFIG_ARCH_POSIX_LIBFUZZER
51+ #define ipc_cmd_err (...)
52+ #else
53+ #define ipc_cmd_err (...) tr_err(__VA_ARGS__)
54+ #endif
55+
4556LOG_MODULE_DECLARE (ipc , CONFIG_SOF_LOG_LEVEL );
4657
4758struct ipc4_msg_data {
@@ -127,25 +138,25 @@ static int ipc4_pcm_params(struct ipc_comp_dev *pcm_dev)
127138
128139 /* sanity check comp */
129140 if (!pcm_dev -> cd -> pipeline ) {
130- tr_err (& ipc_tr , "ipc: comp %d pipeline not found" , pcm_dev -> id );
141+ ipc_cmd_err (& ipc_tr , "ipc: comp %d pipeline not found" , pcm_dev -> id );
131142 return - EINVAL ;
132143 }
133144
134145 /* configure pipeline audio params */
135146 err = ipc4_pipeline_params (pcm_dev -> cd -> pipeline , pcm_dev -> cd );
136147 if (err < 0 ) {
137- tr_err (& ipc_tr , "ipc: pipe %d comp %d params failed %d" ,
138- pcm_dev -> cd -> pipeline -> pipeline_id ,
139- pcm_dev -> cd -> pipeline -> comp_id , err );
148+ ipc_cmd_err (& ipc_tr , "ipc: pipe %d comp %d params failed %d" ,
149+ pcm_dev -> cd -> pipeline -> pipeline_id ,
150+ pcm_dev -> cd -> pipeline -> comp_id , err );
140151 goto error ;
141152 }
142153
143154 /* prepare pipeline audio params */
144155 err = pipeline_prepare (pcm_dev -> cd -> pipeline , pcm_dev -> cd );
145156 if (err < 0 ) {
146- tr_err (& ipc_tr , "ipc: pipe %d comp %d prepare failed %d" ,
147- pcm_dev -> cd -> pipeline -> pipeline_id ,
148- pcm_dev -> cd -> pipeline -> comp_id , err );
157+ ipc_cmd_err (& ipc_tr , "ipc: pipe %d comp %d prepare failed %d" ,
158+ pcm_dev -> cd -> pipeline -> pipeline_id ,
159+ pcm_dev -> cd -> pipeline -> comp_id , err );
149160 goto error ;
150161 }
151162
@@ -154,9 +165,9 @@ static int ipc4_pcm_params(struct ipc_comp_dev *pcm_dev)
154165error :
155166 reset_err = pipeline_reset (pcm_dev -> cd -> pipeline , pcm_dev -> cd );
156167 if (reset_err < 0 )
157- tr_err (& ipc_tr , "ipc: pipe %d comp %d reset failed %d" ,
158- pcm_dev -> cd -> pipeline -> pipeline_id ,
159- pcm_dev -> cd -> pipeline -> comp_id , reset_err );
168+ ipc_cmd_err (& ipc_tr , "ipc: pipe %d comp %d reset failed %d" ,
169+ pcm_dev -> cd -> pipeline -> pipeline_id ,
170+ pcm_dev -> cd -> pipeline -> comp_id , reset_err );
160171
161172 return err ;
162173}
@@ -228,7 +239,7 @@ static int set_pipeline_state(struct ipc_comp_dev *ppl_icd, uint32_t cmd,
228239
229240 host = ipc_get_comp_by_id (ipc , host_id );
230241 if (!host ) {
231- tr_err (& ipc_tr , "ipc: comp host with ID %d not found" , host_id );
242+ ipc_cmd_err (& ipc_tr , "ipc: comp host with ID %d not found" , host_id );
232243 return IPC4_INVALID_RESOURCE_ID ;
233244 }
234245 }
@@ -251,7 +262,7 @@ static int set_pipeline_state(struct ipc_comp_dev *ppl_icd, uint32_t cmd,
251262 cmd = COMP_TRIGGER_PRE_RELEASE ;
252263 break ;
253264 default :
254- tr_err (& ipc_tr , "ipc: current status %d" , status );
265+ ipc_cmd_err (& ipc_tr , "ipc: current status %d" , status );
255266 return IPC4_INVALID_REQUEST ;
256267 }
257268 break ;
@@ -270,15 +281,15 @@ static int set_pipeline_state(struct ipc_comp_dev *ppl_icd, uint32_t cmd,
270281 case COMP_STATE_PAUSED :
271282 ret = pipeline_trigger (host -> cd -> pipeline , host -> cd , COMP_TRIGGER_STOP );
272283 if (ret < 0 ) {
273- tr_err (& ipc_tr , "ipc: comp %d trigger 0x%x failed %d" ,
274- ppl_icd -> id , cmd , ret );
284+ ipc_cmd_err (& ipc_tr , "ipc: comp %d trigger 0x%x failed %d" ,
285+ ppl_icd -> id , cmd , ret );
275286 return IPC4_PIPELINE_STATE_NOT_SET ;
276287 }
277288 if (ret == PPL_STATUS_SCHEDULED )
278289 * delayed = true;
279290 break ;
280291 default :
281- tr_err (& ipc_tr , "ipc: invalid status %d for RESET" , status );
292+ ipc_cmd_err (& ipc_tr , "ipc: invalid status %d for RESET" , status );
282293 return IPC4_INVALID_REQUEST ;
283294 }
284295
@@ -317,14 +328,14 @@ static int set_pipeline_state(struct ipc_comp_dev *ppl_icd, uint32_t cmd,
317328 case SOF_IPC4_PIPELINE_STATE_SAVED :
318329 case SOF_IPC4_PIPELINE_STATE_ERROR_STOP :
319330 default :
320- tr_err (& ipc_tr , "ipc: unsupported trigger cmd 0x%x" , cmd );
331+ ipc_cmd_err (& ipc_tr , "ipc: unsupported trigger cmd 0x%x" , cmd );
321332 return IPC4_INVALID_REQUEST ;
322333 }
323334
324335 /* trigger the component */
325336 ret = pipeline_trigger (host -> cd -> pipeline , host -> cd , cmd );
326337 if (ret < 0 ) {
327- tr_err (& ipc_tr , "ipc: comp %d trigger 0x%x failed %d" , ppl_icd -> id , cmd , ret );
338+ ipc_cmd_err (& ipc_tr , "ipc: comp %d trigger 0x%x failed %d" , ppl_icd -> id , cmd , ret );
328339 ret = IPC4_PIPELINE_STATE_NOT_SET ;
329340 } else if (ret == PPL_STATUS_SCHEDULED ) {
330341 * delayed = true;
@@ -345,7 +356,7 @@ static void ipc_compound_pre_start(int msg_id)
345356static void ipc_compound_post_start (uint32_t msg_id , int ret , bool delayed )
346357{
347358 if (ret ) {
348- tr_err (& ipc_tr , "failed to process msg %d status %d" , msg_id , ret );
359+ ipc_cmd_err (& ipc_tr , "failed to process msg %d status %d" , msg_id , ret );
349360 atomic_set (& msg_data .delayed_reply , 0 );
350361 return ;
351362 }
@@ -358,7 +369,7 @@ static void ipc_compound_post_start(uint32_t msg_id, int ret, bool delayed)
358369static void ipc_compound_msg_done (uint32_t msg_id , int error )
359370{
360371 if (!atomic_read (& msg_data .delayed_reply )) {
361- tr_err (& ipc_tr , "unexpected delayed reply" );
372+ ipc_cmd_err (& ipc_tr , "unexpected delayed reply" );
362373 return ;
363374 }
364375
@@ -379,7 +390,7 @@ static int ipc_wait_for_compound_msg(void)
379390 k_sleep (Z_TIMEOUT_US (250 ));
380391
381392 if (!try_count -- ) {
382- tr_err (& ipc_tr , "failed to wait schedule thread" );
393+ ipc_cmd_err (& ipc_tr , "failed to wait schedule thread" );
383394 return IPC4_FAILURE ;
384395 }
385396 }
@@ -421,7 +432,7 @@ static int ipc4_set_pipeline_state(struct ipc4_message_request *ipc4)
421432
422433 ppl_icd = ipc_get_comp_by_ppl_id (ipc , COMP_TYPE_PIPELINE , ppl_id [i ]);
423434 if (!ppl_icd ) {
424- tr_err (& ipc_tr , "ipc: comp %d not found" , ppl_id [i ]);
435+ ipc_cmd_err (& ipc_tr , "ipc: comp %d not found" , ppl_id [i ]);
425436 return IPC4_INVALID_RESOURCE_ID ;
426437 }
427438
@@ -536,16 +547,16 @@ static int ipc4_process_ipcgtw_cmd(struct ipc4_message_request *ipc4)
536547 if (msg_reply .tx_data ) {
537548 msg_reply .tx_size = reply_size ;
538549 } else {
539- tr_err (& ipc_tr , "failed to allocate %u bytes for msg_reply.tx_data" ,
540- reply_size );
550+ ipc_cmd_err (& ipc_tr , "failed to allocate %u bytes for msg_reply.tx_data" ,
551+ reply_size );
541552 msg_reply .extension = 0 ;
542553 return IPC4_OUT_OF_MEMORY ;
543554 }
544555 }
545556
546557 return err < 0 ? IPC4_FAILURE : IPC4_SUCCESS ;
547558#else
548- tr_err (& ipc_tr , "CONFIG_IPC4_GATEWAY is disabled" );
559+ ipc_cmd_err (& ipc_tr , "CONFIG_IPC4_GATEWAY is disabled" );
549560 return IPC4_UNAVAILABLE ;
550561#endif
551562}
@@ -563,7 +574,7 @@ static int ipc4_process_glb_message(struct ipc4_message_request *ipc4)
563574 case SOF_IPC4_GLB_PERF_MEASUREMENTS_CMD :
564575 case SOF_IPC4_GLB_LOAD_MULTIPLE_MODULES :
565576 case SOF_IPC4_GLB_UNLOAD_MULTIPLE_MODULES :
566- tr_err (& ipc_tr , "not implemented ipc message type %d" , type );
577+ ipc_cmd_err (& ipc_tr , "not implemented ipc message type %d" , type );
567578 ret = IPC4_UNAVAILABLE ;
568579 break ;
569580
@@ -586,7 +597,7 @@ static int ipc4_process_glb_message(struct ipc4_message_request *ipc4)
586597 case SOF_IPC4_GLB_GET_PIPELINE_CONTEXT_SIZE :
587598 case SOF_IPC4_GLB_SAVE_PIPELINE :
588599 case SOF_IPC4_GLB_RESTORE_PIPELINE :
589- tr_err (& ipc_tr , "not implemented ipc message type %d" , type );
600+ ipc_cmd_err (& ipc_tr , "not implemented ipc message type %d" , type );
590601 ret = IPC4_UNAVAILABLE ;
591602 break ;
592603
@@ -597,13 +608,13 @@ static int ipc4_process_glb_message(struct ipc4_message_request *ipc4)
597608 break ;
598609#endif
599610 case SOF_IPC4_GLB_INTERNAL_MESSAGE :
600- tr_err (& ipc_tr , "not implemented ipc message type %d" , type );
611+ ipc_cmd_err (& ipc_tr , "not implemented ipc message type %d" , type );
601612 ret = IPC4_UNAVAILABLE ;
602613 break ;
603614
604615 /* Notification (FW to SW driver) */
605616 case SOF_IPC4_GLB_NOTIFICATION :
606- tr_err (& ipc_tr , "not implemented ipc message type %d" , type );
617+ ipc_cmd_err (& ipc_tr , "not implemented ipc message type %d" , type );
607618 ret = IPC4_UNAVAILABLE ;
608619 break ;
609620
@@ -612,7 +623,7 @@ static int ipc4_process_glb_message(struct ipc4_message_request *ipc4)
612623 break ;
613624
614625 default :
615- tr_err (& ipc_tr , "unsupported ipc message type %d" , type );
626+ ipc_cmd_err (& ipc_tr , "unsupported ipc message type %d" , type );
616627 ret = IPC4_UNAVAILABLE ;
617628 break ;
618629 }
@@ -649,9 +660,9 @@ static int ipc4_init_module_instance(struct ipc4_message_request *ipc4)
649660
650661 dev = comp_new_ipc4 (& module_init );
651662 if (!dev ) {
652- tr_err (& ipc_tr , "error: failed to init module %x : %x" ,
653- (uint32_t )module_init .primary .r .module_id ,
654- (uint32_t )module_init .primary .r .instance_id );
663+ ipc_cmd_err (& ipc_tr , "error: failed to init module %x : %x" ,
664+ (uint32_t )module_init .primary .r .module_id ,
665+ (uint32_t )module_init .primary .r .instance_id );
655666 return IPC4_MOD_NOT_INITIALIZED ;
656667 }
657668
@@ -762,7 +773,7 @@ static int ipc4_get_large_config_module_instance(struct ipc4_message_request *ip
762773 msg_reply .tx_size = data_offset ;
763774 msg_reply .tx_data = response_buffer ;
764775 } else {
765- tr_err (& ipc_tr , "error: failed to allocate tx_data" );
776+ ipc_cmd_err (& ipc_tr , "error: failed to allocate tx_data" );
766777 ret = IPC4_OUT_OF_MEMORY ;
767778 }
768779
@@ -810,9 +821,9 @@ static int ipc4_set_large_config_module_instance(struct ipc4_message_request *ip
810821 config .extension .r .data_off_size ,
811822 (const char * )MAILBOX_HOSTBOX_BASE );
812823 if (ret < 0 ) {
813- tr_err (& ipc_tr , "failed to set large_config_module_instance %x : %x" ,
814- (uint32_t )config .primary .r .module_id ,
815- (uint32_t )config .primary .r .instance_id );
824+ ipc_cmd_err (& ipc_tr , "failed to set large_config_module_instance %x : %x" ,
825+ (uint32_t )config .primary .r .module_id ,
826+ (uint32_t )config .primary .r .instance_id );
816827 ret = IPC4_INVALID_RESOURCE_ID ;
817828 }
818829
@@ -835,9 +846,9 @@ static int ipc4_delete_module_instance(struct ipc4_message_request *ipc4)
835846 comp_id = IPC4_COMP_ID (module .primary .r .module_id , module .primary .r .instance_id );
836847 ret = ipc_comp_free (ipc , comp_id );
837848 if (ret < 0 ) {
838- tr_err (& ipc_tr , "failed to delete module instance %x : %x" ,
839- (uint32_t )module .primary .r .module_id ,
840- (uint32_t )module .primary .r .instance_id );
849+ ipc_cmd_err (& ipc_tr , "failed to delete module instance %x : %x" ,
850+ (uint32_t )module .primary .r .module_id ,
851+ (uint32_t )module .primary .r .instance_id );
841852 ret = IPC4_INVALID_RESOURCE_ID ;
842853 }
843854
@@ -861,7 +872,7 @@ static int ipc4_module_process_d0ix(struct ipc4_message_request *ipc4)
861872
862873 /* only module 0 can be used to set d0ix state */
863874 if (d0ix .primary .r .module_id || d0ix .primary .r .instance_id ) {
864- tr_err (& ipc_tr , "invalid resource id %x : %x" , module_id , instance_id );
875+ ipc_cmd_err (& ipc_tr , "invalid resource id %x : %x" , module_id , instance_id );
865876 return IPC4_INVALID_RESOURCE_ID ;
866877 }
867878
@@ -890,7 +901,7 @@ static int ipc4_module_process_dx(struct ipc4_message_request *ipc4)
890901
891902 /* only module 0 can be used to set dx state */
892903 if (module_id || instance_id ) {
893- tr_err (& ipc_tr , "invalid resource id %x : %x" , module_id , instance_id );
904+ ipc_cmd_err (& ipc_tr , "invalid resource id %x : %x" , module_id , instance_id );
894905 return IPC4_INVALID_RESOURCE_ID ;
895906 }
896907
@@ -903,16 +914,16 @@ static int ipc4_module_process_dx(struct ipc4_message_request *ipc4)
903914
904915 /* check if core enable mask is valid */
905916 if (dx_info .core_mask > MASK (CONFIG_CORE_COUNT - 1 , 0 )) {
906- tr_err (& ipc_tr , "ipc4_module_process_dx: CONFIG_CORE_COUNT: %d < core enable mask: %d" ,
907- CONFIG_CORE_COUNT , dx_info .core_mask );
917+ ipc_cmd_err (& ipc_tr , "ipc4_module_process_dx: CONFIG_CORE_COUNT: %d < core enable mask: %d" ,
918+ CONFIG_CORE_COUNT , dx_info .core_mask );
908919 return IPC4_ERROR_INVALID_PARAM ;
909920 }
910921
911922 /* check primary core first */
912923 if ((dx_info .core_mask & BIT (PLATFORM_PRIMARY_CORE_ID )) &&
913924 (dx_info .dx_mask & BIT (PLATFORM_PRIMARY_CORE_ID ))) {
914925 /* core0 can't be activated more, it's already active since we got here */
915- tr_err (& ipc_tr , "Core0 is already active" );
926+ ipc_cmd_err (& ipc_tr , "Core0 is already active" );
916927 return IPC4_BAD_STATE ;
917928 }
918929
@@ -924,13 +935,13 @@ static int ipc4_module_process_dx(struct ipc4_message_request *ipc4)
924935 if (dx_info .dx_mask & BIT (core_id )) {
925936 ret = cpu_enable_core (core_id );
926937 if (ret != 0 ) {
927- tr_err (& ipc_tr , "failed to enable core %d" , core_id );
938+ ipc_cmd_err (& ipc_tr , "failed to enable core %d" , core_id );
928939 return IPC4_FAILURE ;
929940 }
930941 } else {
931942 cpu_disable_core (core_id );
932943 if (cpu_is_core_enabled (core_id )) {
933- tr_err (& ipc_tr , "failed to disable core %d" , core_id );
944+ ipc_cmd_err (& ipc_tr , "failed to disable core %d" , core_id );
934945 return IPC4_FAILURE ;
935946 }
936947 }
@@ -939,13 +950,13 @@ static int ipc4_module_process_dx(struct ipc4_message_request *ipc4)
939950 /* Deactivating primary core if requested. */
940951 if (dx_info .core_mask & BIT (PLATFORM_PRIMARY_CORE_ID )) {
941952 if (cpu_enabled_cores () & ~BIT (PLATFORM_PRIMARY_CORE_ID )) {
942- tr_err (& ipc_tr , "secondary cores 0x%x still active" ,
943- cpu_enabled_cores ());
953+ ipc_cmd_err (& ipc_tr , "secondary cores 0x%x still active" ,
954+ cpu_enabled_cores ());
944955 return IPC4_BUSY ;
945956 }
946957
947958 if (is_any_ppl_active ()) {
948- tr_err (& ipc_tr , "some pipelines are still active" );
959+ ipc_cmd_err (& ipc_tr , "some pipelines are still active" );
949960 return IPC4_BUSY ;
950961 }
951962
@@ -1130,16 +1141,16 @@ void ipc_cmd(struct ipc_cmd_hdr *_hdr)
11301141 case SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG :
11311142 err = ipc4_process_glb_message (in );
11321143 if (err )
1133- tr_err (& ipc_tr , "ipc4: FW_GEN_MSG failed with err %d" , err );
1144+ ipc_cmd_err (& ipc_tr , "ipc4: FW_GEN_MSG failed with err %d" , err );
11341145 break ;
11351146 case SOF_IPC4_MESSAGE_TARGET_MODULE_MSG :
11361147 err = ipc4_process_module_message (in );
11371148 if (err )
1138- tr_err (& ipc_tr , "ipc4: MODULE_MSG failed with err %d" , err );
1149+ ipc_cmd_err (& ipc_tr , "ipc4: MODULE_MSG failed with err %d" , err );
11391150 break ;
11401151 default :
11411152 /* should not reach here as we only have 2 message types */
1142- tr_err (& ipc_tr , "ipc4: invalid target %d" , target );
1153+ ipc_cmd_err (& ipc_tr , "ipc4: invalid target %d" , target );
11431154 err = IPC4_UNKNOWN_MESSAGE_TYPE ;
11441155 }
11451156
@@ -1161,7 +1172,7 @@ void ipc_cmd(struct ipc_cmd_hdr *_hdr)
11611172 return ;
11621173
11631174 if (ipc_wait_for_compound_msg () != 0 ) {
1164- tr_err (& ipc_tr , "ipc4: failed to send delayed reply" );
1175+ ipc_cmd_err (& ipc_tr , "ipc4: failed to send delayed reply" );
11651176 err = IPC4_FAILURE ;
11661177 }
11671178
0 commit comments