[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/6] x86/setup: Rework cmdline_cook() to be compatible with -Wwrite-strings
- To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Tue, 21 Nov 2023 09:21:53 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dtrFhYKpz0Xt6o9hu6G05oYg8fotudtKjQzc2U+NLg8=; b=aM2Q8OuzGg7j33IyK/zoF/bzFGKoKj12cUmVakKP09wDgTRVP33pyENFQ0e8eUTQUqaIjGZ5lNygZNi3+8F8eEGIwxggCvr+c1zqNyL0X9JKEm+8+3hgePvRFuE1KjOo/wkx1TxTGT7xolb1RzJGbDcgC/hnulPV7ojQPKOPDyVuXD3/hhDgciE5rtmR5C7JdFeRqAWulBwf99BEPt2XBsyKNkYCcBhfiTV20Fp6evrh3baUSkKDKGO5hdeMFXmeq+DHH6GEXW6lwNtNnXp7gIo0uOo9Lc44rWMnk9wRyvIFQspVPkr2k+zqzg89nGJeB48widyIM0RuSc5Pp5fSyg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lo/u7/a79FvguutA4atTzr56zrEgpx2WlTP+qEgzH8SCGZ4vT4bcwLMC5o65auVPbYASP6z8WoJXj5CNC6yf5sFwNwFNJzqycux9nwVIAMIwQZQ+t/Txnm1bwa0GwBrxS5OsdeKn4klHS/6PMe78pyXQ3JFO2QmM6sLk3AlLeB3RIAuHvqGczwOLCCzS5FvrEBGZPmGWoyXxvxSjXtep/eghitY5h7EtkvQ9eYo9wM0Lj25jqmBfhbiyybK6JkyrbGdUfPUbhcA5+2PdiC0KMGxLRnhRBYpGoTHxpcJR80cXPitLX+nuRXXNg9+hcqkVbtFd70szbAw+Vx2QxV8xbw==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
- Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>, Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Tue, 21 Nov 2023 08:22:02 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 20.11.2023 23:49, Andrew Cooper wrote:
> Constify both cmdline variables in create_dom0() and __start_xen().
> Initialise Xen's variable to the empty string to simplify the parsing logic.
>
> Update cmdline_cook() to take and return const pointers, changing it to have
> an early exit for a NULL input (which can happen if the mbi-> pointers happen
> to be 0).
>
> Note this only compiles because strstr() launders the const off the pointer
> when assigning to the mutable kextra, but that logic only mutates the
> mbi->cmdline buffer.
And a good static analyzer would spot this. At the very least I think this
warrants a comment next to that code. But really I'm inclined to re-write
this to eliminate the issue altogether; I'll try to remember to do so once
your change has gone in.
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -837,9 +837,10 @@ static bool __init loader_is_grub2(const char
> *loader_name)
> return (p != NULL) && (p[5] != '0');
> }
>
> -static char * __init cmdline_cook(char *p, const char *loader_name)
> +static const char *__init cmdline_cook(const char *p, const char
> *loader_name)
> {
> - p = p ? : "";
> + if ( !p )
> + return "";
This change is now needed only for create_dom0(), whereas the call site
change to __start_xen() is redundant with the change here. Did you
consider doing a similar transformation in create_dom0(), thus
eliminating the need for this check altogether? Alternatively I'd like
to ask that ...
> @@ -885,7 +886,7 @@ static struct domain *__init create_dom0(const module_t
> *image,
> },
> };
> struct domain *d;
> - char *cmdline;
> + const char *cmdline;
> domid_t domid;
>
> if ( opt_dom0_pvh )
> @@ -971,8 +972,8 @@ static struct domain *__init create_dom0(const module_t
> *image,
> /* SAF-1-safe */
> void __init noreturn __start_xen(unsigned long mbi_p)
> {
> - const char *memmap_type = NULL, *loader;
> - char *cmdline, *kextra;
> + const char *memmap_type = NULL, *loader, *cmdline = "";
> + char *kextra;
> void *bsp_stack;
> struct cpu_info *info = get_cpu_info(), *bsp_info;
> unsigned int initrdidx, num_parked = 0;
> @@ -1027,9 +1028,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
> : "unknown";
>
> /* Parse the command-line options. */
> - cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ?
> - __va(mbi->cmdline) : NULL,
> - loader);
> + if ( mbi->flags & MBI_CMDLINE )
> + cmdline = cmdline_cook(__va(mbi->cmdline), loader);
> +
> if ( (kextra = strstr(cmdline, " -- ")) != NULL )
> {
> /*
... this last hunk be dropped, along with cmdline's initializer. No need
for extra code churn when not gaining us anything. (Also but not only
because the reformatting here is actually beneficial from a readability
pov imo, the variant with applying the same transformation to create_dom0()
would seem preferable to me.)
Jan
|