net: Use skb accessors in network core

In preparation for unifying the skb_frag and bio_vec, use the fine
accessors which already exist and use skb_frag_t instead of
struct skb_frag_struct.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Matthew Wilcox (Oracle) 2019-07-22 20:08:26 -07:00 committed by David S. Miller
parent d7840976e3
commit d8e18a516f
6 changed files with 38 additions and 32 deletions

View File

@ -3166,7 +3166,7 @@ static inline bool skb_can_coalesce(struct sk_buff *skb, int i,
if (skb_zcopy(skb)) if (skb_zcopy(skb))
return false; return false;
if (i) { if (i) {
const struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1]; const skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1];
return page == skb_frag_page(frag) && return page == skb_frag_page(frag) &&
off == frag->page_offset + skb_frag_size(frag); off == frag->page_offset + skb_frag_size(frag);

View File

@ -2485,19 +2485,19 @@ int skb_send_sock_locked(struct sock *sk, struct sk_buff *skb, int offset,
for (fragidx = 0; fragidx < skb_shinfo(skb)->nr_frags; fragidx++) { for (fragidx = 0; fragidx < skb_shinfo(skb)->nr_frags; fragidx++) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[fragidx]; skb_frag_t *frag = &skb_shinfo(skb)->frags[fragidx];
if (offset < frag->size) if (offset < skb_frag_size(frag))
break; break;
offset -= frag->size; offset -= skb_frag_size(frag);
} }
for (; len && fragidx < skb_shinfo(skb)->nr_frags; fragidx++) { for (; len && fragidx < skb_shinfo(skb)->nr_frags; fragidx++) {
skb_frag_t *frag = &skb_shinfo(skb)->frags[fragidx]; skb_frag_t *frag = &skb_shinfo(skb)->frags[fragidx];
slen = min_t(size_t, len, frag->size - offset); slen = min_t(size_t, len, skb_frag_size(frag) - offset);
while (slen) { while (slen) {
ret = kernel_sendpage_locked(sk, frag->page.p, ret = kernel_sendpage_locked(sk, skb_frag_page(frag),
frag->page_offset + offset, frag->page_offset + offset,
slen, MSG_DONTWAIT); slen, MSG_DONTWAIT);
if (ret <= 0) if (ret <= 0)
@ -2975,11 +2975,15 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)
skb_zerocopy_clone(to, from, GFP_ATOMIC); skb_zerocopy_clone(to, from, GFP_ATOMIC);
for (i = 0; i < skb_shinfo(from)->nr_frags; i++) { for (i = 0; i < skb_shinfo(from)->nr_frags; i++) {
int size;
if (!len) if (!len)
break; break;
skb_shinfo(to)->frags[j] = skb_shinfo(from)->frags[i]; skb_shinfo(to)->frags[j] = skb_shinfo(from)->frags[i];
skb_shinfo(to)->frags[j].size = min_t(int, skb_shinfo(to)->frags[j].size, len); size = min_t(int, skb_frag_size(&skb_shinfo(to)->frags[j]),
len -= skb_shinfo(to)->frags[j].size; len);
skb_frag_size_set(&skb_shinfo(to)->frags[j], size);
len -= size;
skb_frag_ref(to, j); skb_frag_ref(to, j);
j++; j++;
} }
@ -3293,7 +3297,7 @@ static int skb_prepare_for_shift(struct sk_buff *skb)
int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen)
{ {
int from, to, merge, todo; int from, to, merge, todo;
struct skb_frag_struct *fragfrom, *fragto; skb_frag_t *fragfrom, *fragto;
BUG_ON(shiftlen > skb->len); BUG_ON(shiftlen > skb->len);
@ -3625,10 +3629,10 @@ static inline skb_frag_t skb_head_frag_to_page_desc(struct sk_buff *frag_skb)
struct page *page; struct page *page;
page = virt_to_head_page(frag_skb->head); page = virt_to_head_page(frag_skb->head);
head_frag.page.p = page; __skb_frag_set_page(&head_frag, page);
head_frag.page_offset = frag_skb->data - head_frag.page_offset = frag_skb->data -
(unsigned char *)page_address(page); (unsigned char *)page_address(page);
head_frag.size = skb_headlen(frag_skb); skb_frag_size_set(&head_frag, skb_headlen(frag_skb));
return head_frag; return head_frag;
} }
@ -4021,7 +4025,7 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
pinfo->nr_frags = nr_frags + 1 + skbinfo->nr_frags; pinfo->nr_frags = nr_frags + 1 + skbinfo->nr_frags;
frag->page.p = page; __skb_frag_set_page(frag, page);
frag->page_offset = first_offset; frag->page_offset = first_offset;
skb_frag_size_set(frag, first_size); skb_frag_size_set(frag, first_size);

View File

@ -55,8 +55,8 @@ void tso_build_data(struct sk_buff *skb, struct tso_t *tso, int size)
skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx]; skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
/* Move to next segment */ /* Move to next segment */
tso->size = frag->size; tso->size = skb_frag_size(frag);
tso->data = page_address(frag->page.p) + frag->page_offset; tso->data = skb_frag_address(frag);
tso->next_frag_idx++; tso->next_frag_idx++;
} }
} }
@ -79,8 +79,8 @@ void tso_start(struct sk_buff *skb, struct tso_t *tso)
skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx]; skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
/* Move to next segment */ /* Move to next segment */
tso->size = frag->size; tso->size = skb_frag_size(frag);
tso->data = page_address(frag->page.p) + frag->page_offset; tso->data = skb_frag_address(frag);
tso->next_frag_idx++; tso->next_frag_idx++;
} }
} }

