forked from mirrors/linux
		
	sfc: fix field-spanning memcpy in selftest
Add a struct_group for the whole packet body so we can copy it in one go without triggering FORTIFY_SOURCE complaints. Fixes:cf60ed4696("sfc: use padding to fix alignment in loopback test") Fixes:30c24dd87f("sfc: siena: use padding to fix alignment in loopback test") Fixes:1186c6b31e("sfc: falcon: use padding to fix alignment in loopback test") Reviewed-by: Andy Moreton <andy.moreton@amd.com> Tested-by: Andy Moreton <andy.moreton@amd.com> Signed-off-by: Edward Cree <ecree.xilinx@gmail.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Link: https://lore.kernel.org/r/20230728165528.59070-1-edward.cree@amd.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
		
							parent
							
								
									d4480c9bb9
								
							
						
					
					
						commit
						55c1528f9b
					
				
					 3 changed files with 39 additions and 30 deletions
				
			
		|  | @ -40,15 +40,16 @@ | |||
|  */ | ||||
| struct ef4_loopback_payload { | ||||
| 	char pad[2]; /* Ensures ip is 4-byte aligned */ | ||||
| 	struct ethhdr header; | ||||
| 	struct iphdr ip; | ||||
| 	struct udphdr udp; | ||||
| 	__be16 iteration; | ||||
| 	char msg[64]; | ||||
| 	struct_group_attr(packet, __packed, | ||||
| 		struct ethhdr header; | ||||
| 		struct iphdr ip; | ||||
| 		struct udphdr udp; | ||||
| 		__be16 iteration; | ||||
| 		char msg[64]; | ||||
| 	); | ||||
| } __packed __aligned(4); | ||||
| #define EF4_LOOPBACK_PAYLOAD_LEN	(sizeof(struct ef4_loopback_payload) - \ | ||||
| 					 offsetof(struct ef4_loopback_payload, \ | ||||
| 						  header)) | ||||
| #define EF4_LOOPBACK_PAYLOAD_LEN	\ | ||||
| 		sizeof_field(struct ef4_loopback_payload, packet) | ||||
| 
 | ||||
| /* Loopback test source MAC address */ | ||||
| static const u8 payload_source[ETH_ALEN] __aligned(2) = { | ||||
|  | @ -299,7 +300,7 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx, | |||
| 
 | ||||
| 	payload = &state->payload; | ||||
| 
 | ||||
| 	memcpy(&received.header, buf_ptr, | ||||
| 	memcpy(&received.packet, buf_ptr, | ||||
| 	       min_t(int, pkt_len, EF4_LOOPBACK_PAYLOAD_LEN)); | ||||
| 	received.ip.saddr = payload->ip.saddr; | ||||
| 	if (state->offload_csum) | ||||
|  | @ -370,7 +371,7 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx, | |||
| 			       buf_ptr, pkt_len, 0); | ||||
| 		netif_err(efx, drv, efx->net_dev, "expected packet:\n"); | ||||
| 		print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1, | ||||
| 			       &state->payload.header, EF4_LOOPBACK_PAYLOAD_LEN, | ||||
| 			       &state->payload.packet, EF4_LOOPBACK_PAYLOAD_LEN, | ||||
| 			       0); | ||||
| 	} | ||||
| #endif | ||||
|  | @ -440,6 +441,8 @@ static int ef4_begin_loopback(struct ef4_tx_queue *tx_queue) | |||
| 		payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); | ||||
| 		/* Strip off the leading padding */ | ||||
| 		skb_pull(skb, offsetof(struct ef4_loopback_payload, header)); | ||||
| 		/* Strip off the trailing padding */ | ||||
| 		skb_trim(skb, EF4_LOOPBACK_PAYLOAD_LEN); | ||||
| 
 | ||||
| 		/* Ensure everything we've written is visible to the
 | ||||
| 		 * interrupt handler. */ | ||||
|  |  | |||
|  | @ -43,15 +43,16 @@ | |||
|  */ | ||||
| struct efx_loopback_payload { | ||||
| 	char pad[2]; /* Ensures ip is 4-byte aligned */ | ||||
| 	struct ethhdr header; | ||||
| 	struct iphdr ip; | ||||
| 	struct udphdr udp; | ||||
| 	__be16 iteration; | ||||
| 	char msg[64]; | ||||
| 	struct_group_attr(packet, __packed, | ||||
| 		struct ethhdr header; | ||||
| 		struct iphdr ip; | ||||
| 		struct udphdr udp; | ||||
| 		__be16 iteration; | ||||
| 		char msg[64]; | ||||
| 	); | ||||
| } __packed __aligned(4); | ||||
| #define EFX_LOOPBACK_PAYLOAD_LEN	(sizeof(struct efx_loopback_payload) - \ | ||||
| 					 offsetof(struct efx_loopback_payload, \ | ||||
| 						  header)) | ||||
| #define EFX_LOOPBACK_PAYLOAD_LEN	\ | ||||
| 		sizeof_field(struct efx_loopback_payload, packet) | ||||
| 
 | ||||
