Skip to contentSkip to conversation

mlx4_en: fix endianness with blue frame support

DISCUSSION Dan Carpenter 2 participants 3 messages Sep 18, 2012 – Sep 24, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello Thadeu Lima de Souza Cascardo,

The patch c5d6136e10d6: "mlx4_en: fix endianness with blue frame support" from Oct 10, 2011, leads to the following warning:
drivers/net/ethernet/mellanox/mlx4/en_tx.c:720 mlx4_en_xmit()
warn: potential memory corrupting cast. 4 vs 2 bytes

That patch introduced a call to cpu_to_be32() and added some endian notation.

	*(__be32 *) (&tx_desc->ctrl.vlan_tag) |= cpu_to_be32(ring->doorbell_qpn);

But it doesn't make sense because the data type is declared as u16 in the header and we would be corrupting the next elements in the struct which are ins_vlan and fence_size.

struct mlx4_wqe_ctrl_seg {
        __be32                  owner_opcode;
        __be16                  vlan_tag;
        u8                      ins_vlan;
        u8                      fence_size;

I guess the reason we get away with it is that the ->doorbell_qpn is normally less that 65k. But doorbell_qpn is a u32 type so I think there is a risk here.

regards,
dan carpenter

#1 lore raw
Quoted 13 lines · Dan Carpenter

Hello Thadeu Lima de Souza Cascardo,

The patch c5d6136e10d6: "mlx4_en: fix endianness with blue frame support" from Oct 10, 2011, leads to the following warning:
drivers/net/ethernet/mellanox/mlx4/en_tx.c:720 mlx4_en_xmit()
warn: potential memory corrupting cast. 4 vs 2 bytes

That patch introduced a call to cpu_to_be32() and added some endian notation.

        *(__be32 *) (&tx_desc->ctrl.vlan_tag) |= cpu_to_be32(ring->doorbell_qpn);

But it doesn't make sense because the data type is declared as u16 in the header and we would be corrupting the next elements in the struct which are ins_vlan and fence_size.

Quoted 8 lines
struct mlx4_wqe_ctrl_seg {
        __be32                  owner_opcode;
        __be16                  vlan_tag;
        u8                      ins_vlan;
        u8                      fence_size;

I guess the reason we get away with it is that the ->doorbell_qpn is normally less that 65k. But doorbell_qpn is a u32 type so I think there is a risk here.

Dan,

QP numbers are 24 bit in size, under blue-flame setting the QP number is written
over the "vlan_tag" field and potentially also the "ins_vlan" field of the control segment,
we can do a little cleanup here with introducing a modified version of the mlx4_wqe_ctrl_seg
structure over which the cast is made under the blue-flame flow.

Or.

#2 lore raw
Quoted 34 lines · Or Gerlitz
Quoted 13 lines · Dan Carpenter

Hello Thadeu Lima de Souza Cascardo,

The patch c5d6136e10d6: "mlx4_en: fix endianness with blue frame support" from Oct 10, 2011, leads to the following warning:
drivers/net/ethernet/mellanox/mlx4/en_tx.c:720 mlx4_en_xmit()
warn: potential memory corrupting cast. 4 vs 2 bytes

That patch introduced a call to cpu_to_be32() and added some endian notation.

        *(__be32 *) (&tx_desc->ctrl.vlan_tag) |= cpu_to_be32(ring->doorbell_qpn);

But it doesn't make sense because the data type is declared as u16 in the header and we would be corrupting the next elements in the struct which are ins_vlan and fence_size.

Quoted 8 lines
struct mlx4_wqe_ctrl_seg {
        __be32                  owner_opcode;
        __be16                  vlan_tag;
        u8                      ins_vlan;
        u8                      fence_size;

I guess the reason we get away with it is that the ->doorbell_qpn is normally less that 65k. But doorbell_qpn is a u32 type so I think there is a risk here.

Dan,

QP numbers are 24 bit in size, under blue-flame setting the QP number is written
over the "vlan_tag" field and potentially also the "ins_vlan" field of the control segment,
we can do a little cleanup here with introducing a modified version of the mlx4_wqe_ctrl_seg
structure over which the cast is made under the blue-flame flow.

Quoted 1 line

Or.

Actually 24 bit big endian would mean they almost always over-write the fence_size field. It's the highest byte of vlan_tag which would not be modified.

I'm not sure how this ever worked. Something is confusing here.

regards,
dan carpenter