Skip to content

Commit 06b4feb

Browse files
jlemonkuba-moo
authored andcommitted
net: group skb_shinfo zerocopy related bits together.
In preparation for expanded zerocopy (TX and RX), move the zerocopy related bits out of tx_flags into their own flag word. Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8c79382 commit 06b4feb

File tree

7 files changed

+32
-31
lines changed

7 files changed

+32
-31
lines changed

drivers/net/tap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
723723
/* copy skb_ubuf_info for callback when skb has no error */
724724
if (zerocopy) {
725725
skb_shinfo(skb)->destructor_arg = msg_control;
726-
skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
727-
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
726+
skb_shinfo(skb)->flags |= SKBFL_ZEROCOPY_FRAG;
728727
} else if (msg_control) {
729728
struct ubuf_info *uarg = msg_control;
730729
uarg->callback(NULL, uarg, false);

drivers/net/tun.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
18151815
/* copy skb_ubuf_info for callback when skb has no error */
18161816
if (zerocopy) {
18171817
skb_shinfo(skb)->destructor_arg = msg_control;
1818-
skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
1819-
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
1818+
skb_shinfo(skb)->flags |= SKBFL_ZEROCOPY_FRAG;
18201819
} else if (msg_control) {
18211820
struct ubuf_info *uarg = msg_control;
18221821
uarg->callback(NULL, uarg, false);

drivers/net/xen-netback/interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
/* Number of bytes allowed on the internal guest Rx queue. */
4848
#define XENVIF_RX_QUEUE_BYTES (XEN_NETIF_RX_RING_SIZE/2 * PAGE_SIZE)
4949

50-
/* This function is used to set SKBTX_DEV_ZEROCOPY as well as
50+
/* This function is used to set SKBFL_ZEROCOPY_ENABLE as well as
5151
* increasing the inflight counter. We need to increase the inflight
5252
* counter because core driver calls into xenvif_zerocopy_callback
5353
* which calls xenvif_skb_zerocopy_complete.
5454
*/
5555
void xenvif_skb_zerocopy_prepare(struct xenvif_queue *queue,
5656
struct sk_buff *skb)
5757
{
58-
skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
58+
skb_shinfo(skb)->flags |= SKBFL_ZEROCOPY_ENABLE;
5959
atomic_inc(&queue->inflight_packets);
6060
}
6161

include/linux/skbuff.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -430,28 +430,32 @@ enum {
430430
/* device driver is going to provide hardware time stamp */
431431
SKBTX_IN_PROGRESS = 1 << 2,
432432

433-
/* device driver supports TX zero-copy buffers */
434-
SKBTX_DEV_ZEROCOPY = 1 << 3,
435-
436433
/* generate wifi status information (where possible) */
437434
SKBTX_WIFI_STATUS = 1 << 4,
438435

439-
/* This indicates at least one fragment might be overwritten
440-
* (as in vmsplice(), sendfile() ...)
441-
* If we need to compute a TX checksum, we'll need to copy
442-
* all frags to avoid possible bad checksum
443-
*/
444-
SKBTX_SHARED_FRAG = 1 << 5,
445-
446436
/* generate software time stamp when entering packet scheduling */
447437
SKBTX_SCHED_TSTAMP = 1 << 6,
448438
};
449439

450-
#define SKBTX_ZEROCOPY_FRAG (SKBTX_DEV_ZEROCOPY | SKBTX_SHARED_FRAG)
451440
#define SKBTX_ANY_SW_TSTAMP (SKBTX_SW_TSTAMP | \
452441
SKBTX_SCHED_TSTAMP)
453442
#define SKBTX_ANY_TSTAMP (SKBTX_HW_TSTAMP | SKBTX_ANY_SW_TSTAMP)
454443

444+
/* Definitions for flags in struct skb_shared_info */
445+
enum {
446+
/* use zcopy routines */
447+
SKBFL_ZEROCOPY_ENABLE = BIT(0),
448+
449+
/* This indicates at least one fragment might be overwritten
450+
* (as in vmsplice(), sendfile() ...)
451+
* If we need to compute a TX checksum, we'll need to copy
452+
* all frags to avoid possible bad checksum
453+
*/
454+
SKBFL_SHARED_FRAG = BIT(1),
455+
};
456+
457+
#define SKBFL_ZEROCOPY_FRAG (SKBFL_ZEROCOPY_ENABLE | SKBFL_SHARED_FRAG)
458+
455459
/*
456460
* The callback notifies userspace to release buffers when skb DMA is done in
457461
* lower device, the skb last reference should be 0 when calling this.
@@ -506,7 +510,7 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb,
506510
* the end of the header data, ie. at skb->end.
507511
*/
508512
struct skb_shared_info {
509-
__u8 __unused;
513+
__u8 flags;
510514
__u8 meta_len;
511515
__u8 nr_frags;
512516
__u8 tx_flags;
@@ -1433,7 +1437,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
14331437

14341438
static inline struct ubuf_info *skb_zcopy(struct sk_buff *skb)
14351439
{
1436-
bool is_zcopy = skb && skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY;
1440+
bool is_zcopy = skb && skb_shinfo(skb)->flags & SKBFL_ZEROCOPY_ENABLE;
14371441

14381442
return is_zcopy ? skb_uarg(skb) : NULL;
14391443
}
@@ -1452,14 +1456,14 @@ static inline void skb_zcopy_set(struct sk_buff *skb, struct ubuf_info *uarg,
14521456
else
14531457
skb_zcopy_get(uarg);
14541458
skb_shinfo(skb)->destructor_arg = uarg;
1455-
skb_shinfo(skb)->tx_flags |= SKBTX_ZEROCOPY_FRAG;
1459+
skb_shinfo(skb)->flags |= SKBFL_ZEROCOPY_FRAG;
14561460
}
14571461
}
14581462

14591463
static inline void skb_zcopy_set_nouarg(struct sk_buff *skb, void *val)
14601464
{
14611465
skb_shinfo(skb)->destructor_arg = (void *)((uintptr_t) val | 0x1UL);
1462-
skb_shinfo(skb)->tx_flags |= SKBTX_ZEROCOPY_FRAG;
1466+
skb_shinfo(skb)->flags |= SKBFL_ZEROCOPY_FRAG;
14631467
}
14641468

14651469
static inline bool skb_zcopy_is_nouarg(struct sk_buff *skb)
@@ -1497,7 +1501,7 @@ static inline void skb_zcopy_clear(struct sk_buff *skb, bool zerocopy_success)
14971501
if (!skb_zcopy_is_nouarg(skb))
14981502
uarg->callback(skb, uarg, zerocopy_success);
14991503

1500-
skb_shinfo(skb)->tx_flags &= ~SKBTX_ZEROCOPY_FRAG;
1504+
skb_shinfo(skb)->flags &= ~SKBFL_ZEROCOPY_FRAG;
15011505
}
15021506
}
15031507

