Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp650742pxb; Tue, 5 Apr 2022 17:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxC/D1qUSU4Yt+3wgO6B0NT6dsmQAnk7oVjnUztxcwv+ekx0dozRpSFGNnhqSg3csrur0VK X-Received: by 2002:a05:6402:2707:b0:419:5b7d:fd21 with SMTP id y7-20020a056402270700b004195b7dfd21mr6156406edd.51.1649204291009; Tue, 05 Apr 2022 17:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204291; cv=none; d=google.com; s=arc-20160816; b=yzjgM14XN9/SGPe4tWM3oTZNt1QiONNeMqHztguwCES1p6WcVm/iMRPP+zHg3N0Ih5 Si5GJx1itS3sJXQhp+XKlWHy8KXvkqjbivd62WrGsZ3NkdDzyLVzStfe8KyOTqFLSFMr Ty8E1DinaJHRotH4/KLGPKe0FbbHpKi+ZglHxH6yb1/PijeaqYYqXyxYCXmEmN7Vt4gx 9ovOeBh2GAVWGWA7vmWebjZLyv3mT8NAjznC7VuyWYre6XmEICJoo/JVEATw7nK8faxj dfzJ3PAEY3F1MohQGcjxr8o12vB4jCaJd6M2ovvRUgnvXRpMI+BYB5nr9/5uJtN+GBM7 M8QQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+eo7gnTdBXmFy1wmi4hfzfuBUNTzI73P2sca008kQdM=; b=0tZBIO6gu6C86GPWbl30lRg1ibibeP8ROVheQ6uBu1vrWngJXQaO0Zsmbld8Gu5uOU ebwBBAt3Ol6LN+Yx1nqRzbjGr3MtoIRsNOxsnqGweBZqdnECdNh0gdbmMssufhASRkzI MukvtiCikol0GUkUGKf37xIMW4/5TSmWjPRGCWWK/CEKgeqfp7PwvmQbCaXut9UKLyDr 7DUUwSR65ETLOWNVpMZ5XnToPhpk0RnIzXePa61TWYJ26A/iar3kCZeYfhB/ruCa+yMW PaxM2z9XiOUcEJj0N3SFfF/NrVwtN+of+Vu46eRhLLIGtf19biRtrg9OYcOo/f+aK7BG Q3Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P3XX0+0H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j2-20020a17090623e200b006df76385e22si10185207ejg.706.2022.04.05.17.17.46; Tue, 05 Apr 2022 17:18:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P3XX0+0H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388705AbiDENc5 (ORCPT + 99 others); Tue, 5 Apr 2022 09:32:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346025AbiDEJXX (ORCPT ); Tue, 5 Apr 2022 05:23:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D93A94EF; Tue, 5 Apr 2022 02:12:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 10FCBB80DA1; Tue, 5 Apr 2022 09:12:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73BBDC385A0; Tue, 5 Apr 2022 09:12:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149967; bh=uvlY6re4qRA42gcweeLvEonqNIH1YFuQWJrOL96quZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P3XX0+0HhRtkDXdWU/tgVqPYTVaNKnccsJKmUo3Ei6SAXWHw3RvsqS07zEyaN0X+k scM195kCzRk1qNlepxQEYdq1ICr3kWGNJ0+THc0rnEPq/5UcIKT11AOznbPvBlHv6W Zzge30qT2+XbLteaihYhSKQKJAt7QJcvyb1upvdU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Li RongQing , Paolo Bonzini Subject: [PATCH 5.16 0905/1017] KVM: x86: fix sending PV IPI Date: Tue, 5 Apr 2022 09:30:18 +0200 Message-Id: <20220405070421.088309561@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Li RongQing commit c15e0ae42c8e5a61e9aca8aac920517cf7b3e94e upstream. If apic_id is less than min, and (max - apic_id) is greater than KVM_IPI_CLUSTER_SIZE, then the third check condition is satisfied but the new apic_id does not fit the bitmask. In this case __send_ipi_mask should send the IPI. This is mostly theoretical, but it can happen if the apic_ids on three iterations of the loop are for example 1, KVM_IPI_CLUSTER_SIZE, 0. Fixes: aaffcfd1e82 ("KVM: X86: Implement PV IPIs in linux guest") Signed-off-by: Li RongQing Message-Id: <1646814944-51801-1-git-send-email-lirongqing@baidu.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -515,7 +515,7 @@ static void __send_ipi_mask(const struct } else if (apic_id < min && max - apic_id < KVM_IPI_CLUSTER_SIZE) { ipi_bitmap <<= min - apic_id; min = apic_id; - } else if (apic_id < min + KVM_IPI_CLUSTER_SIZE) { + } else if (apic_id > min && apic_id < min + KVM_IPI_CLUSTER_SIZE) { max = apic_id < max ? max : apic_id; } else { ret = kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap,