All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Juergen Gross <JGross@suse.com>,
	sstabellini@kernel.org, andrew.cooper3@citrix.com,
	cardoe@cardoe.com, pgnet.dev@gmail.com, ning.sun@intel.com,
	david.vrabel@citrix.com, xen-devel@lists.xenproject.org,
	qiaowei.ren@intel.com, gang.wei@intel.com, fu.wei@linaro.org
Subject: Re: [PATCH v5 14/16] x86/boot: implement early command line parser in C
Date: Thu, 25 Aug 2016 07:27:21 -0600	[thread overview]
Message-ID: <57BF0E59020000780010903D@prv-mh.provo.novell.com> (raw)
In-Reply-To: <1471646606-28519-15-git-send-email-daniel.kiper@oracle.com>

>>> On 20.08.16 at 00:43, <daniel.kiper@oracle.com> wrote:
> +#define NULL	((void *)0)
> +
> +#define __packed	__attribute__((__packed__))
> +#define __stdcall	__attribute__((__stdcall__))
> +
> +#define max(x,y) ({ \
> +        const typeof(x) _x = (x);       \
> +        const typeof(y) _y = (y);       \
> +        (void) (&_x == &_y);            \
> +        _x > _y ? _x : _y; })

Now that you add a second instance of (some of) these, please
move them to a new (local to this directory) header, e.g. defs.h.

> +#define tolower(c) ((c) | 0x20)
> +
> +typedef unsigned char bool_t;

_Bool and bool please and ...

> +typedef unsigned char u8;
> +typedef unsigned short u16;
> +typedef unsigned int size_t;
> +
> +#define FALSE		0
> +#define TRUE		1

... these replaced by true and false. In fact I see no reason why
you couldn't include xen/stdbool.h here now that it can be more
generally used.

> +/*
> + * Space and TAB are obvious delimiters. However, I am
> + * adding "\n" and "\r" here too. Just in case when
> + * crazy bootloader/user puts them somewhere.
> + */
> +static const char delim_chars_comma[] = ", \n\r\t";
> +static const char delim_chars[] = " \n\r\t";

I realize it's minor, but why two arrays instead of

#define delim_chars (delim_chars_comma + 1)

?

> +/*
> + * static const char *delim_chars = &delim_chars_comma[1];
> + *
> + * Older compilers, e.g. gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21),
> + * put &delim_chars_comma[1] directly into *delim_chars. This means that the address
> + * in *delim_chars is not properly updated during runtime. Newer compilers are much
> + * smarter and build fully relocatable code even if above shown construct is used.
> + * However, define delim_chars[] separately to properly build Xen code on
> + * older systems.
> + */

I have to admit that I don't really understand what you want to
say with this comment.

