Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp516944pxb; Wed, 18 Aug 2021 07:37:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOl4oRh5qKmlXeoEutn2b0mTMEn1bJTSodfB44JzsJKJ+UqsAoayu/PDIRnGHdYY/srzgG X-Received: by 2002:a6b:5911:: with SMTP id n17mr5979742iob.180.1629297434600; Wed, 18 Aug 2021 07:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629297434; cv=none; d=google.com; s=arc-20160816; b=jX/ZlrTm6h6H0r8LFexEMQkho1xDSONkVTxRNtya/ZqzPQWX7ibO1+5j7ESB4nogdO c0mTFsX9fqNDUu12hH0k30LaK21cxNlHW5j4z3sa2/RsdkliRNOG0HE79KeLrV9n/Ft+ Capf6sknLnsHmzW1Q1c692F47Ca5iHbBwmCkr+n1eRq5m+ur+x9CWhUIO09R0gudbWmA FSerlXqTqDMFvksFs2EHqBw7RJ2xdov75x+Yi+XRDYImljwz/k8JK6tqDTNcCbxky10t XwMUPkfpKx+Lf6IumXC7L5pWFdfGQW+8/998csLUDijb8v6mnf8tJkucwL+5fVESN/4E u+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=XHSNPY/PKb5zJ0vbvuPUVun5ABAirDnCsVcNZJhehTo=; b=uZoTSfFOdVbT406rAKEz2k8b7YhgGM5kUtB1+mSICYDVkdG9wdDYedyGCYC+iBiCJI vaRMwHH1875627xYATOPxEx4nw4f85wptaFqtt904tr8tZwCekugxJDO7NEHeLWRiMEp 8FEXFZpOGCzetlTsxLtI9NtVO/lPA7f3gimcMorGDkyBV/MR13nx8iXbPXa5SFVxMQJz LjF64pYYdW1KOIVGEAXFhioyaBk9WSB6RSieEDFir7Z1xZyisfeXS8pJgrHjlfvRAgm+ SXe+KpT7J8BgYLh5BsqK5BskkmEa3Ikx0QA/XbaMJdU/2dkTDz//+r+uHbjjazEacOE+ M9kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Qqsieq2O; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si5645164ioj.19.2021.08.18.07.37.01; Wed, 18 Aug 2021 07:37:14 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Qqsieq2O; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239152AbhHROgQ (ORCPT + 99 others); Wed, 18 Aug 2021 10:36:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32168 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238113AbhHROgP (ORCPT ); Wed, 18 Aug 2021 10:36:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629297340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XHSNPY/PKb5zJ0vbvuPUVun5ABAirDnCsVcNZJhehTo=; b=Qqsieq2OJG4sIwnFilqlLDRELxxazPOmMao57yfz33X/cdLOtPVSvLAt1vn8hALR7tdWmT E/BYFEyfVLTfENoSMuGfvaYrA09uYg3tZU6wLJ8ULOlvOB1BYloky64UB+mBdSiOrAN4Mw gx2EzL6NfFsrklM/WAG3I7kDgfmzuHE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-F_LvN2-2OfKTJrnzljoL9Q-1; Wed, 18 Aug 2021 10:35:37 -0400 X-MC-Unique: F_LvN2-2OfKTJrnzljoL9Q-1 Received: by mail-wm1-f71.google.com with SMTP id j33-20020a05600c1c21b02902e6828f7a20so781506wms.7 for ; Wed, 18 Aug 2021 07:35:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=XHSNPY/PKb5zJ0vbvuPUVun5ABAirDnCsVcNZJhehTo=; b=f73KcSpHf9D7xPWayh+PA5d6BP/X2UyOj33QH41KoCOsqojt0RNkkbkMFuGHMr3FKz UaFQx3cSygLQZfK/mYme+Do+L4qsRNRUMeArCt6agPlGlRPT6omaa8iu8cQJf0gTZm5S 5KA2N80B5DmM2SjyRrun/Qtx8sIt5xo0lvmfI2cu1akHD0VdNO/DcbNXutUGBrCb9A14 IOSubdiDQExHCbwsb+WUYHGYmE6Jneak4vDG8fNs8n5Bc2/FD60Q40s6RM3rLQoi9aCr ZgScy2fWu94xb8qbIsofotmworxF1XWGwue58pOCD/cuKHeQxqtGI2XvJjR671pG9dzs D1/g== X-Gm-Message-State: AOAM532DFuAVrfZCaqwK2z/7LbsB9nvTAoEJQCA8MTYiZOpj8RWSBEyP fwQ6ymn7rl5oDPrKXZWl4qCLsp6PnujLKltBDEKZ4EKkrUpah62Q5Iq+KhdQS4Z8nOpqi70FPCA ULfads2wOvZhkOCnOCbgihbUI1jX4m2jn0MinPjFoHFGSTZhk9doZZ/vq/pmzRhYQF/MFPJQM X-Received: by 2002:a1c:e919:: with SMTP id q25mr9086786wmc.28.1629297335776; Wed, 18 Aug 2021 07:35:35 -0700 (PDT) X-Received: by 2002:a1c:e919:: with SMTP id q25mr9086742wmc.28.1629297335389; Wed, 18 Aug 2021 07:35:35 -0700 (PDT) Received: from [192.168.3.132] (p5b0c6417.dip0.t-ipconnect.de. [91.12.100.23]) by smtp.gmail.com with ESMTPSA id e4sm6265234wrw.74.2021.08.18.07.35.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Aug 2021 07:35:34 -0700 (PDT) Subject: Re: [PATCH v4 06/13] KVM: Move WARN on invalid memslot index to update_memslots() To: "Maciej S. Szmigiero" , 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 , Cornelia Huck , Claudio Imbrenda , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <8db0f1d1901768b5de1417caa425e62d1118e5e8.1628871413.git.maciej.szmigiero@oracle.com> From: David Hildenbrand Organization: Red Hat Message-ID: <957c6b3d-9621-a5a5-418c-f61f87a32ee0@redhat.com> Date: Wed, 18 Aug 2021 16:35:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <8db0f1d1901768b5de1417caa425e62d1118e5e8.1628871413.git.maciej.szmigiero@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13.08.21 21:33, Maciej S. Szmigiero wrote: > 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. > Note that WARN_ON_* is frowned upon, because it can result in crashes with panic_on_warn enabled, which is what some distributions do enable. We tend to work around that by using pr_warn()/pr_warn_once(), avoiding eventually crashing the system when there is a way to continue. -- Thanks, David / dhildenb