lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAhV-H6htTqd3nHymcEpj2DDdeXU00OwtPJfYNpiSA7ac5JV7w@mail.gmail.com>
Date: Wed, 14 Feb 2024 21:06:06 +0800
From: Huacai Chen <chenhuacai@...nel.org>
To: WANG Xuerui <kernel@...0n.name>
Cc: Paolo Bonzini <pbonzini@...hat.com>, Tianrui Zhao <zhaotianrui@...ngson.cn>, 
	Bibo Mao <maobibo@...ngson.cn>, kvm@...r.kernel.org, loongarch@...ts.linux.dev, 
	linux-kernel@...r.kernel.org, WANG Xuerui <git@...0n.name>
Subject: Re: [PATCH for-6.8 4/5] KVM: LoongArch: Streamline control flow of kvm_check_cpucfg

Hi, Xuerui,

On Wed, Feb 14, 2024 at 6:16 PM WANG Xuerui <kernel@...0n.name> wrote:
>
> From: WANG Xuerui <git@...0n.name>
>
> All the checks currently done in kvm_check_cpucfg can be realized with
> early returns, so just do that to avoid extra cognitive burden related
> to the return value handling.
>
> The default branch is unreachable because of the earlier validation by
> _kvm_get_cpucfg_mask, so mark it as such too to make things clearer.
>
> Signed-off-by: WANG Xuerui <git@...0n.name>
> ---
>  arch/loongarch/kvm/vcpu.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
> index e973500611b4..9e108ffaba30 100644
> --- a/arch/loongarch/kvm/vcpu.c
> +++ b/arch/loongarch/kvm/vcpu.c
> @@ -339,24 +339,23 @@ static int kvm_check_cpucfg(int id, u64 val)
>                 /* CPUCFG2 features checking */
>                 if (val & ~mask)
>                         /* The unsupported features should not be set */
> -                       ret = -EINVAL;
> -               else if (!(val & CPUCFG2_LLFTP))
> +                       return -EINVAL;
> +               if (!(val & CPUCFG2_LLFTP))
>                         /* The LLFTP must be set, as guest must has a constant timer */
> -                       ret = -EINVAL;
> -               else if ((val & CPUCFG2_FP) && (!(val & CPUCFG2_FPSP) || !(val & CPUCFG2_FPDP)))
> +                       return -EINVAL;
> +               if ((val & CPUCFG2_FP) && (!(val & CPUCFG2_FPSP) || !(val & CPUCFG2_FPDP)))
>                         /* Single and double float point must both be set when enable FP */
> -                       ret = -EINVAL;
> -               else if ((val & CPUCFG2_LSX) && !(val & CPUCFG2_FP))
> +                       return -EINVAL;
> +               if ((val & CPUCFG2_LSX) && !(val & CPUCFG2_FP))
>                         /* FP should be set when enable LSX */
> -                       ret = -EINVAL;
> -               else if ((val & CPUCFG2_LASX) && !(val & CPUCFG2_LSX))
> +                       return -EINVAL;
> +               if ((val & CPUCFG2_LASX) && !(val & CPUCFG2_LSX))
>                         /* LSX, FP should be set when enable LASX, and FP has been checked before. */
> -                       ret = -EINVAL;
> -               break;
> +                       return -EINVAL;
> +               return 0;
>         default:
> -               break;
> +               unreachable();
Maybe BUG() is better than unreachable()?

Huacai
>         }
> -       return ret;
>  }
>
>  static int kvm_get_one_reg(struct kvm_vcpu *vcpu,
> --
> 2.43.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