Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1298813pxb; Fri, 20 Aug 2021 02:31:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzwyQ2nPlpgw7Ug0urW0UqlWEpJKOAhbR3tBONKGrzUdq7edmrcY5gG2FiTd8lxmpQ7Qzp X-Received: by 2002:a17:906:49d5:: with SMTP id w21mr20228723ejv.30.1629451897597; Fri, 20 Aug 2021 02:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629451897; cv=none; d=google.com; s=arc-20160816; b=IgenMsyDW/TzYytWPnkHiSCERrlcnxrDcuzjXEPr0maRQq+1Tg59XTl7nBbxrBQuNK 08+S4dj+NzjXISyQZbDVC2vecd8zBj8lggidaD/ByIFgTELvuavJmyNL6L4BUycUpTGj HRYhmEwwWLeHHvkWY9EQ3hq6sdkMK9zyhELqS3eYjJimMPfCS6L8BCZ6PrxM6Dr+j9Sz ai5CEBT9a+T1iRN3qkg7unM836zTa3CvUda7CljPvIi0k/l6zgapMPSiBWT+3wOiJUn+ dW9T83nu5z4FoxRWxtHOv4TcrFohbnTXd4mckVhyPDX6UrQ+wsg9P6Ms/ekoPxlwwmW0 yu8A== 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=/u+8okw9NC3TUEzgwTlSaEbJlbpO/sr31TcVmCIG3eM=; b=Mjc27wt34k3GKjlBrcrdRsxInut4bQtFFhW+lYurt365yV8lz/nlm6f11ZpwqJeg7y Uu6+VLK+InJT7Q4rJqYiKaIOK9ay5mQR2jw5D+KTmmVDfUt/sLe83KBB8FvbeFkmhwDu TZlo5mvJRA4sIfQw4AAB5oMakDBpbf2Gv9BOtojZWUk0pKMTsnoRP+LbOKIfWxDPIo+p chOW4hkOd1++GoBsigSySLSrL12sVthHOIVcENgZ/c58SlJEvK0dqpzS8qfyW7JIY5o3 gsd5Z2PWqzDLgIzfL4dC0y+uxRRlcsGTqx90Lpyj0L5iT6i9sT7Gr0Lv4Y8Nq2SYqUjn s/rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DBHx2SlI; 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 t2si2209329edd.73.2021.08.20.02.31.13; Fri, 20 Aug 2021 02:31:37 -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=DBHx2SlI; 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 S236739AbhHTJ2Z (ORCPT + 99 others); Fri, 20 Aug 2021 05:28:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43355 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235063AbhHTJ2Y (ORCPT ); Fri, 20 Aug 2021 05:28:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629451666; 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=/u+8okw9NC3TUEzgwTlSaEbJlbpO/sr31TcVmCIG3eM=; b=DBHx2SlI27WlW9ojjfoOSM6wjAYkCL+Tu/so9T7tu/IqAXpYn4N+t4HojW6N+vEYNR9n0Z KdCda0WKDC1V6DmU5qJxGEKafDnbIMs/KzXpsdU2WNQjfASwKrfWidtbr8ZMhPP94AqdAo Pm3GCT5FC7HISpupfkcxi46BQtJ80Io= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-424-zWsxf_OmMEKnPMtuUqaOmQ-1; Fri, 20 Aug 2021 05:27:45 -0400 X-MC-Unique: zWsxf_OmMEKnPMtuUqaOmQ-1 Received: by mail-wr1-f72.google.com with SMTP id n10-20020a5d660a0000b02901551ef5616eso2659057wru.20 for ; Fri, 20 Aug 2021 02:27:45 -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=/u+8okw9NC3TUEzgwTlSaEbJlbpO/sr31TcVmCIG3eM=; b=ATKOZAGtvyfE4b895OBw2No7YRWNVfzT6qecuGRJVu3GiKbrKeRyP81lK2sOnPSgEA AQP0i5v3qMesJmdXNvImrzq5hJu5G1FFevH9U5JaVRdXepzyV/U+RFXdQPE5mcdkOiuw 9xxHrNjnHL+knpzLcFH21WHjgvEDk0G1lyn7PTJ+lRA0EREFEo3uokjmRC4GtWPPawhr 1XqEHwDUICc7TucPekazdBANssQk/F9/WITtfJtMJ0RgMY3sCtbr0yAq2uNBvAN/Pgjm VJUcawnZdG3TWNnJMrrptT6UpUPTsief7EpibdpMRhxs4VNvD2B2Cr4zFswx1Z8UXse+ toaQ== X-Gm-Message-State: AOAM531Wwb3E16e5/bFrGeSdlMqyhCRGNudSwxAZ38r7VPraH3neRRaZ QcWF1d5jaL/UumNeWbRQDItA4Y/Lh2QsjcC3pOYDadxgJ8UnlXLNp3pu/4ZsaSp/0eznNvpqcMc 4SZMW6slWuarth1Xf/Zd5nLlK X-Received: by 2002:a7b:c7c3:: with SMTP id z3mr2877136wmk.96.1629451664226; Fri, 20 Aug 2021 02:27:44 -0700 (PDT) X-Received: by 2002:a7b:c7c3:: with SMTP id z3mr2877101wmk.96.1629451663998; Fri, 20 Aug 2021 02:27:43 -0700 (PDT) Received: from ?IPv6:2003:d8:2f0a:7f00:fad7:3bc9:69d:31f? (p200300d82f0a7f00fad73bc9069d031f.dip0.t-ipconnect.de. [2003:d8:2f0a:7f00:fad7:3bc9:69d:31f]) by smtp.gmail.com with ESMTPSA id c7sm4478795wmq.13.2021.08.20.02.27.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Aug 2021 02:27:43 -0700 (PDT) Subject: Re: [PATCH v4 06/13] KVM: Move WARN on invalid memslot index to update_memslots() To: "Maciej S. Szmigiero" 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: David Hildenbrand Organization: Red Hat Message-ID: <633bf50b-5de4-1e76-736c-067d10bf92b3@redhat.com> Date: Fri, 20 Aug 2021 11:27:42 +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: 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.21 23:43, Maciej S. Szmigiero wrote: > 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"). Okay, that makes sense then, thanks! -- Thanks, David / dhildenb