Skip to contentSkip to conversation

mac80211: do not aggregate frames if max_frags is set to one

PATCH In review Lorenzo Bianconi 2 participants 14 messages Aug 29, 2018 – Aug 30, 2018 2 messages not in the archive mac80211

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/1 mac80211: do not aggregate frames if max_frags is set to one

In reply to a message not in the archive

Do not try to aggregate packets in a A-MSDU frame and add A-MSDU header on the first packet if max_tx_fragments or max_amsdu_subframes are set to one

---
Changes since v1:
- rebased on top of mac80211 master branch
- removed ieee80211_amsdu_realloc_pad chunk

---
 net/mac80211/tx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/mac80211/tx.c +3 -3
index 6a362b2882d3..75646e3fb3d9 100644
@@ -3213,9 +3213,6 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
 	if (skb->len + head->len > max_amsdu_len)
 		goto out;
 
-	if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
-		goto out;
-
 	nfrags = 1 + skb_shinfo(skb)->nr_frags;
 	nfrags += 1 + skb_shinfo(head)->nr_frags;
 	frag_tail = &skb_shinfo(head)->frag_list;
@@ -3231,6 +3228,9 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
 	if (max_frags && nfrags > max_frags)
 		goto out;
 
+	if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
+		goto out;
+
 	/*
 	 * Pad out the previous subframe to a multiple of 4 by adding the
 	 * padding to the next one, that's being added. Note that head->len
Signature · 1 line
2.17.1
maintainer
#2 lore raw
Quoted 10 lines · Lorenzo Bianconi

Do not try to aggregate packets in a A-MSDU frame and add A-MSDU header on the first packet if max_tx_fragments or max_amsdu_subframes are set to one

---
Changes since v1:
- rebased on top of mac80211 master branch
- removed ieee80211_amsdu_realloc_pad chunk

Don't you still have to account for the changed header length if the second one fails or something?

You said you wanted to account for the pad bytes - which now aren't there - but didn't that also take the changed header of the first subframe into account?

johannes

#3 lore raw
Quoted 6 lines · Lorenzo Bianconi
Quoted 4 lines

Do not try to aggregate packets in a A-MSDU frame and add A-MSDU header on the first packet if max_tx_fragments or max_amsdu_subframes are set to one

Quoted 9 lines
Quoted 6 lines

---
Changes since v1:
- rebased on top of mac80211 master branch
- removed ieee80211_amsdu_realloc_pad chunk

Don't you still have to account for the changed header length if the second one fails or something?

That has been fixed by Sara's patch since now we add the pad directly on the head of the
subsequent subframes (not to the tail of the first one). Am I missing something?

Regards,
Lorenzo

Quoted 5 lines

You said you wanted to account for the pad bytes - which now aren't there - but didn't that also take the changed header of the first subframe into account?

johannes

#5 lore raw
In reply to a message not in the archive
Quoted 9 lines · Johannes Berg
Quoted 3 lines · Lorenzo Bianconi

That has been fixed by Sara's patch since now we add the pad directly on the head of the
subsequent subframes (not to the tail of the first one). Am I missing something?

As far as the pad is concerned, yes, but I think the header length also changes?

Ops, maybe I got your point:
ieee80211_amsdu_realloc_pad() in ieee80211_amsdu_prepare_head() can expand the headroom on the first frame
but if ieee80211_amsdu_realloc_pad() on the second one fails, we do not take into account the extra len added on the
first subframe. Is that what you mean?

Quoted 3 lines

I'm too tired now - will think about it again tomorrow.

ack :)

Regards,
Lorenzo

Quoted 1 line

johannes

maintainer
#6 lore raw

First of all, I applied your patch with now, but changed the commit message. I hope it still makes sense.

Quoted 3 lines

Ops, maybe I got your point:
ieee80211_amsdu_realloc_pad() in ieee80211_amsdu_prepare_head() can expand the headroom on the first frame

Right.

Quoted 3 lines

but if ieee80211_amsdu_realloc_pad() on the second one fails, we do not take into account the extra len added on the
first subframe. Is that what you mean?

Yes, that's what I was thinking of, but you described it much better than me :)

If this needs to be addressed, please send a separate patch.

johannes

#7 lore raw
Quoted 2 lines

First of all, I applied your patch with now, but changed the commit message. I hope it still makes sense.

Thx, definitely better than mine :)

Quoted 7 lines
Quoted 4 lines

Ops, maybe I got your point:
ieee80211_amsdu_realloc_pad() in ieee80211_amsdu_prepare_head() can expand the headroom on the first frame

Right.

Quoted 8 lines
Quoted 3 lines

but if ieee80211_amsdu_realloc_pad() on the second one fails, we do not take into account the extra len added on the
first subframe. Is that what you mean?

Yes, that's what I was thinking of, but you described it much better than me :)

If this needs to be addressed, please send a separate patch.

Reviewing the code I guess it is not necessary since pskb_expand_head routine does not modify head->len (or skb->len). Packet len (if we consider padding) is only modified in:

memset(skb_push(skb, pad), 0, pad);

and if we hit that point, we will account new skb->len in flow backlog. Do you agree?

Looking at the code maybe I spotted another issue, I guess there is an off-by-one issue in 'n' estimation since it does not take into account the first frame. We hit the line:

while (*frag_tail) {
}

starting from the second subframe, but if the head does not have packet in the fraglist we will end up having n = 1, while it is actually the second frame. Does n count just subsequent frames or also the first one?

Regards,
Lorenzo

Quoted 2 lines

johannes

maintainer
#8 lore raw
Quoted 2 lines · Lorenzo Bianconi

Reviewing the code I guess it is not necessary since pskb_expand_head routine does not modify head->len (or skb->len).

True.

Quoted 6 lines

Packet len (if we consider padding) is only modified in:

memset(skb_push(skb, pad), 0, pad);

and if we hit that point, we will account new skb->len in flow backlog. Do you agree?

Right, but that's the *pad*. I was thinking about the header conversion.

Let's say you decided to add the second frame to the A-MSDU, at which point the first one isn't really an A-MSDU yet. So we get to:

        if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))

which changes the header of "head" to be 14 bytes longer:

	skb_push(skb, sizeof(*amsdu_hdr));

But now let's say we get a failure here when reallocating the second subframe:

        if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
                                                     2 + pad))
                goto out;

Now we have changed "head", which is on the FQ, but we haven't changed the FQ accounting. So I *think* we still need this:

net/mac80211/tx.c +7 -5
@@ -3239,7 +3239,7 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
 
 	if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
 						     2 + pad))
-		goto out;
+		goto out_recalc;
 
 	ret = true;
 	data = skb_push(skb, ETH_ALEN + 2);
@@ -3256,11 +3256,13 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
 	head->data_len += skb->len;
 	*frag_tail = skb;
 
-	flow->backlog += head->len - orig_len;
-	tin->backlog_bytes += head->len - orig_len;
-
-	fq_recalc_backlog(fq, tin, flow);
+out_recalc:
+	if (head->len != orig_len) {
+		flow->backlog += head->len - orig_len;
+		tin->backlog_bytes += head->len - orig_len;
 
+		fq_recalc_backlog(fq, tin, flow);
+	}
 out:
 	spin_unlock_bh(&fq->lock);
 
Quoted 9 lines

Looking at the code maybe I spotted another issue, I guess there is an off-by-one issue in 'n' estimation since it does not take into account the first frame. We hit the line:

while (*frag_tail) {
}

starting from the second subframe, but if the head does not have packet in the fraglist we will end up having n = 1, while it is actually the second frame.

Hmm, not sure I follow? "head" is the A-MSDU, containing the A-MSDU header and the first subframe in skb->data (and/or frags), with the subframes 2..N in the fraglist.

So I think this is right?

johannes

#9 lore raw
Quoted 54 lines · Lorenzo Bianconi
Quoted 3 lines

Reviewing the code I guess it is not necessary since pskb_expand_head routine does not modify head->len (or skb->len).

True.

Quoted 6 lines

Packet len (if we consider padding) is only modified in:

memset(skb_push(skb, pad), 0, pad);

and if we hit that point, we will account new skb->len in flow backlog. Do you agree?

Right, but that's the *pad*. I was thinking about the header conversion.

Let's say you decided to add the second frame to the A-MSDU, at which point the first one isn't really an A-MSDU yet. So we get to:

        if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))

which changes the header of "head" to be 14 bytes longer:

	skb_push(skb, sizeof(*amsdu_hdr));

But now let's say we get a failure here when reallocating the second subframe:

        if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
                                                     2 + pad))
                goto out;

Now we have changed "head", which is on the FQ, but we haven't changed the FQ accounting. So I *think* we still need this:

net/mac80211/tx.c +1 -5
@@ -3239,7 +3239,7 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
 
 	if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
 						     2 + pad))
-		goto out;
+		goto out_recalc;
 
 	ret = true;
 	data = skb_push(skb, ETH_ALEN + 2);
@@ -3256,11 +3256,13 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
 	head->data_len += skb->len;
 	*frag_tail = skb;
 
-	flow->backlog += head->len - orig_len;
-	tin->backlog_bytes += head->len - orig_len;
-
-	fq_recalc_backlog(fq, tin, flow);

net/mac80211/tx.c static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata, · line 3268

Quoted 10 lines
net/mac80211/tx.c +6 -0
+out_recalc:
+	if (head->len != orig_len) {
+		flow->backlog += head->len - orig_len;
+		tin->backlog_bytes += head->len - orig_len;
 
+		fq_recalc_backlog(fq, tin, flow);
+	}
 out:
 	spin_unlock_bh(&fq->lock);
 

ack, I agree. Do you want I send a patch to fix it?

Quoted 9 lines
Quoted 9 lines

Looking at the code maybe I spotted another issue, I guess there is an off-by-one issue in 'n' estimation since it does not take into account the first frame. We hit the line:

while (*frag_tail) {
}

Quoted 8 lines
Quoted 2 lines

starting from the second subframe, but if the head does not have packet in the fraglist we will end up having n = 1, while it is actually the second frame.

Hmm, not sure I follow? "head" is the A-MSDU, containing the A-MSDU header and the first subframe in skb->data (and/or frags), with the subframes 2..N in the fraglist.

So I think this is right?

yep, correct. But when we are analyzing the second subframe what is the correct value for 'n'? 1 or 2? At the moment I guess it is set to 1 if frag_tail is NULL for head.

Regards,
Lorenzo

Quoted 3 lines

johannes

maintainer
#10 lore raw
Quoted 2 lines · Lorenzo Bianconi

ack, I agree. Do you want I send a patch to fix it?

I have it written now, I'll just commit & send it out.

Quoted 8 lines
Quoted 5 lines

Hmm, not sure I follow? "head" is the A-MSDU, containing the A-MSDU header and the first subframe in skb->data (and/or frags), with the subframes 2..N in the fraglist.

So I think this is right?

yep, correct. But when we are analyzing the second subframe what is the correct value for 'n'? 1 or 2? At the moment I guess it is set to 1 if frag_tail is NULL for head.

Ah. I guess you're right. So basically setting max_subframes to 1 doesn't avoid A-MSDUs completely, since n will still be 1 when we get here ... good point, care to send a patch?

johannes

#11 lore raw
Quoted 5 lines · Lorenzo Bianconi
Quoted 2 lines

ack, I agree. Do you want I send a patch to fix it?

I have it written now, I'll just commit & send it out.

Sound good, thx :)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Hmm, not sure I follow? "head" is the A-MSDU, containing the A-MSDU header and the first subframe in skb->data (and/or frags), with the subframes 2..N in the fraglist.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

So I think this is right?

yep, correct. But when we are analyzing the second subframe what is the correct value for 'n'? 1 or 2? At the moment I guess it is set to 1 if frag_tail is NULL for head.

Ah. I guess you're right. So basically setting max_subframes to 1 doesn't avoid A-MSDUs completely, since n will still be 1 when we get here ... good point, care to send a patch?

ack, I will send a patch for it
Regards,

Lorenzo

Quoted 1 line

johannes

maintainer
#12 lore raw
Quoted 18 lines · Lorenzo Bianconi
Quoted 5 lines · Lorenzo Bianconi
Quoted 2 lines

ack, I agree. Do you want I send a patch to fix it?

I have it written now, I'll just commit & send it out.

Sound good, thx :)

Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Hmm, not sure I follow? "head" is the A-MSDU, containing the A-MSDU header and the first subframe in skb->data (and/or frags), with the subframes 2..N in the fraglist.

So I think this is right?

yep, correct. But when we are analyzing the second subframe what is the correct value for 'n'? 1 or 2? At the moment I guess it is set to 1 if frag_tail is NULL for head.

Quoted 6 lines
Quoted 4 lines

Ah. I guess you're right. So basically setting max_subframes to 1 doesn't avoid A-MSDUs completely, since n will still be 1 when we get here ... good point, care to send a patch?

ack, I will send a patch for it

The same is true for nfrags, btw, no?

johannes

maintainer
#13 lore raw
Quoted 19 lines · Johannes Berg
Quoted 18 lines · Lorenzo Bianconi
Quoted 5 lines · Lorenzo Bianconi
Quoted 2 lines

ack, I agree. Do you want I send a patch to fix it?

I have it written now, I'll just commit & send it out.

Sound good, thx :)

Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Hmm, not sure I follow? "head" is the A-MSDU, containing the A-MSDU header and the first subframe in skb->data (and/or frags), with the subframes 2..N in the fraglist.

So I think this is right?

yep, correct. But when we are analyzing the second subframe what is the correct value for 'n'? 1 or 2? At the moment I guess it is set to 1 if frag_tail is NULL for head.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Ah. I guess you're right. So basically setting max_subframes to 1 doesn't avoid A-MSDUs completely, since n will still be 1 when we get here ... good point, care to send a patch?

ack, I will send a patch for it

The same is true for nfrags, btw, no?

No, it's not, just misread the code.

johannes

#14 lore raw
In reply to Johannes Berg
Quoted 19 lines · Johannes Berg
Quoted 18 lines · Lorenzo Bianconi
Quoted 5 lines · Lorenzo Bianconi
Quoted 2 lines

ack, I agree. Do you want I send a patch to fix it?

I have it written now, I'll just commit & send it out.

Sound good, thx :)

Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Hmm, not sure I follow? "head" is the A-MSDU, containing the A-MSDU header and the first subframe in skb->data (and/or frags), with the subframes 2..N in the fraglist.

So I think this is right?

yep, correct. But when we are analyzing the second subframe what is the correct value for 'n'? 1 or 2? At the moment I guess it is set to 1 if frag_tail is NULL for head.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Ah. I guess you're right. So basically setting max_subframes to 1 doesn't avoid A-MSDUs completely, since n will still be 1 when we get here ... good point, care to send a patch?

ack, I will send a patch for it

The same is true for nfrags, btw, no?

I do not think so since for nfrags we have:
nfrags = 1 + skb_shinfo(skb)->nr_frags;
nfrags += 1 + skb_shinfo(head)->nr_frags;

and even if frag_tail is NULL we will have nfrags = 2.

Agree?

Lorenzo

Quoted 2 lines

johannes

maintainer
#15 lore raw
Quoted 8 lines · Lorenzo Bianconi

I do not think so since for nfrags we have:
nfrags = 1 + skb_shinfo(skb)->nr_frags;
nfrags += 1 + skb_shinfo(head)->nr_frags;

and even if frag_tail is NULL we will have nfrags = 2.

Agree?

Yeah, I misread those two lines.

johannes