> +static unsigned int strtoui(const char *s, const char *stop, const char **next)
> +{
> +    char l;
> +    unsigned int base = 10, ores = 0, res = 0;
> +
> +    if ( *s == '0' )
> +      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
> +
> +    for ( ; *s != '\0'; ++s )
> +    {
> +        if ( stop && strchr(stop, *s) )
> +            goto out;
> +
> +        if ( *s < '0' || (*s > '7' && base == 8) )
> +        {
> +            res = UINT_MAX;
> +            goto out;
> +        }
> +
> +        l = tolower(*s);
> +
> +        if ( *s > '9' && (base != 16 || l < 'a' || l > 'f') )
> +        {
> +            res = UINT_MAX;
> +            goto out;
> +        }
> +
> +        res *= base;
> +        res += (l >= 'a') ? (l - 'a' + 10) : (*s - '0');
> +
> +        if ( ores > res )
> +        {
> +            res = UINT_MAX;
> +            goto out;
> +        }

Without having spent time to try and find an example, it feels like this
check won't catch all possible overflow conditions. If you care about
overflow, please make sure you catch all cases.

> --- a/xen/arch/x86/boot/trampoline.S
> +++ b/xen/arch/x86/boot/trampoline.S
> @@ -220,8 +220,20 @@ trampoline_boot_cpu_entry:
>          /* Jump to the common bootstrap entry point. */
>          jmp     trampoline_protmode_entry
>  
> +#include "video.h"
> +
> +/* Keep in sync with cmdline.c:early_boot_opts_t type! */
> +early_boot_opts:
>  skip_realmode:
>          .byte   0
> +opt_edd:
> +        .byte   0                               /* edd=on/off/skipmbr */
> +opt_edid:
> +        .byte   0                               /* EDID parsing option (force/no/default). */
> +GLOBAL(boot_vid_mode)
> +        .word   VIDEO_80x25                     /* If we don't run at all, assume basic video mode 3 at 80x25. */
> +vesa_size:
> +        .word   0,0,0                           /* width x depth x height */

While I don't mind you using the packed attribute on the C variant,
please insert a padding byte here and there to make the four words
aligned, and add an alignment directive to make the whole structure
at least word aligned.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-08-25 13:27 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19 22:43 [PATCH v5 00/16] x86: multiboot2 protocol support Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 01/16] x86: allow EFI reboot method neither on EFI platforms Daniel Kiper
2016-08-25 11:19   ` Jan Beulich
2016-08-19 22:43 ` [PATCH v5 02/16] x86/boot: remove multiboot1_header_end from symbol table Daniel Kiper
2016-08-25 11:21   ` Jan Beulich
2016-08-30 14:27     ` Daniel Kiper
2016-08-30 15:11       ` Jan Beulich
2016-08-19 22:43 ` [PATCH v5 03/16] x86/boot: create *.lnk files with linker script Daniel Kiper
2016-08-25 11:28   ` Jan Beulich
2016-08-19 22:43 ` [PATCH v5 04/16] x86/boot/reloc: reduce assembly usage as much as possible Daniel Kiper
2016-08-25 11:29   ` Jan Beulich
2016-08-19 22:43 ` [PATCH v5 05/16] x86/boot: call reloc() using stdcall calling convention Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 06/16] x86/boot/reloc: create generic alloc and copy functions Daniel Kiper
2016-08-25 11:34   ` Jan Beulich
2016-08-30 14:32     ` Daniel Kiper
2016-08-30 15:12       ` Jan Beulich
2016-08-31 15:13         ` Daniel Kiper
2016-08-31 15:25           ` Jan Beulich
2016-08-31 19:39             ` Daniel Kiper
2016-09-01  7:35               ` Jan Beulich
2016-09-06 15:33       ` Doug Goldstein
2016-08-19 22:43 ` [PATCH v5 07/16] x86/boot: use %ecx instead of %eax Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 08/16] x86/boot/reloc: rename some variables and rearrange code a bit Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 09/16] x86: add multiboot2 protocol support Daniel Kiper
2016-08-25 11:50   ` Jan Beulich
2016-08-30 14:41     ` Daniel Kiper
2016-08-30 15:14       ` Jan Beulich
2016-08-31 15:21         ` Daniel Kiper
2016-08-31 20:18   ` Andrew Cooper
2016-08-31 21:01     ` Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 10/16] efi: create efi_enabled() Daniel Kiper
2016-08-25 12:16   ` Jan Beulich
2016-08-30 17:19     ` Daniel Kiper
2016-08-31 12:31       ` Jan Beulich
2016-08-19 22:43 ` [PATCH v5 11/16] efi: build xen.gz with EFI code Daniel Kiper
2016-08-25 12:23   ` Jan Beulich
2016-08-19 22:43 ` [PATCH v5 12/16] x86/efi: create new early memory allocator Daniel Kiper
2016-09-05 12:33   ` Jan Beulich
2016-09-07 12:05     ` Daniel Kiper
2016-09-07 14:01       ` Jan Beulich
2016-09-08  8:29         ` Daniel Kiper
2016-09-08  9:59           ` Jan Beulich
2016-08-19 22:43 ` [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms Daniel Kiper
2016-08-25 12:59   ` Jan Beulich
2016-08-30 19:32     ` Daniel Kiper
2016-08-31 12:49       ` Jan Beulich
2016-08-31 17:07         ` Daniel Kiper
2016-09-01  7:40           ` Jan Beulich
2016-09-01 20:37             ` Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 14/16] x86/boot: implement early command line parser in C Daniel Kiper
2016-08-25 13:27   ` Jan Beulich [this message]
2016-08-30 19:58     ` Daniel Kiper
2016-08-31 13:01       ` Jan Beulich
2016-08-31 19:31         ` Daniel Kiper
2016-09-01  7:41           ` Jan Beulich
2016-09-01 20:43             ` Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 15/16] x86: make Xen early boot code relocatable Daniel Kiper
2016-08-25 14:41   ` Jan Beulich
2016-08-31 14:59     ` Daniel Kiper
2016-08-31 15:46       ` Jan Beulich
2016-08-31 20:50         ` Daniel Kiper
2016-09-01  7:46           ` Jan Beulich
2016-09-01 21:19             ` Daniel Kiper
2016-09-02  6:58               ` Jan Beulich
2016-09-02  7:28                 ` Daniel Kiper
2016-08-19 22:43 ` [PATCH v5 16/16] x86: add multiboot2 protocol support for relocatable images Daniel Kiper
2016-08-22 10:10 ` [PATCH v5 00/16] x86: multiboot2 protocol support Jan Beulich
2016-08-30 14:15   ` Daniel Kiper
2016-08-30 15:09     ` Jan Beulich
2016-08-31 15:05       ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57BF0E59020000780010903D@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=JGross@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=cardoe@cardoe.com \
    --cc=daniel.kiper@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=fu.wei@linaro.org \
    --cc=gang.wei@intel.com \
    --cc=ning.sun@intel.com \
    --cc=pgnet.dev@gmail.com \
    --cc=qiaowei.ren@intel.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.