| /* Loopback test source MAC address */ | ||||
| static const u8 payload_source[ETH_ALEN] __aligned(2) = { | ||||
|  | @ -297,7 +298,7 @@ void efx_loopback_rx_packet(struct efx_nic *efx, | |||
| 
 | ||||
| 	payload = &state->payload; | ||||
| 
 | ||||
| 	memcpy(&received.header, buf_ptr, | ||||
| 	memcpy(&received.packet, buf_ptr, | ||||
| 	       min_t(int, pkt_len, EFX_LOOPBACK_PAYLOAD_LEN)); | ||||
| 	received.ip.saddr = payload->ip.saddr; | ||||
| 	if (state->offload_csum) | ||||
|  | @ -368,7 +369,7 @@ void efx_loopback_rx_packet(struct efx_nic *efx, | |||
| 			       buf_ptr, pkt_len, 0); | ||||
| 		netif_err(efx, drv, efx->net_dev, "expected packet:\n"); | ||||
| 		print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1, | ||||
| 			       &state->payload.header, EFX_LOOPBACK_PAYLOAD_LEN, | ||||
| 			       &state->payload.packet, EFX_LOOPBACK_PAYLOAD_LEN, | ||||
| 			       0); | ||||
| 	} | ||||
| #endif | ||||
|  | @ -438,6 +439,8 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue) | |||
| 		payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); | ||||
| 		/* Strip off the leading padding */ | ||||
| 		skb_pull(skb, offsetof(struct efx_loopback_payload, header)); | ||||
| 		/* Strip off the trailing padding */ | ||||
| 		skb_trim(skb, EFX_LOOPBACK_PAYLOAD_LEN); | ||||
| 
 | ||||
| 		/* Ensure everything we've written is visible to the
 | ||||
| 		 * interrupt handler. */ | ||||
|  |  | |||
|  | @ -43,15 +43,16 @@ | |||
|  */ | ||||
| struct efx_loopback_payload { | ||||
| 	char pad[2]; /* Ensures ip is 4-byte aligned */ | ||||
| 	struct ethhdr header; | ||||
| 	struct iphdr ip; | ||||
| 	struct udphdr udp; | ||||
| 	__be16 iteration; | ||||
| 	char msg[64]; | ||||
| 	struct_group_attr(packet, __packed, | ||||
| 		struct ethhdr header; | ||||
| 		struct iphdr ip; | ||||
| 		struct udphdr udp; | ||||
| 		__be16 iteration; | ||||
| 		char msg[64]; | ||||
| 	); | ||||
| } __packed __aligned(4); | ||||
| #define EFX_LOOPBACK_PAYLOAD_LEN	(sizeof(struct efx_loopback_payload) - \ | ||||
| 					 offsetof(struct efx_loopback_payload, \ | ||||
| 						  header)) | ||||
| #define EFX_LOOPBACK_PAYLOAD_LEN	\ | ||||
| 		sizeof_field(struct efx_loopback_payload, packet) | ||||
| 
 | ||||
| /* Loopback test source MAC address */ | ||||
| static const u8 payload_source[ETH_ALEN] __aligned(2) = { | ||||
|  | @ -297,7 +298,7 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx, | |||
| 
 | ||||
| 	payload = &state->payload; | ||||
| 
 | ||||
| 	memcpy(&received.header, buf_ptr, | ||||
| 	memcpy(&received.packet, buf_ptr, | ||||
| 	       min_t(int, pkt_len, EFX_LOOPBACK_PAYLOAD_LEN)); | ||||
| 	received.ip.saddr = payload->ip.saddr; | ||||
| 	if (state->offload_csum) | ||||
|  | @ -368,7 +369,7 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx, | |||
| 			       buf_ptr, pkt_len, 0); | ||||
| 		netif_err(efx, drv, efx->net_dev, "expected packet:\n"); | ||||
| 		print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1, | ||||
| 			       &state->payload.header, EFX_LOOPBACK_PAYLOAD_LEN, | ||||
| 			       &state->payload.packet, EFX_LOOPBACK_PAYLOAD_LEN, | ||||
| 			       0); | ||||
| 	} | ||||
| #endif | ||||
|  | @ -438,6 +439,8 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue) | |||
| 		payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); | ||||
| 		/* Strip off the leading padding */ | ||||
| 		skb_pull(skb, offsetof(struct efx_loopback_payload, header)); | ||||
| 		/* Strip off the trailing padding */ | ||||
| 		skb_trim(skb, EFX_LOOPBACK_PAYLOAD_LEN); | ||||
| 
 | ||||
| 		/* Ensure everything we've written is visible to the
 | ||||
| 		 * interrupt handler. */ | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Edward Cree
						Edward Cree