Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp17832pxb; Wed, 18 Aug 2021 14:45:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsC8XflT2aqij3ssAWjASDbVEZA07/8GoYZMgm9XiVM/NuCCqRl8ItiriLpeqHKf3lNC9+ X-Received: by 2002:a05:6e02:1d08:: with SMTP id i8mr7673431ila.185.1629323120539; Wed, 18 Aug 2021 14:45:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629323120; cv=none; d=google.com; s=arc-20160816; b=0qFmU4jdVFbyhC48ebdLGBym6SmbWqVSoSJSCxMibbDRB8y2KxlI4PKrOpdt7YyDw1 cjsI7HdOHxTW+TRtmODL1LFQo1rA20dW6ln3oeWVKIrhkDqkNhK8f4RvupreWziu1NJQ Mf/O60nG8owaNm8lXpzCmMmPVrUU5DhDYwWZ7110OpN+ka7rww4PwpnjeKcykuAMqbEM agsvkAB/zMtSaxw6rGeaZh55F+pwo5A60RLw0JaBxRpc3VHuEsbByvoC3Zic8OCGuJaq 3A8bAByL1cAwijMOQU0m2ljVwz+Sz7Pzxb0bw4hOOIs4P0ri74sQI0smI4DTu8n9uCDH SNxA== 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:subject:from :references:cc:to; bh=mUtkKWLb5VbAxCC7/A9S/o76KmxkmhYluwCW0XcIOao=; b=P5T4RSqwVJKoCBkQX3P50T1PHgtNCy8taGfoSzxte/c281SMuk6BX2xJWzWF9T/E+j 4EJAa4Rb/2n3mSDt+bFbKpWAJS+cKo1GAllxv1bAlrYSSQAbSuajLSvzp72UqlX7+jVO 9ha7vRl7BoO/efTmFot3ZKXaHHyBt/nr1rlvFEKZEa6YY9uRSK60zruabYjzfDNAuTTb gBi9L0LTUYr+mhkSq0jl+pMnB/zh2bd7/t0RuBATmAaNYB+bgUGg1THOBR8j7iH6RRnl vqBx4jeTjcD/gw5dRFQRt/L0QOM0rNsZipuef2LnFtE3o1Z2UMH/JufM2IthQ1dPkYXH +czQ== 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 d20si902074ioo.61.2021.08.18.14.45.09; Wed, 18 Aug 2021 14:45:20 -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 S234266AbhHRVoJ (ORCPT + 99 others); Wed, 18 Aug 2021 17:44:09 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:34654 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234140AbhHRVoJ (ORCPT ); Wed, 18 Aug 2021 17:44:09 -0400 Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mGTLL-000665-Kq; Wed, 18 Aug 2021 23:43:27 +0200 To: David Hildenbrand 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, Paolo Bonzini , Vitaly Kuznetsov References: <8db0f1d1901768b5de1417caa425e62d1118e5e8.1628871413.git.maciej.szmigiero@oracle.com> <957c6b3d-9621-a5a5-418c-f61f87a32ee0@redhat.com> From: "Maciej S. Szmigiero" Subject: Re: [PATCH v4 06/13] KVM: Move WARN on invalid memslot index to update_memslots() Message-ID: Date: Wed, 18 Aug 2021 23:43:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <957c6b3d-9621-a5a5-418c-f61f87a32ee0@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18.08.2021 16:35, David Hildenbrand wrote: > 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. > This patch uses WARN_ON_ONCE because: 1) It was used in the old code and the patch merely moves the check from kvm_memslot_move_backward() to its caller, 2) This chunk of code is wholly replaced by patch 11 from this series anyway ("Keep memslots in tree-based structures instead of array-based ones"). Thanks, Maciej