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

Re: [PATCH v2] xen/sched: validate RTDS putinfo period and budget


  • To: Oleksii Moisieiev <Oleksii_Moisieiev@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 25 Mar 2026 15:45:13 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=gc2QDuvsxN8t5/jIo64cdy98ZNZAYdRd08s7dNyjEXQ=; b=KLnwJ7dukECD6lsTWHvsWPU1Rdj0QARc6Dr8A6477ca6hekQskt+hlFe8+NPlhyktFX3l1dS41wWEFMoWsse8oF1Qfgba0HZfn6l5y3542GAjsuq09qwQ6KAM3rNPtKME3vvlE3RvS+DDcwZ2XFxSErGgwNZuDbb480FLDlIyTungbRrqjIkBLQ87GbKM3FEnIoHSBN36ySfQn4Ghk728ZWjIul2H/RwoJSupmEnpVWVC43oZankXKG3Ext6x9ZpO4xftgsKxbk1s9vXwd59BERbmMhK94Gmcr7KKA0pwpYvgWTiWYSjQMnwk0J8Uz+1icOamJZCSocRe/v6sHRX9w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yUttoXpksp6qJa6osLtVUTMnfGespKX7rnS9x3dzFWhiemaJZCcAq1NQyUzucT+d8uaitC4xSudX3f2jnvciQ6jE19NC7VEnd32DRh6FW93CLPyv88md8JHbe+t2mFfhZNnWr1TN+CPSo1o2kiYiCKj6J5OW4Cuk/cWRJROuElnlBUB4x3/ntL0wRehbMCj+xnOmla1Vz8aM+TZf9S8zKcJEC1DptZLNNFwdloqbVjKAtvvpHr9SWyxyuao2opTOzUJOL1mswFJ+PwDrLkeglYpZ1+GIzZuvVgtgLBagessXMJiJ2CsdSBGbpnLkSTJpJh8cQqMvQfjjRNeqTvmjtA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Meng Xu <mengxu@xxxxxxxxxxxxx>
  • Delivery-date: Wed, 25 Mar 2026 15:45:30 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 25/03/2026 3:24 pm, Oleksii Moisieiev wrote:
> The RTDS domain-wide XEN_DOMCTL_SCHEDOP_putinfo path only checks for
> zero values before applying period and budget to all vCPUs in the
> domain.
>
> This is weaker than the per-vCPU XEN_DOMCTL_SCHEDOP_putvcpuinfo path,
> which already rejects values below the minimum, above the maximum, and
> cases where budget exceeds period.
>
> Use the same validation rules for putinfo as for putvcpuinfo, so
> invalid domain-wide updates are rejected with -EINVAL instead of being
> applied inconsistently.
>
> Signed-off-by: Oleksii Moisieiev <oleksii_moisieiev@xxxxxxxx>
> ---
>
> Changes in v2:
> - introduce rt_validate_params helper function to check period and budget
>
>  xen/common/sched/rt.c | 37 ++++++++++++++++++++++++-------------
>  1 file changed, 24 insertions(+), 13 deletions(-)
>
> diff --git a/xen/common/sched/rt.c b/xen/common/sched/rt.c
> index 7b1f64a779..645b091de7 100644
> --- a/xen/common/sched/rt.c
> +++ b/xen/common/sched/rt.c
> @@ -1362,6 +1362,20 @@ out:
>      unit_schedule_unlock_irq(lock, unit);
>  }
>  
> +static int
> +rt_validate_params(uint32_t period_us, uint32_t budget_us,
> +                   s_time_t *period, s_time_t *budget)
> +{
> +    *period = MICROSECS(period_us);
> +    *budget = MICROSECS(budget_us);
> +
> +    if ( *period > RTDS_MAX_PERIOD || *budget < RTDS_MIN_BUDGET ||
> +         *budget > *period || *period < RTDS_MIN_PERIOD )
> +        return -EINVAL;
> +
> +    return 0;
> +}

Code written like this is horrible; both to read, and in terms of
generated code.  Because of potential aliasing, that's 7 distinct memory
accesses because the values cannot be cached in registers.

You'll get far better code generation by writing it more like:

{
    s_time_t p = MICROSECS(period_us);
    s_time_t b = MICROSECS(budget_us);

    if ( p > RTDS_MAX_PERIOD || ... )
        return -EINVAL;

    *period = p;
    *budget = b;

    return 0;
}

See https://godbolt.org/z/W63TY8qTW

But it would also be better still if you passed op->u.rtds into this
function rather than {period,budget}_us separately.

~Andrew



 


Rackspace

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