Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp816920ybl; Wed, 11 Dec 2019 07:58:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyzhz58bfV+S7bjB2eusoE1yq4sdFxONYabM4jo5XC6plcC16zsxQPBb6687HTjFSTevcMq X-Received: by 2002:a05:6830:1e81:: with SMTP id n1mr2674918otr.53.1576079921374; Wed, 11 Dec 2019 07:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079921; cv=none; d=google.com; s=arc-20160816; b=kABu40QsRmmPQ6rwnwRai9Sj3FQR/NkWvISjJdON2tI7hEo98J7aSA+DOEwyd06UvJ /ADmaStXY8yUCt0TNVMfj/mpYj/x5nYGFAEnZBwD3oww/s3p7qOZPScxwyqhQn3dva2K ERZR+bRUUdw/49y+ZXVozpr+HmoOHU+rBht1NYoheRmetDfrM/QK/Y9VtwJ1mc+SPuW+ TtUUAGmpbywHOzq3oF4keIxlNKzrT3O0yr53treWtlhNWs6teqnluiGN68TCyfhEH9YD pSA8AVoht+K49YipSm4xA9EPzJ7p9ONJBZgM9y+bNuF9ZQjrmIyD3amrKpR7i/YF/PP3 Gs5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gSon6TtV72+lcSJ5/LMDT5D+pVhwz4aZgzzhsW3JmuM=; b=Fo66Qa5oIHYqDz10YLN2oNnnjODG6WhF5qtxD19TmDddTlggoNLdZ+V99jn5P0HQdF RNH3Ry07K7OnsnLBfu80k3LkJQxSDcG161vCYDJlMoTywsYUcSUvv1Y5H2tNkHfgZUOM Rx3KpOjsn/yAYOddg0WHmMuJ40mhf4Z6gmw9ipw2t+rChP3EEsRH13zShWb+9gyPR6oW SCU4KOvhAA15OjKyCO5mhTH7Rlbp+90uSCndJSAAbj6A0cwwr6ohryOx6fece6kx+2zt +37pAdFUQHE+hZWFLy/tZDpy638JkZAPRQFOuaPA8OeaUemiNlNd3G9GfEHbOxnRF+NM ssdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CFwZ8L7d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z25si1350437oto.211.2019.12.11.07.58.29; Wed, 11 Dec 2019 07:58:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CFwZ8L7d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731789AbfLKPP0 (ORCPT + 99 others); Wed, 11 Dec 2019 10:15:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:39946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731214AbfLKPOb (ORCPT ); Wed, 11 Dec 2019 10:14:31 -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 2722D2465B; Wed, 11 Dec 2019 15:14:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077270; bh=5oMM/cvm6A3aBgzOUr6D1IuzknA4XLlLnZ3txtfxgbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CFwZ8L7dJotIQWT0/MLpuLNb5NMTo/1D/zCs1m/0N6EqeCZ3GxEmLlYqJFpRujtDG Os77BcKVRFdg42vBP9AEhY581ybDnwUSYCw7zRBSnRrzGcc/jbbbAKb+h3Yy53V/6M InufLyTVOHmRxtEVQkeBBjl1Lf+xovQvxh9B1og0= 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 5.3 080/105] KVM: arm/arm64: vgic: Dont rely on the wrong pending table Date: Wed, 11 Dec 2019 16:06:09 +0100 Message-Id: <20191211150257.967838938@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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 @@ -363,8 +363,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; @@ -384,11 +384,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);