Skip to content

Commit

Permalink
Merge branch 'timestamping'
Browse files Browse the repository at this point in the history
Alexander Duyck says:

====================
This change makes it so that the core path for the phy timestamping logic
is shared between skb_tx_tstamp and skb_complete_tx_timestamp.  In addition
it provides a means of using the same skb clone type path in non phy
timestamping drivers.

The main motivation for this is to enable non-phy drivers to be able to
manipulate tx timestamp skbs for such things as putting them in lists or
setting aside buffer in the context block.

v2: Incorporated suggested changes from Willem de Bruijn and Eric Dumazet
     dropped uneeded comment
     restored order of hwtstamp vs swtstamp
     added destructor for skb
    Dropped usage of skb_complete_tx_timestamp as a kfree_skb w/ destructor

v3: Updated destructor handling and dealt with socket reference counting issues

v4: Split out combining destructors into a separate patch
====================
  • Loading branch information
David S. Miller committed Sep 6, 2014
2 parents d546c62 + 82eabd9 commit 2c048e6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 67 deletions.
6 changes: 3 additions & 3 deletions drivers/net/phy/dp83640.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ static void dp83640_remove(struct phy_device *phydev)
kfree_skb(skb);

while ((skb = skb_dequeue(&dp83640->tx_queue)) != NULL)
skb_complete_tx_timestamp(skb, NULL);
kfree_skb(skb);

clock = dp83640_clock_get(dp83640->clock);

Expand Down Expand Up @@ -1405,7 +1405,7 @@ static void dp83640_txtstamp(struct phy_device *phydev,

case HWTSTAMP_TX_ONESTEP_SYNC:
if (is_sync(skb, type)) {
skb_complete_tx_timestamp(skb, NULL);
kfree_skb(skb);
return;
}
/* fall through */
Expand All @@ -1416,7 +1416,7 @@ static void dp83640_txtstamp(struct phy_device *phydev,

case HWTSTAMP_TX_OFF:
default:
skb_complete_tx_timestamp(skb, NULL);
kfree_skb(skb);
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,8 @@ static inline ktime_t net_invalid_timestamp(void)
return ktime_set(0, 0);
}

struct sk_buff *skb_clone_sk(struct sk_buff *skb);

#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING

void skb_clone_tx_timestamp(struct sk_buff *skb);
Expand Down
5 changes: 5 additions & 0 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,12 @@ struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
void sock_wfree(struct sk_buff *skb);
void skb_orphan_partial(struct sk_buff *skb);
void sock_rfree(struct sk_buff *skb);
void sock_efree(struct sk_buff *skb);
#ifdef CONFIG_INET
void sock_edemux(struct sk_buff *skb);
#else
#define sock_edemux(skb) sock_efree(skb)
#endif

int sock_setsockopt(struct socket *sock, int level, int op,
char __user *optval, unsigned int optlen);
Expand Down
79 changes: 58 additions & 21 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3511,32 +3511,33 @@ struct sk_buff *sock_dequeue_err_skb(struct sock *sk)
}
EXPORT_SYMBOL(sock_dequeue_err_skb);

void __skb_tstamp_tx(struct sk_buff *orig_skb,
struct skb_shared_hwtstamps *hwtstamps,
struct sock *sk, int tstype)
struct sk_buff *skb_clone_sk(struct sk_buff *skb)
{
struct sock_exterr_skb *serr;
struct sk_buff *skb;
int err;
struct sock *sk = skb->sk;
struct sk_buff *clone;

if (!sk)
return;
if (!sk || !atomic_inc_not_zero(&sk->sk_refcnt))
return NULL;

if (hwtstamps) {
*skb_hwtstamps(orig_skb) =
*hwtstamps;
} else {
/*
* no hardware time stamps available,
* so keep the shared tx_flags and only
* store software time stamp
*/
orig_skb->tstamp = ktime_get_real();
clone = skb_clone(skb, GFP_ATOMIC);
if (!clone) {
sock_put(sk);
return NULL;
}

skb = skb_clone(orig_skb, GFP_ATOMIC);
if (!skb)
return;
clone->sk = sk;
clone->destructor = sock_efree;

return clone;
}
EXPORT_SYMBOL(skb_clone_sk);

static void __skb_complete_tx_timestamp(struct sk_buff *skb,
struct sock *sk,
int tstype)
{
struct sock_exterr_skb *serr;
int err;

serr = SKB_EXT_ERR(skb);
memset(serr, 0, sizeof(*serr));
Expand All @@ -3554,6 +3555,42 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
if (err)
kfree_skb(skb);
}

void skb_complete_tx_timestamp(struct sk_buff *skb,
struct skb_shared_hwtstamps *hwtstamps)
{
struct sock *sk = skb->sk;

/* take a reference to prevent skb_orphan() from freeing the socket */
sock_hold(sk);

*skb_hwtstamps(skb) = *hwtstamps;
__skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);

sock_put(sk);
}
EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);

