Skip to contentSkip to conversation

xen: Allow a default compiled-in command line using Kconfig

PATCH Superseded Zhongze Liu 3 participants 7 messages Mar 21, 2017

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 xen: Allow a default compiled-in command line using Kconfig

This allows downstreams to set their defaults without modifying the source code all over the place. Also probably useful for the embedded space. (See Also: https://xenproject.atlassian.net/browse/XEN-41)

Added 2 new config entries in common/Kconfig:
CMDLINE and CMDLINE_OVERRIDE
Modified common/kernel.c:cmdline_parse().

The 2 new entries enable an embedded command line to be compiled in the hypervisor. CMDLINE depends on EXPERT = "y", and CMDLINE_OVERRIDE depends on CMDLINE != "".

If CMDLINE is set, it will be parsed prior to the bootloader command line. This order of parsing implies that if any non-cumulative options are set in both CMDLINE and the bootloader command line, only the ones in the latter will take effect. Furthermore, if CMDLINE_OVERRIDE is set to y, the whole bootloader command line will be ignored, which will be useful to work around broken bootloaders. A wrapper to the original common/kernel.c:cmdline_parse() was introduced to complete this task.

Cc Andrew Cooper <[email protected]>
Cc George Dunlap <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Tim Deegan <[email protected]>
Cc Wei Liu <[email protected]>

---
Changed since v6:
* Adjusted the ordering of paragraphs in the commit message, with the motivation of this patch being the first paragraph now.
* Fixed some typos in the commit message.

---
 xen/common/Kconfig  | 22 ++++++++++++++++++++++
 xen/common/kernel.c | 30 ++++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 6 deletions(-)
xen/common/Kconfig +22 -0
index f2ecbc43d6..e1c90b739a 100644
@@ -237,4 +237,26 @@ config FAST_SYMBOL_LOOKUP
 	  The only user of this is Live patching.
 
 	  If unsure, say Y.
+
+config CMDLINE
+	string "Built-in hypervisor command string"
+	default ""
+	depends on EXPERT = "y"
+	---help---
+	  Enter arguments here that should be compiled into the hypervisor
+	  image and used at boot time. When the system boots, this string
+	  will be parsed prior to the bootloader command line. So if a
+	  non-cumulative option is set both in this string and in the
+	  bootloader command line, only the latter one will take effect.
+
+config CMDLINE_OVERRIDE
+	bool "Built-in command line overrides bootloader arguments"
+	default n
+	depends on CMDLINE != ""
+	---help---
+	  Set this option to 'Y' to have the hypervisor ignore the bootloader
+	  command line, and use ONLY the built-in command line.
+
+	  This is used to work around broken bootloaders. This should
+	  be set to 'N' under normal conditions.
 endmenu
xen/common/kernel.c +24 -6
index 4b87c60845..64920e8304 100644
@@ -23,6 +23,7 @@
 enum system_state system_state = SYS_STATE_early_boot;
 
 xen_commandline_t saved_cmdline;
+static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE;
 
 static void __init assign_integer_param(
     const struct kernel_param *param, uint64_t val)
@@ -46,18 +47,13 @@ static void __init assign_integer_param(
     }
 }
 
-void __init cmdline_parse(const char *cmdline)
+static void __init _cmdline_parse(const char *cmdline)
 {
     char opt[100], *optval, *optkey, *q;
     const char *p = cmdline;
     const struct kernel_param *param;
     int bool_assert;
 
-    if ( cmdline == NULL )
-        return;
-
-    safe_strcpy(saved_cmdline, cmdline);
-
     for ( ; ; )
     {
         /* Skip whitespace. */
@@ -147,6 +143,28 @@ void __init cmdline_parse(const char *cmdline)
     }
 }
 
