[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3] xen/console: Skip switching serial input to non existing domains


  • To: Michal Orzel <michal.orzel@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 20 Mar 2023 12:17:20 +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=WfpVXQ7J7Iuww+RURjNQiLuCfLLcPTUb9JN3Lnu6elk=; b=KMLlo4l8pU5r22fckN9xE0OCfrpe07EA9DkhaV9pCvitVJgOqrISRGa1U+kiHk5S20lBEVMvfKB7EvNRZcnosOBkm79CfSit6ULPKJSQx0ZgXTIST85ylH+NZFCfe5MLvxsZR3leAADLtH7FoFljo99cvvTzoOqmgxvIfcrF+Ih1xDwS/Tw9Nt6EkVikuDMSXu8545Pe6bKRhHZVA1PYMAAGHh7PqQhMz4ODilTg1Zr6/xH72Ap6dbSqaMRa29U+FCBfN/3c4SXeX20nefp3sqHaKuiTx0Y/E8nVcbgPjWJ4ikWLov6iA13Hr07UB9ubSpoiElPtm773e6fbEYbwmQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lTN17KCBGDTxYqi1XAaFfmGkOHgfOhgrj4h+xQ0HsEVzptNr8/CuOI7/zaj+YW0IQXt+tazhxP7oKwa31Rtl9fUz7xJ0KICUIhzaPuP7S/Vdc7/he+CmqVfuz6WovV4RaUvdv03YKz2GtjZimwWceNnJz1yaxJxnH5i5HC/sWwTLOAzuoPe0uj/qiFDA9J91poDZ5xkoM83fj/n7k+nNR1bcb9k2QdGkV14eQ4UX8mBMtoj9H07BR+rYvNYl0CEz5JTXN0fq0yOHi46hKHlaEX29OvoZ+m9LcjJRgqsWYEciT8vqyTCkwhECU9eiDOoTvf3unTfSCkwtocmY1hqTXA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 20 Mar 2023 11:17:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 20.03.2023 09:19, Michal Orzel wrote:
> @@ -483,15 +485,34 @@ struct domain *console_input_domain(void)
>  
>  static void switch_serial_input(void)
>  {
> -    if ( console_rx == max_init_domid + 1 )
> -    {
> -        console_rx = 0;
> -        printk("*** Serial input to Xen");
> -    }
> -    else
> +    unsigned int next_rx = console_rx + 1;
> +
> +    /*
> +     * Rotate among Xen, dom0 and boot-time created domUs while skipping
> +     * switching serial input to non existing domains.
> +     */
> +    while ( next_rx <= max_console_rx + 1 )
>      {
> -        console_rx++;
> -        printk("*** Serial input to DOM%d", console_rx - 1);
> +        if ( next_rx == max_console_rx + 1 )

Part of the earlier problems stemmed from the comparison being == here.
Could I talk you into using >= instead?

> +        {
> +            console_rx = 0;
> +            printk("*** Serial input to Xen");
> +            break;
> +        }
> +        else

No need for "else" after "break" (or alike). Omitting it will not only
decrease indentation, but also make more visible that the earlier if()
won't "fall through".

> +        {
> +            struct domain *d = rcu_lock_domain_by_id(next_rx - 1);
> +
> +            if ( d )
> +            {
> +                rcu_unlock_domain(d);
> +                console_rx = next_rx;
> +                printk("*** Serial input to DOM%d", console_rx - 1);

While I expect the compiler will transform this to using "next_rx"
here anyway, I think it would be nice if it was written like this
right away.

Since you touch the printk() anyway, please also switch to using the
more applicable %u.

With the adjustments
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

One other transformation for you to consider is to switch to a base
layout like

    unsigned int next_rx = console_rx;
    while ( next_rx++ <= max_console_rx )
    {
        ...
    }

i.e. without a separate increment at the bottom of the loop. Which,
now that I've spelled it out, raises the question of why the outer
loop needs a condition in the first place (because as written above
it clearly is always true). So perhaps better (and more directly
showing what's going on)

    unsigned int next_rx = console_rx;
    for ( ; ; )
    {
        if ( next_rx++ >= max_console_rx )
        ...
    }

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.