[for-6.8,v2,2/4] KVM: LoongArch: Fix kvm_check_cpucfg incorrectly accepting bad CPUCFG IDs
Message ID | 20240214163358.2913090-3-kernel@xen0n.name |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-65554-ouuuleilei=gmail.com@vger.kernel.org> 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 <ouuuleilei@gmail.com> (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 <ouuuleilei@gmail.com>; 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 <kernel@xen0n.name> To: Paolo Bonzini <pbonzini@redhat.com>, Huacai Chen <chenhuacai@kernel.org> Cc: Tianrui Zhao <zhaotianrui@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui <git@xen0n.name> 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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790892993220995285 X-GMAIL-MSGID: 1790892993220995285 |
Series |
KVM: LoongArch: Fix wrong CPUCFG ID handling
|
|
Commit Message
WANG Xuerui
Feb. 14, 2024, 4:33 p.m. UTC
From: WANG Xuerui <git@xen0n.name> 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 <git@xen0n.name> --- 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) {