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

Configure Feed

Select the types of activity you want to include in your feed.

taprio: validate TCA_TAPRIO_ATTR_FLAGS through policy instead of open-coding

As of now, the field TCA_TAPRIO_ATTR_FLAGS is being validated by manually
checking its value, using the function taprio_flags_valid().

With this patch, the field will be validated through the netlink policy
NLA_POLICY_MASK, where the mask is defined by TAPRIO_SUPPORTED_FLAGS.
The mutual exclusivity of the two flags TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD
and TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST is still checked manually.

Changes since RFC:
- fixed reversed xmas tree
- use NL_SET_ERR_MSG_MOD() for both invalid configuration

Changes since v1:
- Changed NL_SET_ERR_MSG_MOD to NL_SET_ERR_MSG_ATTR when wrong flags
issued
- Changed __u32 to u32

Changes since v2:
- Added the missing parameter for NL_SET_ERR_MSG_ATTR (sorry again for
the noise)

Signed-off-by: Alessandro Marcolini <alessandromarcolini99@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alessandro Marcolini and committed by
David S. Miller
0efc7e54 c57e32fb

+26 -46
+26 -46
net/sched/sch_taprio.c
··· 40 40 41 41 #define TXTIME_ASSIST_IS_ENABLED(flags) ((flags) & TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST) 42 42 #define FULL_OFFLOAD_IS_ENABLED(flags) ((flags) & TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD) 43 + #define TAPRIO_SUPPORTED_FLAGS \ 44 + (TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST | TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD) 43 45 #define TAPRIO_FLAGS_INVALID U32_MAX 44 46 45 47 struct sched_entry { ··· 408 406 rcu_read_unlock(); 409 407 410 408 return entry; 411 - } 412 - 413 - static bool taprio_flags_valid(u32 flags) 414 - { 415 - /* Make sure no other flag bits are set. */ 416 - if (flags & ~(TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST | 417 - TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD)) 418 - return false; 419 - /* txtime-assist and full offload are mutually exclusive */ 420 - if ((flags & TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST) && 421 - (flags & TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD)) 422 - return false; 423 - return true; 424 409 } 425 410 426 411 /* This returns the tstamp value set by TCP in terms of the set clock. */ ··· 1020 1031 [TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME] = 1021 1032 NLA_POLICY_FULL_RANGE_SIGNED(NLA_S64, &taprio_cycle_time_range), 1022 1033 [TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION] = { .type = NLA_S64 }, 1023 - [TCA_TAPRIO_ATTR_FLAGS] = { .type = NLA_U32 }, 1034 + [TCA_TAPRIO_ATTR_FLAGS] = 1035 + NLA_POLICY_MASK(NLA_U32, TAPRIO_SUPPORTED_FLAGS), 1024 1036 [TCA_TAPRIO_ATTR_TXTIME_DELAY] = { .type = NLA_U32 }, 1025 1037 [TCA_TAPRIO_ATTR_TC_ENTRY] = { .type = NLA_NESTED }, 1026 1038 }; ··· 1805 1815 return 0; 1806 1816 } 1807 1817 1808 - /* The semantics of the 'flags' argument in relation to 'change()' 1809 - * requests, are interpreted following two rules (which are applied in 1810 - * this order): (1) an omitted 'flags' argument is interpreted as 1811 - * zero; (2) the 'flags' of a "running" taprio instance cannot be 1812 - * changed. 1813 - */ 1814 - static int taprio_new_flags(const struct nlattr *attr, u32 old, 1815 - struct netlink_ext_ack *extack) 1816 - { 1817 - u32 new = 0; 1818 - 1819 - if (attr) 1820 - new = nla_get_u32(attr); 1821 - 1822 - if (old != TAPRIO_FLAGS_INVALID && old != new) { 1823 - NL_SET_ERR_MSG_MOD(extack, "Changing 'flags' of a running schedule is not supported"); 1824 - return -EOPNOTSUPP; 1825 - } 1826 - 1827 - if (!taprio_flags_valid(new)) { 1828 - NL_SET_ERR_MSG_MOD(extack, "Specified 'flags' are not valid"); 1829 - return -EINVAL; 1830 - } 1831 - 1832 - return new; 1833 - } 1834 - 1835 1818 static int taprio_change(struct Qdisc *sch, struct nlattr *opt, 1836 1819 struct netlink_ext_ack *extack) 1837 1820 { ··· 1815 1852 struct net_device *dev = qdisc_dev(sch); 1816 1853 struct tc_mqprio_qopt *mqprio = NULL; 1817 1854 unsigned long flags; 1855 + u32 taprio_flags; 1818 1856 ktime_t start; 1819 1857 int i, err; 1820 1858 ··· 1827 1863 if (tb[TCA_TAPRIO_ATTR_PRIOMAP]) 1828 1864 mqprio = nla_data(tb[TCA_TAPRIO_ATTR_PRIOMAP]); 1829 1865 1830 - err = taprio_new_flags(tb[TCA_TAPRIO_ATTR_FLAGS], 1831 - q->flags, extack); 1832 - if (err < 0) 1833 - return err; 1866 + /* The semantics of the 'flags' argument in relation to 'change()' 1867 + * requests, are interpreted following two rules (which are applied in 1868 + * this order): (1) an omitted 'flags' argument is interpreted as 1869 + * zero; (2) the 'flags' of a "running" taprio instance cannot be 1870 + * changed. 1871 + */ 1872 + taprio_flags = tb[TCA_TAPRIO_ATTR_FLAGS] ? nla_get_u32(tb[TCA_TAPRIO_ATTR_FLAGS]) : 0; 1834 1873 1835 - q->flags = err; 1874 + /* txtime-assist and full offload are mutually exclusive */ 1875 + if ((taprio_flags & TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST) && 1876 + (taprio_flags & TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD)) { 1877 + NL_SET_ERR_MSG_ATTR(extack, tb[TCA_TAPRIO_ATTR_FLAGS], 1878 + "TXTIME_ASSIST and FULL_OFFLOAD are mutually exclusive"); 1879 + return -EINVAL; 1880 + } 1881 + 1882 + if (q->flags != TAPRIO_FLAGS_INVALID && q->flags != taprio_flags) { 1883 + NL_SET_ERR_MSG_MOD(extack, 1884 + "Changing 'flags' of a running schedule is not supported"); 1885 + return -EOPNOTSUPP; 1886 + } 1887 + q->flags = taprio_flags; 1836 1888 1837 1889 err = taprio_parse_mqprio_opt(dev, mqprio, extack, q->flags); 1838 1890 if (err < 0)