Skip to contentSkip to conversation

bootconfig: Syntax updates

PATCH In review Masami Hiramatsu 3 participants 7 messages Feb 21, 2020 – Feb 22, 2020

Subsystems (3)
lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

v3 cover bootconfig: Syntax updates

Hi,

Here is the 3rd version of the bootconfig syntax update which remains on my queue.

- [1/2] A new patch for prohibiting re-definition of value.
- [2/2] Update the value append operator patch on [1/2].

Thank you,

---

Masami Hiramatsu (2):
bootconfig: Prohibit re-defining value on same key
bootconfig: Add append value operator support

 Documentation/admin-guide/bootconfig.rst   |   19 ++++++++++++++++++-
 lib/bootconfig.c                           |   26 ++++++++++++++++++--------
 tools/bootconfig/samples/bad-samekey.bconf |    6 ++++++
 tools/bootconfig/test-bootconfig.sh        |   16 ++++++++++++++--
 4 files changed, 56 insertions(+), 11 deletions(-)
 create mode 100644 tools/bootconfig/samples/bad-samekey.bconf

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH v3 1/2 bootconfig: Prohibit re-defining value on same key

Currently, bootconfig adds new value on the existing key to the tail of an array. But this looks a bit confusing because admin can rewrite original value in same config file easily.

This rejects following value re-definition.

key = value1
...
key = value2

You should rewrite value1 to value2 in this case.

---
 Documentation/admin-guide/bootconfig.rst   |   11 ++++++++++-
 lib/bootconfig.c                           |   13 ++++++++-----
 tools/bootconfig/samples/bad-samekey.bconf |    6 ++++++
 3 files changed, 24 insertions(+), 6 deletions(-)
 create mode 100644 tools/bootconfig/samples/bad-samekey.bconf
Documentation/admin-guide/bootconfig.rst +10 -1
index dfeffa73dca3..9ee7650b7817 100644
@@ -62,7 +62,16 @@ Or more shorter, written as following::
 In both styles, same key words are automatically merged when parsing it
 at boot time. So you can append similar trees or key-values.
 
-Note that a sub-key and a value can not co-exist under a parent key.
+Same-key Values
+---------------
+
+It is prohibited that two or more values or arraies share a same-key.
+For example,::
+
+ foo = bar, baz
+ foo = qux  # !ERROR! we can not re-define same key
+
+Also, a sub-key and a value can not co-exist under a parent key.
 For example, following config is NOT allowed.::
 
  foo = value1