@@ -3323,7 +3327,7 @@ static inline int skb_linearize(struct sk_buff *skb)
33233327
static inline bool skb_has_shared_frag(const struct sk_buff *skb)
33243328
{
33253329
return skb_is_nonlinear(skb) &&
3326-
skb_shinfo(skb)->tx_flags & SKBTX_SHARED_FRAG;
3330+
skb_shinfo(skb)->flags & SKBFL_SHARED_FRAG;
33273331
}
33283332

33293333
/**

net/core/skbuff.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ static int skb_zerocopy_clone(struct sk_buff *nskb, struct sk_buff *orig,
13271327
* @skb: the skb to modify
13281328
* @gfp_mask: allocation priority
13291329
*
1330-
* This must be called on SKBTX_DEV_ZEROCOPY skb.
1330+
* This must be called on skb with SKBFL_ZEROCOPY_ENABLE.
13311331
* It will copy all frags into kernel and drop the reference
13321332
* to userspace pages.
13331333
*
@@ -3264,8 +3264,7 @@ void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len)
32643264
{
32653265
int pos = skb_headlen(skb);
32663266

3267-
skb_shinfo(skb1)->tx_flags |= skb_shinfo(skb)->tx_flags &
3268-
SKBTX_SHARED_FRAG;
3267+
skb_shinfo(skb1)->flags |= skb_shinfo(skb)->flags & SKBFL_SHARED_FRAG;
32693268
skb_zerocopy_clone(skb1, skb, 0);
32703269
if (len < pos) /* Split line is inside header. */
32713270
skb_split_inside_header(skb, skb1, len, pos);
@@ -3954,8 +3953,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
39543953
skb_copy_from_linear_data_offset(head_skb, offset,
39553954
skb_put(nskb, hsize), hsize);
39563955

3957-
skb_shinfo(nskb)->tx_flags |= skb_shinfo(head_skb)->tx_flags &
3958-
SKBTX_SHARED_FRAG;
3956+
skb_shinfo(nskb)->flags |= skb_shinfo(head_skb)->flags &
3957+
SKBFL_SHARED_FRAG;
39593958

39603959
if (skb_orphan_frags(frag_skb, GFP_ATOMIC) ||
39613960
skb_zerocopy_clone(nskb, frag_skb, GFP_ATOMIC))

net/ipv4/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ struct sk_buff *tcp_build_frag(struct sock *sk, int size_goal, int flags,
10101010
}
10111011

10121012
if (!(flags & MSG_NO_SHARED_FRAGS))
1013-
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
1013+
skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG;
10141014

10151015
skb->len += copy;
10161016
skb->data_len += copy;

net/kcm/kcmsock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static ssize_t kcm_sendpage(struct socket *sock, struct page *page,
786786

787787
if (skb_can_coalesce(skb, i, page, offset)) {
788788
skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], size);
789-
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
789+
skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG;
790790
goto coalesced;
791791
}
792792

@@ -834,7 +834,7 @@ static ssize_t kcm_sendpage(struct socket *sock, struct page *page,
834834

835835
get_page(page);
836836
skb_fill_page_desc(skb, i, page, offset, size);
837-
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
837+
skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG;
838838

839839
coalesced:
840840
skb->len += size;

0 commit comments

Comments
 (0)