From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79CEFC43603 for ; Wed, 11 Dec 2019 15:25:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D6822173E for ; Wed, 11 Dec 2019 15:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077938; bh=05/K+HdX3XI5eOzqwwiLaJkiHzPHa6Dset8Agi/y9uQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=E78ehM4YhoIX9IshE/e1KGDkqgJ3bQH/mf8kxPgJTECwDY0YYQmGd0Km3T3dFyehK Bk+yEbPoF3lZzjRIhjAlH3wilG7u+D9B+neR1vLbUdP41s1NLdNE5V9H6IIX3ImW5o Y+f/jIvpOiQ/X6WRpgyIsEsEeGZKCfJZLbg52Dto= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732814AbfLKPZh (ORCPT ); Wed, 11 Dec 2019 10:25:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:57808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732782AbfLKPZe (ORCPT ); Wed, 11 Dec 2019 10:25:34 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B8DD2208C3; Wed, 11 Dec 2019 15:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077934; bh=05/K+HdX3XI5eOzqwwiLaJkiHzPHa6Dset8Agi/y9uQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sr1KbbW51P+Yl1kz3ejd+UfaxDBKac1efiqVfuMbmh/GKMOlZmhOlhpsa+RSIDUUF JEpQ6dfLbi1CJFzYKWqW+2AGJbQjRslMlWMAgNR3asNqbMoGf20KAbLH2hbLzM5J+b fqyhCFfpNdsu5o2xhaTCzkqgpYaGlT+UO3Wj+7So= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zenghui Yu , Marc Zyngier , Eric Auger Subject: [PATCH 4.19 225/243] KVM: arm/arm64: vgic: Dont rely on the wrong pending table Date: Wed, 11 Dec 2019 16:06:27 +0100 Message-Id: <20191211150354.521461342@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zenghui Yu commit ca185b260951d3b55108c0b95e188682d8a507b7 upstream. It's possible that two LPIs locate in the same "byte_offset" but target two different vcpus, where their pending status are indicated by two different pending tables. In such a scenario, using last_byte_offset optimization will lead KVM relying on the wrong pending table entry. Let us use last_ptr instead, which can be treated as a byte index into a pending table and also, can be vcpu specific. Fixes: 280771252c1b ("KVM: arm64: vgic-v3: KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES") Cc: stable@vger.kernel.org Signed-off-by: Zenghui Yu Signed-off-by: Marc Zyngier Acked-by: Eric Auger Link: https://lore.kernel.org/r/20191029071919.177-4-yuzenghui@huawei.com Signed-off-by: Greg Kroah-Hartman --- virt/kvm/arm/vgic/vgic-v3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -375,8 +375,8 @@ retry: int vgic_v3_save_pending_tables(struct kvm *kvm) { struct vgic_dist *dist = &kvm->arch.vgic; - int last_byte_offset = -1; struct vgic_irq *irq; + gpa_t last_ptr = ~(gpa_t)0; int ret; u8 val; @@ -396,11 +396,11 @@ int vgic_v3_save_pending_tables(struct k bit_nr = irq->intid % BITS_PER_BYTE; ptr = pendbase + byte_offset; - if (byte_offset != last_byte_offset) { + if (ptr != last_ptr) { ret = kvm_read_guest_lock(kvm, ptr, &val, 1); if (ret) return ret; - last_byte_offset = byte_offset; + last_ptr = ptr; } stored = val & (1U << bit_nr);