From patchwork Wed Feb 8 11:43:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9562307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A8108601E5 for ; Wed, 8 Feb 2017 11:45:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B6C328496 for ; Wed, 8 Feb 2017 11:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 901D0284CF; Wed, 8 Feb 2017 11:45:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B69D284D2 for ; Wed, 8 Feb 2017 11:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932276AbdBHLo6 (ORCPT ); Wed, 8 Feb 2017 06:44:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46076 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754354AbdBHLo5 (ORCPT ); Wed, 8 Feb 2017 06:44:57 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 176BDC04BD32; Wed, 8 Feb 2017 11:44:58 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-36.ams2.redhat.com [10.36.116.36]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v18BhbGK022300; Wed, 8 Feb 2017 06:44:54 -0500 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, marc.zyngier@arm.com, christoffer.dall@linaro.org, vijayak@caviumnetworks.com, Vijaya.Kumar@cavium.com, peter.maydell@linaro.org, linux-arm-kernel@lists.infradead.org, drjones@redhat.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: andre.przywara@arm.com, Prasun.Kapoor@cavium.com, pbonzini@redhat.com, dgilbert@redhat.com, quintela@redhat.com Subject: [RFC v2 19/19] KVM: arm64: ITS: Pending table save/restore Date: Wed, 8 Feb 2017 12:43:32 +0100 Message-Id: <1486554212-2774-20-git-send-email-eric.auger@redhat.com> In-Reply-To: <1486554212-2774-1-git-send-email-eric.auger@redhat.com> References: <1486554212-2774-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Feb 2017 11:44:58 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Save and restore the pending tables. Pending table restore obviously requires the pendbaser to be already set. Signed-off-by: Eric Auger --- v1 -> v2: - do not care about the 1st KB which should be zeroed according to the spec. --- virt/kvm/arm/vgic/vgic-its.c | 71 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index c1ae85b..67db680 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1736,7 +1736,48 @@ static int lookup_table(struct vgic_its *its, gpa_t base, int size, int esz, */ static int vgic_its_flush_pending_tables(struct vgic_its *its) { - return -ENXIO; + struct kvm *kvm = its->dev->kvm; + struct vgic_dist *dist = &kvm->arch.vgic; + struct vgic_irq *irq; + int ret; + + /** + * we do not take the dist->lpi_list_lock since we have a garantee + * the LPI list is not touched while the its lock is held + */ + list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { + struct kvm_vcpu *vcpu; + gpa_t pendbase, ptr; + bool stored; + u8 val; + + vcpu = irq->target_vcpu; + if (!vcpu) + return -EINVAL; + + pendbase = PENDBASER_ADDRESS(vcpu->arch.vgic_cpu.pendbaser); + + ptr = pendbase + (irq->intid / BITS_PER_BYTE); + + ret = kvm_read_guest(kvm, (gpa_t)ptr, &val, 1); + if (ret) + return ret; + + stored = val & (irq->intid % BITS_PER_BYTE); + if (stored == irq->pending_latch) + continue; + + if (irq->pending_latch) + val |= 1 << (irq->intid % BITS_PER_BYTE); + else + val &= ~(1 << (irq->intid % BITS_PER_BYTE)); + + ret = kvm_write_guest(kvm, (gpa_t)ptr, &val, 1); + if (ret) + return ret; + } + + return 0; } /** @@ -1745,7 +1786,33 @@ static int vgic_its_flush_pending_tables(struct vgic_its *its) */ static int vgic_its_restore_pending_tables(struct vgic_its *its) { - return -ENXIO; + struct vgic_irq *irq; + struct kvm *kvm = its->dev->kvm; + struct vgic_dist *dist = &kvm->arch.vgic; + int ret; + + list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) { + struct kvm_vcpu *vcpu; + gpa_t pendbase, ptr; + u8 val; + + vcpu = irq->target_vcpu; + if (!vcpu) + return -EINVAL; + + if (!(vcpu->arch.vgic_cpu.pendbaser & GICR_PENDBASER_PTZ)) + return 0; + + pendbase = PENDBASER_ADDRESS(vcpu->arch.vgic_cpu.pendbaser); + + ptr = pendbase + (irq->intid / BITS_PER_BYTE); + + ret = kvm_read_guest(kvm, (gpa_t)ptr, &val, 1); + if (ret) + return ret; + irq->pending_latch = val & (1 << (irq->intid % BITS_PER_BYTE)); + } + return 0; } static int vgic_its_flush_ite(struct vgic_its *its, struct its_device *dev,