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

Re: [PATCH for-4.19] xen/arm64: domctl: Avoid unreachable code in subarch_do_domctl()


  • To: Julien Grall <julien@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Tue, 24 Oct 2023 13:33:20 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.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=8ofgUXmJITgTD8V9BfccIS4sLkKCoGSkXsXvcQDcOxQ=; b=PQbzMItavEW9OZsSfMA0AqOgXnPFrDyGGsJvo2JA+2pE8vhDrPWiNIvc/RvaJA/NwOXx2TMKT34q0LMA3/yQBOCguCCqDdosu0F4Se58HFytXFBHcF+D0Bpyx8IfRWacFTX39mbnQoYsYseRhagarg+rehPyKt9svQ8o5U08cU8r9l/eMTRKYNkJfJwI0rwqcrg7UeygpJo4CrIBSzKiDnA7U7IribUBqwYqaDE/8w9lYFHnxpQAkPx1MwSoENh1g8djqeeP2ZvZ4c5AAxdKBklvZyldUMsZBkkbDURdvup8pAre4ZYVS7kjWDILCiVM9Ndxyjz+Wz6Ddp0MlkGLSQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VBd7+z82uM+9ATzwJAb7sZ2Z6Fe++pQ19od6Hlh0692XKcKDXBXEi+LRn/1ogxxncMLdBie2y+F0LwFR0KNcleagupExf1FBl2nAfKhohH/kGMa4PC3+fzCfU3OGro1yQXxFLN47qm+4EVtk9Z4U0ZdwldSGoZwdea6uvTAsLeo+k/ZM5orZR/6r/uq5A+3rLSa+5xRGT+iyEZehjEa2cm8f9i3a4g945wGVdDgZwq5jsDiHDdesxZ1lBkOkF0Qk6MBjx1KPDh/Ea0BdYjdsNIhELBdR6uaSSJ+8ILNq4CNhcONCuwVXTnSqmod2H/AVg7cYVjDBfwahLo2DiZpulQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Julien Grall <jgrall@xxxxxxxxxx>, Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • Delivery-date: Tue, 24 Oct 2023 13:33:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHaBdnC4y/97Q3UX0qYJDw3uJ9yWrBY8Y4A
  • Thread-topic: [PATCH for-4.19] xen/arm64: domctl: Avoid unreachable code in subarch_do_domctl()

Hi Julien,

> On 23 Oct 2023, at 19:52, Julien Grall <julien@xxxxxxx> wrote:
> 
> From: Julien Grall <jgrall@xxxxxxxxxx>
> 
> The 'break' the XEN_DOMCTL_set_address_size is unreachable and tools
> like Eclair will report as a violation of Misra Rule 2.1.
> 
> Furthermore, the nested switch is not very easy to read. So move
> out the nested switch in a separate function to improve the
> readability and hopefully address the MISRA violation.
> 
> Reported-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
> Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>

Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>

Cheers
Bertrand

> 
> ---
> 
> Only compiled tested. Waiting for the CI to confirm there is no
> regression.
> ---
> xen/arch/arm/arm64/domctl.c | 34 +++++++++++++++++++---------------
> 1 file changed, 19 insertions(+), 15 deletions(-)
> 
> diff --git a/xen/arch/arm/arm64/domctl.c b/xen/arch/arm/arm64/domctl.c
> index 14fc622e9956..8720d126c97d 100644
> --- a/xen/arch/arm/arm64/domctl.c
> +++ b/xen/arch/arm/arm64/domctl.c
> @@ -33,27 +33,31 @@ static long switch_mode(struct domain *d, enum 
> domain_type type)
>     return 0;
> }
> 
> +static long set_address_size(struct domain *d, uint32_t address_size)
> +{
> +    switch ( address_size )
> +    {
> +    case 32:
> +        if ( !cpu_has_el1_32 )
> +            return -EINVAL;
> +        /* SVE is not supported for 32 bit domain */
> +        if ( is_sve_domain(d) )
> +            return -EINVAL;
> +        return switch_mode(d, DOMAIN_32BIT);
> +    case 64:
> +        return switch_mode(d, DOMAIN_64BIT);
> +    default:
> +        return -EINVAL;
> +    }
> +}
> +
> long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
>                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
> {
>     switch ( domctl->cmd )
>     {
>     case XEN_DOMCTL_set_address_size:
> -        switch ( domctl->u.address_size.size )
> -        {
> -        case 32:
> -            if ( !cpu_has_el1_32 )
> -                return -EINVAL;
> -            /* SVE is not supported for 32 bit domain */
> -            if ( is_sve_domain(d) )
> -                return -EINVAL;
> -            return switch_mode(d, DOMAIN_32BIT);
> -        case 64:
> -            return switch_mode(d, DOMAIN_64BIT);
> -        default:
> -            return -EINVAL;
> -        }
> -        break;
> +        return set_address_size(d, domctl->u.address_size.size);
> 
>     default:
>         return -ENOSYS;
> -- 
> 2.40.1
> 
> 




 


Rackspace

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