Date: Sun, 3 Jan 2016 09:44:26 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r293097 - in user/ngie/stable-10-libnv: share/man/man9 sys/dev/pci usr.sbin/iovctl Message-ID: <201601030944.u039iQuY038200@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Sun Jan 3 09:44:26 2016 New Revision: 293097 URL: https://svnweb.freebsd.org/changeset/base/293097 Log: MFC r279465,r284558,r285189,r285273: r279465 (by rstone): Validate the schema that the PF driver passed to us r284558 (by brueffer): Document title should be in CAPS. r285189 (by pkelsey): Fix range upper bound for uint32_t and uint64_t, and reformat range description for uint8_t, uint16_t, uint32_t, and uint64_t. r285273 (by pkelsey): Replace use of .Po Pc with the preferred .Pq for single line enclosures in iovctl.conf(5), iovctl(8), pci(9), and pci_iov_schema(9). Modified: user/ngie/stable-10-libnv/share/man/man9/pci.9 user/ngie/stable-10-libnv/share/man/man9/pci_iov_schema.9 user/ngie/stable-10-libnv/sys/dev/pci/pci_iov.c user/ngie/stable-10-libnv/sys/dev/pci/pci_iov_schema.c user/ngie/stable-10-libnv/sys/dev/pci/schema_private.h user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.8 user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.conf.5 Directory Properties: user/ngie/stable-10-libnv/ (props changed) Modified: user/ngie/stable-10-libnv/share/man/man9/pci.9 ============================================================================== --- user/ngie/stable-10-libnv/share/man/man9/pci.9 Sun Jan 3 09:38:05 2016 (r293096) +++ user/ngie/stable-10-libnv/share/man/man9/pci.9 Sun Jan 3 09:44:26 2016 (r293097) @@ -515,7 +515,7 @@ The function is used to advertise that the given device .Pq and associated device driver supports PCI Single-Root I/O Virtualization -.Po SR-IOV Pc . +.Pq SR-IOV . A driver that supports SR-IOV must implement the .Xr PCI_IOV_INIT 9 , .Xr PCI_IOV_ADD_VF 9 Modified: user/ngie/stable-10-libnv/share/man/man9/pci_iov_schema.9 ============================================================================== --- user/ngie/stable-10-libnv/share/man/man9/pci_iov_schema.9 Sun Jan 3 09:38:05 2016 (r293096) +++ user/ngie/stable-10-libnv/share/man/man9/pci_iov_schema.9 Sun Jan 3 09:44:26 2016 (r293097) @@ -25,8 +25,8 @@ .\" .\" $FreeBSD$ .\" -.Dd May 28, 2015 -.Dt pci_iov_schema 9 +.Dd July 8, 2015 +.Dt PCI_IOV_SCHEMA 9 .Os .Sh NAME .Nm pci_iov_schema , @@ -227,7 +227,7 @@ type. Values of type .Vt uint32_t are unsigned integers in the range 0 to -.Po 2**32 - 1 Pc , +.Pq 2**32 - 1 , inclusive. .Pp The @@ -241,7 +241,7 @@ type. Values of type .Vt uint64_t are unsigned integers in the range 0 to -.Po 2**64 - 1 Pc , +.Pq 2**64 - 1 , inclusive. .Pp The Modified: user/ngie/stable-10-libnv/sys/dev/pci/pci_iov.c ============================================================================== --- user/ngie/stable-10-libnv/sys/dev/pci/pci_iov.c Sun Jan 3 09:38:05 2016 (r293096) +++ user/ngie/stable-10-libnv/sys/dev/pci/pci_iov.c Sun Jan 3 09:44:26 2016 (r293097) @@ -142,6 +142,10 @@ pci_iov_attach_method(device_t bus, devi error = ENOMEM; goto cleanup; } + + error = pci_iov_validate_schema(schema); + if (error != 0) + goto cleanup; iov->iov_schema = schema; iov->iov_cdev = make_dev(&iov_cdevsw, device_get_unit(dev), Modified: user/ngie/stable-10-libnv/sys/dev/pci/pci_iov_schema.c ============================================================================== --- user/ngie/stable-10-libnv/sys/dev/pci/pci_iov_schema.c Sun Jan 3 09:38:05 2016 (r293096) +++ user/ngie/stable-10-libnv/sys/dev/pci/pci_iov_schema.c Sun Jan 3 09:44:26 2016 (r293097) @@ -50,26 +50,66 @@ __FBSDID("$FreeBSD$"); struct config_type_validator; typedef int (validate_func)(const struct config_type_validator *, const nvlist_t *, const char *name); +typedef int (default_validate_t)(const struct config_type_validator *, + const nvlist_t *); static validate_func pci_iov_schema_validate_bool; static validate_func pci_iov_schema_validate_string; static validate_func pci_iov_schema_validate_uint; static validate_func pci_iov_schema_validate_unicast_mac; +static default_validate_t pci_iov_validate_bool_default; +static default_validate_t pci_iov_validate_string_default; +static default_validate_t pci_iov_validate_uint_default; +static default_validate_t pci_iov_validate_unicast_mac_default; + struct config_type_validator { const char *type_name; validate_func *validate; + default_validate_t *default_validate; uintmax_t limit; }; static struct config_type_validator pci_iov_schema_validators[] = { - { "bool", pci_iov_schema_validate_bool }, - { "string", pci_iov_schema_validate_string }, - { "uint8_t", pci_iov_schema_validate_uint, UINT8_MAX }, - { "uint16_t", pci_iov_schema_validate_uint, UINT16_MAX }, - { "uint32_t", pci_iov_schema_validate_uint, UINT32_MAX }, - { "uint64_t", pci_iov_schema_validate_uint, UINT64_MAX }, - { "unicast-mac", pci_iov_schema_validate_unicast_mac }, + { + .type_name = "bool", + .validate = pci_iov_schema_validate_bool, + .default_validate = pci_iov_validate_bool_default + }, + { + .type_name = "string", + .validate = pci_iov_schema_validate_string, + .default_validate = pci_iov_validate_string_default + }, + { + .type_name = "uint8_t", + .validate = pci_iov_schema_validate_uint, + .default_validate = pci_iov_validate_uint_default, + .limit = UINT8_MAX + }, + { + .type_name = "uint16_t", + .validate = pci_iov_schema_validate_uint, + .default_validate = pci_iov_validate_uint_default, + .limit = UINT16_MAX + }, + { + .type_name = "uint32_t", + .validate = pci_iov_schema_validate_uint, + .default_validate = pci_iov_validate_uint_default, + .limit = UINT32_MAX + }, + { + .type_name = "uint64_t", + .validate = pci_iov_schema_validate_uint, + .default_validate = pci_iov_validate_uint_default, + .limit = UINT64_MAX + }, + { + .type_name = "unicast-mac", + .validate = pci_iov_schema_validate_unicast_mac, + .default_validate = pci_iov_validate_unicast_mac_default, + }, }; static const struct config_type_validator * @@ -309,6 +349,227 @@ pci_iov_config_add_default(const nvlist_ panic("Unexpected nvlist type"); } +static int +pci_iov_validate_bool_default(const struct config_type_validator * validator, + const nvlist_t *param) +{ + + if (!nvlist_exists_bool(param, DEFAULT_SCHEMA_NAME)) + return (EINVAL); + return (0); +} + +static int +pci_iov_validate_string_default(const struct config_type_validator * validator, + const nvlist_t *param) +{ + + if (!nvlist_exists_string(param, DEFAULT_SCHEMA_NAME)) + return (EINVAL); + return (0); +} + +static int +pci_iov_validate_uint_default(const struct config_type_validator * validator, + const nvlist_t *param) +{ + uint64_t defaultVal; + + if (!nvlist_exists_number(param, DEFAULT_SCHEMA_NAME)) + return (EINVAL); + + defaultVal = nvlist_get_number(param, DEFAULT_SCHEMA_NAME); + if (defaultVal > validator->limit) + return (EINVAL); + return (0); +} + +static int +pci_iov_validate_unicast_mac_default( + const struct config_type_validator * validator, const nvlist_t *param) +{ + const uint8_t *mac; + size_t size; + + if (!nvlist_exists_binary(param, DEFAULT_SCHEMA_NAME)) + return (EINVAL); + + mac = nvlist_get_binary(param, DEFAULT_SCHEMA_NAME, &size); + if (size != ETHER_ADDR_LEN) + return (EINVAL); + + if (ETHER_IS_MULTICAST(mac)) + return (EINVAL); + return (0); +} + +static int +pci_iov_validate_param_schema(const nvlist_t *schema) +{ + const struct config_type_validator *validator; + const char *type; + int error; + + /* All parameters must define a type. */ + if (!nvlist_exists_string(schema, TYPE_SCHEMA_NAME)) + return (EINVAL); + type = nvlist_get_string(schema, TYPE_SCHEMA_NAME); + + validator = pci_iov_schema_find_validator(type); + if (validator == NULL) + return (EINVAL); + + /* Validate that the default value conforms to the type. */ + if (nvlist_exists(schema, DEFAULT_SCHEMA_NAME)) { + error = validator->default_validate(validator, schema); + if (error != 0) + return (error); + + /* Required and Default are mutually exclusive. */ + if (nvlist_exists(schema, REQUIRED_SCHEMA_NAME)) + return (EINVAL); + } + + /* The "Required" field must be a bool. */ + if (nvlist_exists(schema, REQUIRED_SCHEMA_NAME)) { + if (!nvlist_exists_bool(schema, REQUIRED_SCHEMA_NAME)) + return (EINVAL); + } + + return (0); +} + +static int +pci_iov_validate_subsystem_schema(const nvlist_t *dev_schema, const char *name) +{ + const nvlist_t *sub_schema, *param_schema; + const char *param_name; + void *it; + int type, error; + + if (!nvlist_exists_nvlist(dev_schema, name)) + return (EINVAL); + sub_schema = nvlist_get_nvlist(dev_schema, name); + + it = NULL; + while ((param_name = nvlist_next(sub_schema, &type, &it)) != NULL) { + if (type != NV_TYPE_NVLIST) + return (EINVAL); + param_schema = nvlist_get_nvlist(sub_schema, param_name); + + error = pci_iov_validate_param_schema(param_schema); + if (error != 0) + return (error); + } + + return (0); +} + +/* + * Validate that the driver schema does not define any configuration parameters + * whose names collide with configuration parameters defined in the iov schema. + */ +static int +pci_iov_validate_param_collisions(const nvlist_t *dev_schema) +{ + const nvlist_t *iov_schema, *driver_schema; + const char *name; + void *it; + int type; + + driver_schema = nvlist_get_nvlist(dev_schema, DRIVER_CONFIG_NAME); + iov_schema = nvlist_get_nvlist(dev_schema, IOV_CONFIG_NAME); + + it = NULL; + while ((name = nvlist_next(driver_schema, &type, &it)) != NULL) { + if (nvlist_exists(iov_schema, name)) + return (EINVAL); + } + + return (0); +} + +/* + * Validate that we only have IOV and DRIVER subsystems beneath the given + * device schema node. + */ +static int +pci_iov_validate_schema_subsystems(const nvlist_t *dev_schema) +{ + const char *name; + void *it; + int type; + + it = NULL; + while ((name = nvlist_next(dev_schema, &type, &it)) != NULL) { + if (strcmp(name, IOV_CONFIG_NAME) != 0 && + strcmp(name, DRIVER_CONFIG_NAME) != 0) + return (EINVAL); + } + + return (0); +} + +static int +pci_iov_validate_device_schema(const nvlist_t *schema, const char *name) +{ + const nvlist_t *dev_schema; + int error; + + if (!nvlist_exists_nvlist(schema, name)) + return (EINVAL); + dev_schema = nvlist_get_nvlist(schema, name); + + error = pci_iov_validate_subsystem_schema(dev_schema, IOV_CONFIG_NAME); + if (error != 0) + return (error); + + error = pci_iov_validate_subsystem_schema(dev_schema, + DRIVER_CONFIG_NAME); + if (error != 0) + return (error); + + error = pci_iov_validate_param_collisions(dev_schema); + if (error != 0) + return (error); + + return (pci_iov_validate_schema_subsystems(dev_schema)); +} + +/* Validate that we only have PF and VF devices beneath the top-level schema. */ +static int +pci_iov_validate_schema_devices(const nvlist_t *dev_schema) +{ + const char *name; + void *it; + int type; + + it = NULL; + while ((name = nvlist_next(dev_schema, &type, &it)) != NULL) { + if (strcmp(name, PF_CONFIG_NAME) != 0 && + strcmp(name, VF_SCHEMA_NAME) != 0) + return (EINVAL); + } + + return (0); +} + +int +pci_iov_validate_schema(const nvlist_t *schema) +{ + int error; + + error = pci_iov_validate_device_schema(schema, PF_CONFIG_NAME); + if (error != 0) + return (error); + + error = pci_iov_validate_device_schema(schema, VF_SCHEMA_NAME); + if (error != 0) + return (error); + + return (pci_iov_validate_schema_devices(schema)); +} + /* * Validate that all required parameters from the schema are specified in the * config. If any parameter with a default value is not specified in the Modified: user/ngie/stable-10-libnv/sys/dev/pci/schema_private.h ============================================================================== --- user/ngie/stable-10-libnv/sys/dev/pci/schema_private.h Sun Jan 3 09:38:05 2016 (r293096) +++ user/ngie/stable-10-libnv/sys/dev/pci/schema_private.h Sun Jan 3 09:44:26 2016 (r293097) @@ -29,6 +29,8 @@ #ifndef _SCHEMA_PRIVATE_H_ #define _SCHEMA_PRIVATE_H_ +int pci_iov_validate_schema(const nvlist_t *schema); + int pci_iov_schema_validate_config(const nvlist_t *, nvlist_t *); uint16_t pci_iov_config_get_num_vfs(const nvlist_t *); Modified: user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.8 ============================================================================== --- user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.8 Sun Jan 3 09:38:05 2016 (r293096) +++ user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.8 Sun Jan 3 09:44:26 2016 (r293097) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 21, 2014 +.Dd July 8, 2015 .Dt IOVCTL 8 .Os .Sh NAME @@ -49,7 +49,7 @@ The utility creates or destroys PCI Single-Root I/O Virtualization .Pq SR-IOV Virtual Functions -.Po VFs Pc . +.Pq VFs . When invoked with the .Fl C flag, Modified: user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.conf.5 ============================================================================== --- user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.conf.5 Sun Jan 3 09:38:05 2016 (r293096) +++ user/ngie/stable-10-libnv/usr.sbin/iovctl/iovctl.conf.5 Sun Jan 3 09:44:26 2016 (r293097) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 21, 2014 +.Dd July 8, 2015 .Dt IOVCTL.CONF 5 .Os .Sh NAME @@ -77,7 +77,7 @@ The second section type is the VF sectio This section has the key "VF-" followed by a VF index. VF indices start at 0 and always increment by 1. Valid VF indices are in the range of 0 to -.Po num_vfs - 1 Pc . +.Pq num_vfs - 1 . The VF index must be given as a decimal integer with no leading zeros. This section defines configuration parameters that apply to a single VF. .Pp @@ -103,13 +103,17 @@ xx:xx:xx:xx:xx:xx, where xx is one or tw .It string Accepts any string value. .It uint8_t -Accepts any integer in the range 0-255, inclusive. +Accepts any integer in the range 0 to 255, inclusive. .It uint16_t -Accepts any integer in the range 0-65535, inclusive. +Accepts any integer in the range 0 to 65535, inclusive. .It uint32_t -Accepts any integer in the range 0-2**32, inclusive. +Accepts any integer in the range 0 to +.Pq 2**32 - 1 , +inclusive. .It uint64_t -Accepts any integer in the range 0-2**64, inclusive. +Accepts any integer in the range 0 to +.Pq 2**64 - 1 , +inclusive. .El .Sh OPTIONS The following parameters are accepted by all PF drivers:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601030944.u039iQuY038200>