1. 05 1月, 2022 7 次提交
    • V
      net: dsa: move dsa_switch_tree :: ports and lags to first cache line · b035c88c
      Vladimir Oltean 提交于
      dst->ports is accessed most notably by dsa_master_find_slave(), which is
      invoked in the RX path.
      
      dst->lags is accessed by dsa_lag_dev(), which is invoked in the RX path
      of tag_dsa.c.
      
      dst->tag_ops, dst->default_proto and dst->pd don't need to be in the
      first cache line, so they are moved out by this change.
      
      Before:
      
      pahole -C dsa_switch_tree net/dsa/slave.o
      struct dsa_switch_tree {
              struct list_head           list;                 /*     0    16 */
              struct raw_notifier_head   nh;                   /*    16     8 */
              unsigned int               index;                /*    24     4 */
              struct kref                refcount;             /*    28     4 */
              bool                       setup;                /*    32     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              const struct dsa_device_ops  * tag_ops;          /*    40     8 */
              enum dsa_tag_protocol      default_proto;        /*    48     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_platform_data * pd;                   /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct list_head           ports;                /*    64    16 */
              struct list_head           rtable;               /*    80    16 */
              struct net_device * *      lags;                 /*    96     8 */
              unsigned int               lags_len;             /*   104     4 */
              unsigned int               last_switch;          /*   108     4 */
      
              /* size: 112, cachelines: 2, members: 13 */
              /* sum members: 101, holes: 2, sum holes: 11 */
              /* last cacheline: 48 bytes */
      };
      
      After:
      
      pahole -C dsa_switch_tree net/dsa/slave.o
      struct dsa_switch_tree {
              struct list_head           list;                 /*     0    16 */
              struct list_head           ports;                /*    16    16 */
              struct raw_notifier_head   nh;                   /*    32     8 */
              unsigned int               index;                /*    40     4 */
              struct kref                refcount;             /*    44     4 */
              struct net_device * *      lags;                 /*    48     8 */
              bool                       setup;                /*    56     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              /* --- cacheline 1 boundary (64 bytes) --- */
              const struct dsa_device_ops  * tag_ops;          /*    64     8 */
              enum dsa_tag_protocol      default_proto;        /*    72     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_platform_data * pd;                   /*    80     8 */
              struct list_head           rtable;               /*    88    16 */
              unsigned int               lags_len;             /*   104     4 */
              unsigned int               last_switch;          /*   108     4 */
      
              /* size: 112, cachelines: 2, members: 13 */
              /* sum members: 101, holes: 2, sum holes: 11 */
              /* last cacheline: 48 bytes */
      };
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b035c88c
    • V
      net: dsa: make dsa_switch :: num_ports an unsigned int · 258030ac
      Vladimir Oltean 提交于
      Currently, num_ports is declared as size_t, which is defined as
      __kernel_ulong_t, therefore it occupies 8 bytes of memory.
      
      Even switches with port numbers in the range of tens are exotic, so
      there is no need for this amount of storage.
      
      Additionally, because the max_num_bridges member right above it is also
      4 bytes, it means the compiler needs to add padding between the last 2
      fields. By reducing the size, we don't need that padding and can reduce
      the struct size.
      
      Before:
      
      pahole -C dsa_switch net/dsa/slave.o
      struct dsa_switch {
              struct device *            dev;                  /*     0     8 */
              struct dsa_switch_tree *   dst;                  /*     8     8 */
              unsigned int               index;                /*    16     4 */
              u32                        setup:1;              /*    20: 0  4 */
              u32                        vlan_filtering_is_global:1; /*    20: 1  4 */
              u32                        needs_standalone_vlan_filtering:1; /*    20: 2  4 */
              u32                        configure_vlan_while_not_filtering:1; /*    20: 3  4 */
              u32                        untag_bridge_pvid:1;  /*    20: 4  4 */
              u32                        assisted_learning_on_cpu_port:1; /*    20: 5  4 */
              u32                        vlan_filtering:1;     /*    20: 6  4 */
              u32                        pcs_poll:1;           /*    20: 7  4 */
              u32                        mtu_enforcement_ingress:1; /*    20: 8  4 */
      
              /* XXX 23 bits hole, try to pack */
      
              struct notifier_block      nb;                   /*    24    24 */
      
              /* XXX last struct has 4 bytes of padding */
      
              void *                     priv;                 /*    48     8 */
              void *                     tagger_data;          /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_chip_data *     cd;                   /*    64     8 */
              const struct dsa_switch_ops  * ops;              /*    72     8 */
              u32                        phys_mii_mask;        /*    80     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct mii_bus *           slave_mii_bus;        /*    88     8 */
              unsigned int               ageing_time_min;      /*    96     4 */
              unsigned int               ageing_time_max;      /*   100     4 */
              struct dsa_8021q_context * tag_8021q_ctx;        /*   104     8 */
              struct devlink *           devlink;              /*   112     8 */
              unsigned int               num_tx_queues;        /*   120     4 */
              unsigned int               num_lag_ids;          /*   124     4 */
              /* --- cacheline 2 boundary (128 bytes) --- */
              unsigned int               max_num_bridges;      /*   128     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              size_t                     num_ports;            /*   136     8 */
      
              /* size: 144, cachelines: 3, members: 27 */
              /* sum members: 132, holes: 2, sum holes: 8 */
              /* sum bitfield members: 9 bits, bit holes: 1, sum bit holes: 23 bits */
              /* paddings: 1, sum paddings: 4 */
              /* last cacheline: 16 bytes */
      };
      
      After:
      
      pahole -C dsa_switch net/dsa/slave.o
      struct dsa_switch {
              struct device *            dev;                  /*     0     8 */
              struct dsa_switch_tree *   dst;                  /*     8     8 */
              unsigned int               index;                /*    16     4 */
              u32                        setup:1;              /*    20: 0  4 */
              u32                        vlan_filtering_is_global:1; /*    20: 1  4 */
              u32                        needs_standalone_vlan_filtering:1; /*    20: 2  4 */
              u32                        configure_vlan_while_not_filtering:1; /*    20: 3  4 */
              u32                        untag_bridge_pvid:1;  /*    20: 4  4 */
              u32                        assisted_learning_on_cpu_port:1; /*    20: 5  4 */
              u32                        vlan_filtering:1;     /*    20: 6  4 */
              u32                        pcs_poll:1;           /*    20: 7  4 */
              u32                        mtu_enforcement_ingress:1; /*    20: 8  4 */
      
              /* XXX 23 bits hole, try to pack */
      
              struct notifier_block      nb;                   /*    24    24 */
      
              /* XXX last struct has 4 bytes of padding */
      
              void *                     priv;                 /*    48     8 */
              void *                     tagger_data;          /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_chip_data *     cd;                   /*    64     8 */
              const struct dsa_switch_ops  * ops;              /*    72     8 */
              u32                        phys_mii_mask;        /*    80     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct mii_bus *           slave_mii_bus;        /*    88     8 */
              unsigned int               ageing_time_min;      /*    96     4 */
              unsigned int               ageing_time_max;      /*   100     4 */
              struct dsa_8021q_context * tag_8021q_ctx;        /*   104     8 */
              struct devlink *           devlink;              /*   112     8 */
              unsigned int               num_tx_queues;        /*   120     4 */
              unsigned int               num_lag_ids;          /*   124     4 */
              /* --- cacheline 2 boundary (128 bytes) --- */
              unsigned int               max_num_bridges;      /*   128     4 */
              unsigned int               num_ports;            /*   132     4 */
      
              /* size: 136, cachelines: 3, members: 27 */
              /* sum members: 128, holes: 1, sum holes: 4 */
              /* sum bitfield members: 9 bits, bit holes: 1, sum bit holes: 23 bits */
              /* paddings: 1, sum paddings: 4 */
              /* last cacheline: 8 bytes */
      };
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      258030ac
    • V
      net: dsa: merge all bools of struct dsa_switch into a single u32 · 7787ff77
      Vladimir Oltean 提交于
      struct dsa_switch has 9 boolean properties, many of which are in fact
      set by drivers for custom behavior (vlan_filtering_is_global,
      needs_standalone_vlan_filtering, etc etc). The binary layout of the
      structure could be improved. For example, the "bool setup" at the
      beginning introduces a gratuitous 7 byte hole in the first cache line.
      
      The change merges all boolean properties into bitfields of an u32, and
      places that u32 in the first cache line of the structure, since many
      bools are accessed from the data path (untag_bridge_pvid, vlan_filtering,
      vlan_filtering_is_global).
      
      We place this u32 after the existing ds->index, which is also 4 bytes in
      size. As a positive side effect, ds->tagger_data now fits into the first
      cache line too, because 4 bytes are saved.
      
      Before:
      
      pahole -C dsa_switch net/dsa/slave.o
      struct dsa_switch {
              bool                       setup;                /*     0     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              struct device *            dev;                  /*     8     8 */
              struct dsa_switch_tree *   dst;                  /*    16     8 */
              unsigned int               index;                /*    24     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct notifier_block      nb;                   /*    32    24 */
      
              /* XXX last struct has 4 bytes of padding */
      
              void *                     priv;                 /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              void *                     tagger_data;          /*    64     8 */
              struct dsa_chip_data *     cd;                   /*    72     8 */
              const struct dsa_switch_ops  * ops;              /*    80     8 */
              u32                        phys_mii_mask;        /*    88     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct mii_bus *           slave_mii_bus;        /*    96     8 */
              unsigned int               ageing_time_min;      /*   104     4 */
              unsigned int               ageing_time_max;      /*   108     4 */
              struct dsa_8021q_context * tag_8021q_ctx;        /*   112     8 */
              struct devlink *           devlink;              /*   120     8 */
              /* --- cacheline 2 boundary (128 bytes) --- */
              unsigned int               num_tx_queues;        /*   128     4 */
              bool                       vlan_filtering_is_global; /*   132     1 */
              bool                       needs_standalone_vlan_filtering; /*   133     1 */
              bool                       configure_vlan_while_not_filtering; /*   134     1 */
              bool                       untag_bridge_pvid;    /*   135     1 */
              bool                       assisted_learning_on_cpu_port; /*   136     1 */
              bool                       vlan_filtering;       /*   137     1 */
              bool                       pcs_poll;             /*   138     1 */
              bool                       mtu_enforcement_ingress; /*   139     1 */
              unsigned int               num_lag_ids;          /*   140     4 */
              unsigned int               max_num_bridges;      /*   144     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              size_t                     num_ports;            /*   152     8 */
      
              /* size: 160, cachelines: 3, members: 27 */
              /* sum members: 141, holes: 4, sum holes: 19 */
              /* paddings: 1, sum paddings: 4 */
              /* last cacheline: 32 bytes */
      };
      
      After:
      
      pahole -C dsa_switch net/dsa/slave.o
      struct dsa_switch {
              struct device *            dev;                  /*     0     8 */
              struct dsa_switch_tree *   dst;                  /*     8     8 */
              unsigned int               index;                /*    16     4 */
              u32                        setup:1;              /*    20: 0  4 */
              u32                        vlan_filtering_is_global:1; /*    20: 1  4 */
              u32                        needs_standalone_vlan_filtering:1; /*    20: 2  4 */
              u32                        configure_vlan_while_not_filtering:1; /*    20: 3  4 */
              u32                        untag_bridge_pvid:1;  /*    20: 4  4 */
              u32                        assisted_learning_on_cpu_port:1; /*    20: 5  4 */
              u32                        vlan_filtering:1;     /*    20: 6  4 */
              u32                        pcs_poll:1;           /*    20: 7  4 */
              u32                        mtu_enforcement_ingress:1; /*    20: 8  4 */
      
              /* XXX 23 bits hole, try to pack */
      
              struct notifier_block      nb;                   /*    24    24 */
      
              /* XXX last struct has 4 bytes of padding */
      
              void *                     priv;                 /*    48     8 */
              void *                     tagger_data;          /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_chip_data *     cd;                   /*    64     8 */
              const struct dsa_switch_ops  * ops;              /*    72     8 */
              u32                        phys_mii_mask;        /*    80     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct mii_bus *           slave_mii_bus;        /*    88     8 */
              unsigned int               ageing_time_min;      /*    96     4 */
              unsigned int               ageing_time_max;      /*   100     4 */
              struct dsa_8021q_context * tag_8021q_ctx;        /*   104     8 */
              struct devlink *           devlink;              /*   112     8 */
              unsigned int               num_tx_queues;        /*   120     4 */
              unsigned int               num_lag_ids;          /*   124     4 */
              /* --- cacheline 2 boundary (128 bytes) --- */
              unsigned int               max_num_bridges;      /*   128     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              size_t                     num_ports;            /*   136     8 */
      
              /* size: 144, cachelines: 3, members: 27 */
              /* sum members: 132, holes: 2, sum holes: 8 */
              /* sum bitfield members: 9 bits, bit holes: 1, sum bit holes: 23 bits */
              /* paddings: 1, sum paddings: 4 */
              /* last cacheline: 16 bytes */
      };
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      7787ff77
    • V
      net: dsa: move dsa_port :: type near dsa_port :: index · 06251258
      Vladimir Oltean 提交于
      Both dsa_port :: type and dsa_port :: index introduce a 4 octet hole
      after them, so we can group them together and the holes would be
      eliminated, turning 16 octets of storage into just 8. This makes the
      cpu_dp pointer fit in the first cache line, which is good, because
      dsa_slave_to_master(), called by dsa_enqueue_skb(), uses it.
      
      Before:
      
      pahole -C dsa_port net/dsa/slave.o
      struct dsa_port {
              union {
                      struct net_device * master;              /*     0     8 */
                      struct net_device * slave;               /*     0     8 */
              };                                               /*     0     8 */
              const struct dsa_device_ops  * tag_ops;          /*     8     8 */
              struct dsa_switch_tree *   dst;                  /*    16     8 */
              struct sk_buff *           (*rcv)(struct sk_buff *, struct net_device *); /*    24     8 */
              enum {
                      DSA_PORT_TYPE_UNUSED = 0,
                      DSA_PORT_TYPE_CPU    = 1,
                      DSA_PORT_TYPE_DSA    = 2,
                      DSA_PORT_TYPE_USER   = 3,
              } type;                                          /*    32     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_switch *        ds;                   /*    40     8 */
              unsigned int               index;                /*    48     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              const char  *              name;                 /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_port *          cpu_dp;               /*    64     8 */
              u8                         mac[6];               /*    72     6 */
              u8                         stp_state;            /*    78     1 */
              u8                         vlan_filtering:1;     /*    79: 0  1 */
              u8                         learning:1;           /*    79: 1  1 */
              u8                         lag_tx_enabled:1;     /*    79: 2  1 */
              u8                         devlink_port_setup:1; /*    79: 3  1 */
              u8                         setup:1;              /*    79: 4  1 */
      
              /* XXX 3 bits hole, try to pack */
      
              struct device_node *       dn;                   /*    80     8 */
              unsigned int               ageing_time;          /*    88     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_bridge *        bridge;               /*    96     8 */
              struct devlink_port        devlink_port;         /*   104   288 */
              /* --- cacheline 6 boundary (384 bytes) was 8 bytes ago --- */
              struct phylink *           pl;                   /*   392     8 */
              struct phylink_config      pl_config;            /*   400    40 */
              struct net_device *        lag_dev;              /*   440     8 */
              /* --- cacheline 7 boundary (448 bytes) --- */
              struct net_device *        hsr_dev;              /*   448     8 */
              struct list_head           list;                 /*   456    16 */
              const struct ethtool_ops  * orig_ethtool_ops;    /*   472     8 */
              const struct dsa_netdevice_ops  * netdev_ops;    /*   480     8 */
              struct mutex               addr_lists_lock;      /*   488    32 */
              /* --- cacheline 8 boundary (512 bytes) was 8 bytes ago --- */
              struct list_head           fdbs;                 /*   520    16 */
              struct list_head           mdbs;                 /*   536    16 */
      
              /* size: 552, cachelines: 9, members: 30 */
              /* sum members: 539, holes: 3, sum holes: 12 */
              /* sum bitfield members: 5 bits, bit holes: 1, sum bit holes: 3 bits */
              /* last cacheline: 40 bytes */
      };
      
      After:
      
      pahole -C dsa_port net/dsa/slave.o
      struct dsa_port {
              union {
                      struct net_device * master;              /*     0     8 */
                      struct net_device * slave;               /*     0     8 */
              };                                               /*     0     8 */
              const struct dsa_device_ops  * tag_ops;          /*     8     8 */
              struct dsa_switch_tree *   dst;                  /*    16     8 */
              struct sk_buff *           (*rcv)(struct sk_buff *, struct net_device *); /*    24     8 */
              struct dsa_switch *        ds;                   /*    32     8 */
              unsigned int               index;                /*    40     4 */
              enum {
                      DSA_PORT_TYPE_UNUSED = 0,
                      DSA_PORT_TYPE_CPU    = 1,
                      DSA_PORT_TYPE_DSA    = 2,
                      DSA_PORT_TYPE_USER   = 3,
              } type;                                          /*    44     4 */
              const char  *              name;                 /*    48     8 */
              struct dsa_port *          cpu_dp;               /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              u8                         mac[6];               /*    64     6 */
              u8                         stp_state;            /*    70     1 */
              u8                         vlan_filtering:1;     /*    71: 0  1 */
              u8                         learning:1;           /*    71: 1  1 */
              u8                         lag_tx_enabled:1;     /*    71: 2  1 */
              u8                         devlink_port_setup:1; /*    71: 3  1 */
              u8                         setup:1;              /*    71: 4  1 */
      
              /* XXX 3 bits hole, try to pack */
      
              struct device_node *       dn;                   /*    72     8 */
              unsigned int               ageing_time;          /*    80     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_bridge *        bridge;               /*    88     8 */
              struct devlink_port        devlink_port;         /*    96   288 */
              /* --- cacheline 6 boundary (384 bytes) --- */
              struct phylink *           pl;                   /*   384     8 */
              struct phylink_config      pl_config;            /*   392    40 */
              struct net_device *        lag_dev;              /*   432     8 */
              struct net_device *        hsr_dev;              /*   440     8 */
              /* --- cacheline 7 boundary (448 bytes) --- */
              struct list_head           list;                 /*   448    16 */
              const struct ethtool_ops  * orig_ethtool_ops;    /*   464     8 */
              const struct dsa_netdevice_ops  * netdev_ops;    /*   472     8 */
              struct mutex               addr_lists_lock;      /*   480    32 */
              /* --- cacheline 8 boundary (512 bytes) --- */
              struct list_head           fdbs;                 /*   512    16 */
              struct list_head           mdbs;                 /*   528    16 */
      
              /* size: 544, cachelines: 9, members: 30 */
              /* sum members: 539, holes: 1, sum holes: 4 */
              /* sum bitfield members: 5 bits, bit holes: 1, sum bit holes: 3 bits */
              /* last cacheline: 32 bytes */
      };
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      06251258
    • V
      net: dsa: merge all bools of struct dsa_port into a single u8 · bde82f38
      Vladimir Oltean 提交于
      struct dsa_port has 5 bool members which create quite a number of 7 byte
      holes in the structure layout. By merging them all into bitfields of an
      u8, and placing that u8 in the 1-byte hole after dp->mac and dp->stp_state,
      we can reduce the structure size from 576 bytes to 552 bytes on arm64.
      
      Before:
      
      pahole -C dsa_port net/dsa/slave.o
      struct dsa_port {
              union {
                      struct net_device * master;              /*     0     8 */
                      struct net_device * slave;               /*     0     8 */
              };                                               /*     0     8 */
              const struct dsa_device_ops  * tag_ops;          /*     8     8 */
              struct dsa_switch_tree *   dst;                  /*    16     8 */
              struct sk_buff *           (*rcv)(struct sk_buff *, struct net_device *); /*    24     8 */
              enum {
                      DSA_PORT_TYPE_UNUSED = 0,
                      DSA_PORT_TYPE_CPU    = 1,
                      DSA_PORT_TYPE_DSA    = 2,
                      DSA_PORT_TYPE_USER   = 3,
              } type;                                          /*    32     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_switch *        ds;                   /*    40     8 */
              unsigned int               index;                /*    48     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              const char  *              name;                 /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_port *          cpu_dp;               /*    64     8 */
              u8                         mac[6];               /*    72     6 */
              u8                         stp_state;            /*    78     1 */
      
              /* XXX 1 byte hole, try to pack */
      
              struct device_node *       dn;                   /*    80     8 */
              unsigned int               ageing_time;          /*    88     4 */
              bool                       vlan_filtering;       /*    92     1 */
              bool                       learning;             /*    93     1 */
      
              /* XXX 2 bytes hole, try to pack */
      
              struct dsa_bridge *        bridge;               /*    96     8 */
              struct devlink_port        devlink_port;         /*   104   288 */
              /* --- cacheline 6 boundary (384 bytes) was 8 bytes ago --- */
              bool                       devlink_port_setup;   /*   392     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              struct phylink *           pl;                   /*   400     8 */
              struct phylink_config      pl_config;            /*   408    40 */
              /* --- cacheline 7 boundary (448 bytes) --- */
              struct net_device *        lag_dev;              /*   448     8 */
              bool                       lag_tx_enabled;       /*   456     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              struct net_device *        hsr_dev;              /*   464     8 */
              struct list_head           list;                 /*   472    16 */
              const struct ethtool_ops  * orig_ethtool_ops;    /*   488     8 */
              const struct dsa_netdevice_ops  * netdev_ops;    /*   496     8 */
              struct mutex               addr_lists_lock;      /*   504    32 */
              /* --- cacheline 8 boundary (512 bytes) was 24 bytes ago --- */
              struct list_head           fdbs;                 /*   536    16 */
              struct list_head           mdbs;                 /*   552    16 */
              bool                       setup;                /*   568     1 */
      
              /* size: 576, cachelines: 9, members: 30 */
              /* sum members: 544, holes: 6, sum holes: 25 */
              /* padding: 7 */
      };
      
      After:
      
      pahole -C dsa_port net/dsa/slave.o
      struct dsa_port {
              union {
                      struct net_device * master;              /*     0     8 */
                      struct net_device * slave;               /*     0     8 */
              };                                               /*     0     8 */
              const struct dsa_device_ops  * tag_ops;          /*     8     8 */
              struct dsa_switch_tree *   dst;                  /*    16     8 */
              struct sk_buff *           (*rcv)(struct sk_buff *, struct net_device *); /*    24     8 */
              enum {
                      DSA_PORT_TYPE_UNUSED = 0,
                      DSA_PORT_TYPE_CPU    = 1,
                      DSA_PORT_TYPE_DSA    = 2,
                      DSA_PORT_TYPE_USER   = 3,
              } type;                                          /*    32     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_switch *        ds;                   /*    40     8 */
              unsigned int               index;                /*    48     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              const char  *              name;                 /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_port *          cpu_dp;               /*    64     8 */
              u8                         mac[6];               /*    72     6 */
              u8                         stp_state;            /*    78     1 */
              u8                         vlan_filtering:1;     /*    79: 0  1 */
              u8                         learning:1;           /*    79: 1  1 */
              u8                         lag_tx_enabled:1;     /*    79: 2  1 */
              u8                         devlink_port_setup:1; /*    79: 3  1 */
              u8                         setup:1;              /*    79: 4  1 */
      
              /* XXX 3 bits hole, try to pack */
      
              struct device_node *       dn;                   /*    80     8 */
              unsigned int               ageing_time;          /*    88     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_bridge *        bridge;               /*    96     8 */
              struct devlink_port        devlink_port;         /*   104   288 */
              /* --- cacheline 6 boundary (384 bytes) was 8 bytes ago --- */
              struct phylink *           pl;                   /*   392     8 */
              struct phylink_config      pl_config;            /*   400    40 */
              struct net_device *        lag_dev;              /*   440     8 */
              /* --- cacheline 7 boundary (448 bytes) --- */
              struct net_device *        hsr_dev;              /*   448     8 */
              struct list_head           list;                 /*   456    16 */
              const struct ethtool_ops  * orig_ethtool_ops;    /*   472     8 */
              const struct dsa_netdevice_ops  * netdev_ops;    /*   480     8 */
              struct mutex               addr_lists_lock;      /*   488    32 */
              /* --- cacheline 8 boundary (512 bytes) was 8 bytes ago --- */
              struct list_head           fdbs;                 /*   520    16 */
              struct list_head           mdbs;                 /*   536    16 */
      
              /* size: 552, cachelines: 9, members: 30 */
              /* sum members: 539, holes: 3, sum holes: 12 */
              /* sum bitfield members: 5 bits, bit holes: 1, sum bit holes: 3 bits */
              /* last cacheline: 40 bytes */
      };
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      bde82f38
    • V
      net: dsa: move dsa_port :: stp_state near dsa_port :: mac · b08db33d
      Vladimir Oltean 提交于
      The MAC address of a port is 6 octets in size, and this creates a 2
      octet hole after it. There are some other u8 members of struct dsa_port
      that we can put in that hole. One such member is the stp_state.
      
      Before:
      
      pahole -C dsa_port net/dsa/slave.o
      struct dsa_port {
              union {
                      struct net_device * master;              /*     0     8 */
                      struct net_device * slave;               /*     0     8 */
              };                                               /*     0     8 */
              const struct dsa_device_ops  * tag_ops;          /*     8     8 */
              struct dsa_switch_tree *   dst;                  /*    16     8 */
              struct sk_buff *           (*rcv)(struct sk_buff *, struct net_device *); /*    24     8 */
              enum {
                      DSA_PORT_TYPE_UNUSED = 0,
                      DSA_PORT_TYPE_CPU    = 1,
                      DSA_PORT_TYPE_DSA    = 2,
                      DSA_PORT_TYPE_USER   = 3,
              } type;                                          /*    32     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_switch *        ds;                   /*    40     8 */
              unsigned int               index;                /*    48     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              const char  *              name;                 /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_port *          cpu_dp;               /*    64     8 */
              u8                         mac[6];               /*    72     6 */
      
              /* XXX 2 bytes hole, try to pack */
      
              struct device_node *       dn;                   /*    80     8 */
              unsigned int               ageing_time;          /*    88     4 */
              bool                       vlan_filtering;       /*    92     1 */
              bool                       learning;             /*    93     1 */
              u8                         stp_state;            /*    94     1 */
      
              /* XXX 1 byte hole, try to pack */
      
              struct dsa_bridge *        bridge;               /*    96     8 */
              struct devlink_port        devlink_port;         /*   104   288 */
              /* --- cacheline 6 boundary (384 bytes) was 8 bytes ago --- */
              bool                       devlink_port_setup;   /*   392     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              struct phylink *           pl;                   /*   400     8 */
              struct phylink_config      pl_config;            /*   408    40 */
              /* --- cacheline 7 boundary (448 bytes) --- */
              struct net_device *        lag_dev;              /*   448     8 */
              bool                       lag_tx_enabled;       /*   456     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              struct net_device *        hsr_dev;              /*   464     8 */
              struct list_head           list;                 /*   472    16 */
              const struct ethtool_ops  * orig_ethtool_ops;    /*   488     8 */
              const struct dsa_netdevice_ops  * netdev_ops;    /*   496     8 */
              struct mutex               addr_lists_lock;      /*   504    32 */
              /* --- cacheline 8 boundary (512 bytes) was 24 bytes ago --- */
              struct list_head           fdbs;                 /*   536    16 */
              struct list_head           mdbs;                 /*   552    16 */
              bool                       setup;                /*   568     1 */
      
              /* size: 576, cachelines: 9, members: 30 */
              /* sum members: 544, holes: 6, sum holes: 25 */
              /* padding: 7 */
      };
      
      After:
      
      pahole -C dsa_port net/dsa/slave.o
      struct dsa_port {
              union {
                      struct net_device * master;              /*     0     8 */
                      struct net_device * slave;               /*     0     8 */
              };                                               /*     0     8 */
              const struct dsa_device_ops  * tag_ops;          /*     8     8 */
              struct dsa_switch_tree *   dst;                  /*    16     8 */
              struct sk_buff *           (*rcv)(struct sk_buff *, struct net_device *); /*    24     8 */
              enum {
                      DSA_PORT_TYPE_UNUSED = 0,
                      DSA_PORT_TYPE_CPU    = 1,
                      DSA_PORT_TYPE_DSA    = 2,
                      DSA_PORT_TYPE_USER   = 3,
              } type;                                          /*    32     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              struct dsa_switch *        ds;                   /*    40     8 */
              unsigned int               index;                /*    48     4 */
      
              /* XXX 4 bytes hole, try to pack */
      
              const char  *              name;                 /*    56     8 */
              /* --- cacheline 1 boundary (64 bytes) --- */
              struct dsa_port *          cpu_dp;               /*    64     8 */
              u8                         mac[6];               /*    72     6 */
              u8                         stp_state;            /*    78     1 */
      
              /* XXX 1 byte hole, try to pack */
      
              struct device_node *       dn;                   /*    80     8 */
              unsigned int               ageing_time;          /*    88     4 */
              bool                       vlan_filtering;       /*    92     1 */
              bool                       learning;             /*    93     1 */
      
              /* XXX 2 bytes hole, try to pack */
      
              struct dsa_bridge *        bridge;               /*    96     8 */
              struct devlink_port        devlink_port;         /*   104   288 */
              /* --- cacheline 6 boundary (384 bytes) was 8 bytes ago --- */
              bool                       devlink_port_setup;   /*   392     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              struct phylink *           pl;                   /*   400     8 */
              struct phylink_config      pl_config;            /*   408    40 */
              /* --- cacheline 7 boundary (448 bytes) --- */
              struct net_device *        lag_dev;              /*   448     8 */
              bool                       lag_tx_enabled;       /*   456     1 */
      
              /* XXX 7 bytes hole, try to pack */
      
              struct net_device *        hsr_dev;              /*   464     8 */
              struct list_head           list;                 /*   472    16 */
              const struct ethtool_ops  * orig_ethtool_ops;    /*   488     8 */
              const struct dsa_netdevice_ops  * netdev_ops;    /*   496     8 */
              struct mutex               addr_lists_lock;      /*   504    32 */
              /* --- cacheline 8 boundary (512 bytes) was 24 bytes ago --- */
              struct list_head           fdbs;                 /*   536    16 */
              struct list_head           mdbs;                 /*   552    16 */
              bool                       setup;                /*   568     1 */
      
              /* size: 576, cachelines: 9, members: 30 */
              /* sum members: 544, holes: 6, sum holes: 25 */
              /* padding: 7 */
      };
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b08db33d
    • R
      net: mdio: add helpers to extract clause 45 regad and devad fields · c6af53f0
      Russell King (Oracle) 提交于
      Add a couple of helpers and definitions to extract the clause 45 regad
      and devad fields from the regnum passed into MDIO drivers.
      Tested-by: NDaniel Golle <daniel@makrotopia.org>
      Reviewed-by: NAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: NRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
      Signed-off-by: NDaniel Golle <daniel@makrotopia.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c6af53f0
  2. 04 1月, 2022 5 次提交
  3. 03 1月, 2022 1 次提交
  4. 02 1月, 2022 1 次提交
  5. 31 12月, 2021 5 次提交
  6. 30 12月, 2021 5 次提交
  7. 27 12月, 2021 2 次提交
  8. 26 12月, 2021 3 次提交
    • T
      mm/page_alloc: fix __alloc_size attribute for alloc_pages_exact_nid · 595ec197
      Thibaut Sautereau 提交于
      The second parameter of alloc_pages_exact_nid is the one indicating the
      size of memory pointed by the returned pointer.
      
      Link: https://lkml.kernel.org/r/YbjEgwhn4bGblp//@coeus
      Fixes: abd58f38 ("mm/page_alloc: add __alloc_size attributes for better bounds checking")
      Signed-off-by: NThibaut Sautereau <thibaut.sautereau@ssi.gouv.fr>
      Acked-by: NKees Cook <keescook@chromium.org>
      Cc: Daniel Micay <danielmicay@gmail.com>
      Cc: Levente Polyak <levente@leventepolyak.net>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      595ec197
    • H
      mm: delete unsafe BUG from page_cache_add_speculative() · 94ab10dd
      Hugh Dickins 提交于
      It is not easily reproducible, but on 5.16-rc I have several times hit
      the VM_BUG_ON_PAGE(PageTail(page), page) in
      page_cache_add_speculative(): usually from filemap_get_read_batch() for
      an ext4 read, yesterday from next_uptodate_page() from
      filemap_map_pages() for a shmem fault.
      
      That BUG used to be placed where page_ref_add_unless() had succeeded,
      but now it is placed before folio_ref_add_unless() is attempted: that is
      not safe, since it is only the acquired reference which makes the page
      safe from racing THP collapse or split.
      
      We could keep the BUG, checking PageTail only when
      folio_ref_try_add_rcu() has succeeded; but I don't think it adds much
      value - just delete it.
      
      Link: https://lkml.kernel.org/r/8b98fc6f-3439-8614-c3f3-945c659a1aba@google.com
      Fixes: 020853b6 ("mm: Add folio_try_get_rcu()")
      Signed-off-by: NHugh Dickins <hughd@google.com>
      Acked-by: NKirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Reviewed-by: NMatthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: William Kucharski <william.kucharski@oracle.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Mike Rapoport <rppt@linux.ibm.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      94ab10dd
    • X
      sctp: use call_rcu to free endpoint · 5ec7d18d
      Xin Long 提交于
      This patch is to delay the endpoint free by calling call_rcu() to fix
      another use-after-free issue in sctp_sock_dump():
      
        BUG: KASAN: use-after-free in __lock_acquire+0x36d9/0x4c20
        Call Trace:
          __lock_acquire+0x36d9/0x4c20 kernel/locking/lockdep.c:3218
          lock_acquire+0x1ed/0x520 kernel/locking/lockdep.c:3844
          __raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
          _raw_spin_lock_bh+0x31/0x40 kernel/locking/spinlock.c:168
          spin_lock_bh include/linux/spinlock.h:334 [inline]
          __lock_sock+0x203/0x350 net/core/sock.c:2253
          lock_sock_nested+0xfe/0x120 net/core/sock.c:2774
          lock_sock include/net/sock.h:1492 [inline]
          sctp_sock_dump+0x122/0xb20 net/sctp/diag.c:324
          sctp_for_each_transport+0x2b5/0x370 net/sctp/socket.c:5091
          sctp_diag_dump+0x3ac/0x660 net/sctp/diag.c:527
          __inet_diag_dump+0xa8/0x140 net/ipv4/inet_diag.c:1049
          inet_diag_dump+0x9b/0x110 net/ipv4/inet_diag.c:1065
          netlink_dump+0x606/0x1080 net/netlink/af_netlink.c:2244
          __netlink_dump_start+0x59a/0x7c0 net/netlink/af_netlink.c:2352
          netlink_dump_start include/linux/netlink.h:216 [inline]
          inet_diag_handler_cmd+0x2ce/0x3f0 net/ipv4/inet_diag.c:1170
          __sock_diag_cmd net/core/sock_diag.c:232 [inline]
          sock_diag_rcv_msg+0x31d/0x410 net/core/sock_diag.c:263
          netlink_rcv_skb+0x172/0x440 net/netlink/af_netlink.c:2477
          sock_diag_rcv+0x2a/0x40 net/core/sock_diag.c:274
      
      This issue occurs when asoc is peeled off and the old sk is freed after
      getting it by asoc->base.sk and before calling lock_sock(sk).
      
      To prevent the sk free, as a holder of the sk, ep should be alive when
      calling lock_sock(). This patch uses call_rcu() and moves sock_put and
      ep free into sctp_endpoint_destroy_rcu(), so that it's safe to try to
      hold the ep under rcu_read_lock in sctp_transport_traverse_process().
      
      If sctp_endpoint_hold() returns true, it means this ep is still alive
      and we have held it and can continue to dump it; If it returns false,
      it means this ep is dead and can be freed after rcu_read_unlock, and
      we should skip it.
      
      In sctp_sock_dump(), after locking the sk, if this ep is different from
      tsp->asoc->ep, it means during this dumping, this asoc was peeled off
      before calling lock_sock(), and the sk should be skipped; If this ep is
      the same with tsp->asoc->ep, it means no peeloff happens on this asoc,
      and due to lock_sock, no peeloff will happen either until release_sock.
      
      Note that delaying endpoint free won't delay the port release, as the
      port release happens in sctp_endpoint_destroy() before calling call_rcu().
      Also, freeing endpoint by call_rcu() makes it safe to access the sk by
      asoc->base.sk in sctp_assocs_seq_show() and sctp_rcv().
      
      Thanks Jones to bring this issue up.
      
      v1->v2:
        - improve the changelog.
        - add kfree(ep) into sctp_endpoint_destroy_rcu(), as Jakub noticed.
      
      Reported-by: syzbot+9276d76e83e3bcde6c99@syzkaller.appspotmail.com
      Reported-by: NLee Jones <lee.jones@linaro.org>
      Fixes: d25adbeb ("sctp: fix an use-after-free issue in sctp_sock_dump")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5ec7d18d
  9. 23 12月, 2021 10 次提交
  10. 22 12月, 2021 1 次提交