From patchwork Wed Feb 14 16:33:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Xuerui X-Patchwork-Id: 201033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1341345dyb; Wed, 14 Feb 2024 08:39:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW5BLix9ZGg+b+OV5qXsjX++l95GMGBlvg8N9N2WohAiXSvhunL4aeiyMdKpoSJk5e5h3iNimcgruVgPnX+vrWYwcl9VQ== X-Google-Smtp-Source: AGHT+IEMG+TlXJz6NfAE7/RNU1yx4lkTuUvDwLxu5nWUJ8C0BX70hXtFmWogR5qGhfOpT7dXl7q4 X-Received: by 2002:a05:6a00:1803:b0:6e1:738:93cf with SMTP id y3-20020a056a00180300b006e1073893cfmr3541160pfa.30.1707928770972; Wed, 14 Feb 2024 08:39:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707928770; cv=pass; d=google.com; s=arc-20160816; b=MjOUPUFm5nBKNol0fi7C0zTtXwpVwL9hAA1RE8x6ByaAepTY9L6X2b5Ur+gGiEKvbj q+5aH17gM768SpABLcq9i392zkxo15bx9OHbYvKnSotI8dMeFqb4J7DZvhFhqm8kR91n JoddRf4myybj2Vh7PJRtqpIZkMqAm7384i2D7MkPHzpQ9N572qrYLIeb/RH0FReAyemf Xs7jLZkJ/oaqugWnDpyvMXkGIM5ChnrXN7xf1e3pKNImJ0H/Dzt0uDtodk7fXYeEBtnY 8N1SpcqX7kH+VtQlxzzMhl1pIGor31mioen4PW7dXkODI/oBLvxKhu4GjTvo3CA/BcXP HzDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bfiqB3+pwN35nisRVs+YFHtHnge1kJcbRHJbqJ+9U+o=; fh=03WhE3iote43Jd5DBTjR9a63oT4B0TrVt7RO7A7KOOA=; b=lxs02Jkwj03HO21vbaBhyaRGcKXe0yDq4pMasynzFp3VKgjnbwvJI9tPAz2nGXm0yj /oJ7rBTKRdKMIcILijY6OAFrs8LVU4kfC3tiJHVe3UJdMWidGA34wNjsxTj9kOjSk+l2 QQqxP+4sJhEPxq/6wuEkBwSWTKs1b3CntpMNFbHZRXMKZ8v78Q1ujDpMgDrmnCp8LI04 KnQkfiV5eWGeEG9U56QfHOaFzZkP24Ajn8rQZxF99wUWNFHqZEZW3aaxTVxO5beZDo5G r9fLe5twF3hwnDfY0b8zw/OytPh5H4gggAnQtNeRACN7TPezS0X0SbKibdXtg6VTIo2y gMcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=ZNU0AkXX; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXDL3ytJK1uFb0JD51s15nFYS5ZElQS1UHhmaOFOeixI9amQXk63cE2fXshG/3XeQRpb7iHptljLsTlioeOyFQqTDzdBA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 126-20020a630084000000b005dc48e561adsi3798741pga.20.2024.02.14.08.39.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:39:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=ZNU0AkXX; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 86A96281891 for ; Wed, 14 Feb 2024 16:37:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C2DC65198; Wed, 14 Feb 2024 16:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="ZNU0AkXX" Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1735E5FF16; Wed, 14 Feb 2024 16:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.28.160.31 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; cv=none; b=q1EwQBKVY6r96i/t+W7IY4pUAQ0+UhauC2/73kdOrT8bfztsLGyT2yCdLe6iEXpj+hbKgi3LHY/P+ByIYzuPlnazlbnCLUI3txPbKzEfAA9jKdMjfbrCjZETUuBDSuRGwgpNqt0KMwhZBoEKn1cq7SSvXFye6uzQSl5M2YDFVyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; c=relaxed/simple; bh=qUTm7/R3ovfw0MXxK4QrZKdILlZUuBNM9kI6bR5Fxzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZSUWscURgajYnaoqIkekL4T6/dNX4eVpgmSPJymoGU3jyWsTLydIx2JJnpDaI7Kz7uyiJob3p/OX2iX8z9SNhN3qh7X71hRZKhTJHyIETeUsyeCJmZxhDA1ebOHkAJdEpRaXHV6q1ZhFKSm6oelQgmg3IUYTDF+EtHUP3T8Cw5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name; spf=pass smtp.mailfrom=xen0n.name; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b=ZNU0AkXX; arc=none smtp.client-ip=115.28.160.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1707928441; bh=qUTm7/R3ovfw0MXxK4QrZKdILlZUuBNM9kI6bR5Fxzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNU0AkXX04CwM3rMQCCubKT7skrrj0VQW66Is5+V1MQyNxnY5LDUUe1L4voIFJ1vH NoEbvYoF9cKwr6ofnBvYlg2hkbMBUnEsHOxaDuSohruYvUH45ZJarDyHMElfK6rli4 yTIfRvmdTBaROi9uTRmpVLZnSkX14DLrLQfnty54= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:42e8:c06f:a0dc:12f8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 90E38601A7; Thu, 15 Feb 2024 00:34:01 +0800 (CST) From: WANG Xuerui To: Paolo Bonzini , Huacai Chen Cc: Tianrui Zhao , Bibo Mao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Subject: [PATCH for-6.8 v2 1/4] KVM: LoongArch: Fix input value checking of _kvm_get_cpucfg Date: Thu, 15 Feb 2024 00:33:54 +0800 Message-ID: <20240214163358.2913090-2-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214163358.2913090-1-kernel@xen0n.name> References: <20240214163358.2913090-1-kernel@xen0n.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893118622261659 X-GMAIL-MSGID: 1790893118622261659 From: WANG Xuerui The range check for the CPUCFG ID is wrong (should have been a || instead of &&), and pointless, because the default case a few lines below already serves to deny all unhandled cases. Furthermore, the juggling of the temp return value is unnecessary, because it is semantically equivalent and more readable to just return at every switch case's end. This is done too to avoid potential bugs in the future related to the unwanted complexity. Fixes: db1ecca22edf ("LoongArch: KVM: Add LSX (128bit SIMD) support") Signed-off-by: WANG Xuerui --- arch/loongarch/kvm/vcpu.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index 27701991886d..c4a592623da6 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -300,11 +300,6 @@ static int _kvm_setcsr(struct kvm_vcpu *vcpu, unsigned int id, u64 val) static int _kvm_get_cpucfg(int id, u64 *v) { - int ret = 0; - - if (id < 0 && id >= KVM_MAX_CPUCFG_REGS) - return -EINVAL; - switch (id) { case 2: /* Return CPUCFG2 features which have been supported by KVM */ @@ -324,12 +319,10 @@ static int _kvm_get_cpucfg(int id, u64 *v) if (cpu_has_lasx) *v |= CPUCFG2_LASX; - break; + return 0; default: - ret = -EINVAL; - break; + return -EINVAL; } - return ret; } static int kvm_check_cpucfg(int id, u64 val) From patchwork Wed Feb 14 16:33:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Xuerui X-Patchwork-Id: 201032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1340100dyb; Wed, 14 Feb 2024 08:37:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUUA1TV3nCPaP4Z+9u2Eh46urgi+bbf54Bp3xoaTSEmvDF+vEIM0QDChqKtvoT0zG5loM4NMBxY1e/JfmdK+NestVr3uA== X-Google-Smtp-Source: AGHT+IFbjnTXTO75JwR2yWJRaUuaukZ2xx+qX0Bzsf+Bw1uohn5izkGwgziZ/4nLqQJW/kRMPi3Q X-Received: by 2002:a05:6870:8a2c:b0:21a:c3c0:40c7 with SMTP id p44-20020a0568708a2c00b0021ac3c040c7mr3170593oaq.48.1707928650971; Wed, 14 Feb 2024 08:37:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707928650; cv=pass; d=google.com; s=arc-20160816; b=KP3DNuSS7EixpVWu59iL2cuu8S5jVoZW6AhxmqHNw1QvXCo6laxLRqnr7OoksqJ7rp 3oPq3ezeImO3ApxpaT85RpHDhEgK+mEBm647QHCsuNkdk4hZqkaqPQ6d4B8WWDPuvOOY MLZ2r+PZu39azzy01VUos3xApLAjkFmH1wjgSZpSvLKOcNUCR4oaGgCTxCS/gpWW+IpH h1lUc/xwGCPXcTgDWpE+RAbTs5ka6ex9puJJ7XU1RoUybCqzPlH3fOnE/bq/zMGGNUFI KsZWhy0M5gOaOSZrYQ+2HCW0BB8MD+o2wEm4sr17Fd19QbgIv0gywrjX6jf7rTLQQWen 7CCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gjHliDjaeUpRoyF3DIVnTOoHY/LcPuUweXzNonR4Zs4=; fh=2Q+3T8QPYLG/fDTEFFQJXooe6iodK43hSFSvdBOG4Us=; b=qxTn1a1tNzfSYG2UcS0KtkYjMOi97jo9lBV4pcln0CDWB1S8TVFERJ4v1/bIWL0hIJ 7PzFQzyZ6qJ87Z4MlbyEo8g9gLM8dPbY3Rr3sO139AoW3JCGOHF0UAOslUwih+azSAse aoV5+YtijMV0dPjTwD5wm1fyGnooeVhgwSaCmNDVXWwBZw7wFbYyvCg0wGxhgamkIgMb XUlbOSB/mXCKyWbkwKHhLQ7YeZYGvsVjKm6Rzu2r7d0z17/WTF7uIbq9ffD2yJ2LIG1G A0ZAf1bMWK8Ay9LHX/2GH+0iXjqDcvyKWj7E+DaDT0IyqpfHlFbuqeuNcofVU5ld4Pw5 CT0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=rlNYvQ0G; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65554-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65554-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUPYzh+OZowaNghOvPOMJAETX6P/YsIsLfHnT38a283svu06gAZmYDfpMsd965d+QNX7AFhtBVj1bhitzOIHTZYWLaOiw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q30-20020ab054de000000b007d6d702a6d7si782018uaa.221.2024.02.14.08.37.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:37:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65554-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=rlNYvQ0G; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65554-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65554-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B4DAB1C20F7C for ; Wed, 14 Feb 2024 16:37:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C42FB6350F; Wed, 14 Feb 2024 16:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="rlNYvQ0G" Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F78060EE5; Wed, 14 Feb 2024 16:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.28.160.31 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; cv=none; b=pPhXplVwxQ/GWZ9bCZb8Lkk4OX1YuNts0I55DETSYmGUdyq1/eMbuaxJnxNJtYNX7sae2ydM+SwP7FmTDb1c0gRAzXgR3RK8fIDUtETPAADLk4RwYWhZMhs2C6NZcceCnFjDDgek/S/LSWEUdH7C2eBCUZWSjrPsl7xC4jr4pf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; c=relaxed/simple; bh=RLw0Ke+gAZcjvLomlJhUe4+W8YYZZSg0ARVq9aMVCrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RGpFaEAJPRQleEu4Z0hwdM8Ps1+neZckYmevN/T7TeWrZX3QikUbDRSYCueWdaAYWmq4hTJg8raN+BLEILO/+8f8cc+2+fgCl5259MtKdiixUxD85ySRkYxy8gop6KqK5LxfjE8Gmmlpbo6xKn+1BZkRL5Vzyo727oKHT42FowY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name; spf=pass smtp.mailfrom=xen0n.name; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b=rlNYvQ0G; arc=none smtp.client-ip=115.28.160.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1707928442; bh=RLw0Ke+gAZcjvLomlJhUe4+W8YYZZSg0ARVq9aMVCrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rlNYvQ0GW/S/jXNaAYENVYlNVf23pL9YeFrT0eWgiytcNZT60OP/wdnkHkTCCOif8 VWOOPEtMhrEVmGABPOn3H/AfPxUBKHwvhvVHkisAOM+jXlQx3QdZXAqSzKe3DF/xTr fmniFaUIbwsr6uNI8YNTQc8QnakMysFZIWzPOcQg= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:42e8:c06f:a0dc:12f8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 4A01D601C2; Thu, 15 Feb 2024 00:34:02 +0800 (CST) From: WANG Xuerui To: Paolo Bonzini , Huacai Chen Cc: Tianrui Zhao , Bibo Mao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Subject: [PATCH for-6.8 v2 2/4] KVM: LoongArch: Fix kvm_check_cpucfg incorrectly accepting bad CPUCFG IDs Date: Thu, 15 Feb 2024 00:33:55 +0800 Message-ID: <20240214163358.2913090-3-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214163358.2913090-1-kernel@xen0n.name> References: <20240214163358.2913090-1-kernel@xen0n.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790892993220995285 X-GMAIL-MSGID: 1790892993220995285 From: WANG Xuerui The return value of _kvm_get_cpucfg is meant to be checked, but this was not done, so bad CPUCFG IDs wrongly fall back to the default case and 0 is returned. Check the return value to fix the UAPI behavior. While at it, also remove the redundant range check, because _kvm_get_cpucfg already rejects all unrecognized input CPUCFG IDs. It was also wrong and no-op, in the same way as the former identical check in _kvm_get_cpucfg. Fixes: db1ecca22edf ("LoongArch: KVM: Add LSX (128bit SIMD) support") Signed-off-by: WANG Xuerui --- arch/loongarch/kvm/vcpu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index c4a592623da6..cc2332b056ba 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -328,12 +328,10 @@ static int _kvm_get_cpucfg(int id, u64 *v) static int kvm_check_cpucfg(int id, u64 val) { u64 mask; - int ret = 0; - - if (id < 0 && id >= KVM_MAX_CPUCFG_REGS) - return -EINVAL; + int ret; - if (_kvm_get_cpucfg(id, &mask)) + ret = _kvm_get_cpucfg(id, &mask); + if (ret) return ret; switch (id) { From patchwork Wed Feb 14 16:33:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Xuerui X-Patchwork-Id: 201034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1341508dyb; Wed, 14 Feb 2024 08:39:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXjMIq0tCnNWYMvVE9XmrU89W6VjuXDhxGfOGnAOMBdZgpQdubDkehbWjWW3xCC2M4iH28VvBMlo2eFmTb+0WiP8wB9yw== X-Google-Smtp-Source: AGHT+IHpqnLucrMohkM/PPnjpcERAgsxWwYfToFf4P/WQmhvrS+HjN0Bphu6rLVrLBrJgUskq7AQ X-Received: by 2002:a17:902:f705:b0:1db:5b41:c59a with SMTP id h5-20020a170902f70500b001db5b41c59amr3160400plo.45.1707928786570; Wed, 14 Feb 2024 08:39:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707928786; cv=pass; d=google.com; s=arc-20160816; b=vDoF5EFk6Uwv4KmxcD8qRsEgVU6XfCiYEg5+Psq+ONlrqxP8rsDY70DJXfoges/d5b vGSNN1U2nQUf0dcx9jSZT/2a9tMnUTvgicI1e7KPByFoTdejA/dZrjS9s4Sj5Yur2Os8 KIDnLAOkFZzEIK8jkve0xKlM7sxYJxbotymhgkqEyKxByW7E59Hwgdt8FCWIf7P+EXX8 E+iMJHU2wa1kRxSk+oEcQtT/noNfFPXzu1dS8NBEUqX8hon4oLmeFkE5phDsbK1Nr+kr 674jByx4HMDMGrIRMRu1AzoQRzD6pkoGrhyVmL34/8TWwopbrKiQT8iNSrlqRMFJclyw QwbA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Pyj7psfQ9omEicu4WWM5idDO2TxPx1IprjGbZwJCuzc=; fh=IXS/UOQx8T/HIAwo6kNMO66FUH3MGE2grpl8KqWyqbA=; b=Syagrn2PM0dboJ5UEhW8Qw0RX9yFU3RtJvxW8A/6bFzib5UXqHfCgcXcBBP/zdhqNG sbOG6GL9is/OnqS9QLj7L1HGz6KSC6AFv/wh14SxvdUqQ0uD/uLr+BgbJfpCOHX9LafC U/hYWQLuGnCIo6q2kGY0SCDUesBgJOd32W6yKnQd/Tc1HxjgUQOFuhTvB2fppVQAXmW0 wCwlVaKsSsBgNq55T68Ce478c8bkC4nW6iIWmb5Mu8HCrSigNKs4Q6s3EcvvGfxKOAeL 5FYIpsUXqrW0K7IplGtAtI8wela9l4KnQ8qw+dKEti6qLVDnsKmzMbT7IZbKtDF72bfn ywQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=naMmfsy+; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65557-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65557-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCV1tXrnxXxq9a2334ahxMe+z57W8fTk55I3jUUG1lsO9mL2Kv116mu1ZV98ligU2zet0sOaldl1D9CWM9tXmgF0ePCyDw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h2-20020a170902f54200b001d9ef3f39bbsi4075332plf.548.2024.02.14.08.39.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:39:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65557-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=naMmfsy+; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65557-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65557-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D2FA1284E15 for ; Wed, 14 Feb 2024 16:38:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8A7C65BCA; Wed, 14 Feb 2024 16:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="naMmfsy+" Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57C126166F; Wed, 14 Feb 2024 16:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.28.160.31 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928448; cv=none; b=ED2qFXpLXmtNmHpzKJQRHCglvrb7vplCFjWIJsxpOuDsOJZ2UQYqlCC8Ew1NYwsWsKGYumkFXuBCobyayDEEAWxt/pBmeR7jcuFKvlvFP7Qtro2z32wPSdRtQ5+M8nqLpakvQpJuTFxMSa7kneNMDBfXyXtApHYgkgSNmB3Jq8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928448; c=relaxed/simple; bh=VP6OWLTFU7Iwj95xAdgUR/i01Q0SJTbE9ZgKz6xmu84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fbT7imKRk50jMsLAbR8c3XFuaqzi5t7/M3ga/WpP7yY66Wfw6L84QYhuVwa15KxdCSULcvKSGfYGjca3fmLU4hxNUZL6c73OIOojQpcGOpfwdfkK8I7LiJgc3JgV/7j+nNOb3+70femSLTOQicVthEzpZgqM5rEvzPmM3vV0CH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name; spf=pass smtp.mailfrom=xen0n.name; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b=naMmfsy+; arc=none smtp.client-ip=115.28.160.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1707928443; bh=VP6OWLTFU7Iwj95xAdgUR/i01Q0SJTbE9ZgKz6xmu84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=naMmfsy+ntQ5Ahxt+D9gh8gQ4S3XLqAraQ3mSDPFsjwvXQyaXRn4eExZ2KSiUnnmX X55S4dnrrdhApVmlUj8J8GCA6AqWyTsSwo7T+9hT8doo57WHXTLjK+wCtf+AaZQ7Ry eCGBSKZ5vA4v3sNWgNOyyxQJ+Ei0nQebeaC0F4EM= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:42e8:c06f:a0dc:12f8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id EA013601C6; Thu, 15 Feb 2024 00:34:02 +0800 (CST) From: WANG Xuerui To: Paolo Bonzini , Huacai Chen Cc: Tianrui Zhao , Bibo Mao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Subject: [PATCH for-6.8 v2 3/4] KVM: LoongArch: Rename _kvm_get_cpucfg to _kvm_get_cpucfg_mask Date: Thu, 15 Feb 2024 00:33:56 +0800 Message-ID: <20240214163358.2913090-4-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214163358.2913090-1-kernel@xen0n.name> References: <20240214163358.2913090-1-kernel@xen0n.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893135270864739 X-GMAIL-MSGID: 1790893135270864739 From: WANG Xuerui The function is not actually a getter of guest CPUCFG, but rather validation of the input CPUCFG ID plus information about the supported bit flags of that CPUCFG leaf. So rename it to avoid confusion. Signed-off-by: WANG Xuerui --- arch/loongarch/kvm/vcpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index cc2332b056ba..e973500611b4 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -298,7 +298,7 @@ static int _kvm_setcsr(struct kvm_vcpu *vcpu, unsigned int id, u64 val) return ret; } -static int _kvm_get_cpucfg(int id, u64 *v) +static int _kvm_get_cpucfg_mask(int id, u64 *v) { switch (id) { case 2: @@ -330,7 +330,7 @@ static int kvm_check_cpucfg(int id, u64 val) u64 mask; int ret; - ret = _kvm_get_cpucfg(id, &mask); + ret = _kvm_get_cpucfg_mask(id, &mask); if (ret) return ret; @@ -557,7 +557,7 @@ static int kvm_loongarch_get_cpucfg_attr(struct kvm_vcpu *vcpu, uint64_t val; uint64_t __user *uaddr = (uint64_t __user *)attr->addr; - ret = _kvm_get_cpucfg(attr->attr, &val); + ret = _kvm_get_cpucfg_mask(attr->attr, &val); if (ret) return ret; From patchwork Wed Feb 14 16:33:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Xuerui X-Patchwork-Id: 201035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1341531dyb; Wed, 14 Feb 2024 08:39:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWV/8if93Em1y7x3o60ml5C8WLfwKQTECdpQ1wtc+VKSpE7kf3w1/64jlYJ32U9a3yhPjNxCrL1IFa2fcRx6jxs5PXdQw== X-Google-Smtp-Source: AGHT+IFbdR/sKjk/5EG2YMrbBFiYa0E2oCTlM6nije9NjM+5tKyWDevaOhLB8rUOjfntWunRCV9y X-Received: by 2002:a05:6358:7f1d:b0:176:6144:2f12 with SMTP id p29-20020a0563587f1d00b0017661442f12mr2811750rwn.28.1707928788353; Wed, 14 Feb 2024 08:39:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707928788; cv=pass; d=google.com; s=arc-20160816; b=ia6cWCNGE80NKujkEI7Rkv5yQ+OJ9g+echaxiSWic5oGjrLdtjoahkeJRJjLfCp+Tw laY8Ccquc2+jN9SQrJja0vUG7JFBAkJQ+T8zb9J3dsVo3XgBk/RqETJ3ZluNNag21hCW dfDFYC8zmLovV1xp65d/tRmV/Sxnp++DxAIUyZdCeH3cEgPE0lmVdu7i8CEIi3RjH2yx SJi86X//wtfu5REORwEYV4U6/weJ2b1iwYehP4CFG3uxygtPvNlqngSBANbEC3yc5a3X a6ZT4vUnDqfPTt8/02A7mJ8mEaPbehaPxnELdBXR2X/4cJwCsIZ97UfGzZ9in8vXTOji mj5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7p+zoSoyb2JbQQounRKmxa3wGQMdUKth5MXfwZxJvLE=; fh=PRoDNC/h9wDrbV++BrgrGfhcEDS7UAS2DZGzgVrW67o=; b=Xv+/Qo0i+N7VYhnstOlh8Hexz68GdZf8nFwScVhasJO4fbpDO9WhDUsMcAUsqp/9BE yp22J8T7diRXJY/iullstmgmnyx/0gF9JATGwekwPzDEgIU2KC/jQUTCjZbcoroTbzPr LilvT5x7dsIdAgl+06EyFc5PD8ncem3HdWQuBRQhV7gLiY1NsAI5wW3EvIRRCRIhlB5L E0/r5u4DdqsbByILoUryqIs8VhemHVztcgjPEiSjCj5aLwX13HCXuKSNSoWOoxKzQOYm 0o0bvfzYXNrEaHY0cIpxd+ke4Mut2Wy+Z0pgPw+6A2cRcsidjPy+cTqoL6BceoQw3/fP v5Gw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=Jnf8OFkq; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65558-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65558-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXcqQWZ0/WpiOYAWs7wNyFuqKHR1E+0f/T3CDv1aP3kurQzDjW6hjaNDzDnSmUnzBJwmqrez3JCcIqVHt4S9j7FwqZrMg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 126-20020a630084000000b005dc48e561adsi3798741pga.20.2024.02.14.08.39.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:39:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65558-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=Jnf8OFkq; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65558-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65558-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F1EC42852E0 for ; Wed, 14 Feb 2024 16:38:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF1FF65BD2; Wed, 14 Feb 2024 16:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="Jnf8OFkq" Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C35B762158; Wed, 14 Feb 2024 16:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.28.160.31 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928448; cv=none; b=nA0NK+qZi8gywYfOFCQtVQn7PgvIaUiXrw+h6KO42LX1AGPPlGbYvRDtHom+ZkCz6mQ44E/NGNd8hGEWTniZfCZ8qlkLSiRnimvHA1ma8gzUqgbxehwa59D5hZWwLdyxLSZdHTJYytNQxJu7iGWlHw14s6bhBsvGI4dpaHpBscU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928448; c=relaxed/simple; bh=PcrXxYoGFClCitVwkysGKdmr3Nu5wkP9upQVqRlzsuo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VJcQRd1OhZs5Do8xqTfYBw9qJoafwBv0bYGMkIuO1Zsnmp7ze+dNLMuiRD1xcWGv88fg4RQIe3HRI6wQWdxw3nXEwrg6A7jVrm/mk6Ff4NjGdYjmFy0r6PJjFZcZy1QCt4Vu5wE0YiMTYS8TwMGpniM2aYAN2Kx0h2vt9PBcmCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name; spf=pass smtp.mailfrom=xen0n.name; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b=Jnf8OFkq; arc=none smtp.client-ip=115.28.160.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1707928443; bh=PcrXxYoGFClCitVwkysGKdmr3Nu5wkP9upQVqRlzsuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jnf8OFkqtVlmQbPloTxNCJMJsQq5QNPAnVRqPabXSB43Whlxp1YmtdU/jbD4S+vkl HrAa37q3eBKxbJD2mOYrm7x3gELhFslp8k1/Mb6FI5uP7dUC5jAGRt4WnJ1Zu3JE05 sU06Y5IQ5LoRTkJoOE8X8heQBpWmokFLBM0m74xw= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:42e8:c06f:a0dc:12f8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 995CA60562; Thu, 15 Feb 2024 00:34:03 +0800 (CST) From: WANG Xuerui To: Paolo Bonzini , Huacai Chen Cc: Tianrui Zhao , Bibo Mao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Subject: [PATCH for-6.8 v2 4/4] KVM: LoongArch: Streamline kvm_check_cpucfg and improve comments Date: Thu, 15 Feb 2024 00:33:57 +0800 Message-ID: <20240214163358.2913090-5-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214163358.2913090-1-kernel@xen0n.name> References: <20240214163358.2913090-1-kernel@xen0n.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893137043905994 X-GMAIL-MSGID: 1790893137043905994 From: WANG Xuerui 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 should be unreachable because of the earlier validation by _kvm_get_cpucfg_mask, so we warn in case it is actually reached and return -EINVAL in that case too. While at it, clean up comments of _kvm_get_cpucfg_mask and kvm_check_cpucfg, by removing comments that are merely restatement of the code nearby, and paraphrasing the rest so they read more natural for English speakers (that likely are not familiar with the actual Chinese-influenced grammar). No functional changes intended. Signed-off-by: WANG Xuerui --- arch/loongarch/kvm/vcpu.c | 45 +++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index e973500611b4..b467a44e670a 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -302,20 +302,16 @@ static int _kvm_get_cpucfg_mask(int id, u64 *v) { switch (id) { case 2: - /* Return CPUCFG2 features which have been supported by KVM */ + /* CPUCFG2 features unconditionally supported by KVM */ *v = CPUCFG2_FP | CPUCFG2_FPSP | CPUCFG2_FPDP | CPUCFG2_FPVERS | CPUCFG2_LLFTP | CPUCFG2_LLFTPREV | CPUCFG2_LAM; /* - * If LSX is supported by CPU, it is also supported by KVM, - * as we implement it. + * For the ISA extensions listed below, if one is supported + * by the host, then it is also supported by KVM. */ if (cpu_has_lsx) *v |= CPUCFG2_LSX; - /* - * if LASX is supported by CPU, it is also supported by KVM, - * as we implement it. - */ if (cpu_has_lasx) *v |= CPUCFG2_LASX; @@ -336,27 +332,26 @@ static int kvm_check_cpucfg(int id, u64 val) switch (id) { case 2: - /* CPUCFG2 features checking */ if (val & ~mask) - /* The unsupported features should not be set */ - ret = -EINVAL; - else 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))) - /* Single and double float point must both be set when enable FP */ - ret = -EINVAL; - else if ((val & CPUCFG2_LSX) && !(val & CPUCFG2_FP)) - /* FP should be set when enable LSX */ - ret = -EINVAL; - else if ((val & CPUCFG2_LASX) && !(val & CPUCFG2_LSX)) - /* LSX, FP should be set when enable LASX, and FP has been checked before. */ - ret = -EINVAL; - break; + /* Unsupported features should not be set */ + return -EINVAL; + if (!(val & CPUCFG2_LLFTP)) + /* Guests must have a constant timer */ + return -EINVAL; + if ((val & CPUCFG2_FP) && (!(val & CPUCFG2_FPSP) || !(val & CPUCFG2_FPDP))) + /* Single and double float point must both be set when FP is enabled */ + return -EINVAL; + if ((val & CPUCFG2_LSX) && !(val & CPUCFG2_FP)) + /* LSX architecturally implies FP but val does not satisfy that */ + return -EINVAL; + if ((val & CPUCFG2_LASX) && !(val & CPUCFG2_LSX)) + /* LASX architecturally implies LSX and FP but val does not satisfy that */ + return -EINVAL; + return 0; default: - break; + WARN_ON_ONCE(1); + return -EINVAL; } - return ret; } static int kvm_get_one_reg(struct kvm_vcpu *vcpu,