lib/bootconfig.c +8 -5
index 54ac623ca781..2ef304db31f2 100644
@@ -581,7 +581,7 @@ static int __init __xbc_parse_keys(char *k)
 static int __init xbc_parse_kv(char **k, char *v)
 {
 	struct xbc_node *prev_parent = last_parent;
-	struct xbc_node *node, *child;
+	struct xbc_node *child;
 	char *next;
 	int c, ret;
 
@@ -590,15 +590,18 @@ static int __init xbc_parse_kv(char **k, char *v)
 		return ret;
 
 	child = xbc_node_get_child(last_parent);
-	if (child && xbc_node_is_key(child))
-		return xbc_parse_error("Value is mixed with subkey", v);
+	if (child) {
+		if (xbc_node_is_key(child))
+			return xbc_parse_error("Value is mixed with subkey", v);
+		else
+			return xbc_parse_error("Value is redefined", v);
+	}
 
 	c = __xbc_parse_value(&v, &next);
 	if (c < 0)
 		return c;
 
-	node = xbc_add_sibling(v, XBC_VALUE);
-	if (!node)
+	if (!xbc_add_sibling(v, XBC_VALUE))
 		return -ENOMEM;
 
 	if (c == ',') {	/* Array */
tools/bootconfig/samples/bad-samekey.bconf new file +6 -0
new file mode 100644
index 000000000000..e8d983a4563c
@@ -0,0 +1,6 @@
+# Same key value is not allowed
+key {
+	foo = value
+	bar = value2
+}
+key.foo = value
reviewer
#2 lore raw

Re: [PATCH v3 1/2] bootconfig: Prohibit re-defining value on same key

Quoted 7 lines · Masami Hiramatsu

Currently, bootconfig adds new value on the existing key to the tail of an array. But this looks a bit confusing because admin can rewrite original value in same config file easily.

This rejects following value re-definition.

Quoted 7 lines

key = value1
...
key = value2

You should rewrite value1 to value2 in this case.

Hi,
One correction below and then question.

Quoted 12 lines
---
 Documentation/admin-guide/bootconfig.rst   |   11 ++++++++++-
 lib/bootconfig.c                           |   13 ++++++++-----
 tools/bootconfig/samples/bad-samekey.bconf |    6 ++++++
 3 files changed, 24 insertions(+), 6 deletions(-)
 create mode 100644 tools/bootconfig/samples/bad-samekey.bconf
Documentation/admin-guide/bootconfig.rst +0 -0
index dfeffa73dca3..9ee7650b7817 100644

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 68

Quoted 8 lines
Documentation/admin-guide/bootconfig.rst +4 -1
@@ -62,7 +62,16 @@ Or more shorter, written as following::
 In both styles, same key words are automatically merged when parsing it
 at boot time. So you can append similar trees or key-values.
 
-Note that a sub-key and a value can not co-exist under a parent key.
+Same-key Values
+---------------
+
+It is prohibited that two or more values or arraies share a same-key.

I think (?): arrays

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 77

Quoted 9 lines
Documentation/admin-guide/bootconfig.rst +6 -0
+For example,::
+
+ foo = bar, baz
+ foo = qux  # !ERROR! we can not re-define same key
+
+Also, a sub-key and a value can not co-exist under a parent key.
 For example, following config is NOT allowed.::
 
  foo = value1

I'm pretty sure that the kernel command line allows someone to use
key=value1 ... key=value2
and the first setting is just overwritten with value2 (for most "key"s).

Am I wrong? and is this patch saying that bootconfig won't operate like that?

thanks.

Signature · 1 line
~Randy
#3 lore raw

Re: [PATCH v3 1/2] bootconfig: Prohibit re-defining value on same key

Hi Randy,

Quoted 23 lines · Randy Dunlap

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 68

Quoted 11 lines · Masami Hiramatsu
Documentation/admin-guide/bootconfig.rst +4 -1
@@ -62,7 +62,16 @@ Or more shorter, written as following::
 In both styles, same key words are automatically merged when parsing it
 at boot time. So you can append similar trees or key-values.
 
-Note that a sub-key and a value can not co-exist under a parent key.
+Same-key Values
+---------------
+
+It is prohibited that two or more values or arraies share a same-key.

I think (?): arrays

Quoted 8 lines
Documentation/admin-guide/bootconfig.rst +6 -0
+For example,::
+
+ foo = bar, baz
+ foo = qux  # !ERROR! we can not re-define same key
+
+Also, a sub-key and a value can not co-exist under a parent key.
 For example, following config is NOT allowed.::
 
Quoted 8 lines

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 77

Quoted 1 line
Documentation/admin-guide/bootconfig.rst +0 -0
  foo = value1

I'm pretty sure that the kernel command line allows someone to use
key=value1 ... key=value2
and the first setting is just overwritten with value2 (for most "key"s).

Am I wrong? and is this patch saying that bootconfig won't operate like that?

I think so. Both are retained.
A typical example is "console=ttyS0 console=tty", to have the kernel output on both the serial and the graphical console.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author maintainer
#4 lore raw

Re: [PATCH v3 1/2] bootconfig: Prohibit re-defining value on same key

Quoted 33 lines · On Sat, 22 Feb 2020 10:31:17 +0100 Geert Uytterhoeven <[email protected]>…

Hi Randy,

Quoted 30 lines · Randy Dunlap

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 68

Quoted 11 lines · Masami Hiramatsu
Documentation/admin-guide/bootconfig.rst +4 -1
@@ -62,7 +62,16 @@ Or more shorter, written as following::
 In both styles, same key words are automatically merged when parsing it
 at boot time. So you can append similar trees or key-values.
 
-Note that a sub-key and a value can not co-exist under a parent key.
+Same-key Values
+---------------
+
+It is prohibited that two or more values or arraies share a same-key.

I think (?): arrays

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 77

Quoted 9 lines
Documentation/admin-guide/bootconfig.rst +6 -0
+For example,::
+
+ foo = bar, baz
+ foo = qux  # !ERROR! we can not re-define same key
+
+Also, a sub-key and a value can not co-exist under a parent key.
 For example, following config is NOT allowed.::
 
  foo = value1

I'm pretty sure that the kernel command line allows someone to use
key=value1 ... key=value2
and the first setting is just overwritten with value2 (for most "key"s).

Quoted 5 lines
Quoted 1 line

Am I wrong? and is this patch saying that bootconfig won't operate like that?

I think so. Both are retained.
A typical example is "console=ttyS0 console=tty", to have the kernel output on both the serial and the graphical console.

Right, it actually depends on how the option is defined and its handler. If the option is defined with module_param*() macros, those will be overwritten.
But if it is defined with __setup() or early_param(), the handler function will be called repeatedly. Thus, overwrite or append or skip later one depends on the option handler.

I think the bootconfig is a bit different from legacy command line at this moment. The legacy command line can be modified by bootloader, whereas the bootconfig is a single text file which user can update each value. Of course bootloader will support the bootconfig to append some key-values in the future.
So I would like to introduce another "overwrite" operator (":=") and "assign default" operator ("?=") too. With those operators, the bootloader can just add their own key-value without decoding the current bootconfig.

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
reviewer
#5 lore raw

Re: [PATCH v3 1/2] bootconfig: Prohibit re-defining value on same key

Quoted 36 lines · Masami Hiramatsu
Quoted 33 lines · On Sat, 22 Feb 2020 10:31:17 +0100 Geert Uytterhoeven <[email protected]>…

Hi Randy,

Quoted 30 lines · Randy Dunlap

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 68

Quoted 11 lines · Masami Hiramatsu
Documentation/admin-guide/bootconfig.rst +4 -1
@@ -62,7 +62,16 @@ Or more shorter, written as following::
 In both styles, same key words are automatically merged when parsing it
 at boot time. So you can append similar trees or key-values.
 
-Note that a sub-key and a value can not co-exist under a parent key.
+Same-key Values
+---------------
+
+It is prohibited that two or more values or arraies share a same-key.

I think (?): arrays

Documentation/admin-guide/bootconfig.rst Or more shorter, written as following:: · line 77

Quoted 9 lines
Documentation/admin-guide/bootconfig.rst +6 -0
+For example,::
+
+ foo = bar, baz
+ foo = qux  # !ERROR! we can not re-define same key
+
+Also, a sub-key and a value can not co-exist under a parent key.
 For example, following config is NOT allowed.::
 
  foo = value1

I'm pretty sure that the kernel command line allows someone to use
key=value1 ... key=value2
and the first setting is just overwritten with value2 (for most "key"s).

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

Am I wrong? and is this patch saying that bootconfig won't operate like that?

I think so. Both are retained.
A typical example is "console=ttyS0 console=tty", to have the kernel output on both the serial and the graphical console.

Yes, I was aware of that one also.

Quoted 6 lines

Right, it actually depends on how the option is defined and its handler. If the option is defined with module_param*() macros, those will be overwritten.
But if it is defined with __setup() or early_param(), the handler function will be called repeatedly. Thus, overwrite or append or skip later one depends on the option handler.

OK, thanks for that clarification.

Quoted 9 lines

I think the bootconfig is a bit different from legacy command line at this moment. The legacy command line can be modified by bootloader, whereas the bootconfig is a single text file which user can update each value. Of course bootloader will support the bootconfig to append some key-values in the future.
So I would like to introduce another "overwrite" operator (":=") and "assign default" operator ("?=") too. With those operators, the bootloader can just add their own key-value without decoding the current bootconfig.

Signature · 1 line
~Randy
author maintainer
#6 lore raw

PATCH v3 2/2 bootconfig: Add append value operator support

In reply to Masami Hiramatsu

Add append value operator "+=" support to bootconfig syntax. With this operator, user can add new value to the key as an entry of array instead of overwriting.
For example,

foo = bar
...
foo += baz

Then the key "foo" has "bar" and "baz" values as an array.

---
V3: update on value re-definition error patch.

---
 Documentation/admin-guide/bootconfig.rst |   10 +++++++++-
 lib/bootconfig.c                         |   15 +++++++++++----
 tools/bootconfig/test-bootconfig.sh      |   16 ++++++++++++++--
 3 files changed, 34 insertions(+), 7 deletions(-)
Documentation/admin-guide/bootconfig.rst +9 -1
index 9ee7650b7817..82a657096ebc 100644
@@ -71,7 +71,15 @@ For example,::
  foo = bar, baz
  foo = qux  # !ERROR! we can not re-define same key
 
-Also, a sub-key and a value can not co-exist under a parent key.
+If you want to append the value to existing key as an array member,
+you can use ``+=`` operator. For example::
+
+ foo = bar, baz
+ foo += qux
+
+In this case, the key ``foo`` has ``bar``, ``baz`` and ``qux``.
+
+However, a sub-key and a value can not co-exist under a parent key.
 For example, following config is NOT allowed.::
 
  foo = value1
lib/bootconfig.c +11 -4
index 2ef304db31f2..ec3ce7fd299f 100644
@@ -578,7 +578,7 @@ static int __init __xbc_parse_keys(char *k)
 	return __xbc_add_key(k);
 }
 
-static int __init xbc_parse_kv(char **k, char *v)
+static int __init xbc_parse_kv(char **k, char *v, int op)
 {
 	struct xbc_node *prev_parent = last_parent;
 	struct xbc_node *child;
@@ -593,7 +593,7 @@ static int __init xbc_parse_kv(char **k, char *v)
 	if (child) {
 		if (xbc_node_is_key(child))
 			return xbc_parse_error("Value is mixed with subkey", v);
-		else
+		else if (op == '=')
 			return xbc_parse_error("Value is redefined", v);
 	}
 
@@ -774,7 +774,7 @@ int __init xbc_init(char *buf)
 
 	p = buf;
 	do {
-		q = strpbrk(p, "{}=;\n#");
+		q = strpbrk(p, "{}=+;\n#");
 		if (!q) {
 			p = skip_spaces(p);
 			if (*p != '\0')
@@ -785,8 +785,15 @@ int __init xbc_init(char *buf)
 		c = *q;
 		*q++ = '\0';
 		switch (c) {
+		case '+':
+			if (*q++ != '=') {
+				ret = xbc_parse_error("Wrong '+' operator",
+							q - 2);
+				break;
+			}
+			/* Fall through */
 		case '=':
-			ret = xbc_parse_kv(&p, q);
+			ret = xbc_parse_kv(&p, q, c);
 			break;
 		case '{':
 			ret = xbc_open_brace(&p, q);
tools/bootconfig/test-bootconfig.sh +14 -2
index adafb7c50940..1411f4c3454f 100755
@@ -9,7 +9,7 @@ TEMPCONF=`mktemp temp-XXXX.bconf`
 NG=0
 
 cleanup() {
-  rm -f $INITRD $TEMPCONF
+  rm -f $INITRD $TEMPCONF $OUTFILE
   exit $NG
 }
 
@@ -71,7 +71,6 @@ printf " \0\0\0 \0\0\0" >> $INITRD
 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
 xfail grep -i "failed" $OUTFILE
 xfail grep -i "error" $OUTFILE
-rm $OUTFILE
 
 echo "Max node number check"
 
@@ -96,6 +95,19 @@ truncate -s 32764 $TEMPCONF
 echo "\"" >> $TEMPCONF	# add 2 bytes + terminal ('\"\n\0')
 xpass $BOOTCONF -a $TEMPCONF $INITRD
 
+echo "Adding same-key values"
+cat > $TEMPCONF << EOF
+key = bar, baz
+key += qux
+EOF
+echo > $INITRD
+
+xpass $BOOTCONF -a $TEMPCONF $INITRD
+$BOOTCONF $INITRD > $OUTFILE
+xpass grep -q "bar" $OUTFILE
+xpass grep -q "baz" $OUTFILE
+xpass grep -q "qux" $OUTFILE
+
 echo "=== expected failure cases ==="
 for i in samples/bad-* ; do
   xfail $BOOTCONF -a $i $INITRD