forked from mirrors/linux
		
	ipvlan: adopt u64_stats_t
As explained in commit 316580b69d ("u64_stats: provide u64_stats_t type")
we should use u64_stats_t and related accessors to avoid load/store tearing.
Add READ_ONCE() when reading rx_errs & tx_drps.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									09cca53c16
								
							
						
					
					
						commit
						5665f48ef3
					
				
					 3 changed files with 17 additions and 17 deletions
				
			
		|  | @ -47,11 +47,11 @@ typedef enum { | ||||||
| } ipvl_hdr_type; | } ipvl_hdr_type; | ||||||
| 
 | 
 | ||||||
| struct ipvl_pcpu_stats { | struct ipvl_pcpu_stats { | ||||||
| 	u64			rx_pkts; | 	u64_stats_t		rx_pkts; | ||||||
| 	u64			rx_bytes; | 	u64_stats_t		rx_bytes; | ||||||
| 	u64			rx_mcast; | 	u64_stats_t		rx_mcast; | ||||||
| 	u64			tx_pkts; | 	u64_stats_t		tx_pkts; | ||||||
| 	u64			tx_bytes; | 	u64_stats_t		tx_bytes; | ||||||
| 	struct u64_stats_sync	syncp; | 	struct u64_stats_sync	syncp; | ||||||
| 	u32			rx_errs; | 	u32			rx_errs; | ||||||
| 	u32			tx_drps; | 	u32			tx_drps; | ||||||
|  |  | ||||||
|  | @ -19,10 +19,10 @@ void ipvlan_count_rx(const struct ipvl_dev *ipvlan, | ||||||
| 
 | 
 | ||||||
| 		pcptr = this_cpu_ptr(ipvlan->pcpu_stats); | 		pcptr = this_cpu_ptr(ipvlan->pcpu_stats); | ||||||
| 		u64_stats_update_begin(&pcptr->syncp); | 		u64_stats_update_begin(&pcptr->syncp); | ||||||
| 		pcptr->rx_pkts++; | 		u64_stats_inc(&pcptr->rx_pkts); | ||||||
| 		pcptr->rx_bytes += len; | 		u64_stats_add(&pcptr->rx_bytes, len); | ||||||
| 		if (mcast) | 		if (mcast) | ||||||
| 			pcptr->rx_mcast++; | 			u64_stats_inc(&pcptr->rx_mcast); | ||||||
| 		u64_stats_update_end(&pcptr->syncp); | 		u64_stats_update_end(&pcptr->syncp); | ||||||
| 	} else { | 	} else { | ||||||
| 		this_cpu_inc(ipvlan->pcpu_stats->rx_errs); | 		this_cpu_inc(ipvlan->pcpu_stats->rx_errs); | ||||||
|  |  | ||||||
|  | @ -224,8 +224,8 @@ static netdev_tx_t ipvlan_start_xmit(struct sk_buff *skb, | ||||||
| 		pcptr = this_cpu_ptr(ipvlan->pcpu_stats); | 		pcptr = this_cpu_ptr(ipvlan->pcpu_stats); | ||||||
| 
 | 
 | ||||||
| 		u64_stats_update_begin(&pcptr->syncp); | 		u64_stats_update_begin(&pcptr->syncp); | ||||||
| 		pcptr->tx_pkts++; | 		u64_stats_inc(&pcptr->tx_pkts); | ||||||
| 		pcptr->tx_bytes += skblen; | 		u64_stats_add(&pcptr->tx_bytes, skblen); | ||||||
| 		u64_stats_update_end(&pcptr->syncp); | 		u64_stats_update_end(&pcptr->syncp); | ||||||
| 	} else { | 	} else { | ||||||
| 		this_cpu_inc(ipvlan->pcpu_stats->tx_drps); | 		this_cpu_inc(ipvlan->pcpu_stats->tx_drps); | ||||||
|  | @ -300,11 +300,11 @@ static void ipvlan_get_stats64(struct net_device *dev, | ||||||
| 			pcptr = per_cpu_ptr(ipvlan->pcpu_stats, idx); | 			pcptr = per_cpu_ptr(ipvlan->pcpu_stats, idx); | ||||||
| 			do { | 			do { | ||||||
| 				strt= u64_stats_fetch_begin_irq(&pcptr->syncp); | 				strt= u64_stats_fetch_begin_irq(&pcptr->syncp); | ||||||
| 				rx_pkts = pcptr->rx_pkts; | 				rx_pkts = u64_stats_read(&pcptr->rx_pkts); | ||||||
| 				rx_bytes = pcptr->rx_bytes; | 				rx_bytes = u64_stats_read(&pcptr->rx_bytes); | ||||||
| 				rx_mcast = pcptr->rx_mcast; | 				rx_mcast = u64_stats_read(&pcptr->rx_mcast); | ||||||
| 				tx_pkts = pcptr->tx_pkts; | 				tx_pkts = u64_stats_read(&pcptr->tx_pkts); | ||||||
| 				tx_bytes = pcptr->tx_bytes; | 				tx_bytes = u64_stats_read(&pcptr->tx_bytes); | ||||||
| 			} while (u64_stats_fetch_retry_irq(&pcptr->syncp, | 			} while (u64_stats_fetch_retry_irq(&pcptr->syncp, | ||||||
| 							   strt)); | 							   strt)); | ||||||
| 
 | 
 | ||||||
|  | @ -315,8 +315,8 @@ static void ipvlan_get_stats64(struct net_device *dev, | ||||||
| 			s->tx_bytes += tx_bytes; | 			s->tx_bytes += tx_bytes; | ||||||
| 
 | 
 | ||||||
| 			/* u32 values are updated without syncp protection. */ | 			/* u32 values are updated without syncp protection. */ | ||||||
| 			rx_errs += pcptr->rx_errs; | 			rx_errs += READ_ONCE(pcptr->rx_errs); | ||||||
| 			tx_drps += pcptr->tx_drps; | 			tx_drps += READ_ONCE(pcptr->tx_drps); | ||||||
| 		} | 		} | ||||||
| 		s->rx_errors = rx_errs; | 		s->rx_errors = rx_errs; | ||||||
| 		s->rx_dropped = rx_errs; | 		s->rx_dropped = rx_errs; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Eric Dumazet
						Eric Dumazet