Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net-sysctl: factor-out rpm mask manipulation helpers

Will simplify the following patch. No functional change
intended.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Paolo Abeni and committed by
Jakub Kicinski
370ca718 135746c6

+44 -30
+2
net/core/dev.h
··· 9 9 struct netdev_bpf; 10 10 struct netdev_phys_item_id; 11 11 struct netlink_ext_ack; 12 + struct cpumask; 12 13 13 14 /* Random bits of netdevice that don't need to be exposed */ 14 15 #define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */ ··· 135 134 WRITE_ONCE(dev->gro_ipv4_max_size, size); 136 135 } 137 136 137 + int rps_cpumask_housekeeping(struct cpumask *mask); 138 138 #endif
+42 -30
net/core/net-sysfs.c
··· 831 831 return len < PAGE_SIZE ? len : -EINVAL; 832 832 } 833 833 834 - static ssize_t store_rps_map(struct netdev_rx_queue *queue, 835 - const char *buf, size_t len) 834 + static int netdev_rx_queue_set_rps_mask(struct netdev_rx_queue *queue, 835 + cpumask_var_t mask) 836 836 { 837 - struct rps_map *old_map, *map; 838 - cpumask_var_t mask; 839 - int err, cpu, i; 840 837 static DEFINE_MUTEX(rps_map_mutex); 841 - 842 - if (!capable(CAP_NET_ADMIN)) 843 - return -EPERM; 844 - 845 - if (!alloc_cpumask_var(&mask, GFP_KERNEL)) 846 - return -ENOMEM; 847 - 848 - err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); 849 - if (err) { 850 - free_cpumask_var(mask); 851 - return err; 852 - } 853 - 854 - if (!cpumask_empty(mask)) { 855 - cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_DOMAIN)); 856 - cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_WQ)); 857 - if (cpumask_empty(mask)) { 858 - free_cpumask_var(mask); 859 - return -EINVAL; 860 - } 861 - } 838 + struct rps_map *old_map, *map; 839 + int cpu, i; 862 840 863 841 map = kzalloc(max_t(unsigned int, 864 842 RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES), 865 843 GFP_KERNEL); 866 - if (!map) { 867 - free_cpumask_var(mask); 844 + if (!map) 868 845 return -ENOMEM; 869 - } 870 846 871 847 i = 0; 872 848 for_each_cpu_and(cpu, mask, cpu_online_mask) ··· 869 893 870 894 if (old_map) 871 895 kfree_rcu(old_map, rcu); 896 + return 0; 897 + } 872 898 899 + int rps_cpumask_housekeeping(struct cpumask *mask) 900 + { 901 + if (!cpumask_empty(mask)) { 902 + cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_DOMAIN)); 903 + cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_WQ)); 904 + if (cpumask_empty(mask)) 905 + return -EINVAL; 906 + } 907 + return 0; 908 + } 909 + 910 + static ssize_t store_rps_map(struct netdev_rx_queue *queue, 911 + const char *buf, size_t len) 912 + { 913 + cpumask_var_t mask; 914 + int err; 915 + 916 + if (!capable(CAP_NET_ADMIN)) 917 + return -EPERM; 918 + 919 + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) 920 + return -ENOMEM; 921 + 922 + err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); 923 + if (err) 924 + goto out; 925 + 926 + err = rps_cpumask_housekeeping(mask); 927 + if (err) 928 + goto out; 929 + 930 + err = netdev_rx_queue_set_rps_mask(queue, mask); 931 + 932 + out: 873 933 free_cpumask_var(mask); 874 - return len; 934 + return err ? : len; 875 935 } 876 936 877 937 static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,