Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp24430lql; Fri, 12 Apr 2024 02:24:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4D7/3A94negbsFy1hI5wPaTFyEjG3GyOoUm4UKadnoebdv84SRDQkN8ltoOHcVSFN/BmDVS4kIqjXVIpCRKXdX1DOmDoGqtS+lvnaxQ== X-Google-Smtp-Source: AGHT+IFaiR7qA+dVs+fxDW2BhObQ34Rr2lnrPhdAbfPTFm1O1L05EL4viej+dJ4dzQ0DnRNCy9TJ X-Received: by 2002:a05:6a21:6d87:b0:1a7:c67:82ff with SMTP id wl7-20020a056a216d8700b001a70c6782ffmr2744894pzb.13.1712913847363; Fri, 12 Apr 2024 02:24:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712913847; cv=pass; d=google.com; s=arc-20160816; b=DH8liq+AICtqyLNBwb7BDDzGfnlDMF9UTjgUliRwcTt9koYUbt/mvXRi9y1qfYRvtN 35bAlJtChlKeZ/fByUkzJcTdAvQiThysXQMJ5JGpQ3qIJbhYu4o9M8D2z2xr4lK5zqrJ DYuxdDKHJMG9iImihgZ66eXuohi8Y7XtYIWptOHFrUZ3jyVPJST66IeX+E6o0zBBV8Lo vCtAiKlXxVlrnMqF0t+Uib7G5gzOgFw9dxd8BWO5ecBKBoNN2q+Bg3l733pa+8xjmx7/ LqE6TrmO2irtLmOJ2KmBJTXl5XfYNpDcmlzVDWw+Ixt+JLxbaADk70OxN9gEj17aISWM UYmA== 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:message-id:date:subject:cc:to :from; bh=nHjiwVhYMMAT9UjuAunfX9V53G+AP7iZ7595vJTOkNA=; fh=zF3JZS20BRe7MFy8wNHWyBZjfCP6i5huXZVCWv2u57M=; b=PgQ08slHromqymDh3yQNwRDIUrOZdohIkT2j0bp4bJADeZxdDDsgV+sjzSAi30c6ed EN/Omx8Gn8BMVqHpnKwkB4/CO2LxHyugRLpU/gNC5f+cpUMD/5AClHvS5c9goyndHCM9 YmXCQrM3vu+JeTSU5n8BWeW635+E4l4eyd08eVBHFWT1kWKXq/PIUSDvQ+fHl2CdSFrz 79wpz8BFcrig2qecAickNsgXoEGmWk3kfQ9xCFb4rK5hou+dVl+UfAK/OQfuMKqGvMQP zO2z4QubFTHAhP1k3Xdhc8MgHRodayNOOr57XBrAqfEKU7jwSA1VZmY06ENXjM7MH+Re svZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=linx-info.com); spf=pass (google.com: domain of linux-kernel+bounces-142323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142323-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y23-20020aa78057000000b006eaf0665127si2963734pfm.306.2024.04.12.02.24.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=linx-info.com); spf=pass (google.com: domain of linux-kernel+bounces-142323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142323-linux.lists.archive=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 74957B278E6 for ; Fri, 12 Apr 2024 09:03:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A37D858208; Fri, 12 Apr 2024 08:52:36 +0000 (UTC) Received: from mail.linx-info.com (mail.linx-info.com [121.69.130.50]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43B9E53E03; Fri, 12 Apr 2024 08:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=121.69.130.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911956; cv=none; b=dbP5Vgx5rvFDtRBsy67wt2IU2mE8V0TZ+Bb0++xGsAiVZe5VGzRCJ69RFQ6bkUXXAceEiTcF8Sn1VapeZ9dWD7Ym9vhNLuYAZq8sUxfF9G6FaA27oVvyRjEc47WjKFTHwD+9XOZVkfAhkGtmUNC4iWURBofJvrcTB+cFttXYKK8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911956; c=relaxed/simple; bh=6PmQtfpvoTFi/3cmAtE2o3h2Hn94hmQPmO4RMbgjjko=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=sjiabDu1aNotvc7X96zdMUn+tS2Lez1AidIv7+VBMB710zlD5v+xI0PA6LCvVYoTI8YxsXqbEhJp7OIfsVVf2EbfEp7ojbnkARTo4A8K7G8Cd0FDfvVgnLtAg3ndbwChfoaNlePItv2VIboFqDOgXjfGyQ3akk4maQi3UxCNtZ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linx-info.com; spf=pass smtp.mailfrom=linx-info.com; arc=none smtp.client-ip=121.69.130.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linx-info.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linx-info.com Received: from localhost (localhost [127.0.0.1]) by mail.linx-info.com (Postfix) with ESMTP id A93E7320F70; Fri, 12 Apr 2024 16:47:07 +0800 (CST) X-Virus-Scanned: Debian amavisd-new at linx-info.com Received: from mail.linx-info.com ([127.0.0.1]) by localhost (mail.linx-info.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id al50rqZR2Ojr; Fri, 12 Apr 2024 16:47:07 +0800 (CST) Received: from linx.. (unknown [172.16.0.253]) by mail.linx-info.com (Postfix) with ESMTP id 270B3320D3D; Fri, 12 Apr 2024 16:47:07 +0800 (CST) From: Wujie Duan To: zhaotianrui@loongson.cn, maobibo@loongson.cn, chenhuacai@kernel.org, kernel@xen0n.name Cc: kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Wujie Duan Subject: [PATCH] KVM: loongarch: Add vcpu id check before create vcpu Date: Fri, 12 Apr 2024 16:47:03 +0800 Message-Id: <20240412084703.1407412-1-wjduan@linx-info.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a pre-allocation arch condition to checks that vcpu id should smaller than max_vcpus Signed-off-by: Wujie Duan --- arch/loongarch/kvm/vcpu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index 3a8779065f73..d41cacf39583 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -884,6 +884,9 @@ long kvm_arch_vcpu_async_ioctl(struct file *filp, int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) { + if (id >= kvm->max_vcpus) + return -EINVAL; + return 0; } -- 2.40.1