Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2375695pxb; Mon, 20 Sep 2021 20:38:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRtKJ1e0DMVeox082ALbbttqjSDxP/cOoSkc5HWTAdk0oPiL9ueROHZpHR9trwSLvdm55c X-Received: by 2002:a50:bf49:: with SMTP id g9mr9584638edk.262.1632195502012; Mon, 20 Sep 2021 20:38:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632195502; cv=none; d=google.com; s=arc-20160816; b=pYMrXgEdZ14miTekd3Vyo6+x0oxxHizUM4sgM/mEOxF0E7NhN3Hpxz6El5/KTCedqs c88AFU1QKiBunjHiaxAbC0lXQYXrw/IM2rgV/vIwi8IAuXLoK+Gw451qnIYd/AnHPdXx RWjvG9/3Z8Tu7gTIpvnlpS0zW2rQLcp1APAp2EEBzR4BdpsYyedDT1HSZ31E+2uVCmeW 6D9o5SNOLMh9fyyHrqUDVD8d3v2wCV7C+b+us4zw/X4JUXtcq5v+OVDU+HEEvkxfk63P rJ1eAADHopdbwEtp739kgzW497R7ynZsR0fQ7q71oy/XgMZKdqvAUN8F7HDa1TFXQ2U9 AsRg== 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=L/UrA7bMPdZwkvQmnO8qkcnJ3SiGLrN9NysaTFsPcyY=; b=U98p2vTmpbiy2sL18aa087PjrkBzK5kSXaPXPBgavKpUBMAEpQI4c6wxq4anyZ+qhU DD9PeXLKoaAROOAxcPM7iPEhLMPE+UiO3d0vaNQiI9AwnzevuhoExcyLWzicYuDjjc9x 0eNtav69sCbESUV/t8cOwJ8JUMHB0YogwuowzZUv4ZyqGzHeYb73Jb9HGRR7rl0wf6d9 25/NAhypRx8BUnMHPUKTcmKYBMcR2V557yTDeRWVACz1XhMYw1SsYwPDhdPL+eKL5yaJ 7qzuKB+pDx1I9c9K9lFjmWii/lvVlQKPv2fZVas0rwlmv3afYquL078AcSL7wec1BlPY w+xg== 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 v8si24927224ede.567.2021.09.20.20.37.58; Mon, 20 Sep 2021 20:38:21 -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 S1343906AbhITVnh (ORCPT + 99 others); Mon, 20 Sep 2021 17:43:37 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:45482 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236706AbhITVl1 (ORCPT ); Mon, 20 Sep 2021 17:41:27 -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 1mSR0l-0006QL-CD; Mon, 20 Sep 2021 23:39:39 +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 v5 06/13] KVM: Move WARN on invalid memslot index to update_memslots() Date: Mon, 20 Sep 2021 23:38:54 +0200 Message-Id: X-Mailer: git-send-email 2.33.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 Reviewed-by: Claudio Imbrenda --- 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 14043a6edb88..348fae880189 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1281,8 +1281,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; /* @@ -1386,6 +1385,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.