+/**
+ *    cmdline_parse -- parses the xen command line.
+ * If CONFIG_CMDLINE is set, it would be parsed prior to @cmdline.
+ * But if CONFIG_CMDLINE_OVERRIDE is set to y, @cmdline will be ignored.
+ */
+void __init cmdline_parse(const char *cmdline)
+{
+    if ( opt_builtin_cmdline[0] )
+    {
+        printk("Built-in command line: %s\n", opt_builtin_cmdline);
+        _cmdline_parse(opt_builtin_cmdline);
+    }
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+    if ( cmdline == NULL )
+        return;
+
+    safe_strcpy(saved_cmdline, cmdline);
+    _cmdline_parse(cmdline);
+#endif
+}
+
 int __init parse_bool(const char *s)
 {
     if ( !strcmp("no", s) ||
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 5 lines · Zhongze Liu

This allows downstreams to set their defaults without modifying the source code
all over the place. Also probably useful for the embedded space. (See Also: https://xenproject.atlassian.net/browse/XEN-41)

Quoted 9 lines

Added 2 new config entries in common/Kconfig:
    CMDLINE and CMDLINE_OVERRIDE
Modified common/kernel.c:cmdline_parse().

The 2 new entries enable an embedded command line to be compiled in the hypervisor. CMDLINE depends on EXPERT = "y", and CMDLINE_OVERRIDE
depends on CMDLINE != "".

Well, Jan also said:

"albeit I think the commit message should have what is now the 4th paragraph first, with what are currently 1st and 2nd paragraphs dropped altogether."

And those "1st and 2nd paragraphs" refers to, in this version, the text that goes from "Added 2 new..." to "...depends on CMDLINE != """, which, for what is worth, I agree does not add much and should be dropped.

Although it's probably not a super big deal...

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

2017-03-21 16:59 GMT+08:00 Dario Faggioli <[email protected]>:

Quoted 21 lines · Zhongze Liu
Quoted 5 lines

This allows downstreams to set their defaults without modifying the source code
all over the place. Also probably useful for the embedded space. (See Also: https://xenproject.atlassian.net/browse/XEN-41)

Quoted 9 lines

Added 2 new config entries in common/Kconfig:
CMDLINE and CMDLINE_OVERRIDE
Modified common/kernel.c:cmdline_parse().

The 2 new entries enable an embedded command line to be compiled in the hypervisor. CMDLINE depends on EXPERT = "y", and CMDLINE_OVERRIDE
depends on CMDLINE != "".

Well, Jan also said:

"albeit I think the commit message should have what is now the 4th paragraph first, with what are currently 1st and 2nd paragraphs dropped altogether."

Quoted 7 lines

And those "1st and 2nd paragraphs" refers to, in this version, the text that goes from "Added 2 new..." to "...depends on CMDLINE != """, which, for what is worth, I agree does not add much and should be dropped.

Although it's probably not a super big deal...

I thought these two paragraphs help people reading this message understand more clearly what has been touched and what has been done.
Although, as you put it, this is really not a super big dea, I'll try to make my commit message more concise in my later patches.

Cheers.

Zhongze Liu

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

On Tue, 2017-03-21 at 17:17 +0800, Zhongze Liu wrote:
:

Quoted 18 lines
Quoted 2 lines · Zhongze Liu
Quoted 1 line

Added 2 new config entries in common/Kconfig:

Quoted 9 lines
Quoted 8 lines

    CMDLINE and CMDLINE_OVERRIDE
Modified common/kernel.c:cmdline_parse().

The 2 new entries enable an embedded command line to be compiled in the hypervisor. CMDLINE depends on EXPERT = "y", and CMDLINE_OVERRIDE
depends on CMDLINE != "".

Quoted 6 lines

And those "1st and 2nd paragraphs" refers to, in this version, the text
that goes from "Added 2 new..." to "...depends on CMDLINE != """, which, for what is worth, I agree does not add much and should be dropped.

Quoted 4 lines

I thought these two paragraphs help people reading this message understand more clearly what has been touched and what has been done.

Right. And in fact, coming up with good changelogs is definitely not the easiest part of preparing a patch. :-)

It's, therefore, quite difficult to come up with rules that can be called truly general. In this specific case, all the information conveyed by those paragraphs is already there, e.g., by looking at the diffstat (during the review process) and at the code.

And the purpose of the commit message is not to explain *what* the code does (or, let's say, not at this level of details), but other things, such as:
- why there were the need for the patch;
- why the code does what it does in the specific way it does it. :-)

It's certainly not straightforward to draw a line, and even people that
are doing this for ages not always get it right at the first time, and
there's always room for learning and improving... That's why we often mention things like this. :-D

Quoted 4 lines

Although, as you put it, this is really not a super big dea, I'll try to make
my commit message more concise in my later patches.

It's not necessarily a matter of length. Much more so a matter of redundancy and of what kind of information is there.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
In reply to Zhongze Liu
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 09:43, <[email protected]> wrote:

Added 2 new config entries in common/Kconfig:
CMDLINE and CMDLINE_OVERRIDE
Modified common/kernel.c:cmdline_parse().

The 2 new entries enable an embedded command line to be compiled in the hypervisor. CMDLINE depends on EXPERT = "y", and CMDLINE_OVERRIDE depends on CMDLINE != "".

I'm slightly confused: Didn't you agree to my suggestion to drop these two paragraphs altogether? My intention is still to purge them while committing.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
In reply to Dario Faggioli

2017-03-21 17:30 GMT+08:00 Dario Faggioli <[email protected]>:

Quoted 43 lines · Zhongze Liu

:

Quoted 18 lines
Quoted 2 lines · Zhongze Liu
Quoted 1 line

Added 2 new config entries in common/Kconfig:

Quoted 9 lines
Quoted 8 lines

CMDLINE and CMDLINE_OVERRIDE
Modified common/kernel.c:cmdline_parse().

The 2 new entries enable an embedded command line to be compiled in the hypervisor. CMDLINE depends on EXPERT = "y", and CMDLINE_OVERRIDE
depends on CMDLINE != "".

Quoted 6 lines

And those "1st and 2nd paragraphs" refers to, in this version, the text
that goes from "Added 2 new..." to "...depends on CMDLINE != """, which, for what is worth, I agree does not add much and should be dropped.

Quoted 4 lines

I thought these two paragraphs help people reading this message understand more clearly what has been touched and what has been done.

Right. And in fact, coming up with good changelogs is definitely not the easiest part of preparing a patch. :-)

It's, therefore, quite difficult to come up with rules that can be called truly general. In this specific case, all the information conveyed by those paragraphs is already there, e.g., by looking at the diffstat (during the review process) and at the code.

And the purpose of the commit message is not to explain *what* the code does (or, let's say, not at this level of details), but other things, such as:
- why there were the need for the patch;
- why the code does what it does in the specific way it does it. :-)

It's certainly not straightforward to draw a line, and even people that
are doing this for ages not always get it right at the first time, and
there's always room for learning and improving... That's why we often mention things like this. :-D

Quoted 7 lines
Quoted 4 lines

Although, as you put it, this is really not a super big dea, I'll try to make
my commit message more concise in my later patches.

It's not necessarily a matter of length. Much more so a matter of redundancy and of what kind of information is there.

Thanks for your kind words. Having thoroughly read your comment, I think I now understand why these two paragraphs are redundant. Thanks for teaching me about that. I'll surely try my best to learn more
about how to write a good commit message. And I think the best way is to observe what others do and try to develop a good "taste" of it.

Cheers.

Zhongze Liu.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
In reply to Jan Beulich

2017-03-21 17:37 GMT+08:00 Jan Beulich <[email protected]>:

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.03.17 at 09:43, <[email protected]> wrote:

Added 2 new config entries in common/Kconfig:
CMDLINE and CMDLINE_OVERRIDE
Modified common/kernel.c:cmdline_parse().

Quoted 8 lines
Quoted 3 lines

The 2 new entries enable an embedded command line to be compiled in the hypervisor. CMDLINE depends on EXPERT = "y", and CMDLINE_OVERRIDE depends on CMDLINE != "".

I'm slightly confused: Didn't you agree to my suggestion to drop these two paragraphs altogether? My intention is still to purge them while committing.

Sorry Jan, I didn't mean to confuse you. I think I should have said:
"partly agree" and
explain why. my fault, sorry. Having read through Dario's words, I now understand
what your concerns are. And now I'm trying to develop a good taste of commit messages.

I'm still learning things, so please do continue to point out my problems if you find any. I
sincerely appreciate all the things I've learned here so far. Thanks.

Cheers.

Zhongze Liu.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel