From patchwork Wed Feb 14 10:15:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Xuerui X-Patchwork-Id: 200891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1118935dyb; Wed, 14 Feb 2024 02:35:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU6f2znKiLbgqaHkg0U4aoBM2T3tGKQaVMLc2K6hF03VN18WvtRI+pYJQaNa0dcbcFLQwh0ZAmzMHHIrVDkpPfG+OUc4Q== X-Google-Smtp-Source: AGHT+IHXiubwAUFkF3PeYZ1LMapQtxaTc22RJ24bgZG6lx0v+g6kOyFXdPpbFJk8T385b4SccBo/ X-Received: by 2002:a05:622a:58e:b0:42d:b68a:4f56 with SMTP id c14-20020a05622a058e00b0042db68a4f56mr2236820qtb.45.1707906923730; Wed, 14 Feb 2024 02:35:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707906923; cv=pass; d=google.com; s=arc-20160816; b=zyERP6PfIQTbZ6NdKZ9o/pgGXCpGgStiZOoXnwslcw1gMXPnCdrbJ+IBxF4NtmSuww r31krNgygVbA7HoN/dPlewZo96UQEt6LZRGVPJl+QwAaynugmLbrh0KCm7m0OPSrZHZG RTgapspVKfV5OcM4bBDW6i80sVCbGzOJ5Oh6iIxomhmH+RuMGiQOMI1zgfSnGG6SQ3Se sYDOJTYfoZD2NEiHLQQy4cRV9nwbvpPJRn4f7XFELoZXvyi1IhOkEMdRZzUP8Frp8sJB xynu7bn/2uOLR3sIhHqt9Af1E8ny4y/JiSkuXhYSnWidQ5/7yp0n8CTpDXQExEMFPBJ6 ZX1A== 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=Kc6m0sf1pzFksumkOKN/VAszzW+1uwS3X3KWYQqt8Ms=; b=vpEk6zG74u/NjSjsMmnV3B/40NgczDJEcaeGE2dEGopc2kG1oyvAnuIlw3Fa4yP6+v BSLmdiiBm9R5n6KqhLAfYclzANfqP9dTcZhTwQwt1/z44wrTP9tY23SM3FoZbx6Rb1By deVVHZz3im2wfbLp84C0fqU2tiOyJu63eqlKSbhVm2KExDuCLFTLb4l3R0GJkh6wza75 tyzHGL4Jfic7A7wkA0or8i7wJ32N8Cb0s4Rt54Ej8bVjP6DB7bhXHYuEm9xMFdSees0B aNUQxonUCPmAEBsTcLhxECBa7+eDRBsPGsATtlUhS1BKlgCbCtHoyTD837d12qfiN3Xb gcFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=AnHykjQd; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65045-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWWJIlOHgvcmT7SabSViFn+6rS4EY8SUGVmm90Yqc1QJ1tqjVtfEVIrp3jOEnfYc6qbMfKKusDyz86qlHWplq1xEXlWtg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e17-20020a05622a111100b0042db696fff1si2186865qty.283.2024.02.14.02.35.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 02:35:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65045-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=AnHykjQd; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65045-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 0B4451C2734A for ; Wed, 14 Feb 2024 10:25:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF3EB1BC3B; Wed, 14 Feb 2024 10:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="AnHykjQd" 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 69EC0171A2; Wed, 14 Feb 2024 10:24:08 +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=1707906252; cv=none; b=SO1olORUl7NxlbJFNsiBRkBXRFI1Jm5yE5hjRiHHukn8dni7iuQjZpC1VWuAerpTdf+VtdQxNCemNFCgrwoqYYCDuGCaPpWVPUhke+Sb5ux2Z1UrkL6iRt71hkv8YwBo8oQLj9fufSSxZ0m9W+e0eyTVlRmcCotbUYWYms2xjvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707906252; c=relaxed/simple; bh=qUTm7/R3ovfw0MXxK4QrZKdILlZUuBNM9kI6bR5Fxzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XFgxRPbgwNYJ1qRIO8JZshUWBOO2ncGYUuoiuOIAGaE43e9iNIloXoKkHAby5qAaDAWcdOxUYLFaWbVK0gZgcF6iD6IIhh17waVrpSKdMkJZtp89e8UjLFe6EtxpF6DAM8LNhtoUD/RufE62eYkO5gyZD+pafbaFcDKzvnQFvcM= 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=AnHykjQd; 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=1707905765; bh=qUTm7/R3ovfw0MXxK4QrZKdILlZUuBNM9kI6bR5Fxzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AnHykjQdE1CficUI8gdhrgpFjRfWTnDfdo/3pAtd8JVI8QHIsghXTdXwSjL1Fg7sz jw8WvUNInaOnTLhKJuxzq29eNk0fhq9PYUwGntbZSLVCe/uMu13LjJmVOhkc8wgEPV VunNPOwdUcIGAqKUPO9cRjUrvDXrZRe/bAfifxGg= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:5531:eef6:1274:cebe]) (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 6215D6017D; Wed, 14 Feb 2024 18:16:05 +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 1/5] KVM: LoongArch: Fix input value checking of _kvm_get_cpucfg Date: Wed, 14 Feb 2024 18:15:53 +0800 Message-ID: <20240214101557.2900512-2-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214101557.2900512-1-kernel@xen0n.name> References: <20240214101557.2900512-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: 1790870210682610535 X-GMAIL-MSGID: 1790870210682610535 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 10:15: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: 200890 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1116205dyb; Wed, 14 Feb 2024 02:28:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXzYejL7R+KMHpmoX8REqEZ96Dkc7kbER9GI6oPsMKQCz58pOJ2fgVSu327AbX2RRqQS87yaqUjeFa7mG8jYvIYUnIDtQ== X-Google-Smtp-Source: AGHT+IHaTs94IEoom+2HLVM8q+Tbud+v8kDPGlVmlZ3tt3iG/oG2gImk0jkYq87O3dequHINNhsq X-Received: by 2002:a17:902:e752:b0:1d9:ce46:6ebd with SMTP id p18-20020a170902e75200b001d9ce466ebdmr2920389plf.16.1707906500496; Wed, 14 Feb 2024 02:28:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707906500; cv=pass; d=google.com; s=arc-20160816; b=JsOJWatY6x3az+G1ZnSG+6e1qKbY7Ldcb6d3BDgiui9CP74E4gH1N7jZakAABEPrnK nz3QBf2ekXurxjhM16t5tF1NaK3VRleVE57wmTf+iCYmrEq6dyjxyGn7kcntISTYvBSt yD3D4qydKdOU9jOpXlFRVAXX3SkBgWZxp558bouBAmfUek5gmWAST4qA32UagKiq4LKU z5G2QhXMGuAW/F/JnL1iwepi4LsOKzCU55yv/nS1QWzdAt8bJUIHmYynjJdZFTmWUvML 1bx/2cm7/dQKjs5w3L/6QWd6RMMk6Le/QhtPOh2Uj39/sehDRYyZNIHmKey3GQqK4K3i DIqQ== 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=hn3cshUDLAuNQ13c6qHxVABFkOdeqRsh3oqCUi3w9Jk=; b=p/S+UZch71uRV/VqpWML7Fogmob8D+GRyfq9ijbXm6DZFroWNvSTDUcYsf/Ohe5uTT 5g1zyusFYaQQq09gtk4w+mRCDtkqXaS+HPrzJAN1zna8M5XaZBzFQi/tx49sZFbf7QoZ jUaKcMVAsl95P9fPqADxSo/bs4SUtD5WqVpsJoRJaM63VkrkdY1n13/r8h6GIwLld3VB e3qm3TnXTR6xnr5Hni5RFyRMOBknxKqoN+te5j8BHq12j4BSos4Q7jJe7uMUXkMlmgpB NFvJS7ehVsjngV3rM1xmnuWhRiTsl+pUPCllx+1z4VLjztHWZqpG+51a0/jlchiDhNUZ Bpgw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=QOQHz9Rr; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65042-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65042-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXMWjC+10/wkNfEcOA7tLFQi9IzWWbCgVncCdbuKmyvgZXPt+RfQjwe5jnJvBEY+PLkCoAWQy+brD2hy5OV+DJ6MHESWg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i2-20020a170902cf0200b001db42888181si2194577plg.499.2024.02.14.02.28.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 02:28:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65042-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=QOQHz9Rr; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65042-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65042-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 ED8FC28572C for ; Wed, 14 Feb 2024 10:25:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E6B41AADF; Wed, 14 Feb 2024 10:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="QOQHz9Rr" 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 6C1861755E; Wed, 14 Feb 2024 10:24:08 +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=1707906250; cv=none; b=F/p/WBT7O3d7jQJipQ87nqPrTzOP9LSSO8bTgEYRnJVIrDtWjWc7y8mfIU/Xm/H1pmFjys+224+eTdjggrVZKIpmb8JUIj0Ax5XlMl6wJVGy8n3J1yBPznCCvXrEcGaU6G4M9BiF1ZG26kqpdRMsiSgfeThpelFNuh4QlU7Fj44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707906250; c=relaxed/simple; bh=RLw0Ke+gAZcjvLomlJhUe4+W8YYZZSg0ARVq9aMVCrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B8bhutAgH7F7xeQxo0Cn7WyCzuZGTIVMes8SOkay54g7qsFrVoADFIpVd+cN/jQXNc2jpoLG5SW1pUFCt7u1cWuipyT/dzKWIcPxIOz7zwUvf23BVyuQEj71wup+ePPv80p0LOmUn3amGfJn1Rxppr7mo1f16iI/E7hHgvxnRK0= 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=QOQHz9Rr; 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=1707905766; bh=RLw0Ke+gAZcjvLomlJhUe4+W8YYZZSg0ARVq9aMVCrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QOQHz9RrVavX6BeKFy7gBmTGpqvwBepZ7fDQO0dBCdOduCsqYJLFvZR1npngVfOZo euevnVDYHQHw0+mIjO6IUmsqD1OAMkmRUs4wVTAdK5f2AWFIKDAKD0m4MBRnCb+dnm ChKaWPTjcX54Vvg8n3XGSFoDOoSzsdBmc6iqHL/8= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:5531:eef6:1274:cebe]) (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 7B052601A7; Wed, 14 Feb 2024 18:16:06 +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 2/5] KVM: LoongArch: Fix kvm_check_cpucfg incorrectly accepting bad CPUCFG IDs Date: Wed, 14 Feb 2024 18:15:54 +0800 Message-ID: <20240214101557.2900512-3-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214101557.2900512-1-kernel@xen0n.name> References: <20240214101557.2900512-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: 1790869766498626063 X-GMAIL-MSGID: 1790869766498626063 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 10:15: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: 200896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1121648dyb; Wed, 14 Feb 2024 02:42:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdOO15WNntV3ssAoshEldQNY28NDhjfIjZdsDTuFkh9SViZNjj1drm+0C3DeBWvMqGQ96rohUO+aM+/XajWuydarawJw== X-Google-Smtp-Source: AGHT+IGlDv9jm5iPzdPUlJ3LPjG9L5sfYyUfS0DI+leJ6ZSg61+IhcPFNyNmIfptTWUM1S+iGF59 X-Received: by 2002:a05:6e02:c94:b0:363:b13d:3273 with SMTP id b20-20020a056e020c9400b00363b13d3273mr2484325ile.28.1707907348383; Wed, 14 Feb 2024 02:42:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707907348; cv=pass; d=google.com; s=arc-20160816; b=x7lKHwHtsI2khPkkaix/j0AoW/MWKkmd+3eg6/EHEgeWTdRUoP9eR64y2lT7OMWtJp L0hBsRBr7P7YdSWl+HBBad8zvKyOniErM7xFA/U72TXDAHZq+8/S8Ybcst1E43wLfC77 femA7uGD2qASNgTVklkV9GJXXL3OH4pKi+25ahjPmIz93Dnzv2j+vApSdkp5Xp+mQx35 16sobH1ERlshAp/wzMjnk1cfJfPP5ZoXe1atX/iIBeOpQ7A6kTZoDXuduZYy7DiTLUcM /ig6FjdET2jqsmMQzWPamXtsMJPyXHidjInE1Mn6HAj3+JD6c6fqAdd+qjGEOKES8rIg beaA== 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=sIDZ7IuJYrjoGfP/sP15hfyslQLu9kqJ/FD8mqwRfbE=; b=XmKtAzpDDyOPo4107Nweq+KLyvqjgJxDsxqWQAhp/+DV774Brhmpak4i733Yz065Az YlPc+fhGsmntz0UCUkTHw7bSw5gw8dFdjay8qrqP6i7q1vtWx1UBr7eHBXc1CFTD7id3 71lOUZOgebk2y2wtv/lwPeL5nhf9xAobeHYWieTPnlRJfBt5rN5YXwXt8xd1ugx9d9Qe G+81PRkCnx84TIpNhvmEAGG4InBEamHqf+t99S9Sq9ej960NpACCZfkOlxFZiwKXr6HS 4hjCg6UZ5+TTaAVGjPA3wxVjaCiY96MuZHQnt7xS/5YdC6Bru54lgftMQFjHIO4vIZQj fQKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=xPELIX1z; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65041-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65041-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXftReU1LBVOLzfMPdJb0/IOEY8p2XC98zOywvECTFAR2vXQCzJllnhaPCpf0CCPcyFdGNk94JmQfzWi/Y3R3bibhGbrw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m19-20020a637113000000b005ce030a6460si3567181pgc.71.2024.02.14.02.42.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 02:42:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65041-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=xPELIX1z; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65041-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65041-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 85662B24EE0 for ; Wed, 14 Feb 2024 10:25:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F36041A29A; Wed, 14 Feb 2024 10:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="xPELIX1z" 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 69EF417543; Wed, 14 Feb 2024 10:24:08 +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=1707906250; cv=none; b=SoXmaCXK9rQpVW3t6Vb8EMC7SrdbRiGIZJaViMjwUlghGAeQHSOSbryXgyNRqfjycHiDNKrwdFLqK1+HkQ6cFbKa9KOHbSyku04R+OeRzCj3u7jMAshBKGUxWW4wkNkxriWGpqcwDjk4rUoMSq1Spr8GfXZf08Ed7alNQ4GJMaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707906250; c=relaxed/simple; bh=VP6OWLTFU7Iwj95xAdgUR/i01Q0SJTbE9ZgKz6xmu84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EPAOii1fmPeuRZOpE7A6+TNcPf4Bc7EZ1AX9sxvdom8ChFT5PDvD4VGJcEbtbDpYjGAEuMAfww71faeODfCDVpLJf8A7aIEzrxq6t7jNfGnodiXBEGEKkFUWUyFBqGo0BaZDohAYDlGV1gHeKplxYa7RYz/6U3DAyldga5oiSZ8= 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=xPELIX1z; 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=1707905767; bh=VP6OWLTFU7Iwj95xAdgUR/i01Q0SJTbE9ZgKz6xmu84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xPELIX1zkthuNl7p7i0jC+9O9gRLMpQR6i86bz0hw432410swsodTqRxYGqmArAK6 ooPVVN57ifBG3uEKJHR6S+7CSg8sgzPpIgku7G16GDft5x55pLkzQ5NtxPHNx+85dB sp1BmohNFFBTlvOgjn6QhkdTa/VuOM3Scq3/9Vos= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:5531:eef6:1274:cebe]) (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 AB9B5601C2; Wed, 14 Feb 2024 18:16:07 +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 3/5] KVM: LoongArch: Rename _kvm_get_cpucfg to _kvm_get_cpucfg_mask Date: Wed, 14 Feb 2024 18:15:55 +0800 Message-ID: <20240214101557.2900512-4-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214101557.2900512-1-kernel@xen0n.name> References: <20240214101557.2900512-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: 1790870655771201482 X-GMAIL-MSGID: 1790870655771201482 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 10:15: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: 200897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1121858dyb; Wed, 14 Feb 2024 02:43:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXPXgK8aaMVJ1LlbmWFYlgbCI3150KO3oP4ePaaKOZJT4bpNnVdGxtNg3eCEDQvY/pi3u6ZzbuHo4DnfGv+G4LdQihaJA== X-Google-Smtp-Source: AGHT+IHHinfbBnqZZqyfliCuyYO5niwA4qvNJWCNh2GSpSPXrME6I3LuOe1qUig5ak9MOUch8vYe X-Received: by 2002:aa7:9d0c:0:b0:6e0:6c0d:f55a with SMTP id k12-20020aa79d0c000000b006e06c0df55amr1997768pfp.8.1707907380680; Wed, 14 Feb 2024 02:43:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707907380; cv=pass; d=google.com; s=arc-20160816; b=lg7qh9dW0wBGWpn0BKnPczQatsvZOcg5t7GDl+aQpYZRXMcuXtcml7eS7joRyPoA/0 DFzBJq1dRlQva5tfnEHc7u5jGYL/I48KxFiXeCmtrUEyjNefTtrkuUOFLW1WkZDQBxp9 ouxEg+7GQgDRLMfL4Cnj3uOqEIQ7BtCvDKVHyIVpYl1Gnt7cmp56THFuh4uZtFkGlYwN A76QpUFTPdP+yReAgWnSg9MRcxtotDZ4B9WcZzi+LZDvbZ9Y4UmDbVvbiiuHox/m5BAx vhFMX54CUktuGGvaS1D/dRR9DDKQclTtzU/y3h8zZ45vuIZznuNt4svZadf0du6bfAlZ AqeQ== 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=RHNnlWo/dTC6sjCkmLRk2kkdbF0UW6ee+nmiFsRx7Fw=; fh=B49GbIh5ek5sTKfhpR9Vtje8P0F2zl16rPmec+16Lyc=; b=VMqS5aWi7PtH2CfzQ0gP9VMuZx7UqjA3XqJei5Q6e4f7ALxW+KL7c80uuKbtyTjr9E xCcWA+CUByjvIdrtLb2xFBGOEm/D12FATaxmdRrRgP5pVCfpF6Lu2sTQGUFTirt7Plp/ MbfDiFHlzdUpUEKQovEOR22h7UQ4SFu4z1yGXiKZWvpZ+NYDNuvVAJ5qDZPmqAhLFf3t SALyIaVUpZzKUctAfhk5vN/13bpyHmqJ3T+Bma5d7rCIJoUpuWoVRntpt3dQ0JuF38af zP9BdFEg26Dd6WL13c6Ut3cTkD3Pm7HCW1gSwfjiOyHCb8YQFOGbwRaOi71eb2nLIWku 9DrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=cOXRPrNH; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65044-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUbS+vMtsNm/PBSLTQLEEpaksQorRVL6VoJbF3go6VEJo36hKXltPQ375nWKigH98gQam2xAyCsYXn2zYYOPSTf5+mIsQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id r9-20020aa79ec9000000b006e03e373076si8215320pfq.25.2024.02.14.02.43.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 02:43:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=cOXRPrNH; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65044-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EE938B27F1A for ; Wed, 14 Feb 2024 10:25:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02F7F1B964; Wed, 14 Feb 2024 10:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="cOXRPrNH" 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 7A31C17580; Wed, 14 Feb 2024 10:24:08 +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=1707906251; cv=none; b=Qf1eM5pBlmM4diWjd0xnMZTc3II49uzoy/QGSwRmoUXPwncFQHXJoFl/PS9RwVShM5dhrZAn19tHmVAmdMFjD6fbyPzle5SCEiM4Skv09G3vC2hXhreYsUK8b4dIXiGQkUu0fNMISBms+8AefoDuOkS712vBZr9FMgyJVkld0cE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707906251; c=relaxed/simple; bh=UEF3EtzASKcetwcq4bXXyQ5NmYXr4KVcBieRDjHk7ok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AmF+v2zuuLJ+cZXvpiGtgGFjtsOdQ3BrWdjiYCtA4X3BKb6Dhuth1CaUnnzfxtsYpApDVILM/9nMkCaLHMWi1YLa5neZSkVHz/fgldzO9dQWPeKdQ7vl4eOzbVsoQnsQrkL/EdSDCwN8QMrWUSiB1HSbMhBu2k5pKdH6+I9h1WU= 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=cOXRPrNH; 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=1707905768; bh=UEF3EtzASKcetwcq4bXXyQ5NmYXr4KVcBieRDjHk7ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cOXRPrNHUvE8DHxSgDP4KOW6f/OrLuGnwlp5dJvrkprvNZtiBseCBWzy34+S2cOTV dKjfN/r4Z98QKBWNK3waITUgB5aV9t5UEheqlf46SUTbg2tDX5NboTSAp6G3iaD3Xv rGeZl+8u96PemsRIQ8TRmwxJnF7t4DD5z+er+/dM= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:5531:eef6:1274:cebe]) (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 A1FE5601C6; Wed, 14 Feb 2024 18:16:08 +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 4/5] KVM: LoongArch: Streamline control flow of kvm_check_cpucfg Date: Wed, 14 Feb 2024 18:15:56 +0800 Message-ID: <20240214101557.2900512-5-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214101557.2900512-1-kernel@xen0n.name> References: <20240214101557.2900512-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: 1790870689410020062 X-GMAIL-MSGID: 1790870689410020062 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 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 --- 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(); } - return ret; } static int kvm_get_one_reg(struct kvm_vcpu *vcpu, From patchwork Wed Feb 14 10:15: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: 200888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1111775dyb; Wed, 14 Feb 2024 02:16:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVf+knMqt8lfIB6zRIvl2wR/4eXPAi4OIeqkyP6MEJH8gPVZx6XCJg+ugr7WY8cvQrJqi88k+dyeUFFe9yiC1aEzmreKg== X-Google-Smtp-Source: AGHT+IEjeIudy/5Kfhi9/nnDGfJCqJwAfmgi7Yf352moMGOkAkWjTrEsHIpYS0lYRA1hEx2sNKrl X-Received: by 2002:a25:84d2:0:b0:dcc:f6e2:44d0 with SMTP id x18-20020a2584d2000000b00dccf6e244d0mr2002543ybm.37.1707905813209; Wed, 14 Feb 2024 02:16:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707905813; cv=pass; d=google.com; s=arc-20160816; b=zY7LOwL9N7hXMFbHNGIjqEyvDpceeaq0ka1REItunNQ/6W5ruzw1JGR4i++YYyYZAe uYmTufv6ZzD0NbrIPlz2ppWCYvTfAiwO/eTMl8mjdbeZklgpqtgtYHqA9XVmoyFMpC9s tIJqMDoy/DOMv03l23Z4r3RknXOzEivQDx0VKbZdLp4TEZE2EVVA1PhAmHlyhMzN0MUb CcNaSYkes7hYJe4U8skfJ1JtK3vzMTjcIqucrFrs3WwjU6aiYVw+mUdOmRjdMkG0ukv/ zuA2Robq4TgwiDd0eI6ib6Jdm1BTda4YMsKpVbouf/jseKCBSZzlY/eesWBxce/l0DYL zbCQ== 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=bGRgT0divJ/KD2WyBItPZAmrgw48yLvLyea+cSkDaXs=; fh=kYV5blxIlzhvxacf6MeoneQCnFpBQu8lHV2sHdvDEP4=; b=NR6rRm9+jW3N/LvvO0JHosL9elSlIWJXBuHCs2z1tfFOi8A2CdokJIvdEKFER+eYOF sN0xFTr5eXr7tFn1msoe1OweZsrMjx0c2wsCHVx5x4qI5dgRwe/ihQ7wVEIufkLGBbD/ QhxVK2sAATLNlqmg4wsC2iqx8i4cGMqGhqwcAjYIl8xfuXmwDOTuSA/FyPUgWMAn/T2G 6gIdUdpnRjl9Ec15TXhflsWOp9UFoCTSVZAeVKUcBZ1bYC81oK6ASUr87S0ELsjT7mc7 Hp/CjfpRIiXSjq/4zNqLz/QseN3bYtYWGIpzI6lxnlEoYhwAxNWJqoKkOr1gPfgJwk/d Vl3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=GlwHXq5K; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65032-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65032-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCW1Ma1zWMXN5Shikv79elleW5wXeGvbDzIeWW60ckc/VZfisoFmIVU2YpIm4dTD450liAuh4vY+mET6OoeadHExMh42FQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y9-20020a05620a09c900b00785d9bbb481si5808084qky.627.2024.02.14.02.16.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 02:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65032-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=GlwHXq5K; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65032-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65032-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 00D011C24CF3 for ; Wed, 14 Feb 2024 10:16:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB0FB18057; Wed, 14 Feb 2024 10:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="GlwHXq5K" 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 EC7B6171AC; Wed, 14 Feb 2024 10:16:13 +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=1707905776; cv=none; b=FIODYYogxAa11CEkW/fGtmx/kKMzXlz0nmGQ8wqsgrc04OO0eAjNW8TR3DwRdcbMj9u245URdGWhzCYHnJ6uE3gwgM/AmA3R2jjdni6RG2MzLgZVDEA1GtI35FqUVL3l6F/Ll1MmoZizonbGOAJ94gn1bET+Ml/YuQe7nIpppIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707905776; c=relaxed/simple; bh=eTiNyXEgBPCIo0Ta8sYgjRV8p1Xz0hDcVMygIqs3U3E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B5mwd8xgekWIEmHy+vF+v+ucle1Ufa2ZiCOtLm86cDh0gNHTttCFWe9V6N8fd82yIsaJo9lcyFREDdIqaio30wMzkjTrm9xQhirtYjEwxr5sJRAEUBCqP8s55BKeWuMj3q9yBH3mO5cBTfkDewuYUkki7LAIPGZsCeDGPm2PXYo= 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=GlwHXq5K; 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=1707905769; bh=eTiNyXEgBPCIo0Ta8sYgjRV8p1Xz0hDcVMygIqs3U3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GlwHXq5KtlJN3WjzDugZTkyJEy5LHE+ExYx073zzj48EYrqsL7zgxjG0jH/CXdUWu lHC5BxTxuznnRWa29bxkSyDY9QBTn3MlyULKk31DvSXmHgOaImFsYVGo+Dmwyixr+h HhHqPrIQO+kYbav4MpoP9qcNYRLyGihzdZ4frvdI= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:5531:eef6:1274:cebe]) (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 9843160562; Wed, 14 Feb 2024 18:16:09 +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 5/5] KVM: LoongArch: Clean up comments of _kvm_get_cpucfg_mask and kvm_check_cpucfg Date: Wed, 14 Feb 2024 18:15:57 +0800 Message-ID: <20240214101557.2900512-6-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214101557.2900512-1-kernel@xen0n.name> References: <20240214101557.2900512-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: 1790869045971437671 X-GMAIL-MSGID: 1790869045971437671 From: WANG Xuerui Remove comments that are merely restatement of the code nearby, and paraphrase the rest so they read more natural for English speakers (that lack understanding of Chinese grammar). No functional changes. Signed-off-by: WANG Xuerui --- arch/loongarch/kvm/vcpu.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index 9e108ffaba30..ff51d6ba59aa 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -302,20 +302,14 @@ 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. - */ + /* If LSX 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. - */ + /* Same with LASX */ if (cpu_has_lasx) *v |= CPUCFG2_LASX; @@ -336,21 +330,23 @@ 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 */ + /* Unsupported features should not be set */ return -EINVAL; if (!(val & CPUCFG2_LLFTP)) - /* The LLFTP must be set, as guest must has a constant timer */ + /* 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 enable FP */ + /* Single and double float point must both be set when FP is enabled */ return -EINVAL; if ((val & CPUCFG2_LSX) && !(val & CPUCFG2_FP)) - /* FP should be set when enable LSX */ + /* LSX is architecturally defined to imply FP */ return -EINVAL; if ((val & CPUCFG2_LASX) && !(val & CPUCFG2_LSX)) - /* LSX, FP should be set when enable LASX, and FP has been checked before. */ + /* + * LASX is architecturally defined to imply LSX and FP + * FP is checked just above + */ return -EINVAL; return 0; default: