From patchwork Thu Aug 15 13:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 819411 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp1152072wrm; Thu, 15 Aug 2024 06:13:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWxuOTes3rhyPkWXaU5ltZ+nrku/2ba1O2Kksv9V/he659vFXUUSklyGtY4nkJOKjX1e6P2p+Rh9bGHWIGi80cn X-Google-Smtp-Source: AGHT+IGFmRMV/+KGcEnu0TYtTAWw2uXC1EhtC7JtYul/XdZYlY+uLhEgDFaOB4ZPJWSUlS8aHtZA X-Received: by 2002:a05:6214:4386:b0:6bf:6ef4:b338 with SMTP id 6a1803df08f44-6bf6ef4bdc9mr27515536d6.39.1723727609518; Thu, 15 Aug 2024 06:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723727609; cv=none; d=google.com; s=arc-20160816; b=zhRtVpEWv2PSuFVrCTbZM4GpVyOYx9BL4oJ8ppyT9ygEUATH5RvmmLOZtWJGiEajS3 tJuZuto+0w8sHhWNJfaxCbdt+VO/sUgoYz2kWsbac0h/QgfBbMcELlxIAY45WKeF9aqJ OuDDhqtNJpnl97r534YcNdmW9lob6+kTBIFK76xg3vWg3IYkcb8XWPi++pPzId1FnB6d eeTwBljCW18es7emWIVP+Iq8eb7L462UjAsKeVxA9ZnhXRoqmpMRbn805KdyZ031BvYl rHN6RSc2iURWaS7Vld0C8v+E7UsBT3auLprW2/AnS5sEYAJ+XqwUkHCXGiulHKUanJA1 f+qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fLB7mJfkqSlFxiYgEnzw0Isby/ZPn7qIXDefx+aMhHg=; fh=OTkfrEnbNDInppsfj4HB8z6V33zCj7LOct256XBfW6M=; b=JZSDnfiw579kKrjt/QCqygwvF786VZneMCLDJGw5XGRIdA3+iZaiFmdLDOmaxV5sxM thBTZnD50PTBMo2bETmsQlNHh/DAYArxAZij87pX48KOFxdjl/3AMguZNQxN+A/UY0PV JdZZn0IcfSmArILHSQaPNMtBDwWcJ0BC9p9RN8ZTviNCCBBAHHGFfcyMVNdmJc3jk1gd MgY+L7p5YNLWCOP8jdCpMJXjdztFcSXtlkDnGHOyiZrs57jx+xXkv4TpjeZ5MuYLcj4B OWxmm9tW2o7gNK7xcBJlSwgPEHRWStb/yAyrla/zjD7fXFBC+9bQfCYeq/oJ6QKlIsd3 qeQA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=La885RhC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6bf6ff1074esi17041086d6.465.2024.08.15.06.13.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Aug 2024 06:13:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=La885RhC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1seaGy-0002WZ-4G; Thu, 15 Aug 2024 09:12:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1seaGx-0002Ve-Cd for qemu-devel@nongnu.org; Thu, 15 Aug 2024 09:12:11 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1seaGv-0001Iz-NI for qemu-devel@nongnu.org; Thu, 15 Aug 2024 09:12:11 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ef7fef3ccfso10591791fa.3 for ; Thu, 15 Aug 2024 06:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723727528; x=1724332328; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fLB7mJfkqSlFxiYgEnzw0Isby/ZPn7qIXDefx+aMhHg=; b=La885RhCR/dPLyR19c6+fw05pSwC+LuEJBqaietJTAd+8BALawektZCrnh+oi9rQrk LrIElFRJlnxHAt2rMMivaSgyGlNE+6IxP2zqOkdqLbjzO3vVIOj8uZr4ANLBYXif5jf5 rl1p3NFals6fVOnEjZS3H1kfWcqjwljTsyzP+APz0M8Q942SgslkYiFZvRT21jXU0orM Q+5p/cQmh92FIeHrtGLpGywzJeFJhpf6OXatPkqd41JhY86tLpnwkvsK1xtTrBoFytl0 2LL77uYLjGfSk+iatkTxWiNNNlvn0wnjgPFpYls7a8pp2IO5iwIC1dJ9qFrcNJebGydb hesQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723727528; x=1724332328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fLB7mJfkqSlFxiYgEnzw0Isby/ZPn7qIXDefx+aMhHg=; b=ZgE1vLpiOQOkN/TLORqs5vALZokH9qkiy58jiNFsLXusdgLjP4ln1IP/bni7G4FPhf ncu2CbhO+KrThfu4uDmUDpnuw5YyZzy0zyZujtEBfgIn4jQg0xkpx41sRKbIWK+WGK2B UfZSiWhnRKC5jLQ4B20zMf6ljNiAtY9yrTvCXuZGAuw2YGt9vTOSuKQ0JgHii4zisIIC hQAMnkSIQJhGKSrNDpGF16PupvTLIxxiJ+9ShiLl+HCfxP5uf7EmROskf4ShxfTkd8Qe Ptv1uEx66M8ovVyIcAnK7RB4/jzIhcQCWXZgeOmK8vd2baaTPCT1wE25rcFE+MaKkLyF ZalA== X-Gm-Message-State: AOJu0YwbRMKDSUoHitQ5B4ogo1c0bTGkuvU0zf0NpE0KKF0z3YbrnC5J 8hVm8DWKxqOc3JKrCwePvBN9K505ZqXY/R08muNtUwUrh8aDc+mwT+aAdj2mq3z4O/tpXF4HqUs 1 X-Received: by 2002:a05:651c:544:b0:2ef:392e:e45 with SMTP id 38308e7fff4ca-2f3aa1f923dmr47729241fa.33.1723727527871; Thu, 15 Aug 2024 06:12:07 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded19627sm48269935e9.5.2024.08.15.06.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 06:12:07 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Paolo Bonzini Subject: [PATCH for-9.2 1/2] kvm: Make 'mmap_size' be 'int' in kvm_init_vcpu(), do_kvm_destroy_vcpu() Date: Thu, 15 Aug 2024 14:12:05 +0100 Message-Id: <20240815131206.3231819-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240815131206.3231819-1-peter.maydell@linaro.org> References: <20240815131206.3231819-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=peter.maydell@linaro.org; helo=mail-lj1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In kvm_init_vcpu()and do_kvm_destroy_vcpu(), the return value from kvm_ioctl(..., KVM_GET_VCPU_MMAP_SIZE, ...) is an 'int', but we put it into a 'long' logal variable mmap_size. Coverity then complains that there might be a truncation when we copy that value into the 'int ret' which we use for returning a value in an error-exit codepath. This can't ever actually overflow because the value was in an 'int' to start with, but it makes more sense to use 'int' for mmap_size so we don't do the widen-then-narrow sequence in the first place. Resolves: Coverity CID 1547515 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- Borderline whether this was worth changing, but I came down on the side of "yes". --- accel/kvm/kvm-all.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index beb1988d12c..6c4cb263ba3 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -414,7 +414,7 @@ int kvm_create_and_park_vcpu(CPUState *cpu) static int do_kvm_destroy_vcpu(CPUState *cpu) { KVMState *s = kvm_state; - long mmap_size; + int mmap_size; int ret = 0; trace_kvm_destroy_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu)); @@ -459,7 +459,7 @@ void kvm_destroy_vcpu(CPUState *cpu) int kvm_init_vcpu(CPUState *cpu, Error **errp) { KVMState *s = kvm_state; - long mmap_size; + int mmap_size; int ret; trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));