Skip to content

Commit ada2fee

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: lan9303: fix broken backpressure in .port_fdb_dump
rtnl_fdb_dump() has logic to split a dump of PF_BRIDGE neighbors into multiple netlink skbs if the buffer provided by user space is too small (one buffer will typically handle a few hundred FDB entries). When the current buffer becomes full, nlmsg_put() in dsa_slave_port_fdb_do_dump() returns -EMSGSIZE and DSA saves the index of the last dumped FDB entry, returns to rtnl_fdb_dump() up to that point, and then the dump resumes on the same port with a new skb, and FDB entries up to the saved index are simply skipped. Since dsa_slave_port_fdb_do_dump() is pointed to by the "cb" passed to drivers, then drivers must check for the -EMSGSIZE error code returned by it. Otherwise, when a netlink skb becomes full, DSA will no longer save newly dumped FDB entries to it, but the driver will continue dumping. So FDB entries will be missing from the dump. Fix the broken backpressure by propagating the "cb" return code and allow rtnl_fdb_dump() to restart the FDB dump with a new skb. Fixes: ab33534 ("net: dsa: lan9303: Add port_fast_age and port_fdb_dump methods") Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cd39128 commit ada2fee

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

drivers/net/dsa/lan9303-core.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,12 @@ static int lan9303_alr_make_entry_raw(struct lan9303 *chip, u32 dat0, u32 dat1)
557557
return 0;
558558
}
559559

560-
typedef void alr_loop_cb_t(struct lan9303 *chip, u32 dat0, u32 dat1,
561-
int portmap, void *ctx);
560+
typedef int alr_loop_cb_t(struct lan9303 *chip, u32 dat0, u32 dat1,
561+
int portmap, void *ctx);
562562

563-
static void lan9303_alr_loop(struct lan9303 *chip, alr_loop_cb_t *cb, void *ctx)
563+
static int lan9303_alr_loop(struct lan9303 *chip, alr_loop_cb_t *cb, void *ctx)
564564
{
565-
int i;
565+
int ret = 0, i;
566566

567567
mutex_lock(&chip->alr_mutex);
568568
lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD,
@@ -582,13 +582,17 @@ static void lan9303_alr_loop(struct lan9303 *chip, alr_loop_cb_t *cb, void *ctx)
582582
LAN9303_ALR_DAT1_PORT_BITOFFS;
583583
portmap = alrport_2_portmap[alrport];
584584

585-
cb(chip, dat0, dat1, portmap, ctx);
585+
ret = cb(chip, dat0, dat1, portmap, ctx);
586+
if (ret)
587+
break;
586588

587589
lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD,
588590
LAN9303_ALR_CMD_GET_NEXT);
589591
lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD, 0);
590592
}
591593
mutex_unlock(&chip->alr_mutex);
594+
595+
return ret;
592596
}
593597

594598
static void alr_reg_to_mac(u32 dat0, u32 dat1, u8 mac[6])
@@ -606,18 +610,20 @@ struct del_port_learned_ctx {
606610
};
607611

608612
/* Clear learned (non-static) entry on given port */
609-
static void alr_loop_cb_del_port_learned(struct lan9303 *chip, u32 dat0,
610-
u32 dat1, int portmap, void *ctx)
613+
static int alr_loop_cb_del_port_learned(struct lan9303 *chip, u32 dat0,
614+
u32 dat1, int portmap, void *ctx)
611615
{
612616
struct del_port_learned_ctx *del_ctx = ctx;
613617
int port = del_ctx->port;
614618

615619
if (((BIT(port) & portmap) == 0) || (dat1 & LAN9303_ALR_DAT1_STATIC))
616-
return;
620+
return 0;
617621

618622
/* learned entries has only one port, we can just delete */
619623
dat1 &= ~LAN9303_ALR_DAT1_VALID; /* delete entry */
620624
lan9303_alr_make_entry_raw(chip, dat0, dat1);
625+
626+
return 0;
621627
}
622628

623629
struct port_fdb_dump_ctx {
@@ -626,19 +632,19 @@ struct port_fdb_dump_ctx {
626632
dsa_fdb_dump_cb_t *cb;
627633
};
628634

629-
static void alr_loop_cb_fdb_port_dump(struct lan9303 *chip, u32 dat0,
630-
u32 dat1, int portmap, void *ctx)
635+
static int alr_loop_cb_fdb_port_dump(struct lan9303 *chip, u32 dat0,
636+
u32 dat1, int portmap, void *ctx)
631637
{
632638
struct port_fdb_dump_ctx *dump_ctx = ctx;
633639
u8 mac[ETH_ALEN];
634640
bool is_static;
635641

636642
if ((BIT(dump_ctx->port) & portmap) == 0)
637-
return;
643+
return 0;
638644

639645
alr_reg_to_mac(dat0, dat1, mac);
640646
is_static = !!(dat1 & LAN9303_ALR_DAT1_STATIC);
641-
dump_ctx->cb(mac, 0, is_static, dump_ctx->data);
647+
return dump_ctx->cb(mac, 0, is_static, dump_ctx->data);
642648
}
643649

644650
/* Set a static ALR entry. Delete entry if port_map is zero */
@@ -1210,9 +1216,7 @@ static int lan9303_port_fdb_dump(struct dsa_switch *ds, int port,
12101216
};
12111217

12121218
dev_dbg(chip->dev, "%s(%d)\n", __func__, port);
1213-
lan9303_alr_loop(chip, alr_loop_cb_fdb_port_dump, &dump_ctx);
1214-
1215-
return 0;
1219+
return lan9303_alr_loop(chip, alr_loop_cb_fdb_port_dump, &dump_ctx);
12161220
}
12171221

12181222
static int lan9303_port_mdb_prepare(struct dsa_switch *ds, int port,

0 commit comments

Comments
 (0)