View File

@ -1776,19 +1776,21 @@ static int tcp_zerocopy_receive(struct sock *sk,
break; break;
frags = skb_shinfo(skb)->frags; frags = skb_shinfo(skb)->frags;
while (offset) { while (offset) {
if (frags->size > offset) if (skb_frag_size(frags) > offset)
goto out; goto out;
offset -= frags->size; offset -= skb_frag_size(frags);
frags++; frags++;
} }
} }
if (frags->size != PAGE_SIZE || frags->page_offset) { if (skb_frag_size(frags) != PAGE_SIZE || frags->page_offset) {
int remaining = zc->recv_skip_hint; int remaining = zc->recv_skip_hint;
int size = skb_frag_size(frags);
while (remaining && (frags->size != PAGE_SIZE || while (remaining && (size != PAGE_SIZE ||
frags->page_offset)) { frags->page_offset)) {
remaining -= frags->size; remaining -= size;
frags++; frags++;
size = skb_frag_size(frags);
} }
zc->recv_skip_hint -= remaining; zc->recv_skip_hint -= remaining;
break; break;
@ -3781,7 +3783,7 @@ int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *hp,
return 1; return 1;
for (i = 0; i < shi->nr_frags; ++i) { for (i = 0; i < shi->nr_frags; ++i) {
const struct skb_frag_struct *f = &shi->frags[i]; const skb_frag_t *f = &shi->frags[i];
unsigned int offset = f->page_offset; unsigned int offset = f->page_offset;
struct page *page = skb_frag_page(f) + (offset >> PAGE_SHIFT); struct page *page = skb_frag_page(f) + (offset >> PAGE_SHIFT);

View File

@ -635,15 +635,15 @@ static int kcm_write_msgs(struct kcm_sock *kcm)
frag_offset = 0; frag_offset = 0;
do_frag: do_frag:
frag = &skb_shinfo(skb)->frags[fragidx]; frag = &skb_shinfo(skb)->frags[fragidx];
if (WARN_ON(!frag->size)) { if (WARN_ON(!skb_frag_size(frag))) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
ret = kernel_sendpage(psock->sk->sk_socket, ret = kernel_sendpage(psock->sk->sk_socket,
frag->page.p, skb_frag_page(frag),
frag->page_offset + frag_offset, frag->page_offset + frag_offset,
frag->size - frag_offset, skb_frag_size(frag) - frag_offset,
MSG_DONTWAIT); MSG_DONTWAIT);
if (ret <= 0) { if (ret <= 0) {
if (ret == -EAGAIN) { if (ret == -EAGAIN) {
@ -678,7 +678,7 @@ static int kcm_write_msgs(struct kcm_sock *kcm)
sent += ret; sent += ret;
frag_offset += ret; frag_offset += ret;
KCM_STATS_ADD(psock->stats.tx_bytes, ret); KCM_STATS_ADD(psock->stats.tx_bytes, ret);
if (frag_offset < frag->size) { if (frag_offset < skb_frag_size(frag)) {
/* Not finished with this frag */ /* Not finished with this frag */
goto do_frag; goto do_frag;
} }

View File

@ -243,14 +243,14 @@ static void tls_append_frag(struct tls_record_info *record,
skb_frag_t *frag; skb_frag_t *frag;
frag = &record->frags[record->num_frags - 1]; frag = &record->frags[record->num_frags - 1];
if (frag->page.p == pfrag->page && if (skb_frag_page(frag) == pfrag->page &&
frag->page_offset + frag->size == pfrag->offset) { frag->page_offset + skb_frag_size(frag) == pfrag->offset) {
frag->size += size; skb_frag_size_add(frag, size);
} else { } else {
++frag; ++frag;
frag->page.p = pfrag->page; __skb_frag_set_page(frag, pfrag->page);
frag->page_offset = pfrag->offset; frag->page_offset = pfrag->offset;
frag->size = size; skb_frag_size_set(frag, size);
++record->num_frags; ++record->num_frags;
get_page(pfrag->page); get_page(pfrag->page);
} }
@ -301,8 +301,8 @@ static int tls_push_record(struct sock *sk,
frag = &record->frags[i]; frag = &record->frags[i];
sg_unmark_end(&offload_ctx->sg_tx_data[i]); sg_unmark_end(&offload_ctx->sg_tx_data[i]);
sg_set_page(&offload_ctx->sg_tx_data[i], skb_frag_page(frag), sg_set_page(&offload_ctx->sg_tx_data[i], skb_frag_page(frag),
frag->size, frag->page_offset); skb_frag_size(frag), frag->page_offset);
sk_mem_charge(sk, frag->size); sk_mem_charge(sk, skb_frag_size(frag));
get_page(skb_frag_page(frag)); get_page(skb_frag_page(frag));
} }
sg_mark_end(&offload_ctx->sg_tx_data[record->num_frags - 1]); sg_mark_end(&offload_ctx->sg_tx_data[record->num_frags - 1]);