void __skb_tstamp_tx(struct sk_buff *orig_skb,
struct skb_shared_hwtstamps *hwtstamps,
struct sock *sk, int tstype)
{
struct sk_buff *skb;

if (!sk)
return;

if (hwtstamps)
*skb_hwtstamps(orig_skb) = *hwtstamps;
else
orig_skb->tstamp = ktime_get_real();

skb = skb_clone(orig_skb, GFP_ATOMIC);
if (!skb)
return;

__skb_complete_tx_timestamp(skb, sk, tstype);
}
EXPORT_SYMBOL_GPL(__skb_tstamp_tx);

void skb_tstamp_tx(struct sk_buff *orig_skb,
Expand Down
10 changes: 8 additions & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,18 +1637,24 @@ void sock_rfree(struct sk_buff *skb)
}
EXPORT_SYMBOL(sock_rfree);

void sock_efree(struct sk_buff *skb)
{
sock_put(skb->sk);
}
EXPORT_SYMBOL(sock_efree);

#ifdef CONFIG_INET
void sock_edemux(struct sk_buff *skb)
{
struct sock *sk = skb->sk;

#ifdef CONFIG_INET
if (sk->sk_state == TCP_TIME_WAIT)
inet_twsk_put(inet_twsk(sk));
else
#endif
sock_put(sk);
}
EXPORT_SYMBOL(sock_edemux);
#endif

kuid_t sock_i_uid(struct sock *sk)
{
Expand Down
43 changes: 3 additions & 40 deletions net/core/timestamping.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
{
struct phy_device *phydev;
struct sk_buff *clone;
struct sock *sk = skb->sk;
unsigned int type;

if (!sk)
if (!skb->sk)
return;

type = classify(skb);
Expand All @@ -48,50 +47,14 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)

phydev = skb->dev->phydev;
if (likely(phydev->drv->txtstamp)) {
if (!atomic_inc_not_zero(&sk->sk_refcnt))
clone = skb_clone_sk(skb);
if (!clone)
return;

clone = skb_clone(skb, GFP_ATOMIC);
if (!clone) {
sock_put(sk);
return;
}

clone->sk = sk;
phydev->drv->txtstamp(phydev, clone, type);
}
}
EXPORT_SYMBOL_GPL(skb_clone_tx_timestamp);

void skb_complete_tx_timestamp(struct sk_buff *skb,
struct skb_shared_hwtstamps *hwtstamps)
{
struct sock *sk = skb->sk;
struct sock_exterr_skb *serr;
int err;

if (!hwtstamps) {
sock_put(sk);
kfree_skb(skb);
return;
}

*skb_hwtstamps(skb) = *hwtstamps;

serr = SKB_EXT_ERR(skb);
memset(serr, 0, sizeof(*serr));
serr->ee.ee_errno = ENOMSG;
serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
skb->sk = NULL;

err = sock_queue_err_skb(sk, skb);

sock_put(sk);
if (err)
kfree_skb(skb);
}
EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);

bool skb_defer_rx_timestamp(struct sk_buff *skb)
{
struct phy_device *phydev;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ void udp_v4_early_demux(struct sk_buff *skb)
return;

skb->sk = sk;
skb->destructor = sock_edemux;
skb->destructor = sock_efree;
dst = sk->sk_rx_dst;

if (dst)
Expand Down

0 comments on commit 2c048e6

Please sign in to comment.