Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp1082035pxb; Fri, 13 Aug 2021 13:06:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTv3GSHFSOsZyGMsIEN223DxvCuRcbORaieCdCAEz/ZO/JFqqoB+DjjjATdo9y+nMODPv2 X-Received: by 2002:a05:6402:13c5:: with SMTP id a5mr5058588edx.132.1628885167295; Fri, 13 Aug 2021 13:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628885167; cv=none; d=google.com; s=arc-20160816; b=LmcwvDvN13084Lc54wrIu1W71QYXuza9mAituxmgmrpKDV4VWEopf4Q4quXJgbpE6a 0GF3ivsKvZGEsHwO3h2u+wmylWJ611oxXWbMUE6tBUXnOn1xnBgahDK3siDe4WcekXXu bsJnBeNeeWSa6eJzRinuBjv3ZuHxSQwS/3REcp/4crHQKIvQyUm2H8l46Dl+OwUf5Rel oEs5g7xypyJMrEsHYWKcd9AEG48a8h5r4BHA32no0AxUROizdn3VwCO5xuIlJot2Ewg8 5ptwDif1v7HocNGh933Hf3V71CAoYmlq8tR97vbaSPas3/IbQ6I8fsx4nDtcukOLoFIi FlVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DQZo6FZPFMKIeJZNPiiGF+OivHvCH4hXpNnG5iuetMc=; b=sIUFqKKBs3OoF6QTrUBl4lhP/hsFoE0njJqyj3Df65/IEArNrANkHzsp3A4WZsHozn WZie4JCsmWeNftN3L5n84/OaE+hlgAsw5MQ3kfeL9qG034sV9Feh/wNY7kjG4uoUi/cM MlC5kdi4zf9ft5VjDedqCTU0vl6qG8pNScshvLgFYYRL54QO9DMksWvGU9wnpLXn5vVb IZZ+nLrYZ8uPrc73M2wOSla+8LPUBg5LX9oLO4yR4vbDyNPTTKspwFRVd7+lachz4SuH Ak4YYDpQR06mYFrDT8Iu390mV6JZKGT+vaK9M+Qcu+wgZkimzqqO87TjGKs6SsxC+HIE Bc9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b29si2850345edn.332.2021.08.13.13.05.44; Fri, 13 Aug 2021 13:06:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234465AbhHMUCJ (ORCPT + 99 others); Fri, 13 Aug 2021 16:02:09 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:50356 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbhHMUCI (ORCPT ); Fri, 13 Aug 2021 16:02:08 -0400 Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mEcwN-00042n-U7; Fri, 13 Aug 2021 21:34:03 +0200 From: "Maciej S. Szmigiero" To: Paolo Bonzini , Vitaly Kuznetsov Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Igor Mammedov , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/13] KVM: Move WARN on invalid memslot index to update_memslots() Date: Fri, 13 Aug 2021 21:33:19 +0200 Message-Id: <8db0f1d1901768b5de1417caa425e62d1118e5e8.1628871413.git.maciej.szmigiero@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Maciej S. Szmigiero" Since kvm_memslot_move_forward() can theoretically return a negative memslot index even when kvm_memslot_move_backward() returned a positive one (and so did not WARN) let's just move the warning to the common code. Signed-off-by: Maciej S. Szmigiero --- virt/kvm/kvm_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 03ef42d2e421..7000efff1425 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1293,8 +1293,7 @@ static inline int kvm_memslot_move_backward(struct kvm_memslots *slots, struct kvm_memory_slot *mslots = slots->memslots; int i; - if (WARN_ON_ONCE(slots->id_to_index[memslot->id] == -1) || - WARN_ON_ONCE(!slots->used_slots)) + if (slots->id_to_index[memslot->id] == -1 || !slots->used_slots) return -1; /* @@ -1398,6 +1397,9 @@ static void update_memslots(struct kvm_memslots *slots, i = kvm_memslot_move_backward(slots, memslot); i = kvm_memslot_move_forward(slots, memslot, i); + if (WARN_ON_ONCE(i < 0)) + return; + /* * Copy the memslot to its new position in memslots and update * its index accordingly.