@@ -368,15 +368,6 @@ struct virtio_net_ctrl_rss {
368
368
struct control_buf {
369
369
struct virtio_net_ctrl_hdr hdr ;
370
370
virtio_net_ctrl_ack status ;
371
- struct virtio_net_ctrl_mq mq ;
372
- u8 promisc ;
373
- u8 allmulti ;
374
- __virtio16 vid ;
375
- __virtio64 offloads ;
376
- struct virtio_net_ctrl_coal_tx coal_tx ;
377
- struct virtio_net_ctrl_coal_rx coal_rx ;
378
- struct virtio_net_ctrl_coal_vq coal_vq ;
379
- struct virtio_net_stats_capabilities stats_cap ;
380
371
};
381
372
382
373
struct virtnet_info {
@@ -2828,14 +2819,19 @@ static void virtnet_ack_link_announce(struct virtnet_info *vi)
2828
2819
2829
2820
static int _virtnet_set_queues (struct virtnet_info * vi , u16 queue_pairs )
2830
2821
{
2822
+ struct virtio_net_ctrl_mq * mq __free (kfree ) = NULL ;
2831
2823
struct scatterlist sg ;
2832
2824
struct net_device * dev = vi -> dev ;
2833
2825
2834
2826
if (!vi -> has_cvq || !virtio_has_feature (vi -> vdev , VIRTIO_NET_F_MQ ))
2835
2827
return 0 ;
2836
2828
2837
- vi -> ctrl -> mq .virtqueue_pairs = cpu_to_virtio16 (vi -> vdev , queue_pairs );
2838
- sg_init_one (& sg , & vi -> ctrl -> mq , sizeof (vi -> ctrl -> mq ));
2829
+ mq = kzalloc (sizeof (* mq ), GFP_KERNEL );
2830
+ if (!mq )
2831
+ return - ENOMEM ;
2832
+
2833
+ mq -> virtqueue_pairs = cpu_to_virtio16 (vi -> vdev , queue_pairs );
2834
+ sg_init_one (& sg , mq , sizeof (* mq ));
2839
2835
2840
2836
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_MQ ,
2841
2837
VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET , & sg )) {
@@ -2864,6 +2860,7 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
2864
2860
2865
2861
static int virtnet_close (struct net_device * dev )
2866
2862
{
2863
+ u8 * promisc_allmulti __free (kfree ) = NULL ;
2867
2864
struct virtnet_info * vi = netdev_priv (dev );
2868
2865
int i ;
2869
2866
@@ -2888,6 +2885,7 @@ static void virtnet_rx_mode_work(struct work_struct *work)
2888
2885
struct scatterlist sg [2 ];
2889
2886
struct virtio_net_ctrl_mac * mac_data ;
2890
2887
struct netdev_hw_addr * ha ;
2888
+ u8 * promisc_allmulti ;
2891
2889
int uc_count ;
2892
2890
int mc_count ;
2893
2891
void * buf ;
@@ -2899,22 +2897,27 @@ static void virtnet_rx_mode_work(struct work_struct *work)
2899
2897
2900
2898
rtnl_lock ();
2901
2899
2902
- vi -> ctrl -> promisc = ((dev -> flags & IFF_PROMISC ) != 0 );
2903
- vi -> ctrl -> allmulti = ((dev -> flags & IFF_ALLMULTI ) != 0 );
2900
+ promisc_allmulti = kzalloc (sizeof (* promisc_allmulti ), GFP_ATOMIC );
2901
+ if (!promisc_allmulti ) {
2902
+ dev_warn (& dev -> dev , "Failed to set RX mode, no memory.\n" );
2903
+ return ;
2904
+ }
2904
2905
2905
- sg_init_one (sg , & vi -> ctrl -> promisc , sizeof (vi -> ctrl -> promisc ));
2906
+ * promisc_allmulti = !!(dev -> flags & IFF_PROMISC );
2907
+ sg_init_one (sg , promisc_allmulti , sizeof (* promisc_allmulti ));
2906
2908
2907
2909
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_RX ,
2908
2910
VIRTIO_NET_CTRL_RX_PROMISC , sg ))
2909
2911
dev_warn (& dev -> dev , "Failed to %sable promisc mode.\n" ,
2910
- vi -> ctrl -> promisc ? "en" : "dis" );
2912
+ * promisc_allmulti ? "en" : "dis" );
2911
2913
2912
- sg_init_one (sg , & vi -> ctrl -> allmulti , sizeof (vi -> ctrl -> allmulti ));
2914
+ * promisc_allmulti = !!(dev -> flags & IFF_ALLMULTI );
2915
+ sg_init_one (sg , promisc_allmulti , sizeof (* promisc_allmulti ));
2913
2916
2914
2917
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_RX ,
2915
2918
VIRTIO_NET_CTRL_RX_ALLMULTI , sg ))
2916
2919
dev_warn (& dev -> dev , "Failed to %sable allmulti mode.\n" ,
2917
- vi -> ctrl -> allmulti ? "en" : "dis" );
2920
+ * promisc_allmulti ? "en" : "dis" );
2918
2921
2919
2922
netif_addr_lock_bh (dev );
2920
2923
@@ -2975,10 +2978,15 @@ static int virtnet_vlan_rx_add_vid(struct net_device *dev,
2975
2978
__be16 proto , u16 vid )
2976
2979
{
2977
2980
struct virtnet_info * vi = netdev_priv (dev );
2981
+ __virtio16 * _vid __free (kfree ) = NULL ;
2978
2982
struct scatterlist sg ;
2979
2983
2980
- vi -> ctrl -> vid = cpu_to_virtio16 (vi -> vdev , vid );
2981
- sg_init_one (& sg , & vi -> ctrl -> vid , sizeof (vi -> ctrl -> vid ));
2984
+ _vid = kzalloc (sizeof (* _vid ), GFP_KERNEL );
2985
+ if (!_vid )
2986
+ return - ENOMEM ;
2987
+
2988
+ * _vid = cpu_to_virtio16 (vi -> vdev , vid );
2989
+ sg_init_one (& sg , _vid , sizeof (* _vid ));
2982
2990
2983
2991
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_VLAN ,
2984
2992
VIRTIO_NET_CTRL_VLAN_ADD , & sg ))
@@ -2990,10 +2998,15 @@ static int virtnet_vlan_rx_kill_vid(struct net_device *dev,
2990
2998
__be16 proto , u16 vid )
2991
2999
{
2992
3000
struct virtnet_info * vi = netdev_priv (dev );
3001
+ __virtio16 * _vid __free (kfree ) = NULL ;
2993
3002
struct scatterlist sg ;
2994
3003
2995
- vi -> ctrl -> vid = cpu_to_virtio16 (vi -> vdev , vid );
2996
- sg_init_one (& sg , & vi -> ctrl -> vid , sizeof (vi -> ctrl -> vid ));
3004
+ _vid = kzalloc (sizeof (* _vid ), GFP_KERNEL );
3005
+ if (!_vid )
3006
+ return - ENOMEM ;
3007
+
3008
+ * _vid = cpu_to_virtio16 (vi -> vdev , vid );
3009
+ sg_init_one (& sg , _vid , sizeof (* _vid ));
2997
3010
2998
3011
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_VLAN ,
2999
3012
VIRTIO_NET_CTRL_VLAN_DEL , & sg ))
@@ -3106,12 +3119,17 @@ static void virtnet_cpu_notif_remove(struct virtnet_info *vi)
3106
3119
static int virtnet_send_ctrl_coal_vq_cmd (struct virtnet_info * vi ,
3107
3120
u16 vqn , u32 max_usecs , u32 max_packets )
3108
3121
{
3122
+ struct virtio_net_ctrl_coal_vq * coal_vq __free (kfree ) = NULL ;
3109
3123
struct scatterlist sgs ;
3110
3124
3111
- vi -> ctrl -> coal_vq .vqn = cpu_to_le16 (vqn );
3112
- vi -> ctrl -> coal_vq .coal .max_usecs = cpu_to_le32 (max_usecs );
3113
- vi -> ctrl -> coal_vq .coal .max_packets = cpu_to_le32 (max_packets );
3114
- sg_init_one (& sgs , & vi -> ctrl -> coal_vq , sizeof (vi -> ctrl -> coal_vq ));
3125
+ coal_vq = kzalloc (sizeof (* coal_vq ), GFP_KERNEL );
3126
+ if (!coal_vq )
3127
+ return - ENOMEM ;
3128
+
3129
+ coal_vq -> vqn = cpu_to_le16 (vqn );
3130
+ coal_vq -> coal .max_usecs = cpu_to_le32 (max_usecs );
3131
+ coal_vq -> coal .max_packets = cpu_to_le32 (max_packets );
3132
+ sg_init_one (& sgs , coal_vq , sizeof (* coal_vq ));
3115
3133
3116
3134
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_NOTF_COAL ,
3117
3135
VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET ,
@@ -3257,11 +3275,15 @@ static bool virtnet_commit_rss_command(struct virtnet_info *vi)
3257
3275
3258
3276
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_MQ ,
3259
3277
vi -> has_rss ? VIRTIO_NET_CTRL_MQ_RSS_CONFIG
3260
- : VIRTIO_NET_CTRL_MQ_HASH_CONFIG , sgs )) {
3261
- dev_warn (& dev -> dev , "VIRTIONET issue with committing RSS sgs\n" );
3262
- return false;
3263
- }
3278
+ : VIRTIO_NET_CTRL_MQ_HASH_CONFIG , sgs ))
3279
+ goto err ;
3280
+
3264
3281
return true;
3282
+
3283
+ err :
3284
+ dev_warn (& dev -> dev , "VIRTIONET issue with committing RSS sgs\n" );
3285
+ return false;
3286
+
3265
3287
}
3266
3288
3267
3289
static void virtnet_init_default_rss (struct virtnet_info * vi )
@@ -4193,12 +4215,17 @@ static int virtnet_get_link_ksettings(struct net_device *dev,
4193
4215
static int virtnet_send_tx_notf_coal_cmds (struct virtnet_info * vi ,
4194
4216
struct ethtool_coalesce * ec )
4195
4217
{
4218
+ struct virtio_net_ctrl_coal_tx * coal_tx __free (kfree ) = NULL ;
4196
4219
struct scatterlist sgs_tx ;
4197
4220
int i ;
4198
4221
4199
- vi -> ctrl -> coal_tx .tx_usecs = cpu_to_le32 (ec -> tx_coalesce_usecs );
4200
- vi -> ctrl -> coal_tx .tx_max_packets = cpu_to_le32 (ec -> tx_max_coalesced_frames );
4201
- sg_init_one (& sgs_tx , & vi -> ctrl -> coal_tx , sizeof (vi -> ctrl -> coal_tx ));
4222
+ coal_tx = kzalloc (sizeof (* coal_tx ), GFP_KERNEL );
4223
+ if (!coal_tx )
4224
+ return - ENOMEM ;
4225
+
4226
+ coal_tx -> tx_usecs = cpu_to_le32 (ec -> tx_coalesce_usecs );
4227
+ coal_tx -> tx_max_packets = cpu_to_le32 (ec -> tx_max_coalesced_frames );
4228
+ sg_init_one (& sgs_tx , coal_tx , sizeof (* coal_tx ));
4202
4229
4203
4230
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_NOTF_COAL ,
4204
4231
VIRTIO_NET_CTRL_NOTF_COAL_TX_SET ,
@@ -4218,6 +4245,7 @@ static int virtnet_send_tx_notf_coal_cmds(struct virtnet_info *vi,
4218
4245
static int virtnet_send_rx_notf_coal_cmds (struct virtnet_info * vi ,
4219
4246
struct ethtool_coalesce * ec )
4220
4247
{
4248
+ struct virtio_net_ctrl_coal_rx * coal_rx __free (kfree ) = NULL ;
4221
4249
bool rx_ctrl_dim_on = !!ec -> use_adaptive_rx_coalesce ;
4222
4250
struct scatterlist sgs_rx ;
4223
4251
int i ;
@@ -4236,6 +4264,10 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi,
4236
4264
return 0 ;
4237
4265
}
4238
4266
4267
+ coal_rx = kzalloc (sizeof (* coal_rx ), GFP_KERNEL );
4268
+ if (!coal_rx )
4269
+ return - ENOMEM ;
4270
+
4239
4271
if (!rx_ctrl_dim_on && vi -> rx_dim_enabled ) {
4240
4272
vi -> rx_dim_enabled = false;
4241
4273
for (i = 0 ; i < vi -> max_queue_pairs ; i ++ )
@@ -4246,9 +4278,9 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi,
4246
4278
* we need apply the global new params even if they
4247
4279
* are not updated.
4248
4280
*/
4249
- vi -> ctrl -> coal_rx . rx_usecs = cpu_to_le32 (ec -> rx_coalesce_usecs );
4250
- vi -> ctrl -> coal_rx . rx_max_packets = cpu_to_le32 (ec -> rx_max_coalesced_frames );
4251
- sg_init_one (& sgs_rx , & vi -> ctrl -> coal_rx , sizeof (vi -> ctrl -> coal_rx ));
4281
+ coal_rx -> rx_usecs = cpu_to_le32 (ec -> rx_coalesce_usecs );
4282
+ coal_rx -> rx_max_packets = cpu_to_le32 (ec -> rx_max_coalesced_frames );
4283
+ sg_init_one (& sgs_rx , coal_rx , sizeof (* coal_rx ));
4252
4284
4253
4285
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_NOTF_COAL ,
4254
4286
VIRTIO_NET_CTRL_NOTF_COAL_RX_SET ,
@@ -4823,10 +4855,16 @@ static int virtnet_restore_up(struct virtio_device *vdev)
4823
4855
4824
4856
static int virtnet_set_guest_offloads (struct virtnet_info * vi , u64 offloads )
4825
4857
{
4858
+ __virtio64 * _offloads __free (kfree ) = NULL ;
4826
4859
struct scatterlist sg ;
4827
- vi -> ctrl -> offloads = cpu_to_virtio64 (vi -> vdev , offloads );
4828
4860
4829
- sg_init_one (& sg , & vi -> ctrl -> offloads , sizeof (vi -> ctrl -> offloads ));
4861
+ _offloads = kzalloc (sizeof (* _offloads ), GFP_KERNEL );
4862
+ if (!_offloads )
4863
+ return - ENOMEM ;
4864
+
4865
+ * _offloads = cpu_to_virtio64 (vi -> vdev , offloads );
4866
+
4867
+ sg_init_one (& sg , _offloads , sizeof (* _offloads ));
4830
4868
4831
4869
if (!virtnet_send_command (vi , VIRTIO_NET_CTRL_GUEST_OFFLOADS ,
4832
4870
VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET , & sg )) {
@@ -5810,10 +5848,18 @@ static int virtnet_probe(struct virtio_device *vdev)
5810
5848
}
5811
5849
5812
5850
if (virtio_has_feature (vi -> vdev , VIRTIO_NET_F_DEVICE_STATS )) {
5851
+ struct virtio_net_stats_capabilities * stats_cap __free (kfree ) = NULL ;
5813
5852
struct scatterlist sg ;
5814
5853
__le64 v ;
5815
5854
5816
- sg_init_one (& sg , & vi -> ctrl -> stats_cap , sizeof (vi -> ctrl -> stats_cap ));
5855
+ stats_cap = kzalloc (sizeof (* stats_cap ), GFP_KERNEL );
5856
+ if (!stats_cap ) {
5857
+ rtnl_unlock ();
5858
+ err = - ENOMEM ;
5859
+ goto free_unregister_netdev ;
5860
+ }
5861
+
5862
+ sg_init_one (& sg , stats_cap , sizeof (* stats_cap ));
5817
5863
5818
5864
if (!virtnet_send_command_reply (vi , VIRTIO_NET_CTRL_STATS ,
5819
5865
VIRTIO_NET_CTRL_STATS_QUERY ,
@@ -5824,7 +5870,7 @@ static int virtnet_probe(struct virtio_device *vdev)
5824
5870
goto free_unregister_netdev ;
5825
5871
}
5826
5872
5827
- v = vi -> ctrl -> stats_cap . supported_stats_types [0 ];
5873
+ v = stats_cap -> supported_stats_types [0 ];
5828
5874
vi -> device_stats_cap = le64_to_cpu (v );
5829
5875
}
5830
5876
0 commit comments