@@ -522,14 +522,17 @@ impl Net {
522522 self . read_tap ( ) . map_err ( NetError :: IO )
523523 }
524524
525- fn process_rx ( & mut self ) -> Result < ( ) , DeviceError > {
525+ fn process_rx ( & mut self ) -> Result < bool , DeviceError > {
526+ let mut signal_queue = false ;
526527 // Read as many frames as possible.
527528 loop {
528529 match self . read_from_mmds_or_tap ( ) {
529530 Ok ( count) => {
530531 self . rx_bytes_read = count;
531532 self . metrics . rx_count . inc ( ) ;
532- if !self . rate_limited_rx_single_frame ( ) {
533+ if self . rate_limited_rx_single_frame ( ) {
534+ signal_queue = true ;
535+ } else {
533536 self . rx_deferred_frame = true ;
534537 break ;
535538 }
@@ -553,9 +556,11 @@ impl Net {
553556 }
554557 }
555558
556- // At this point we processed as many Rx frames as possible.
557- // We have to wake the guest if at least one descriptor chain has been used.
558- self . signal_used_queue ( NetQueue :: Rx )
559+ // We only notify guest if there is at least one packet processed successfully.
560+ if signal_queue {
561+ self . signal_used_queue ( NetQueue :: Rx ) ?;
562+ }
563+ Ok ( signal_queue)
559564 }
560565
561566 // Process the deferred frame first, then continue reading from tap.
@@ -564,10 +569,12 @@ impl Net {
564569 self . rx_deferred_frame = false ;
565570 // process_rx() was interrupted possibly before consuming all
566571 // packets in the tap; try continuing now.
567- return self . process_rx ( ) ;
572+ // we only signal queue if process_rx() did not already.
573+ if !self . process_rx ( ) ? {
574+ self . signal_used_queue ( NetQueue :: Rx ) ?;
575+ }
568576 }
569-
570- self . signal_used_queue ( NetQueue :: Rx )
577+ Ok ( ( ) )
571578 }
572579
573580 fn resume_rx ( & mut self ) -> Result < ( ) , DeviceError > {
@@ -652,7 +659,8 @@ impl Net {
652659
653660 // An incoming frame for the MMDS may trigger the transmission of a new message.
654661 if process_rx_for_mmds {
655- self . process_rx ( )
662+ self . process_rx ( ) ?;
663+ Ok ( ( ) )
656664 } else {
657665 Ok ( ( ) )
658666 }
@@ -720,15 +728,14 @@ impl Net {
720728 return ;
721729 }
722730
723- if self . rx_deferred_frame
724731 // Process a deferred frame first if available. Don't read from tap again
725732 // until we manage to receive this deferred frame.
726- {
727- self . handle_deferred_frame ( )
728- . unwrap_or_else ( |err| report_net_event_fail ( & self . metrics , err) ) ;
729- } else {
730- self . process_rx ( )
731- . unwrap_or_else ( |err| report_net_event_fail ( & self . metrics , err) ) ;
733+ if self . rx_deferred_frame {
734+ if let Err ( err ) = self . handle_deferred_frame ( ) {
735+ report_net_event_fail ( & self . metrics , err) ;
736+ }
737+ } else if let Err ( err ) = self . process_rx ( ) {
738+ report_net_event_fail ( & self . metrics , err) ;
732739 }
733740 }
734741
0 commit comments