diff options
| author | Arnaldo Carvalho de Melo <[email protected]> | 2020-03-04 13:29:19 +0000 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <[email protected]> | 2020-03-04 13:29:19 +0000 |
| commit | d46eec8e975a8180e178e01ba505801c44bc9a6c (patch) | |
| tree | bff067e554fc03c576e107297085d30c8e381370 /drivers/net/wireguard/send.c | |
| parent | perf/x86: Add Intel Tiger Lake uncore support (diff) | |
| parent | perf diff: Fix undefined string comparison spotted by clang's -Wstring-compare (diff) | |
| download | kernel-d46eec8e975a8180e178e01ba505801c44bc9a6c.tar.gz kernel-d46eec8e975a8180e178e01ba505801c44bc9a6c.zip | |
Merge remote-tracking branch 'acme/perf/urgent' into perf/core
To pick up fixes.
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'drivers/net/wireguard/send.c')
| -rw-r--r-- | drivers/net/wireguard/send.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/net/wireguard/send.c b/drivers/net/wireguard/send.c index c13260563446..7348c10cbae3 100644 --- a/drivers/net/wireguard/send.c +++ b/drivers/net/wireguard/send.c @@ -143,16 +143,22 @@ static void keep_key_fresh(struct wg_peer *peer) static unsigned int calculate_skb_padding(struct sk_buff *skb) { + unsigned int padded_size, last_unit = skb->len; + + if (unlikely(!PACKET_CB(skb)->mtu)) + return ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE) - last_unit; + /* We do this modulo business with the MTU, just in case the networking * layer gives us a packet that's bigger than the MTU. In that case, we * wouldn't want the final subtraction to overflow in the case of the - * padded_size being clamped. + * padded_size being clamped. Fortunately, that's very rarely the case, + * so we optimize for that not happening. */ - unsigned int last_unit = skb->len % PACKET_CB(skb)->mtu; - unsigned int padded_size = ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE); + if (unlikely(last_unit > PACKET_CB(skb)->mtu)) + last_unit %= PACKET_CB(skb)->mtu; - if (padded_size > PACKET_CB(skb)->mtu) - padded_size = PACKET_CB(skb)->mtu; + padded_size = min(PACKET_CB(skb)->mtu, + ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE)); return padded_size - last_unit; } |
